The fewer magic numbers the better.
Also more directly tested a submitheader case of bad previous blockhash.
The fewer magic numbers the better.
Also more directly tested a submitheader case of bad previous blockhash.
163 | @@ -164,9 +164,9 @@ def assert_submitblock(block, result_str_1, result_str_2=None): 164 | assert_submitblock(bad_block, 'prev-blk-not-found', 'prev-blk-not-found') 165 | 166 | self.log.info('submitheader tests') 167 | - assert_raises_rpc_error(-22, 'Block header decode failed', lambda: node.submitheader(hexdata='xx' * 80)) 168 | - assert_raises_rpc_error(-22, 'Block header decode failed', lambda: node.submitheader(hexdata='ff' * 78)) 169 | - assert_raises_rpc_error(-25, 'Must submit previous header', lambda: node.submitheader(hexdata='ff' * 80)) 170 | + assert_raises_rpc_error(-22, 'Block header decode failed', lambda: node.submitheader(hexdata='xx' * BLOCK_HEADER_SIZE)) 171 | + assert_raises_rpc_error(-22, 'Block header decode failed', lambda: node.submitheader(hexdata='ff' * (BLOCK_HEADER_SIZE-2))) 172 | + assert_raises_rpc_error(-25, 'Must submit previous header', lambda: node.submitheader(hexdata=super(CBlock, bad_block).serialize().hex()))
I'm not sure I follow here: which constructor is it that takes CBlock and bad_block as parameters?
The base class is CBlockHeader, so we're accessing its serialization function.
Maybe rename bad_block above to bad_hashPrevBlock_block or similar, and invoke the CBlockHeader constructor directly?
Currentry, minimum required version of Python (test) is 3.4. https://github.com/bitcoin/bitcoin/blob/master/doc/dependencies.md
But hex() seems to be introdued in Python 3.5. https://docs.python.org/3.5/library/stdtypes.html?highlight=bytes%20hex#bytes.hex
I got following error when executing this test on Python3.4.
AttributeError: 'bytes' object has no attribute 'hex'
212 | @@ -211,28 +213,30 @@ def run_test(self): 213 | self.test_rest_request('/block/{}'.format(bb_hash)) 214 | self.nodes[0].reconsiderblock(bb_hash) 215 | 216 | + BLOCK_HEADER_SIZE = len(CBlockHeader().serialize())
As this constant is used in multiple places, wouldn't it be an idea to define it in a shared place?
Done, defined right after CBlockHeader is defined
(and added an assert right after for the invariant of 80)
utACK b651ef7e1c39a820089695b29d14a07d910a385a
14 | @@ -15,6 +15,7 @@ 15 | from test_framework.messages import ( 16 | CBlock, 17 | CBlockHeader, 18 | + BLOCK_HEADER_SIZE
style-nit: Missing trailing , :eyes: