Skip to content
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/2064.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix bug in geth PoA middleware where a ``None`` response should throw a ``BlockNotFound`` error, but was instead throwing an ``AttributeError``
11 changes: 11 additions & 0 deletions tests/core/eth-module/test_poa.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import pytest

from web3.exceptions import (
BlockNotFound,
ExtraDataLengthError,
)
from web3.middleware import (
Expand Down Expand Up @@ -37,3 +38,13 @@ def test_geth_proof_of_authority(web3):
block = web3.eth.get_block('latest')
assert 'extraData' not in block
assert block.proofOfAuthorityData == b'\xff' * 33


def test_returns_none_response(web3):
return_none_response = construct_fixture_middleware({
'eth_getBlockByNumber': None,
})
web3.middleware_onion.inject(geth_poa_middleware, layer=0)
web3.middleware_onion.inject(return_none_response, layer=0)
with pytest.raises(BlockNotFound):
web3.eth.get_block(100000000000)
15 changes: 10 additions & 5 deletions web3/middleware/geth_poa.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
from eth_utils.curried import (
apply_formatter_if,
apply_formatters_to_dict,
apply_key_map,
is_null,
)
from eth_utils.toolz import (
complement,
compose,
)
from hexbytes import (
HexBytes,
)

from web3._utils.rpc_abi import (
RPC,
)
from web3.middleware.formatting import (
construct_formatting_middleware,
)
from web3.types import (
RPCEndpoint,
)

is_not_null = complement(is_null)

remap_geth_poa_fields = apply_key_map({
'extraData': 'proofOfAuthorityData',
Expand All @@ -28,7 +33,7 @@

geth_poa_middleware = construct_formatting_middleware(
result_formatters={
RPCEndpoint("eth_getBlockByHash"): geth_poa_cleanup,
RPCEndpoint("eth_getBlockByNumber"): geth_poa_cleanup,
RPC.eth_getBlockByHash: apply_formatter_if(is_not_null, geth_poa_cleanup),
RPC.eth_getBlockByNumber: apply_formatter_if(is_not_null, geth_poa_cleanup),
},
)