When using brownie in a live environment, it should be possible to temporarily enter into --fork via a context manager.
Specification
Add a context manager brownie.forked:
with brownie.forked:
scary_transactions()
Upon entering the context, ganache launches and forks against whatever live environment brownie is using. The active network shifts to fork mode, but all existing objects persist.
When the context exits, it cleans up by removing any TransactionReceipt or Contract objects, and correcting nonces and balances.
A kwarg can be included so that if no exception is raised during the context manager, the same transactions are then broadcasted on the mainnet. Bonus points if they're sent using required_confs=0.
A lot of the logic for this should already exist, I think it's possible with some minor modifications to chain.revert, chain.undo and chain.redo. The hardest part will be the idea of having an active network over top of another active network. I'm not sure if this is a feasible change without also breaking things - this might have to wait until v2.0.0. But it's worth exploring right away as the functionality would be very useful.
Overview
When using brownie in a live environment, it should be possible to temporarily enter into
--fork
via a context manager.Specification
Add a context manager
brownie.forked
:TransactionReceipt
orContract
objects, and correcting nonces and balances.required_confs=0
.A lot of the logic for this should already exist, I think it's possible with some minor modifications to
chain.revert
,chain.undo
andchain.redo
. The hardest part will be the idea of having an active network over top of another active network. I'm not sure if this is a feasible change without also breaking things - this might have to wait untilv2.0.0
. But it's worth exploring right away as the functionality would be very useful.