From 91527be9f3850a8e20ee7fca4f515527927f7b35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrei=20B=C4=83ncioiu?= Date: Mon, 14 Oct 2024 15:32:26 +0300 Subject: [PATCH] Tests on localnet. --- .../check_with_mesh_cli_on_localnet.yml | 52 +++++++++++++++++++ systemtests/generate_testdata_on_network.py | 39 +++++++++----- systemtests/localnet.toml | 4 +- 3 files changed, 80 insertions(+), 15 deletions(-) create mode 100644 .github/workflows/check_with_mesh_cli_on_localnet.yml diff --git a/.github/workflows/check_with_mesh_cli_on_localnet.yml b/.github/workflows/check_with_mesh_cli_on_localnet.yml new file mode 100644 index 00000000..900dc779 --- /dev/null +++ b/.github/workflows/check_with_mesh_cli_on_localnet.yml @@ -0,0 +1,52 @@ +name: Check with Mesh CLI (localnet) + +on: + pull_request: + workflow_dispatch: + +jobs: + test: + runs-on: ubuntu-latest + + steps: + - uses: actions/setup-python@v5 + with: + python-version: 3.11 + + - uses: actions/checkout@v4 + + - name: Install dependencies + run: | + pipx install multiversx-sdk-cli --force + pip install -r ./requirements-dev.txt + curl -sSfL https://raw.githubusercontent.com/coinbase/mesh-cli/master/scripts/install.sh | sh -s -- -b "$HOME/.local/bin" + echo "$HOME/.local/bin" >> $GITHUB_PATH + + - name: Build + run: | + cd $GITHUB_WORKSPACE/cmd/rosetta && go build . + cd $GITHUB_WORKSPACE/systemtests && go build ./proxyToObserverAdapter.go + + - name: Set up MultiversX localnet + run: | + mkdir -p ~/localnet && cd ~/localnet + mxpy localnet setup --configfile=${GITHUB_WORKSPACE}/systemtests/localnet.toml + + # Start the localnet and store the PID + nohup mxpy localnet start --configfile=${GITHUB_WORKSPACE}/systemtests/localnet.toml > localnet.log 2>&1 & echo $! > localnet.pid + + - name: Generate testdata + run: | + source .env + PYTHONPATH=. python3 ./systemtests/generate_testdata_on_network.py setup --network localnet + PYTHONPATH=. python3 ./systemtests/generate_testdata_on_network.py run --network localnet + + - name: check:data + run: | + source .env + PYTHONPATH=. python3 ./systemtests/check_with_mesh_cli.py --mode=data --network=localnet + + - name: Stop MultiversX localnet + if: success() || failure() + run: | + kill $(cat localnet.pid) || echo "Testnet already stopped" diff --git a/systemtests/generate_testdata_on_network.py b/systemtests/generate_testdata_on_network.py index 7c2c2cb3..62c345a2 100644 --- a/systemtests/generate_testdata_on_network.py +++ b/systemtests/generate_testdata_on_network.py @@ -56,6 +56,8 @@ def do_setup(args: Any): memento.clear() + controller.wait_until_epoch(configuration.activation_epoch_sirius) + print("Do airdrops for native currency...") controller.do_airdrops_for_native_currency() @@ -76,6 +78,8 @@ def do_run(args: Any): accounts = BunchOfAccounts(configuration, memento) controller = Controller(configuration, accounts, memento) + controller.wait_until_epoch(configuration.activation_epoch_spica) + print("## Intra-shard, simple MoveBalance with refund") controller.send(controller.create_simple_move_balance( sender=accounts.get_user(shard=0, index=0), @@ -99,7 +103,7 @@ def do_run(args: Any): print("## Cross-shard, invalid MoveBalance with refund") controller.send(controller.create_invalid_move_balance( - sender=accounts.get_user(shard=0, index=4), + sender=accounts.get_user(shard=0, index=3), receiver=accounts.get_user(shard=1, index=1).address, additional_gas_limit=42000, ), await_completion=True) @@ -161,7 +165,7 @@ def do_run(args: Any): print("## Intra-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=4), + sender=accounts.get_user(shard=0, index=3), contract=accounts.get_contract_address("dummy", shard=0, index=0), function="doSomething", native_amount=42, @@ -200,7 +204,7 @@ def do_run(args: Any): relayer=accounts.get_user(shard=0, index=0), inner_transactions=[ controller.create_native_transfer_within_multiesdt_transfer_and_execute( - sender=accounts.get_user(shard=0, index=3), + sender=accounts.get_user(shard=0, index=2), contract=accounts.get_contract_address("dummy", shard=0, index=0), function="doSomething", native_amount=42, @@ -208,7 +212,7 @@ def do_run(args: Any): seal_for_broadcast=False, ), controller.create_native_transfer_within_multiesdt_transfer_and_execute( - sender=accounts.get_user(shard=0, index=4), + sender=accounts.get_user(shard=0, index=3), contract=accounts.get_contract_address("dummy", shard=0, index=0), function="doNothing", native_amount=42, @@ -288,7 +292,7 @@ def do_run(args: Any): 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), + sender=accounts.get_user(shard=1, index=2), receiver=Address.from_bech32("erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u"), amount=1000000000000000000 ), await_completion=True) @@ -386,30 +390,28 @@ def do_run(args: Any): 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=4), - receiver=accounts.get_user(shard=0, index=5).address, + sender=accounts.get_user(shard=0, index=2), + receiver=accounts.get_user(shard=0, 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=4), - receiver=accounts.get_user(shard=0, index=5).address, + sender=accounts.get_user(shard=0, index=3), + receiver=accounts.get_user(shard=0, 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=4), - receiver=accounts.get_user(shard=1, index=5).address, + sender=accounts.get_user(shard=0, index=2), + receiver=accounts.get_user(shard=1, index=3).address, native_amount_as_value=0, native_amount_in_data=[43, 44] ), await_completion=True) - # TODO intra relayed v3, unde e signal error, sa vad ca apare si SCR. deranjeaza pe logica aia cu pre-post-sirius? - class BunchOfAccounts: def __init__(self, configuration: Configuration, memento: "Memento") -> None: @@ -1148,6 +1150,17 @@ def await_completed_one(transaction: Transaction) -> TransactionOnNetwork: transactions_on_network = Pool(8).map(await_completed_one, transactions) return transactions_on_network + def wait_until_epoch(self, epoch: int): + print(f"⏳ Waiting until epoch {epoch}...") + + while True: + current_epoch = self.network_provider.get_network_status().epoch_number + if current_epoch >= epoch: + print(f"✓ Reached epoch {current_epoch} >= {epoch}") + break + + time.sleep(30) + class NoncesTracker: def __init__(self, proxy_url: str) -> None: diff --git a/systemtests/localnet.toml b/systemtests/localnet.toml index 27b77791..44fa51f1 100644 --- a/systemtests/localnet.toml +++ b/systemtests/localnet.toml @@ -28,14 +28,14 @@ port_first_validator_rest_api = 10200 [software.mx_chain_go] resolution = "remote" -archive_url = "https://github.com/multiversx/mx-chain-go/archive/refs/heads/master.zip" +archive_url = "https://github.com/multiversx/mx-chain-go/archive/refs/heads/inner_hash_on_scr_prev.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" [software.mx_chain_proxy_go] resolution = "remote" -archive_url = "https://github.com/multiversx/mx-chain-proxy-go/archive/refs/heads/master.zip" +archive_url = "https://github.com/multiversx/mx-chain-proxy-go/archive/refs/heads/new_core_go.zip" archive_download_folder = "~/multiversx-sdk/localnet_software_remote/downloaded/mx-chain-proxy-go" archive_extraction_folder = "~/multiversx-sdk/localnet_software_remote/extracted/mx-chain-proxy-go" local_path = "~/multiversx-sdk/localnet_software_local/mx-chain-proxy-go"