Skip to content

Commit

Permalink
Tests on localnet.
Browse files Browse the repository at this point in the history
  • Loading branch information
andreibancioiu committed Oct 14, 2024
1 parent 18482fd commit 91527be
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 15 deletions.
52 changes: 52 additions & 0 deletions .github/workflows/check_with_mesh_cli_on_localnet.yml
Original file line number Diff line number Diff line change
@@ -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"
39 changes: 26 additions & 13 deletions systemtests/generate_testdata_on_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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),
Expand All @@ -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)
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -200,15 +204,15 @@ 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,
custom_amount=7,
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,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions systemtests/localnet.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

0 comments on commit 91527be

Please sign in to comment.