Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
post merge
  • Loading branch information
Mark A. Greenslade committed Feb 11, 2021
2 parents de5efd3 + 86525a0 commit ad8724e
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 15 deletions.
12 changes: 7 additions & 5 deletions stests/core/crypto/hashifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
HashAlgorithm.BLAKE2B: blake2b,
}

ENCODERS = {
HashEncoding.BYTES: lambda x: x,
HashEncoding.HEX: lambda x: x.hex(),
}


def get_hash(
data: bytes,
Expand All @@ -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))
23 changes: 17 additions & 6 deletions stests/generators/utils/accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Expand Down
6 changes: 4 additions & 2 deletions stests/generators/wg_101/p1s1_do_transfers.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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,
)
6 changes: 4 additions & 2 deletions stests/generators/wg_111/p1s1_do_transfers.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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,
)

0 comments on commit ad8724e

Please sign in to comment.