def _test_getchaintxstats(self):
    self.log.info('Test getchaintxstats')
    assert_raises_rpc_error((- 1), 'getchaintxstats', self.nodes[0].getchaintxstats, 0, '', 0)
    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())
    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)
    assert_equal(chaintxstats['txcount'], 201)
    assert_equal(round((chaintxstats['txrate'] * 156), 10), Decimal(1))
    b1_hash = self.nodes[0].getblockhash(1)
    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'])
    chaintxstats = self.nodes[0].getchaintxstats()
    assert_equal(chaintxstats['time'], b200['time'])
    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_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_final_block_hash'], b1_hash)
    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)
def _test_getchaintxstats(self):
    self.log.info('Test getchaintxstats')
    assert_raises_rpc_error((- 1), 'getchaintxstats', self.nodes[0].getchaintxstats, 0, , 0)
    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())
    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)
    assert_equal(chaintxstats['txcount'], 201)
    assert_equal(round((chaintxstats['txrate'] * 156), 10), Decimal(1))
    b1_hash = self.nodes[0].getblockhash(1)
    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'])
    chaintxstats = self.nodes[0].getchaintxstats()
    assert_equal(chaintxstats['time'], b200['time'])
    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_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_final_block_hash'], b1_hash)
    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)