ethereum / pytest-ethereum

MIT License
19 stars 12 forks source link

Simplified "happy path" API #32

Open njgheorghita opened 5 years ago

njgheorghita commented 5 years ago

Feature Request

What was wrong?

From #25 . . . @carver @pipermerriam

A simplified "happy path" API that simply assumes that everything will go well, and raises an exception when it doesn't. eg~ prefer something like receipt = ethtest.mine_txn(txn) over txn_hash = w3.eth.sendTransaction(txn); receipt = w3.eth.waitForTransactionReceipt(txn_hash).

How can it be fixed?

Suggestion - A simple wrapper function that takes a built transaction, sends it on a given w3 instance, and returns the transaction receipt. Raises a TransactionError if tx fails.

import pytest_ethereum as pte
receipt = pte.mine_txn(built_transaction, w3)
pipermerriam commented 5 years ago

Maybe something like:

from pytest_ethereum import pte
chain = pte.Chain(w3)
receipt = chain.transact(...)

Where transact has some API accepting transactions in a format that's "easy" for users. The Chain object could then be the place where we expose other convenience APIs like:

>>> account = chain.Account('0x...')
>>> account.balance
1234
carver commented 5 years ago

Where transact has some API accepting transactions in a format that's "easy" for users.

One option is something we've been talking about for web3: chain.transact(sender=..., to=..., gas=...).

njgheorghita commented 5 years ago

If y'all are up for it, it'd be helpful to schedule a short call and discuss/whiteboard the general api we're aiming for, and the lines between pte/web3. (though, with xmas break coming up soon, i'm also down to punt till early january when i'm fresh and less likely to forget everything we talk about/decide on over break)

pipermerriam commented 5 years ago

punt till early january when i'm fresh and less likely to forget everything we talk about/decide on over break

:+1:

Maybe just toss a calendar invite our way?