@@ -62,6 +62,7 @@ def run_test(self):
6262 self ._test_getnetworkhashps ()
6363 self ._test_stopatheight ()
6464 self ._test_waitforblockheight ()
65+ self ._test_muhash ()
6566 assert self .nodes [0 ].verifychain (4 , 0 )
6667
6768 def mine_chain (self ):
@@ -73,6 +74,10 @@ def mine_chain(self):
7374 self .nodes [0 ].generatetoaddress (1 , address )
7475 assert_equal (self .nodes [0 ].getblockchaininfo ()['blocks' ], 200 )
7576
77+ def mine_block (self ):
78+ address = self .nodes [0 ].get_deterministic_priv_key ().address
79+ self .nodes [0 ].generatetoaddress (1 , address )
80+
7681 def _test_getblockchaininfo (self ):
7782 self .log .info ("Test getblockchaininfo" )
7883
@@ -202,6 +207,10 @@ def _test_getchaintxstats(self):
202207
203208 def _test_gettxoutsetinfo (self ):
204209 node = self .nodes [0 ]
210+
211+ # TODO: Without this sleep muhash result is inconsistent
212+ import time
213+ time .sleep (0.1 )
205214 res = node .gettxoutsetinfo ()
206215
207216 assert_equal (res ['total_amount' ], Decimal ('8725.00000000' ))
@@ -231,7 +240,6 @@ def _test_gettxoutsetinfo(self):
231240
232241 self .log .info ("Test that gettxoutsetinfo() returns the same result after invalidate/reconsider block" )
233242 node .reconsiderblock (b1hash )
234-
235243 res3 = node .gettxoutsetinfo ()
236244 # The field 'disk_size' is non-deterministic and can thus not be
237245 # compared between res and res3. Everything else should be the same.
@@ -331,6 +339,31 @@ def assert_waitforheight(height, timeout=2):
331339 assert_waitforheight (current_height )
332340 assert_waitforheight (current_height + 1 )
333341
342+ def _test_muhash (self ):
343+ self .restart_node (0 )
344+ node = self .nodes [0 ]
345+
346+ self .log .info ("Test that gettxoutsetinfo() muhash is unchanged when rolling back a new block" )
347+
348+ # Test consistency of hashing
349+ res = node .gettxoutsetinfo ()
350+ muhash_at_207 = res ['muhash' ]
351+ assert (node .gettxoutsetinfo ()['muhash' ] == muhash_at_207 )
352+
353+ # Hash is updated with new block
354+ self .mine_block ()
355+ assert (node .gettxoutsetinfo ()['muhash' ] != muhash_at_207 )
356+
357+ # Hash is rolled back to previous block if invalidated
358+ b208hash = node .getblockhash (208 )
359+ node .invalidateblock (b208hash )
360+ assert (node .gettxoutsetinfo ()['muhash' ] == muhash_at_207 )
361+
362+ # Hash persists restart
363+ self .stop_node (0 )
364+ self .start_node (0 )
365+ assert (node .gettxoutsetinfo ()['muhash' ] == muhash_at_207 )
366+
334367
335368if __name__ == '__main__' :
336369 BlockchainTest ().main ()
0 commit comments