def run_test(self):
    test_data = os.path.join(TESTSDIR, self.options.test_data)
    if self.options.gen_test_data:
        self.generate_test_data(test_data)
    else:
        self.load_test_data(test_data)
    self.sync_all()
    stats = self.get_stats()
    expected_keys = self.expected_stats[0].keys()
    assert_equal(set(stats[0].keys()), set(expected_keys))
    assert_equal(stats[0]['height'], self.start_height)
    assert_equal(stats[self.max_stat_pos]['height'], (self.start_height + self.max_stat_pos))
    for i in range((self.max_stat_pos + 1)):
        self.log.info(('Checking block %d\n' % i))
        assert_equal(stats[i], self.expected_stats[i])
        blockhash = self.expected_stats[i]['blockhash']
        stats_by_hash = self.nodes[0].getblockstats(hash_or_height=blockhash)
        assert_equal(stats_by_hash, self.expected_stats[i])
    for stat in expected_keys:
        for i in range((self.max_stat_pos + 1)):
            result = self.nodes[0].getblockstats(hash_or_height=(self.start_height + i), stats=[stat])
            assert_equal(list(result.keys()), [stat])
            if (result[stat] != self.expected_stats[i][stat]):
                self.log.info(('result[%s] (%d) failed, %r != %r' % (stat, i, result[stat], self.expected_stats[i][stat])))
            assert_equal(result[stat], self.expected_stats[i][stat])
    some_stats = {'minfee', 'maxfee'}
    stats = self.nodes[0].getblockstats(hash_or_height=1, stats=list(some_stats))
    assert_equal(set(stats.keys()), some_stats)
    tip = (self.start_height + self.max_stat_pos)
    assert_raises_rpc_error((- 8), ('Target block height %d after current tip %d' % ((tip + 1), tip)), self.nodes[0].getblockstats, hash_or_height=(tip + 1))
    assert_raises_rpc_error((- 8), ('Target block height %d is negative' % (- 1)), self.nodes[0].getblockstats, hash_or_height=(- 1))
    inv_sel_stat = 'asdfghjkl'
    inv_stats = [[inv_sel_stat], ['minfee', inv_sel_stat], [inv_sel_stat, 'minfee'], ['minfee', inv_sel_stat, 'maxfee']]
    for inv_stat in inv_stats:
        assert_raises_rpc_error((- 8), ('Invalid selected statistic %s' % inv_sel_stat), self.nodes[0].getblockstats, hash_or_height=1, stats=inv_stat)
    assert_raises_rpc_error((- 8), ('Invalid selected statistic aaa%s' % inv_sel_stat), self.nodes[0].getblockstats, hash_or_height=1, stats=['minfee', ('aaa%s' % inv_sel_stat)])
    assert_raises_rpc_error((- 5), 'Block not found', self.nodes[0].getblockstats, hash_or_height='000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f')
    assert_raises_rpc_error((- 1), 'getblockstats hash_or_height ( stats )', self.nodes[0].getblockstats, '00', 1, 2)
    assert_raises_rpc_error((- 1), 'getblockstats hash_or_height ( stats )', self.nodes[0].getblockstats)
def run_test(self):
    test_data = os.path.join(TESTSDIR, self.options.test_data)
    if self.options.gen_test_data:
        self.generate_test_data(test_data)
    else:
        self.load_test_data(test_data)
    self.sync_all()
    stats = self.get_stats()
    expected_keys = self.expected_stats[0].keys()
    assert_equal(set(stats[0].keys()), set(expected_keys))
    assert_equal(stats[0]['height'], self.start_height)
    assert_equal(stats[self.max_stat_pos]['height'], (self.start_height + self.max_stat_pos))
    for i in range((self.max_stat_pos + 1)):
        self.log.info(('Checking block %d\n' % i))
        assert_equal(stats[i], self.expected_stats[i])
        blockhash = self.expected_stats[i]['blockhash']
        stats_by_hash = self.nodes[0].getblockstats(hash_or_height=blockhash)
        assert_equal(stats_by_hash, self.expected_stats[i])
    for stat in expected_keys:
        for i in range((self.max_stat_pos + 1)):
            result = self.nodes[0].getblockstats(hash_or_height=(self.start_height + i), stats=[stat])
            assert_equal(list(result.keys()), [stat])
            if (result[stat] != self.expected_stats[i][stat]):
                self.log.info(('result[%s] (%d) failed, %r != %r' % (stat, i, result[stat], self.expected_stats[i][stat])))
            assert_equal(result[stat], self.expected_stats[i][stat])
    some_stats = {'minfee', 'maxfee'}
    stats = self.nodes[0].getblockstats(hash_or_height=1, stats=list(some_stats))
    assert_equal(set(stats.keys()), some_stats)
    tip = (self.start_height + self.max_stat_pos)
    assert_raises_rpc_error((- 8), ('Target block height %d after current tip %d' % ((tip + 1), tip)), self.nodes[0].getblockstats, hash_or_height=(tip + 1))
    assert_raises_rpc_error((- 8), ('Target block height %d is negative' % (- 1)), self.nodes[0].getblockstats, hash_or_height=(- 1))
    inv_sel_stat = 'asdfghjkl'
    inv_stats = [[inv_sel_stat], ['minfee', inv_sel_stat], [inv_sel_stat, 'minfee'], ['minfee', inv_sel_stat, 'maxfee']]
    for inv_stat in inv_stats:
        assert_raises_rpc_error((- 8), ('Invalid selected statistic %s' % inv_sel_stat), self.nodes[0].getblockstats, hash_or_height=1, stats=inv_stat)
    assert_raises_rpc_error((- 8), ('Invalid selected statistic aaa%s' % inv_sel_stat), self.nodes[0].getblockstats, hash_or_height=1, stats=['minfee', ('aaa%s' % inv_sel_stat)])
    assert_raises_rpc_error((- 5), 'Block not found', self.nodes[0].getblockstats, hash_or_height='000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f')
    assert_raises_rpc_error((- 1), 'getblockstats hash_or_height ( stats )', self.nodes[0].getblockstats, '00', 1, 2)
    assert_raises_rpc_error((- 1), 'getblockstats hash_or_height ( stats )', self.nodes[0].getblockstats)