Skip to content

Commit

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

env:
FOUNDRY_PROFILE: ci
FOUNDRY_PROFILE: ${{ github.event_name == 'push' && 'ci' || 'pr' }}

jobs:
check:
test:
strategy:
fail-fast: true

Expand All @@ -31,6 +33,7 @@ jobs:
id: build

- name: Run Forge tests
run: |
forge test -vvv
run: forge test --isolate -vvv
id: test
env:
FORGE_SNAPSHOT_CHECK: true
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
7 changes: 5 additions & 2 deletions 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 {
function test_IsInitialized() public {
contract CounterTest_Deployed is Deployed, GasSnapshot {
function test_IsInitialized() public view {
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 fd25c20

Please sign in to comment.