Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed error when accessing blocks by blocknumber using eth_tester #1660

Merged
merged 6 commits into from
Jun 9, 2020
Merged

fixed error when accessing blocks by blocknumber using eth_tester #1660

merged 6 commits into from
Jun 9, 2020

Conversation

MatthiasLohr
Copy link
Contributor

What was wrong?

When accessing a block by its block number using eth_tester, e.g. 3, the following error occured:

Block number must be a positive integer or one of the strings 'latest', 'earliest', or 'pending'. Got: 0x3

How was it fixed?

With this pull request, the ethereum_tester_middleware is extended by typing instructions for eth_getBalance.

Cute Animal Picture

Too tired for searching for a cat picture. Meow.

Copy link
Member

@pipermerriam pipermerriam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to have a test added for this as well.

@carver
Copy link
Collaborator

carver commented May 26, 2020

For reference:

def test_eth_getCode_with_block_identifier(
self, web3: "Web3", emitter_contract: "Contract"
) -> None:
code = web3.eth.getCode(emitter_contract.address, block_identifier=web3.eth.blockNumber)
assert isinstance(code, HexBytes)
assert len(code) > 0

Something like that, but with balance. I'd try to go one step further and say that you can verify that the balances are different on different blocks.

Notice that coinbase has a balance at the latest block:

balance = web3.eth.getBalance(coinbase)
assert is_integer(balance)
assert balance >= 0

It seems a good bet that that balance is lower at the genesis block. See if you can verify that in a test. I'd highly recommend reverting the implementation commit, then writing the test and confirming that it fails. (In tox -e py36-integration-ethtester)

@wolovim
Copy link
Member

wolovim commented Jun 5, 2020

@carver the genesis balance vs. later balance idea is a no-go in at least one case:

(Pdb++) web3.eth.getBalance(coinbase)
1000000000000000000000000
(Pdb++) web3.eth.blockNumber
0

however, testing of Literal(0) is enough to demonstrate that without the fix, an error is thrown:

ValidationError: Block number must be a positive integer or one of the strings 'latest', 'earliest', or 'pending'.  Got: 0x0

@carver
Copy link
Collaborator

carver commented Jun 8, 2020

genesis balance vs. later balance idea is a no-go in at least one case:

Sure, you would need to mine a block before that idea would work.

@wolovim wolovim requested a review from carver June 9, 2020 18:03
Copy link
Collaborator

@carver carver left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, LGTM! :shipit:

@wolovim wolovim merged commit 587d673 into ethereum:master Jun 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants