From 65a40a2eea2acb0c81234f925e88799d5008cbae Mon Sep 17 00:00:00 2001 From: Jordan Hagan Date: Fri, 1 Dec 2023 10:45:02 +1100 Subject: [PATCH 1/5] add Storage test --- DEVELOPING.md | 37 +++++++++++++++++++++++++++++++ test/Storage.t.sol | 55 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 92 insertions(+) create mode 100644 DEVELOPING.md create mode 100644 test/Storage.t.sol diff --git a/DEVELOPING.md b/DEVELOPING.md new file mode 100644 index 00000000..9467f88e --- /dev/null +++ b/DEVELOPING.md @@ -0,0 +1,37 @@ +# Environment Setup + +You will need to make sure you have these packages installed: + +* foundry + +The you need to ensure your environment has these variables set: + +``` +MAINNET_RPC_URL= +``` + + +# Project Initialization + +``` +foundryup +``` + +# Running a build + +``` +forge build +``` + +# Running the tests + +``` +forge test +``` + +# Generating a coverage report + +``` +forge coverage --ir-minimum --report lcov +``` + diff --git a/test/Storage.t.sol b/test/Storage.t.sol new file mode 100644 index 00000000..7a403802 --- /dev/null +++ b/test/Storage.t.sol @@ -0,0 +1,55 @@ +// SPDX-License-Identifier: MIT +pragma solidity 0.8.21; + +import "forge-std/Test.sol"; + +import { Storage } from "src/contracts/atlas/Storage.sol"; + +using stdStorage for StdStorage; + + +contract StorageTest is Test { + function testNewStorage() public { + Storage s = new Storage( + 1, // _escrowDuration + address(1), // _factory + address(2), // _verification + address(3), // _gasAccLib + address(4), // _safetyLocksLib + address(5) // _simulator + ); + + assertEq(s.ESCROW_DURATION(), 1); + assertEq(s.FACTORY(), address(1)); + assertEq(s.VERIFICATION(), address(2)); + assertEq(s.GAS_ACC_LIB(), address(3)); + assertEq(s.SAFETY_LOCKS_LIB(), address(4)); + assertEq(s.SIMULATOR(), address(5)); + } + + function testStorageSlotsDontChange() public { + Storage s = new Storage( + 1, // _escrowDuration + address(1), // _factory + address(2), // _verification + address(3), // _gasAccLib + address(4), // _safetyLocksLib + address(5) // _simulator + ); + + // look up the storage slots so that we can make sure they don't change by accident + + uint256 totalSupplySlot = stdstore.target(address(s)).sig('totalSupply()').find(); + uint256 noncesSlot = stdstore.target(address(s)).sig('nonces(address)').with_key(address(this)).find(); + uint256 lockSlot = stdstore.target(address(s)).sig('lock()').find(); + + // TODO: figure out how to check the allowance and ledger slots, haven't been able to make these work yet + + // if you're getting an error from one of these assertions, it means that the storage slot has changed + // and you either need to update the slot number or revert the change + + assertEq(totalSupplySlot, 0); + assertEq(noncesSlot, 49784443915320261189887103614045882155521089248264299114442679287293484801912); + assertEq(lockSlot, 4); + } +} From 60a6f7e682a73a5bb2465e7a784ca57f5264cdac Mon Sep 17 00:00:00 2001 From: Jordan Hagan Date: Fri, 1 Dec 2023 10:49:44 +1100 Subject: [PATCH 2/5] fix lint errors --- test/Storage.t.sol | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/Storage.t.sol b/test/Storage.t.sol index 7a403802..e93a4434 100644 --- a/test/Storage.t.sol +++ b/test/Storage.t.sol @@ -39,9 +39,9 @@ contract StorageTest is Test { // look up the storage slots so that we can make sure they don't change by accident - uint256 totalSupplySlot = stdstore.target(address(s)).sig('totalSupply()').find(); - uint256 noncesSlot = stdstore.target(address(s)).sig('nonces(address)').with_key(address(this)).find(); - uint256 lockSlot = stdstore.target(address(s)).sig('lock()').find(); + uint256 totalSupplySlot = stdstore.target(address(s)).sig("totalSupply()").find(); + uint256 noncesSlot = stdstore.target(address(s)).sig("nonces(address)").with_key(address(this)).find(); + uint256 lockSlot = stdstore.target(address(s)).sig("lock()").find(); // TODO: figure out how to check the allowance and ledger slots, haven't been able to make these work yet @@ -49,7 +49,7 @@ contract StorageTest is Test { // and you either need to update the slot number or revert the change assertEq(totalSupplySlot, 0); - assertEq(noncesSlot, 49784443915320261189887103614045882155521089248264299114442679287293484801912); + assertEq(noncesSlot, 49_784_443_915_320_261_189_887_103_614_045_882_155_521_089_248_264_299_114_442_679_287_293_484_801_912); assertEq(lockSlot, 4); } } From ab05568a70506fbe8b5f231d5ab12ca191a9c2a0 Mon Sep 17 00:00:00 2001 From: Jordan Hagan Date: Fri, 1 Dec 2023 10:53:07 +1100 Subject: [PATCH 3/5] fix formatting again --- test/Storage.t.sol | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/test/Storage.t.sol b/test/Storage.t.sol index e93a4434..99f96c42 100644 --- a/test/Storage.t.sol +++ b/test/Storage.t.sol @@ -7,7 +7,6 @@ import { Storage } from "src/contracts/atlas/Storage.sol"; using stdStorage for StdStorage; - contract StorageTest is Test { function testNewStorage() public { Storage s = new Storage( @@ -38,7 +37,7 @@ contract StorageTest is Test { ); // look up the storage slots so that we can make sure they don't change by accident - + uint256 totalSupplySlot = stdstore.target(address(s)).sig("totalSupply()").find(); uint256 noncesSlot = stdstore.target(address(s)).sig("nonces(address)").with_key(address(this)).find(); uint256 lockSlot = stdstore.target(address(s)).sig("lock()").find(); @@ -49,7 +48,10 @@ contract StorageTest is Test { // and you either need to update the slot number or revert the change assertEq(totalSupplySlot, 0); - assertEq(noncesSlot, 49_784_443_915_320_261_189_887_103_614_045_882_155_521_089_248_264_299_114_442_679_287_293_484_801_912); + assertEq( + noncesSlot, + 49_784_443_915_320_261_189_887_103_614_045_882_155_521_089_248_264_299_114_442_679_287_293_484_801_912 + ); assertEq(lockSlot, 4); } } From 922963c98daee78ee133f79e86f0ccd505e714eb Mon Sep 17 00:00:00 2001 From: Jordan Hagan Date: Fri, 8 Dec 2023 11:53:34 +1100 Subject: [PATCH 4/5] Tested internal constructor variables --- test/Storage.t.sol | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/test/Storage.t.sol b/test/Storage.t.sol index 99f96c42..9f4989b4 100644 --- a/test/Storage.t.sol +++ b/test/Storage.t.sol @@ -9,7 +9,7 @@ using stdStorage for StdStorage; contract StorageTest is Test { function testNewStorage() public { - Storage s = new Storage( + MockStorageTests s = new MockStorageTests( 1, // _escrowDuration address(1), // _factory address(2), // _verification @@ -24,6 +24,8 @@ contract StorageTest is Test { assertEq(s.GAS_ACC_LIB(), address(3)); assertEq(s.SAFETY_LOCKS_LIB(), address(4)); assertEq(s.SIMULATOR(), address(5)); + assertEq(s.getInitialChainId(), block.chainid); + assertEq(s.getInitialDomainSeparator(), bytes32("SEPARATOR")); } function testStorageSlotsDontChange() public { @@ -55,3 +57,28 @@ contract StorageTest is Test { assertEq(lockSlot, 4); } } + +contract MockStorageTests is Storage { + constructor( + uint256 _escrowDuration, + address _factory, + address _verification, + address _gasAccLib, + address _safetyLocksLib, + address _simulator + ) + Storage(_escrowDuration, _factory, _verification, _gasAccLib, _safetyLocksLib, _simulator) + { } + + function getInitialChainId() public view returns (uint256) { + return INITIAL_CHAIN_ID; + } + + function getInitialDomainSeparator() public view returns (bytes32) { + return INITIAL_DOMAIN_SEPARATOR; + } + + function _computeDomainSeparator() override internal view virtual returns (bytes32) { + return bytes32("SEPARATOR"); + } +} From 548845bf3d6a3a83c9adfdc3de85891770c0020c Mon Sep 17 00:00:00 2001 From: Jordan Hagan Date: Fri, 8 Dec 2023 11:54:01 +1100 Subject: [PATCH 5/5] forge fmt --- test/Storage.t.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Storage.t.sol b/test/Storage.t.sol index 9f4989b4..f39257b2 100644 --- a/test/Storage.t.sol +++ b/test/Storage.t.sol @@ -78,7 +78,7 @@ contract MockStorageTests is Storage { return INITIAL_DOMAIN_SEPARATOR; } - function _computeDomainSeparator() override internal view virtual returns (bytes32) { + function _computeDomainSeparator() internal view virtual override returns (bytes32) { return bytes32("SEPARATOR"); } }