31
31
assert_raises_rpc_error ,
32
32
assert_is_hex_string ,
33
33
assert_is_hash_string ,
34
+ wait_until ,
34
35
)
35
36
from test_framework .blocktools import (
36
37
create_block ,
@@ -62,6 +63,7 @@ def run_test(self):
62
63
self ._test_getnetworkhashps ()
63
64
self ._test_stopatheight ()
64
65
self ._test_waitforblockheight ()
66
+ self ._test_muhash ()
65
67
assert self .nodes [0 ].verifychain (4 , 0 )
66
68
67
69
def mine_chain (self ):
@@ -73,6 +75,10 @@ def mine_chain(self):
73
75
self .nodes [0 ].generatetoaddress (1 , address )
74
76
assert_equal (self .nodes [0 ].getblockchaininfo ()['blocks' ], 200 )
75
77
78
+ def mine_block (self ):
79
+ address = self .nodes [0 ].get_deterministic_priv_key ().address
80
+ self .nodes [0 ].generatetoaddress (1 , address )
81
+
76
82
def _test_getblockchaininfo (self ):
77
83
self .log .info ("Test getblockchaininfo" )
78
84
@@ -202,6 +208,8 @@ def _test_getchaintxstats(self):
202
208
203
209
def _test_gettxoutsetinfo (self ):
204
210
node = self .nodes [0 ]
211
+
212
+ wait_until (lambda : self .nodes [0 ].getblockcount () == 200 )
205
213
res = node .gettxoutsetinfo ()
206
214
207
215
assert_equal (res ['total_amount' ], Decimal ('8725.00000000' ))
@@ -231,7 +239,6 @@ def _test_gettxoutsetinfo(self):
231
239
232
240
self .log .info ("Test that gettxoutsetinfo() returns the same result after invalidate/reconsider block" )
233
241
node .reconsiderblock (b1hash )
234
-
235
242
res3 = node .gettxoutsetinfo ()
236
243
# The field 'disk_size' is non-deterministic and can thus not be
237
244
# compared between res and res3. Everything else should be the same.
@@ -331,6 +338,31 @@ def assert_waitforheight(height, timeout=2):
331
338
assert_waitforheight (current_height )
332
339
assert_waitforheight (current_height + 1 )
333
340
341
+ def _test_muhash (self ):
342
+ self .restart_node (0 )
343
+ node = self .nodes [0 ]
344
+
345
+ self .log .info ("Test that gettxoutsetinfo() muhash is unchanged when rolling back a new block" )
346
+
347
+ # Test consistency of hashing
348
+ res = node .gettxoutsetinfo ()
349
+ muhash_at_207 = res ['muhash' ]
350
+ assert (node .gettxoutsetinfo ()['muhash' ] == muhash_at_207 )
351
+
352
+ # Hash is updated with new block
353
+ self .mine_block ()
354
+ assert (node .gettxoutsetinfo ()['muhash' ] != muhash_at_207 )
355
+
356
+ # Hash is rolled back to previous block if invalidated
357
+ b208hash = node .getblockhash (208 )
358
+ node .invalidateblock (b208hash )
359
+ assert (node .gettxoutsetinfo ()['muhash' ] == muhash_at_207 )
360
+
361
+ # Hash persists restart
362
+ self .stop_node (0 )
363
+ self .start_node (0 )
364
+ assert (node .gettxoutsetinfo ()['muhash' ] == muhash_at_207 )
365
+
334
366
335
367
if __name__ == '__main__' :
336
368
BlockchainTest ().main ()
0 commit comments