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

use cast rpc anvil_mine to advance chain #53

Merged
merged 1 commit into from
May 7, 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
9 changes: 0 additions & 9 deletions contracts/script/utils/Utils.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 2 additions & 4 deletions tests/anvil/start-anvil-chain-with-el-and-avs-deployed.sh
Original file line number Diff line number Diff line change
@@ -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=$(
Expand Down Expand Up @@ -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
5 changes: 2 additions & 3 deletions tests/integration/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Loading