diff --git a/qa/rpc-tests/blockchain.py b/qa/rpc-tests/blockchain.py index 0ffff2469ec..3f40125517b 100755 --- a/qa/rpc-tests/blockchain.py +++ b/qa/rpc-tests/blockchain.py @@ -24,7 +24,7 @@ start_node, connect_nodes_bi, ) - +import logging class BlockchainTest(BitcoinTestFramework): """ @@ -39,6 +39,7 @@ def __init__(self): super().__init__() self.setup_clean_chain = False self.num_nodes = 2 + self.log = logging.getLogger("GetBlockchainTest") def setup_network(self, split=False): self.nodes = [] @@ -108,9 +109,36 @@ def _test_gettxoutsetinfo(self): assert_equal(res['transactions'], 120) assert_equal(res['height'], 120) assert_equal(res['txouts'], 120) + size = res['disk_size'] + print(size) + assert size > 6400 + assert size < 64000 assert_equal(len(res['bestblock']), 64) assert_equal(len(res['hash_serialized_2']), 64) + self.log.info("Test that gettxoutsetinfo() works for blockchain with just the genesis block") + b1hash = node.getblockhash(1) + node.invalidateblock(b1hash) + + res2 = node.gettxoutsetinfo() + assert_equal(res2['transactions'], 0) + assert_equal(res2['total_amount'], Decimal('0')) + assert_equal(res2['height'], 0) + assert_equal(res2['txouts'], 0) + assert_equal(res2['bestblock'], node.getblockhash(0)) + assert_equal(len(res2['hash_serialized_2']), 64) + + self.log.info("Test that gettxoutsetinfo() returns the same result after invalidate/reconsider block") + node.reconsiderblock(b1hash) + + res3 = node.gettxoutsetinfo() + assert_equal(res['total_amount'], res3['total_amount']) + assert_equal(res['transactions'], res3['transactions']) + assert_equal(res['height'], res3['height']) + assert_equal(res['txouts'], res3['txouts']) + assert_equal(res['bestblock'], res3['bestblock']) + assert_equal(res['hash_serialized_2'], res3['hash_serialized_2']) + def _test_getblockheader(self): node = self.nodes[0] diff --git a/src/test/coins_tests.cpp b/src/test/coins_tests.cpp index 263103b9f9f..97e73abf759 100644 --- a/src/test/coins_tests.cpp +++ b/src/test/coins_tests.cpp @@ -150,7 +150,7 @@ BOOST_AUTO_TEST_CASE(coins_cache_simulation_test) const Coin& entry = (InsecureRandRange(500) == 0) ? AccessByTxid(*stack.back(), txid) : stack.back()->AccessCoin(COutPoint(txid, 0)); BOOST_CHECK(coin == entry); - if (InsecureRandRange(5) == 0 == 0 || coin.IsSpent()) { + if (InsecureRandRange(5) == 0 || coin.IsSpent()) { Coin newcoin; newcoin.out.nValue = InsecureRandRange(1); newcoin.nHeight = 1;