Merge #12083: Improve getchaintxstats test coverage
57e6786
qa: Improve getchaintxstats functional test (João Barbosa)501b439
rpc: Refactor blockhash parse in getchaintxstats (João Barbosa) Pull request description: Tree-SHA512: 61dec5cb68122998df7ec7b5239830f3caf0fe7185c107a66f27653ab2531a800db19a09050671b6fa8dbb5b53181da861eb31199c79d8635f246ccfa0d10efd
This commit is contained in:
commit
228b086b9a
2 changed files with 28 additions and 20 deletions
|
@ -1542,15 +1542,12 @@ UniValue getchaintxstats(const JSONRPCRequest& request)
|
||||||
const CBlockIndex* pindex;
|
const CBlockIndex* pindex;
|
||||||
int blockcount = 30 * 24 * 60 * 60 / Params().GetConsensus().nPowTargetSpacing; // By default: 1 month
|
int blockcount = 30 * 24 * 60 * 60 / Params().GetConsensus().nPowTargetSpacing; // By default: 1 month
|
||||||
|
|
||||||
bool havehash = !request.params[1].isNull();
|
if (request.params[1].isNull()) {
|
||||||
uint256 hash;
|
LOCK(cs_main);
|
||||||
if (havehash) {
|
pindex = chainActive.Tip();
|
||||||
hash = uint256S(request.params[1].get_str());
|
} else {
|
||||||
}
|
uint256 hash = uint256S(request.params[1].get_str());
|
||||||
|
|
||||||
{
|
|
||||||
LOCK(cs_main);
|
LOCK(cs_main);
|
||||||
if (havehash) {
|
|
||||||
auto it = mapBlockIndex.find(hash);
|
auto it = mapBlockIndex.find(hash);
|
||||||
if (it == mapBlockIndex.end()) {
|
if (it == mapBlockIndex.end()) {
|
||||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found");
|
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found");
|
||||||
|
@ -1559,9 +1556,6 @@ UniValue getchaintxstats(const JSONRPCRequest& request)
|
||||||
if (!chainActive.Contains(pindex)) {
|
if (!chainActive.Contains(pindex)) {
|
||||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Block is not in main chain");
|
throw JSONRPCError(RPC_INVALID_PARAMETER, "Block is not in main chain");
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
pindex = chainActive.Tip();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(pindex != nullptr);
|
assert(pindex != nullptr);
|
||||||
|
|
|
@ -102,6 +102,22 @@ class BlockchainTest(BitcoinTestFramework):
|
||||||
def _test_getchaintxstats(self):
|
def _test_getchaintxstats(self):
|
||||||
self.log.info("Test getchaintxstats")
|
self.log.info("Test getchaintxstats")
|
||||||
|
|
||||||
|
# Test `getchaintxstats` invalid extra parameters
|
||||||
|
assert_raises_rpc_error(-1, 'getchaintxstats', self.nodes[0].getchaintxstats, 0, '', 0)
|
||||||
|
|
||||||
|
# Test `getchaintxstats` invalid `nblocks`
|
||||||
|
assert_raises_rpc_error(-1, "JSON value is not an integer as expected", self.nodes[0].getchaintxstats, '')
|
||||||
|
assert_raises_rpc_error(-8, "Invalid block count: should be between 0 and the block's height - 1", self.nodes[0].getchaintxstats, -1)
|
||||||
|
assert_raises_rpc_error(-8, "Invalid block count: should be between 0 and the block's height - 1", self.nodes[0].getchaintxstats, self.nodes[0].getblockcount())
|
||||||
|
|
||||||
|
# Test `getchaintxstats` invalid `blockhash`
|
||||||
|
assert_raises_rpc_error(-1, "JSON value is not a string as expected", self.nodes[0].getchaintxstats, blockhash=0)
|
||||||
|
assert_raises_rpc_error(-5, "Block not found", self.nodes[0].getchaintxstats, blockhash='0')
|
||||||
|
blockhash = self.nodes[0].getblockhash(200)
|
||||||
|
self.nodes[0].invalidateblock(blockhash)
|
||||||
|
assert_raises_rpc_error(-8, "Block is not in main chain", self.nodes[0].getchaintxstats, blockhash=blockhash)
|
||||||
|
self.nodes[0].reconsiderblock(blockhash)
|
||||||
|
|
||||||
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)
|
||||||
|
@ -133,8 +149,6 @@ class BlockchainTest(BitcoinTestFramework):
|
||||||
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(-8, "Invalid block count: should be between 0 and the block's height - 1", self.nodes[0].getchaintxstats, 201)
|
|
||||||
|
|
||||||
def _test_gettxoutsetinfo(self):
|
def _test_gettxoutsetinfo(self):
|
||||||
node = self.nodes[0]
|
node = self.nodes[0]
|
||||||
res = node.gettxoutsetinfo()
|
res = node.gettxoutsetinfo()
|
||||||
|
|
Loading…
Reference in a new issue