Skip to content

Commit

Permalink
Merge pull request #53 from Layr-Labs/fix-advance-chain-logic
Browse files Browse the repository at this point in the history
use cast rpc anvil_mine to advance chain
  • Loading branch information
samlaf authored May 7, 2024
2 parents 8bd0ac6 + a23262d commit ef349fb
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 16 deletions.
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

0 comments on commit ef349fb

Please sign in to comment.