Changeset View
Changeset View
Standalone View
Standalone View
test/functional/rpc_blockchain.py
Show First 20 Lines • Show All 71 Lines • ▼ Show 20 Lines | def _test_getblockchaininfo(self): | ||||
assert res['pruneheight'] >= 0 | assert res['pruneheight'] >= 0 | ||||
self.restart_node(0, ['-stopatheight=207']) | self.restart_node(0, ['-stopatheight=207']) | ||||
res = self.nodes[0].getblockchaininfo() | res = self.nodes[0].getblockchaininfo() | ||||
# should have exact keys | # should have exact keys | ||||
assert_equal(sorted(res.keys()), keys) | assert_equal(sorted(res.keys()), keys) | ||||
def _test_getchaintxstats(self): | def _test_getchaintxstats(self): | ||||
self.log.info("Test getchaintxstats") | |||||
chaintxstats = self.nodes[0].getchaintxstats(1) | chaintxstats = self.nodes[0].getchaintxstats(1) | ||||
# 200 txs plus genesis tx | # 200 txs plus genesis tx | ||||
assert_equal(chaintxstats['txcount'], 201) | assert_equal(chaintxstats['txcount'], 201) | ||||
# tx rate should be 1 per 10 minutes, or 1/600 | # tx rate should be 1 per 10 minutes, or 1/600 | ||||
# we have to round because of binary math | # we have to round because of binary math | ||||
assert_equal(round(chaintxstats['txrate'] * 600, 10), Decimal(1)) | assert_equal(round(chaintxstats['txrate'] * 600, 10), Decimal(1)) | ||||
b1 = self.nodes[0].getblock(self.nodes[0].getblockhash(1)) | b1_hash = self.nodes[0].getblockhash(1) | ||||
b200 = self.nodes[0].getblock(self.nodes[0].getblockhash(200)) | b1 = self.nodes[0].getblock(b1_hash) | ||||
b200_hash = self.nodes[0].getblockhash(200) | |||||
b200 = self.nodes[0].getblock(b200_hash) | |||||
time_diff = b200['mediantime'] - b1['mediantime'] | time_diff = b200['mediantime'] - b1['mediantime'] | ||||
chaintxstats = self.nodes[0].getchaintxstats() | chaintxstats = self.nodes[0].getchaintxstats() | ||||
assert_equal(chaintxstats['time'], b200['time']) | assert_equal(chaintxstats['time'], b200['time']) | ||||
assert_equal(chaintxstats['txcount'], 201) | assert_equal(chaintxstats['txcount'], 201) | ||||
assert_equal(chaintxstats['window_final_block_hash'], b200_hash) | |||||
assert_equal(chaintxstats['window_block_count'], 199) | assert_equal(chaintxstats['window_block_count'], 199) | ||||
assert_equal(chaintxstats['window_tx_count'], 199) | assert_equal(chaintxstats['window_tx_count'], 199) | ||||
assert_equal(chaintxstats['window_interval'], time_diff) | assert_equal(chaintxstats['window_interval'], time_diff) | ||||
assert_equal( | assert_equal( | ||||
round(chaintxstats['txrate'] * time_diff, 10), Decimal(199)) | round(chaintxstats['txrate'] * time_diff, 10), Decimal(199)) | ||||
chaintxstats = self.nodes[0].getchaintxstats(blockhash=b1['hash']) | chaintxstats = self.nodes[0].getchaintxstats(blockhash=b1_hash) | ||||
assert_equal(chaintxstats['time'], b1['time']) | assert_equal(chaintxstats['time'], b1['time']) | ||||
assert_equal(chaintxstats['txcount'], 2) | assert_equal(chaintxstats['txcount'], 2) | ||||
assert_equal(chaintxstats['window_final_block_hash'], b1_hash) | |||||
assert_equal(chaintxstats['window_block_count'], 0) | assert_equal(chaintxstats['window_block_count'], 0) | ||||
assert('window_tx_count' not in chaintxstats) | assert('window_tx_count' not in chaintxstats) | ||||
assert('window_interval' not in chaintxstats) | assert('window_interval' not in chaintxstats) | ||||
assert('txrate' not in chaintxstats) | assert('txrate' not in chaintxstats) | ||||
assert_raises_rpc_error( | assert_raises_rpc_error( | ||||
-8, "Invalid block count: should be between 0 and the block's height - 1", | -8, "Invalid block count: should be between 0 and the block's height - 1", | ||||
self.nodes[0].getchaintxstats, 201) | self.nodes[0].getchaintxstats, 201) | ||||
▲ Show 20 Lines • Show All 135 Lines • Show Last 20 Lines |