From a23262db23aef85e2a3b774d735ab38b696ed91f Mon Sep 17 00:00:00 2001 From: Samuel Laferriere Date: Tue, 7 May 2024 12:55:57 -0700 Subject: [PATCH] use cast rpc anvil_mine to advance chain --- contracts/script/utils/Utils.sol | 9 --------- .../anvil/start-anvil-chain-with-el-and-avs-deployed.sh | 6 ++---- tests/integration/integration_test.go | 5 ++--- 3 files changed, 4 insertions(+), 16 deletions(-) diff --git a/contracts/script/utils/Utils.sol b/contracts/script/utils/Utils.sol index 19320d99..9310c761 100644 --- a/contracts/script/utils/Utils.sol +++ b/contracts/script/utils/Utils.sol @@ -23,15 +23,6 @@ contract Utils is Script { } } - // TODO: this doesn't actually advance by n blocks... maybe because broadcasting batches txs somehow..? - function advanceChainByNBlocks(uint256 n) public { - for (uint256 i = 0; i < n; i++) { - // we transfer eth to ourselves to advance the block - vm.broadcast(msg.sender); - payable(msg.sender).transfer(1 wei); - } - } - function convertBoolToString( bool input ) public pure returns (string memory) { diff --git a/tests/anvil/start-anvil-chain-with-el-and-avs-deployed.sh b/tests/anvil/start-anvil-chain-with-el-and-avs-deployed.sh index fa4ce124..85033db4 100755 --- a/tests/anvil/start-anvil-chain-with-el-and-avs-deployed.sh +++ b/tests/anvil/start-anvil-chain-with-el-and-avs-deployed.sh @@ -1,7 +1,6 @@ #!/bin/bash RPC_URL=http://localhost:8545 -PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 # cd to the directory of this script so that this can be run from anywhere parent_path=$( @@ -36,9 +35,8 @@ cd ../../contracts # at which it was deployed (aka quorum was created/updated), but when we start anvil by loading state file it starts at block number 0 # so calling getOperatorListAtBlockNumber reverts because it thinks there are no quorums registered at block 0 # advancing chain manually like this is a current hack until https://github.com/foundry-rs/foundry/issues/6679 is merged -# also not that it doesn't really advance by the correct number of blocks.. not sure why, so we just forward by a bunch of blocks that should be enough -forge script script/utils/Utils.sol --sig "advanceChainByNBlocks(uint256)" 100 --rpc-url $RPC_URL --private-key $PRIVATE_KEY --broadcast -echo "current block-number:" $(cast block-number) +cast rpc anvil_mine 100 --rpc-url $RPC_URL +echo "advancing chain... current block-number:" $(cast block-number) # Bring Anvil back to the foreground docker attach anvil diff --git a/tests/integration/integration_test.go b/tests/integration/integration_test.go index 6c8f66d3..963cc173 100644 --- a/tests/integration/integration_test.go +++ b/tests/integration/integration_test.go @@ -229,11 +229,10 @@ func advanceChain(anvilC testcontainers.Container) { panic(err) } rpcUrl := "http://" + anvilEndpoint - privateKey := "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80" cmd := exec.Command("bash", "-c", fmt.Sprintf( - `forge script script/utils/Utils.sol --sig "advanceChainByNBlocks(uint256)" 100 --rpc-url %s --private-key %s --broadcast`, - rpcUrl, privateKey), + `cast rpc anvil_mine 100 --rpc-url %s`, + rpcUrl), ) cmd.Dir = "../../contracts" err = cmd.Run()