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 tstorish test script #46

Merged
merged 8 commits into from
Mar 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
21 changes: 12 additions & 9 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ remappings = [
'seaport-types/=src/types/',
'seaport-core/src/=src/core/',
'seaport-core/=src/core/',
'seaport/=src/main/'
'seaport/=src/main/',
]
optimizer_runs = 4_294_967_295
fs_permissions = [
Expand All @@ -28,7 +28,7 @@ fs_permissions = [
{ access = "write", path = "./call-metrics.txt" },
{ access = "write", path = "./mutation-metrics.txt" },
{ access = "write", path = "./assume-metrics.txt" },
{ access = "write", path = "./fuzz_debug.json" }
{ access = "write", path = "./fuzz_debug.json" },
]

[profile.validator]
Expand All @@ -47,7 +47,7 @@ out = 'reference-out'
script = 'reference'
# specify something so it doesn't try to compile the files in test/foundry
test = 'test/foundry'
cache_path='reference-cache'
cache_path = 'reference-cache'

[profile.optimized]
src = 'src'
Expand All @@ -57,14 +57,14 @@ out = 'optimized-out'
script = 'script'
bytecode_hash = 'none'
# no need to compile tests with via-ir since they load optimized bytecode directly by default
test ='src/main'
test = 'src/main'
evm_version = 'cancun'
cache_path='optimized-cache'
extra_output_files=['irOptimized']
cache_path = 'optimized-cache'
extra_output_files = ['irOptimized']

[profile.test]
src = 'test/foundry'
cache_path='test-cache'
cache_path = 'test-cache'

[profile.test.fuzz]
runs = 1_000
Expand All @@ -81,11 +81,14 @@ optimizer = false
test = 'test/foundry/new'

[profile.offerers]
src='offerers'
test='offerers'
src = 'offerers'
test = 'offerers'
out = 'offerers-out'
script = 'offerers'

[profile.tstorish]
test = 'tstorish'

[fmt]
line_length = 80
tab_width = 4
Expand Down
17 changes: 17 additions & 0 deletions script/TstorishDeploy.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;

import { Script, console2 } from "forge-std/Script.sol";
import { ConduitController } from
"seaport-core/src/conduit/ConduitController.sol";
import { Consideration } from "seaport-core/src/lib/Consideration.sol";

contract TstorishDeploy is Script {
function run() public {
vm.broadcast();
ConduitController controller = new ConduitController();
vm.label(address(controller), "controller");
vm.broadcast();
Consideration seaport = new Consideration(address(controller));
}
}
29 changes: 29 additions & 0 deletions tstorish.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# remove old dump
rm -f seaport.dump
# spin up anvil and prepare to dump state
anvil --hardfork shanghai --dump-state ./seaport.dump &
# save pid to kill later
pid=$!
# execute foundry script to deploy seaport
FOUNDRY_PROFILE=optimized forge script TstorishDeploy --rpc-url http://localhost:8545 --slow --skip-simulation --broadcast --private-key 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
# get code of 0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512
seaport=$(curl -sX POST --data '{"jsonrpc":"2.0","method":"eth_getCode","params":["0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512", "latest"],"id":1}' -H "Content-Type: application/json" http://localhost:8545 | jq '.result')
# exit anvil
echo $seaport
kill $pid
anvil --hardfork shanghai &
# save pid to kill later
pid=$!
# wait for anvil to warm up
sleep 5
# call setCode on the 0xe7f address with the $seaport var
curl -X POST --data '{"jsonrpc":"2.0","method":"anvil_setCode","params":["0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512", '"$seaport"'],"id":1}' -H "Content-Type: application/json" http://localhost:8545
# mine a block
# execute Tstorish test
FOUNDRY_PROFILE=tstorish forge test -vvvv --fork-url http://localhost:8545
# get exit code of previous
exit_code=$?
# kill anvil
kill $pid
# exit with exit code of previous
exit $exit_code
39 changes: 39 additions & 0 deletions tstorish/Tstorish.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;

import { Test } from "forge-std/Test.sol";

import {
ReentrancyGuard,
ReentrancyErrors
} from "seaport-core/src/lib/ReentrancyGuard.sol";

contract TstorishTest is Test {
ReentrancyGuard seaport;

function setUp() public {
seaport = ReentrancyGuard(
payable(
// second contract deployed by first anvil pk
0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512
)
);
}

function testActivate() public {
vm.etch(
0xCafac3dD18aC6c6e92c921884f9E4176737C052c,
hex"3d5c"
);

// first call updates storage
vm.record();
seaport.__activateTstore();
(bytes32[] memory reads, bytes32[] memory writes) =
vm.accesses(address(seaport));
assertEq(writes.length, 1);
// second call reverts
vm.expectRevert(ReentrancyErrors.TStoreAlreadyActivated.selector);
seaport.__activateTstore();
}
}
Loading