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,10 +88,9 @@ 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
- # round-trip the encoded bip34 block height commitment
92
94
block = CBlock ()
93
95
block .nVersion = tmpl ["version" ]
94
96
block .hashPrevBlock = int (tmpl ["previousblockhash" ], 16 )
@@ -116,7 +118,11 @@ def assert_submitblock(block, result_str_1, result_str_2=None):
116
118
assert_raises_rpc_error (- 22 , "Block does not start with a coinbase" , node .submitblock , bad_block .serialize ().hex ())
117
119
118
120
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
+ })
120
126
121
127
self .log .info ("getblocktemplate: Test duplicate transaction" )
122
128
bad_block = copy .deepcopy (block )
@@ -135,7 +141,7 @@ def assert_submitblock(block, result_str_1, result_str_2=None):
135
141
136
142
self .log .info ("getblocktemplate: Test nonfinal transaction" )
137
143
bad_block = copy .deepcopy (block )
138
- bad_block .vtx [0 ].nLockTime = 2 ** 32 - 1
144
+ bad_block .vtx [0 ].nLockTime = 2 ** 32 - 1
139
145
bad_block .vtx [0 ].rehash ()
140
146
assert_template (node , bad_block , 'bad-txns-nonfinal' )
141
147
assert_submitblock (bad_block , 'bad-txns-nonfinal' )
@@ -145,7 +151,11 @@ def assert_submitblock(block, result_str_1, result_str_2=None):
145
151
bad_block_sn = bytearray (block .serialize ())
146
152
assert_equal (bad_block_sn [BLOCK_HEADER_SIZE ], 1 )
147
153
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
+ })
149
159
150
160
self .log .info ("getblocktemplate: Test bad bits" )
151
161
bad_block = copy .deepcopy (block )
@@ -160,7 +170,7 @@ def assert_submitblock(block, result_str_1, result_str_2=None):
160
170
161
171
self .log .info ("getblocktemplate: Test bad timestamps" )
162
172
bad_block = copy .deepcopy (block )
163
- bad_block .nTime = 2 ** 31 - 1
173
+ bad_block .nTime = 2 ** 31 - 1
164
174
assert_template (node , bad_block , 'time-too-new' )
165
175
assert_submitblock (bad_block , 'time-too-new' , 'time-too-new' )
166
176
bad_block .nTime = 0
0 commit comments