Skip to content

Commit b4b057a

Browse files
committed
Merge #10445: Add test for empty chain and reorg consistency for gettxoutsetinfo.
513da90 Add test for empty chain and reorg consistency for gettxoutsetinfo. (Gregory Maxwell) 822755a Fix: make CCoinsViewDbCursor::Seek work for missing keys (Pieter Wuille) Tree-SHA512: e549921e8b8f599bf61ebe0ee7ef1d2f474043723d633e24665fe434b996a98e039612de8a1c2cd16b63f154943ff5ea1c1935e9561cfb813a00d47d926d0b22
2 parents b40ceed + 513da90 commit b4b057a

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

src/txdb.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,11 @@ CCoinsViewCursor *CCoinsViewDB::Cursor() const
9898
that restriction. */
9999
i->pcursor->Seek(DB_COINS);
100100
// Cache key of first record
101-
i->pcursor->GetKey(i->keyTmp);
101+
if (i->pcursor->Valid()) {
102+
i->pcursor->GetKey(i->keyTmp);
103+
} else {
104+
i->keyTmp.first = 0; // Make sure Valid() and GetKey() return false
105+
}
102106
return i;
103107
}
104108

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)