64 lines
2.4 KiB
Solidity
64 lines
2.4 KiB
Solidity
// SPDX-License-Identifier: MIT
|
|
pragma solidity ^0.8.24;
|
|
|
|
import "forge-std/Test.sol";
|
|
import "../contracts/_GreeterFactory.sol";
|
|
|
|
/// @title _GreeterFactory Test Suite
|
|
/// @notice Foundry tests for _GreeterFactory
|
|
contract _GreeterFactoryTest is Test {
|
|
_GreeterFactory public instance;
|
|
|
|
event LogSetup(string message);
|
|
|
|
function setUp() public {
|
|
instance = new _GreeterFactory("Implement: Deploys and manages instances of the ");
|
|
emit LogSetup("setUp complete");
|
|
}
|
|
|
|
// ── deployment tests ───────────────────────────────────────────────
|
|
|
|
function test_Deployment() public view {
|
|
assertEq(instance.topic(), "Implement: Deploys and manages instances of the ", "initial topic mismatch");
|
|
}
|
|
|
|
function test_DeploymentNonEmpty() public view {
|
|
assertTrue(bytes(instance.topic()).length > 0, "topic should not be empty");
|
|
}
|
|
|
|
// ── state mutation tests ───────────────────────────────────────────
|
|
|
|
function test_SetTopic() public {
|
|
string memory next = "updated value";
|
|
instance.setTopic(next);
|
|
assertEq(instance.topic(), next, "setTopic failed");
|
|
}
|
|
|
|
function test_SetTopicEmpty() public {
|
|
instance.setTopic("");
|
|
assertEq(instance.topic(), "", "setting empty topic failed");
|
|
}
|
|
|
|
function test_SetTopicTwice() public {
|
|
instance.setTopic("first");
|
|
instance.setTopic("second");
|
|
assertEq(instance.topic(), "second", "double set failed");
|
|
}
|
|
|
|
// ── fuzz tests ────────────────────────────────────────────────────
|
|
|
|
function testFuzz_SetTopic(string calldata newTopic) public {
|
|
instance.setTopic(newTopic);
|
|
assertEq(instance.topic(), newTopic, "fuzz setTopic mismatch");
|
|
}
|
|
|
|
// ── gas benchmarks ────────────────────────────────────────────────
|
|
|
|
function test_SetTopicGas() public {
|
|
uint256 gasBefore = gasleft();
|
|
instance.setTopic("gas benchmark");
|
|
uint256 gasUsed = gasBefore - gasleft();
|
|
assertTrue(gasUsed < 100_000, "setTopic gas too high");
|
|
}
|
|
}
|