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_utxo_set_hash ()
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
@@ -204,6 +210,8 @@ def _test_getchaintxstats(self):
204
210
205
211
def _test_gettxoutsetinfo (self ):
206
212
node = self .nodes [0 ]
213
+
214
+ wait_until (lambda : self .nodes [0 ].getblockcount () == 200 )
207
215
res = node .gettxoutsetinfo ()
208
216
209
217
assert_equal (res ['total_amount' ], Decimal ('8725.00000000' ))
@@ -233,7 +241,6 @@ def _test_gettxoutsetinfo(self):
233
241
234
242
self .log .info ("Test that gettxoutsetinfo() returns the same result after invalidate/reconsider block" )
235
243
node .reconsiderblock (b1hash )
236
-
237
244
res3 = node .gettxoutsetinfo ()
238
245
# The field 'disk_size' is non-deterministic and can thus not be
239
246
# compared between res and res3. Everything else should be the same.
@@ -333,6 +340,31 @@ def assert_waitforheight(height, timeout=2):
333
340
assert_waitforheight (current_height )
334
341
assert_waitforheight (current_height + 1 )
335
342
343
+ def _test_utxo_set_hash (self ):
344
+ self .restart_node (0 )
345
+ node = self .nodes [0 ]
346
+
347
+ self .log .info ("Test that gettxoutsetinfo() utxo set hash is unchanged when rolling back a new block" )
348
+
349
+ # Test consistency of hashing
350
+ res = node .gettxoutsetinfo ()
351
+ hash_at_207 = res ['utxo_set_hash' ]
352
+ assert (node .gettxoutsetinfo ()['utxo_set_hash' ] == hash_at_207 )
353
+
354
+ # Hash is updated with new block
355
+ self .mine_block ()
356
+ assert (node .gettxoutsetinfo ()['utxo_set_hash' ] != hash_at_207 )
357
+
358
+ # Hash is rolled back to previous block if invalidated
359
+ b208hash = node .getblockhash (208 )
360
+ node .invalidateblock (b208hash )
361
+ assert (node .gettxoutsetinfo ()['utxo_set_hash' ] == hash_at_207 )
362
+
363
+ # Hash persists restart
364
+ self .stop_node (0 )
365
+ self .start_node (0 )
366
+ assert (node .gettxoutsetinfo ()['utxo_set_hash' ] == hash_at_207 )
367
+
336
368
337
369
if __name__ == '__main__' :
338
370
BlockchainTest ().main ()
0 commit comments