Skip to content

Commit

Permalink
test: Add coverage for getchaintxstats in assumeutxo context
Browse files Browse the repository at this point in the history
  • Loading branch information
fjahr authored and MarcoFalke committed May 20, 2024
1 parent fa060ae commit ef692e5
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion test/functional/feature_assumeutxo.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
from test_framework.messages import tx_from_hex
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import (
assert_approx,
assert_equal,
assert_raises_rpc_error,
)
Expand Down Expand Up @@ -257,14 +258,28 @@ def check_tx_counts(final: bool) -> None:
the snapshot, and final values after the snapshot is validated."""
for height, block in blocks.items():
tx = n1.getblockheader(block.hash)["nTx"]
chain_tx = n1.getchaintxstats(nblocks=1, blockhash=block.hash).get("txcount", None)
stats = n1.getchaintxstats(nblocks=1, blockhash=block.hash)
chain_tx = stats.get("txcount", None)
window_tx_count = stats.get("window_tx_count", None)
tx_rate = stats.get("txrate", None)
window_interval = stats.get("window_interval")

# Intermediate nTx of the starting block should be set, but nTx of
# later blocks should be 0 before they are downloaded.
# The window_tx_count of one block is equal to the blocks tx count.
# If the window tx count is unknown, the value is missing.
# The tx_rate is calculated from window_tx_count and window_interval
# when possible.
if final or height == START_HEIGHT:
assert_equal(tx, block.tx)
assert_equal(window_tx_count, tx)
if window_interval > 0:
assert_approx(tx_rate, window_tx_count / window_interval, vspan=0.1)
else:
assert_equal(tx_rate, None)
else:
assert_equal(tx, 0)
assert_equal(window_tx_count, None)

# Intermediate nChainTx of the starting block and snapshot block
# should be set, but others should be None until they are downloaded.
Expand Down

0 comments on commit ef692e5

Please sign in to comment.