From 86525a0afd0146681badff73cdb5b937617e5d70 Mon Sep 17 00:00:00 2001 From: "Mark A. Greenslade" Date: Thu, 11 Feb 2021 21:56:44 +0100 Subject: [PATCH] 1. Fixed account creation issue in wg-101 & wg-111. --- sh/scripts/cache_register_nctl.py | 2 +- stests/core/crypto/hashifier.py | 12 ++++++---- stests/generators/utils/accounts.py | 23 ++++++++++++++----- stests/generators/wg_101/p1s1_do_transfers.py | 6 +++-- stests/generators/wg_111/p1s1_do_transfers.py | 6 +++-- 5 files changed, 33 insertions(+), 16 deletions(-) diff --git a/sh/scripts/cache_register_nctl.py b/sh/scripts/cache_register_nctl.py index 319337de..aca88f09 100644 --- a/sh/scripts/cache_register_nctl.py +++ b/sh/scripts/cache_register_nctl.py @@ -152,7 +152,7 @@ def _get_artefacts_node(path: pathlib.Path) -> typing.Tuple[int, dict, pathlib.P """ # Set path to config. - path_cfg = path / "config" / "node-config.toml" + path_cfg = path / "config" / "1_0_0" / "config.toml" if not path_cfg.exists(): raise ValueError(f"Invalid nctl node - node config toml file not found: {path}") diff --git a/stests/core/crypto/hashifier.py b/stests/core/crypto/hashifier.py index 35e6ab14..9ed79df5 100644 --- a/stests/core/crypto/hashifier.py +++ b/stests/core/crypto/hashifier.py @@ -11,6 +11,11 @@ HashAlgorithm.BLAKE2B: blake2b, } +ENCODERS = { + HashEncoding.BYTES: lambda x: x, + HashEncoding.HEX: lambda x: x.hex(), +} + def get_hash( data: bytes, @@ -25,10 +30,7 @@ def get_hash( :param algo: Type of hashing algo to apply. :param encoding: Hash output encoding type. - :returns: Hash of input data. + :returns: Encoded hash of input data. """ - algo = ALGOS[algo] - hashed_data = algo.get_hash(data, size) - - return hashed_data if encoding == HashEncoding.BYTES else hashed_data.hex() + return ENCODERS[encoding](ALGOS[algo].get_hash(data, size)) diff --git a/stests/generators/utils/accounts.py b/stests/generators/utils/accounts.py index c878ed38..6a9a34ea 100644 --- a/stests/generators/utils/accounts.py +++ b/stests/generators/utils/accounts.py @@ -100,23 +100,20 @@ def do_transfer( def do_transfer_fire_forget( ctx: ExecutionContext, - cp1_index: int, - cp2_index: int, + cp2: Account, amount: int, transfer_type: DeployType, ): """Executes fire & forget token transfers between counter-parties. :param ctx: Execution context information. - :param cp1_index: Account index of counter-party 1. - :param cp2_range: Account indexes of counter-party 2. + :param cp2: Counter-party 2 account. :param amount: Amount (in motes) to transfer. :param transfer_type: Type of transfer to dispatch. """ network, node = get_network_node(ctx) - cp1 = get_account(ctx, network, cp1_index) - cp2 = factory.create_account_for_run(ctx, cp2_index) + cp1 = get_account(ctx, network, get_account_idx_for_network_faucet()) dispatch_info = chain.DeployDispatchInfo(cp1, network, node) dispatch_fn = TFR_TYPE_TO_TFR_FN[transfer_type] dispatch_fn(dispatch_info, cp2, amount) @@ -194,6 +191,20 @@ def get_account_range(accounts: int, deploys: int) -> int: return range(1, (deploys if accounts == 0 else accounts) + 1) +def get_account_set(ctx: ExecutionContext, accounts: int, deploys: int) -> int: + """Returns run specific faucet account index whcn dispatching a deploy batch. + + :param ctx: Execution context information. + :param accounts: Number of accounts within batch. + :param deploys: Number of deploys within batch. + :returns: Set of accounts to act as transfer targets. + + """ + account_range = range(deploys) if accounts == 0 else range(accounts) + + return [factory.create_account_for_run(ctx, i + 1) for i in account_range] + + def get_account_deploy_count(accounts: int, account_idx: int, deploys: int) -> int: """Returns account index to use for a particular transfer. diff --git a/stests/generators/wg_101/p1s1_do_transfers.py b/stests/generators/wg_101/p1s1_do_transfers.py index 80c0c013..0f4016d4 100644 --- a/stests/generators/wg_101/p1s1_do_transfers.py +++ b/stests/generators/wg_101/p1s1_do_transfers.py @@ -1,5 +1,6 @@ import typing +from stests.core import factory from stests.core.types.chain import DeployType from stests.core.types.orchestration import ExecutionContext from stests.generators.utils import accounts @@ -17,11 +18,12 @@ def execute(ctx: ExecutionContext): :returns: 3 member tuple -> actor, message count, message arg factory. """ + account_set = accounts.get_account_set(ctx, ctx.args.accounts, ctx.args.transfers) for deploy_idx in range(1, ctx.args.transfers + 1): + account_idx = accounts.get_account_idx_for_deploy(ctx.args.accounts, deploy_idx) accounts.do_transfer_fire_forget( ctx, - accounts.get_account_idx_for_network_faucet(), - accounts.get_account_idx_for_deploy(ctx.args.accounts, deploy_idx), + account_set[account_idx - 1], ctx.args.amount, DeployType.TRANSFER_NATIVE, ) diff --git a/stests/generators/wg_111/p1s1_do_transfers.py b/stests/generators/wg_111/p1s1_do_transfers.py index bc82f182..84fb4d56 100644 --- a/stests/generators/wg_111/p1s1_do_transfers.py +++ b/stests/generators/wg_111/p1s1_do_transfers.py @@ -1,5 +1,6 @@ import typing +from stests.core import factory from stests.core.types.chain import DeployType from stests.core.types.orchestration import ExecutionContext from stests.generators.utils import accounts @@ -17,11 +18,12 @@ def execute(ctx: ExecutionContext): :returns: 3 member tuple -> actor, message count, message arg factory. """ + account_set = accounts.get_account_set(ctx, ctx.args.accounts, ctx.args.transfers) for deploy_idx in range(1, ctx.args.transfers + 1): + account_idx = accounts.get_account_idx_for_deploy(ctx.args.accounts, deploy_idx) accounts.do_transfer_fire_forget( ctx, - accounts.get_account_idx_for_network_faucet(), - accounts.get_account_idx_for_deploy(ctx.args.accounts, deploy_idx), + account_set[account_idx - 1], ctx.args.amount, DeployType.TRANSFER_WASM, )