aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@gmail.com>2017-10-02 15:21:26 +0200
committerWladimir J. van der Laan <laanwj@gmail.com>2017-10-02 15:22:41 +0200
commit90926db2381d87c68858659873230a3811ebdce5 (patch)
tree41737ac11fc519327d7289d8a7e120025e8b12d4 /test
parent339da9ca4143b5bb5cbe4d0713ae49661af956a6 (diff)
parent07704c1b3768d6c290046c783063644fc7b7d1da (diff)
downloadbitcoin-90926db2381d87c68858659873230a3811ebdce5.tar.xz
Merge #11021: [rpc] fix getchaintxstats()
07704c1 Add some tests for getchaintxstats (Akio Nakamura) 3336676 Fix 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
Diffstat (limited to 'test')
-rwxr-xr-xtest/functional/blockchain.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/test/functional/blockchain.py b/test/functional/blockchain.py
index c5967aa10b..5bd3bc8f83 100755
--- a/test/functional/blockchain.py
+++ b/test/functional/blockchain.py
@@ -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()