Skip to content

Commit

Permalink
[squashme] add missing disk size assertion in blockchain.py
Browse files Browse the repository at this point in the history
  • Loading branch information
xanimo committed Jul 12, 2024
1 parent f0a3bbd commit f2a7bba
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
30 changes: 29 additions & 1 deletion qa/rpc-tests/blockchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
start_node,
connect_nodes_bi,
)

import logging

class BlockchainTest(BitcoinTestFramework):
"""
Expand All @@ -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 = []
Expand Down Expand Up @@ -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]

Expand Down
2 changes: 1 addition & 1 deletion src/test/coins_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit f2a7bba

Please sign in to comment.