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 shanghai TSTORE test #51

Merged
merged 2 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
8 changes: 8 additions & 0 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,14 @@ script = 'offerers'

[profile.tstorish]
test = 'tstorish'
evm_version = 'cancun'

[profile.tstorishLegacy]
src = 'tstorishLegacy'
test = 'tstorishLegacy'
out = 'tstorishLegacy-out'
script = 'tstorishLegacy'
evm_version = 'shanghai'

[fmt]
line_length = 80
Expand Down
29 changes: 21 additions & 8 deletions tstorish.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# exit on any failure
set -e
# remove old dump
rm -f seaport.dump
# spin up anvil and prepare to dump state
Expand All @@ -8,22 +10,33 @@ pid=$!
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')
# execute first Tstorish test
FOUNDRY_PROFILE=tstorishLegacy forge test --match-test test_preActivate -vvvv --fork-url http://localhost:8545 --evm-version shanghai
# exit anvil
echo $seaport
kill $pid
if kill -0 $pid 2>/dev/null; then
kill $pid
echo ">>> Shutting down shanghai anvil"
else
echo ">>> Unable to locate shanghai anvil PID"
fi
anvil --hardfork shanghai &
# save pid to kill later
pid=$!
# wait for anvil to warm up
sleep 5
sleep 1
# 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
curl -sX 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
# execute second Tstorish test
FOUNDRY_PROFILE=tstorish forge test --match-test test_activate -vvvv --fork-url http://localhost:8545 --evm-version cancun
# get exit code of previous
exit_code=$?
# kill anvil
kill $pid
# exit anvil
if kill -0 $pid 2>/dev/null; then
kill $pid
echo ">>> Shutting down cancun anvil"
else
echo ">>> Unable to locate cancun anvil PID"
fi
# exit with exit code of previous
exit $exit_code
7 changes: 6 additions & 1 deletion tstorish/Tstorish.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,17 @@ contract TstorishTest is Test {
);
}

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

assertEq(
address(0xCafac3dD18aC6c6e92c921884f9E4176737C052c).codehash,
keccak256(hex"3d5c")
);

// first call updates storage
vm.record();
seaport.__activateTstore();
Expand Down
31 changes: 31 additions & 0 deletions tstorishLegacy/TstorishLegacy.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;

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

interface SeaportReentrancyGuard {
function __activateTstore() external;

error TStoreNotSupported();
}

contract TstorishLegacyTest is Test {
SeaportReentrancyGuard seaport;

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

function test_preActivate() public {
assertEq(
address(0xCafac3dD18aC6c6e92c921884f9E4176737C052c).codehash,
keccak256(hex"3d5c")
);

vm.expectRevert(SeaportReentrancyGuard.TStoreNotSupported.selector);
seaport.__activateTstore();
}
}
Loading