Skip to content

Commit

Permalink
Improve tests, add more tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
andreibancioiu committed Oct 16, 2024
1 parent 3b541b9 commit 4ce11ad
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 10 deletions.
1 change: 1 addition & 0 deletions systemtests/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class Configuration:
memento_file: str = ""
sponsor_secret_key: bytes = bytes.fromhex(os.environ.get("SPONSOR_SECRET_KEY", ""))
users_mnemonic: str = os.environ.get("USERS_MNEMONIC", "")
num_users: int = 128


CONFIGURATIONS = {
Expand Down
42 changes: 32 additions & 10 deletions systemtests/generate_testdata_on_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def do_run(args: Any):
), await_completion=True)

print("## Cross-shard, transfer & execute with native & custom transfer")
controller.send(controller.create_native_transfer_within_multiesdt_transfer_and_execute(
controller.send(controller.create_transfer_and_execute(
sender=accounts.get_user(shard=0, index=1),
contract=accounts.get_contract_address("dummy", shard=0, index=0),
function="doSomething",
Expand All @@ -169,7 +169,7 @@ def do_run(args: Any):
), await_completion=True)

print("## Intra-shard, transfer & execute with native & custom transfer")
controller.send(controller.create_native_transfer_within_multiesdt_transfer_and_execute(
controller.send(controller.create_transfer_and_execute(
sender=accounts.get_user(shard=0, index=3),
contract=accounts.get_contract_address("dummy", shard=0, index=0),
function="doSomething",
Expand All @@ -182,15 +182,15 @@ def do_run(args: Any):
controller.create_relayed_v3_with_inner_transactions(
relayer=accounts.get_user(shard=0, index=0),
inner_transactions=[
controller.create_native_transfer_within_multiesdt_transfer_and_execute(
controller.create_transfer_and_execute(
sender=accounts.get_user(shard=0, index=1),
contract=accounts.get_contract_address("dummy", shard=2, index=0),
function="doSomething",
native_amount=42,
custom_amount=7,
seal_for_broadcast=False,
),
controller.create_native_transfer_within_multiesdt_transfer_and_execute(
controller.create_transfer_and_execute(
sender=accounts.get_user(shard=0, index=2),
contract=accounts.get_contract_address("dummy", shard=2, index=0),
function="doNothing",
Expand All @@ -208,15 +208,15 @@ def do_run(args: Any):
controller.create_relayed_v3_with_inner_transactions(
relayer=accounts.get_user(shard=0, index=0),
inner_transactions=[
controller.create_native_transfer_within_multiesdt_transfer_and_execute(
controller.create_transfer_and_execute(
sender=accounts.get_user(shard=0, index=2),
contract=accounts.get_contract_address("dummy", shard=0, index=0),
function="doSomething",
native_amount=42,
custom_amount=7,
seal_for_broadcast=False,
),
controller.create_native_transfer_within_multiesdt_transfer_and_execute(
controller.create_transfer_and_execute(
sender=accounts.get_user(shard=0, index=3),
contract=accounts.get_contract_address("dummy", shard=0, index=0),
function="doNothing",
Expand All @@ -229,6 +229,24 @@ def do_run(args: Any):
await_completion=True
)

print("## Intra-shard, transfer & execute with native transfer, with signal error, wrapped in Relayed V3")
controller.send(
controller.create_relayed_v3_with_inner_transactions(
relayer=accounts.get_user(shard=0, index=0),
inner_transactions=[
controller.create_transfer_and_execute(
sender=accounts.get_user(shard=0, index=3),
contract=accounts.get_contract_address("dummy", shard=0, index=0),
function="doNothing",
native_amount=42,
custom_amount=0,
seal_for_broadcast=False
)
]
),
await_completion=True
)

print("## Intra-shard, relayed v1 transaction with MoveBalance")
controller.send(controller.create_relayed_v1_with_move_balance(
relayer=accounts.get_user(shard=0, index=0),
Expand Down Expand Up @@ -437,7 +455,7 @@ def __init__(self, configuration: Configuration, memento: "Memento") -> None:
self.users_by_bech32: Dict[str, Account] = {}
self.contracts: List[SmartContract] = []

for i in range(128):
for i in range(configuration.num_users):
user = self._create_user(i)
self.users.append(user)
self.users_by_bech32[user.address.to_bech32()] = user
Expand Down Expand Up @@ -834,16 +852,20 @@ def create_native_transfer_within_multiesdt_fuzzy(self, sender: "Account", recei

return transaction

def create_native_transfer_within_multiesdt_transfer_and_execute(self, sender: "Account", contract: Address, function: str, native_amount: int, custom_amount: int, seal_for_broadcast: bool = True) -> Transaction:
custom_currency = self.memento.get_custom_currencies()[0]
def create_transfer_and_execute(self, sender: "Account", contract: Address, function: str, native_amount: int, custom_amount: int, seal_for_broadcast: bool = True) -> Transaction:
token_transfers: List[TokenTransfer] = []

if custom_amount:
custom_currency = self.memento.get_custom_currencies()[0]
token_transfers = [TokenTransfer(Token(custom_currency), custom_amount)]

transaction = self.contracts_transactions_factory.create_transaction_for_execute(
sender=sender.address,
contract=contract,
function=function,
gas_limit=3000000,
native_transfer_amount=native_amount,
token_transfers=[TokenTransfer(Token(custom_currency), custom_amount)]
token_transfers=token_transfers
)

if seal_for_broadcast:
Expand Down

0 comments on commit 4ce11ad

Please sign in to comment.