ethereum / pytest-ethereum

MIT License
19 stars 12 forks source link

Proposal: Add Testing Environment class #10

Open fubuloubu opened 5 years ago

fubuloubu commented 5 years ago

This fixture would be the primary access point for test environment (tester) functionality, which might include:

fubuloubu commented 5 years ago

Being able to manipulate time easily would be nice. For example, let's say you have a contract that allows you to withdraw funds in 7 days (e.g. Plasma). You should be able to do this:

contract.deposit(transact={})
# Can't withdraw a deposit within 7 days
with tx_fails:
    contract.withdraw(transact={})
# Set time to 7 days, minus 1 block
tester.set_time(tester.now() + tester.utils.days(7) - 15)
with tx_fails:
    contract.withdraw(transact={})
# Each block is 15 seconds
tester.mine()
# Now I can withdraw!
contract.withdraw(transact={})