-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy pathtest_poa.py
36 lines (29 loc) · 1.26 KB
/
test_poa.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import pytest
from web3.middleware import (
construct_fixture_middleware,
geth_poa_middleware,
)
# In the spec, a block with extra data longer than 32 bytes is invalid
def test_long_extra_data(web3):
return_block_with_long_extra_data = construct_fixture_middleware({
'eth_getBlockByNumber': {'extraData': '0x' + 'ff' * 33},
})
web3.middleware_stack.inject(return_block_with_long_extra_data, layer=0)
with pytest.raises(ValueError):
web3.eth.getBlock('latest')
def test_full_extra_data(web3):
return_block_with_long_extra_data = construct_fixture_middleware({
'eth_getBlockByNumber': {'extraData': '0x' + 'ff' * 32},
})
web3.middleware_stack.inject(return_block_with_long_extra_data, layer=0)
block = web3.eth.getBlock('latest')
assert block.extraData == b'\xff' * 32
def test_geth_proof_of_authority(web3):
return_block_with_long_extra_data = construct_fixture_middleware({
'eth_getBlockByNumber': {'extraData': '0x' + 'ff' * 33},
})
web3.middleware_stack.inject(geth_poa_middleware, layer=0)
web3.middleware_stack.inject(return_block_with_long_extra_data, layer=0)
block = web3.eth.getBlock('latest')
assert 'extraData' not in block
assert block.proofOfAuthorityData == b'\xff' * 33