fubuloubu / pytest-ethereum-old

py.test plugin for testing Ethereum smart contracts
MIT License
20 stars 1 forks source link

Implement zero gas price strategy #8

Closed fubuloubu closed 6 years ago

fubuloubu commented 6 years ago

This is an idea @jacqueswww had that I think is really clever, there is no need (for testing purposes) for gas prices to be a thing in testing. In fact, it makes it EASIER since you can do things like this:

# Accounts 1 and 2 start out with the same balance
assert t.a[1].balance == t.a[2].balance
# Account 1 sends account 2 100 wei
t.a[1].send(t.a[2], 100)
# No extra gas fees taken out! We can do exact equivalencies!
assert t.a[2].balance - t.a[1].balance == 100

# Account 2 sends account 1 100 wei
t.a[2].send(t.a[1], 100)
# Back where we started! No gas payment considerations!
assert t.a[1].balance == t.a[2].balance

The code for this is really simple, check it out here: https://github.com/ethereum/vyper/blob/248c723288e84899908048efff4c3e0b12f0b3dc/tests/conftest.py#L105-L113

fubuloubu commented 6 years ago

Finished this here: https://github.com/fubuloubu/pytest-ethereum/blob/be38026aff093a991a540e08b381d664a2006a8f/pytest_ethereum/tester.py#L18-L21