Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add gasmetering to tests #1

Merged
merged 2 commits into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}
Loading