Skip to content

Commit

Permalink
Add fork_block_number to launch_anvil
Browse files Browse the repository at this point in the history
  • Loading branch information
miohtama committed Oct 25, 2023
1 parent d9cfcf2 commit ad947b8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Current

- Add `launch_anvil(fork_block_number)` option

# 0.22.28

- More retryable JSON-RPC errors whitelisted. Now `ValueError: {'code': -32701, 'message': 'Please specify address in your request or, to remove restrictions, order a dedicated full node here: https://www.allnodes.com/bnb/host'}`.
Expand Down
11 changes: 10 additions & 1 deletion eth_defi/provider/anvil.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class RPCRequestError(Exception):
"port": "--port",
"host": "--host",
"fork": "--fork-url",
"fork_block": "--fork-block-number",
"fork_block_number": "--fork-block-number",
"hardfork": "--hardfork",
"chain_id": "--chain-id",
"default_balance": "--balance",
Expand Down Expand Up @@ -201,6 +201,7 @@ def launch_anvil(
gas_limit: Optional[int] = None,
steps_tracing=False,
test_request_timeout=3.0,
fork_block_number: Optional[int] = None,
) -> AnvilLaunch:
"""Creates Anvil unit test backend or mainnet fork.
Expand Down Expand Up @@ -361,6 +362,11 @@ def test_anvil_fork_transfer_busd(web3: Web3, large_busd_holder: HexAddress, use
:param test_request_timeout:
Set the timeout fro the JSON-RPC requests that attempt to determine if Anvil was successfully launched.
:param fork_block_number:
For at a specific block height of the parent chain.
If not given, fork at the latest block.
Needs an archive node to work.
"""

attempts_left = attempts
Expand Down Expand Up @@ -390,6 +396,9 @@ def test_anvil_fork_transfer_busd(web3: Web3, large_busd_holder: HexAddress, use
steps_tracing=steps_tracing,
)

if fork_block_number:
args["fork_block_number"] = fork_block_number

if block_time not in (0, None):
assert block_time > 0, f"Got bad block time {block_time}"
args["block_time"] = block_time
Expand Down

0 comments on commit ad947b8

Please sign in to comment.