18
18
from test_framework .messages import (
19
19
CBlock ,
20
20
CBlockHeader ,
21
- BLOCK_HEADER_SIZE
22
- )
23
- from test_framework .mininode import (
24
- P2PDataStore ,
21
+ BLOCK_HEADER_SIZE ,
25
22
)
23
+ from test_framework .mininode import P2PDataStore
26
24
from test_framework .test_framework import BitcoinTestFramework
27
25
from test_framework .util import (
28
26
assert_equal ,
29
27
assert_raises_rpc_error ,
30
28
connect_nodes ,
31
29
)
32
30
31
+
33
32
def assert_template (node , block , expect , rehash = True ):
34
33
if rehash :
35
34
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
+ })
37
40
assert_equal (rsp , expect )
38
41
39
42
@@ -85,7 +88,7 @@ def assert_submitblock(block, result_str_1, result_str_2=None):
85
88
next_height = int (tmpl ["height" ])
86
89
coinbase_tx = create_coinbase (height = next_height )
87
90
# 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
89
92
coinbase_tx .rehash ()
90
93
91
94
# round-trip the encoded bip34 block height commitment
@@ -116,7 +119,11 @@ def assert_submitblock(block, result_str_1, result_str_2=None):
116
119
assert_raises_rpc_error (- 22 , "Block does not start with a coinbase" , node .submitblock , bad_block .serialize ().hex ())
117
120
118
121
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' ]})
122
+ assert_raises_rpc_error (- 22 , "Block decode failed" , node .getblocktemplate , {
123
+ 'data' : block .serialize ()[:- 1 ].hex (),
124
+ 'mode' : 'proposal' ,
125
+ 'rules' : ['segwit' ],
126
+ })
120
127
121
128
self .log .info ("getblocktemplate: Test duplicate transaction" )
122
129
bad_block = copy .deepcopy (block )
@@ -135,7 +142,7 @@ def assert_submitblock(block, result_str_1, result_str_2=None):
135
142
136
143
self .log .info ("getblocktemplate: Test nonfinal transaction" )
137
144
bad_block = copy .deepcopy (block )
138
- bad_block .vtx [0 ].nLockTime = 2 ** 32 - 1
145
+ bad_block .vtx [0 ].nLockTime = 2 ** 32 - 1
139
146
bad_block .vtx [0 ].rehash ()
140
147
assert_template (node , bad_block , 'bad-txns-nonfinal' )
141
148
assert_submitblock (bad_block , 'bad-txns-nonfinal' )
@@ -145,7 +152,11 @@ def assert_submitblock(block, result_str_1, result_str_2=None):
145
152
bad_block_sn = bytearray (block .serialize ())
146
153
assert_equal (bad_block_sn [BLOCK_HEADER_SIZE ], 1 )
147
154
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' ]})
155
+ assert_raises_rpc_error (- 22 , "Block decode failed" , node .getblocktemplate , {
156
+ 'data' : bad_block_sn .hex (),
157
+ 'mode' : 'proposal' ,
158
+ 'rules' : ['segwit' ],
159
+ })
149
160
150
161
self .log .info ("getblocktemplate: Test bad bits" )
151
162
bad_block = copy .deepcopy (block )
@@ -160,7 +171,7 @@ def assert_submitblock(block, result_str_1, result_str_2=None):
160
171
161
172
self .log .info ("getblocktemplate: Test bad timestamps" )
162
173
bad_block = copy .deepcopy (block )
163
- bad_block .nTime = 2 ** 31 - 1
174
+ bad_block .nTime = 2 ** 31 - 1
164
175
assert_template (node , bad_block , 'time-too-new' )
165
176
assert_submitblock (bad_block , 'time-too-new' , 'time-too-new' )
166
177
bad_block .nTime = 0
0 commit comments