Skip to content

Commit

Permalink
add gasmetering to tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Madeveda committed Jul 1, 2024
1 parent 58d15c2 commit e05ecbc
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 5 deletions.
1 change: 1 addition & 0 deletions .forge-snapshots/Increment counter number.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
26276
1 change: 1 addition & 0 deletions .forge-snapshots/Set counter number.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
26507
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ jobs:

- name: Run Forge tests
run: |
forge test -vvv
rm .forge-snapshots/* && forge test --isolate -vvv
id: test
16 changes: 14 additions & 2 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,28 @@ via_ir = true
solc = "0.8.23"
verbosity = 2
ffi = true
fs_permissions = [{ access = "read-write", path = ".forge-snapshots"},
{ access = "read", path = "script/" }]

remappings = [
"forge-std=lib/forge-std/src",
"@openzeppelin/contracts=lib/openzeppelin-contracts/contracts",
"@openzeppelin/contracts-upgradeable=lib/openzeppelin-contracts-upgradeable/contracts"
]

[profile.intense.fuzz]
[profile.default.fuzz]
runs = 1000

[profile.pr.fuzz]
runs = 10000
max_test_rejects = 999999

[profile.ci.fuzz]
runs = 100000

[profile.debug]
via_ir = false
optimizer_runs = 200
fuzz.runs = 100

[fmt]
line_length = 160
Expand Down
5 changes: 4 additions & 1 deletion test/Counter.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pragma solidity 0.8.23;

import "forge-std/Test.sol";
import "test/util/TestHelpers.sol";
import {GasSnapshot} from "forge-gas-snapshot/GasSnapshot.sol";

import {Counter} from "src/Counter.sol";

Expand All @@ -15,18 +16,20 @@ abstract contract Deployed is Test, TestHelpers {
}
}

contract CounterTest_Deployed is Deployed {
contract CounterTest_Deployed is Deployed, GasSnapshot {
function test_IsInitialized() public {
assertEq(counter.number(), 10);
}

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

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

0 comments on commit e05ecbc

Please sign in to comment.