def _restart_init_test(self): self.SIZE = 20 self.addr0 = self.nodes[0].getnewaddress() # 100 blocks without endorsements self.nodes[0].generate(nblocks=100) self.log.info("node0 started mining of {} endorsed blocks".format( self.SIZE)) create_endorsed_chain(self.nodes[0], self.apm, self.SIZE, self.addr0) self.log.info("node0 finished creation of {} endorsed blocks".format( self.SIZE)) self.sync_blocks(self.nodes) self.log.info("nodes are in sync") # stop node0 self.restart_node(0) self.restart_node(1) self.log.info("nodes[0,1] restarted") self.sync_all(self.nodes, timeout=30) self.log.info("nodes are in sync") bestblocks = [self.get_best_block(x) for x in self.nodes] popdata = [ x.getpopdatabyheight(bestblocks[0]['height']) for x in self.nodes ] # when node0 stops, its VBK/BTC trees get cleared. When we start it again, it MUST load payloads into trees. # if this assert fails, it means that node restarted, but NOT loaded its VBK/BTC state into memory. # node[2] is a control node that has never been shut down. assert_equal(popdata[0], popdata[2]) assert_equal(popdata[1], popdata[2]) self.log.warning("success! _restart_init_test()")
def run_test(self): """Main test logic""" from pypoptools.pypopminer import MockMiner self.apm = MockMiner() self.addrs = [x.getnewaddress() for x in self.nodes] self.endorsed_length = 100 assert_pop_state_equal(self.nodes) create_endorsed_chain(self.nodes[0], self.apm, self.endorsed_length, self.addrs[0]) self.sync_all(self.nodes, timeout=20) assert_pop_state_equal(self.nodes) checkblocks = 0 # all blocks # 0, 1, 2, 3, 4 for checklevel in range(5): self.log.info("checkblocks={} checklevel={}".format(checkblocks, checklevel)) self.restart_node(0, extra_args=[ "-checkblocks={}".format(checkblocks), "-checklevel={}".format(checklevel) ]) connect_nodes(self.nodes[0], 1) self.sync_all(self.nodes, timeout=120) assert_pop_state_equal(self.nodes) self.log.info("success")
def run_test(self): """Main test logic""" from pypoptools.pypopminer import MockMiner self.apm = MockMiner() node = self.nodes[0] addr = node.getnewaddress() # stop 1 block behind activation self.log.info("Mining blocks until activation -5 blocks") self.log.info("Current node[0] height {}".format(node.getblockcount())) mine_until_pop_active(node, addr, delta=-5) self.log.info("Current node[0] height {}".format(node.getblockcount())) # check that getblocktemplate does NOT have pop-related fields before POP activation self.log.info("Check that getblocktemplate does not have POP fields") resp = self.getblocktemplate() assert_no_field(resp, 'pop_data') assert_no_field(resp, 'pop_data_root') assert_no_field(resp, 'pop_first_previous_keystone') assert_no_field(resp, 'pop_second_previous_keystone') assert_no_field(resp, 'pop_rewards') self.log.info("Mining blocks until activation +5 blocks") self.log.info("Current node[0] height {}".format(node.getblockcount())) mine_until_pop_active(node, addr, delta=+5) self.log.info("Current node[0] height {}".format(node.getblockcount())) self.log.info("Mine chain of {} consecutive endorsed blocks".format( POP_PAYOUT_DELAY)) create_endorsed_chain(node, self.apm, POP_PAYOUT_DELAY, addr) self.log.info("Current node[0] height {}".format(node.getblockcount())) endorse_block(self.nodes[0], self.apm, node.getblockcount() - 5, addr) self.log.info("Current node[0] height {}".format(node.getblockcount())) self.log.info("Check that getblocktemplate does have POP fields") resp = self.getblocktemplate() is_dict = lambda x: isinstance(x, dict) is_list = lambda x: isinstance(x, list) is_int = lambda x: isinstance(x, int) is_hex = lambda x: bytes.fromhex(x) is_payload = lambda x: is_dict(x) and "id" in x and "serialized" in x is_payload_list = lambda x: is_list(x) and all( is_payload(p) for p in x) assert_field_exists(resp, 'pop_data', type=is_dict) assert_field_exists(resp['pop_data'], 'atvs', type=is_payload_list) assert_field_exists(resp['pop_data'], 'vtbs', type=is_payload_list) assert_field_exists(resp['pop_data'], 'vbkblocks', type=is_payload_list) assert_field_exists(resp['pop_data'], 'version', type=is_int) assert_field_exists(resp, 'pop_data_root', type=is_hex) assert_field_exists(resp, 'pop_first_previous_keystone', type=is_hex) assert_field_exists(resp, 'pop_second_previous_keystone', type=is_hex) assert_field_exists(resp, 'pop_rewards', type=is_list) for reward in resp['pop_rewards']: assert_field_exists(reward, 'amount', type=is_int) assert_field_exists(reward, 'payout_info', type=is_hex) self.log.info("Current node[0] height {}".format(node.getblockcount()))
def _4_chains_converge(self): self.log.warning("_4_chains_converge() started!") # disconnect all nodes for i in range(self.num_nodes): for node in self.nodes: disconnect_nodes(node, i) self.log.info("all nodes disconnected") lastblock = self.nodes[3].getblockcount() # node[i] creates endorsed chain toMine = 15 for i, node in enumerate(self.nodes): self.log.info( "node[{}] started to create endorsed chain of {} blocks". format(i, toMine)) addr = node.getnewaddress() create_endorsed_chain(node, self.apm, toMine, addr) # all nodes have different tips at height 303 + keystone interval bestblocks = [self.get_best_block(x) for x in self.nodes] for b in bestblocks: assert b['height'] == lastblock + toMine assert len(set([x['hash'] for x in bestblocks])) == len(bestblocks) self.log.info("all nodes have different tips") # connect all nodes to each other for i in range(self.num_nodes): for node in self.nodes: connect_nodes(node, i) self.log.info("all nodes connected") self.sync_blocks(self.nodes, timeout=60) self.sync_pop_tips(self.nodes, timeout=60) self.log.info("all nodes have common tip") expected_best = bestblocks[0] bestblocks = [self.get_best_block(x) for x in self.nodes] for best in bestblocks: assert_equal(best, expected_best) self.log.warning("_4_chains_converge() succeeded!")