Skip to content

Commit ebb4432

Browse files
committed
test: Add functional test for rolling utxo set hash
1 parent d9e1809 commit ebb4432

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

test/functional/rpc_blockchain.py

+33-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
assert_raises_rpc_error,
3232
assert_is_hex_string,
3333
assert_is_hash_string,
34+
wait_until,
3435
)
3536
from test_framework.blocktools import (
3637
create_block,
@@ -62,6 +63,7 @@ def run_test(self):
6263
self._test_getnetworkhashps()
6364
self._test_stopatheight()
6465
self._test_waitforblockheight()
66+
self._test_muhash()
6567
assert self.nodes[0].verifychain(4, 0)
6668

6769
def mine_chain(self):
@@ -73,6 +75,10 @@ def mine_chain(self):
7375
self.nodes[0].generatetoaddress(1, address)
7476
assert_equal(self.nodes[0].getblockchaininfo()['blocks'], 200)
7577

78+
def mine_block(self):
79+
address = self.nodes[0].get_deterministic_priv_key().address
80+
self.nodes[0].generatetoaddress(1, address)
81+
7682
def _test_getblockchaininfo(self):
7783
self.log.info("Test getblockchaininfo")
7884

@@ -202,6 +208,8 @@ def _test_getchaintxstats(self):
202208

203209
def _test_gettxoutsetinfo(self):
204210
node = self.nodes[0]
211+
212+
wait_until(lambda: self.nodes[0].getblockcount() == 200)
205213
res = node.gettxoutsetinfo()
206214

207215
assert_equal(res['total_amount'], Decimal('8725.00000000'))
@@ -231,7 +239,6 @@ def _test_gettxoutsetinfo(self):
231239

232240
self.log.info("Test that gettxoutsetinfo() returns the same result after invalidate/reconsider block")
233241
node.reconsiderblock(b1hash)
234-
235242
res3 = node.gettxoutsetinfo()
236243
# The field 'disk_size' is non-deterministic and can thus not be
237244
# compared between res and res3. Everything else should be the same.
@@ -331,6 +338,31 @@ def assert_waitforheight(height, timeout=2):
331338
assert_waitforheight(current_height)
332339
assert_waitforheight(current_height + 1)
333340

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+
334366

335367
if __name__ == '__main__':
336368
BlockchainTest().main()

0 commit comments

Comments
 (0)