Skip to content

Commit

Permalink
Improve system tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
andreibancioiu committed Oct 9, 2024
1 parent bc89fab commit ff27144
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 38 deletions.
Binary file modified systemtests/contracts/dummy.wasm
Binary file not shown.
84 changes: 46 additions & 38 deletions systemtests/generate_testdata_on_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,78 +77,78 @@ def do_run(args: Any):
controller.send(controller.create_simple_move_balance_with_refund(
sender=accounts.get_user(shard=0, index=0),
receiver=accounts.get_user(shard=0, index=1).address,
))
), await_completion=True)

print("## Cross-shard, simple MoveBalance with refund")
controller.send(controller.create_simple_move_balance_with_refund(
sender=accounts.get_user(shard=0, index=1),
receiver=accounts.get_user(shard=1, index=0).address,
))
), await_completion=True)

print("## Intra-shard, invalid MoveBalance with refund")
controller.send(controller.create_invalid_move_balance_with_refund(
sender=accounts.get_user(shard=0, index=2),
receiver=accounts.get_user(shard=0, index=3).address,
))
), await_completion=True)

print("## Cross-shard, invalid MoveBalance with refund")
controller.send(controller.create_invalid_move_balance_with_refund(
sender=accounts.get_user(shard=0, index=4),
receiver=accounts.get_user(shard=1, index=1).address,
))
), await_completion=True)

print("## Intra-shard, sending value to non-payable contract")
controller.send(controller.create_simple_move_balance_with_refund(
sender=accounts.get_user(shard=0, index=0),
receiver=accounts.get_contract_address("adder", 0, 0),
))
), await_completion=True)

print("## Cross-shard, sending value to non-payable contract")
controller.send(controller.create_simple_move_balance_with_refund(
sender=accounts.get_user(shard=0, index=1),
receiver=accounts.get_contract_address("adder", 1, 0),
))
), await_completion=True)

print("## Intra-shard, native transfer within MultiESDTTransfer")
controller.send(controller.create_native_transfer_within_multiesdt(
sender=accounts.get_user(shard=0, index=0),
receiver=accounts.get_user(shard=0, index=1).address,
native_amount=42,
custom_amount=7
))
), await_completion=True)

print("## Cross-shard, native transfer within MultiESDTTransfer")
controller.send(controller.create_native_transfer_within_multiesdt(
sender=accounts.get_user(shard=0, index=1),
receiver=accounts.get_user(shard=1, index=0).address,
native_amount=42,
custom_amount=7
))
), await_completion=True)

print("## Intra-shard, native transfer within MultiESDTTransfer, towards non-payable contract")
controller.send(controller.create_native_transfer_within_multiesdt(
sender=accounts.get_user(shard=0, index=0),
receiver=accounts.get_contract_address("adder", 0, 0),
native_amount=42,
custom_amount=7
))
), await_completion=True)

print("## Cross-shard, native transfer within MultiESDTTransfer, towards non-payable contract")
controller.send(controller.create_native_transfer_within_multiesdt(
sender=accounts.get_user(shard=0, index=1),
receiver=accounts.get_contract_address("adder", 1, 0),
native_amount=42,
custom_amount=7
))
), await_completion=True)

print("## Cross-shard, transfer & execute with native & custom transfer")
controller.send(controller.create_native_transfer_within_multiesdt_transfer_and_execute(
sender=accounts.get_user(shard=0, index=1),
contract=accounts.get_contract_address("dummy", shard=2, index=0),
contract=accounts.get_contract_address("dummy", shard=0, index=0),
function="doSomething",
native_amount=42,
custom_amount=7,
))
), await_completion=True)

print("## Intra-shard, transfer & execute with native & custom transfer")
controller.send(controller.create_native_transfer_within_multiesdt_transfer_and_execute(
Expand All @@ -157,7 +157,7 @@ def do_run(args: Any):
function="doSomething",
native_amount=42,
custom_amount=7,
))
), await_completion=True)

print("## Cross-shard, transfer & execute with native & custom transfer, wrapped in Relayed V3")
controller.send(
Expand All @@ -181,7 +181,8 @@ def do_run(args: Any):
seal_for_broadcast=False
)
]
)
),
await_completion=True
)

print("## Intra-shard, transfer & execute with native & custom transfer, wrapped in Relayed V3")
Expand All @@ -206,7 +207,8 @@ def do_run(args: Any):
seal_for_broadcast=False
)
]
)
),
await_completion=True
)

print("## Intra-shard, relayed v1 transaction with MoveBalance")
Expand All @@ -215,55 +217,55 @@ def do_run(args: Any):
sender=accounts.get_user(shard=0, index=1),
receiver=accounts.get_user(shard=0, index=2).address,
amount=42
))
), await_completion=True)

print("## Relayed v3, senders and receivers in same shard")
controller.send(controller.create_relayed_v3_with_a_few_inner_move_balances(
relayer=accounts.get_user(shard=0, index=0),
senders=accounts.get_users_by_shard(0)[1:3],
receivers=[account.address for account in accounts.get_users_by_shard(0)[3:5]],
amount=42
))
), await_completion=True)

print("## Relayed v3, senders and receivers in different shards")
controller.send(controller.create_relayed_v3_with_a_few_inner_move_balances(
relayer=accounts.get_user(shard=0, index=0),
senders=accounts.get_users_by_shard(0)[1:3],
receivers=[account.address for account in accounts.get_users_by_shard(1)[3:5]],
amount=42
))
), await_completion=True)

print("## Relayed v3, senders and receivers in same shard (insufficient balance)")
controller.send(controller.create_relayed_v3_with_a_few_inner_move_balances(
relayer=accounts.get_user(shard=0, index=0),
senders=accounts.get_users_by_shard(0)[1:3],
receivers=[account.address for account in accounts.get_users_by_shard(0)[3:5]],
amount=1000000000000000000000
))
), await_completion=True)

print("## Relayed v3, senders and receivers in different shards (insufficient balance)")
controller.send(controller.create_relayed_v3_with_a_few_inner_move_balances(
relayer=accounts.get_user(shard=0, index=0),
senders=accounts.get_users_by_shard(0)[1:3],
receivers=[account.address for account in accounts.get_users_by_shard(1)[3:5]],
amount=1000000000000000000000
))
), await_completion=True)

print("## Relayed v3, senders and receivers in same shard, sending to non-payable contract")
controller.send(controller.create_relayed_v3_with_a_few_inner_move_balances(
relayer=accounts.get_user(shard=0, index=0),
senders=[accounts.get_user(shard=0, index=5)],
receivers=[accounts.get_contract_address("adder", 0, 0)],
amount=1000000000000000000
))
), await_completion=True)

print("## Relayed v3, completely intra-shard, with a few contract calls")
controller.send(controller.create_relayed_v3_with_a_few_contract_calls(
relayer=accounts.get_user(shard=0, index=0),
senders=[accounts.get_user(shard=0, index=0)] * 7,
contracts=[accounts.get_contract_address("dummy", shard=0, index=0)] * 7,
inner_transaction_amount=0
))
), await_completion=True)

print("## Relayed v3, cross-shard, with gas limit = 599999999")
controller.send(controller.create_relayed_v3_with_a_few_contract_calls(
Expand All @@ -272,55 +274,55 @@ def do_run(args: Any):
contracts=[accounts.get_contract_address("dummy", shard=1, index=0)],
inner_transaction_amount=0,
inner_transaction_gas_limit=599949999,
))
), await_completion=True)

print("## Intra-shard, relayed v1 transaction with MoveBalance (with bad receiver, system smart contract)")
controller.send(controller.create_relayed_v1_with_move_balance(
relayer=accounts.get_user(shard=1, index=0),
sender=accounts.get_user(shard=1, index=9),
receiver=Address.from_bech32("erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u"),
amount=1000000000000000000
))
), await_completion=True)

print("## Direct contract deployment with MoveBalance")
controller.send(controller.create_contract_deployment_with_move_balance(
sender=accounts.get_user(shard=0, index=0),
amount=10000000000000000
))
), await_completion=True)

print("## Intra-shard, contract call with MoveBalance, with signal error")
controller.send(controller.create_contract_call_with_move_balance_with_signal_error(
sender=accounts.get_user(shard=0, index=0),
contract=accounts.get_contract_address("adder", 0, 0),
amount=10000000000000000
))
), await_completion=True)

print("## Cross-shard, contract call with MoveBalance, with signal error")
controller.send(controller.create_contract_call_with_move_balance_with_signal_error(
sender=accounts.get_user(shard=0, index=0),
contract=accounts.get_contract_address("adder", 1, 0),
amount=10000000000000000
))
), await_completion=True)

print("## Direct contract deployment with MoveBalance, with signal error")
controller.send(controller.create_contract_deployment_with_move_balance_with_signal_error(
sender=accounts.get_user(shard=0, index=0),
amount=77
))
), await_completion=True)

print("## Intra-shard, relayed v1 transaction with contract call with MoveBalance, with signal error")
controller.send(controller.create_relayed_v1_with_contract_call_with_move_balance_with_signal_error(
relayer=accounts.get_user(shard=0, index=0),
sender=accounts.get_user(shard=0, index=1),
contract=accounts.get_contract_address("adder", 0, 0),
amount=1
))
), await_completion=True)

print("## Intra-shard ClaimDeveloperRewards on directly owned contract")
controller.send(controller.create_claim_developer_rewards_on_directly_owned_contract(
sender=accounts.get_user(shard=0, index=0),
contract=accounts.get_contract_address("adder", 0, 0),
))
), await_completion=True)

print("## Cross-shard ClaimDeveloperRewards on directly owned contract")
controller.do_change_contract_owner(
Expand All @@ -337,13 +339,13 @@ def do_run(args: Any):
controller.send(controller.create_claim_developer_rewards_on_child_contract(
sender=accounts.get_user(shard=0, index=0),
parent_contract=accounts.get_contract_address("developerRewards", shard=0, index=0),
))
), await_completion=True)

print("## ClaimDeveloperRewards on child contract (owned by a contract); user & parent contract in different shards")
controller.send(controller.create_claim_developer_rewards_on_child_contract(
sender=accounts.get_user(shard=0, index=0),
parent_contract=accounts.get_contract_address("developerRewards", shard=1, index=0),
))
), await_completion=True)


class BunchOfAccounts:
Expand Down Expand Up @@ -922,7 +924,7 @@ def create_contract_call_with_move_balance_with_signal_error(self, sender: "Acco
transaction = self.contracts_transactions_factory.create_transaction_for_execute(
sender=sender.address,
contract=contract,
function="missingFunction",
function="doSomething",
gas_limit=5000000,
arguments=[1, 2, 3, 4, 5],
native_transfer_amount=amount
Expand Down Expand Up @@ -1012,7 +1014,7 @@ def sign(self, transaction: Transaction):
bytes_for_signing = self.transaction_computer.compute_bytes_for_signing(transaction)
transaction.signature = sender.signer.sign(bytes_for_signing)

def send_multiple(self, transactions: List[Transaction], chunk_size: int = 1024, wait_between_chunks: float = 0):
def send_multiple(self, transactions: List[Transaction], chunk_size: int = 1024, wait_between_chunks: float = 0, await_completion: bool = False):
print(f"Sending {len(transactions)} transactions...")

chunks = list(split_to_chunks(transactions, chunk_size))
Expand All @@ -1023,12 +1025,18 @@ def send_multiple(self, transactions: List[Transaction], chunk_size: int = 1024,
print(f"Sent {num_sent} transactions. Waiting {wait_between_chunks} seconds...")
time.sleep(wait_between_chunks)

def send(self, transaction: Transaction):
if await_completion:
self.await_completed(transactions)

def send(self, transaction: Transaction, await_completion: bool = False):
transaction_hash = self.network_provider.send_transaction(transaction)
print(f"{self.configuration.explorer_url}/transactions/{transaction_hash}")
print(f" 🌍 {self.configuration.explorer_url}/transactions/{transaction_hash}")

if await_completion:
self.await_completed([transaction])

def await_completed(self, transactions: List[Transaction]) -> List[TransactionOnNetwork]:
print(f"Awaiting completion of {len(transactions)} transactions...")
print(f"Awaiting completion of {len(transactions)} transactions...")

# Short wait before starting requests, to avoid "transaction not found" errors.
time.sleep(3)
Expand All @@ -1037,7 +1045,7 @@ def await_completed_one(transaction: Transaction) -> TransactionOnNetwork:
transaction_hash = self.transaction_computer.compute_transaction_hash(transaction).hex()
transaction_on_network = self.transaction_awaiter.await_completed(transaction_hash)

print(f"Completed: {self.configuration.explorer_url}/transactions/{transaction_hash}")
print(f"Completed: {self.configuration.explorer_url}/transactions/{transaction_hash}")
return transaction_on_network

transactions_on_network = Pool(8).map(await_completed_one, transactions)
Expand Down

0 comments on commit ff27144

Please sign in to comment.