Changeset View
Changeset View
Standalone View
Standalone View
test/functional/rpc_getblockstats.py
Show First 20 Lines • Show All 54 Lines • ▼ Show 20 Lines | def add_options(self, parser): | ||||
help='Test data file') | help='Test data file') | ||||
def set_test_params(self): | def set_test_params(self): | ||||
self.num_nodes = 2 | self.num_nodes = 2 | ||||
self.extra_args = [['-txindex'], ['-paytxfee=0.003']] | self.extra_args = [['-txindex'], ['-paytxfee=0.003']] | ||||
self.setup_clean_chain = True | self.setup_clean_chain = True | ||||
def get_stats(self): | def get_stats(self): | ||||
return [self.nodes[0].getblockstats(hash_or_height=self.start_height + i) for i in range(self.max_stat_pos + 1)] | return [self.nodes[0].getblockstats( | ||||
hash_or_height=self.start_height + i) for i in range(self.max_stat_pos + 1)] | |||||
def generate_test_data(self, filename): | def generate_test_data(self, filename): | ||||
mocktime = time.time() | mocktime = time.time() | ||||
self.nodes[0].generate(101) | self.nodes[0].generate(101) | ||||
self.nodes[0].sendtoaddress( | self.nodes[0].sendtoaddress( | ||||
address=self.nodes[1].getnewaddress(), amount=10, subtractfeefromamount=True) | address=self.nodes[1].getnewaddress(), amount=10, subtractfeefromamount=True) | ||||
self.nodes[0].generate(1) | self.nodes[0].generate(1) | ||||
Show All 31 Lines | class GetblockstatsTest(BitcoinTestFramework): | ||||
def load_test_data(self, filename): | def load_test_data(self, filename): | ||||
with open(filename, 'r', encoding="utf8") as f: | with open(filename, 'r', encoding="utf8") as f: | ||||
d = json.load(f, parse_float=decimal.Decimal) | d = json.load(f, parse_float=decimal.Decimal) | ||||
blocks = d['blocks'] | blocks = d['blocks'] | ||||
mocktime = d['mocktime'] | mocktime = d['mocktime'] | ||||
self.expected_stats = d['stats'] | self.expected_stats = d['stats'] | ||||
self.log.info(self.expected_stats) | self.log.info(self.expected_stats) | ||||
# Set the timestamps from the file so that the nodes can get out of Initial Block Download | # Set the timestamps from the file so that the nodes can get out of | ||||
# Initial Block Download | |||||
self.nodes[0].setmocktime(mocktime) | self.nodes[0].setmocktime(mocktime) | ||||
self.nodes[1].setmocktime(mocktime) | self.nodes[1].setmocktime(mocktime) | ||||
for i, b in enumerate(blocks): | for i, b in enumerate(blocks): | ||||
self.nodes[0].submitblock(b) | self.nodes[0].submitblock(b) | ||||
def run_test(self): | def run_test(self): | ||||
test_data = os.path.join(TESTSDIR, self.options.test_data) | test_data = os.path.join(TESTSDIR, self.options.test_data) | ||||
▲ Show 20 Lines • Show All 85 Lines • Show Last 20 Lines |