Skip to content

Commit 513da90

Browse files
committed
Add test for empty chain and reorg consistency for gettxoutsetinfo.
1 parent 822755a commit 513da90

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

test/functional/blockchain.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class BlockchainTest(BitcoinTestFramework):
3232
def __init__(self):
3333
super().__init__()
3434
self.setup_clean_chain = False
35-
self.num_nodes = 2
35+
self.num_nodes = 1
3636

3737
def run_test(self):
3838
self._test_gettxoutsetinfo()
@@ -50,9 +50,33 @@ def _test_gettxoutsetinfo(self):
5050
assert_equal(res['height'], 200)
5151
assert_equal(res['txouts'], 200)
5252
assert_equal(res['bytes_serialized'], 13924),
53+
assert_equal(res['bestblock'], node.getblockhash(200))
5354
assert_equal(len(res['bestblock']), 64)
5455
assert_equal(len(res['hash_serialized']), 64)
5556

57+
self.log.info("Test that gettxoutsetinfo() works for blockchain with just the genesis block")
58+
b1hash = node.getblockhash(1)
59+
node.invalidateblock(b1hash)
60+
61+
res2 = node.gettxoutsetinfo()
62+
assert_equal(res2['transactions'], 0)
63+
assert_equal(res2['total_amount'], Decimal('0'))
64+
assert_equal(res2['height'], 0)
65+
assert_equal(res2['txouts'], 0)
66+
assert_equal(res2['bestblock'], node.getblockhash(0))
67+
assert_equal(len(res2['hash_serialized']), 64)
68+
69+
self.log.info("Test that gettxoutsetinfo() returns the same result after invalidate/reconsider block")
70+
node.reconsiderblock(b1hash)
71+
72+
res3 = node.gettxoutsetinfo()
73+
assert_equal(res['total_amount'], res3['total_amount'])
74+
assert_equal(res['transactions'], res3['transactions'])
75+
assert_equal(res['height'], res3['height'])
76+
assert_equal(res['txouts'], res3['txouts'])
77+
assert_equal(res['bestblock'], res3['bestblock'])
78+
assert_equal(res['hash_serialized'], res3['hash_serialized'])
79+
5680
def _test_getblockheader(self):
5781
node = self.nodes[0]
5882

0 commit comments

Comments
 (0)