mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-06-03 17:54:19 +02:00
Merge #11021: [rpc] fix getchaintxstats()
07704c1Add some tests for getchaintxstats (Akio Nakamura)3336676Fix getchaintxstats() (Akio Nakamura) Pull request description: 1. calculate nblocks more adaptive. -> set default nblocks to min (blocks for 1 month, target block's height - 1) -> before PR: if not specify nblocks-parameter, illegal parameter error will happen when target block height is below nblocks. 2. correct error message. -> nblocks accepts [1 .. block's height -1] . so add a word "-1". 3. add check 0-divide. -> if nTimeDiff = 0 then use UniValue(UniValue::VNULL) and returns {... "txrate": null} . -> before PR: if nTimeDiff = 0 then returns {... "txrate":} and bitcoin-cli cannot handle the response. Tree-SHA512: e1962ce7bb05a5bc7dec03eb04a8e7578f50fdb68927fcfc0a2232905ef4d679293eee148ebe0866682d209a8c458d21fbe71715e7311adb81f37089aae1ed93
This commit is contained in:
@@ -81,6 +81,28 @@ class BlockchainTest(BitcoinTestFramework):
|
||||
# we have to round because of binary math
|
||||
assert_equal(round(chaintxstats['txrate'] * 600, 10), Decimal(1))
|
||||
|
||||
b1 = self.nodes[0].getblock(self.nodes[0].getblockhash(1))
|
||||
b200 = self.nodes[0].getblock(self.nodes[0].getblockhash(200))
|
||||
time_diff = b200['mediantime'] - b1['mediantime']
|
||||
|
||||
chaintxstats = self.nodes[0].getchaintxstats()
|
||||
assert_equal(chaintxstats['time'], b200['time'])
|
||||
assert_equal(chaintxstats['txcount'], 201)
|
||||
assert_equal(chaintxstats['window_block_count'], 199)
|
||||
assert_equal(chaintxstats['window_tx_count'], 199)
|
||||
assert_equal(chaintxstats['window_interval'], time_diff)
|
||||
assert_equal(round(chaintxstats['txrate'] * time_diff, 10), Decimal(199))
|
||||
|
||||
chaintxstats = self.nodes[0].getchaintxstats(blockhash=b1['hash'])
|
||||
assert_equal(chaintxstats['time'], b1['time'])
|
||||
assert_equal(chaintxstats['txcount'], 2)
|
||||
assert_equal(chaintxstats['window_block_count'], 0)
|
||||
assert('window_tx_count' not in chaintxstats)
|
||||
assert('window_interval' not in chaintxstats)
|
||||
assert('txrate' not in chaintxstats)
|
||||
|
||||
assert_raises_jsonrpc(-8, "Invalid block count: should be between 0 and the block's height - 1", self.nodes[0].getchaintxstats, 201)
|
||||
|
||||
def _test_gettxoutsetinfo(self):
|
||||
node = self.nodes[0]
|
||||
res = node.gettxoutsetinfo()
|
||||
|
||||
Reference in New Issue
Block a user