Skip to content

Commit

Permalink
add gasmetering to tests (#1)
Browse files Browse the repository at this point in the history
add gasmetering to tests
  • Loading branch information
Madeveda authored Jul 1, 2024
1 parent 58d15c2 commit 4fda306
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 6 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
10 changes: 8 additions & 2 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,15 @@ name: test
on:
pull_request:
branches: [main, master, staging, dev, feat/**, fix/**]
env:
FOUNDRY_PROFILE: pr
push:
branches: [main, master, staging, dev]
env:
FOUNDRY_PROFILE: ci

env:
FOUNDRY_PROFILE: ci
FORGE_SNAPSHOT_CHECK: true

jobs:
check:
Expand All @@ -32,5 +38,5 @@ jobs:

- name: Run Forge tests
run: |
forge test -vvv
rm .forge-snapshots/* && forge test --isolate -vvv
id: test
18 changes: 16 additions & 2 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,30 @@ 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 4fda306

Please sign in to comment.