Skip to content

Commit 2342b46

Browse files
fjahrMarcoFalke
authored andcommitted
test: Add coverage for getchaintxstats in assumeutxo context
1 parent faf2a67 commit 2342b46

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

test/functional/feature_assumeutxo.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
from test_framework.messages import tx_from_hex
3434
from test_framework.test_framework import BitcoinTestFramework
3535
from test_framework.util import (
36+
assert_approx,
3637
assert_equal,
3738
assert_raises_rpc_error,
3839
)
@@ -301,14 +302,28 @@ def check_tx_counts(final: bool) -> None:
301302
the snapshot, and final values after the snapshot is validated."""
302303
for height, block in blocks.items():
303304
tx = n1.getblockheader(block.hash)["nTx"]
304-
chain_tx = n1.getchaintxstats(nblocks=1, blockhash=block.hash).get("txcount", None)
305+
stats = n1.getchaintxstats(nblocks=1, blockhash=block.hash)
306+
chain_tx = stats.get("txcount", None)
307+
window_tx_count = stats.get("window_tx_count", None)
308+
tx_rate = stats.get("txrate", None)
309+
window_interval = stats.get("window_interval")
305310

306311
# Intermediate nTx of the starting block should be set, but nTx of
307312
# later blocks should be 0 before they are downloaded.
313+
# The window_tx_count of one block is equal to the blocks tx count.
314+
# If the window tx count is unknown, the value is missing.
315+
# The tx_rate is calculated from window_tx_count and window_interval
316+
# when possible.
308317
if final or height == START_HEIGHT:
309318
assert_equal(tx, block.tx)
319+
assert_equal(window_tx_count, tx)
320+
if window_interval > 0:
321+
assert_approx(tx_rate, window_tx_count / window_interval, vspan=0.1)
322+
else:
323+
assert_equal(tx_rate, None)
310324
else:
311325
assert_equal(tx, 0)
326+
assert_equal(window_tx_count, None)
312327

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

0 commit comments

Comments
 (0)