1818from test_framework .messages import (
1919 CBlock ,
2020 CBlockHeader ,
21- BLOCK_HEADER_SIZE
22- )
23- from test_framework .mininode import (
24- P2PDataStore ,
21+ BLOCK_HEADER_SIZE ,
2522)
23+ from test_framework .mininode import P2PDataStore
2624from test_framework .test_framework import BitcoinTestFramework
2725from test_framework .util import (
2826 assert_equal ,
2927 assert_raises_rpc_error ,
3028 connect_nodes ,
3129)
3230
31+
3332def assert_template (node , block , expect , rehash = True ):
3433 if rehash :
3534 block .hashMerkleRoot = block .calc_merkle_root ()
36- rsp = node .getblocktemplate (template_request = {'data' : block .serialize ().hex (), 'mode' : 'proposal' , 'rules' : ['segwit' ]})
35+ rsp = node .getblocktemplate (template_request = {
36+ 'data' : block .serialize ().hex (),
37+ 'mode' : 'proposal' ,
38+ 'rules' : ['segwit' ],
39+ })
3740 assert_equal (rsp , expect )
3841
3942
@@ -85,10 +88,9 @@ def assert_submitblock(block, result_str_1, result_str_2=None):
8588 next_height = int (tmpl ["height" ])
8689 coinbase_tx = create_coinbase (height = next_height )
8790 # sequence numbers must not be max for nLockTime to have effect
88- coinbase_tx .vin [0 ].nSequence = 2 ** 32 - 2
91+ coinbase_tx .vin [0 ].nSequence = 2 ** 32 - 2
8992 coinbase_tx .rehash ()
9093
91- # round-trip the encoded bip34 block height commitment
9294 block = CBlock ()
9395 block .nVersion = tmpl ["version" ]
9496 block .hashPrevBlock = int (tmpl ["previousblockhash" ], 16 )
@@ -116,7 +118,11 @@ def assert_submitblock(block, result_str_1, result_str_2=None):
116118 assert_raises_rpc_error (- 22 , "Block does not start with a coinbase" , node .submitblock , bad_block .serialize ().hex ())
117119
118120 self .log .info ("getblocktemplate: Test truncated final transaction" )
119- assert_raises_rpc_error (- 22 , "Block decode failed" , node .getblocktemplate , {'data' : block .serialize ()[:- 1 ].hex (), 'mode' : 'proposal' , 'rules' : ['segwit' ]})
121+ assert_raises_rpc_error (- 22 , "Block decode failed" , node .getblocktemplate , {
122+ 'data' : block .serialize ()[:- 1 ].hex (),
123+ 'mode' : 'proposal' ,
124+ 'rules' : ['segwit' ],
125+ })
120126
121127 self .log .info ("getblocktemplate: Test duplicate transaction" )
122128 bad_block = copy .deepcopy (block )
@@ -135,7 +141,7 @@ def assert_submitblock(block, result_str_1, result_str_2=None):
135141
136142 self .log .info ("getblocktemplate: Test nonfinal transaction" )
137143 bad_block = copy .deepcopy (block )
138- bad_block .vtx [0 ].nLockTime = 2 ** 32 - 1
144+ bad_block .vtx [0 ].nLockTime = 2 ** 32 - 1
139145 bad_block .vtx [0 ].rehash ()
140146 assert_template (node , bad_block , 'bad-txns-nonfinal' )
141147 assert_submitblock (bad_block , 'bad-txns-nonfinal' )
@@ -145,7 +151,11 @@ def assert_submitblock(block, result_str_1, result_str_2=None):
145151 bad_block_sn = bytearray (block .serialize ())
146152 assert_equal (bad_block_sn [BLOCK_HEADER_SIZE ], 1 )
147153 bad_block_sn [BLOCK_HEADER_SIZE ] += 1
148- assert_raises_rpc_error (- 22 , "Block decode failed" , node .getblocktemplate , {'data' : bad_block_sn .hex (), 'mode' : 'proposal' , 'rules' : ['segwit' ]})
154+ assert_raises_rpc_error (- 22 , "Block decode failed" , node .getblocktemplate , {
155+ 'data' : bad_block_sn .hex (),
156+ 'mode' : 'proposal' ,
157+ 'rules' : ['segwit' ],
158+ })
149159
150160 self .log .info ("getblocktemplate: Test bad bits" )
151161 bad_block = copy .deepcopy (block )
@@ -160,7 +170,7 @@ def assert_submitblock(block, result_str_1, result_str_2=None):
160170
161171 self .log .info ("getblocktemplate: Test bad timestamps" )
162172 bad_block = copy .deepcopy (block )
163- bad_block .nTime = 2 ** 31 - 1
173+ bad_block .nTime = 2 ** 31 - 1
164174 assert_template (node , bad_block , 'time-too-new' )
165175 assert_submitblock (bad_block , 'time-too-new' , 'time-too-new' )
166176 bad_block .nTime = 0
0 commit comments