Skip to content

Commit

Permalink
Additional tests (relayed).
Browse files Browse the repository at this point in the history
  • Loading branch information
andreibancioiu committed Jan 8, 2025
1 parent 0e529d7 commit 7f22638
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 87 deletions.
148 changes: 62 additions & 86 deletions systemtests/generate_testdata_on_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,21 +225,24 @@ def do_run(args: Any):
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=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)
for relayed_version in [1, 3]:
print(f"## Intra-shard, relayed v{relayed_version} transaction with contract call with MoveBalance, with signal error")
controller.send(controller.create_relayed_with_contract_call_with_move_balance_with_signal_error(
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,
relayed_version=relayed_version,
), await_completion=True)

print("## Cross-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=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(f"## Cross-shard, relayed v{relayed_version} transaction with contract call with MoveBalance, with signal error")
controller.send(controller.create_relayed_with_contract_call_with_move_balance_with_signal_error(
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,
relayed_version=relayed_version,
), await_completion=True)

print("## Intra-shard ClaimDeveloperRewards on directly owned contract")
controller.send(controller.create_claim_developer_rewards_on_directly_owned_contract(
Expand Down Expand Up @@ -741,7 +744,7 @@ def create_relayed_with_move_balance(self, relayer: "Account", sender: "Account"
return transaction

if relayed_version == 2:
raise ValueError("Relayed v2 does not support move balance operations.")
raise ValueError("not implemented")

if relayed_version == 3:
transaction = self.transfer_transactions_factory.create_transaction_for_native_token_transfer(
Expand All @@ -760,57 +763,6 @@ def create_relayed_with_move_balance(self, relayer: "Account", sender: "Account"

raise ValueError(f"Unsupported relayed version: {relayed_version}")

def create_relayed_v1_with_esdt_transfer(self, relayer: "Account", sender: "Account", receiver: Address, amount: int) -> Transaction:
custom_currency = self.memento.get_custom_currencies()[0]

# 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)

inner_transaction = self.transfer_transactions_factory.create_transaction_for_esdt_token_transfer(
sender=sender.address,
receiver=receiver,
token_transfers=[TokenTransfer(Token(custom_currency), amount)]
)

self.apply_nonce(inner_transaction)
self.sign(inner_transaction)

transaction = self.relayed_transactions_factory.create_relayed_v1_transaction(
inner_transaction=inner_transaction,
relayer_address=relayer.address,
)

transaction.nonce = relayer_nonce
self.sign(transaction)

return transaction

def create_relayed_v2_with_move_balance(self, relayer: "Account", sender: "Account", receiver: Address, amount: 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)

inner_transaction = self.transfer_transactions_factory.create_transaction_for_native_token_transfer(
sender=sender.address,
receiver=receiver,
native_amount=amount
)

inner_transaction.gas_limit = 0

self.apply_nonce(inner_transaction)
self.sign(inner_transaction)

transaction = self.relayed_transactions_factory.create_relayed_v2_transaction(
inner_transaction=inner_transaction,
inner_transaction_gas_limit=100000,
relayer_address=relayer.address,
)

transaction.nonce = relayer_nonce
self.sign(transaction)

return transaction

def create_contract_deployment_with_move_balance(self, sender: "Account", amount: int) -> Transaction:
transaction = self.contracts_transactions_factory.create_transaction_for_deploy(
sender=sender.address,
Expand Down Expand Up @@ -894,31 +846,55 @@ def create_change_owner_address(self, contract: Address, owner: "Account", new_o

return transaction

def create_relayed_v1_with_contract_call_with_move_balance_with_signal_error(self, relayer: "Account", sender: "Account", contract: Address, amount: 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)
def create_relayed_with_contract_call_with_move_balance_with_signal_error(self, relayer: "Account", sender: "Account", contract: Address, amount: int, relayed_version: int) -> Transaction:
if relayed_version == 1:
# 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)

inner_transaction = self.contracts_transactions_factory.create_transaction_for_execute(
sender=sender.address,
contract=contract,
function="add",
gas_limit=5000000,
arguments=[BigUIntValue(1), BigUIntValue(2), BigUIntValue(3), BigUIntValue(4), BigUIntValue(5)],
native_transfer_amount=amount
)
inner_transaction = self.contracts_transactions_factory.create_transaction_for_execute(
sender=sender.address,
contract=contract,
function="add",
gas_limit=5000000,
arguments=[BigUIntValue(1), BigUIntValue(2), BigUIntValue(3), BigUIntValue(4), BigUIntValue(5)],
native_transfer_amount=amount
)

self.apply_nonce(inner_transaction)
self.sign(inner_transaction)
self.apply_nonce(inner_transaction)
self.sign(inner_transaction)

transaction = self.relayed_transactions_factory.create_relayed_v1_transaction(
inner_transaction=inner_transaction,
relayer_address=relayer.address,
)
transaction = self.relayed_transactions_factory.create_relayed_v1_transaction(
inner_transaction=inner_transaction,
relayer_address=relayer.address,
)

transaction.nonce = relayer_nonce
self.sign(transaction)
transaction.nonce = relayer_nonce
self.sign(transaction)

return transaction
return transaction

if relayed_version == 2:
raise ValueError("not implemented")

if relayed_version == 3:
transaction = self.contracts_transactions_factory.create_transaction_for_execute(
sender=sender.address,
contract=contract,
function="add",
gas_limit=5000000,
arguments=[BigUIntValue(1), BigUIntValue(2), BigUIntValue(3), BigUIntValue(4), BigUIntValue(5)],
native_transfer_amount=amount
)

transaction.relayer = relayer.address
transaction.gas_limit += ADDITIONAL_GAS_LIMIT_FOR_RELAYED_V3
self.apply_nonce(transaction)
self.sign(transaction)
self.sign_as_relayer_v3(transaction)

return transaction

raise ValueError(f"Unsupported relayed version: {relayed_version}")

def apply_nonce(self, transaction: Transaction):
sender = self.accounts.get_account_by_bech32(transaction.sender.to_bech32())
Expand Down
2 changes: 1 addition & 1 deletion systemtests/localnet.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ port_first_validator_rest_api = 10200

[software.mx_chain_go]
resolution = "remote"
archive_url = "https://github.com/multiversx/mx-chain-go/archive/refs/heads/feat/relayedv3.zip"
archive_url = "https://github.com/multiversx/mx-chain-go/archive/refs/heads/MX-16416-tx-type.zip"
archive_download_folder = "~/multiversx-sdk/localnet_software_remote/downloaded/mx-chain-go"
archive_extraction_folder = "~/multiversx-sdk/localnet_software_remote/extracted/mx-chain-go"
local_path = "~/multiversx-sdk/localnet_software_local/mx-chain-go"
Expand Down
1 change: 1 addition & 0 deletions systemtests/rosetta_config/internal-custom-currencies.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]

0 comments on commit 7f22638

Please sign in to comment.