Skip to content

Commit

Permalink
test: add complete tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ZeroEkkusu committed Nov 3, 2023
1 parent 6309130 commit 204ad2b
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 32 deletions.
2 changes: 1 addition & 1 deletion script/1.0.0/input.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"initialOwner": "0x48789ECd4317eCc8dBdB1d06EF39F01c5862a941"
},
"Counter": {
"number": 3
"number": 10
}
}
}
53 changes: 53 additions & 0 deletions test/1.0.0/Counter.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.22;

import "forge-std/Test.sol";
import "test/util/TestHelpers.sol";

import "script/1.0.0/Deploy.s.sol";

abstract contract BeforeScript is Test, TestHelpers, CounterDeployer {
Counter internal counter;

function setUp() public {
(counter, , ) = deployCounter_NoInit(makeAddr(""));
}
}

contract CounterTest_Zero is BeforeScript {
function test_Initializes(uint256 number) public {
counter.initialize(number);
assertEq(counter.number(), number);
}
}

abstract contract AfterScript is Test, TestHelpers, Deploy {
function setUp() public virtual {
run();
}
}

contract CounterTest_Initialized is AfterScript {
function test_IsInitialized() public {
assertEq(counter.number(), 10);
}

function test_RevertsIf_InitializedAgain() public {
vm.expectRevert(Initializable.InvalidInitialization.selector);
counter.initialize(1);
}

function test_IncrementsNumber() public {
counter.increment();
assertEq(counter.number(), 11);
}

function testFuzz_SetsNumber(uint256 x) public {
counter.setNumber(x);
assertEq(counter.number(), x);
}

function test_ReturnsVersion() public {
assertEq(counter.version(), "1.0.0");
}
}
31 changes: 0 additions & 31 deletions test/Counter.t.sol

This file was deleted.

13 changes: 13 additions & 0 deletions test/util/TestHelpers.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.22;

import "forge-std/Test.sol";

abstract contract TestHelpers is Test {
Account internal DEPLOYER;

constructor() {
DEPLOYER = makeAccount("DEPLOYER");
vm.setEnv("PRIVATE_KEY", vm.toString(DEPLOYER.key));
}
}

0 comments on commit 204ad2b

Please sign in to comment.