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.66k stars 551 forks source link

Fork mode as a context manager #746

Open iamdefinitelyahuman opened 4 years ago

iamdefinitelyahuman commented 4 years ago

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:

with brownie.forked:
    scary_transactions()

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.

BlinkyStitt commented 3 years ago

Anyone put any more thoughts into this? This would be really handy for testing transactions before sending them to mainnet.

BlinkyStitt commented 3 years ago

I'm trying some things