def start_node(self, num, processors, peering, schedulers, poet_kwargs): LOGGER.info('Starting node %s', num) sawtooth_home = mkdtemp() with SetSawtoothHome(sawtooth_home): processes = NodeController.start_node( num, processors, peering, schedulers, sawtooth_home, NodeController.validator_cmds, poet_kwargs) # Check that none of the processes have returned for proc in processes: if proc.returncode is not None: raise subprocess.CalledProcessError(proc.pid, proc.returncode) self.nodes[num] = processes self.clients[num] = IntkeyClient(NodeController.http_address(num), WAIT) time.sleep(1)
def test_network_trust_permissioning(self): """Test the network "trust" permissioning role. Notes: 1) Create a network of 2 validators. 2) Assert that 2 blocks of consensus happens within 200s 3) Add a policy that denies the non-genesis validator from the network role. 4) Assert that the validators get 2 blocks out of consensus. 5) Add a new policy that allows both validators to use the network role. 6) Assert that the validators come back into consensus within 200s. 7) Add a policy that denies the non-genesis validator from the network.consensus role. 8) Assert that the validators get 2 blocks out of consensus. 9) Add a policy that allows both validators to use the network.consensus role. 10) Assert that the validators come back into consensus """ walter = Admin("http://127.0.0.1:{}".format(8008 + 0)) sawtooth_home0 = mkdtemp() self.sawtooth_home[0] = sawtooth_home0 sawtooth_home1 = mkdtemp() self.sawtooth_home[1] = sawtooth_home1 with SetSawtoothHome(sawtooth_home0): write_validator_config( sawtooth_home0, roles={"network": "trust"}, endpoint="tcp://127.0.0.1:{}".format(8800 + 0), bind=["network:tcp://127.0.0.1:{}".format(8800 + 0), "component:tcp://127.0.0.1:{}".format(4004 + 0)], seeds=["tcp://127.0.0.1:{}".format(8800 + 1)], peering="dynamic", scheduler='parallel') validator_non_genesis_init(sawtooth_home1) validator_genesis_init(sawtooth_home0, sawtooth_home1, identity_pub_key=walter.pub_key, role="network") self.processes.extend(start_validator(0, sawtooth_home0)) self.clients.append(Client(NodeController.http_address(0))) with SetSawtoothHome(sawtooth_home1): write_validator_config( sawtooth_home1, roles={"network": "trust"}, endpoint="tcp://127.0.0.1:{}".format(8800 + 1), bind=["network:tcp://127.0.0.1:{}".format(8800 + 1), "component:tcp://127.0.0.1:{}".format(4004 + 1)], peering="dynamic", seeds=["tcp://127.0.0.1:{}".format(8800 + 0)], scheduler='parallel') self.processes.extend(start_validator(1, sawtooth_home1)) self.clients.append(Client(NodeController.http_address(1))) with open(os.path.join(self.sawtooth_home[1], 'keys', 'validator.pub'), 'r') as infile: non_genesis_key = infile.read().strip('\n') with open(os.path.join(self.sawtooth_home[0], 'keys', 'validator.pub'), 'r') as infile: genesis_key = infile.read().strip('\n') wait_for_consensus(self.clients, amount=2) walter.set_public_key_for_role( "non_genesis_out_of_network", "network", permit_keys=[genesis_key], deny_keys=[non_genesis_key]) wait_for_out_of_consensus(self.clients, tolerance=2) show_blocks(self.clients[0].block_list()) show_blocks(self.clients[1].block_list()) walter.set_public_key_for_role( "allow_all", "network", permit_keys=[genesis_key, non_genesis_key], deny_keys=[]) wait_for_consensus(self.clients) show_blocks(self.clients[0].block_list()) show_blocks(self.clients[1].block_list()) walter.set_public_key_for_role( "non_genesis_out_of_network", "network.consensus", permit_keys=[genesis_key], deny_keys=[non_genesis_key]) wait_for_out_of_consensus(self.clients, tolerance=2) show_blocks(self.clients[0].block_list()) show_blocks(self.clients[1].block_list()) walter.set_public_key_for_role( "allow_all_for_consensus", "network.consensus", permit_keys=[genesis_key, non_genesis_key], deny_keys=[]) wait_for_consensus(self.clients) show_blocks(self.clients[0].block_list()) show_blocks(self.clients[1].block_list())