@@ -41,6 +41,12 @@ def set_test_params(self):
41
41
def run_test (self ):
42
42
node = self .nodes [0 ]
43
43
44
+ def assert_submitblock (block , result_str_1 , result_str_2 = None ):
45
+ block .solve ()
46
+ result_str_2 = result_str_2 or 'duplicate-invalid'
47
+ assert_equal (result_str_1 , node .submitblock (hexdata = b2x (block .serialize ())))
48
+ assert_equal (result_str_2 , node .submitblock (hexdata = b2x (block .serialize ())))
49
+
44
50
self .log .info ('getmininginfo' )
45
51
mining_info = node .getmininginfo ()
46
52
assert_equal (mining_info ['blocks' ], 200 )
@@ -93,6 +99,7 @@ def run_test(self):
93
99
bad_block = copy .deepcopy (block )
94
100
bad_block .vtx .append (bad_block .vtx [0 ])
95
101
assert_template (node , bad_block , 'bad-txns-duplicate' )
102
+ assert_submitblock (bad_block , 'bad-txns-duplicate' , 'bad-txns-duplicate' )
96
103
97
104
self .log .info ("getblocktemplate: Test invalid transaction" )
98
105
bad_block = copy .deepcopy (block )
@@ -101,12 +108,14 @@ def run_test(self):
101
108
bad_tx .rehash ()
102
109
bad_block .vtx .append (bad_tx )
103
110
assert_template (node , bad_block , 'bad-txns-inputs-missingorspent' )
111
+ assert_submitblock (bad_block , 'bad-txns-inputs-missingorspent' )
104
112
105
113
self .log .info ("getblocktemplate: Test nonfinal transaction" )
106
114
bad_block = copy .deepcopy (block )
107
115
bad_block .vtx [0 ].nLockTime = 2 ** 32 - 1
108
116
bad_block .vtx [0 ].rehash ()
109
117
assert_template (node , bad_block , 'bad-txns-nonfinal' )
118
+ assert_submitblock (bad_block , 'bad-txns-nonfinal' )
110
119
111
120
self .log .info ("getblocktemplate: Test bad tx count" )
112
121
# The tx count is immediately after the block header
@@ -125,24 +134,29 @@ def run_test(self):
125
134
bad_block = copy .deepcopy (block )
126
135
bad_block .hashMerkleRoot += 1
127
136
assert_template (node , bad_block , 'bad-txnmrklroot' , False )
137
+ assert_submitblock (bad_block , 'bad-txnmrklroot' , 'bad-txnmrklroot' )
128
138
129
139
self .log .info ("getblocktemplate: Test bad timestamps" )
130
140
bad_block = copy .deepcopy (block )
131
141
bad_block .nTime = 2 ** 31 - 1
132
142
assert_template (node , bad_block , 'time-too-new' )
143
+ assert_submitblock (bad_block , 'time-too-new' , 'time-too-new' )
133
144
bad_block .nTime = 0
134
145
assert_template (node , bad_block , 'time-too-old' )
146
+ assert_submitblock (bad_block , 'time-too-old' , 'time-too-old' )
135
147
136
148
self .log .info ("getblocktemplate: Test not best block" )
137
149
bad_block = copy .deepcopy (block )
138
150
bad_block .hashPrevBlock = 123
139
151
assert_template (node , bad_block , 'inconclusive-not-best-prevblk' )
152
+ assert_submitblock (bad_block , 'prev-blk-not-found' , 'prev-blk-not-found' )
140
153
141
154
self .log .info ('submitheader tests' )
142
155
assert_raises_rpc_error (- 22 , 'Block header decode failed' , lambda : node .submitheader (hexdata = 'xx' * 80 ))
143
156
assert_raises_rpc_error (- 22 , 'Block header decode failed' , lambda : node .submitheader (hexdata = 'ff' * 78 ))
144
157
assert_raises_rpc_error (- 25 , 'Must submit previous header' , lambda : node .submitheader (hexdata = 'ff' * 80 ))
145
158
159
+ block .nTime += 1
146
160
block .solve ()
147
161
148
162
def chain_tip (b_hash , * , status = 'headers-only' , branchlen = 1 ):
@@ -161,7 +175,8 @@ def chain_tip(b_hash, *, status='headers-only', branchlen=1):
161
175
node .submitheader (hexdata = b2x (CBlockHeader (bad_block_root ).serialize ()))
162
176
assert chain_tip (bad_block_root .hash ) in node .getchaintips ()
163
177
# Should still reject invalid blocks, even if we have the header:
164
- assert_equal (node .submitblock (hexdata = b2x (bad_block_root .serialize ())), 'invalid' )
178
+ assert_equal (node .submitblock (hexdata = b2x (bad_block_root .serialize ())), 'bad-txnmrklroot' )
179
+ assert_equal (node .submitblock (hexdata = b2x (bad_block_root .serialize ())), 'bad-txnmrklroot' )
165
180
assert chain_tip (bad_block_root .hash ) in node .getchaintips ()
166
181
# We know the header for this invalid block, so should just return early without error:
167
182
node .submitheader (hexdata = b2x (CBlockHeader (bad_block_root ).serialize ()))
@@ -172,7 +187,8 @@ def chain_tip(b_hash, *, status='headers-only', branchlen=1):
172
187
bad_block_lock .vtx [0 ].rehash ()
173
188
bad_block_lock .hashMerkleRoot = bad_block_lock .calc_merkle_root ()
174
189
bad_block_lock .solve ()
175
- assert_equal (node .submitblock (hexdata = b2x (bad_block_lock .serialize ())), 'invalid' )
190
+ assert_equal (node .submitblock (hexdata = b2x (bad_block_lock .serialize ())), 'bad-txns-nonfinal' )
191
+ assert_equal (node .submitblock (hexdata = b2x (bad_block_lock .serialize ())), 'duplicate-invalid' )
176
192
# Build a "good" block on top of the submitted bad block
177
193
bad_block2 = copy .deepcopy (block )
178
194
bad_block2 .hashPrevBlock = bad_block_lock .sha256
@@ -198,6 +214,7 @@ def chain_tip(b_hash, *, status='headers-only', branchlen=1):
198
214
assert_raises_rpc_error (- 25 , 'bad-prevblk' , lambda : node .submitheader (hexdata = b2x (CBlockHeader (bad_block2 ).serialize ())))
199
215
node .submitheader (hexdata = b2x (CBlockHeader (block ).serialize ()))
200
216
node .submitheader (hexdata = b2x (CBlockHeader (bad_block_root ).serialize ()))
217
+ assert_equal (node .submitblock (hexdata = b2x (block .serialize ())), 'duplicate' ) # valid
201
218
202
219
203
220
if __name__ == '__main__' :
0 commit comments