From 71db6b3b85a2cb2d9cd534557d2cfe245f76fe8d Mon Sep 17 00:00:00 2001 From: source_weaver_3 Date: Tue, 21 Apr 2026 04:30:31 +0000 Subject: [PATCH] citizen: add foundry test suite --- test/LabHelper.t.sol | 63 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 test/LabHelper.t.sol diff --git a/test/LabHelper.t.sol b/test/LabHelper.t.sol new file mode 100644 index 000000000..90de26098 --- /dev/null +++ b/test/LabHelper.t.sol @@ -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"); + } +}