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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions newsfragments/1660.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added formatter rules for eth_tester middleware to allow :meth:`~web3.eth.Eth.getBalance` by using integer block numbers
wolovim marked this conversation as resolved.
Show resolved Hide resolved
9 changes: 9 additions & 0 deletions web3/_utils/module_testing/eth_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,15 @@ def test_eth_getBalance(self, web3: "Web3") -> None:
assert is_integer(balance)
assert balance >= 0

def test_eth_getBalance_with_block_identifier(self, web3: "Web3") -> None:
miner_address = web3.eth.getBlock(1)['miner']
genesis_balance = web3.eth.getBalance(miner_address, 0)
later_balance = web3.eth.getBalance(miner_address, 1)

assert is_integer(genesis_balance)
assert is_integer(later_balance)
assert later_balance > genesis_balance

def test_eth_getStorageAt(
self, web3: "Web3", emitter_contract_address: ChecksumAddress
) -> None:
Expand Down
4 changes: 4 additions & 0 deletions web3/providers/eth_tester/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,10 @@ def is_hexstr(value: Any) -> bool:
identity,
apply_formatter_if(is_not_named_block, to_integer_if_hex),
),
RPCEndpoint('eth_getBalance'): apply_formatters_to_args(
identity,
apply_formatter_if(is_not_named_block, to_integer_if_hex),
),
# EVM
RPCEndpoint('evm_revert'): apply_formatters_to_args(hex_to_integer),
# Personal
Expand Down
2 changes: 1 addition & 1 deletion web3/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
TValue = TypeVar("TValue")

BlockParams = Literal["latest", "earliest", "pending"]
BlockIdentifier = Union[BlockParams, BlockNumber, Hash32, HexStr, HexBytes]
BlockIdentifier = Union[BlockParams, BlockNumber, Hash32, HexStr, HexBytes, int]
LatestBlockParam = Literal["latest"]

FunctionIdentifier = Union[str, Type[FallbackFn], Type[ReceiveFn]]
Expand Down