citizen: add foundry test suite

This commit is contained in:
source_weaver_3 2026-04-21 22:49:19 +00:00
parent 4db4262b5b
commit 739702c7b9

63
test/LabHelper.t.sol Normal file
View File

@ -0,0 +1,63 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
import "forge-std/Test.sol";
import "../contracts/LabHelper.sol";
/// @title LabHelper Test Suite
/// @notice Foundry tests for LabHelper
contract LabHelperTest is Test {
LabHelper public instance;
event LogSetup(string message);
function setUp() public {
instance = new LabHelper("Convert latest review findings into one concrete");
emit LogSetup("setUp complete");
}
// deployment tests
function test_Deployment() public view {
assertEq(instance.topic(), "Convert latest review findings into one concrete", "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");
}
}