Skip to content

Commit 07704c1

Browse files
committed
Add some tests for getchaintxstats
1. Add a test for no parameters. 2. Add a test for the block's height = 1. 3. Add a test for nblocks is out of range.
1 parent 3336676 commit 07704c1

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

test/functional/blockchain.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,28 @@ def _test_getchaintxstats(self):
5656
# we have to round because of binary math
5757
assert_equal(round(chaintxstats['txrate'] * 600, 10), Decimal(1))
5858

59+
b1 = self.nodes[0].getblock(self.nodes[0].getblockhash(1))
60+
b200 = self.nodes[0].getblock(self.nodes[0].getblockhash(200))
61+
time_diff = b200['mediantime'] - b1['mediantime']
62+
63+
chaintxstats = self.nodes[0].getchaintxstats()
64+
assert_equal(chaintxstats['time'], b200['time'])
65+
assert_equal(chaintxstats['txcount'], 201)
66+
assert_equal(chaintxstats['window_block_count'], 199)
67+
assert_equal(chaintxstats['window_tx_count'], 199)
68+
assert_equal(chaintxstats['window_interval'], time_diff)
69+
assert_equal(round(chaintxstats['txrate'] * time_diff, 10), Decimal(199))
70+
71+
chaintxstats = self.nodes[0].getchaintxstats(blockhash=b1['hash'])
72+
assert_equal(chaintxstats['time'], b1['time'])
73+
assert_equal(chaintxstats['txcount'], 2)
74+
assert_equal(chaintxstats['window_block_count'], 0)
75+
assert('window_tx_count' not in chaintxstats)
76+
assert('window_interval' not in chaintxstats)
77+
assert('txrate' not in chaintxstats)
78+
79+
assert_raises_jsonrpc(-8, "Invalid block count: should be between 0 and the block's height - 1", self.nodes[0].getchaintxstats, 201)
80+
5981
def _test_gettxoutsetinfo(self):
6082
node = self.nodes[0]
6183
res = node.gettxoutsetinfo()

0 commit comments

Comments
 (0)