Skip to content

Commit

Permalink
Some refactoring (constants for shards).
Browse files Browse the repository at this point in the history
  • Loading branch information
andreibancioiu committed Dec 20, 2024
1 parent 8a32d24 commit ab42e15
Showing 1 changed file with 70 additions and 65 deletions.
135 changes: 70 additions & 65 deletions systemtests/generate_testdata_on_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
CONTRACT_PATH_FORWARDER = Path(__file__).parent / "contracts" / "forwarder.wasm"
CONTRACT_PATH_DEVELOPER_REWARDS = Path(__file__).parent / "contracts" / "developer_rewards.wasm"

SOME_SHARD = 0
OTHER_SHARD = 1


def main():
parser = ArgumentParser()
Expand Down Expand Up @@ -84,205 +87,207 @@ def do_run(args: Any):

print("## Intra-shard, simple MoveBalance with refund")
controller.send(controller.create_simple_move_balance(
sender=accounts.get_user(shard=0, index=0),
receiver=accounts.get_user(shard=0, index=1).address,
sender=accounts.get_user(shard=SOME_SHARD, index=0),
receiver=accounts.get_user(shard=SOME_SHARD, index=1).address,
additional_gas_limit=42000,
), await_completion=True)

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

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

print("## Cross-shard, invalid MoveBalance with refund")
controller.send(controller.create_simple_move_balance(
sender=accounts.get_user(shard=0, index=3),
receiver=accounts.get_user(shard=1, index=1).address,
sender=accounts.get_user(shard=SOME_SHARD, index=3),
receiver=accounts.get_user(shard=OTHER_SHARD, index=1).address,
amount=1000000000000000000000000,
additional_gas_limit=42000,
), await_completion=True)

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

print("## Cross-shard, sending value to non-payable contract")
controller.send(controller.create_simple_move_balance(
sender=accounts.get_user(shard=0, index=1),
receiver=accounts.get_contract_address("adder", 1, 0),
sender=accounts.get_user(shard=SOME_SHARD, index=1),
receiver=accounts.get_contract_address("adder", shard=OTHER_SHARD, index=0),
additional_gas_limit=42000,
), 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,
sender=accounts.get_user(shard=SOME_SHARD, index=0),
receiver=accounts.get_user(shard=SOME_SHARD, 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,
sender=accounts.get_user(shard=SOME_SHARD, index=1),
receiver=accounts.get_user(shard=OTHER_SHARD, 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),
sender=accounts.get_user(shard=SOME_SHARD, index=0),
receiver=accounts.get_contract_address("adder", shard=SOME_SHARD, index=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),
sender=accounts.get_user(shard=SOME_SHARD, index=1),
receiver=accounts.get_contract_address("adder", shard=OTHER_SHARD, index=0),
native_amount=42,
custom_amount=7
), await_completion=True)

print("## Cross-shard, transfer & execute with native & custom transfer")
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),
sender=accounts.get_user(shard=SOME_SHARD, index=1),
contract=accounts.get_contract_address("dummy", shard=SOME_SHARD, 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_transfer_and_execute(
sender=accounts.get_user(shard=0, index=3),
contract=accounts.get_contract_address("dummy", shard=0, index=0),
sender=accounts.get_user(shard=SOME_SHARD, index=3),
contract=accounts.get_contract_address("dummy", shard=SOME_SHARD, index=0),
function="doSomething",
native_amount=42,
custom_amount=7,
), 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),
sender=accounts.get_user(shard=0, index=1),
receiver=accounts.get_user(shard=0, index=2).address,
amount=42
print("## Intra-shard, relayed transactions with MoveBalance")
controller.send(controller.create_relayed_with_move_balance(
relayer=accounts.get_user(shard=SOME_SHARD, index=0),
sender=accounts.get_user(shard=SOME_SHARD, index=1),
receiver=accounts.get_user(shard=SOME_SHARD, index=2).address,
amount=42,
relayed_version=1,
), 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=2),
print("## Intra-shard, relayed transactions with MoveBalance (with bad receiver, system smart contract)")
controller.send(controller.create_relayed_with_move_balance(
relayer=accounts.get_user(shard=SOME_SHARD, index=0),
sender=accounts.get_user(shard=SOME_SHARD, index=2),
receiver=Address.from_bech32("erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u"),
amount=1000000000000000000
amount=1000000000000000000,
relayed_version=1,
), 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),
sender=accounts.get_user(shard=SOME_SHARD, 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),
sender=accounts.get_user(shard=SOME_SHARD, index=0),
contract=accounts.get_contract_address("adder", shard=SOME_SHARD, index=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),
sender=accounts.get_user(shard=SOME_SHARD, index=0),
contract=accounts.get_contract_address("adder", shard=OTHER_SHARD, index=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),
sender=accounts.get_user(shard=SOME_SHARD, 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),
relayer=accounts.get_user(shard=SOME_SHARD, index=0),
sender=accounts.get_user(shard=SOME_SHARD, index=1),
contract=accounts.get_contract_address("adder", shard=SOME_SHARD, index=0),
amount=1
), await_completion=True)

print("## Cross-shard, relayed v1 transaction with contract call with MoveBalance, with signal error (1)")
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", 1, 0),
relayer=accounts.get_user(shard=SOME_SHARD, index=0),
sender=accounts.get_user(shard=SOME_SHARD, index=1),
contract=accounts.get_contract_address("adder", shard=OTHER_SHARD, index=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),
sender=accounts.get_user(shard=SOME_SHARD, index=0),
contract=accounts.get_contract_address("adder", shard=SOME_SHARD, index=0),
), await_completion=True)

print("## Cross-shard ClaimDeveloperRewards on directly owned contract")
controller.do_change_contract_owner(
contract=accounts.get_contract_address("adder", shard=1, index=0),
new_owner=accounts.get_user(shard=0, index=0)
contract=accounts.get_contract_address("adder", shard=OTHER_SHARD, index=0),
new_owner=accounts.get_user(shard=SOME_SHARD, index=0)
)

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", shard=1, index=0),
sender=accounts.get_user(shard=SOME_SHARD, index=0),
contract=accounts.get_contract_address("adder", shard=OTHER_SHARD, index=0),
))

print("## ClaimDeveloperRewards on child contract (owned by a contract); user & parent contract in same shard")
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),
sender=accounts.get_user(shard=SOME_SHARD, index=0),
parent_contract=accounts.get_contract_address("developerRewards", shard=SOME_SHARD, 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),
sender=accounts.get_user(shard=SOME_SHARD, index=0),
parent_contract=accounts.get_contract_address("developerRewards", shard=OTHER_SHARD, index=0),
), await_completion=True)

print("## Intra-shard, transfer native within MultiESDTTransfer (fuzzy, with tx.value != 0)")
controller.send(controller.create_native_transfer_within_multiesdt_fuzzy(
sender=accounts.get_user(shard=0, index=2),
receiver=accounts.get_user(shard=0, index=3).address,
sender=accounts.get_user(shard=SOME_SHARD, index=2),
receiver=accounts.get_user(shard=SOME_SHARD, index=3).address,
native_amount_as_value=42,
native_amount_in_data=[43, 44]
), await_completion=True)

print("## Intra-shard, transfer native within MultiESDTTransfer (fuzzy, with tx.value == 0)")
controller.send(controller.create_native_transfer_within_multiesdt_fuzzy(
sender=accounts.get_user(shard=0, index=3),
receiver=accounts.get_user(shard=0, index=3).address,
sender=accounts.get_user(shard=SOME_SHARD, index=3),
receiver=accounts.get_user(shard=SOME_SHARD, index=3).address,
native_amount_as_value=0,
native_amount_in_data=[43, 44]
), await_completion=True)

print("## Cross-shard, transfer native within MultiESDTTransfer (fuzzy, with tx.value == 0)")
controller.send(controller.create_native_transfer_within_multiesdt_fuzzy(
sender=accounts.get_user(shard=0, index=2),
receiver=accounts.get_user(shard=1, index=3).address,
sender=accounts.get_user(shard=SOME_SHARD, index=2),
receiver=accounts.get_user(shard=OTHER_SHARD, index=3).address,
native_amount_as_value=0,
native_amount_in_data=[43, 44]
), await_completion=True)
Expand Down Expand Up @@ -585,7 +590,7 @@ def do_create_contract_deployments(self):

for contract in self.memento.get_contracts("developerRewards"):
transaction = self.contracts_transactions_factory.create_transaction_for_execute(
sender=self.accounts.get_user(shard=0, index=0).address,
sender=self.accounts.get_user(shard=SOME_SHARD, index=0).address,
contract=Address.new_from_bech32(contract.address),
function="deployChild",
gas_limit=5000000,
Expand Down Expand Up @@ -709,7 +714,7 @@ def create_transfer_and_execute(self, sender: "Account", contract: Address, func

return transaction

def create_relayed_v1_with_move_balance(self, relayer: "Account", sender: "Account", receiver: Address, amount: int) -> Transaction:
def create_relayed_with_move_balance(self, relayer: "Account", sender: "Account", receiver: Address, amount: int, relayed_version: int) -> Transaction:
# Relayer nonce is reserved before sender nonce, to ensure good ordering (if sender and relayer are the same account).
relayer_nonce = self._reserve_nonce(relayer)

Expand Down

0 comments on commit ab42e15

Please sign in to comment.