From 4fda306e5f04e2e031be0576dfc30d1a628d8617 Mon Sep 17 00:00:00 2001 From: Madeveda <55543890+Madeveda@users.noreply.github.com> Date: Tue, 2 Jul 2024 00:03:10 +0200 Subject: [PATCH] add gasmetering to tests (#1) add gasmetering to tests --- .forge-snapshots/Increment counter number.snap | 1 + .forge-snapshots/Set counter number.snap | 1 + .github/workflows/test.yaml | 10 ++++++++-- foundry.toml | 18 ++++++++++++++++-- lib/forge-std | 2 +- test/Counter.t.sol | 5 ++++- 6 files changed, 31 insertions(+), 6 deletions(-) create mode 100644 .forge-snapshots/Increment counter number.snap create mode 100644 .forge-snapshots/Set counter number.snap diff --git a/.forge-snapshots/Increment counter number.snap b/.forge-snapshots/Increment counter number.snap new file mode 100644 index 0000000..1d3d6fb --- /dev/null +++ b/.forge-snapshots/Increment counter number.snap @@ -0,0 +1 @@ +26276 \ No newline at end of file diff --git a/.forge-snapshots/Set counter number.snap b/.forge-snapshots/Set counter number.snap new file mode 100644 index 0000000..7edaeb9 --- /dev/null +++ b/.forge-snapshots/Set counter number.snap @@ -0,0 +1 @@ +26507 \ No newline at end of file diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 42c3cda..45e423e 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -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: @@ -32,5 +38,5 @@ jobs: - name: Run Forge tests run: | - forge test -vvv + rm .forge-snapshots/* && forge test --isolate -vvv id: test diff --git a/foundry.toml b/foundry.toml index baea3d3..88deca3 100644 --- a/foundry.toml +++ b/foundry.toml @@ -8,6 +8,10 @@ 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", @@ -15,9 +19,19 @@ remappings = [ "@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 diff --git a/lib/forge-std b/lib/forge-std index 2f11269..8948d45 160000 --- a/lib/forge-std +++ b/lib/forge-std @@ -1 +1 @@ -Subproject commit 2f112697506eab12d433a65fdc31a639548fe365 +Subproject commit 8948d45d3d9022c508b83eb5d26fd3a7a93f2f32 diff --git a/test/Counter.t.sol b/test/Counter.t.sol index 12eb00d..a752cc1 100644 --- a/test/Counter.t.sol +++ b/test/Counter.t.sol @@ -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"; @@ -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); } }