From 17933fa1693e5779a8769f01c212cc2559e9bcd0 Mon Sep 17 00:00:00 2001 From: Mark Toda Date: Tue, 27 Aug 2024 15:10:32 -0400 Subject: [PATCH 1/4] feat: use soldeer --- .forge-snapshots/manySstore.snap | 2 +- .forge-snapshots/singleSstore.snap | 2 +- .forge-snapshots/singleSstoreClosure.snap | 2 +- .forge-snapshots/singleSstoreLastCall.snap | 2 +- .forge-snapshots/sstoreClosure.snap | 2 +- .gitignore | 1 + .gitmodules | 3 --- .soldeerignore | 5 +++++ README.md | 2 +- foundry.toml | 13 +++++++++++++ lib/forge-std | 1 - remappings.txt | 1 + soldeer.lock | 6 ++++++ src/GasSnapshot.sol | 4 ++-- test/GasSnapshot.t.sol | 16 ++++++++-------- 15 files changed, 42 insertions(+), 20 deletions(-) delete mode 100644 .gitmodules create mode 100644 .soldeerignore delete mode 160000 lib/forge-std create mode 100644 remappings.txt create mode 100644 soldeer.lock diff --git a/.forge-snapshots/manySstore.snap b/.forge-snapshots/manySstore.snap index ef72e9b..1fbb791 100644 --- a/.forge-snapshots/manySstore.snap +++ b/.forge-snapshots/manySstore.snap @@ -1 +1 @@ -70348 \ No newline at end of file +49284 \ No newline at end of file diff --git a/.forge-snapshots/singleSstore.snap b/.forge-snapshots/singleSstore.snap index d049b15..80ecb46 100644 --- a/.forge-snapshots/singleSstore.snap +++ b/.forge-snapshots/singleSstore.snap @@ -1 +1 @@ -48459 \ No newline at end of file +27395 \ No newline at end of file diff --git a/.forge-snapshots/singleSstoreClosure.snap b/.forge-snapshots/singleSstoreClosure.snap index c59e906..962f066 100644 --- a/.forge-snapshots/singleSstoreClosure.snap +++ b/.forge-snapshots/singleSstoreClosure.snap @@ -1 +1 @@ -46269 \ No newline at end of file +25205 \ No newline at end of file diff --git a/.forge-snapshots/singleSstoreLastCall.snap b/.forge-snapshots/singleSstoreLastCall.snap index 4c52430..97400eb 100644 --- a/.forge-snapshots/singleSstoreLastCall.snap +++ b/.forge-snapshots/singleSstoreLastCall.snap @@ -1 +1 @@ -43429 \ No newline at end of file +22365 \ No newline at end of file diff --git a/.forge-snapshots/sstoreClosure.snap b/.forge-snapshots/sstoreClosure.snap index 5ed0938..edc2416 100644 --- a/.forge-snapshots/sstoreClosure.snap +++ b/.forge-snapshots/sstoreClosure.snap @@ -1 +1 @@ -68158 \ No newline at end of file +47094 \ No newline at end of file diff --git a/.gitignore b/.gitignore index 2c4088a..3f55d40 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ out/ lib/ cache/ +dependencies/ diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index 888d42d..0000000 --- a/.gitmodules +++ /dev/null @@ -1,3 +0,0 @@ -[submodule "lib/forge-std"] - path = lib/forge-std - url = https://github.com/foundry-rs/forge-std diff --git a/.soldeerignore b/.soldeerignore new file mode 100644 index 0000000..6ae3add --- /dev/null +++ b/.soldeerignore @@ -0,0 +1,5 @@ +.git/ +.github/ +.forge_snapshots/ +out/ +dependencies/ diff --git a/README.md b/README.md index 00f4491..72a15b5 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ Forge has native gas reporting with `forge snapshot` and `forge test --gas-repor # Installation ```solidity -forge install marktoda/forge-gas-snapshot +soldeer install forge-gas-snapshot~v0.0.4 ``` - NOTE: foundry.toml must be updated to allow forge to write the snapshots diff --git a/foundry.toml b/foundry.toml index 692a1c0..cb0294f 100644 --- a/foundry.toml +++ b/foundry.toml @@ -4,3 +4,16 @@ out = 'out' libs = ['lib'] ffi = true fs_permissions = [{ access = "read-write", path = ".forge-snapshots/"}] + +[soldeer] +# whether soldeer manages remappings +remappings_generated = true + +# whether soldeer re-generates all remappings when installing, updating or uninstalling deps +remappings_regenerate = true + +# whether to suffix the remapping with the version: `name-a.b.c` +remappings_version = false + +[dependencies] +forge-std = "1.9.2" diff --git a/lib/forge-std b/lib/forge-std deleted file mode 160000 index 2d8b7b8..0000000 --- a/lib/forge-std +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 2d8b7b876a5b328d6a73e13c4740ed7a0d72d5f4 diff --git a/remappings.txt b/remappings.txt new file mode 100644 index 0000000..bc90c1e --- /dev/null +++ b/remappings.txt @@ -0,0 +1 @@ +forge-std/=dependencies/forge-std-1.9.2/ diff --git a/soldeer.lock b/soldeer.lock new file mode 100644 index 0000000..74aa013 --- /dev/null +++ b/soldeer.lock @@ -0,0 +1,6 @@ +[[dependencies]] +name = "forge-std" +version = "1.9.2" +source = "https://soldeer-revisions.s3.amazonaws.com/forge-std/1_9_2_06-08-2024_17:31:25_forge-std-1.9.2.zip" +checksum = "20fd008c7c69b6c737cc0284469d1c76497107bc3e004d8381f6d8781cb27980" +integrity = "ae8b0d2637a0bdd85b6134117c0a7549dbe0ee8af66db454c66060547b654a89" diff --git a/src/GasSnapshot.sol b/src/GasSnapshot.sol index b879755..0782b29 100644 --- a/src/GasSnapshot.sol +++ b/src/GasSnapshot.sol @@ -1,8 +1,8 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.15; -import "forge-std/console2.sol"; -import {Script} from "forge-std/Script.sol"; +import "forge-std/src/console2.sol"; +import {Script} from "forge-std/src/Script.sol"; import {UintString} from "./utils/UintString.sol"; contract GasSnapshot is Script { diff --git a/test/GasSnapshot.t.sol b/test/GasSnapshot.t.sol index cc68ff8..5973a35 100644 --- a/test/GasSnapshot.t.sol +++ b/test/GasSnapshot.t.sol @@ -1,8 +1,8 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.13; -import "forge-std/console2.sol"; -import {Test} from "forge-std/Test.sol"; +import "forge-std/src/console2.sol"; +import {Test} from "forge-std/src/Test.sol"; import {GasSnapshot} from "../src/GasSnapshot.sol"; import {SimpleOperations} from "../src/test/SimpleOperations.sol"; @@ -26,7 +26,7 @@ contract GasSnapshotTest is Test, GasSnapshot { snapEnd(); string memory value = vm.readLine(".forge-snapshots/singleSstore.snap"); - assertEq(value, "48459"); + assertEq(value, "27395"); } function testSingleSstoreLastCall() public { @@ -35,21 +35,21 @@ contract GasSnapshotTest is Test, GasSnapshot { string memory value = vm.readLine(".forge-snapshots/singleSstoreLastCall.snap"); // includes 21,000 overhead for transaction, 20,000 clean SSTORE - assertEq(value, "43429"); + assertEq(value, "22365"); } function testSingleSstoreClosure() public { snap("singleSstoreClosure", simpleOperations.singleSstore); string memory value = vm.readLine(".forge-snapshots/singleSstoreClosure.snap"); - assertEq(value, "46269"); + assertEq(value, "25205"); } function testManySstoreClosure() public { snap("sstoreClosure", simpleOperations.manySstore); string memory value = vm.readLine(".forge-snapshots/sstoreClosure.snap"); - assertEq(value, "68158"); + assertEq(value, "47094"); } function testInternalClosure() public { @@ -96,7 +96,7 @@ contract GasSnapshotTest is Test, GasSnapshot { snapEnd(); string memory value = vm.readLine(".forge-snapshots/manySstore.snap"); - assertEq(value, "70348"); + assertEq(value, "49284"); } function testSnapshotCodeSize() public { @@ -132,7 +132,7 @@ contract GasSnapshotTest is Test, GasSnapshot { // preloaded with the wrong value snapStart("checkManySstore"); simpleOperations.manySstore(); - vm.expectRevert(abi.encodeWithSelector(GasSnapshot.GasMismatch.selector, 1, 73825)); + vm.expectRevert(abi.encodeWithSelector(GasSnapshot.GasMismatch.selector, 1, 52761)); snapEnd(); } From b81e7f225cd1403ac2a9ed8d9156fc2797ab7e3e Mon Sep 17 00:00:00 2001 From: Mark Toda Date: Wed, 28 Aug 2024 14:02:01 -0400 Subject: [PATCH 2/4] feat: update test workflow --- .github/workflows/test.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8e738d4..899cdda 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -22,6 +22,14 @@ jobs: with: version: nightly + - name: Install Dependencies + uses: foundry-rs/foundry-toolchain@v1 + with: + version: nightly + run: | + forge soldeer install + id: install + - name: Run Forge build run: | forge --version From 877f227ef0f60b79896d5066ddbcf1c5662d9fbc Mon Sep 17 00:00:00 2001 From: Mark Toda Date: Wed, 28 Aug 2024 14:07:45 -0400 Subject: [PATCH 3/4] fix: readme --- .github/workflows/test.yml | 3 --- README.md | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 899cdda..c47e4eb 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -23,9 +23,6 @@ jobs: version: nightly - name: Install Dependencies - uses: foundry-rs/foundry-toolchain@v1 - with: - version: nightly run: | forge soldeer install id: install diff --git a/README.md b/README.md index 72a15b5..e9c8ac4 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ Forge has native gas reporting with `forge snapshot` and `forge test --gas-repor # Installation ```solidity -soldeer install forge-gas-snapshot~v0.0.4 +forge soldeer install forge-gas-snapshot~v0.0.4 ``` - NOTE: foundry.toml must be updated to allow forge to write the snapshots From 0cc4cb9445cf10f855e26d0b1ed5b755e010307a Mon Sep 17 00:00:00 2001 From: Mark Toda Date: Wed, 28 Aug 2024 14:28:48 -0400 Subject: [PATCH 4/4] fix: snaps --- .forge-snapshots/manySstore.snap | 2 +- .forge-snapshots/singleSstore.snap | 2 +- .forge-snapshots/singleSstoreClosure.snap | 2 +- .forge-snapshots/singleSstoreLastCall.snap | 2 +- .forge-snapshots/sstoreClosure.snap | 2 +- test/GasSnapshot.t.sol | 12 ++++++------ 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/.forge-snapshots/manySstore.snap b/.forge-snapshots/manySstore.snap index 1fbb791..ef72e9b 100644 --- a/.forge-snapshots/manySstore.snap +++ b/.forge-snapshots/manySstore.snap @@ -1 +1 @@ -49284 \ No newline at end of file +70348 \ No newline at end of file diff --git a/.forge-snapshots/singleSstore.snap b/.forge-snapshots/singleSstore.snap index 80ecb46..d049b15 100644 --- a/.forge-snapshots/singleSstore.snap +++ b/.forge-snapshots/singleSstore.snap @@ -1 +1 @@ -27395 \ No newline at end of file +48459 \ No newline at end of file diff --git a/.forge-snapshots/singleSstoreClosure.snap b/.forge-snapshots/singleSstoreClosure.snap index 962f066..c59e906 100644 --- a/.forge-snapshots/singleSstoreClosure.snap +++ b/.forge-snapshots/singleSstoreClosure.snap @@ -1 +1 @@ -25205 \ No newline at end of file +46269 \ No newline at end of file diff --git a/.forge-snapshots/singleSstoreLastCall.snap b/.forge-snapshots/singleSstoreLastCall.snap index 97400eb..4c52430 100644 --- a/.forge-snapshots/singleSstoreLastCall.snap +++ b/.forge-snapshots/singleSstoreLastCall.snap @@ -1 +1 @@ -22365 \ No newline at end of file +43429 \ No newline at end of file diff --git a/.forge-snapshots/sstoreClosure.snap b/.forge-snapshots/sstoreClosure.snap index edc2416..5ed0938 100644 --- a/.forge-snapshots/sstoreClosure.snap +++ b/.forge-snapshots/sstoreClosure.snap @@ -1 +1 @@ -47094 \ No newline at end of file +68158 \ No newline at end of file diff --git a/test/GasSnapshot.t.sol b/test/GasSnapshot.t.sol index 5973a35..baeb3c7 100644 --- a/test/GasSnapshot.t.sol +++ b/test/GasSnapshot.t.sol @@ -26,7 +26,7 @@ contract GasSnapshotTest is Test, GasSnapshot { snapEnd(); string memory value = vm.readLine(".forge-snapshots/singleSstore.snap"); - assertEq(value, "27395"); + assertEq(value, "48459"); } function testSingleSstoreLastCall() public { @@ -35,21 +35,21 @@ contract GasSnapshotTest is Test, GasSnapshot { string memory value = vm.readLine(".forge-snapshots/singleSstoreLastCall.snap"); // includes 21,000 overhead for transaction, 20,000 clean SSTORE - assertEq(value, "22365"); + assertEq(value, "43429"); } function testSingleSstoreClosure() public { snap("singleSstoreClosure", simpleOperations.singleSstore); string memory value = vm.readLine(".forge-snapshots/singleSstoreClosure.snap"); - assertEq(value, "25205"); + assertEq(value, "46269"); } function testManySstoreClosure() public { snap("sstoreClosure", simpleOperations.manySstore); string memory value = vm.readLine(".forge-snapshots/sstoreClosure.snap"); - assertEq(value, "47094"); + assertEq(value, "68158"); } function testInternalClosure() public { @@ -96,7 +96,7 @@ contract GasSnapshotTest is Test, GasSnapshot { snapEnd(); string memory value = vm.readLine(".forge-snapshots/manySstore.snap"); - assertEq(value, "49284"); + assertEq(value, "70348"); } function testSnapshotCodeSize() public { @@ -132,7 +132,7 @@ contract GasSnapshotTest is Test, GasSnapshot { // preloaded with the wrong value snapStart("checkManySstore"); simpleOperations.manySstore(); - vm.expectRevert(abi.encodeWithSelector(GasSnapshot.GasMismatch.selector, 1, 52761)); + vm.expectRevert(abi.encodeWithSelector(GasSnapshot.GasMismatch.selector, 1, 73825)); snapEnd(); }