diff --git a/cardano_node_tests/cluster_management/cluster_getter.py b/cardano_node_tests/cluster_management/cluster_getter.py index 247739760..bbfc79a5b 100644 --- a/cardano_node_tests/cluster_management/cluster_getter.py +++ b/cardano_node_tests/cluster_management/cluster_getter.py @@ -256,8 +256,12 @@ def _respin(self, start_cmd: str = "", stop_cmd: str = "") -> bool: # noqa: C90 fp_out.write(cluster_instance_id) self.log(f"c{self.cluster_instance_num}: started cluster instance '{cluster_instance_id}'") - # Create dir for faucet addresses data - addr_data_dir = state_dir / common.ADDRS_DATA_DIRNAME + # Create dir for faucet addresses data among tests artifacts, so it can be accessed + # during testnet cleanup. + addr_data_dir = ( + temptools.get_pytest_worker_tmp() + / f"{common.ADDRS_DATA_DIRNAME}_ci{self.cluster_instance_num}" + ) addr_data_dir.mkdir(parents=True, exist_ok=True) # Setup faucet addresses diff --git a/cardano_node_tests/utils/cluster_nodes.py b/cardano_node_tests/utils/cluster_nodes.py index 83aca2f78..0a56cbf05 100644 --- a/cardano_node_tests/utils/cluster_nodes.py +++ b/cardano_node_tests/utils/cluster_nodes.py @@ -54,7 +54,13 @@ class ClusterType: LOCAL: tp.Final[str] = "local" TESTNET: tp.Final[str] = "testnet" - test_addr_records: tp.ClassVar[tp.Tuple[str, ...]] = ("user1",) + test_addr_records: tp.ClassVar[tp.Tuple[str, ...]] = ( + "user1", + "user2", + "user3", + "user4", + "user5", + ) NODES: tp.ClassVar[tp.Set[str]] = set() @@ -129,7 +135,7 @@ def create_addrs_data( cluster_env = get_cluster_env() instance_num = cluster_env.instance_num - # create new addresses + # Create new addresses new_addrs_data: tp.Dict[str, tp.Dict[str, tp.Any]] = {} for addr_name in self.test_addr_records: addr_name_instance = f"{addr_name}_ci{instance_num}" @@ -141,7 +147,7 @@ def create_addrs_data( "payment": payment, } - # create records for existing addresses + # Create records for existing addresses faucet_addrs_data: tp.Dict[str, tp.Dict[str, tp.Any]] = {"faucet": {"payment": None}} byron_dir = cluster_env.state_dir / "byron" shelley_dir = cluster_env.state_dir / "shelley" @@ -162,14 +168,15 @@ def create_addrs_data( msg = "Faucet address file doesn't exist." raise RuntimeError(msg) - # fund new addresses from faucet address + # Fund new addresses from faucet address LOGGER.debug("Funding created addresses.") to_fund = [d["payment"] for d in new_addrs_data.values()] + amount_per_address = 100_000_000_000_000 // len(self.test_addr_records) faucet.fund_from_faucet( *to_fund, cluster_obj=cluster_obj, faucet_data=faucet_addrs_data["faucet"], - amount=100_000_000_000_000, + amount=amount_per_address, destination_dir=destination_dir, force=True, ) @@ -238,19 +245,43 @@ def create_addrs_data( destination_dir: clusterlib.FileType = ".", ) -> tp.Dict[str, tp.Dict[str, tp.Any]]: """Create addresses and their keys for usage in tests.""" + # Store record of the original faucet address shelley_dir = get_cluster_env().state_dir / "shelley" + faucet_rec = clusterlib.AddressRecord( + address=clusterlib.read_address_from_file(shelley_dir / "faucet.addr"), + vkey_file=shelley_dir / "faucet.vkey", + skey_file=shelley_dir / "faucet.skey", + ) + faucet_addrs_data: tp.Dict[str, tp.Dict[str, tp.Any]] = { + self.test_addr_records[1]: {"payment": faucet_rec} + } - addrs_data: tp.Dict[str, tp.Dict[str, tp.Any]] = {} - for addr_name in self.test_addr_records: - faucet_addr = { - "payment": clusterlib.AddressRecord( - address=clusterlib.read_address_from_file(shelley_dir / "faucet.addr"), - vkey_file=shelley_dir / "faucet.vkey", - skey_file=shelley_dir / "faucet.skey", - ) + # Create new addresses + new_addrs_data: tp.Dict[str, tp.Dict[str, tp.Any]] = {} + for addr_name in self.test_addr_records[1:]: + payment = cluster_obj.g_address.gen_payment_addr_and_keys( + name=addr_name, + destination_dir=destination_dir, + ) + new_addrs_data[addr_name] = { + "payment": payment, } - addrs_data[addr_name] = faucet_addr + # Fund new addresses from faucet address + LOGGER.debug("Funding created addresses.") + to_fund = [d["payment"] for d in new_addrs_data.values()] + faucet_balance = cluster_obj.g_query.get_address_balance(address=faucet_rec.address) + amount_per_address = faucet_balance // len(self.test_addr_records) + faucet.fund_from_faucet( + *to_fund, + cluster_obj=cluster_obj, + faucet_data=faucet_addrs_data[self.test_addr_records[1]], + amount=amount_per_address, + destination_dir=destination_dir, + force=True, + ) + + addrs_data = {**new_addrs_data, **faucet_addrs_data} return addrs_data