eth-brownie / brownie

A Python-based development and testing framework for smart contracts targeting the Ethereum Virtual Machine.
https://eth-brownie.readthedocs.io
MIT License
2.64k stars 553 forks source link

Allow specify block to fork at for "mainnet-fork" #790

Open yanncks opened 4 years ago

yanncks commented 4 years ago

Ganache supports specifying the block to fork at: -f or --fork: Fork from another currently running Ethereum client at a given block. Input should be the HTTP location and port of the other client, e.g. http://localhost:8545. You can optionally specify the block to fork from using an @ sign: http://localhost:8545@1599200.

Would it be possible to surface this as a config or CLI option in brownie?

yanncks commented 4 years ago

alternatively, it isn't clear from these docs how to revert state to a specific block https://eth-brownie.readthedocs.io/en/stable/core-chain.html?highlight=time%20travel#time-travel. is that possible?

iamdefinitelyahuman commented 4 years ago

Should be possible, as a setting or cli flag, yes. Since most users don't have an archive node and thus are limited to the most recent 128 blocks, I figured there wouldn't be much demand. But it's not that hard to expose.

For time travel it isn't as easy. Ganache lets you declare a height when you launch, but you can't adjust that value once it's already running. So you can only ever go back in time as far as the initial height that you forked at.

yanncks commented 4 years ago

Oh I see. When using Infura, does that give you access to an archive node?

iamdefinitelyahuman commented 4 years ago

Unfortunately not.

lmittmann commented 3 years ago

Any update on exposing the fork block?

michaelbnewman commented 3 years ago

I found a temporary solution is to run mainnet forking with hardhat at a specific block number I'm interested in, then connect brownie to that hardhat localhost RPC. Very handy for looking at internal transfers.

0xalfalfa commented 3 years ago

Here's my workaround:

gosuto-inzasheru commented 3 years ago

i like that work-around @0xalfalfa! i was thinking something similar but with some bash magic and run it through brownie run.

a proper implementation doesn't seem far away though, after finding out that ganache-cli already has the parameter --fork_block_number: https://github.com/trufflesuite/ganache/blob/master/README.md#options.

appears to me it only needs to be supported by the cmd-settings part of the app that passes args to ganache? eg brownie run --network mainnet-fork --fork_block_number 13131313.

dont know if i am the one to tackle this, but if anyone could give pointers on where to look in the code in order to prep a pr that would be cool :-) initial thought is to start by adding the cli flag here: https://github.com/eth-brownie/brownie/blob/master/brownie/network/rpc/ganache.py