From 1a6a2702f65f0e5ee66f6dd01539c4e943408a20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrei=20B=C4=83ncioiu?= Date: Thu, 10 Oct 2024 17:04:10 +0300 Subject: [PATCH 01/90] Spica / gateway: upwards & backwards compatibility. --- multiversx_sdk_cli/localnet/step_config.py | 16 ++++++---------- pyproject.toml | 2 +- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/multiversx_sdk_cli/localnet/step_config.py b/multiversx_sdk_cli/localnet/step_config.py index ba3a4447..48053a63 100644 --- a/multiversx_sdk_cli/localnet/step_config.py +++ b/multiversx_sdk_cli/localnet/step_config.py @@ -171,17 +171,13 @@ def copy_config_to_proxy(config: ConfigRoot): proxy_config = config.proxy_config_folder() makefolder(proxy_config) - shutil.copy( - config_prototype / 'config.toml', - proxy_config) + shutil.copy(config_prototype / 'config.toml', proxy_config) + shutil.copytree(config_prototype / 'apiConfig', proxy_config / 'apiConfig') - shutil.copytree( - config_prototype / 'apiConfig', - proxy_config / 'apiConfig') - - shutil.copy( - config_prototype / 'external.toml', - proxy_config) + # Removed in newer versions: + # https://github.com/multiversx/mx-chain-proxy-go/pull/454 + if (config_prototype / 'external.toml').exists(): + shutil.copy(config_prototype / 'external.toml', proxy_config) def patch_proxy_config(config: ConfigRoot): diff --git a/pyproject.toml b/pyproject.toml index c90a4f59..d6deeb97 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "hatchling.build" [project] name = "multiversx-sdk-cli" -version = "9.7.0" +version = "9.7.1" authors = [ { name="MultiversX" }, ] From c32d32885db0a43ba6095594e0deb9162a824bf5 Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Thu, 24 Oct 2024 12:35:30 +0300 Subject: [PATCH 02/90] Added cli validators test in pytest and CI for localnet dependent tests. --- .github/workflows/test-localnet-tests.yml | 63 ++++++ .../tests/test_cli_validators.py | 197 ++++++++++++++++++ 2 files changed, 260 insertions(+) create mode 100644 .github/workflows/test-localnet-tests.yml create mode 100644 multiversx_sdk_cli/tests/test_cli_validators.py diff --git a/.github/workflows/test-localnet-tests.yml b/.github/workflows/test-localnet-tests.yml new file mode 100644 index 00000000..3b675c91 --- /dev/null +++ b/.github/workflows/test-localnet-tests.yml @@ -0,0 +1,63 @@ +name: Test localnet-dependent tests + +on: + pull_request: + branches: [main, feat/*] + workflow_dispatch: + +env: + BRANCH_NAME: ${{ github.head_ref || github.ref_name }} + +jobs: + localnet: + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest, macos-latest] + python-version: [3.11] + + steps: + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + + - uses: actions/checkout@v2 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + + - name: Install dependencies + run: | + python3 -m pip install --upgrade pip + pip3 install -r requirements.txt + pip3 install -r ./requirements-dev.txt --upgrade + + - name: Deploy a localnet + run: | + mkdir -p ~/multiversx-sdk + export PYTHONPATH=. + python3 -m multiversx_sdk_cli.cli config set github_api_token ${{ secrets.GITHUB_TOKEN }} + python3 -m multiversx_sdk_cli.cli localnet prerequisites --configfile=./multiversx_sdk_cli/tests/testdata/localnet_with_resolution_remote.toml + python3 -m multiversx_sdk_cli.cli localnet build --configfile=./multiversx_sdk_cli/tests/testdata/localnet_with_resolution_remote.toml + + # "Go" and artifacts from "GOPATH/pkg/mod" are not needed anymore. + sudo rm -rf ~/multiversx-sdk/golang + + python3 -m multiversx_sdk_cli.cli localnet clean --configfile=./multiversx_sdk_cli/tests/testdata/localnet_with_resolution_remote.toml + python3 -m multiversx_sdk_cli.cli localnet config --configfile=./multiversx_sdk_cli/tests/testdata/localnet_with_resolution_remote.toml + python3 -m multiversx_sdk_cli.cli localnet start --configfile=./multiversx_sdk_cli/tests/testdata/localnet_with_resolution_remote.toml --stop-after-seconds=120 + + if grep -r --include=\*.log "started committing block" ./localnet; then + echo "The localnet processed blocks successfully." + else + echo "The localnet failed to process blocks." + exit 1 + fi + + ls + + - name: Test localnet dependent tests + run: | + pytest -m require_localnet multiversx_sdk_cli/tests diff --git a/multiversx_sdk_cli/tests/test_cli_validators.py b/multiversx_sdk_cli/tests/test_cli_validators.py new file mode 100644 index 00000000..7046371e --- /dev/null +++ b/multiversx_sdk_cli/tests/test_cli_validators.py @@ -0,0 +1,197 @@ +import pytest + +from pathlib import Path + +from multiversx_sdk_cli.cli import main + +testdata_path = Path(__file__).parent / "testdata" +testdata_out = Path(__file__).parent / "testdata-out" + +alice_pem = testdata_path / "alice.pem" +reward_address = "erd1k2s324ww2g0yj38qn2ch2jwctdy8mnfxep94q9arncc6xecg3xaq6mjse8" +bls_key = "e7beaa95b3877f47348df4dd1cb578a4f7cabf7a20bfeefe5cdd263878ff132b765e04fef6f40c93512b666c47ed7719b8902f6c922c04247989b7137e837cc81a62e54712471c97a2ddab75aa9c2f58f813ed4c0fa722bde0ab718bff382208" + + +@pytest.mark.require_localnet +def test_stake(): + validators_json = testdata_path / "validators.json" + + # Stake with recall nonce + return_code = main([ + "validator", "stake", + "--pem", str(alice_pem), + "--value", "2500000000000000000000", + "--validators-file", str(validators_json), + "--reward-address", reward_address, + "--chain", "localnet", + "--proxy", "http://127.0.0.1:7950", + "--estimate-gas", "--recall-nonce" + ]) + assert return_code == 0 + + # Stake with provided nonce + return_code = main([ + "validator", "stake", + "--pem", str(alice_pem), + "--value", "2500000000000000000000", + "--validators-file", str(validators_json), + "--reward-address", reward_address, + "--chain", "localnet", + "--proxy", "http://127.0.0.1:7950", + "--estimate-gas", "--nonce=0" + ]) + assert return_code == 0 + + +@pytest.mark.require_localnet +def test_stake_top_up(): + # Stake with topUp + return_code = main([ + "validator", "stake", "--top-up", + "--pem", str(alice_pem), + "--value", "2711000000000000000000", + "--chain", "localnet", + "--proxy", "http://127.0.0.1:7950", + "--estimate-gas", "--recall-nonce" + ]) + assert return_code == 0 + + +@pytest.mark.require_localnet +def test_unstake(): + # Unstake + return_code = main([ + "validator", "unstake", + "--pem", str(alice_pem), + "--nodes-public-key", bls_key, + "--chain", "localnet", + "--proxy", "http://127.0.0.1:7950", + "--estimate-gas", "--recall-nonce" + ]) + assert return_code == 0 + + +@pytest.mark.require_localnet +def test_unbond(): + # Unbond + return_code = main([ + "validator", "unbond", + "--pem", str(alice_pem), + "--nodes-public-key", bls_key, + "--chain", "localnet", + "--proxy", "http://127.0.0.1:7950", + "--estimate-gas", "--recall-nonce" + ]) + assert return_code == 0 + + +@pytest.mark.require_localnet +def test_unjail(): + # Unjail + return_code = main([ + "validator", "unjail", + "--pem", str(alice_pem), + "--value", "2500000000000000000000", + "--nodes-public-key", bls_key, + "--chain", "localnet", + "--proxy", "http://127.0.0.1:7950", + "--estimate-gas", "--recall-nonce" + ]) + assert return_code == 0 + + +@pytest.mark.require_localnet +def test_change_reward_address(): + # Change reward address + return_code = main([ + "validator", "change-reward-address", + "--pem", str(alice_pem), + "--reward-address", reward_address, + "--chain", "localnet", + "--proxy", "http://127.0.0.1:7950", + "--estimate-gas", "--recall-nonce" + ]) + assert return_code == 0 + + +@pytest.mark.require_localnet +def test_unstake_nodes(): + # Unstake Nodes + return_code = main([ + "validator", "unstake-nodes", + "--pem", str(alice_pem), + "--nodes-public-key", bls_key, + "--chain", "localnet", + "--proxy", "http://127.0.0.1:7950", + "--estimate-gas", "--recall-nonce" + ]) + assert return_code == 0 + + +@pytest.mark.require_localnet +def test_unstake_tokens(): + # Unstake Tokens + return_code = main([ + "validator", "unstake-tokens", + "--pem", str(alice_pem), + "--unstake-value", "11000000000000000000", + "--chain", "localnet", + "--proxy", "http://127.0.0.1:7950", + "--estimate-gas", "--recall-nonce" + ]) + assert return_code == 0 + + +@pytest.mark.require_localnet +def test_unbond_nodes(): + # Unbond nodes + return_code = main([ + "validator", "unbond-nodes", + "--pem", str(alice_pem), + "--nodes-public-keys", bls_key, + "--chain", "localnet", + "--proxy", "http://127.0.0.1:7950", + "--estimate-gas", "--recall-nonce" + ]) + assert return_code == 0 + + +@pytest.mark.require_localnet +def test_unbond_tokens(): + # Unbond nodes + return_code = main([ + "validator", "unbond-tokens", + "--pem", str(alice_pem), + "--unbond-value", "20000000000000000000", + "--chain", "localnet", + "--proxy", "http://127.0.0.1:7950", + "--estimate-gas", "--recall-nonce" + ]) + assert return_code == 0 + + +@pytest.mark.require_localnet +def test_clean_registration_data(): + # Clean registration data + return_code = main([ + "validator", "clean-registered-data", + "--pem", str(alice_pem), + "--chain", "localnet", + "--proxy", "http://127.0.0.1:7950", + "--estimate-gas", "--recall-nonce" + ]) + assert return_code == 0 + + +@pytest.mark.require_localnet +def test_re_stake_unstaked_nodes(): + # Clean registration data + return_code = main([ + "validator", "restake-unstaked-nodes", + "--pem", str(alice_pem), + "--nodes-public-keys", bls_key, + "--chain", "localnet", + "--proxy", "http://127.0.0.1:7950", + "--estimate-gas", "--recall-nonce" + ]) + assert return_code == 0 From 84efeb2d301ede00f03078bee5c75788d1effce7 Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Thu, 24 Oct 2024 12:54:41 +0300 Subject: [PATCH 03/90] Added fixture for proxy polling. --- .github/workflows/test-localnet-tests.yml | 2 - .../tests/test_cli_validators.py | 56 +++++++++++++++---- pytest.ini | 1 + 3 files changed, 45 insertions(+), 14 deletions(-) diff --git a/.github/workflows/test-localnet-tests.yml b/.github/workflows/test-localnet-tests.yml index 3b675c91..21db81d5 100644 --- a/.github/workflows/test-localnet-tests.yml +++ b/.github/workflows/test-localnet-tests.yml @@ -55,8 +55,6 @@ jobs: echo "The localnet failed to process blocks." exit 1 fi - - ls - name: Test localnet dependent tests run: | diff --git a/multiversx_sdk_cli/tests/test_cli_validators.py b/multiversx_sdk_cli/tests/test_cli_validators.py index 7046371e..56f58777 100644 --- a/multiversx_sdk_cli/tests/test_cli_validators.py +++ b/multiversx_sdk_cli/tests/test_cli_validators.py @@ -1,3 +1,5 @@ +import requests +import time import pytest from pathlib import Path @@ -7,13 +9,43 @@ testdata_path = Path(__file__).parent / "testdata" testdata_out = Path(__file__).parent / "testdata-out" +proxy_url = "http://127.0.0.1:7950/network/config" alice_pem = testdata_path / "alice.pem" reward_address = "erd1k2s324ww2g0yj38qn2ch2jwctdy8mnfxep94q9arncc6xecg3xaq6mjse8" bls_key = "e7beaa95b3877f47348df4dd1cb578a4f7cabf7a20bfeefe5cdd263878ff132b765e04fef6f40c93512b666c47ed7719b8902f6c922c04247989b7137e837cc81a62e54712471c97a2ddab75aa9c2f58f813ed4c0fa722bde0ab718bff382208" +@pytest.fixture() +def poll_endpoint(): + start_time = time.time() # Record the start time + timeout = 60 + interval = 1 + + while True: + try: + # Make the request to the endpoint + response = requests.get(proxy_url, timeout=5) # Add request timeout to prevent blocking indefinitely + if response.status_code == 200: + # Break out of the loop if we get a successful response + return response.json() # Return the response (or .text, .content based on your needs) + else: + print(f"Received non-200 status code: {response.status_code}") + + except requests.RequestException as e: + # Handle network exceptions or timeouts + print(f"Request failed: {e}") + + # Check if the timeout is reached + if time.time() - start_time > timeout: + print("Polling timed out") + break + + # Wait for the specified interval before sending the next request + time.sleep(interval) + + @pytest.mark.require_localnet -def test_stake(): +def test_stake(poll_endpoint): validators_json = testdata_path / "validators.json" # Stake with recall nonce @@ -44,7 +76,7 @@ def test_stake(): @pytest.mark.require_localnet -def test_stake_top_up(): +def test_stake_top_up(poll_endpoint): # Stake with topUp return_code = main([ "validator", "stake", "--top-up", @@ -58,7 +90,7 @@ def test_stake_top_up(): @pytest.mark.require_localnet -def test_unstake(): +def test_unstake(poll_endpoint): # Unstake return_code = main([ "validator", "unstake", @@ -72,7 +104,7 @@ def test_unstake(): @pytest.mark.require_localnet -def test_unbond(): +def test_unbond(poll_endpoint): # Unbond return_code = main([ "validator", "unbond", @@ -86,7 +118,7 @@ def test_unbond(): @pytest.mark.require_localnet -def test_unjail(): +def test_unjail(poll_endpoint): # Unjail return_code = main([ "validator", "unjail", @@ -101,7 +133,7 @@ def test_unjail(): @pytest.mark.require_localnet -def test_change_reward_address(): +def test_change_reward_address(poll_endpoint): # Change reward address return_code = main([ "validator", "change-reward-address", @@ -115,7 +147,7 @@ def test_change_reward_address(): @pytest.mark.require_localnet -def test_unstake_nodes(): +def test_unstake_nodes(poll_endpoint): # Unstake Nodes return_code = main([ "validator", "unstake-nodes", @@ -129,7 +161,7 @@ def test_unstake_nodes(): @pytest.mark.require_localnet -def test_unstake_tokens(): +def test_unstake_tokens(poll_endpoint): # Unstake Tokens return_code = main([ "validator", "unstake-tokens", @@ -143,7 +175,7 @@ def test_unstake_tokens(): @pytest.mark.require_localnet -def test_unbond_nodes(): +def test_unbond_nodes(poll_endpoint): # Unbond nodes return_code = main([ "validator", "unbond-nodes", @@ -157,7 +189,7 @@ def test_unbond_nodes(): @pytest.mark.require_localnet -def test_unbond_tokens(): +def test_unbond_tokens(poll_endpoint): # Unbond nodes return_code = main([ "validator", "unbond-tokens", @@ -171,7 +203,7 @@ def test_unbond_tokens(): @pytest.mark.require_localnet -def test_clean_registration_data(): +def test_clean_registration_data(poll_endpoint): # Clean registration data return_code = main([ "validator", "clean-registered-data", @@ -184,7 +216,7 @@ def test_clean_registration_data(): @pytest.mark.require_localnet -def test_re_stake_unstaked_nodes(): +def test_re_stake_unstaked_nodes(poll_endpoint): # Clean registration data return_code = main([ "validator", "restake-unstaked-nodes", diff --git a/pytest.ini b/pytest.ini index 6669f27f..cab31729 100644 --- a/pytest.ini +++ b/pytest.ini @@ -2,5 +2,6 @@ markers = skip_on_windows: marks tests as being skiped when running on windows (deselect with '-m "skip_on_windows"') only: only run a specific test (run using: pytest -m "only") + require_localnet: marks tests that require a localnet (run using: pytest -m require_localnet) log_cli = True From 1685f0248df4c8a934b0611927f29fe4aa103798 Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Thu, 24 Oct 2024 14:16:39 +0300 Subject: [PATCH 04/90] try different endpoint for polling. --- multiversx_sdk_cli/tests/test_cli_validators.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/multiversx_sdk_cli/tests/test_cli_validators.py b/multiversx_sdk_cli/tests/test_cli_validators.py index 56f58777..256eeeaf 100644 --- a/multiversx_sdk_cli/tests/test_cli_validators.py +++ b/multiversx_sdk_cli/tests/test_cli_validators.py @@ -9,7 +9,7 @@ testdata_path = Path(__file__).parent / "testdata" testdata_out = Path(__file__).parent / "testdata-out" -proxy_url = "http://127.0.0.1:7950/network/config" +proxy_url = "http://localhost:7950/network/config" alice_pem = testdata_path / "alice.pem" reward_address = "erd1k2s324ww2g0yj38qn2ch2jwctdy8mnfxep94q9arncc6xecg3xaq6mjse8" bls_key = "e7beaa95b3877f47348df4dd1cb578a4f7cabf7a20bfeefe5cdd263878ff132b765e04fef6f40c93512b666c47ed7719b8902f6c922c04247989b7137e837cc81a62e54712471c97a2ddab75aa9c2f58f813ed4c0fa722bde0ab718bff382208" From f4e9c730ed1e2be54f50ae7a847147e91afec185 Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Thu, 24 Oct 2024 14:39:37 +0300 Subject: [PATCH 05/90] adding debug command. --- .github/workflows/test-localnet-tests.yml | 1 + multiversx_sdk_cli/tests/test_cli_validators.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test-localnet-tests.yml b/.github/workflows/test-localnet-tests.yml index 21db81d5..ea1677eb 100644 --- a/.github/workflows/test-localnet-tests.yml +++ b/.github/workflows/test-localnet-tests.yml @@ -58,4 +58,5 @@ jobs: - name: Test localnet dependent tests run: | + netstat -tulpn pytest -m require_localnet multiversx_sdk_cli/tests diff --git a/multiversx_sdk_cli/tests/test_cli_validators.py b/multiversx_sdk_cli/tests/test_cli_validators.py index 256eeeaf..56f58777 100644 --- a/multiversx_sdk_cli/tests/test_cli_validators.py +++ b/multiversx_sdk_cli/tests/test_cli_validators.py @@ -9,7 +9,7 @@ testdata_path = Path(__file__).parent / "testdata" testdata_out = Path(__file__).parent / "testdata-out" -proxy_url = "http://localhost:7950/network/config" +proxy_url = "http://127.0.0.1:7950/network/config" alice_pem = testdata_path / "alice.pem" reward_address = "erd1k2s324ww2g0yj38qn2ch2jwctdy8mnfxep94q9arncc6xecg3xaq6mjse8" bls_key = "e7beaa95b3877f47348df4dd1cb578a4f7cabf7a20bfeefe5cdd263878ff132b765e04fef6f40c93512b666c47ed7719b8902f6c922c04247989b7137e837cc81a62e54712471c97a2ddab75aa9c2f58f813ed4c0fa722bde0ab718bff382208" From 315e3b0b34175fc5520ba46d12568ebc472a8f96 Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Thu, 24 Oct 2024 14:48:51 +0300 Subject: [PATCH 06/90] more debugging. --- .github/workflows/test-localnet-tests.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test-localnet-tests.yml b/.github/workflows/test-localnet-tests.yml index ea1677eb..3ab50df7 100644 --- a/.github/workflows/test-localnet-tests.yml +++ b/.github/workflows/test-localnet-tests.yml @@ -13,7 +13,9 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - os: [ubuntu-latest, macos-latest] +# TODO: enable mac-os back once debugging is done. +# os: [ubuntu-latest, macos-latest] + os: [ubuntu-latest] python-version: [3.11] steps: @@ -59,4 +61,6 @@ jobs: - name: Test localnet dependent tests run: | netstat -tulpn + sleep 3m + curl -XGET http://127.0.0.1:7950/network/config pytest -m require_localnet multiversx_sdk_cli/tests From 39be1b4515d71e4773cabad30bfe78107785af33 Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Thu, 24 Oct 2024 16:03:10 +0300 Subject: [PATCH 07/90] make localnet run in background. --- .github/workflows/test-localnet-tests.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/test-localnet-tests.yml b/.github/workflows/test-localnet-tests.yml index 3ab50df7..a4e03d87 100644 --- a/.github/workflows/test-localnet-tests.yml +++ b/.github/workflows/test-localnet-tests.yml @@ -49,7 +49,7 @@ jobs: python3 -m multiversx_sdk_cli.cli localnet clean --configfile=./multiversx_sdk_cli/tests/testdata/localnet_with_resolution_remote.toml python3 -m multiversx_sdk_cli.cli localnet config --configfile=./multiversx_sdk_cli/tests/testdata/localnet_with_resolution_remote.toml - python3 -m multiversx_sdk_cli.cli localnet start --configfile=./multiversx_sdk_cli/tests/testdata/localnet_with_resolution_remote.toml --stop-after-seconds=120 + python3 -m multiversx_sdk_cli.cli localnet start --configfile=./multiversx_sdk_cli/tests/testdata/localnet_with_resolution_remote.toml & if grep -r --include=\*.log "started committing block" ./localnet; then echo "The localnet processed blocks successfully." @@ -60,7 +60,5 @@ jobs: - name: Test localnet dependent tests run: | - netstat -tulpn - sleep 3m curl -XGET http://127.0.0.1:7950/network/config pytest -m require_localnet multiversx_sdk_cli/tests From 18d6c714a25d3ed8fb6cc9fab0d97b41120d615c Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Thu, 24 Oct 2024 17:35:47 +0300 Subject: [PATCH 08/90] added Dockerfile and integrated CI with docker. --- .github/workflows/test-localnet-tests.yml | 38 ++--------------------- Dockerfile | 22 +++++++++++++ 2 files changed, 25 insertions(+), 35 deletions(-) create mode 100644 Dockerfile diff --git a/.github/workflows/test-localnet-tests.yml b/.github/workflows/test-localnet-tests.yml index a4e03d87..1d6d80cb 100644 --- a/.github/workflows/test-localnet-tests.yml +++ b/.github/workflows/test-localnet-tests.yml @@ -19,46 +19,14 @@ jobs: python-version: [3.11] steps: - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v2 - with: - python-version: ${{ matrix.python-version }} - - - uses: actions/checkout@v2 - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v2 - with: - python-version: ${{ matrix.python-version }} - - - name: Install dependencies + - name: Set up Docker image run: | - python3 -m pip install --upgrade pip - pip3 install -r requirements.txt - pip3 install -r ./requirements-dev.txt --upgrade + docker build --build-arg PYTHON_VERSION=${{ matrix.python-version }} -t mxpy . - name: Deploy a localnet run: | - mkdir -p ~/multiversx-sdk - export PYTHONPATH=. - python3 -m multiversx_sdk_cli.cli config set github_api_token ${{ secrets.GITHUB_TOKEN }} - python3 -m multiversx_sdk_cli.cli localnet prerequisites --configfile=./multiversx_sdk_cli/tests/testdata/localnet_with_resolution_remote.toml - python3 -m multiversx_sdk_cli.cli localnet build --configfile=./multiversx_sdk_cli/tests/testdata/localnet_with_resolution_remote.toml - - # "Go" and artifacts from "GOPATH/pkg/mod" are not needed anymore. - sudo rm -rf ~/multiversx-sdk/golang - - python3 -m multiversx_sdk_cli.cli localnet clean --configfile=./multiversx_sdk_cli/tests/testdata/localnet_with_resolution_remote.toml - python3 -m multiversx_sdk_cli.cli localnet config --configfile=./multiversx_sdk_cli/tests/testdata/localnet_with_resolution_remote.toml - python3 -m multiversx_sdk_cli.cli localnet start --configfile=./multiversx_sdk_cli/tests/testdata/localnet_with_resolution_remote.toml & - - if grep -r --include=\*.log "started committing block" ./localnet; then - echo "The localnet processed blocks successfully." - else - echo "The localnet failed to process blocks." - exit 1 - fi + docker run -d -p 7950:7950 mxpy localnet start - name: Test localnet dependent tests run: | - curl -XGET http://127.0.0.1:7950/network/config pytest -m require_localnet multiversx_sdk_cli/tests diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..0bf6711b --- /dev/null +++ b/Dockerfile @@ -0,0 +1,22 @@ +ARG PYTHON_VERSION=3.10 + +# Step 1: Use an official Python runtime as a parent image +FROM python:${PYTHON_VERSION}-slim + +# Step 2: Set the working directory in the container +WORKDIR /usr/src/app + +# Step 3: Copy the requirements file into the container +COPY requirements.txt ./ + +# Step 5: Copy the requirements-dev file into the container +COPY requirements-dev.txt ./ + +# Step 6: Install any dependencies listed in requirements.txt +RUN pip install --no-cache-dir -r requirements.txt + +# Step 7: Copy the current directory contents into the container +COPY . . + +# Step 6: Specify the command to run the application +ENTRYPOINT ["python", "-m", "multiversx_sdk_cli.cli"] \ No newline at end of file From 3f825a2922537a4168787df8233a012c7b6799a5 Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Thu, 24 Oct 2024 17:38:17 +0300 Subject: [PATCH 09/90] add checkout. --- .github/workflows/test-localnet-tests.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test-localnet-tests.yml b/.github/workflows/test-localnet-tests.yml index 1d6d80cb..73e140c6 100644 --- a/.github/workflows/test-localnet-tests.yml +++ b/.github/workflows/test-localnet-tests.yml @@ -19,6 +19,7 @@ jobs: python-version: [3.11] steps: + - uses: actions/checkout@v2 - name: Set up Docker image run: | docker build --build-arg PYTHON_VERSION=${{ matrix.python-version }} -t mxpy . From 99a198d40fb0369375e9fa0f13b0904db704255d Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Thu, 24 Oct 2024 17:40:50 +0300 Subject: [PATCH 10/90] install python dependencies in order to trigger the tests. --- .github/workflows/test-localnet-tests.yml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/.github/workflows/test-localnet-tests.yml b/.github/workflows/test-localnet-tests.yml index 73e140c6..b9b4c626 100644 --- a/.github/workflows/test-localnet-tests.yml +++ b/.github/workflows/test-localnet-tests.yml @@ -19,7 +19,23 @@ jobs: python-version: [3.11] steps: + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + - uses: actions/checkout@v2 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + + - name: Install dependencies + run: | + python3 -m pip install --upgrade pip + pip3 install -r requirements.txt + pip3 install -r ./requirements-dev.txt --upgrade + - name: Set up Docker image run: | docker build --build-arg PYTHON_VERSION=${{ matrix.python-version }} -t mxpy . From 3d2be36de5842efdcd725a4ea2fb00b379fed68a Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Thu, 24 Oct 2024 17:47:31 +0300 Subject: [PATCH 11/90] rename to localhost. possible issue with the loopback interface. --- multiversx_sdk_cli/tests/test_cli_validators.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/multiversx_sdk_cli/tests/test_cli_validators.py b/multiversx_sdk_cli/tests/test_cli_validators.py index 56f58777..256eeeaf 100644 --- a/multiversx_sdk_cli/tests/test_cli_validators.py +++ b/multiversx_sdk_cli/tests/test_cli_validators.py @@ -9,7 +9,7 @@ testdata_path = Path(__file__).parent / "testdata" testdata_out = Path(__file__).parent / "testdata-out" -proxy_url = "http://127.0.0.1:7950/network/config" +proxy_url = "http://localhost:7950/network/config" alice_pem = testdata_path / "alice.pem" reward_address = "erd1k2s324ww2g0yj38qn2ch2jwctdy8mnfxep94q9arncc6xecg3xaq6mjse8" bls_key = "e7beaa95b3877f47348df4dd1cb578a4f7cabf7a20bfeefe5cdd263878ff132b765e04fef6f40c93512b666c47ed7719b8902f6c922c04247989b7137e837cc81a62e54712471c97a2ddab75aa9c2f58f813ed4c0fa722bde0ab718bff382208" From beef1398f9538b8072c4c3120a549fec0f1ce9bb Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Thu, 24 Oct 2024 17:50:32 +0300 Subject: [PATCH 12/90] debug commands --- .github/workflows/test-localnet-tests.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test-localnet-tests.yml b/.github/workflows/test-localnet-tests.yml index b9b4c626..46e5bed4 100644 --- a/.github/workflows/test-localnet-tests.yml +++ b/.github/workflows/test-localnet-tests.yml @@ -46,4 +46,5 @@ jobs: - name: Test localnet dependent tests run: | + curl -X GET http://localhost:7950/network/config pytest -m require_localnet multiversx_sdk_cli/tests From 95f1a152c44a0bfb727ed459ab8a98169e57e1bb Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Thu, 24 Oct 2024 17:51:49 +0300 Subject: [PATCH 13/90] more debugging. --- .github/workflows/test-localnet-tests.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test-localnet-tests.yml b/.github/workflows/test-localnet-tests.yml index 46e5bed4..c472d2b0 100644 --- a/.github/workflows/test-localnet-tests.yml +++ b/.github/workflows/test-localnet-tests.yml @@ -46,5 +46,6 @@ jobs: - name: Test localnet dependent tests run: | + docker ps curl -X GET http://localhost:7950/network/config pytest -m require_localnet multiversx_sdk_cli/tests From 23b9961ca4448f949043f7733c2b2cdb0f7c912c Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Thu, 24 Oct 2024 17:53:04 +0300 Subject: [PATCH 14/90] add a sleep for debugging. --- .github/workflows/test-localnet-tests.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test-localnet-tests.yml b/.github/workflows/test-localnet-tests.yml index c472d2b0..ad58ab04 100644 --- a/.github/workflows/test-localnet-tests.yml +++ b/.github/workflows/test-localnet-tests.yml @@ -47,5 +47,6 @@ jobs: - name: Test localnet dependent tests run: | docker ps + sleep 5m curl -X GET http://localhost:7950/network/config pytest -m require_localnet multiversx_sdk_cli/tests From ef9cdb2b9d8c8d0fbdd027e6b16cbdcd0657bf0a Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Thu, 24 Oct 2024 18:01:59 +0300 Subject: [PATCH 15/90] trying to debug docker publishing in GHA. --- .github/workflows/test-localnet-tests.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test-localnet-tests.yml b/.github/workflows/test-localnet-tests.yml index ad58ab04..1c70bb08 100644 --- a/.github/workflows/test-localnet-tests.yml +++ b/.github/workflows/test-localnet-tests.yml @@ -42,11 +42,11 @@ jobs: - name: Deploy a localnet run: | - docker run -d -p 7950:7950 mxpy localnet start + docker run -name localnet -d -p 7950:7950 mxpy localnet start - name: Test localnet dependent tests run: | - docker ps sleep 5m - curl -X GET http://localhost:7950/network/config + docker logs localnet | grep proxy + curl -X GET http://0.0.0.0:7950/network/config pytest -m require_localnet multiversx_sdk_cli/tests From 5043947beb63ad6ff003c241e2463370fe91db5d Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Thu, 24 Oct 2024 18:05:10 +0300 Subject: [PATCH 16/90] cosmetic changes --- .github/workflows/test-localnet-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test-localnet-tests.yml b/.github/workflows/test-localnet-tests.yml index 1c70bb08..39929665 100644 --- a/.github/workflows/test-localnet-tests.yml +++ b/.github/workflows/test-localnet-tests.yml @@ -42,7 +42,7 @@ jobs: - name: Deploy a localnet run: | - docker run -name localnet -d -p 7950:7950 mxpy localnet start + docker run --name localnet -d -p 7950:7950 mxpy localnet start - name: Test localnet dependent tests run: | From 4953eaa2fbcac5d76655ec8ec3fc075591446a07 Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Thu, 24 Oct 2024 18:12:02 +0300 Subject: [PATCH 17/90] move sleep above. --- .github/workflows/test-localnet-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test-localnet-tests.yml b/.github/workflows/test-localnet-tests.yml index 39929665..6135ca63 100644 --- a/.github/workflows/test-localnet-tests.yml +++ b/.github/workflows/test-localnet-tests.yml @@ -43,10 +43,10 @@ jobs: - name: Deploy a localnet run: | docker run --name localnet -d -p 7950:7950 mxpy localnet start + sleep 2m - name: Test localnet dependent tests run: | - sleep 5m docker logs localnet | grep proxy curl -X GET http://0.0.0.0:7950/network/config pytest -m require_localnet multiversx_sdk_cli/tests From a5ccb0352d7403d8c15aac9e76241d00e457efc4 Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Thu, 24 Oct 2024 18:19:28 +0300 Subject: [PATCH 18/90] more debugging. --- .github/workflows/test-localnet-tests.yml | 5 ++--- multiversx_sdk_cli/tests/test_cli_validators.py | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test-localnet-tests.yml b/.github/workflows/test-localnet-tests.yml index 6135ca63..c9ee68e1 100644 --- a/.github/workflows/test-localnet-tests.yml +++ b/.github/workflows/test-localnet-tests.yml @@ -43,10 +43,9 @@ jobs: - name: Deploy a localnet run: | docker run --name localnet -d -p 7950:7950 mxpy localnet start - sleep 2m - name: Test localnet dependent tests run: | - docker logs localnet | grep proxy - curl -X GET http://0.0.0.0:7950/network/config + sleep 2m + curl -XGET http://0.0.0.0:7950/network/config pytest -m require_localnet multiversx_sdk_cli/tests diff --git a/multiversx_sdk_cli/tests/test_cli_validators.py b/multiversx_sdk_cli/tests/test_cli_validators.py index 256eeeaf..6833513b 100644 --- a/multiversx_sdk_cli/tests/test_cli_validators.py +++ b/multiversx_sdk_cli/tests/test_cli_validators.py @@ -18,7 +18,7 @@ @pytest.fixture() def poll_endpoint(): start_time = time.time() # Record the start time - timeout = 60 + timeout = 300 interval = 1 while True: From 7e889f1697bd8bd0a92259756f7c366670a00c83 Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Thu, 24 Oct 2024 18:25:47 +0300 Subject: [PATCH 19/90] increase timeout to 10 mins. --- .github/workflows/test-localnet-tests.yml | 2 -- multiversx_sdk_cli/tests/test_cli_validators.py | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/test-localnet-tests.yml b/.github/workflows/test-localnet-tests.yml index c9ee68e1..01297dd5 100644 --- a/.github/workflows/test-localnet-tests.yml +++ b/.github/workflows/test-localnet-tests.yml @@ -46,6 +46,4 @@ jobs: - name: Test localnet dependent tests run: | - sleep 2m - curl -XGET http://0.0.0.0:7950/network/config pytest -m require_localnet multiversx_sdk_cli/tests diff --git a/multiversx_sdk_cli/tests/test_cli_validators.py b/multiversx_sdk_cli/tests/test_cli_validators.py index 6833513b..8a01ae41 100644 --- a/multiversx_sdk_cli/tests/test_cli_validators.py +++ b/multiversx_sdk_cli/tests/test_cli_validators.py @@ -18,7 +18,7 @@ @pytest.fixture() def poll_endpoint(): start_time = time.time() # Record the start time - timeout = 300 + timeout = 600 interval = 1 while True: From 0af4d95e7dea639e3b0b35f53888e656a7fc77cd Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Thu, 24 Oct 2024 18:35:00 +0300 Subject: [PATCH 20/90] check logs of docker localnet inside worker. --- .github/workflows/test-localnet-tests.yml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/.github/workflows/test-localnet-tests.yml b/.github/workflows/test-localnet-tests.yml index 01297dd5..896a6067 100644 --- a/.github/workflows/test-localnet-tests.yml +++ b/.github/workflows/test-localnet-tests.yml @@ -42,8 +42,4 @@ jobs: - name: Deploy a localnet run: | - docker run --name localnet -d -p 7950:7950 mxpy localnet start - - - name: Test localnet dependent tests - run: | - pytest -m require_localnet multiversx_sdk_cli/tests + docker run --name localnet -p 7950:7950 mxpy localnet start From 05a7e574541e9455d4cab3580851900c302a7836 Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Thu, 24 Oct 2024 19:27:01 +0300 Subject: [PATCH 21/90] fix CI and dockerfile by installing build-essential in the docker container. --- .github/workflows/test-localnet-tests.yml | 6 +++++- Dockerfile | 7 +++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test-localnet-tests.yml b/.github/workflows/test-localnet-tests.yml index 896a6067..a5cc097f 100644 --- a/.github/workflows/test-localnet-tests.yml +++ b/.github/workflows/test-localnet-tests.yml @@ -42,4 +42,8 @@ jobs: - name: Deploy a localnet run: | - docker run --name localnet -p 7950:7950 mxpy localnet start + docker run --name localnet -d -p 7950:7950 mxpy localnet setup && mxpy localnet start + + - name: Test localnet dependent tests + run: | + pytest -m require_localnet multiversx_sdk_cli/tests diff --git a/Dockerfile b/Dockerfile index 0bf6711b..3d69006a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -15,8 +15,11 @@ COPY requirements-dev.txt ./ # Step 6: Install any dependencies listed in requirements.txt RUN pip install --no-cache-dir -r requirements.txt -# Step 7: Copy the current directory contents into the container +# Step 7: Install build-essential. Will be needed to compile the node binaries. +RUN apt update && apt install -y build-essential + +# Step 8: Copy the current directory contents into the container COPY . . -# Step 6: Specify the command to run the application +# Step 9: Specify the command to run the application ENTRYPOINT ["python", "-m", "multiversx_sdk_cli.cli"] \ No newline at end of file From ec17ddac0f5fcd6ce74c13544be7c8db15876800 Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Thu, 24 Oct 2024 19:30:38 +0300 Subject: [PATCH 22/90] adding verbose command. --- .github/workflows/test-localnet-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test-localnet-tests.yml b/.github/workflows/test-localnet-tests.yml index a5cc097f..06db8c9d 100644 --- a/.github/workflows/test-localnet-tests.yml +++ b/.github/workflows/test-localnet-tests.yml @@ -42,7 +42,7 @@ jobs: - name: Deploy a localnet run: | - docker run --name localnet -d -p 7950:7950 mxpy localnet setup && mxpy localnet start + docker run --name localnet -d -p 7950:7950 mxpy localnet setup && python -m multiversx_sdk_cli.cli localnet start - name: Test localnet dependent tests run: | From 1a4fe12f5f5bafd8041bdbd63f724d25910ec065 Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Fri, 25 Oct 2024 10:29:43 +0300 Subject: [PATCH 23/90] Fix deploy localnet job. --- .github/workflows/test-localnet-tests.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test-localnet-tests.yml b/.github/workflows/test-localnet-tests.yml index 06db8c9d..82b99b91 100644 --- a/.github/workflows/test-localnet-tests.yml +++ b/.github/workflows/test-localnet-tests.yml @@ -42,7 +42,9 @@ jobs: - name: Deploy a localnet run: | - docker run --name localnet -d -p 7950:7950 mxpy localnet setup && python -m multiversx_sdk_cli.cli localnet start + docker run -d -p 7950:7950 \ + -v ./multiversx_sdk_cli/tests/testdata/localnet_with_resolution_remote.toml=/usr/src/app/localnet.toml \ + mxpy localnet setup && python -m multiversx_sdk_cli.cli localnet start - name: Test localnet dependent tests run: | From 900530f3f2c6f0eb0e0d963d35735cfaa3f87e5f Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Fri, 25 Oct 2024 10:31:49 +0300 Subject: [PATCH 24/90] fix whitespaces in multi-line command. --- .github/workflows/test-localnet-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test-localnet-tests.yml b/.github/workflows/test-localnet-tests.yml index 82b99b91..bbf55dd5 100644 --- a/.github/workflows/test-localnet-tests.yml +++ b/.github/workflows/test-localnet-tests.yml @@ -42,7 +42,7 @@ jobs: - name: Deploy a localnet run: | - docker run -d -p 7950:7950 \ + docker run -d -p 7950:7950 \ -v ./multiversx_sdk_cli/tests/testdata/localnet_with_resolution_remote.toml=/usr/src/app/localnet.toml \ mxpy localnet setup && python -m multiversx_sdk_cli.cli localnet start From 17a08cf813f4fc05b2d3e62ef8bc4e9386933cd0 Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Fri, 25 Oct 2024 11:07:02 +0300 Subject: [PATCH 25/90] fixing docker image and localnet setup. --- .github/workflows/test-localnet-tests.yml | 6 ++---- Dockerfile | 5 ++++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/.github/workflows/test-localnet-tests.yml b/.github/workflows/test-localnet-tests.yml index bbf55dd5..7cccad1a 100644 --- a/.github/workflows/test-localnet-tests.yml +++ b/.github/workflows/test-localnet-tests.yml @@ -42,10 +42,8 @@ jobs: - name: Deploy a localnet run: | - docker run -d -p 7950:7950 \ - -v ./multiversx_sdk_cli/tests/testdata/localnet_with_resolution_remote.toml=/usr/src/app/localnet.toml \ - mxpy localnet setup && python -m multiversx_sdk_cli.cli localnet start - + docker run -d -p 7950:7950 mxpy localnet start \ + --configfile=/usr/src/app/multiversx_sdk_cli/tests/testdata/localnet_with_resolution_remote.toml - name: Test localnet dependent tests run: | pytest -m require_localnet multiversx_sdk_cli/tests diff --git a/Dockerfile b/Dockerfile index 3d69006a..9d6f84a4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -21,5 +21,8 @@ RUN apt update && apt install -y build-essential # Step 8: Copy the current directory contents into the container COPY . . -# Step 9: Specify the command to run the application +# Step 9: Setup the localnet configuration in the eventuality of a localnet start. +RUN python -m multiversx_sdk_cli.cli localnet setup --configfile=/usr/src/app/multiversx_sdk_cli/tests/testdata/localnet_with_resolution_remote.toml + +# Step 10: Specify the entrypoint to run the application ENTRYPOINT ["python", "-m", "multiversx_sdk_cli.cli"] \ No newline at end of file From 8359cbb3ccc6e0121a52375193014ddaefb8dd6d Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Fri, 25 Oct 2024 11:19:59 +0300 Subject: [PATCH 26/90] adding separate validators json file for docker tests. --- Dockerfile | 2 +- multiversx_sdk_cli/tests/test_cli_validators.py | 2 +- .../tests/testdata/validators_docker.json | 13 +++++++++++++ 3 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 multiversx_sdk_cli/tests/testdata/validators_docker.json diff --git a/Dockerfile b/Dockerfile index 9d6f84a4..bf595f5f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -25,4 +25,4 @@ COPY . . RUN python -m multiversx_sdk_cli.cli localnet setup --configfile=/usr/src/app/multiversx_sdk_cli/tests/testdata/localnet_with_resolution_remote.toml # Step 10: Specify the entrypoint to run the application -ENTRYPOINT ["python", "-m", "multiversx_sdk_cli.cli"] \ No newline at end of file +CMD ["python", "-m", "multiversx_sdk_cli.cli"] \ No newline at end of file diff --git a/multiversx_sdk_cli/tests/test_cli_validators.py b/multiversx_sdk_cli/tests/test_cli_validators.py index 8a01ae41..eeccb028 100644 --- a/multiversx_sdk_cli/tests/test_cli_validators.py +++ b/multiversx_sdk_cli/tests/test_cli_validators.py @@ -46,7 +46,7 @@ def poll_endpoint(): @pytest.mark.require_localnet def test_stake(poll_endpoint): - validators_json = testdata_path / "validators.json" + validators_json = testdata_path / "validators_docker.json" # Stake with recall nonce return_code = main([ diff --git a/multiversx_sdk_cli/tests/testdata/validators_docker.json b/multiversx_sdk_cli/tests/testdata/validators_docker.json new file mode 100644 index 00000000..edf4f998 --- /dev/null +++ b/multiversx_sdk_cli/tests/testdata/validators_docker.json @@ -0,0 +1,13 @@ +{ + "validators": [ + { + "pemFile": "/usr/src/app/localnet/validator00/config/walletKey.pem" + }, + { + "pemFile": "/usr/src/app/localnet/validator00/config/walletKey.pem" + }, + { + "pemFile": "/usr/src/app/localnet/validator00/config/walletKey.pem" + } + ] +} From b43c31a785e95e41e3fee4245e60396740b09eed Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Fri, 25 Oct 2024 11:23:43 +0300 Subject: [PATCH 27/90] fixing Dockerfile --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index bf595f5f..9d6f84a4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -25,4 +25,4 @@ COPY . . RUN python -m multiversx_sdk_cli.cli localnet setup --configfile=/usr/src/app/multiversx_sdk_cli/tests/testdata/localnet_with_resolution_remote.toml # Step 10: Specify the entrypoint to run the application -CMD ["python", "-m", "multiversx_sdk_cli.cli"] \ No newline at end of file +ENTRYPOINT ["python", "-m", "multiversx_sdk_cli.cli"] \ No newline at end of file From bbe93e7af76598b59b73562b7f3acb75515ad222 Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Fri, 25 Oct 2024 11:31:44 +0300 Subject: [PATCH 28/90] fix paths for validators_docker.json --- multiversx_sdk_cli/tests/testdata/validators_docker.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/multiversx_sdk_cli/tests/testdata/validators_docker.json b/multiversx_sdk_cli/tests/testdata/validators_docker.json index edf4f998..ac0198c0 100644 --- a/multiversx_sdk_cli/tests/testdata/validators_docker.json +++ b/multiversx_sdk_cli/tests/testdata/validators_docker.json @@ -1,13 +1,13 @@ { "validators": [ { - "pemFile": "/usr/src/app/localnet/validator00/config/walletKey.pem" + "pemFile": "/usr/src/app/localnet/validator00/config/validatorKey.pem" }, { - "pemFile": "/usr/src/app/localnet/validator00/config/walletKey.pem" + "pemFile": "/usr/src/app/localnet/validator00/config/validatorKey.pem" }, { - "pemFile": "/usr/src/app/localnet/validator00/config/walletKey.pem" + "pemFile": "/usr/src/app/localnet/validator00/config/validatorKey.pem" } ] } From ad7e421f941811858cc2800c2008ccca86cbbd2f Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Fri, 25 Oct 2024 11:41:28 +0300 Subject: [PATCH 29/90] fix paths in validators_docker.json --- multiversx_sdk_cli/tests/testdata/validators_docker.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/multiversx_sdk_cli/tests/testdata/validators_docker.json b/multiversx_sdk_cli/tests/testdata/validators_docker.json index ac0198c0..e0cc9f79 100644 --- a/multiversx_sdk_cli/tests/testdata/validators_docker.json +++ b/multiversx_sdk_cli/tests/testdata/validators_docker.json @@ -4,10 +4,10 @@ "pemFile": "/usr/src/app/localnet/validator00/config/validatorKey.pem" }, { - "pemFile": "/usr/src/app/localnet/validator00/config/validatorKey.pem" + "pemFile": "/usr/src/app/localnet/validator01/config/validatorKey.pem" }, { - "pemFile": "/usr/src/app/localnet/validator00/config/validatorKey.pem" + "pemFile": "/usr/src/app/localnet/validator02/config/validatorKey.pem" } ] } From bfe909fe156897d01d822dce731aee7e0882587f Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Fri, 25 Oct 2024 12:17:51 +0300 Subject: [PATCH 30/90] fix validators_docker.json --- .github/workflows/test-localnet-tests.yml | 9 ++++++++- multiversx_sdk_cli/tests/testdata/validators_docker.json | 6 +++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test-localnet-tests.yml b/.github/workflows/test-localnet-tests.yml index 7cccad1a..44c9c103 100644 --- a/.github/workflows/test-localnet-tests.yml +++ b/.github/workflows/test-localnet-tests.yml @@ -42,8 +42,15 @@ jobs: - name: Deploy a localnet run: | - docker run -d -p 7950:7950 mxpy localnet start \ + docker run --name localnet -d -p 7950:7950 mxpy localnet start \ --configfile=/usr/src/app/multiversx_sdk_cli/tests/testdata/localnet_with_resolution_remote.toml + - name: Test localnet dependent tests run: | + docker cp localnet:/usr/src/app/localnet/validator00/config/validatorKey.pem ./validatorKey00.pem + docker cp localnet:/usr/src/app/localnet/validator01/config/validatorKey.pem ./validatorKey01.pem + docker cp localnet:/usr/src/app/localnet/validator02/config/validatorKey.pem ./validatorKey02.pem + + + pytest -m require_localnet multiversx_sdk_cli/tests diff --git a/multiversx_sdk_cli/tests/testdata/validators_docker.json b/multiversx_sdk_cli/tests/testdata/validators_docker.json index e0cc9f79..c3314d0a 100644 --- a/multiversx_sdk_cli/tests/testdata/validators_docker.json +++ b/multiversx_sdk_cli/tests/testdata/validators_docker.json @@ -1,13 +1,13 @@ { "validators": [ { - "pemFile": "/usr/src/app/localnet/validator00/config/validatorKey.pem" + "pemFile": "~/mx-sdk-py-cli/validatorKey00.pem" }, { - "pemFile": "/usr/src/app/localnet/validator01/config/validatorKey.pem" + "pemFile": "~/mx-sdk-py-cli/validatorKey01.pem" }, { - "pemFile": "/usr/src/app/localnet/validator02/config/validatorKey.pem" + "pemFile": "~/mx-sdk-py-cli/validatorKey02.pem" } ] } From 83b76aa80e1e0f986d8c3e5c67d40f672457cbb4 Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Fri, 25 Oct 2024 12:22:08 +0300 Subject: [PATCH 31/90] fix yaml file. --- .github/workflows/test-localnet-tests.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/test-localnet-tests.yml b/.github/workflows/test-localnet-tests.yml index 44c9c103..a341db7a 100644 --- a/.github/workflows/test-localnet-tests.yml +++ b/.github/workflows/test-localnet-tests.yml @@ -50,7 +50,4 @@ jobs: docker cp localnet:/usr/src/app/localnet/validator00/config/validatorKey.pem ./validatorKey00.pem docker cp localnet:/usr/src/app/localnet/validator01/config/validatorKey.pem ./validatorKey01.pem docker cp localnet:/usr/src/app/localnet/validator02/config/validatorKey.pem ./validatorKey02.pem - - - pytest -m require_localnet multiversx_sdk_cli/tests From 88047542e2f6507d999994d527a6f4b01583b54b Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Fri, 25 Oct 2024 12:40:07 +0300 Subject: [PATCH 32/90] fix yaml file, round 2. --- .github/workflows/test-localnet-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test-localnet-tests.yml b/.github/workflows/test-localnet-tests.yml index a341db7a..343b2ee0 100644 --- a/.github/workflows/test-localnet-tests.yml +++ b/.github/workflows/test-localnet-tests.yml @@ -50,4 +50,4 @@ jobs: docker cp localnet:/usr/src/app/localnet/validator00/config/validatorKey.pem ./validatorKey00.pem docker cp localnet:/usr/src/app/localnet/validator01/config/validatorKey.pem ./validatorKey01.pem docker cp localnet:/usr/src/app/localnet/validator02/config/validatorKey.pem ./validatorKey02.pem - pytest -m require_localnet multiversx_sdk_cli/tests + pytest -m require_localnet multiversx_sdk_cli/tests From d3d0d5c7a9c91fb2f2446d6bee59a1869e11a9c0 Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Fri, 25 Oct 2024 12:47:12 +0300 Subject: [PATCH 33/90] add debug commands. --- .github/workflows/test-localnet-tests.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/test-localnet-tests.yml b/.github/workflows/test-localnet-tests.yml index 343b2ee0..582060b1 100644 --- a/.github/workflows/test-localnet-tests.yml +++ b/.github/workflows/test-localnet-tests.yml @@ -50,4 +50,9 @@ jobs: docker cp localnet:/usr/src/app/localnet/validator00/config/validatorKey.pem ./validatorKey00.pem docker cp localnet:/usr/src/app/localnet/validator01/config/validatorKey.pem ./validatorKey01.pem docker cp localnet:/usr/src/app/localnet/validator02/config/validatorKey.pem ./validatorKey02.pem + + ls + echo $(pwd) + + pytest -m require_localnet multiversx_sdk_cli/tests From 9f9b8c03664d00312a3204eaa5755c9f62bdd8d3 Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Fri, 25 Oct 2024 12:54:47 +0300 Subject: [PATCH 34/90] debug home directory inside runner. --- .github/workflows/test-localnet-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test-localnet-tests.yml b/.github/workflows/test-localnet-tests.yml index 582060b1..dfa69246 100644 --- a/.github/workflows/test-localnet-tests.yml +++ b/.github/workflows/test-localnet-tests.yml @@ -52,7 +52,7 @@ jobs: docker cp localnet:/usr/src/app/localnet/validator02/config/validatorKey.pem ./validatorKey02.pem ls - echo $(pwd) + echo ~ pytest -m require_localnet multiversx_sdk_cli/tests From 79392ad94d0013d87e32fd77cf9a463cfbf6d7b5 Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Fri, 25 Oct 2024 13:00:15 +0300 Subject: [PATCH 35/90] fix paths. --- multiversx_sdk_cli/tests/testdata/validators_docker.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/multiversx_sdk_cli/tests/testdata/validators_docker.json b/multiversx_sdk_cli/tests/testdata/validators_docker.json index c3314d0a..2adb1109 100644 --- a/multiversx_sdk_cli/tests/testdata/validators_docker.json +++ b/multiversx_sdk_cli/tests/testdata/validators_docker.json @@ -1,13 +1,13 @@ { "validators": [ { - "pemFile": "~/mx-sdk-py-cli/validatorKey00.pem" + "pemFile": "~/work/mx-sdk-py-cli/mx-sdk-py-cli/validatorKey00.pem" }, { - "pemFile": "~/mx-sdk-py-cli/validatorKey01.pem" + "pemFile": "~/work/mx-sdk-py-cli/mx-sdk-py-cli/validatorKey01.pem" }, { - "pemFile": "~/mx-sdk-py-cli/validatorKey02.pem" + "pemFile": "~/work/mx-sdk-py-cli/mx-sdk-py-clivalidatorKey02.pem" } ] } From d3f707dc4ff508f159d47181ea1f145b29538249 Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Fri, 25 Oct 2024 13:37:42 +0300 Subject: [PATCH 36/90] more debugging. --- .github/workflows/test-localnet-tests.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/test-localnet-tests.yml b/.github/workflows/test-localnet-tests.yml index dfa69246..618c5f6a 100644 --- a/.github/workflows/test-localnet-tests.yml +++ b/.github/workflows/test-localnet-tests.yml @@ -52,7 +52,10 @@ jobs: docker cp localnet:/usr/src/app/localnet/validator02/config/validatorKey.pem ./validatorKey02.pem ls + echo "HOME DIR:" echo ~ + echo "CURR PATH:" + echo $(pwd) pytest -m require_localnet multiversx_sdk_cli/tests From adaf45a3f1b402343d445e04fe2cea41568f7002 Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Fri, 25 Oct 2024 13:41:11 +0300 Subject: [PATCH 37/90] fix more paths. --- multiversx_sdk_cli/tests/testdata/validators_docker.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/multiversx_sdk_cli/tests/testdata/validators_docker.json b/multiversx_sdk_cli/tests/testdata/validators_docker.json index 2adb1109..51fe7684 100644 --- a/multiversx_sdk_cli/tests/testdata/validators_docker.json +++ b/multiversx_sdk_cli/tests/testdata/validators_docker.json @@ -7,7 +7,7 @@ "pemFile": "~/work/mx-sdk-py-cli/mx-sdk-py-cli/validatorKey01.pem" }, { - "pemFile": "~/work/mx-sdk-py-cli/mx-sdk-py-clivalidatorKey02.pem" + "pemFile": "~/work/mx-sdk-py-cli/mx-sdk-py-cli/validatorKey02.pem" } ] } From 28fa95858729a40bd8b8c662a2c13d257346f774 Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Fri, 25 Oct 2024 13:46:13 +0300 Subject: [PATCH 38/90] add debug sleep. --- .github/workflows/test-localnet-tests.yml | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/.github/workflows/test-localnet-tests.yml b/.github/workflows/test-localnet-tests.yml index 618c5f6a..2b407afd 100644 --- a/.github/workflows/test-localnet-tests.yml +++ b/.github/workflows/test-localnet-tests.yml @@ -50,12 +50,5 @@ jobs: docker cp localnet:/usr/src/app/localnet/validator00/config/validatorKey.pem ./validatorKey00.pem docker cp localnet:/usr/src/app/localnet/validator01/config/validatorKey.pem ./validatorKey01.pem docker cp localnet:/usr/src/app/localnet/validator02/config/validatorKey.pem ./validatorKey02.pem - - ls - echo "HOME DIR:" - echo ~ - echo "CURR PATH:" - echo $(pwd) - - + sleep 2m pytest -m require_localnet multiversx_sdk_cli/tests From 0e46464b98bb24d30c9c0cdcab2e4a9110913341 Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Fri, 25 Oct 2024 13:53:09 +0300 Subject: [PATCH 39/90] cosmetic changes. --- .github/workflows/test-localnet-tests.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test-localnet-tests.yml b/.github/workflows/test-localnet-tests.yml index 2b407afd..de79cbcb 100644 --- a/.github/workflows/test-localnet-tests.yml +++ b/.github/workflows/test-localnet-tests.yml @@ -13,9 +13,7 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: -# TODO: enable mac-os back once debugging is done. -# os: [ubuntu-latest, macos-latest] - os: [ubuntu-latest] + os: [ubuntu-latest, macos-latest] python-version: [3.11] steps: @@ -50,5 +48,6 @@ jobs: docker cp localnet:/usr/src/app/localnet/validator00/config/validatorKey.pem ./validatorKey00.pem docker cp localnet:/usr/src/app/localnet/validator01/config/validatorKey.pem ./validatorKey01.pem docker cp localnet:/usr/src/app/localnet/validator02/config/validatorKey.pem ./validatorKey02.pem +# TODO: introduce polling in test fixture sleep 2m pytest -m require_localnet multiversx_sdk_cli/tests From 7045c321b6688f4abf69b2b46eec12676a816d50 Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Fri, 25 Oct 2024 13:54:48 +0300 Subject: [PATCH 40/90] fix yaml file. --- .github/workflows/test-localnet-tests.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test-localnet-tests.yml b/.github/workflows/test-localnet-tests.yml index de79cbcb..5cf98d84 100644 --- a/.github/workflows/test-localnet-tests.yml +++ b/.github/workflows/test-localnet-tests.yml @@ -43,11 +43,12 @@ jobs: docker run --name localnet -d -p 7950:7950 mxpy localnet start \ --configfile=/usr/src/app/multiversx_sdk_cli/tests/testdata/localnet_with_resolution_remote.toml +# TODO: introduce polling in test fixture +# remove sleep - name: Test localnet dependent tests run: | docker cp localnet:/usr/src/app/localnet/validator00/config/validatorKey.pem ./validatorKey00.pem docker cp localnet:/usr/src/app/localnet/validator01/config/validatorKey.pem ./validatorKey01.pem docker cp localnet:/usr/src/app/localnet/validator02/config/validatorKey.pem ./validatorKey02.pem -# TODO: introduce polling in test fixture sleep 2m pytest -m require_localnet multiversx_sdk_cli/tests From d07aa7cb99157f7aeafcfdf4a6a823dbc9519ef3 Mon Sep 17 00:00:00 2001 From: Alexandru Popenta Date: Fri, 25 Oct 2024 16:10:46 +0300 Subject: [PATCH 41/90] remove relayed v3 related code and tests --- multiversx_sdk_cli/cli_shared.py | 7 -- multiversx_sdk_cli/cli_transactions.py | 37 +------- .../tests/test_cli_transactions.py | 91 +------------------ multiversx_sdk_cli/transactions.py | 15 --- pyproject.toml | 2 +- 5 files changed, 4 insertions(+), 148 deletions(-) diff --git a/multiversx_sdk_cli/cli_shared.py b/multiversx_sdk_cli/cli_shared.py index 867c2e1f..1236914d 100644 --- a/multiversx_sdk_cli/cli_shared.py +++ b/multiversx_sdk_cli/cli_shared.py @@ -92,17 +92,10 @@ def add_tx_args( sub.add_argument("--version", type=int, default=DEFAULT_TX_VERSION, help="the transaction version (default: %(default)s)") add_guardian_args(sub) - add_relayed_v3_args(sub) sub.add_argument("--options", type=int, default=0, help="the transaction options (default: 0)") -def add_relayed_v3_args(sub: Any): - sub.add_argument("--relayer", help="the address of the relayer") - sub.add_argument("--inner-transactions", help="a json file containing the inner transactions; should only be provided when creating the relayer's transaction") - sub.add_argument("--inner-transactions-outfile", type=str, help="where to save the transaction as an inner transaction (default: stdout)") - - def add_guardian_args(sub: Any): sub.add_argument("--guardian", type=str, help="the address of the guradian", default="") sub.add_argument("--guardian-service-url", type=str, help="the url of the guardian service", default="") diff --git a/multiversx_sdk_cli/cli_transactions.py b/multiversx_sdk_cli/cli_transactions.py index 924e4c9d..a701961b 100644 --- a/multiversx_sdk_cli/cli_transactions.py +++ b/multiversx_sdk_cli/cli_transactions.py @@ -1,17 +1,14 @@ import logging from pathlib import Path -from typing import Any, Dict, List - -from multiversx_sdk import Transaction, TransactionsConverter +from typing import Any, List from multiversx_sdk_cli import cli_shared, utils from multiversx_sdk_cli.cli_output import CLIOutputBuilder from multiversx_sdk_cli.cosign_transaction import cosign_transaction from multiversx_sdk_cli.custom_network_provider import CustomNetworkProvider -from multiversx_sdk_cli.errors import BadUsage, NoWalletProvided +from multiversx_sdk_cli.errors import NoWalletProvided from multiversx_sdk_cli.transactions import (compute_relayed_v1_data, do_prepare_transaction, - load_inner_transactions_from_file, load_transaction_from_file) logger = logging.getLogger("cli.transactions") @@ -85,14 +82,8 @@ def create_transaction(args: Any): if args.data_file: args.data = Path(args.data_file).read_text() - check_relayer_transaction_with_data_field_for_relayed_v3(args) - tx = do_prepare_transaction(args) - if hasattr(args, "inner_transactions_outfile") and args.inner_transactions_outfile: - save_transaction_to_inner_transactions_file(tx, args) - return - if hasattr(args, "relay") and args.relay: logger.warning("RelayedV1 transactions are deprecated. Please use RelayedV3 instead.") args.outfile.write(compute_relayed_v1_data(tx)) @@ -101,30 +92,6 @@ def create_transaction(args: Any): cli_shared.send_or_simulate(tx, args) -def save_transaction_to_inner_transactions_file(transaction: Transaction, args: Any): - inner_txs_file = Path(args.inner_transactions_outfile).expanduser() - transactions = get_inner_transactions_if_any(inner_txs_file) - transactions.append(transaction) - - tx_converter = TransactionsConverter() - inner_transactions: Dict[str, Any] = {} - inner_transactions["innerTransactions"] = [tx_converter.transaction_to_dictionary(tx) for tx in transactions] - - with open(inner_txs_file, "w") as file: - utils.dump_out_json(inner_transactions, file) - - -def get_inner_transactions_if_any(file: Path) -> List[Transaction]: - if file.is_file(): - return load_inner_transactions_from_file(file) - return [] - - -def check_relayer_transaction_with_data_field_for_relayed_v3(args: Any): - if hasattr(args, "inner_transactions") and args.inner_transactions and args.data: - raise BadUsage("Can't set data field when creating a relayedV3 transaction") - - def send_transaction(args: Any): args = utils.as_object(args) diff --git a/multiversx_sdk_cli/tests/test_cli_transactions.py b/multiversx_sdk_cli/tests/test_cli_transactions.py index c8148ae3..1ac07470 100644 --- a/multiversx_sdk_cli/tests/test_cli_transactions.py +++ b/multiversx_sdk_cli/tests/test_cli_transactions.py @@ -1,7 +1,6 @@ import json -import os from pathlib import Path -from typing import Any, List +from typing import Any from multiversx_sdk_cli.cli import main @@ -89,93 +88,5 @@ def test_create_multi_transfer_transaction(capsys: Any): assert signature == "575b029d52ff5ffbfb7bab2f04052de88a6f7d022a6ad368459b8af9acaed3717d3f95db09f460649a8f405800838bc2c432496bd03c9039ea166bd32b84660e" -def test_create_and_save_inner_transaction(): - return_code = main([ - "tx", "new", - "--pem", str(testdata_path / "alice.pem"), - "--receiver", "erd1spyavw0956vq68xj8y4tenjpq2wd5a9p2c6j8gsz7ztyrnpxrruqzu66jx", - "--nonce", "77", - "--gas-limit", "500000", - "--relayer", "erd1k2s324ww2g0yj38qn2ch2jwctdy8mnfxep94q9arncc6xecg3xaq6mjse8", - "--inner-transactions-outfile", str(testdata_out / "inner_transactions.json"), - "--chain", "T", - ]) - assert False if return_code else True - assert Path(testdata_out / "inner_transactions.json").is_file() - - -def test_create_and_append_inner_transaction(): - return_code = main([ - "tx", "new", - "--pem", str(testdata_path / "alice.pem"), - "--receiver", "erd1fggp5ru0jhcjrp5rjqyqrnvhr3sz3v2e0fm3ktknvlg7mcyan54qzccnan", - "--nonce", "1234", - "--gas-limit", "50000", - "--relayer", "erd1k2s324ww2g0yj38qn2ch2jwctdy8mnfxep94q9arncc6xecg3xaq6mjse8", - "--inner-transactions-outfile", str(testdata_out / "inner_transactions.json"), - "--chain", "T", - ]) - assert False if return_code else True - - with open(testdata_out / "inner_transactions.json", "r") as file: - json_file = json.load(file) - - inner_txs: List[Any] = json_file["innerTransactions"] - assert len(inner_txs) == 2 - - -def test_create_invalid_relayed_transaction(): - return_code = main([ - "tx", "new", - "--pem", str(testdata_path / "testUser.pem"), - "--receiver", "erd1cqqxak4wun7508e0yj9ng843r6hv4mzd0hhpjpsejkpn9wa9yq8sj7u2u5", - "--nonce", "987", - "--gas-limit", "5000000", - "--inner-transactions", str(testdata_out / "inner_transactions.json"), - "--data", "test data", - "--chain", "T", - ]) - assert return_code - - -def test_create_relayer_transaction(capsys: Any): - return_code = main([ - "tx", "new", - "--pem", str(testdata_path / "testUser.pem"), - "--receiver", "erd1cqqxak4wun7508e0yj9ng843r6hv4mzd0hhpjpsejkpn9wa9yq8sj7u2u5", - "--nonce", "987", - "--gas-limit", "5000000", - "--inner-transactions", str(testdata_out / "inner_transactions.json"), - "--chain", "T", - ]) - # remove test file to ensure consistency when running test file locally - os.remove(testdata_out / "inner_transactions.json") - - assert False if return_code else True - - tx = _read_stdout(capsys) - tx_json = json.loads(tx)["emittedTransaction"] - - assert tx_json["sender"] == "erd1cqqxak4wun7508e0yj9ng843r6hv4mzd0hhpjpsejkpn9wa9yq8sj7u2u5" - assert tx_json["receiver"] == "erd1cqqxak4wun7508e0yj9ng843r6hv4mzd0hhpjpsejkpn9wa9yq8sj7u2u5" - assert tx_json["gasLimit"] == 5000000 - assert tx_json["nonce"] == 987 - assert tx_json["chainID"] == "T" - - # should be the two inner transactions created in the tests above - inner_transactions = tx_json["innerTransactions"] - assert len(inner_transactions) == 2 - - assert inner_transactions[0]["sender"] == "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th" - assert inner_transactions[0]["receiver"] == "erd1spyavw0956vq68xj8y4tenjpq2wd5a9p2c6j8gsz7ztyrnpxrruqzu66jx" - assert inner_transactions[0]["nonce"] == 77 - assert inner_transactions[0]["relayer"] == "erd1k2s324ww2g0yj38qn2ch2jwctdy8mnfxep94q9arncc6xecg3xaq6mjse8" - - assert inner_transactions[1]["sender"] == "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th" - assert inner_transactions[1]["receiver"] == "erd1fggp5ru0jhcjrp5rjqyqrnvhr3sz3v2e0fm3ktknvlg7mcyan54qzccnan" - assert inner_transactions[1]["nonce"] == 1234 - assert inner_transactions[1]["relayer"] == "erd1k2s324ww2g0yj38qn2ch2jwctdy8mnfxep94q9arncc6xecg3xaq6mjse8" - - def _read_stdout(capsys: Any) -> str: return capsys.readouterr().out.strip() diff --git a/multiversx_sdk_cli/transactions.py b/multiversx_sdk_cli/transactions.py index 1e441a17..41937a50 100644 --- a/multiversx_sdk_cli/transactions.py +++ b/multiversx_sdk_cli/transactions.py @@ -2,7 +2,6 @@ import json import logging import time -from pathlib import Path from typing import Any, Dict, List, Optional, Protocol, TextIO from multiversx_sdk import (Address, Token, TokenComputer, TokenTransfer, @@ -79,12 +78,6 @@ def do_prepare_transaction(args: Any) -> Transaction: if args.guardian: tx.guardian = args.guardian - if args.relayer: - tx.relayer = Address.new_from_bech32(args.relayer).to_bech32() - - if args.inner_transactions: - tx.inner_transactions = load_inner_transactions_from_file(Path(args.inner_transactions).expanduser()) - tx.signature = bytes.fromhex(account.sign_transaction(tx)) tx = sign_tx_by_guardian(args, tx) @@ -227,11 +220,3 @@ def load_transaction_from_file(f: TextIO) -> Transaction: tx_converter = TransactionsConverter() return tx_converter.dictionary_to_transaction(transaction_dictionary) - - -def load_inner_transactions_from_file(path: Path) -> List[Transaction]: - data_json = path.read_text() - transactions: List[Dict[str, Any]] = json.loads(data_json).get("innerTransactions") - - tx_converter = TransactionsConverter() - return [tx_converter.dictionary_to_transaction(transaction) for transaction in transactions] diff --git a/pyproject.toml b/pyproject.toml index d6deeb97..4463bf73 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "hatchling.build" [project] name = "multiversx-sdk-cli" -version = "9.7.1" +version = "9.8.0" authors = [ { name="MultiversX" }, ] From a39a12111e7deb2e42e05e7156fd15a0af0a36ac Mon Sep 17 00:00:00 2001 From: Alexandru Popenta Date: Fri, 1 Nov 2024 14:03:53 +0200 Subject: [PATCH 42/90] use newest sdk and add client name --- multiversx_sdk_cli/cli_accounts.py | 4 ++- multiversx_sdk_cli/cli_contracts.py | 16 ++++----- multiversx_sdk_cli/cli_delegation.py | 4 ++- multiversx_sdk_cli/cli_dns.py | 15 +++++--- multiversx_sdk_cli/cli_shared.py | 19 +++++++--- multiversx_sdk_cli/cli_transactions.py | 20 +++++------ multiversx_sdk_cli/config.py | 6 ++++ multiversx_sdk_cli/custom_network_provider.py | 36 ------------------- multiversx_sdk_cli/interfaces.py | 7 +--- .../tests/test_cli_transactions.py | 17 +++++++++ multiversx_sdk_cli/tests/test_proxy.py | 4 ++- pyproject.toml | 4 +-- requirements.txt | 2 +- 13 files changed, 77 insertions(+), 77 deletions(-) delete mode 100644 multiversx_sdk_cli/custom_network_provider.py diff --git a/multiversx_sdk_cli/cli_accounts.py b/multiversx_sdk_cli/cli_accounts.py index 9ae5933a..f7a5afe5 100644 --- a/multiversx_sdk_cli/cli_accounts.py +++ b/multiversx_sdk_cli/cli_accounts.py @@ -4,6 +4,7 @@ from multiversx_sdk import Address, ProxyNetworkProvider from multiversx_sdk_cli import cli_shared, utils +from multiversx_sdk_cli.config import get_config_for_network_providers logger = logging.getLogger("cli.accounts") @@ -33,7 +34,8 @@ def _add_address_arg(sub: Any): def get_account(args: Any): proxy_url = args.proxy address = args.address - proxy = ProxyNetworkProvider(proxy_url) + config = get_config_for_network_providers() + proxy = ProxyNetworkProvider(url=proxy_url, config=config) account = proxy.get_account(Address.new_from_bech32(address)) if args.balance: diff --git a/multiversx_sdk_cli/cli_contracts.py b/multiversx_sdk_cli/cli_contracts.py index 8f7c14a9..9516bcf4 100644 --- a/multiversx_sdk_cli/cli_contracts.py +++ b/multiversx_sdk_cli/cli_contracts.py @@ -10,6 +10,7 @@ from multiversx_sdk_cli import cli_shared, projects, utils from multiversx_sdk_cli.cli_output import CLIOutputBuilder +from multiversx_sdk_cli.config import get_config_for_network_providers from multiversx_sdk_cli.constants import NUMBER_OF_SHARDS from multiversx_sdk_cli.contract_verification import \ trigger_contract_verification @@ -100,7 +101,7 @@ def setup_parser(args: List[str], subparsers: Any) -> Any: cli_shared.add_tx_args(args, sub, with_receiver=False, with_data=False) _add_function_arg(sub) _add_arguments_arg(sub) - _add_token_transfers_args(sub) + cli_shared.add_token_transfers_args(sub) sub.add_argument("--wait-result", action="store_true", default=False, help="signal to wait for the transaction result - only valid if --send is set") sub.add_argument("--timeout", default=100, help="max num of seconds to wait for result" @@ -243,12 +244,6 @@ def _add_arguments_arg(sub: Any): "E.g. [{ 'to': 'erd1...', 'amount': 10000000000 }]") -def _add_token_transfers_args(sub: Any): - sub.add_argument("--token-transfers", nargs='+', - help="token transfers for transfer & execute, as [token, amount] " - "E.g. --token-transfers NFT-123456-0a 1 ESDT-987654 100000000") - - def _add_metadata_arg(sub: Any): sub.add_argument("--metadata-not-upgradeable", dest="metadata_upgradeable", action="store_false", help="‼ mark the contract as NOT upgradeable (default: upgradeable)") @@ -448,14 +443,15 @@ def query(args: Any): args.chain = "" cli_shared.prepare_chain_id_in_args(args) - config = TransactionsFactoryConfig(args.chain) + factory_config = TransactionsFactoryConfig(args.chain) abi = Abi.load(Path(args.abi)) if args.abi else None - contract = SmartContract(config, abi) + contract = SmartContract(factory_config, abi) arguments, should_prepare_args = _get_contract_arguments(args) contract_address = Address.new_from_bech32(args.contract) - proxy = ProxyNetworkProvider(args.proxy) + network_provider_config = get_config_for_network_providers() + proxy = ProxyNetworkProvider(url=args.proxy, config=network_provider_config) function = args.function result = contract.query_contract( diff --git a/multiversx_sdk_cli/cli_delegation.py b/multiversx_sdk_cli/cli_delegation.py index aafbaa4b..cc6dcaa2 100644 --- a/multiversx_sdk_cli/cli_delegation.py +++ b/multiversx_sdk_cli/cli_delegation.py @@ -3,6 +3,7 @@ from multiversx_sdk import ProxyNetworkProvider, TransactionsFactoryConfig from multiversx_sdk_cli import cli_shared, errors, utils +from multiversx_sdk_cli.config import get_config_for_network_providers from multiversx_sdk_cli.delegation import DelegationOperations @@ -209,7 +210,8 @@ def do_create_delegation_contract(args: Any): def get_contract_address_by_deploy_tx_hash(args: Any): args = utils.as_object(args) - proxy = ProxyNetworkProvider(args.proxy) + config = get_config_for_network_providers() + proxy = ProxyNetworkProvider(url=args.proxy, config=config) transaction = proxy.get_transaction(args.create_tx_hash) transaction_events = transaction.logs.events diff --git a/multiversx_sdk_cli/cli_dns.py b/multiversx_sdk_cli/cli_dns.py index 80e93747..703f29a1 100644 --- a/multiversx_sdk_cli/cli_dns.py +++ b/multiversx_sdk_cli/cli_dns.py @@ -4,6 +4,7 @@ from prettytable import PrettyTable from multiversx_sdk_cli import cli_shared +from multiversx_sdk_cli.config import get_config_for_network_providers from multiversx_sdk_cli.constants import ADDRESS_ZERO_BECH32 from multiversx_sdk_cli.dns import (compute_dns_address_for_shard_id, dns_address_for_name, name_hash, register, @@ -79,14 +80,17 @@ def _ensure_proxy_is_provided(args: Any): def dns_resolve(args: Any): _ensure_proxy_is_provided(args) - addr = resolve(args.name, ProxyNetworkProvider(args.proxy)) + config = get_config_for_network_providers() + addr = resolve(args.name, ProxyNetworkProvider(url=args.proxy, config=config)) if addr.to_hex() != Address.new_from_bech32(ADDRESS_ZERO_BECH32).to_hex(): print(addr.to_bech32()) def dns_validate_name(args: Any): _ensure_proxy_is_provided(args) - validate_name(args.name, args.shard_id, ProxyNetworkProvider(args.proxy)) + + config = get_config_for_network_providers() + validate_name(args.name, args.shard_id, ProxyNetworkProvider(url=args.proxy, config=config)) def get_name_hash(args: Any): @@ -107,13 +111,16 @@ def get_dns_address_for_name_hex(args: Any): def get_registration_cost(args: Any): _ensure_proxy_is_provided(args) - print(registration_cost(args.shard_id, ProxyNetworkProvider(args.proxy))) + + config = get_config_for_network_providers() + print(registration_cost(args.shard_id, ProxyNetworkProvider(url=args.proxy, config=config))) def get_version(args: Any): _ensure_proxy_is_provided(args) - proxy = ProxyNetworkProvider(args.proxy) + config = get_config_for_network_providers() + proxy = ProxyNetworkProvider(url=args.proxy, config=config) if args.all: t = PrettyTable(['Shard ID', 'Contract address (bech32)', 'Contract address (hex)', 'Version']) for shard_id in range(0, 256): diff --git a/multiversx_sdk_cli/cli_shared.py b/multiversx_sdk_cli/cli_shared.py index 1236914d..d239de14 100644 --- a/multiversx_sdk_cli/cli_shared.py +++ b/multiversx_sdk_cli/cli_shared.py @@ -14,7 +14,6 @@ load_password) from multiversx_sdk_cli.constants import (DEFAULT_TX_VERSION, TRANSACTION_OPTIONS_TX_GUARDED) -from multiversx_sdk_cli.custom_network_provider import CustomNetworkProvider from multiversx_sdk_cli.errors import ArgumentsNotProvidedError from multiversx_sdk_cli.interfaces import ITransaction from multiversx_sdk_cli.ledger.ledger_functions import do_get_ledger_address @@ -141,6 +140,12 @@ def add_omit_fields_arg(sub: Any): sub.add_argument("--omit-fields", default="[]", type=str, required=False, help="omit fields in the output payload (default: %(default)s)") +def add_token_transfers_args(sub: Any): + sub.add_argument("--token-transfers", nargs='+', + help="token transfers for transfer & execute, as [token, amount] " + "E.g. --token-transfers NFT-123456-0a 1 ESDT-987654 100000000") + + def parse_omit_fields_arg(args: Any) -> List[str]: literal = args.omit_fields parsed = ast.literal_eval(literal) @@ -182,7 +187,8 @@ def prepare_nonce_in_args(args: Any): if args.recall_nonce: account = prepare_account(args) - account.sync_nonce(ProxyNetworkProvider(args.proxy)) + network_provider_config = config.get_config_for_network_providers() + account.sync_nonce(ProxyNetworkProvider(url=args.proxy, config=network_provider_config)) args.nonce = account.nonce @@ -191,7 +197,8 @@ def prepare_chain_id_in_args(args: Any): raise ArgumentsNotProvidedError("chain ID cannot be decided: `--chain` or `--proxy` should be provided") if args.chain and args.proxy: - proxy = ProxyNetworkProvider(args.proxy) + network_provider_config = config.get_config_for_network_providers() + proxy = ProxyNetworkProvider(url=args.proxy, config=network_provider_config) fetched_chain_id = proxy.get_network_config().chain_id if args.chain != fetched_chain_id: @@ -204,7 +211,8 @@ def prepare_chain_id_in_args(args: Any): if args.chain: return elif args.proxy: - proxy = ProxyNetworkProvider(args.proxy) + network_provider_config = config.get_config_for_network_providers() + proxy = ProxyNetworkProvider(url=args.proxy, config=network_provider_config) args.chain = proxy.get_network_config().chain_id @@ -253,7 +261,8 @@ def check_options_for_guarded_tx(options: int): def send_or_simulate(tx: ITransaction, args: Any, dump_output: bool = True) -> CLIOutputBuilder: - proxy = CustomNetworkProvider(args.proxy) + network_provider_config = config.get_config_for_network_providers() + proxy = ProxyNetworkProvider(url=args.proxy, config=network_provider_config) is_set_wait_result = hasattr(args, "wait_result") and args.wait_result is_set_send = hasattr(args, "send") and args.send diff --git a/multiversx_sdk_cli/cli_transactions.py b/multiversx_sdk_cli/cli_transactions.py index a701961b..d8a8ae1d 100644 --- a/multiversx_sdk_cli/cli_transactions.py +++ b/multiversx_sdk_cli/cli_transactions.py @@ -2,10 +2,12 @@ from pathlib import Path from typing import Any, List +from multiversx_sdk import ProxyNetworkProvider + from multiversx_sdk_cli import cli_shared, utils from multiversx_sdk_cli.cli_output import CLIOutputBuilder +from multiversx_sdk_cli.config import get_config_for_network_providers from multiversx_sdk_cli.cosign_transaction import cosign_transaction -from multiversx_sdk_cli.custom_network_provider import CustomNetworkProvider from multiversx_sdk_cli.errors import NoWalletProvided from multiversx_sdk_cli.transactions import (compute_relayed_v1_data, do_prepare_transaction, @@ -20,7 +22,7 @@ def setup_parser(args: List[str], subparsers: Any) -> Any: sub = cli_shared.add_command_subparser(subparsers, "tx", "new", f"Create a new transaction.{CLIOutputBuilder.describe()}") _add_common_arguments(args, sub) - _add_token_transfers_args(sub) + cli_shared.add_token_transfers_args(sub) cli_shared.add_outfile_arg(sub, what="signed transaction, hash") cli_shared.add_broadcast_args(sub, relay=True) cli_shared.add_proxy_arg(sub) @@ -65,12 +67,6 @@ def _add_common_arguments(args: List[str], sub: Any): sub.add_argument("--data-file", type=str, default=None, help="a file containing transaction data") -def _add_token_transfers_args(sub: Any): - sub.add_argument("--token-transfers", nargs='+', - help="token transfers for transfer & execute, as [token, amount] " - "E.g. --token-transfers NFT-123456-0a 1 ESDT-987654 100000000") - - def create_transaction(args: Any): args = utils.as_object(args) @@ -97,7 +93,9 @@ def send_transaction(args: Any): tx = load_transaction_from_file(args.infile) output = CLIOutputBuilder() - proxy = CustomNetworkProvider(args.proxy) + + config = get_config_for_network_providers() + proxy = ProxyNetworkProvider(url=args.proxy, config=config) try: tx_hash = proxy.send_transaction(tx) @@ -110,7 +108,9 @@ def send_transaction(args: Any): def get_transaction(args: Any): args = utils.as_object(args) omit_fields = cli_shared.parse_omit_fields_arg(args) - proxy = CustomNetworkProvider(args.proxy) + + config = get_config_for_network_providers() + proxy = ProxyNetworkProvider(url=args.proxy, config=config) transaction = proxy.get_transaction(args.hash, True) output = CLIOutputBuilder().set_transaction_on_network(transaction, omit_fields).build() diff --git a/multiversx_sdk_cli/config.py b/multiversx_sdk_cli/config.py index 3b54049f..db067f65 100644 --- a/multiversx_sdk_cli/config.py +++ b/multiversx_sdk_cli/config.py @@ -2,6 +2,8 @@ from pathlib import Path from typing import Any, Dict, List +from multiversx_sdk import NetworkProviderConfig + from multiversx_sdk_cli import errors, utils SDK_PATH = Path("~/multiversx-sdk").expanduser().resolve() @@ -242,3 +244,7 @@ def get_dependency_directory(key: str, tag: str) -> Path: def get_dependency_parent_directory(key: str) -> Path: return SDK_PATH / key + + +def get_config_for_network_providers() -> NetworkProviderConfig: + return NetworkProviderConfig(client_name="mxpy") diff --git a/multiversx_sdk_cli/custom_network_provider.py b/multiversx_sdk_cli/custom_network_provider.py deleted file mode 100644 index e11c9870..00000000 --- a/multiversx_sdk_cli/custom_network_provider.py +++ /dev/null @@ -1,36 +0,0 @@ -from typing import Any, Dict, Optional, Protocol - -from multiversx_sdk import GenericError, ProxyNetworkProvider - -from multiversx_sdk_cli.errors import ProxyError -from multiversx_sdk_cli.interfaces import ISimulateResponse, ITransaction - - -class ITransactionOnNetwork(Protocol): - hash: str - is_completed: Optional[bool] - - def to_dictionary(self) -> Dict[str, Any]: - ... - - -class CustomNetworkProvider: - def __init__(self, url: str) -> None: - self._provider = ProxyNetworkProvider(url) - - def send_transaction(self, transaction: ITransaction) -> str: - try: - hash = self._provider.send_transaction(transaction) - return hash - except GenericError as ge: - url = ge.url - message = ge.data.get("error", "") - data = ge.data.get("data", "") - code = ge.data.get("code", "") - raise ProxyError(message, url, data, code) - - def get_transaction(self, tx_hash: str, with_process_status: Optional[bool] = False) -> ITransactionOnNetwork: - return self._provider.get_transaction(tx_hash, with_process_status) - - def simulate_transaction(self, transaction: ITransaction) -> ISimulateResponse: - return self._provider.simulate_transaction(transaction) diff --git a/multiversx_sdk_cli/interfaces.py b/multiversx_sdk_cli/interfaces.py index e0db9a2f..e59c3c8f 100644 --- a/multiversx_sdk_cli/interfaces.py +++ b/multiversx_sdk_cli/interfaces.py @@ -1,4 +1,4 @@ -from typing import Any, Dict, Protocol, Sequence +from typing import Any, Dict, Protocol class IAddress(Protocol): @@ -25,11 +25,6 @@ class ITransaction(Protocol): guardian: str signature: bytes guardian_signature: bytes - relayer: str - - @property - def inner_transactions(self) -> Sequence["ITransaction"]: - ... class IAccount(Protocol): diff --git a/multiversx_sdk_cli/tests/test_cli_transactions.py b/multiversx_sdk_cli/tests/test_cli_transactions.py index 1ac07470..dea29655 100644 --- a/multiversx_sdk_cli/tests/test_cli_transactions.py +++ b/multiversx_sdk_cli/tests/test_cli_transactions.py @@ -88,5 +88,22 @@ def test_create_multi_transfer_transaction(capsys: Any): assert signature == "575b029d52ff5ffbfb7bab2f04052de88a6f7d022a6ad368459b8af9acaed3717d3f95db09f460649a8f405800838bc2c432496bd03c9039ea166bd32b84660e" +def test_create_multi_transfer_transaction_with_single_egld_transfer(capsys: Any): + return_code = main([ + "tx", "new", + "--pem", str(testdata_path / "alice.pem"), + "--receiver", "erd1spyavw0956vq68xj8y4tenjpq2wd5a9p2c6j8gsz7ztyrnpxrruqzu66jx", + "--nonce", "7", + "--gas-limit", "1300000", + "--token-transfers", "EGLD-000000", "1000000000000000000", + "--chain", "T", + ]) + assert return_code == 0 + tx = _read_stdout(capsys) + tx_json = json.loads(tx) + data = tx_json["emittedTransactionData"] + assert data == "MultiESDTNFTTransfer@8049d639e5a6980d1cd2392abcce41029cda74a1563523a202f09641cc2618f8@01@45474c442d303030303030@@0de0b6b3a7640000" + + def _read_stdout(capsys: Any) -> str: return capsys.readouterr().out.strip() diff --git a/multiversx_sdk_cli/tests/test_proxy.py b/multiversx_sdk_cli/tests/test_proxy.py index 8cff09a5..8234f7fb 100644 --- a/multiversx_sdk_cli/tests/test_proxy.py +++ b/multiversx_sdk_cli/tests/test_proxy.py @@ -2,6 +2,7 @@ from multiversx_sdk_cli.accounts import Account from multiversx_sdk_cli.cli import main +from multiversx_sdk_cli.config import get_config_for_network_providers def test_get_account(): @@ -20,7 +21,8 @@ def test_get_account(): def test_sync_nonce(): account = Account(address=Address.new_from_bech32("erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th")) - proxy = ProxyNetworkProvider("https://testnet-api.multiversx.com") + config = get_config_for_network_providers() + proxy = ProxyNetworkProvider("https://testnet-api.multiversx.com", config=config) account.sync_nonce(proxy) assert True if account.nonce else False diff --git a/pyproject.toml b/pyproject.toml index 4463bf73..566c5d78 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "hatchling.build" [project] name = "multiversx-sdk-cli" -version = "9.8.0" +version = "9.8.1" authors = [ { name="MultiversX" }, ] @@ -28,7 +28,7 @@ dependencies = [ "requests-cache", "rich==13.3.4", "argcomplete==3.2.2", - "multiversx-sdk==0.13.0" + "multiversx-sdk==0.16.2" ] [project.scripts] diff --git a/requirements.txt b/requirements.txt index 2048553c..a44a9c25 100644 --- a/requirements.txt +++ b/requirements.txt @@ -10,4 +10,4 @@ requests-cache rich==13.3.4 argcomplete==3.2.2 -multiversx-sdk==0.13.0 +multiversx-sdk==0.16.2 From 8cdb2d7452b56939377df349c54aad4e4f0a7c42 Mon Sep 17 00:00:00 2001 From: Alexandru Popenta Date: Fri, 1 Nov 2024 16:00:00 +0200 Subject: [PATCH 43/90] update to latest sdk-py --- pyproject.toml | 2 +- requirements.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 566c5d78..aa46997b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -28,7 +28,7 @@ dependencies = [ "requests-cache", "rich==13.3.4", "argcomplete==3.2.2", - "multiversx-sdk==0.16.2" + "multiversx-sdk==0.16.3" ] [project.scripts] diff --git a/requirements.txt b/requirements.txt index a44a9c25..46320488 100644 --- a/requirements.txt +++ b/requirements.txt @@ -10,4 +10,4 @@ requests-cache rich==13.3.4 argcomplete==3.2.2 -multiversx-sdk==0.16.2 +multiversx-sdk==0.16.3 From 5f0f807a59811d142cb4b64a2d9183860b047a47 Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Mon, 4 Nov 2024 15:43:07 +0200 Subject: [PATCH 44/90] remove docker --- .github/workflows/test-localnet-tests.yml | 19 +++++---------- Dockerfile | 28 ----------------------- 2 files changed, 6 insertions(+), 41 deletions(-) delete mode 100644 Dockerfile diff --git a/.github/workflows/test-localnet-tests.yml b/.github/workflows/test-localnet-tests.yml index 5cf98d84..baea51e9 100644 --- a/.github/workflows/test-localnet-tests.yml +++ b/.github/workflows/test-localnet-tests.yml @@ -34,21 +34,14 @@ jobs: pip3 install -r requirements.txt pip3 install -r ./requirements-dev.txt --upgrade - - name: Set up Docker image + - name: Set up MultiversX localnet run: | - docker build --build-arg PYTHON_VERSION=${{ matrix.python-version }} -t mxpy . + # Start the local testnet with mxpy + mkdir -p ~/localnet && cd ~/localnet + mxpy localnet setup --configfile=${GITHUB_WORKSPACE}/localnet.toml + nohup mxpy localnet start --configfile=${GITHUB_WORKSPACE}/localnet.toml > localnet.log 2>&1 & echo $! > localnet.pid + sleep 120 # Allow time for the testnet to fully start - - name: Deploy a localnet - run: | - docker run --name localnet -d -p 7950:7950 mxpy localnet start \ - --configfile=/usr/src/app/multiversx_sdk_cli/tests/testdata/localnet_with_resolution_remote.toml - -# TODO: introduce polling in test fixture -# remove sleep - name: Test localnet dependent tests run: | - docker cp localnet:/usr/src/app/localnet/validator00/config/validatorKey.pem ./validatorKey00.pem - docker cp localnet:/usr/src/app/localnet/validator01/config/validatorKey.pem ./validatorKey01.pem - docker cp localnet:/usr/src/app/localnet/validator02/config/validatorKey.pem ./validatorKey02.pem - sleep 2m pytest -m require_localnet multiversx_sdk_cli/tests diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 9d6f84a4..00000000 --- a/Dockerfile +++ /dev/null @@ -1,28 +0,0 @@ -ARG PYTHON_VERSION=3.10 - -# Step 1: Use an official Python runtime as a parent image -FROM python:${PYTHON_VERSION}-slim - -# Step 2: Set the working directory in the container -WORKDIR /usr/src/app - -# Step 3: Copy the requirements file into the container -COPY requirements.txt ./ - -# Step 5: Copy the requirements-dev file into the container -COPY requirements-dev.txt ./ - -# Step 6: Install any dependencies listed in requirements.txt -RUN pip install --no-cache-dir -r requirements.txt - -# Step 7: Install build-essential. Will be needed to compile the node binaries. -RUN apt update && apt install -y build-essential - -# Step 8: Copy the current directory contents into the container -COPY . . - -# Step 9: Setup the localnet configuration in the eventuality of a localnet start. -RUN python -m multiversx_sdk_cli.cli localnet setup --configfile=/usr/src/app/multiversx_sdk_cli/tests/testdata/localnet_with_resolution_remote.toml - -# Step 10: Specify the entrypoint to run the application -ENTRYPOINT ["python", "-m", "multiversx_sdk_cli.cli"] \ No newline at end of file From 7a1c8cbc740505d737d2d5aa18fd1681b34ee4a1 Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Mon, 4 Nov 2024 15:47:42 +0200 Subject: [PATCH 45/90] fix mxpy commands in CI. --- .github/workflows/test-localnet-tests.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test-localnet-tests.yml b/.github/workflows/test-localnet-tests.yml index baea51e9..0f4a3b0a 100644 --- a/.github/workflows/test-localnet-tests.yml +++ b/.github/workflows/test-localnet-tests.yml @@ -38,8 +38,8 @@ jobs: run: | # Start the local testnet with mxpy mkdir -p ~/localnet && cd ~/localnet - mxpy localnet setup --configfile=${GITHUB_WORKSPACE}/localnet.toml - nohup mxpy localnet start --configfile=${GITHUB_WORKSPACE}/localnet.toml > localnet.log 2>&1 & echo $! > localnet.pid + python3 -m multiversx_sdk_cli.cli localnet setup --configfile=${GITHUB_WORKSPACE}/localnet.toml + nohup python3 -m multiversx_sdk_cli.cli localnet start --configfile=${GITHUB_WORKSPACE}/localnet.toml > localnet.log 2>&1 & echo $! > localnet.pid sleep 120 # Allow time for the testnet to fully start - name: Test localnet dependent tests From 6d2888e951773d210fae449ce99001b5961d875b Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Mon, 4 Nov 2024 15:50:03 +0200 Subject: [PATCH 46/90] cosmetic changes. --- .github/workflows/test-localnet-tests.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/test-localnet-tests.yml b/.github/workflows/test-localnet-tests.yml index 0f4a3b0a..366a31b1 100644 --- a/.github/workflows/test-localnet-tests.yml +++ b/.github/workflows/test-localnet-tests.yml @@ -37,7 +37,6 @@ jobs: - name: Set up MultiversX localnet run: | # Start the local testnet with mxpy - mkdir -p ~/localnet && cd ~/localnet python3 -m multiversx_sdk_cli.cli localnet setup --configfile=${GITHUB_WORKSPACE}/localnet.toml nohup python3 -m multiversx_sdk_cli.cli localnet start --configfile=${GITHUB_WORKSPACE}/localnet.toml > localnet.log 2>&1 & echo $! > localnet.pid sleep 120 # Allow time for the testnet to fully start From 685ca9eeab29f797287c8b8fb30393a35986a3eb Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Mon, 4 Nov 2024 15:57:05 +0200 Subject: [PATCH 47/90] debug strings --- .github/workflows/test-localnet-tests.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/test-localnet-tests.yml b/.github/workflows/test-localnet-tests.yml index 366a31b1..31d52ff6 100644 --- a/.github/workflows/test-localnet-tests.yml +++ b/.github/workflows/test-localnet-tests.yml @@ -38,6 +38,10 @@ jobs: run: | # Start the local testnet with mxpy python3 -m multiversx_sdk_cli.cli localnet setup --configfile=${GITHUB_WORKSPACE}/localnet.toml + echo "LIST FILES" + ls + echo "PWD" + pwd nohup python3 -m multiversx_sdk_cli.cli localnet start --configfile=${GITHUB_WORKSPACE}/localnet.toml > localnet.log 2>&1 & echo $! > localnet.pid sleep 120 # Allow time for the testnet to fully start From 7bdab1ae338deeb74461b4589e4255adab147af9 Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Mon, 4 Nov 2024 16:00:35 +0200 Subject: [PATCH 48/90] more debug commands. --- .github/workflows/test-localnet-tests.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/test-localnet-tests.yml b/.github/workflows/test-localnet-tests.yml index 31d52ff6..1a3ee83c 100644 --- a/.github/workflows/test-localnet-tests.yml +++ b/.github/workflows/test-localnet-tests.yml @@ -42,6 +42,9 @@ jobs: ls echo "PWD" pwd + echo "HOME DIR" + cd ~ + pwd nohup python3 -m multiversx_sdk_cli.cli localnet start --configfile=${GITHUB_WORKSPACE}/localnet.toml > localnet.log 2>&1 & echo $! > localnet.pid sleep 120 # Allow time for the testnet to fully start From 343ba6b5000aa4f875d9057a3128a6318ce72346 Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Mon, 4 Nov 2024 16:07:14 +0200 Subject: [PATCH 49/90] fix CI tests and remove docker naming. --- multiversx_sdk_cli/tests/test_cli_validators.py | 2 +- .../tests/testdata/validators_ci.json | 13 +++++++++++++ .../tests/testdata/validators_docker.json | 13 ------------- 3 files changed, 14 insertions(+), 14 deletions(-) create mode 100644 multiversx_sdk_cli/tests/testdata/validators_ci.json delete mode 100644 multiversx_sdk_cli/tests/testdata/validators_docker.json diff --git a/multiversx_sdk_cli/tests/test_cli_validators.py b/multiversx_sdk_cli/tests/test_cli_validators.py index eeccb028..233b1d0d 100644 --- a/multiversx_sdk_cli/tests/test_cli_validators.py +++ b/multiversx_sdk_cli/tests/test_cli_validators.py @@ -46,7 +46,7 @@ def poll_endpoint(): @pytest.mark.require_localnet def test_stake(poll_endpoint): - validators_json = testdata_path / "validators_docker.json" + validators_json = testdata_path / "validators_ci.json" # Stake with recall nonce return_code = main([ diff --git a/multiversx_sdk_cli/tests/testdata/validators_ci.json b/multiversx_sdk_cli/tests/testdata/validators_ci.json new file mode 100644 index 00000000..3067c23a --- /dev/null +++ b/multiversx_sdk_cli/tests/testdata/validators_ci.json @@ -0,0 +1,13 @@ +{ + "validators": [ + { + "pemFile": "~/work/mx-sdk-py-cli/mx-sdk-py-cli/localnet/validator00/validatorKey00.pem" + }, + { + "pemFile": "~/work/mx-sdk-py-cli/mx-sdk-py-cli/localnet/validator01/validatorKey01.pem" + }, + { + "pemFile": "~/work/mx-sdk-py-cli/mx-sdk-py-cli/localnet/validator02/validatorKey02.pem" + } + ] +} diff --git a/multiversx_sdk_cli/tests/testdata/validators_docker.json b/multiversx_sdk_cli/tests/testdata/validators_docker.json deleted file mode 100644 index 51fe7684..00000000 --- a/multiversx_sdk_cli/tests/testdata/validators_docker.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "validators": [ - { - "pemFile": "~/work/mx-sdk-py-cli/mx-sdk-py-cli/validatorKey00.pem" - }, - { - "pemFile": "~/work/mx-sdk-py-cli/mx-sdk-py-cli/validatorKey01.pem" - }, - { - "pemFile": "~/work/mx-sdk-py-cli/mx-sdk-py-cli/validatorKey02.pem" - } - ] -} From bf164f63f59d68ed4d29cc9dde0619a15f2423a9 Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Mon, 4 Nov 2024 16:20:42 +0200 Subject: [PATCH 50/90] remove polling. --- .../tests/test_cli_validators.py | 58 +++++++++---------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/multiversx_sdk_cli/tests/test_cli_validators.py b/multiversx_sdk_cli/tests/test_cli_validators.py index 233b1d0d..db026fd2 100644 --- a/multiversx_sdk_cli/tests/test_cli_validators.py +++ b/multiversx_sdk_cli/tests/test_cli_validators.py @@ -44,35 +44,35 @@ def poll_endpoint(): time.sleep(interval) -@pytest.mark.require_localnet -def test_stake(poll_endpoint): - validators_json = testdata_path / "validators_ci.json" - - # Stake with recall nonce - return_code = main([ - "validator", "stake", - "--pem", str(alice_pem), - "--value", "2500000000000000000000", - "--validators-file", str(validators_json), - "--reward-address", reward_address, - "--chain", "localnet", - "--proxy", "http://127.0.0.1:7950", - "--estimate-gas", "--recall-nonce" - ]) - assert return_code == 0 - - # Stake with provided nonce - return_code = main([ - "validator", "stake", - "--pem", str(alice_pem), - "--value", "2500000000000000000000", - "--validators-file", str(validators_json), - "--reward-address", reward_address, - "--chain", "localnet", - "--proxy", "http://127.0.0.1:7950", - "--estimate-gas", "--nonce=0" - ]) - assert return_code == 0 +# @pytest.mark.require_localnet +# def test_stake(poll_endpoint): +# validators_json = testdata_path / "validators_ci.json" +# +# # Stake with recall nonce +# return_code = main([ +# "validator", "stake", +# "--pem", str(alice_pem), +# "--value", "2500000000000000000000", +# "--validators-file", str(validators_json), +# "--reward-address", reward_address, +# "--chain", "localnet", +# "--proxy", "http://127.0.0.1:7950", +# "--estimate-gas", "--recall-nonce" +# ]) +# assert return_code == 0 +# +# # Stake with provided nonce +# return_code = main([ +# "validator", "stake", +# "--pem", str(alice_pem), +# "--value", "2500000000000000000000", +# "--validators-file", str(validators_json), +# "--reward-address", reward_address, +# "--chain", "localnet", +# "--proxy", "http://127.0.0.1:7950", +# "--estimate-gas", "--nonce=0" +# ]) +# assert return_code == 0 @pytest.mark.require_localnet From e8137fa4a7cb92620935e4a7e2b8365fd542db4e Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Mon, 4 Nov 2024 16:21:08 +0200 Subject: [PATCH 51/90] cosmetic changes. --- .../tests/test_cli_validators.py | 112 +++++++++--------- 1 file changed, 56 insertions(+), 56 deletions(-) diff --git a/multiversx_sdk_cli/tests/test_cli_validators.py b/multiversx_sdk_cli/tests/test_cli_validators.py index db026fd2..fed75da6 100644 --- a/multiversx_sdk_cli/tests/test_cli_validators.py +++ b/multiversx_sdk_cli/tests/test_cli_validators.py @@ -15,64 +15,64 @@ bls_key = "e7beaa95b3877f47348df4dd1cb578a4f7cabf7a20bfeefe5cdd263878ff132b765e04fef6f40c93512b666c47ed7719b8902f6c922c04247989b7137e837cc81a62e54712471c97a2ddab75aa9c2f58f813ed4c0fa722bde0ab718bff382208" -@pytest.fixture() -def poll_endpoint(): - start_time = time.time() # Record the start time - timeout = 600 - interval = 1 - - while True: - try: - # Make the request to the endpoint - response = requests.get(proxy_url, timeout=5) # Add request timeout to prevent blocking indefinitely - if response.status_code == 200: - # Break out of the loop if we get a successful response - return response.json() # Return the response (or .text, .content based on your needs) - else: - print(f"Received non-200 status code: {response.status_code}") - - except requests.RequestException as e: - # Handle network exceptions or timeouts - print(f"Request failed: {e}") - - # Check if the timeout is reached - if time.time() - start_time > timeout: - print("Polling timed out") - break - - # Wait for the specified interval before sending the next request - time.sleep(interval) - - -# @pytest.mark.require_localnet -# def test_stake(poll_endpoint): -# validators_json = testdata_path / "validators_ci.json" +# @pytest.fixture() +# def poll_endpoint(): +# start_time = time.time() # Record the start time +# timeout = 600 +# interval = 1 # -# # Stake with recall nonce -# return_code = main([ -# "validator", "stake", -# "--pem", str(alice_pem), -# "--value", "2500000000000000000000", -# "--validators-file", str(validators_json), -# "--reward-address", reward_address, -# "--chain", "localnet", -# "--proxy", "http://127.0.0.1:7950", -# "--estimate-gas", "--recall-nonce" -# ]) -# assert return_code == 0 +# while True: +# try: +# # Make the request to the endpoint +# response = requests.get(proxy_url, timeout=5) # Add request timeout to prevent blocking indefinitely +# if response.status_code == 200: +# # Break out of the loop if we get a successful response +# return response.json() # Return the response (or .text, .content based on your needs) +# else: +# print(f"Received non-200 status code: {response.status_code}") # -# # Stake with provided nonce -# return_code = main([ -# "validator", "stake", -# "--pem", str(alice_pem), -# "--value", "2500000000000000000000", -# "--validators-file", str(validators_json), -# "--reward-address", reward_address, -# "--chain", "localnet", -# "--proxy", "http://127.0.0.1:7950", -# "--estimate-gas", "--nonce=0" -# ]) -# assert return_code == 0 +# except requests.RequestException as e: +# # Handle network exceptions or timeouts +# print(f"Request failed: {e}") +# +# # Check if the timeout is reached +# if time.time() - start_time > timeout: +# print("Polling timed out") +# break +# +# # Wait for the specified interval before sending the next request +# time.sleep(interval) + + +@pytest.mark.require_localnet +def test_stake(poll_endpoint): + validators_json = testdata_path / "validators_ci.json" + + # Stake with recall nonce + return_code = main([ + "validator", "stake", + "--pem", str(alice_pem), + "--value", "2500000000000000000000", + "--validators-file", str(validators_json), + "--reward-address", reward_address, + "--chain", "localnet", + "--proxy", "http://127.0.0.1:7950", + "--estimate-gas", "--recall-nonce" + ]) + assert return_code == 0 + + # Stake with provided nonce + return_code = main([ + "validator", "stake", + "--pem", str(alice_pem), + "--value", "2500000000000000000000", + "--validators-file", str(validators_json), + "--reward-address", reward_address, + "--chain", "localnet", + "--proxy", "http://127.0.0.1:7950", + "--estimate-gas", "--nonce=0" + ]) + assert return_code == 0 @pytest.mark.require_localnet From 3fb2a0e73ddc6523f6ef64eb5afc800ffd81fc19 Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Mon, 4 Nov 2024 16:22:24 +0200 Subject: [PATCH 52/90] fix unused fixture. --- multiversx_sdk_cli/tests/test_cli_validators.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/multiversx_sdk_cli/tests/test_cli_validators.py b/multiversx_sdk_cli/tests/test_cli_validators.py index fed75da6..e75e59bd 100644 --- a/multiversx_sdk_cli/tests/test_cli_validators.py +++ b/multiversx_sdk_cli/tests/test_cli_validators.py @@ -45,7 +45,7 @@ @pytest.mark.require_localnet -def test_stake(poll_endpoint): +def test_stake(): validators_json = testdata_path / "validators_ci.json" # Stake with recall nonce From af2c955028a6f377de1eda101ad08d92f23517c4 Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Mon, 4 Nov 2024 16:32:52 +0200 Subject: [PATCH 53/90] remove polling fixture. --- .../tests/test_cli_validators.py | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/multiversx_sdk_cli/tests/test_cli_validators.py b/multiversx_sdk_cli/tests/test_cli_validators.py index e75e59bd..0891ef56 100644 --- a/multiversx_sdk_cli/tests/test_cli_validators.py +++ b/multiversx_sdk_cli/tests/test_cli_validators.py @@ -76,7 +76,7 @@ def test_stake(): @pytest.mark.require_localnet -def test_stake_top_up(poll_endpoint): +def test_stake_top_up(): # Stake with topUp return_code = main([ "validator", "stake", "--top-up", @@ -90,7 +90,7 @@ def test_stake_top_up(poll_endpoint): @pytest.mark.require_localnet -def test_unstake(poll_endpoint): +def test_unstake(): # Unstake return_code = main([ "validator", "unstake", @@ -104,7 +104,7 @@ def test_unstake(poll_endpoint): @pytest.mark.require_localnet -def test_unbond(poll_endpoint): +def test_unbond(): # Unbond return_code = main([ "validator", "unbond", @@ -118,7 +118,7 @@ def test_unbond(poll_endpoint): @pytest.mark.require_localnet -def test_unjail(poll_endpoint): +def test_unjail(): # Unjail return_code = main([ "validator", "unjail", @@ -133,7 +133,7 @@ def test_unjail(poll_endpoint): @pytest.mark.require_localnet -def test_change_reward_address(poll_endpoint): +def test_change_reward_address(): # Change reward address return_code = main([ "validator", "change-reward-address", @@ -147,7 +147,7 @@ def test_change_reward_address(poll_endpoint): @pytest.mark.require_localnet -def test_unstake_nodes(poll_endpoint): +def test_unstake_nodes(): # Unstake Nodes return_code = main([ "validator", "unstake-nodes", @@ -161,7 +161,7 @@ def test_unstake_nodes(poll_endpoint): @pytest.mark.require_localnet -def test_unstake_tokens(poll_endpoint): +def test_unstake_tokens(): # Unstake Tokens return_code = main([ "validator", "unstake-tokens", @@ -175,7 +175,7 @@ def test_unstake_tokens(poll_endpoint): @pytest.mark.require_localnet -def test_unbond_nodes(poll_endpoint): +def test_unbond_nodes(): # Unbond nodes return_code = main([ "validator", "unbond-nodes", @@ -189,7 +189,7 @@ def test_unbond_nodes(poll_endpoint): @pytest.mark.require_localnet -def test_unbond_tokens(poll_endpoint): +def test_unbond_tokens(): # Unbond nodes return_code = main([ "validator", "unbond-tokens", @@ -203,7 +203,7 @@ def test_unbond_tokens(poll_endpoint): @pytest.mark.require_localnet -def test_clean_registration_data(poll_endpoint): +def test_clean_registration_data(): # Clean registration data return_code = main([ "validator", "clean-registered-data", @@ -216,7 +216,7 @@ def test_clean_registration_data(poll_endpoint): @pytest.mark.require_localnet -def test_re_stake_unstaked_nodes(poll_endpoint): +def test_re_stake_unstaked_nodes(): # Clean registration data return_code = main([ "validator", "restake-unstaked-nodes", From c7d799f2e6e5a8a7ff35cd381a3784a7428f6c46 Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Mon, 4 Nov 2024 16:46:39 +0200 Subject: [PATCH 54/90] more debugging. --- .github/workflows/test-localnet-tests.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test-localnet-tests.yml b/.github/workflows/test-localnet-tests.yml index 1a3ee83c..71c22526 100644 --- a/.github/workflows/test-localnet-tests.yml +++ b/.github/workflows/test-localnet-tests.yml @@ -46,6 +46,7 @@ jobs: cd ~ pwd nohup python3 -m multiversx_sdk_cli.cli localnet start --configfile=${GITHUB_WORKSPACE}/localnet.toml > localnet.log 2>&1 & echo $! > localnet.pid + cat ${GITHUB_WORKSPACE}/localnet.toml sleep 120 # Allow time for the testnet to fully start - name: Test localnet dependent tests From 5a274c47f62994601360ca52724c04a9937d7ac8 Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Mon, 4 Nov 2024 16:54:53 +0200 Subject: [PATCH 55/90] show log in CI. --- .github/workflows/test-localnet-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test-localnet-tests.yml b/.github/workflows/test-localnet-tests.yml index 71c22526..9bcd80b0 100644 --- a/.github/workflows/test-localnet-tests.yml +++ b/.github/workflows/test-localnet-tests.yml @@ -46,7 +46,7 @@ jobs: cd ~ pwd nohup python3 -m multiversx_sdk_cli.cli localnet start --configfile=${GITHUB_WORKSPACE}/localnet.toml > localnet.log 2>&1 & echo $! > localnet.pid - cat ${GITHUB_WORKSPACE}/localnet.toml + cat ${GITHUB_WORKSPACE}/localnet.log sleep 120 # Allow time for the testnet to fully start - name: Test localnet dependent tests From 42c12601feb678a93cb38a988f85497bb8d5a756 Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Mon, 4 Nov 2024 16:58:33 +0200 Subject: [PATCH 56/90] more debugging in CI. --- .github/workflows/test-localnet-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test-localnet-tests.yml b/.github/workflows/test-localnet-tests.yml index 9bcd80b0..718a9eba 100644 --- a/.github/workflows/test-localnet-tests.yml +++ b/.github/workflows/test-localnet-tests.yml @@ -46,7 +46,7 @@ jobs: cd ~ pwd nohup python3 -m multiversx_sdk_cli.cli localnet start --configfile=${GITHUB_WORKSPACE}/localnet.toml > localnet.log 2>&1 & echo $! > localnet.pid - cat ${GITHUB_WORKSPACE}/localnet.log + cat localnet.log sleep 120 # Allow time for the testnet to fully start - name: Test localnet dependent tests From 1ba5d85c3742d1cc97e29ff3adf94a96eb017c30 Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Mon, 4 Nov 2024 17:10:31 +0200 Subject: [PATCH 57/90] more debugging in CI. --- .github/workflows/test-localnet-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test-localnet-tests.yml b/.github/workflows/test-localnet-tests.yml index 718a9eba..3127a395 100644 --- a/.github/workflows/test-localnet-tests.yml +++ b/.github/workflows/test-localnet-tests.yml @@ -46,7 +46,7 @@ jobs: cd ~ pwd nohup python3 -m multiversx_sdk_cli.cli localnet start --configfile=${GITHUB_WORKSPACE}/localnet.toml > localnet.log 2>&1 & echo $! > localnet.pid - cat localnet.log + ls sleep 120 # Allow time for the testnet to fully start - name: Test localnet dependent tests From 25760e9945aebc6697fe99376b4e19ef814f26fd Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Mon, 4 Nov 2024 17:14:00 +0200 Subject: [PATCH 58/90] check logs in CI. --- .github/workflows/test-localnet-tests.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test-localnet-tests.yml b/.github/workflows/test-localnet-tests.yml index 3127a395..82d0b2f7 100644 --- a/.github/workflows/test-localnet-tests.yml +++ b/.github/workflows/test-localnet-tests.yml @@ -47,6 +47,7 @@ jobs: pwd nohup python3 -m multiversx_sdk_cli.cli localnet start --configfile=${GITHUB_WORKSPACE}/localnet.toml > localnet.log 2>&1 & echo $! > localnet.pid ls + cat localnet.log sleep 120 # Allow time for the testnet to fully start - name: Test localnet dependent tests From fe180f00a22466d0d45b6b8275f992bc483de71c Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Mon, 4 Nov 2024 17:18:17 +0200 Subject: [PATCH 59/90] rewrite setting up commands. --- .github/workflows/test-localnet-tests.yml | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/.github/workflows/test-localnet-tests.yml b/.github/workflows/test-localnet-tests.yml index 82d0b2f7..3d376f42 100644 --- a/.github/workflows/test-localnet-tests.yml +++ b/.github/workflows/test-localnet-tests.yml @@ -36,19 +36,10 @@ jobs: - name: Set up MultiversX localnet run: | - # Start the local testnet with mxpy - python3 -m multiversx_sdk_cli.cli localnet setup --configfile=${GITHUB_WORKSPACE}/localnet.toml - echo "LIST FILES" - ls - echo "PWD" - pwd - echo "HOME DIR" - cd ~ - pwd - nohup python3 -m multiversx_sdk_cli.cli localnet start --configfile=${GITHUB_WORKSPACE}/localnet.toml > localnet.log 2>&1 & echo $! > localnet.pid - ls - cat localnet.log - sleep 120 # Allow time for the testnet to fully start + python3 -m multiversx_sdk_cli.cli localnet clean --configfile=./multiversx_sdk_cli/tests/testdata/localnet_with_resolution_remote.toml + python3 -m multiversx_sdk_cli.cli localnet config --configfile=./multiversx_sdk_cli/tests/testdata/localnet_with_resolution_remote.toml + nohup python3 -m multiversx_sdk_cli.cli localnet start --configfile=./multiversx_sdk_cli/tests/testdata/localnet_with_resolution_remote.toml + sleep 120 - name: Test localnet dependent tests run: | From 61bf2919055830ab6673db1f3f237dc86aee95aa Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Mon, 4 Nov 2024 17:26:18 +0200 Subject: [PATCH 60/90] debug. --- .github/workflows/test-localnet-tests.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/test-localnet-tests.yml b/.github/workflows/test-localnet-tests.yml index 3d376f42..6beac073 100644 --- a/.github/workflows/test-localnet-tests.yml +++ b/.github/workflows/test-localnet-tests.yml @@ -36,7 +36,6 @@ jobs: - name: Set up MultiversX localnet run: | - python3 -m multiversx_sdk_cli.cli localnet clean --configfile=./multiversx_sdk_cli/tests/testdata/localnet_with_resolution_remote.toml python3 -m multiversx_sdk_cli.cli localnet config --configfile=./multiversx_sdk_cli/tests/testdata/localnet_with_resolution_remote.toml nohup python3 -m multiversx_sdk_cli.cli localnet start --configfile=./multiversx_sdk_cli/tests/testdata/localnet_with_resolution_remote.toml sleep 120 From 4ce863e00e68baa5f9c8b91fd543573617697d36 Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Mon, 4 Nov 2024 17:33:18 +0200 Subject: [PATCH 61/90] more commands. --- .github/workflows/test-localnet-tests.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.github/workflows/test-localnet-tests.yml b/.github/workflows/test-localnet-tests.yml index 6beac073..3b3b7925 100644 --- a/.github/workflows/test-localnet-tests.yml +++ b/.github/workflows/test-localnet-tests.yml @@ -36,6 +36,15 @@ jobs: - name: Set up MultiversX localnet run: | + mkdir -p ~/multiversx-sdk + export PYTHONPATH=. + python3 -m multiversx_sdk_cli.cli localnet prerequisites --configfile=./multiversx_sdk_cli/tests/testdata/localnet_with_resolution_remote.toml + python3 -m multiversx_sdk_cli.cli localnet build --configfile=./multiversx_sdk_cli/tests/testdata/localnet_with_resolution_remote.toml + + # "Go" and artifacts from "GOPATH/pkg/mod" are not needed anymore. + sudo rm -rf ~/multiversx-sdk/golang + + python3 -m multiversx_sdk_cli.cli localnet clean --configfile=./multiversx_sdk_cli/tests/testdata/localnet_with_resolution_remote.toml python3 -m multiversx_sdk_cli.cli localnet config --configfile=./multiversx_sdk_cli/tests/testdata/localnet_with_resolution_remote.toml nohup python3 -m multiversx_sdk_cli.cli localnet start --configfile=./multiversx_sdk_cli/tests/testdata/localnet_with_resolution_remote.toml sleep 120 From 380c08b9ee18aa8f2adc52b24eee80a8426c4bc3 Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Mon, 4 Nov 2024 17:39:07 +0200 Subject: [PATCH 62/90] make nohup run in background. --- .github/workflows/test-localnet-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test-localnet-tests.yml b/.github/workflows/test-localnet-tests.yml index 3b3b7925..630ef7cb 100644 --- a/.github/workflows/test-localnet-tests.yml +++ b/.github/workflows/test-localnet-tests.yml @@ -46,7 +46,7 @@ jobs: python3 -m multiversx_sdk_cli.cli localnet clean --configfile=./multiversx_sdk_cli/tests/testdata/localnet_with_resolution_remote.toml python3 -m multiversx_sdk_cli.cli localnet config --configfile=./multiversx_sdk_cli/tests/testdata/localnet_with_resolution_remote.toml - nohup python3 -m multiversx_sdk_cli.cli localnet start --configfile=./multiversx_sdk_cli/tests/testdata/localnet_with_resolution_remote.toml + nohup python3 -m multiversx_sdk_cli.cli localnet start --configfile=./multiversx_sdk_cli/tests/testdata/localnet_with_resolution_remote.toml > localnet.log 2>&1 & echo $! > localnet.pid sleep 120 - name: Test localnet dependent tests From 58e29a0386cd4916c03f300d63f398d0366303ce Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Mon, 4 Nov 2024 17:49:11 +0200 Subject: [PATCH 63/90] debug localnet config. --- .github/workflows/test-localnet-tests.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test-localnet-tests.yml b/.github/workflows/test-localnet-tests.yml index 630ef7cb..f05bf9c2 100644 --- a/.github/workflows/test-localnet-tests.yml +++ b/.github/workflows/test-localnet-tests.yml @@ -47,6 +47,7 @@ jobs: python3 -m multiversx_sdk_cli.cli localnet clean --configfile=./multiversx_sdk_cli/tests/testdata/localnet_with_resolution_remote.toml python3 -m multiversx_sdk_cli.cli localnet config --configfile=./multiversx_sdk_cli/tests/testdata/localnet_with_resolution_remote.toml nohup python3 -m multiversx_sdk_cli.cli localnet start --configfile=./multiversx_sdk_cli/tests/testdata/localnet_with_resolution_remote.toml > localnet.log 2>&1 & echo $! > localnet.pid + ls sleep 120 - name: Test localnet dependent tests From 31b65631bec57dcbc6ec3ae97c19bea84f874afe Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Mon, 4 Nov 2024 17:53:51 +0200 Subject: [PATCH 64/90] more debugging paths. --- .github/workflows/test-localnet-tests.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test-localnet-tests.yml b/.github/workflows/test-localnet-tests.yml index f05bf9c2..dec981f5 100644 --- a/.github/workflows/test-localnet-tests.yml +++ b/.github/workflows/test-localnet-tests.yml @@ -47,6 +47,7 @@ jobs: python3 -m multiversx_sdk_cli.cli localnet clean --configfile=./multiversx_sdk_cli/tests/testdata/localnet_with_resolution_remote.toml python3 -m multiversx_sdk_cli.cli localnet config --configfile=./multiversx_sdk_cli/tests/testdata/localnet_with_resolution_remote.toml nohup python3 -m multiversx_sdk_cli.cli localnet start --configfile=./multiversx_sdk_cli/tests/testdata/localnet_with_resolution_remote.toml > localnet.log 2>&1 & echo $! > localnet.pid + cd localnet ls sleep 120 From 92e6386de09c43b38dc2884bdf51ef70100b87cb Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Mon, 4 Nov 2024 18:01:42 +0200 Subject: [PATCH 65/90] fix paths for ci validator keys file. --- .github/workflows/test-localnet-tests.yml | 2 ++ multiversx_sdk_cli/tests/testdata/validators_ci.json | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test-localnet-tests.yml b/.github/workflows/test-localnet-tests.yml index dec981f5..b3a8ba37 100644 --- a/.github/workflows/test-localnet-tests.yml +++ b/.github/workflows/test-localnet-tests.yml @@ -48,7 +48,9 @@ jobs: python3 -m multiversx_sdk_cli.cli localnet config --configfile=./multiversx_sdk_cli/tests/testdata/localnet_with_resolution_remote.toml nohup python3 -m multiversx_sdk_cli.cli localnet start --configfile=./multiversx_sdk_cli/tests/testdata/localnet_with_resolution_remote.toml > localnet.log 2>&1 & echo $! > localnet.pid cd localnet + cd validator00 ls + pwd sleep 120 - name: Test localnet dependent tests diff --git a/multiversx_sdk_cli/tests/testdata/validators_ci.json b/multiversx_sdk_cli/tests/testdata/validators_ci.json index 3067c23a..99a390c6 100644 --- a/multiversx_sdk_cli/tests/testdata/validators_ci.json +++ b/multiversx_sdk_cli/tests/testdata/validators_ci.json @@ -1,13 +1,13 @@ { "validators": [ { - "pemFile": "~/work/mx-sdk-py-cli/mx-sdk-py-cli/localnet/validator00/validatorKey00.pem" + "pemFile": "~/work/mx-sdk-py-cli/mx-sdk-py-cli/localnet/validator00/config/validatorKey.pem" }, { - "pemFile": "~/work/mx-sdk-py-cli/mx-sdk-py-cli/localnet/validator01/validatorKey01.pem" + "pemFile": "~/work/mx-sdk-py-cli/mx-sdk-py-cli/localnet/validator01/config/validatorKey.pem" }, { - "pemFile": "~/work/mx-sdk-py-cli/mx-sdk-py-cli/localnet/validator02/validatorKey02.pem" + "pemFile": "~/work/mx-sdk-py-cli/mx-sdk-py-cli/localnet/validator02/config/validatorKey.pem" } ] } From e8c89e1729c163b0ef57704ea2806a3607725aae Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Mon, 4 Nov 2024 18:10:52 +0200 Subject: [PATCH 66/90] clean remaining commented code. --- .github/workflows/test-localnet-tests.yml | 4 --- .../tests/test_cli_validators.py | 29 ------------------- 2 files changed, 33 deletions(-) diff --git a/.github/workflows/test-localnet-tests.yml b/.github/workflows/test-localnet-tests.yml index b3a8ba37..630ef7cb 100644 --- a/.github/workflows/test-localnet-tests.yml +++ b/.github/workflows/test-localnet-tests.yml @@ -47,10 +47,6 @@ jobs: python3 -m multiversx_sdk_cli.cli localnet clean --configfile=./multiversx_sdk_cli/tests/testdata/localnet_with_resolution_remote.toml python3 -m multiversx_sdk_cli.cli localnet config --configfile=./multiversx_sdk_cli/tests/testdata/localnet_with_resolution_remote.toml nohup python3 -m multiversx_sdk_cli.cli localnet start --configfile=./multiversx_sdk_cli/tests/testdata/localnet_with_resolution_remote.toml > localnet.log 2>&1 & echo $! > localnet.pid - cd localnet - cd validator00 - ls - pwd sleep 120 - name: Test localnet dependent tests diff --git a/multiversx_sdk_cli/tests/test_cli_validators.py b/multiversx_sdk_cli/tests/test_cli_validators.py index 0891ef56..3f5d6402 100644 --- a/multiversx_sdk_cli/tests/test_cli_validators.py +++ b/multiversx_sdk_cli/tests/test_cli_validators.py @@ -15,35 +15,6 @@ bls_key = "e7beaa95b3877f47348df4dd1cb578a4f7cabf7a20bfeefe5cdd263878ff132b765e04fef6f40c93512b666c47ed7719b8902f6c922c04247989b7137e837cc81a62e54712471c97a2ddab75aa9c2f58f813ed4c0fa722bde0ab718bff382208" -# @pytest.fixture() -# def poll_endpoint(): -# start_time = time.time() # Record the start time -# timeout = 600 -# interval = 1 -# -# while True: -# try: -# # Make the request to the endpoint -# response = requests.get(proxy_url, timeout=5) # Add request timeout to prevent blocking indefinitely -# if response.status_code == 200: -# # Break out of the loop if we get a successful response -# return response.json() # Return the response (or .text, .content based on your needs) -# else: -# print(f"Received non-200 status code: {response.status_code}") -# -# except requests.RequestException as e: -# # Handle network exceptions or timeouts -# print(f"Request failed: {e}") -# -# # Check if the timeout is reached -# if time.time() - start_time > timeout: -# print("Polling timed out") -# break -# -# # Wait for the specified interval before sending the next request -# time.sleep(interval) - - @pytest.mark.require_localnet def test_stake(): validators_json = testdata_path / "validators_ci.json" From 0080690f8698b83c6b2fb0eb6fab9e1a0b498120 Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Mon, 4 Nov 2024 23:54:29 +0200 Subject: [PATCH 67/90] added conftest and strict markers. --- .github/workflows/test-localnet-tests.yml | 1 + multiversx_sdk_cli/tests/conftest.py | 12 ++++++++++++ multiversx_sdk_cli/tests/test_cli_validators.py | 2 -- pytest.ini | 4 ++-- 4 files changed, 15 insertions(+), 4 deletions(-) create mode 100644 multiversx_sdk_cli/tests/conftest.py diff --git a/.github/workflows/test-localnet-tests.yml b/.github/workflows/test-localnet-tests.yml index 630ef7cb..e4b66985 100644 --- a/.github/workflows/test-localnet-tests.yml +++ b/.github/workflows/test-localnet-tests.yml @@ -52,3 +52,4 @@ jobs: - name: Test localnet dependent tests run: | pytest -m require_localnet multiversx_sdk_cli/tests + diff --git a/multiversx_sdk_cli/tests/conftest.py b/multiversx_sdk_cli/tests/conftest.py new file mode 100644 index 00000000..601ea625 --- /dev/null +++ b/multiversx_sdk_cli/tests/conftest.py @@ -0,0 +1,12 @@ +import pytest + + +# function executed right after test items collected but before test run +def pytest_collection_modifyitems(config, items): + if not config.getoption('-m'): + skip_me = pytest.mark.skip(reason="to run marked tests, you need to explicitly run them wiht -m") + for item in items: + if "require_localnet" in item.keywords: + item.add_marker(skip_me) + if "skip_on_winodws" in item.keywords: + item.add_marker(skip_me) diff --git a/multiversx_sdk_cli/tests/test_cli_validators.py b/multiversx_sdk_cli/tests/test_cli_validators.py index 3f5d6402..8b7cc521 100644 --- a/multiversx_sdk_cli/tests/test_cli_validators.py +++ b/multiversx_sdk_cli/tests/test_cli_validators.py @@ -1,5 +1,3 @@ -import requests -import time import pytest from pathlib import Path diff --git a/pytest.ini b/pytest.ini index cab31729..4cee0be1 100644 --- a/pytest.ini +++ b/pytest.ini @@ -1,7 +1,7 @@ [pytest] markers = - skip_on_windows: marks tests as being skiped when running on windows (deselect with '-m "skip_on_windows"') + skip_on_windows: marks tests as being skipped when running on windows (deselect with '-m "skip_on_windows"') only: only run a specific test (run using: pytest -m "only") - require_localnet: marks tests that require a localnet (run using: pytest -m require_localnet) + require_localnet: marks tests that require a localnet (select with '-m "require_localnet"') log_cli = True From 69404f006d0687bbd0971b0a39a653524ddb600a Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Tue, 5 Nov 2024 10:14:37 +0200 Subject: [PATCH 68/90] modified skip on windows marker. --- .github/workflows/build-windows.yml | 2 +- multiversx_sdk_cli/tests/conftest.py | 4 ++-- multiversx_sdk_cli/tests/test_cli_deps.py | 4 ++-- pytest.ini | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build-windows.yml b/.github/workflows/build-windows.yml index e7010de2..ae33b14e 100644 --- a/.github/workflows/build-windows.yml +++ b/.github/workflows/build-windows.yml @@ -47,7 +47,7 @@ jobs: shell: bash run: | export PYTHONPATH=. - pytest -m "not skip_on_windows" . + pytest -m "run_on_windows" . - name: Run CLI tests shell: bash run: | diff --git a/multiversx_sdk_cli/tests/conftest.py b/multiversx_sdk_cli/tests/conftest.py index 601ea625..2939fe5e 100644 --- a/multiversx_sdk_cli/tests/conftest.py +++ b/multiversx_sdk_cli/tests/conftest.py @@ -4,9 +4,9 @@ # function executed right after test items collected but before test run def pytest_collection_modifyitems(config, items): if not config.getoption('-m'): - skip_me = pytest.mark.skip(reason="to run marked tests, you need to explicitly run them wiht -m") + skip_me = pytest.mark.skip(reason="to run marked tests, you need to explicitly run them with -m") for item in items: if "require_localnet" in item.keywords: item.add_marker(skip_me) - if "skip_on_winodws" in item.keywords: + if "run_on_windows" in item.keywords: item.add_marker(skip_me) diff --git a/multiversx_sdk_cli/tests/test_cli_deps.py b/multiversx_sdk_cli/tests/test_cli_deps.py index 63162d71..1d57bbf5 100644 --- a/multiversx_sdk_cli/tests/test_cli_deps.py +++ b/multiversx_sdk_cli/tests/test_cli_deps.py @@ -41,13 +41,13 @@ def test_deps_check_testwallets(): assert return_code == 0 -@pytest.mark.skip_on_windows +@pytest.mark.run_on_windows def test_deps_install_all(): return_code = main(["deps", "install", "all"]) assert return_code == 0 -@pytest.mark.skip_on_windows +@pytest.mark.run_on_windows def test_deps_check_all(): return_code = main(["deps", "check", "all"]) assert return_code == 0 diff --git a/pytest.ini b/pytest.ini index 4cee0be1..f1722316 100644 --- a/pytest.ini +++ b/pytest.ini @@ -1,6 +1,6 @@ [pytest] markers = - skip_on_windows: marks tests as being skipped when running on windows (deselect with '-m "skip_on_windows"') + run_on_windows: marks tests as being skipped when running on windows (select with '-m "run_on_windows"') only: only run a specific test (run using: pytest -m "only") require_localnet: marks tests that require a localnet (select with '-m "require_localnet"') From c2adbf221fe38bc9624ead44615a57d79eec9baf Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Tue, 5 Nov 2024 11:26:10 +0200 Subject: [PATCH 69/90] fix skip_on_windows marker --- .github/workflows/build-windows.yml | 2 +- .github/workflows/test-localnet-tests.yml | 2 +- multiversx_sdk_cli/tests/conftest.py | 4 +--- multiversx_sdk_cli/tests/test_cli_deps.py | 4 ++-- pytest.ini | 2 +- 5 files changed, 6 insertions(+), 8 deletions(-) diff --git a/.github/workflows/build-windows.yml b/.github/workflows/build-windows.yml index ae33b14e..e7010de2 100644 --- a/.github/workflows/build-windows.yml +++ b/.github/workflows/build-windows.yml @@ -47,7 +47,7 @@ jobs: shell: bash run: | export PYTHONPATH=. - pytest -m "run_on_windows" . + pytest -m "not skip_on_windows" . - name: Run CLI tests shell: bash run: | diff --git a/.github/workflows/test-localnet-tests.yml b/.github/workflows/test-localnet-tests.yml index e4b66985..c79969c9 100644 --- a/.github/workflows/test-localnet-tests.yml +++ b/.github/workflows/test-localnet-tests.yml @@ -51,5 +51,5 @@ jobs: - name: Test localnet dependent tests run: | - pytest -m require_localnet multiversx_sdk_cli/tests + pytest -m require_localnet . diff --git a/multiversx_sdk_cli/tests/conftest.py b/multiversx_sdk_cli/tests/conftest.py index 2939fe5e..abff81f5 100644 --- a/multiversx_sdk_cli/tests/conftest.py +++ b/multiversx_sdk_cli/tests/conftest.py @@ -4,9 +4,7 @@ # function executed right after test items collected but before test run def pytest_collection_modifyitems(config, items): if not config.getoption('-m'): - skip_me = pytest.mark.skip(reason="to run marked tests, you need to explicitly run them with -m") + skip_me = pytest.mark.skip(reason="require_localnet will only run if explicitly set to with -m") for item in items: if "require_localnet" in item.keywords: item.add_marker(skip_me) - if "run_on_windows" in item.keywords: - item.add_marker(skip_me) diff --git a/multiversx_sdk_cli/tests/test_cli_deps.py b/multiversx_sdk_cli/tests/test_cli_deps.py index 1d57bbf5..63162d71 100644 --- a/multiversx_sdk_cli/tests/test_cli_deps.py +++ b/multiversx_sdk_cli/tests/test_cli_deps.py @@ -41,13 +41,13 @@ def test_deps_check_testwallets(): assert return_code == 0 -@pytest.mark.run_on_windows +@pytest.mark.skip_on_windows def test_deps_install_all(): return_code = main(["deps", "install", "all"]) assert return_code == 0 -@pytest.mark.run_on_windows +@pytest.mark.skip_on_windows def test_deps_check_all(): return_code = main(["deps", "check", "all"]) assert return_code == 0 diff --git a/pytest.ini b/pytest.ini index f1722316..4cee0be1 100644 --- a/pytest.ini +++ b/pytest.ini @@ -1,6 +1,6 @@ [pytest] markers = - run_on_windows: marks tests as being skipped when running on windows (select with '-m "run_on_windows"') + skip_on_windows: marks tests as being skipped when running on windows (deselect with '-m "skip_on_windows"') only: only run a specific test (run using: pytest -m "only") require_localnet: marks tests that require a localnet (select with '-m "require_localnet"') From 1b1a414fcffa08f1a1e5cc45c4c5b269396f6539 Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Tue, 5 Nov 2024 11:59:00 +0200 Subject: [PATCH 70/90] fix windows build --- .github/workflows/build-windows.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-windows.yml b/.github/workflows/build-windows.yml index e7010de2..b6f87291 100644 --- a/.github/workflows/build-windows.yml +++ b/.github/workflows/build-windows.yml @@ -47,7 +47,7 @@ jobs: shell: bash run: | export PYTHONPATH=. - pytest -m "not skip_on_windows" . + pytest -m "not skip_on_windows and not require_localnet" . - name: Run CLI tests shell: bash run: | From 40674117db339547eea73f11794d578bea5ffb49 Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Tue, 5 Nov 2024 14:15:09 +0200 Subject: [PATCH 71/90] remove duplicated bash tests and added teardown for localnet tests. --- .github/workflows/test-localnet-tests.yml | 2 + .../tests/test_cli_contracts.sh | 119 ------------------ multiversx_sdk_cli/tests/test_cli_dns.sh | 113 ----------------- .../tests/test_cli_validators.sh | 44 ------- 4 files changed, 2 insertions(+), 276 deletions(-) delete mode 100755 multiversx_sdk_cli/tests/test_cli_contracts.sh delete mode 100644 multiversx_sdk_cli/tests/test_cli_dns.sh delete mode 100755 multiversx_sdk_cli/tests/test_cli_validators.sh diff --git a/.github/workflows/test-localnet-tests.yml b/.github/workflows/test-localnet-tests.yml index c79969c9..9ff0eee2 100644 --- a/.github/workflows/test-localnet-tests.yml +++ b/.github/workflows/test-localnet-tests.yml @@ -52,4 +52,6 @@ jobs: - name: Test localnet dependent tests run: | pytest -m require_localnet . + python3 -m multiversx_sdk_cli.cli localnet stop --configfile=./multiversx_sdk_cli/tests/testdata/localnet_with_resolution_remote.toml + diff --git a/multiversx_sdk_cli/tests/test_cli_contracts.sh b/multiversx_sdk_cli/tests/test_cli_contracts.sh deleted file mode 100755 index bf7f9fa6..00000000 --- a/multiversx_sdk_cli/tests/test_cli_contracts.sh +++ /dev/null @@ -1,119 +0,0 @@ -#!/usr/bin/env bash - -source "./shared.sh" - -testTrivialCommands() { - echo "testTrivialCommands" - ${CLI} contract templates -} - -testCreateContracts() { - echo "testCreateContracts" - ${CLI} contract new --template adder --path ${SANDBOX} || return 1 - ${CLI} contract new --template crypto-zombies --path ${SANDBOX} || return 1 - ${CLI} contract new --template empty --path ${SANDBOX} || return 1 -} - -testBuildContracts() { - echo "testBuildContracts" - - # Improve compilation time by reusing build artifacts for Rust projects - export TARGET_DIR=$(pwd)/${SANDBOX}/TARGET - mkdir -p ${TARGET_DIR} - - ${CLI} contract build --path=${SANDBOX}/adder --target-dir=${TARGET_DIR} || return 1 - assertFileExists ${SANDBOX}/adder/output/adder.wasm || return 1 - assertFileExists ${SANDBOX}/adder/output/adder.abi.json || return 1 - - ${CLI} contract build --path=${SANDBOX}/crypto-zombies --target-dir=${TARGET_DIR} || return 1 - assertFileExists ${SANDBOX}/crypto-zombies/output/crypto-zombies.wasm || return 1 - assertFileExists ${SANDBOX}/crypto-zombies/output/crypto-zombies.abi.json || return 1 - - ${CLI} contract build --path=${SANDBOX}/empty --target-dir=${TARGET_DIR} || return 1 - assertFileExists ${SANDBOX}/empty/output/empty.wasm || return 1 - assertFileExists ${SANDBOX}/empty/output/empty.abi.json || return 1 -} - -testRunScenarios() { - echo "testRunScenarios" - ${CLI} --verbose contract test --path=${SANDBOX}/adder || return 1 - ${CLI} --verbose contract test --path=${SANDBOX}/empty || return 1 -} - -testWasmName() { - echo "testWasmName" - - ${CLI} contract clean --path ${SANDBOX}/adder - assertFileDoesNotExist ${SANDBOX}/adder/output/adder-2.wasm || return 1 - ${CLI} contract build --path=${SANDBOX}/adder --target-dir=${TARGET_DIR} --wasm-name adder-2 || return 1 - assertFileExists ${SANDBOX}/adder/output/adder-2.wasm || return 1 - assertFileExists ${SANDBOX}/adder/output/adder.abi.json || return 1 -} - -testCleanContracts() { - echo "testCleanContracts" - - assertFileExists ${SANDBOX}/adder/output/adder.wasm || return 1 - assertFileExists ${SANDBOX}/adder/output/adder.abi.json || return 1 - ${CLI} contract clean --path ${SANDBOX}/adder || return 1 - assertFileDoesNotExist ${SANDBOX}/adder/output/adder.wasm || return 1 - assertFileDoesNotExist ${SANDBOX}/adder/output/adder.abi.json || return 1 - - assertFileExists ${SANDBOX}/crypto-zombies/output/crypto-zombies.wasm || return 1 - assertFileExists ${SANDBOX}/crypto-zombies/output/crypto-zombies.abi.json || return 1 - ${CLI} contract clean --path ${SANDBOX}/crypto-zombies || return 1 - assertFileDoesNotExist ${SANDBOX}/crypto-zombies/output/crypto-zombies.wasm || return 1 - assertFileDoesNotExist ${SANDBOX}/crypto-zombies/output/crypto-zombies.abi.json || return 1 - - assertFileExists ${SANDBOX}/empty/output/empty.wasm || return 1 - assertFileExists ${SANDBOX}/empty/output/empty.abi.json || return 1 - ${CLI} contract clean --path ${SANDBOX}/empty || return 1 - assertFileDoesNotExist ${SANDBOX}/empty/output/empty.wasm || return 1 - assertFileDoesNotExist ${SANDBOX}/empty/output/empty.abi.json || return 1 -} - -testVerifyContract(){ - echo "testVerifyContract" - - nohup python3 local_verify_server.py >/dev/null 2>&1 & - sleep 1 - - query_response=$(curl -s localhost:7777/verify -X POST) - - command_response=$(${CLI} contract verify erd1qqqqqqqqqqqqqpgquzmh78klkqwt0p4rjys0qtp3la07gz4d396qn50nnm \ - --verifier-url=http://localhost:7777 --packaged-src=testdata/dummy.json \ - --pem=testdata/walletKey.pem --docker-image=multiversx/sdk-rust-contract-builder:v4.0.0) - - result_curl=$(echo $query_response | awk -F ": " '{ print $2 }' | awk -F'"' '{print $2}') - result_cli=$(echo $command_response | awk -F ": " '{ print $2 }' | awk -F'"' '{print $2}') - - if [[ $result_curl == $result_cli ]]; - then - echo "Test passed!" - else - return 1 - fi - - pkill -f local_verify_server.py -} - -testReproducibleBuild() { - echo "testReproducibleBuild" - - wget -O ${SANDBOX}/example.zip https://github.com/multiversx/mx-reproducible-contract-build-example-sc/archive/refs/tags/v0.2.1.zip || return 1 - unzip ${SANDBOX}/example.zip -d ${SANDBOX} || return 1 - ${CLI} contract reproducible-build ${SANDBOX}/mx-reproducible-contract-build-example-sc-0.2.1 --docker-image=multiversx/sdk-rust-contract-builder:v4.1.2 --no-docker-interactive --no-docker-tty || return 1 - assertFileExists ${SANDBOX}/mx-reproducible-contract-build-example-sc-0.2.1/output-docker/artifacts.json || return 1 -} - -testAll() { - ${CLI} config set dependencies.rust.tag ${RUST_VERSION} - - cleanSandbox || return 1 - testTrivialCommands || return 1 - testCreateContracts || return 1 - testBuildContracts || return 1 - testRunScenarios || return 1 - testCleanContracts || return 1 - testWasmName || return 1 -} diff --git a/multiversx_sdk_cli/tests/test_cli_dns.sh b/multiversx_sdk_cli/tests/test_cli_dns.sh deleted file mode 100644 index fa3c9340..00000000 --- a/multiversx_sdk_cli/tests/test_cli_dns.sh +++ /dev/null @@ -1,113 +0,0 @@ -#!/usr/bin/env bash - -source "./shared.sh" - -REGISTRATION_COST=100 - -testOnline() { - testRegistrationOnline || return 1 - # Wait for nonces to be incremented (at source shards) - sleep 15 - testTransactionsWithUsernamesOnline || return 1 -} - -testRegistrationOnline() { - ${CLI} --verbose dns register --name="testuser" --pem=${TestUser} --value=${REGISTRATION_COST} \ - --recall-nonce --gas-limit=100000000 --gas-price=1000000000 --chain=${CHAIN_ID} \ - --outfile=${SANDBOX}/txRegisterUser.txt --send --proxy=${PROXY} || return 1 - - ${CLI} --verbose dns register --name="testuser2" --pem=${TestUser2} --value=${REGISTRATION_COST} \ - --recall-nonce --gas-limit=100000000 --gas-price=1000000000 --chain=${CHAIN_ID} \ - --outfile=${SANDBOX}/txRegisterUser2.txt --send --proxy=${PROXY} || return 1 -} - -testTransactionsWithUsernamesOnline() { - ${CLI} --verbose tx new --pem=${TestUser} --receiver=${TestUser2} \ - --value="1${DENOMINATION}" --recall-nonce --gas-limit=50000 --gas-price=2000000000 --chain=${CHAIN_ID} \ - --outfile=${SANDBOX}/txA.txt --send --proxy=${PROXY} || return 1 - - sleep 10 - - ${CLI} --verbose tx new --pem=${TestUser} --receiver=${TestUser2} --receiver-username="testuser2" \ - --value="1${DENOMINATION}" --recall-nonce --gas-limit=50000 --gas-price=2000000000 --chain=${CHAIN_ID} \ - --outfile=${SANDBOX}/txB.txt --send --proxy=${PROXY} || return 1 - - sleep 10 - - ${CLI} --verbose tx new --pem=${TestUser} --receiver=${TestUser2} --receiver-username="testuser2foo" \ - --value="1${DENOMINATION}" --recall-nonce --gas-limit=50000 --gas-price=2000000000 --chain=${CHAIN_ID} \ - --outfile=${SANDBOX}/txC.txt --send --proxy=${PROXY} || return 1 - - sleep 10 - - ${CLI} --verbose tx new --pem=${TestUser} --sender-username="testuser" --receiver=${TestUser2} --receiver-username="testuser2" \ - --value="1${DENOMINATION}" --recall-nonce --gas-limit=50000 --gas-price=2000000000 --chain=${CHAIN_ID} \ - --outfile=${SANDBOX}/txD.txt --send --proxy=${PROXY} || return 1 - - sleep 10 - - ${CLI} --verbose tx new --pem=${TestUser} --sender-username="testuser" --receiver=${TestUser2} \ - --value="1${DENOMINATION}" --recall-nonce --gas-limit=50000 --gas-price=2000000000 --chain=${CHAIN_ID} \ - --outfile=${SANDBOX}/txF.txt --send --proxy=${PROXY} || return 1 - - sleep 10 - - ${CLI} --verbose tx new --pem=${TestUser} --sender-username="testuserfoo" --receiver=${TestUser2} \ - --value="1${DENOMINATION}" --recall-nonce --gas-limit=50000 --gas-price=2000000000 --chain=${CHAIN_ID} \ - --outfile=${SANDBOX}/txG.txt --send --proxy=${PROXY} || return 1 -} - - -testOffline() { - testRegistrationOffline || return 1 - testTransactionsWithUsernamesOffline || return 1 -} - -testRegistrationOffline() { - ${CLI} --verbose dns register --name="testuser" --pem=${TestUser} --value=${REGISTRATION_COST} \ - --nonce=7 --gas-limit=100000000 --gas-price=1000000000 --chain=${CHAIN_ID} \ - --outfile=${SANDBOX}/txRegisterUser.txt || return 1 - assertFileExists ${SANDBOX}/txRegisterUser.txt || return 1 - - ${CLI} --verbose dns register --name="testuser2" --pem=${TestUser2} --value=${REGISTRATION_COST} \ - --nonce=8 --gas-limit=100000000 --gas-price=1000000000 --chain=${CHAIN_ID} \ - --outfile=${SANDBOX}/txRegisterUser2.txt || return 1 - assertFileExists ${SANDBOX}/txRegisterUser2.txt || return 1 -} - -testTransactionsWithUsernamesOffline() { - ${CLI} --verbose tx new --pem=${TestUser} --receiver="erd1ssmsc9022udc8pdw7wk3hxw74jr900xg28vwpz3z60gep66fasasl2nkm4" \ - --value="1${DENOMINATION}" --nonce=42 --gas-limit=50000 --gas-price=2000000000 --chain=${CHAIN_ID} \ - --outfile=${SANDBOX}/txA.txt || return 1 - assertFileExists ${SANDBOX}/txA.txt || return 1 - - ${CLI} --verbose tx new --pem=${TestUser} --receiver="erd1ssmsc9022udc8pdw7wk3hxw74jr900xg28vwpz3z60gep66fasasl2nkm4" --receiver-username="testuser2" \ - --value="1${DENOMINATION}" --nonce=43 --gas-limit=50000 --gas-price=2000000000 --chain=${CHAIN_ID} \ - --outfile=${SANDBOX}/txB.txt || return 1 - assertFileExists ${SANDBOX}/txB.txt || return 1 - - ${CLI} --verbose tx new --pem=${TestUser} --receiver="erd1ssmsc9022udc8pdw7wk3hxw74jr900xg28vwpz3z60gep66fasasl2nkm4" --receiver-username="testuser2foo" \ - --value="1${DENOMINATION}" --nonce=44 --gas-limit=50000 --gas-price=2000000000 --chain=${CHAIN_ID} \ - --outfile=${SANDBOX}/txC.txt || return 1 - assertFileExists ${SANDBOX}/txC.txt || return 1 - - ${CLI} --verbose tx new --pem=${TestUser} --sender-username="testuser" --receiver="erd1ssmsc9022udc8pdw7wk3hxw74jr900xg28vwpz3z60gep66fasasl2nkm4" --receiver-username="testuser2" \ - --value="1${DENOMINATION}" --nonce=45 --gas-limit=50000 --gas-price=2000000000 --chain=${CHAIN_ID} \ - --outfile=${SANDBOX}/txD.txt || return 1 - assertFileExists ${SANDBOX}/txD.txt || return 1 - - ${CLI} --verbose tx new --pem=${TestUser} --sender-username="testuser" --receiver="erd1ssmsc9022udc8pdw7wk3hxw74jr900xg28vwpz3z60gep66fasasl2nkm4" \ - --value="1${DENOMINATION}" --nonce=46 --gas-limit=50000 --gas-price=2000000000 --chain=${CHAIN_ID} \ - --outfile=${SANDBOX}/txF.txt || return 1 - assertFileExists ${SANDBOX}/txF.txt || return 1 - - ${CLI} --verbose tx new --pem=${TestUser} --sender-username="testuserfoo" --receiver="erd1ssmsc9022udc8pdw7wk3hxw74jr900xg28vwpz3z60gep66fasasl2nkm4" \ - --value="1${DENOMINATION}" --nonce=47 --gas-limit=50000 --gas-price=2000000000 --chain=${CHAIN_ID} \ - --outfile=${SANDBOX}/txG.txt || return 1 - assertFileExists ${SANDBOX}/txG.txt || return 1 -} - -testAll() { - testOnline || return 1 - testOffline || return 1 -} diff --git a/multiversx_sdk_cli/tests/test_cli_validators.sh b/multiversx_sdk_cli/tests/test_cli_validators.sh deleted file mode 100755 index d489c9c0..00000000 --- a/multiversx_sdk_cli/tests/test_cli_validators.sh +++ /dev/null @@ -1,44 +0,0 @@ -#!/usr/bin/env bash - -source "./shared.sh" - -testAll() { - BLS_KEY="e7beaa95b3877f47348df4dd1cb578a4f7cabf7a20bfeefe5cdd263878ff132b765e04fef6f40c93512b666c47ed7719b8902f6c922c04247989b7137e837cc81a62e54712471c97a2ddab75aa9c2f58f813ed4c0fa722bde0ab718bff382208" - REWARD_ADDRESS="erd1k2s324ww2g0yj38qn2ch2jwctdy8mnfxep94q9arncc6xecg3xaq6mjse8" - - echo "Stake with recall nonce" - ${CLI} --verbose validator stake --pem="${USERS}/alice.pem" --value="2500${DENOMINATION}" --validators-file=./testdata/validators.json --reward-address=${REWARD_ADDRESS} --chain=${CHAIN_ID} --proxy=${PROXY} --estimate-gas --recall-nonce || return 1 - echo "Stake with provided nonce" - ${CLI} --verbose validator stake --pem="${USERS}/bob.pem" --value="2500${DENOMINATION}" --validators-file=./testdata/validators.json --reward-address=${REWARD_ADDRESS} --chain=${CHAIN_ID} --proxy=${PROXY} --estimate-gas --nonce=300 || return 1 - - - echo "Stake with topUP" - ${CLI} --verbose validator stake --top-up --pem="${USERS}/carol.pem" --value="2711${DENOMINATION}" --chain=${CHAIN_ID} --proxy=${PROXY} --estimate-gas --recall-nonce || return 1 - - echo "Unstake" - ${CLI} --verbose validator unstake --pem="${USERS}/dan.pem" --nodes-public-keys="${BLS_KEY}" --chain=${CHAIN_ID} --proxy=${PROXY} --estimate-gas --recall-nonce || return 1 - echo "Unbond" - ${CLI} --verbose validator unbond --pem="${USERS}/eve.pem" --nodes-public-keys=${BLS_KEY} --chain=${CHAIN_ID} --proxy=${PROXY} --estimate-gas --recall-nonce || return 1 - echo "Unjail" - ${CLI} --verbose validator unjail --pem="${USERS}/frank.pem" --value="2500${DENOMINATION}" --nodes-public-keys=${BLS_KEY} --chain=${CHAIN_ID} --proxy=${PROXY} --estimate-gas --recall-nonce || return 1 - echo "Change reward address" - ${CLI} --verbose validator change-reward-address --pem="${USERS}/grace.pem" --reward-address=${REWARD_ADDRESS} --chain=${CHAIN_ID} --proxy=${PROXY} --estimate-gas --recall-nonce || return 1 - - echo "UnstakeNodes" - ${CLI} --verbose validator unstake-nodes --pem="${USERS}/heidi.pem" --nodes-public-keys=${BLS_KEY} --chain=${CHAIN_ID} --proxy=${PROXY} --estimate-gas --recall-nonce || return 1 - - echo "UnstakeTokens" - ${CLI} --verbose validator unstake-tokens --pem="${USERS}/ivan.pem" --unstake-value="11${DENOMINATION}" --chain=${CHAIN_ID} --proxy=${PROXY} --estimate-gas --recall-nonce || return 1 - - echo "UnbondNodes" - ${CLI} --verbose validator unbond-nodes --pem="${USERS}/judy.pem" --nodes-public-keys=${BLS_KEY} --chain=${CHAIN_ID} --proxy=${PROXY} --estimate-gas --recall-nonce || return 1 - - echo "UnbondTokens" - ${CLI} --verbose validator unbond-tokens --pem="${USERS}/mallory.pem" --unbond-value="20${DENOMINATION}" --chain=${CHAIN_ID} --proxy=${PROXY} --estimate-gas --recall-nonce || return 1 - - echo "CleanRegistrationData" - ${CLI} --verbose validator clean-registered-data --pem="${USERS}/mike.pem" --chain=${CHAIN_ID} --proxy=${PROXY} --estimate-gas --recall-nonce || return 1 - - echo "ReStakeUnstakedNodes" - ${CLI} --verbose validator restake-unstaked-nodes --pem="${USERS}/alice.pem" --nodes-public-keys=${BLS_KEY} --chain=${CHAIN_ID} --proxy=${PROXY} --estimate-gas --recall-nonce || return 1 -} From 572725d84e36e13f2af7795456c8277c341dfe41 Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Tue, 5 Nov 2024 16:35:32 +0200 Subject: [PATCH 72/90] Revert "remove duplicated bash tests and added teardown for localnet tests." This reverts commit 40674117db339547eea73f11794d578bea5ffb49. --- .github/workflows/test-localnet-tests.yml | 2 - .../tests/test_cli_contracts.sh | 119 ++++++++++++++++++ multiversx_sdk_cli/tests/test_cli_dns.sh | 113 +++++++++++++++++ .../tests/test_cli_validators.sh | 44 +++++++ 4 files changed, 276 insertions(+), 2 deletions(-) create mode 100755 multiversx_sdk_cli/tests/test_cli_contracts.sh create mode 100644 multiversx_sdk_cli/tests/test_cli_dns.sh create mode 100755 multiversx_sdk_cli/tests/test_cli_validators.sh diff --git a/.github/workflows/test-localnet-tests.yml b/.github/workflows/test-localnet-tests.yml index 9ff0eee2..c79969c9 100644 --- a/.github/workflows/test-localnet-tests.yml +++ b/.github/workflows/test-localnet-tests.yml @@ -52,6 +52,4 @@ jobs: - name: Test localnet dependent tests run: | pytest -m require_localnet . - python3 -m multiversx_sdk_cli.cli localnet stop --configfile=./multiversx_sdk_cli/tests/testdata/localnet_with_resolution_remote.toml - diff --git a/multiversx_sdk_cli/tests/test_cli_contracts.sh b/multiversx_sdk_cli/tests/test_cli_contracts.sh new file mode 100755 index 00000000..bf7f9fa6 --- /dev/null +++ b/multiversx_sdk_cli/tests/test_cli_contracts.sh @@ -0,0 +1,119 @@ +#!/usr/bin/env bash + +source "./shared.sh" + +testTrivialCommands() { + echo "testTrivialCommands" + ${CLI} contract templates +} + +testCreateContracts() { + echo "testCreateContracts" + ${CLI} contract new --template adder --path ${SANDBOX} || return 1 + ${CLI} contract new --template crypto-zombies --path ${SANDBOX} || return 1 + ${CLI} contract new --template empty --path ${SANDBOX} || return 1 +} + +testBuildContracts() { + echo "testBuildContracts" + + # Improve compilation time by reusing build artifacts for Rust projects + export TARGET_DIR=$(pwd)/${SANDBOX}/TARGET + mkdir -p ${TARGET_DIR} + + ${CLI} contract build --path=${SANDBOX}/adder --target-dir=${TARGET_DIR} || return 1 + assertFileExists ${SANDBOX}/adder/output/adder.wasm || return 1 + assertFileExists ${SANDBOX}/adder/output/adder.abi.json || return 1 + + ${CLI} contract build --path=${SANDBOX}/crypto-zombies --target-dir=${TARGET_DIR} || return 1 + assertFileExists ${SANDBOX}/crypto-zombies/output/crypto-zombies.wasm || return 1 + assertFileExists ${SANDBOX}/crypto-zombies/output/crypto-zombies.abi.json || return 1 + + ${CLI} contract build --path=${SANDBOX}/empty --target-dir=${TARGET_DIR} || return 1 + assertFileExists ${SANDBOX}/empty/output/empty.wasm || return 1 + assertFileExists ${SANDBOX}/empty/output/empty.abi.json || return 1 +} + +testRunScenarios() { + echo "testRunScenarios" + ${CLI} --verbose contract test --path=${SANDBOX}/adder || return 1 + ${CLI} --verbose contract test --path=${SANDBOX}/empty || return 1 +} + +testWasmName() { + echo "testWasmName" + + ${CLI} contract clean --path ${SANDBOX}/adder + assertFileDoesNotExist ${SANDBOX}/adder/output/adder-2.wasm || return 1 + ${CLI} contract build --path=${SANDBOX}/adder --target-dir=${TARGET_DIR} --wasm-name adder-2 || return 1 + assertFileExists ${SANDBOX}/adder/output/adder-2.wasm || return 1 + assertFileExists ${SANDBOX}/adder/output/adder.abi.json || return 1 +} + +testCleanContracts() { + echo "testCleanContracts" + + assertFileExists ${SANDBOX}/adder/output/adder.wasm || return 1 + assertFileExists ${SANDBOX}/adder/output/adder.abi.json || return 1 + ${CLI} contract clean --path ${SANDBOX}/adder || return 1 + assertFileDoesNotExist ${SANDBOX}/adder/output/adder.wasm || return 1 + assertFileDoesNotExist ${SANDBOX}/adder/output/adder.abi.json || return 1 + + assertFileExists ${SANDBOX}/crypto-zombies/output/crypto-zombies.wasm || return 1 + assertFileExists ${SANDBOX}/crypto-zombies/output/crypto-zombies.abi.json || return 1 + ${CLI} contract clean --path ${SANDBOX}/crypto-zombies || return 1 + assertFileDoesNotExist ${SANDBOX}/crypto-zombies/output/crypto-zombies.wasm || return 1 + assertFileDoesNotExist ${SANDBOX}/crypto-zombies/output/crypto-zombies.abi.json || return 1 + + assertFileExists ${SANDBOX}/empty/output/empty.wasm || return 1 + assertFileExists ${SANDBOX}/empty/output/empty.abi.json || return 1 + ${CLI} contract clean --path ${SANDBOX}/empty || return 1 + assertFileDoesNotExist ${SANDBOX}/empty/output/empty.wasm || return 1 + assertFileDoesNotExist ${SANDBOX}/empty/output/empty.abi.json || return 1 +} + +testVerifyContract(){ + echo "testVerifyContract" + + nohup python3 local_verify_server.py >/dev/null 2>&1 & + sleep 1 + + query_response=$(curl -s localhost:7777/verify -X POST) + + command_response=$(${CLI} contract verify erd1qqqqqqqqqqqqqpgquzmh78klkqwt0p4rjys0qtp3la07gz4d396qn50nnm \ + --verifier-url=http://localhost:7777 --packaged-src=testdata/dummy.json \ + --pem=testdata/walletKey.pem --docker-image=multiversx/sdk-rust-contract-builder:v4.0.0) + + result_curl=$(echo $query_response | awk -F ": " '{ print $2 }' | awk -F'"' '{print $2}') + result_cli=$(echo $command_response | awk -F ": " '{ print $2 }' | awk -F'"' '{print $2}') + + if [[ $result_curl == $result_cli ]]; + then + echo "Test passed!" + else + return 1 + fi + + pkill -f local_verify_server.py +} + +testReproducibleBuild() { + echo "testReproducibleBuild" + + wget -O ${SANDBOX}/example.zip https://github.com/multiversx/mx-reproducible-contract-build-example-sc/archive/refs/tags/v0.2.1.zip || return 1 + unzip ${SANDBOX}/example.zip -d ${SANDBOX} || return 1 + ${CLI} contract reproducible-build ${SANDBOX}/mx-reproducible-contract-build-example-sc-0.2.1 --docker-image=multiversx/sdk-rust-contract-builder:v4.1.2 --no-docker-interactive --no-docker-tty || return 1 + assertFileExists ${SANDBOX}/mx-reproducible-contract-build-example-sc-0.2.1/output-docker/artifacts.json || return 1 +} + +testAll() { + ${CLI} config set dependencies.rust.tag ${RUST_VERSION} + + cleanSandbox || return 1 + testTrivialCommands || return 1 + testCreateContracts || return 1 + testBuildContracts || return 1 + testRunScenarios || return 1 + testCleanContracts || return 1 + testWasmName || return 1 +} diff --git a/multiversx_sdk_cli/tests/test_cli_dns.sh b/multiversx_sdk_cli/tests/test_cli_dns.sh new file mode 100644 index 00000000..fa3c9340 --- /dev/null +++ b/multiversx_sdk_cli/tests/test_cli_dns.sh @@ -0,0 +1,113 @@ +#!/usr/bin/env bash + +source "./shared.sh" + +REGISTRATION_COST=100 + +testOnline() { + testRegistrationOnline || return 1 + # Wait for nonces to be incremented (at source shards) + sleep 15 + testTransactionsWithUsernamesOnline || return 1 +} + +testRegistrationOnline() { + ${CLI} --verbose dns register --name="testuser" --pem=${TestUser} --value=${REGISTRATION_COST} \ + --recall-nonce --gas-limit=100000000 --gas-price=1000000000 --chain=${CHAIN_ID} \ + --outfile=${SANDBOX}/txRegisterUser.txt --send --proxy=${PROXY} || return 1 + + ${CLI} --verbose dns register --name="testuser2" --pem=${TestUser2} --value=${REGISTRATION_COST} \ + --recall-nonce --gas-limit=100000000 --gas-price=1000000000 --chain=${CHAIN_ID} \ + --outfile=${SANDBOX}/txRegisterUser2.txt --send --proxy=${PROXY} || return 1 +} + +testTransactionsWithUsernamesOnline() { + ${CLI} --verbose tx new --pem=${TestUser} --receiver=${TestUser2} \ + --value="1${DENOMINATION}" --recall-nonce --gas-limit=50000 --gas-price=2000000000 --chain=${CHAIN_ID} \ + --outfile=${SANDBOX}/txA.txt --send --proxy=${PROXY} || return 1 + + sleep 10 + + ${CLI} --verbose tx new --pem=${TestUser} --receiver=${TestUser2} --receiver-username="testuser2" \ + --value="1${DENOMINATION}" --recall-nonce --gas-limit=50000 --gas-price=2000000000 --chain=${CHAIN_ID} \ + --outfile=${SANDBOX}/txB.txt --send --proxy=${PROXY} || return 1 + + sleep 10 + + ${CLI} --verbose tx new --pem=${TestUser} --receiver=${TestUser2} --receiver-username="testuser2foo" \ + --value="1${DENOMINATION}" --recall-nonce --gas-limit=50000 --gas-price=2000000000 --chain=${CHAIN_ID} \ + --outfile=${SANDBOX}/txC.txt --send --proxy=${PROXY} || return 1 + + sleep 10 + + ${CLI} --verbose tx new --pem=${TestUser} --sender-username="testuser" --receiver=${TestUser2} --receiver-username="testuser2" \ + --value="1${DENOMINATION}" --recall-nonce --gas-limit=50000 --gas-price=2000000000 --chain=${CHAIN_ID} \ + --outfile=${SANDBOX}/txD.txt --send --proxy=${PROXY} || return 1 + + sleep 10 + + ${CLI} --verbose tx new --pem=${TestUser} --sender-username="testuser" --receiver=${TestUser2} \ + --value="1${DENOMINATION}" --recall-nonce --gas-limit=50000 --gas-price=2000000000 --chain=${CHAIN_ID} \ + --outfile=${SANDBOX}/txF.txt --send --proxy=${PROXY} || return 1 + + sleep 10 + + ${CLI} --verbose tx new --pem=${TestUser} --sender-username="testuserfoo" --receiver=${TestUser2} \ + --value="1${DENOMINATION}" --recall-nonce --gas-limit=50000 --gas-price=2000000000 --chain=${CHAIN_ID} \ + --outfile=${SANDBOX}/txG.txt --send --proxy=${PROXY} || return 1 +} + + +testOffline() { + testRegistrationOffline || return 1 + testTransactionsWithUsernamesOffline || return 1 +} + +testRegistrationOffline() { + ${CLI} --verbose dns register --name="testuser" --pem=${TestUser} --value=${REGISTRATION_COST} \ + --nonce=7 --gas-limit=100000000 --gas-price=1000000000 --chain=${CHAIN_ID} \ + --outfile=${SANDBOX}/txRegisterUser.txt || return 1 + assertFileExists ${SANDBOX}/txRegisterUser.txt || return 1 + + ${CLI} --verbose dns register --name="testuser2" --pem=${TestUser2} --value=${REGISTRATION_COST} \ + --nonce=8 --gas-limit=100000000 --gas-price=1000000000 --chain=${CHAIN_ID} \ + --outfile=${SANDBOX}/txRegisterUser2.txt || return 1 + assertFileExists ${SANDBOX}/txRegisterUser2.txt || return 1 +} + +testTransactionsWithUsernamesOffline() { + ${CLI} --verbose tx new --pem=${TestUser} --receiver="erd1ssmsc9022udc8pdw7wk3hxw74jr900xg28vwpz3z60gep66fasasl2nkm4" \ + --value="1${DENOMINATION}" --nonce=42 --gas-limit=50000 --gas-price=2000000000 --chain=${CHAIN_ID} \ + --outfile=${SANDBOX}/txA.txt || return 1 + assertFileExists ${SANDBOX}/txA.txt || return 1 + + ${CLI} --verbose tx new --pem=${TestUser} --receiver="erd1ssmsc9022udc8pdw7wk3hxw74jr900xg28vwpz3z60gep66fasasl2nkm4" --receiver-username="testuser2" \ + --value="1${DENOMINATION}" --nonce=43 --gas-limit=50000 --gas-price=2000000000 --chain=${CHAIN_ID} \ + --outfile=${SANDBOX}/txB.txt || return 1 + assertFileExists ${SANDBOX}/txB.txt || return 1 + + ${CLI} --verbose tx new --pem=${TestUser} --receiver="erd1ssmsc9022udc8pdw7wk3hxw74jr900xg28vwpz3z60gep66fasasl2nkm4" --receiver-username="testuser2foo" \ + --value="1${DENOMINATION}" --nonce=44 --gas-limit=50000 --gas-price=2000000000 --chain=${CHAIN_ID} \ + --outfile=${SANDBOX}/txC.txt || return 1 + assertFileExists ${SANDBOX}/txC.txt || return 1 + + ${CLI} --verbose tx new --pem=${TestUser} --sender-username="testuser" --receiver="erd1ssmsc9022udc8pdw7wk3hxw74jr900xg28vwpz3z60gep66fasasl2nkm4" --receiver-username="testuser2" \ + --value="1${DENOMINATION}" --nonce=45 --gas-limit=50000 --gas-price=2000000000 --chain=${CHAIN_ID} \ + --outfile=${SANDBOX}/txD.txt || return 1 + assertFileExists ${SANDBOX}/txD.txt || return 1 + + ${CLI} --verbose tx new --pem=${TestUser} --sender-username="testuser" --receiver="erd1ssmsc9022udc8pdw7wk3hxw74jr900xg28vwpz3z60gep66fasasl2nkm4" \ + --value="1${DENOMINATION}" --nonce=46 --gas-limit=50000 --gas-price=2000000000 --chain=${CHAIN_ID} \ + --outfile=${SANDBOX}/txF.txt || return 1 + assertFileExists ${SANDBOX}/txF.txt || return 1 + + ${CLI} --verbose tx new --pem=${TestUser} --sender-username="testuserfoo" --receiver="erd1ssmsc9022udc8pdw7wk3hxw74jr900xg28vwpz3z60gep66fasasl2nkm4" \ + --value="1${DENOMINATION}" --nonce=47 --gas-limit=50000 --gas-price=2000000000 --chain=${CHAIN_ID} \ + --outfile=${SANDBOX}/txG.txt || return 1 + assertFileExists ${SANDBOX}/txG.txt || return 1 +} + +testAll() { + testOnline || return 1 + testOffline || return 1 +} diff --git a/multiversx_sdk_cli/tests/test_cli_validators.sh b/multiversx_sdk_cli/tests/test_cli_validators.sh new file mode 100755 index 00000000..d489c9c0 --- /dev/null +++ b/multiversx_sdk_cli/tests/test_cli_validators.sh @@ -0,0 +1,44 @@ +#!/usr/bin/env bash + +source "./shared.sh" + +testAll() { + BLS_KEY="e7beaa95b3877f47348df4dd1cb578a4f7cabf7a20bfeefe5cdd263878ff132b765e04fef6f40c93512b666c47ed7719b8902f6c922c04247989b7137e837cc81a62e54712471c97a2ddab75aa9c2f58f813ed4c0fa722bde0ab718bff382208" + REWARD_ADDRESS="erd1k2s324ww2g0yj38qn2ch2jwctdy8mnfxep94q9arncc6xecg3xaq6mjse8" + + echo "Stake with recall nonce" + ${CLI} --verbose validator stake --pem="${USERS}/alice.pem" --value="2500${DENOMINATION}" --validators-file=./testdata/validators.json --reward-address=${REWARD_ADDRESS} --chain=${CHAIN_ID} --proxy=${PROXY} --estimate-gas --recall-nonce || return 1 + echo "Stake with provided nonce" + ${CLI} --verbose validator stake --pem="${USERS}/bob.pem" --value="2500${DENOMINATION}" --validators-file=./testdata/validators.json --reward-address=${REWARD_ADDRESS} --chain=${CHAIN_ID} --proxy=${PROXY} --estimate-gas --nonce=300 || return 1 + + + echo "Stake with topUP" + ${CLI} --verbose validator stake --top-up --pem="${USERS}/carol.pem" --value="2711${DENOMINATION}" --chain=${CHAIN_ID} --proxy=${PROXY} --estimate-gas --recall-nonce || return 1 + + echo "Unstake" + ${CLI} --verbose validator unstake --pem="${USERS}/dan.pem" --nodes-public-keys="${BLS_KEY}" --chain=${CHAIN_ID} --proxy=${PROXY} --estimate-gas --recall-nonce || return 1 + echo "Unbond" + ${CLI} --verbose validator unbond --pem="${USERS}/eve.pem" --nodes-public-keys=${BLS_KEY} --chain=${CHAIN_ID} --proxy=${PROXY} --estimate-gas --recall-nonce || return 1 + echo "Unjail" + ${CLI} --verbose validator unjail --pem="${USERS}/frank.pem" --value="2500${DENOMINATION}" --nodes-public-keys=${BLS_KEY} --chain=${CHAIN_ID} --proxy=${PROXY} --estimate-gas --recall-nonce || return 1 + echo "Change reward address" + ${CLI} --verbose validator change-reward-address --pem="${USERS}/grace.pem" --reward-address=${REWARD_ADDRESS} --chain=${CHAIN_ID} --proxy=${PROXY} --estimate-gas --recall-nonce || return 1 + + echo "UnstakeNodes" + ${CLI} --verbose validator unstake-nodes --pem="${USERS}/heidi.pem" --nodes-public-keys=${BLS_KEY} --chain=${CHAIN_ID} --proxy=${PROXY} --estimate-gas --recall-nonce || return 1 + + echo "UnstakeTokens" + ${CLI} --verbose validator unstake-tokens --pem="${USERS}/ivan.pem" --unstake-value="11${DENOMINATION}" --chain=${CHAIN_ID} --proxy=${PROXY} --estimate-gas --recall-nonce || return 1 + + echo "UnbondNodes" + ${CLI} --verbose validator unbond-nodes --pem="${USERS}/judy.pem" --nodes-public-keys=${BLS_KEY} --chain=${CHAIN_ID} --proxy=${PROXY} --estimate-gas --recall-nonce || return 1 + + echo "UnbondTokens" + ${CLI} --verbose validator unbond-tokens --pem="${USERS}/mallory.pem" --unbond-value="20${DENOMINATION}" --chain=${CHAIN_ID} --proxy=${PROXY} --estimate-gas --recall-nonce || return 1 + + echo "CleanRegistrationData" + ${CLI} --verbose validator clean-registered-data --pem="${USERS}/mike.pem" --chain=${CHAIN_ID} --proxy=${PROXY} --estimate-gas --recall-nonce || return 1 + + echo "ReStakeUnstakedNodes" + ${CLI} --verbose validator restake-unstaked-nodes --pem="${USERS}/alice.pem" --nodes-public-keys=${BLS_KEY} --chain=${CHAIN_ID} --proxy=${PROXY} --estimate-gas --recall-nonce || return 1 +} From eb4228918c4380499aae3fb12d00554975840ab6 Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Tue, 5 Nov 2024 16:35:54 +0200 Subject: [PATCH 73/90] bring back bash tests as they are used in other tests. --- .github/workflows/test-localnet-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test-localnet-tests.yml b/.github/workflows/test-localnet-tests.yml index c79969c9..2ad02795 100644 --- a/.github/workflows/test-localnet-tests.yml +++ b/.github/workflows/test-localnet-tests.yml @@ -52,4 +52,4 @@ jobs: - name: Test localnet dependent tests run: | pytest -m require_localnet . - + python3 -m multiversx_sdk_cli.cli localnet stop --configfile=./multiversx_sdk_cli/tests/testdata/localnet_with_resolution_remote.toml From 10ffa3c0ac360418b48453bf2aeba882c49207a1 Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Tue, 5 Nov 2024 17:04:42 +0200 Subject: [PATCH 74/90] added teardown for localnet. --- .github/workflows/test-localnet-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test-localnet-tests.yml b/.github/workflows/test-localnet-tests.yml index 2ad02795..8c62ad80 100644 --- a/.github/workflows/test-localnet-tests.yml +++ b/.github/workflows/test-localnet-tests.yml @@ -52,4 +52,4 @@ jobs: - name: Test localnet dependent tests run: | pytest -m require_localnet . - python3 -m multiversx_sdk_cli.cli localnet stop --configfile=./multiversx_sdk_cli/tests/testdata/localnet_with_resolution_remote.toml + python3 -m multiversx_sdk_cli.cli localnet clean --configfile=./multiversx_sdk_cli/tests/testdata/localnet_with_resolution_remote.toml From d382db0e57a86f60fb38b7bb33837603111fb137 Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Tue, 5 Nov 2024 17:16:22 +0200 Subject: [PATCH 75/90] clean unused bash tests. --- .github/workflows/build-windows.yml | 4 +- .github/workflows/build.yml | 5 - multiversx_sdk_cli/tests/test_cli_all.sh | 4 - multiversx_sdk_cli/tests/test_cli_dns.sh | 113 ------------------ multiversx_sdk_cli/tests/test_cli_tx.sh | 29 ----- .../tests/test_cli_validators.sh | 44 ------- 6 files changed, 1 insertion(+), 198 deletions(-) delete mode 100644 multiversx_sdk_cli/tests/test_cli_dns.sh delete mode 100644 multiversx_sdk_cli/tests/test_cli_tx.sh delete mode 100755 multiversx_sdk_cli/tests/test_cli_validators.sh diff --git a/.github/workflows/build-windows.yml b/.github/workflows/build-windows.yml index b6f87291..df4528a9 100644 --- a/.github/workflows/build-windows.yml +++ b/.github/workflows/build-windows.yml @@ -54,6 +54,4 @@ jobs: export PROXY=https://testnet-gateway.multiversx.com export CHAIN_ID=T cd ./multiversx_sdk_cli/tests - source ./test_cli_tx.sh && testAll || return 1 - source ./test_cli_dns.sh && testOffline || return 1 - source ./test_cli_validators.sh && testAll || return 1 + testAll || return 1 diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 9dda9a37..044f4b88 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -44,8 +44,3 @@ jobs: run: | export PYTHONPATH=. pytest . - - name: Run CLI tests - run: | - cd ./multiversx_sdk_cli/tests - source ./test_cli_contracts.sh && testAll || return 1 - source ./test_cli_dns.sh && testOffline || return 1 diff --git a/multiversx_sdk_cli/tests/test_cli_all.sh b/multiversx_sdk_cli/tests/test_cli_all.sh index 28cb34f2..95cd2418 100644 --- a/multiversx_sdk_cli/tests/test_cli_all.sh +++ b/multiversx_sdk_cli/tests/test_cli_all.sh @@ -6,12 +6,8 @@ USE_PROXY=$1 testAll() { pushd $SCRIPT_DIR source ./shared.sh - source ./test_cli_contracts.sh && testAll - source ./test_cli_dns.sh && testAll if [ -n "$USE_PROXY" ]; then - source ./test_cli_validators.sh && testAll - source ./test_cli_tx.sh && testAll source ./test_cli_config.sh && testAll fi popd diff --git a/multiversx_sdk_cli/tests/test_cli_dns.sh b/multiversx_sdk_cli/tests/test_cli_dns.sh deleted file mode 100644 index fa3c9340..00000000 --- a/multiversx_sdk_cli/tests/test_cli_dns.sh +++ /dev/null @@ -1,113 +0,0 @@ -#!/usr/bin/env bash - -source "./shared.sh" - -REGISTRATION_COST=100 - -testOnline() { - testRegistrationOnline || return 1 - # Wait for nonces to be incremented (at source shards) - sleep 15 - testTransactionsWithUsernamesOnline || return 1 -} - -testRegistrationOnline() { - ${CLI} --verbose dns register --name="testuser" --pem=${TestUser} --value=${REGISTRATION_COST} \ - --recall-nonce --gas-limit=100000000 --gas-price=1000000000 --chain=${CHAIN_ID} \ - --outfile=${SANDBOX}/txRegisterUser.txt --send --proxy=${PROXY} || return 1 - - ${CLI} --verbose dns register --name="testuser2" --pem=${TestUser2} --value=${REGISTRATION_COST} \ - --recall-nonce --gas-limit=100000000 --gas-price=1000000000 --chain=${CHAIN_ID} \ - --outfile=${SANDBOX}/txRegisterUser2.txt --send --proxy=${PROXY} || return 1 -} - -testTransactionsWithUsernamesOnline() { - ${CLI} --verbose tx new --pem=${TestUser} --receiver=${TestUser2} \ - --value="1${DENOMINATION}" --recall-nonce --gas-limit=50000 --gas-price=2000000000 --chain=${CHAIN_ID} \ - --outfile=${SANDBOX}/txA.txt --send --proxy=${PROXY} || return 1 - - sleep 10 - - ${CLI} --verbose tx new --pem=${TestUser} --receiver=${TestUser2} --receiver-username="testuser2" \ - --value="1${DENOMINATION}" --recall-nonce --gas-limit=50000 --gas-price=2000000000 --chain=${CHAIN_ID} \ - --outfile=${SANDBOX}/txB.txt --send --proxy=${PROXY} || return 1 - - sleep 10 - - ${CLI} --verbose tx new --pem=${TestUser} --receiver=${TestUser2} --receiver-username="testuser2foo" \ - --value="1${DENOMINATION}" --recall-nonce --gas-limit=50000 --gas-price=2000000000 --chain=${CHAIN_ID} \ - --outfile=${SANDBOX}/txC.txt --send --proxy=${PROXY} || return 1 - - sleep 10 - - ${CLI} --verbose tx new --pem=${TestUser} --sender-username="testuser" --receiver=${TestUser2} --receiver-username="testuser2" \ - --value="1${DENOMINATION}" --recall-nonce --gas-limit=50000 --gas-price=2000000000 --chain=${CHAIN_ID} \ - --outfile=${SANDBOX}/txD.txt --send --proxy=${PROXY} || return 1 - - sleep 10 - - ${CLI} --verbose tx new --pem=${TestUser} --sender-username="testuser" --receiver=${TestUser2} \ - --value="1${DENOMINATION}" --recall-nonce --gas-limit=50000 --gas-price=2000000000 --chain=${CHAIN_ID} \ - --outfile=${SANDBOX}/txF.txt --send --proxy=${PROXY} || return 1 - - sleep 10 - - ${CLI} --verbose tx new --pem=${TestUser} --sender-username="testuserfoo" --receiver=${TestUser2} \ - --value="1${DENOMINATION}" --recall-nonce --gas-limit=50000 --gas-price=2000000000 --chain=${CHAIN_ID} \ - --outfile=${SANDBOX}/txG.txt --send --proxy=${PROXY} || return 1 -} - - -testOffline() { - testRegistrationOffline || return 1 - testTransactionsWithUsernamesOffline || return 1 -} - -testRegistrationOffline() { - ${CLI} --verbose dns register --name="testuser" --pem=${TestUser} --value=${REGISTRATION_COST} \ - --nonce=7 --gas-limit=100000000 --gas-price=1000000000 --chain=${CHAIN_ID} \ - --outfile=${SANDBOX}/txRegisterUser.txt || return 1 - assertFileExists ${SANDBOX}/txRegisterUser.txt || return 1 - - ${CLI} --verbose dns register --name="testuser2" --pem=${TestUser2} --value=${REGISTRATION_COST} \ - --nonce=8 --gas-limit=100000000 --gas-price=1000000000 --chain=${CHAIN_ID} \ - --outfile=${SANDBOX}/txRegisterUser2.txt || return 1 - assertFileExists ${SANDBOX}/txRegisterUser2.txt || return 1 -} - -testTransactionsWithUsernamesOffline() { - ${CLI} --verbose tx new --pem=${TestUser} --receiver="erd1ssmsc9022udc8pdw7wk3hxw74jr900xg28vwpz3z60gep66fasasl2nkm4" \ - --value="1${DENOMINATION}" --nonce=42 --gas-limit=50000 --gas-price=2000000000 --chain=${CHAIN_ID} \ - --outfile=${SANDBOX}/txA.txt || return 1 - assertFileExists ${SANDBOX}/txA.txt || return 1 - - ${CLI} --verbose tx new --pem=${TestUser} --receiver="erd1ssmsc9022udc8pdw7wk3hxw74jr900xg28vwpz3z60gep66fasasl2nkm4" --receiver-username="testuser2" \ - --value="1${DENOMINATION}" --nonce=43 --gas-limit=50000 --gas-price=2000000000 --chain=${CHAIN_ID} \ - --outfile=${SANDBOX}/txB.txt || return 1 - assertFileExists ${SANDBOX}/txB.txt || return 1 - - ${CLI} --verbose tx new --pem=${TestUser} --receiver="erd1ssmsc9022udc8pdw7wk3hxw74jr900xg28vwpz3z60gep66fasasl2nkm4" --receiver-username="testuser2foo" \ - --value="1${DENOMINATION}" --nonce=44 --gas-limit=50000 --gas-price=2000000000 --chain=${CHAIN_ID} \ - --outfile=${SANDBOX}/txC.txt || return 1 - assertFileExists ${SANDBOX}/txC.txt || return 1 - - ${CLI} --verbose tx new --pem=${TestUser} --sender-username="testuser" --receiver="erd1ssmsc9022udc8pdw7wk3hxw74jr900xg28vwpz3z60gep66fasasl2nkm4" --receiver-username="testuser2" \ - --value="1${DENOMINATION}" --nonce=45 --gas-limit=50000 --gas-price=2000000000 --chain=${CHAIN_ID} \ - --outfile=${SANDBOX}/txD.txt || return 1 - assertFileExists ${SANDBOX}/txD.txt || return 1 - - ${CLI} --verbose tx new --pem=${TestUser} --sender-username="testuser" --receiver="erd1ssmsc9022udc8pdw7wk3hxw74jr900xg28vwpz3z60gep66fasasl2nkm4" \ - --value="1${DENOMINATION}" --nonce=46 --gas-limit=50000 --gas-price=2000000000 --chain=${CHAIN_ID} \ - --outfile=${SANDBOX}/txF.txt || return 1 - assertFileExists ${SANDBOX}/txF.txt || return 1 - - ${CLI} --verbose tx new --pem=${TestUser} --sender-username="testuserfoo" --receiver="erd1ssmsc9022udc8pdw7wk3hxw74jr900xg28vwpz3z60gep66fasasl2nkm4" \ - --value="1${DENOMINATION}" --nonce=47 --gas-limit=50000 --gas-price=2000000000 --chain=${CHAIN_ID} \ - --outfile=${SANDBOX}/txG.txt || return 1 - assertFileExists ${SANDBOX}/txG.txt || return 1 -} - -testAll() { - testOnline || return 1 - testOffline || return 1 -} diff --git a/multiversx_sdk_cli/tests/test_cli_tx.sh b/multiversx_sdk_cli/tests/test_cli_tx.sh deleted file mode 100644 index 618073bb..00000000 --- a/multiversx_sdk_cli/tests/test_cli_tx.sh +++ /dev/null @@ -1,29 +0,0 @@ -#!/usr/bin/env bash - -source "./shared.sh" - -BOB="erd1cux02zersde0l7hhklzhywcxk4u9n4py5tdxyx7vrvhnza2r4gmq4vw35r" - -testAll() { - cleanSandbox || return 1 - - echo "tx new, don't --send" - ${CLI} --verbose tx new --pem="${USERS}/alice.pem" --receiver=${BOB} --proxy=${PROXY} --value="1${DENOMINATION}" --recall-nonce --data="foo" --gas-limit=70000 --chain=${CHAIN_ID} --outfile=${SANDBOX}/txA.txt || return 1 - echo "tx send" - ${CLI} --verbose tx send --infile=${SANDBOX}/txA.txt --proxy=${PROXY} || return 1 - echo "tx new --send" - ${CLI} --verbose tx new --pem="${USERS}/bob.pem" --receiver=${BOB} --value="1${DENOMINATION}" --recall-nonce --data="foo" --gas-limit=60000 --chain=${CHAIN_ID} --send --outfile=${SANDBOX}/txB.txt --proxy=${PROXY} || return 1 - echo "tx new with --data-file" - echo '"{hello world!}"' > ${SANDBOX}/dummy.txt - ${CLI} --verbose tx new --pem="${USERS}/carol.pem" --receiver=${BOB} --value="1${DENOMINATION}" --recall-nonce --data-file=${SANDBOX}/dummy.txt --gas-limit=70000 --chain=${CHAIN_ID} --proxy=${PROXY} || return 1 - - echo "tx new --relay" - ${CLI} --verbose tx new --pem="${USERS}/dan.pem" --receiver=${BOB} --proxy=${PROXY} --value="1${DENOMINATION}" --nonce=1 --data="foo" --gas-limit=70000 --chain=${CHAIN_ID} --outfile=${SANDBOX}/txInner.txt --relay || return 1 - ${CLI} --verbose tx new --pem="${USERS}/eve.pem" --receiver=${BOB} --proxy=${PROXY} --value="1${DENOMINATION}" --recall-nonce --data-file=${SANDBOX}/txInner.txt --gas-limit=200000 --chain=${CHAIN_ID} --outfile=${SANDBOX}/txWrapper.txt || return 1 - - echo "tx new --simulate" - ${CLI} --verbose tx new --simulate --pem="${USERS}/frank.pem" --receiver=${BOB} --value="1${DENOMINATION}" --recall-nonce --data="foo" --gas-limit=70000 --chain=${CHAIN_ID} --proxy=${PROXY} || return 1 - - echo "tx new --send --wait-result" - ${CLI} --verbose tx new --send --wait-result --pem="${USERS}/grace.pem" --receiver=${BOB} --value="1${DENOMINATION}" --recall-nonce --data="foo" --gas-limit=70000 --chain=${CHAIN_ID} --proxy=${PROXY} || return 1 -} diff --git a/multiversx_sdk_cli/tests/test_cli_validators.sh b/multiversx_sdk_cli/tests/test_cli_validators.sh deleted file mode 100755 index d489c9c0..00000000 --- a/multiversx_sdk_cli/tests/test_cli_validators.sh +++ /dev/null @@ -1,44 +0,0 @@ -#!/usr/bin/env bash - -source "./shared.sh" - -testAll() { - BLS_KEY="e7beaa95b3877f47348df4dd1cb578a4f7cabf7a20bfeefe5cdd263878ff132b765e04fef6f40c93512b666c47ed7719b8902f6c922c04247989b7137e837cc81a62e54712471c97a2ddab75aa9c2f58f813ed4c0fa722bde0ab718bff382208" - REWARD_ADDRESS="erd1k2s324ww2g0yj38qn2ch2jwctdy8mnfxep94q9arncc6xecg3xaq6mjse8" - - echo "Stake with recall nonce" - ${CLI} --verbose validator stake --pem="${USERS}/alice.pem" --value="2500${DENOMINATION}" --validators-file=./testdata/validators.json --reward-address=${REWARD_ADDRESS} --chain=${CHAIN_ID} --proxy=${PROXY} --estimate-gas --recall-nonce || return 1 - echo "Stake with provided nonce" - ${CLI} --verbose validator stake --pem="${USERS}/bob.pem" --value="2500${DENOMINATION}" --validators-file=./testdata/validators.json --reward-address=${REWARD_ADDRESS} --chain=${CHAIN_ID} --proxy=${PROXY} --estimate-gas --nonce=300 || return 1 - - - echo "Stake with topUP" - ${CLI} --verbose validator stake --top-up --pem="${USERS}/carol.pem" --value="2711${DENOMINATION}" --chain=${CHAIN_ID} --proxy=${PROXY} --estimate-gas --recall-nonce || return 1 - - echo "Unstake" - ${CLI} --verbose validator unstake --pem="${USERS}/dan.pem" --nodes-public-keys="${BLS_KEY}" --chain=${CHAIN_ID} --proxy=${PROXY} --estimate-gas --recall-nonce || return 1 - echo "Unbond" - ${CLI} --verbose validator unbond --pem="${USERS}/eve.pem" --nodes-public-keys=${BLS_KEY} --chain=${CHAIN_ID} --proxy=${PROXY} --estimate-gas --recall-nonce || return 1 - echo "Unjail" - ${CLI} --verbose validator unjail --pem="${USERS}/frank.pem" --value="2500${DENOMINATION}" --nodes-public-keys=${BLS_KEY} --chain=${CHAIN_ID} --proxy=${PROXY} --estimate-gas --recall-nonce || return 1 - echo "Change reward address" - ${CLI} --verbose validator change-reward-address --pem="${USERS}/grace.pem" --reward-address=${REWARD_ADDRESS} --chain=${CHAIN_ID} --proxy=${PROXY} --estimate-gas --recall-nonce || return 1 - - echo "UnstakeNodes" - ${CLI} --verbose validator unstake-nodes --pem="${USERS}/heidi.pem" --nodes-public-keys=${BLS_KEY} --chain=${CHAIN_ID} --proxy=${PROXY} --estimate-gas --recall-nonce || return 1 - - echo "UnstakeTokens" - ${CLI} --verbose validator unstake-tokens --pem="${USERS}/ivan.pem" --unstake-value="11${DENOMINATION}" --chain=${CHAIN_ID} --proxy=${PROXY} --estimate-gas --recall-nonce || return 1 - - echo "UnbondNodes" - ${CLI} --verbose validator unbond-nodes --pem="${USERS}/judy.pem" --nodes-public-keys=${BLS_KEY} --chain=${CHAIN_ID} --proxy=${PROXY} --estimate-gas --recall-nonce || return 1 - - echo "UnbondTokens" - ${CLI} --verbose validator unbond-tokens --pem="${USERS}/mallory.pem" --unbond-value="20${DENOMINATION}" --chain=${CHAIN_ID} --proxy=${PROXY} --estimate-gas --recall-nonce || return 1 - - echo "CleanRegistrationData" - ${CLI} --verbose validator clean-registered-data --pem="${USERS}/mike.pem" --chain=${CHAIN_ID} --proxy=${PROXY} --estimate-gas --recall-nonce || return 1 - - echo "ReStakeUnstakedNodes" - ${CLI} --verbose validator restake-unstaked-nodes --pem="${USERS}/alice.pem" --nodes-public-keys=${BLS_KEY} --chain=${CHAIN_ID} --proxy=${PROXY} --estimate-gas --recall-nonce || return 1 -} From 7ab16ba09f8aee9f102d662bed6c2ada3a58b865 Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Wed, 6 Nov 2024 10:26:02 +0200 Subject: [PATCH 76/90] remove cli tests for windows. --- .github/workflows/build-windows.yml | 7 ------- 1 file changed, 7 deletions(-) diff --git a/.github/workflows/build-windows.yml b/.github/workflows/build-windows.yml index df4528a9..b157b6e8 100644 --- a/.github/workflows/build-windows.yml +++ b/.github/workflows/build-windows.yml @@ -48,10 +48,3 @@ jobs: run: | export PYTHONPATH=. pytest -m "not skip_on_windows and not require_localnet" . - - name: Run CLI tests - shell: bash - run: | - export PROXY=https://testnet-gateway.multiversx.com - export CHAIN_ID=T - cd ./multiversx_sdk_cli/tests - testAll || return 1 From ca1d4fd9a178e7076ab19764d1155a4e955d2eda Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Wed, 6 Nov 2024 10:27:22 +0200 Subject: [PATCH 77/90] remove deleted shell scripts. --- multiversx_sdk_cli/tests/test_cli_all.sh | 3 +++ 1 file changed, 3 insertions(+) mode change 100644 => 100755 multiversx_sdk_cli/tests/test_cli_all.sh diff --git a/multiversx_sdk_cli/tests/test_cli_all.sh b/multiversx_sdk_cli/tests/test_cli_all.sh old mode 100644 new mode 100755 index 95cd2418..cd49eb4a --- a/multiversx_sdk_cli/tests/test_cli_all.sh +++ b/multiversx_sdk_cli/tests/test_cli_all.sh @@ -3,6 +3,9 @@ SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" USE_PROXY=$1 +source ./shared.sh +source ./test_cli_validators.sh && testAll + testAll() { pushd $SCRIPT_DIR source ./shared.sh From 8d2ee9a5a8c81667795df652ec446c31207efec1 Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Tue, 19 Nov 2024 07:10:59 +0200 Subject: [PATCH 78/90] removed unnecessary shell scripts. --- multiversx_sdk_cli/tests/test_cli_all.sh | 17 ----------------- multiversx_sdk_cli/tests/test_cli_config.sh | 14 -------------- 2 files changed, 31 deletions(-) delete mode 100755 multiversx_sdk_cli/tests/test_cli_all.sh delete mode 100644 multiversx_sdk_cli/tests/test_cli_config.sh diff --git a/multiversx_sdk_cli/tests/test_cli_all.sh b/multiversx_sdk_cli/tests/test_cli_all.sh deleted file mode 100755 index cd49eb4a..00000000 --- a/multiversx_sdk_cli/tests/test_cli_all.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env bash - -SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" -USE_PROXY=$1 - -source ./shared.sh -source ./test_cli_validators.sh && testAll - -testAll() { - pushd $SCRIPT_DIR - source ./shared.sh - - if [ -n "$USE_PROXY" ]; then - source ./test_cli_config.sh && testAll - fi - popd -} diff --git a/multiversx_sdk_cli/tests/test_cli_config.sh b/multiversx_sdk_cli/tests/test_cli_config.sh deleted file mode 100644 index d6609f52..00000000 --- a/multiversx_sdk_cli/tests/test_cli_config.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/usr/bin/env bash - -source "./shared.sh" - -testAll() { - set -x - - ${CLI} --verbose config set proxy "https://testnet-api.multiversx.com" - ${CLI} --verbose config get proxy - ${CLI} --verbose config set txVersion 1 - ${CLI} --verbose config get txVersion - - set +x -} From a3e08cef30206acdcfb03543f7ac7eb50d4ff104 Mon Sep 17 00:00:00 2001 From: Alexandru Popenta Date: Fri, 22 Nov 2024 16:17:58 +0200 Subject: [PATCH 79/90] relayed v3 implementation --- multiversx_sdk_cli/cli_shared.py | 17 +++++- multiversx_sdk_cli/interfaces.py | 2 + .../tests/test_cli_transactions.py | 59 +++++++++++++++++++ multiversx_sdk_cli/transactions.py | 26 ++++++++ pyproject.toml | 4 +- requirements.txt | 2 +- 6 files changed, 106 insertions(+), 4 deletions(-) diff --git a/multiversx_sdk_cli/cli_shared.py b/multiversx_sdk_cli/cli_shared.py index d239de14..ca4e8e3c 100644 --- a/multiversx_sdk_cli/cli_shared.py +++ b/multiversx_sdk_cli/cli_shared.py @@ -68,7 +68,8 @@ def add_tx_args( with_nonce: bool = True, with_receiver: bool = True, with_data: bool = True, - with_estimate_gas: bool = False): + with_estimate_gas: bool = False, + with_relayer_wallet_args: bool = True): if with_nonce: sub.add_argument("--nonce", type=int, required=not ("--recall-nonce" in args), help="# the nonce for the transaction") sub.add_argument("--recall-nonce", action="store_true", default=False, help="⭮ whether to recall the nonce when creating the transaction (default: %(default)s)") @@ -90,6 +91,10 @@ def add_tx_args( sub.add_argument("--chain", help="the chain identifier") sub.add_argument("--version", type=int, default=DEFAULT_TX_VERSION, help="the transaction version (default: %(default)s)") + sub.add_argument("--relayer", help="the bech32 address of the relayer") + if with_relayer_wallet_args: + add_relayed_v3_wallet_args(args, sub) + add_guardian_args(sub) sub.add_argument("--options", type=int, default=0, help="the transaction options (default: 0)") @@ -122,6 +127,16 @@ def add_guardian_wallet_args(args: List[str], sub: Any): sub.add_argument("--guardian-ledger-address-index", type=int, default=0, help="🔐 the index of the address when using Ledger") +def add_relayed_v3_wallet_args(args: List[str], sub: Any): + sub.add_argument("--relayer-pem", required=check_if_sign_method_required(args, "--relayer-pem"), help="🔑 the PEM file, if keyfile not provided") + sub.add_argument("--relayer-pem-index", type=int, default=0, help="🔑 the index in the PEM file (default: %(default)s)") + sub.add_argument("--relayer-keyfile", required=check_if_sign_method_required(args, "--relayer-keyfile"), help="🔑 a JSON keyfile, if PEM not provided") + sub.add_argument("--relayer-passfile", help="🔑 a file containing keyfile's password, if keyfile provided") + sub.add_argument("--relayer-ledger", action="store_true", required=check_if_sign_method_required(args, "--relayer-ledger"), default=False, help="🔐 bool flag for signing transaction using ledger") + sub.add_argument("--relayer-ledger-account-index", type=int, default=0, help="🔐 the index of the account when using Ledger") + sub.add_argument("--relayer-ledger-address-index", type=int, default=0, help="🔐 the index of the address when using Ledger") + + def add_proxy_arg(sub: Any): sub.add_argument("--proxy", help="🔗 the URL of the proxy") diff --git a/multiversx_sdk_cli/interfaces.py b/multiversx_sdk_cli/interfaces.py index e59c3c8f..469047a0 100644 --- a/multiversx_sdk_cli/interfaces.py +++ b/multiversx_sdk_cli/interfaces.py @@ -25,6 +25,8 @@ class ITransaction(Protocol): guardian: str signature: bytes guardian_signature: bytes + relayer: str + relayer_signature: bytes class IAccount(Protocol): diff --git a/multiversx_sdk_cli/tests/test_cli_transactions.py b/multiversx_sdk_cli/tests/test_cli_transactions.py index dea29655..6509b7db 100644 --- a/multiversx_sdk_cli/tests/test_cli_transactions.py +++ b/multiversx_sdk_cli/tests/test_cli_transactions.py @@ -2,6 +2,8 @@ from pathlib import Path from typing import Any +import pytest + from multiversx_sdk_cli.cli import main testdata_path = Path(__file__).parent / "testdata" @@ -105,5 +107,62 @@ def test_create_multi_transfer_transaction_with_single_egld_transfer(capsys: Any assert data == "MultiESDTNFTTransfer@8049d639e5a6980d1cd2392abcce41029cda74a1563523a202f09641cc2618f8@01@45474c442d303030303030@@0de0b6b3a7640000" +def test_create_relayed_v3_transaction(capsys: Any): + return_code = main([ + "tx", "new", + "--pem", str(testdata_path / "alice.pem"), + "--receiver", "erd1spyavw0956vq68xj8y4tenjpq2wd5a9p2c6j8gsz7ztyrnpxrruqzu66jx", + "--nonce", "7", + "--gas-limit", "1300000", + "--value", "1000000000000000000", + "--chain", "T", + "--relayer", "erd1cqqxak4wun7508e0yj9ng843r6hv4mzd0hhpjpsejkpn9wa9yq8sj7u2u5", + "--relayer-pem", str(testdata_path / "testUser.pem") + ]) + assert return_code == 0 + + tx = _read_stdout(capsys) + tx_json = json.loads(tx)["emittedTransaction"] + assert tx_json["sender"] == "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th" + assert tx_json["receiver"] == "erd1spyavw0956vq68xj8y4tenjpq2wd5a9p2c6j8gsz7ztyrnpxrruqzu66jx" + assert tx_json["relayer"] == "erd1cqqxak4wun7508e0yj9ng843r6hv4mzd0hhpjpsejkpn9wa9yq8sj7u2u5" + assert tx_json["signature"] + assert tx_json["relayerSignature"] + + # no relayer wallet provided + return_code = main([ + "tx", "new", + "--pem", str(testdata_path / "alice.pem"), + "--receiver", "erd1spyavw0956vq68xj8y4tenjpq2wd5a9p2c6j8gsz7ztyrnpxrruqzu66jx", + "--nonce", "7", + "--gas-limit", "1300000", + "--value", "1000000000000000000", + "--chain", "T", + "--relayer", "erd1cqqxak4wun7508e0yj9ng843r6hv4mzd0hhpjpsejkpn9wa9yq8sj7u2u5" + ]) + assert return_code == 0 + tx = _read_stdout(capsys) + tx_json = json.loads(tx)["emittedTransaction"] + assert tx_json["sender"] == "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th" + assert tx_json["receiver"] == "erd1spyavw0956vq68xj8y4tenjpq2wd5a9p2c6j8gsz7ztyrnpxrruqzu66jx" + assert tx_json["relayer"] == "erd1cqqxak4wun7508e0yj9ng843r6hv4mzd0hhpjpsejkpn9wa9yq8sj7u2u5" + assert tx_json["signature"] + assert not tx_json["relayerSignature"] + + # incorrect relayer wallet + with pytest.raises(Exception, match="Relayer address does not match the provided relayer wallet."): + main([ + "tx", "new", + "--pem", str(testdata_path / "alice.pem"), + "--receiver", "erd1spyavw0956vq68xj8y4tenjpq2wd5a9p2c6j8gsz7ztyrnpxrruqzu66jx", + "--nonce", "7", + "--gas-limit", "1300000", + "--value", "1000000000000000000", + "--chain", "T", + "--relayer", "erd1cqqxak4wun7508e0yj9ng843r6hv4mzd0hhpjpsejkpn9wa9yq8sj7u2u5", + "--relayer-pem", str(testdata_path / "alice.pem") + ]) + + def _read_stdout(capsys: Any) -> str: return capsys.readouterr().out.strip() diff --git a/multiversx_sdk_cli/transactions.py b/multiversx_sdk_cli/transactions.py index 41937a50..b1ae6a42 100644 --- a/multiversx_sdk_cli/transactions.py +++ b/multiversx_sdk_cli/transactions.py @@ -78,6 +78,18 @@ def do_prepare_transaction(args: Any) -> Transaction: if args.guardian: tx.guardian = args.guardian + if args.relayer: + tx.relayer = args.relayer + + try: + relayer_account = load_relayer_account_from_args(args) + if relayer_account.address.to_bech32() != tx.relayer: + raise Exception("Relayer address does not match the provided relayer wallet.") + + tx.relayer_signature = bytes.fromhex(relayer_account.sign_transaction(tx)) + except errors.NoWalletProvided: + logger.warning("Relayer wallet not provided. Transaction will not be signed by relayer.") + tx.signature = bytes.fromhex(account.sign_transaction(tx)) tx = sign_tx_by_guardian(args, tx) @@ -97,6 +109,20 @@ def load_sender_account_from_args(args: Any) -> Account: return account +def load_relayer_account_from_args(args: Any) -> Account: + if args.relayer_ledger: + account = LedgerAccount(account_index=args.relayer_ledger_account_index, address_index=args.relayer_ledger_address_index) + if args.relayer_pem: + account = Account(pem_file=args.relayer_pem, pem_index=args.relayer_pem_index) + elif args.relayer_keyfile: + password = load_password(args) + account = Account(key_file=args.relayer_keyfile, password=password) + else: + raise errors.NoWalletProvided() + + return account + + def prepare_token_transfers(transfers: List[Any]) -> List[TokenTransfer]: token_computer = TokenComputer() token_transfers: List[TokenTransfer] = [] diff --git a/pyproject.toml b/pyproject.toml index aa46997b..e21a5e6d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "hatchling.build" [project] name = "multiversx-sdk-cli" -version = "9.8.1" +version = "9.9.0" authors = [ { name="MultiversX" }, ] @@ -28,7 +28,7 @@ dependencies = [ "requests-cache", "rich==13.3.4", "argcomplete==3.2.2", - "multiversx-sdk==0.16.3" + "multiversx-sdk==0.17.0" ] [project.scripts] diff --git a/requirements.txt b/requirements.txt index 46320488..6ddbda18 100644 --- a/requirements.txt +++ b/requirements.txt @@ -10,4 +10,4 @@ requests-cache rich==13.3.4 argcomplete==3.2.2 -multiversx-sdk==0.16.3 +multiversx-sdk==0.17.0 From ccfb060c3842bcd074d723af0dc6ffd3f6bce1ff Mon Sep 17 00:00:00 2001 From: Alexandru Popenta Date: Mon, 25 Nov 2024 12:51:15 +0200 Subject: [PATCH 80/90] relay previously saved transaction --- multiversx_sdk_cli/cli_shared.py | 21 ++++- multiversx_sdk_cli/cli_transactions.py | 33 ++++++- multiversx_sdk_cli/errors.py | 5 + .../tests/test_cli_transactions.py | 93 ++++++++++++++----- multiversx_sdk_cli/transactions.py | 8 +- 5 files changed, 131 insertions(+), 29 deletions(-) diff --git a/multiversx_sdk_cli/cli_shared.py b/multiversx_sdk_cli/cli_shared.py index ca4e8e3c..5ce01dde 100644 --- a/multiversx_sdk_cli/cli_shared.py +++ b/multiversx_sdk_cli/cli_shared.py @@ -127,12 +127,13 @@ def add_guardian_wallet_args(args: List[str], sub: Any): sub.add_argument("--guardian-ledger-address-index", type=int, default=0, help="🔐 the index of the address when using Ledger") +# Required check not properly working, same for guardian. Will be refactored in the future. def add_relayed_v3_wallet_args(args: List[str], sub: Any): - sub.add_argument("--relayer-pem", required=check_if_sign_method_required(args, "--relayer-pem"), help="🔑 the PEM file, if keyfile not provided") + sub.add_argument("--relayer-pem", help="🔑 the PEM file, if keyfile not provided") sub.add_argument("--relayer-pem-index", type=int, default=0, help="🔑 the index in the PEM file (default: %(default)s)") - sub.add_argument("--relayer-keyfile", required=check_if_sign_method_required(args, "--relayer-keyfile"), help="🔑 a JSON keyfile, if PEM not provided") + sub.add_argument("--relayer-keyfile", help="🔑 a JSON keyfile, if PEM not provided") sub.add_argument("--relayer-passfile", help="🔑 a file containing keyfile's password, if keyfile provided") - sub.add_argument("--relayer-ledger", action="store_true", required=check_if_sign_method_required(args, "--relayer-ledger"), default=False, help="🔐 bool flag for signing transaction using ledger") + sub.add_argument("--relayer-ledger", action="store_true", default=False, help="🔐 bool flag for signing transaction using ledger") sub.add_argument("--relayer-ledger-account-index", type=int, default=0, help="🔐 the index of the account when using Ledger") sub.add_argument("--relayer-ledger-address-index", type=int, default=0, help="🔐 the index of the address when using Ledger") @@ -181,6 +182,20 @@ def prepare_account(args: Any): return account +def prepare_relayer_account(args: Any) -> Account: + if args.relayer_ledger: + account = LedgerAccount(account_index=args.relayer_ledger_account_index, address_index=args.relayer_ledger_address_index) + if args.relayer_pem: + account = Account(pem_file=args.relayer_pem, pem_index=args.relayer_pem_index) + elif args.relayer_keyfile: + password = load_password(args) + account = Account(key_file=args.relayer_keyfile, password=password) + else: + raise errors.NoWalletProvided() + + return account + + def prepare_guardian_account(args: Any): if args.guardian_pem: account = Account(pem_file=args.guardian_pem, pem_index=args.guardian_pem_index) diff --git a/multiversx_sdk_cli/cli_transactions.py b/multiversx_sdk_cli/cli_transactions.py index d8a8ae1d..b9dc2bd6 100644 --- a/multiversx_sdk_cli/cli_transactions.py +++ b/multiversx_sdk_cli/cli_transactions.py @@ -8,7 +8,7 @@ from multiversx_sdk_cli.cli_output import CLIOutputBuilder from multiversx_sdk_cli.config import get_config_for_network_providers from multiversx_sdk_cli.cosign_transaction import cosign_transaction -from multiversx_sdk_cli.errors import NoWalletProvided +from multiversx_sdk_cli.errors import IncorrectWalletError, NoWalletProvided from multiversx_sdk_cli.transactions import (compute_relayed_v1_data, do_prepare_transaction, load_transaction_from_file) @@ -57,6 +57,14 @@ def setup_parser(args: List[str], subparsers: Any) -> Any: cli_shared.add_guardian_wallet_args(args, sub) sub.set_defaults(func=sign_transaction) + sub = cli_shared.add_command_subparser(subparsers, "tx", "relay", f"Relay a previously saved transaction.{CLIOutputBuilder.describe()}") + cli_shared.add_relayed_v3_wallet_args(args, sub) + cli_shared.add_infile_arg(sub, what="a previously saved transaction") + cli_shared.add_outfile_arg(sub, what="the signed transaction") + cli_shared.add_broadcast_args(sub) + cli_shared.add_proxy_arg(sub) + sub.set_defaults(func=relay_transaction) + parser.epilog = cli_shared.build_group_epilog(subparsers) return subparsers @@ -141,3 +149,26 @@ def sign_transaction(args: Any): tx = cosign_transaction(tx, args.guardian_service_url, args.guardian_2fa_code) cli_shared.send_or_simulate(tx, args) + + +def relay_transaction(args: Any): + args = utils.as_object(args) + + if not _is_relayer_wallet_provided(args): + raise NoWalletProvided() + + cli_shared.check_broadcast_args(args) + + tx = load_transaction_from_file(args.infile) + relayer = cli_shared.prepare_relayer_account(args) + + if tx.relayer != relayer.address.to_bech32(): + raise IncorrectWalletError("Relayer wallet does not match the relayer's address set in the transaction.") + + tx.relayer_signature = bytes.fromhex(relayer.sign_transaction(tx)) + + cli_shared.send_or_simulate(tx, args) + + +def _is_relayer_wallet_provided(args: Any): + return any([args.relayer_pem, args.relayer_keyfile, args.relayer_ledger]) diff --git a/multiversx_sdk_cli/errors.py b/multiversx_sdk_cli/errors.py index b5cb32b4..2164ad6d 100644 --- a/multiversx_sdk_cli/errors.py +++ b/multiversx_sdk_cli/errors.py @@ -182,3 +182,8 @@ def __init__(self, message: str, inner: Any = None): class NativeAuthClientError(KnownError): def __init__(self, message: str): super().__init__(message) + + +class IncorrectWalletError(KnownError): + def __init__(self, message: str): + super().__init__(message) diff --git a/multiversx_sdk_cli/tests/test_cli_transactions.py b/multiversx_sdk_cli/tests/test_cli_transactions.py index 6509b7db..b7bcd4a3 100644 --- a/multiversx_sdk_cli/tests/test_cli_transactions.py +++ b/multiversx_sdk_cli/tests/test_cli_transactions.py @@ -2,8 +2,6 @@ from pathlib import Path from typing import Any -import pytest - from multiversx_sdk_cli.cli import main testdata_path = Path(__file__).parent / "testdata" @@ -107,7 +105,46 @@ def test_create_multi_transfer_transaction_with_single_egld_transfer(capsys: Any assert data == "MultiESDTNFTTransfer@8049d639e5a6980d1cd2392abcce41029cda74a1563523a202f09641cc2618f8@01@45474c442d303030303030@@0de0b6b3a7640000" +def test_relayed_v3_without_relayer_wallet(capsys: Any): + return_code = main([ + "tx", "new", + "--pem", str(testdata_path / "alice.pem"), + "--receiver", "erd1spyavw0956vq68xj8y4tenjpq2wd5a9p2c6j8gsz7ztyrnpxrruqzu66jx", + "--nonce", "7", + "--gas-limit", "1300000", + "--value", "1000000000000000000", + "--chain", "T", + "--relayer", "erd1cqqxak4wun7508e0yj9ng843r6hv4mzd0hhpjpsejkpn9wa9yq8sj7u2u5" + ]) + assert return_code == 0 + tx = _read_stdout(capsys) + tx_json = json.loads(tx)["emittedTransaction"] + assert tx_json["sender"] == "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th" + assert tx_json["receiver"] == "erd1spyavw0956vq68xj8y4tenjpq2wd5a9p2c6j8gsz7ztyrnpxrruqzu66jx" + assert tx_json["relayer"] == "erd1cqqxak4wun7508e0yj9ng843r6hv4mzd0hhpjpsejkpn9wa9yq8sj7u2u5" + assert tx_json["signature"] + assert not tx_json["relayerSignature"] + + +def test_relayed_v3_incorrect_relayer(): + return_code = main([ + "tx", "new", + "--pem", str(testdata_path / "alice.pem"), + "--receiver", "erd1spyavw0956vq68xj8y4tenjpq2wd5a9p2c6j8gsz7ztyrnpxrruqzu66jx", + "--nonce", "7", + "--gas-limit", "1300000", + "--value", "1000000000000000000", + "--chain", "T", + "--relayer", "erd1cqqxak4wun7508e0yj9ng843r6hv4mzd0hhpjpsejkpn9wa9yq8sj7u2u5", + "--relayer-pem", str(testdata_path / "alice.pem") + ]) + assert return_code + + def test_create_relayed_v3_transaction(capsys: Any): + # create relayed v3 tx and save signature and relayer signature + # create the same tx, save to file + # sign from file with relayer wallet and make sure signatures match return_code = main([ "tx", "new", "--pem", str(testdata_path / "alice.pem"), @@ -129,7 +166,13 @@ def test_create_relayed_v3_transaction(capsys: Any): assert tx_json["signature"] assert tx_json["relayerSignature"] - # no relayer wallet provided + initial_sender_signature = tx_json["signature"] + initial_relayer_signature = tx_json["relayerSignature"] + + # Clear the captured content + capsys.readouterr() + + # save tx to file then load and sign tx by relayer return_code = main([ "tx", "new", "--pem", str(testdata_path / "alice.pem"), @@ -138,30 +181,36 @@ def test_create_relayed_v3_transaction(capsys: Any): "--gas-limit", "1300000", "--value", "1000000000000000000", "--chain", "T", - "--relayer", "erd1cqqxak4wun7508e0yj9ng843r6hv4mzd0hhpjpsejkpn9wa9yq8sj7u2u5" + "--relayer", "erd1cqqxak4wun7508e0yj9ng843r6hv4mzd0hhpjpsejkpn9wa9yq8sj7u2u5", + "--outfile", str(testdata_out / "relayed.json") + ]) + assert return_code == 0 + + # Clear the captured content + capsys.readouterr() + + return_code = main([ + "tx", "relay", + "--relayer-pem", str(testdata_path / "testUser.pem"), + "--infile", str(testdata_out / "relayed.json") ]) assert return_code == 0 + tx = _read_stdout(capsys) tx_json = json.loads(tx)["emittedTransaction"] - assert tx_json["sender"] == "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th" - assert tx_json["receiver"] == "erd1spyavw0956vq68xj8y4tenjpq2wd5a9p2c6j8gsz7ztyrnpxrruqzu66jx" - assert tx_json["relayer"] == "erd1cqqxak4wun7508e0yj9ng843r6hv4mzd0hhpjpsejkpn9wa9yq8sj7u2u5" - assert tx_json["signature"] - assert not tx_json["relayerSignature"] + assert tx_json["signature"] == initial_sender_signature + assert tx_json["relayerSignature"] == initial_relayer_signature + + # Clear the captured content + capsys.readouterr() - # incorrect relayer wallet - with pytest.raises(Exception, match="Relayer address does not match the provided relayer wallet."): - main([ - "tx", "new", - "--pem", str(testdata_path / "alice.pem"), - "--receiver", "erd1spyavw0956vq68xj8y4tenjpq2wd5a9p2c6j8gsz7ztyrnpxrruqzu66jx", - "--nonce", "7", - "--gas-limit", "1300000", - "--value", "1000000000000000000", - "--chain", "T", - "--relayer", "erd1cqqxak4wun7508e0yj9ng843r6hv4mzd0hhpjpsejkpn9wa9yq8sj7u2u5", - "--relayer-pem", str(testdata_path / "alice.pem") - ]) + +def test_check_relayer_wallet_is_provided(): + return_code = main([ + "tx", "relay", + "--infile", str(testdata_out / "relayed.json") + ]) + assert return_code def _read_stdout(capsys: Any) -> str: diff --git a/multiversx_sdk_cli/transactions.py b/multiversx_sdk_cli/transactions.py index b1ae6a42..96536228 100644 --- a/multiversx_sdk_cli/transactions.py +++ b/multiversx_sdk_cli/transactions.py @@ -14,7 +14,7 @@ from multiversx_sdk_cli.cli_password import (load_guardian_password, load_password) from multiversx_sdk_cli.cosign_transaction import cosign_transaction -from multiversx_sdk_cli.errors import NoWalletProvided +from multiversx_sdk_cli.errors import IncorrectWalletError, NoWalletProvided from multiversx_sdk_cli.interfaces import ITransaction from multiversx_sdk_cli.ledger.ledger_functions import do_get_ledger_address @@ -84,11 +84,13 @@ def do_prepare_transaction(args: Any) -> Transaction: try: relayer_account = load_relayer_account_from_args(args) if relayer_account.address.to_bech32() != tx.relayer: - raise Exception("Relayer address does not match the provided relayer wallet.") + raise IncorrectWalletError("") tx.relayer_signature = bytes.fromhex(relayer_account.sign_transaction(tx)) - except errors.NoWalletProvided: + except NoWalletProvided: logger.warning("Relayer wallet not provided. Transaction will not be signed by relayer.") + except IncorrectWalletError: + raise IncorrectWalletError("Relayer wallet does not match the relayer's address set in the transaction.") tx.signature = bytes.fromhex(account.sign_transaction(tx)) tx = sign_tx_by_guardian(args, tx) From b6751a351743248b6d1ccd6c8facc531d7471b39 Mon Sep 17 00:00:00 2001 From: Alexandru Popenta Date: Mon, 25 Nov 2024 12:53:22 +0200 Subject: [PATCH 81/90] regenerate CLI.md file --- CLI.md | 357 +++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 223 insertions(+), 134 deletions(-) diff --git a/CLI.md b/CLI.md index 3cf655de..fc9f0c77 100644 --- a/CLI.md +++ b/CLI.md @@ -218,15 +218,19 @@ options: --value VALUE the value to transfer (default: 0) --chain CHAIN the chain identifier --version VERSION the transaction version (default: 2) + --relayer RELAYER the bech32 address of the relayer + --relayer-pem RELAYER_PEM 🔑 the PEM file, if keyfile not provided + --relayer-pem-index RELAYER_PEM_INDEX 🔑 the index in the PEM file (default: 0) + --relayer-keyfile RELAYER_KEYFILE 🔑 a JSON keyfile, if PEM not provided + --relayer-passfile RELAYER_PASSFILE 🔑 a file containing keyfile's password, if keyfile provided + --relayer-ledger 🔐 bool flag for signing transaction using ledger + --relayer-ledger-account-index RELAYER_LEDGER_ACCOUNT_INDEX + 🔐 the index of the account when using Ledger + --relayer-ledger-address-index RELAYER_LEDGER_ADDRESS_INDEX + 🔐 the index of the address when using Ledger --guardian GUARDIAN the address of the guradian --guardian-service-url GUARDIAN_SERVICE_URL the url of the guardian service --guardian-2fa-code GUARDIAN_2FA_CODE the 2fa code for the guardian - --relayer RELAYER the address of the relayer - --inner-transactions INNER_TRANSACTIONS a json file containing the inner transactions; should only be provided - when creating the relayer's transaction - --inner-transactions-outfile INNER_TRANSACTIONS_OUTFILE - where to save the transaction as an inner transaction (default: - stdout) --options OPTIONS the transaction options (default: 0) --arguments ARGUMENTS [ARGUMENTS ...] arguments for the contract transaction, as [number, bech32-address, ascii string, boolean] or hex-encoded. E.g. --arguments 42 0x64 1000 @@ -311,15 +315,19 @@ options: --value VALUE the value to transfer (default: 0) --chain CHAIN the chain identifier --version VERSION the transaction version (default: 2) + --relayer RELAYER the bech32 address of the relayer + --relayer-pem RELAYER_PEM 🔑 the PEM file, if keyfile not provided + --relayer-pem-index RELAYER_PEM_INDEX 🔑 the index in the PEM file (default: 0) + --relayer-keyfile RELAYER_KEYFILE 🔑 a JSON keyfile, if PEM not provided + --relayer-passfile RELAYER_PASSFILE 🔑 a file containing keyfile's password, if keyfile provided + --relayer-ledger 🔐 bool flag for signing transaction using ledger + --relayer-ledger-account-index RELAYER_LEDGER_ACCOUNT_INDEX + 🔐 the index of the account when using Ledger + --relayer-ledger-address-index RELAYER_LEDGER_ADDRESS_INDEX + 🔐 the index of the address when using Ledger --guardian GUARDIAN the address of the guradian --guardian-service-url GUARDIAN_SERVICE_URL the url of the guardian service --guardian-2fa-code GUARDIAN_2FA_CODE the 2fa code for the guardian - --relayer RELAYER the address of the relayer - --inner-transactions INNER_TRANSACTIONS a json file containing the inner transactions; should only be provided - when creating the relayer's transaction - --inner-transactions-outfile INNER_TRANSACTIONS_OUTFILE - where to save the transaction as an inner transaction (default: - stdout) --options OPTIONS the transaction options (default: 0) --function FUNCTION the function to call --arguments ARGUMENTS [ARGUMENTS ...] arguments for the contract transaction, as [number, bech32-address, @@ -414,15 +422,19 @@ options: --value VALUE the value to transfer (default: 0) --chain CHAIN the chain identifier --version VERSION the transaction version (default: 2) + --relayer RELAYER the bech32 address of the relayer + --relayer-pem RELAYER_PEM 🔑 the PEM file, if keyfile not provided + --relayer-pem-index RELAYER_PEM_INDEX 🔑 the index in the PEM file (default: 0) + --relayer-keyfile RELAYER_KEYFILE 🔑 a JSON keyfile, if PEM not provided + --relayer-passfile RELAYER_PASSFILE 🔑 a file containing keyfile's password, if keyfile provided + --relayer-ledger 🔐 bool flag for signing transaction using ledger + --relayer-ledger-account-index RELAYER_LEDGER_ACCOUNT_INDEX + 🔐 the index of the account when using Ledger + --relayer-ledger-address-index RELAYER_LEDGER_ADDRESS_INDEX + 🔐 the index of the address when using Ledger --guardian GUARDIAN the address of the guradian --guardian-service-url GUARDIAN_SERVICE_URL the url of the guardian service --guardian-2fa-code GUARDIAN_2FA_CODE the 2fa code for the guardian - --relayer RELAYER the address of the relayer - --inner-transactions INNER_TRANSACTIONS a json file containing the inner transactions; should only be provided - when creating the relayer's transaction - --inner-transactions-outfile INNER_TRANSACTIONS_OUTFILE - where to save the transaction as an inner transaction (default: - stdout) --options OPTIONS the transaction options (default: 0) --arguments ARGUMENTS [ARGUMENTS ...] arguments for the contract transaction, as [number, bech32-address, ascii string, boolean] or hex-encoded. E.g. --arguments 42 0x64 1000 @@ -520,10 +532,10 @@ usage: mxpy tx COMMAND [-h] ... Create and broadcast Transactions COMMANDS: - {new,send,get,sign} + {new,send,get,sign,relay} OPTIONS: - -h, --help show this help message and exit + -h, --help show this help message and exit ---------------- COMMANDS summary @@ -532,6 +544,7 @@ new Create a new transaction. send Send a previously saved transaction. get Get a transaction. sign Sign a previously saved transaction. +relay Relay a previously saved transaction. ``` ### Transactions.New @@ -577,15 +590,19 @@ options: --data DATA the payload, or 'memo' of the transaction (default: ) --chain CHAIN the chain identifier --version VERSION the transaction version (default: 2) + --relayer RELAYER the bech32 address of the relayer + --relayer-pem RELAYER_PEM 🔑 the PEM file, if keyfile not provided + --relayer-pem-index RELAYER_PEM_INDEX 🔑 the index in the PEM file (default: 0) + --relayer-keyfile RELAYER_KEYFILE 🔑 a JSON keyfile, if PEM not provided + --relayer-passfile RELAYER_PASSFILE 🔑 a file containing keyfile's password, if keyfile provided + --relayer-ledger 🔐 bool flag for signing transaction using ledger + --relayer-ledger-account-index RELAYER_LEDGER_ACCOUNT_INDEX + 🔐 the index of the account when using Ledger + --relayer-ledger-address-index RELAYER_LEDGER_ADDRESS_INDEX + 🔐 the index of the address when using Ledger --guardian GUARDIAN the address of the guradian --guardian-service-url GUARDIAN_SERVICE_URL the url of the guardian service --guardian-2fa-code GUARDIAN_2FA_CODE the 2fa code for the guardian - --relayer RELAYER the address of the relayer - --inner-transactions INNER_TRANSACTIONS a json file containing the inner transactions; should only be provided - when creating the relayer's transaction - --inner-transactions-outfile INNER_TRANSACTIONS_OUTFILE - where to save the transaction as an inner transaction (default: - stdout) --options OPTIONS the transaction options (default: 0) --data-file DATA_FILE a file containing transaction data --token-transfers TOKEN_TRANSFERS [TOKEN_TRANSFERS ...] @@ -730,15 +747,19 @@ options: --value VALUE the value to transfer (default: 0) --chain CHAIN the chain identifier --version VERSION the transaction version (default: 2) + --relayer RELAYER the bech32 address of the relayer + --relayer-pem RELAYER_PEM 🔑 the PEM file, if keyfile not provided + --relayer-pem-index RELAYER_PEM_INDEX 🔑 the index in the PEM file (default: 0) + --relayer-keyfile RELAYER_KEYFILE 🔑 a JSON keyfile, if PEM not provided + --relayer-passfile RELAYER_PASSFILE 🔑 a file containing keyfile's password, if keyfile provided + --relayer-ledger 🔐 bool flag for signing transaction using ledger + --relayer-ledger-account-index RELAYER_LEDGER_ACCOUNT_INDEX + 🔐 the index of the account when using Ledger + --relayer-ledger-address-index RELAYER_LEDGER_ADDRESS_INDEX + 🔐 the index of the address when using Ledger --guardian GUARDIAN the address of the guradian --guardian-service-url GUARDIAN_SERVICE_URL the url of the guardian service --guardian-2fa-code GUARDIAN_2FA_CODE the 2fa code for the guardian - --relayer RELAYER the address of the relayer - --inner-transactions INNER_TRANSACTIONS a json file containing the inner transactions; should only be provided - when creating the relayer's transaction - --inner-transactions-outfile INNER_TRANSACTIONS_OUTFILE - where to save the transaction as an inner transaction (default: - stdout) --options OPTIONS the transaction options (default: 0) --send ✓ whether to broadcast the transaction (default: False) --simulate whether to simulate the transaction (default: False) @@ -786,15 +807,19 @@ options: --value VALUE the value to transfer (default: 0) --chain CHAIN the chain identifier --version VERSION the transaction version (default: 2) + --relayer RELAYER the bech32 address of the relayer + --relayer-pem RELAYER_PEM 🔑 the PEM file, if keyfile not provided + --relayer-pem-index RELAYER_PEM_INDEX 🔑 the index in the PEM file (default: 0) + --relayer-keyfile RELAYER_KEYFILE 🔑 a JSON keyfile, if PEM not provided + --relayer-passfile RELAYER_PASSFILE 🔑 a file containing keyfile's password, if keyfile provided + --relayer-ledger 🔐 bool flag for signing transaction using ledger + --relayer-ledger-account-index RELAYER_LEDGER_ACCOUNT_INDEX + 🔐 the index of the account when using Ledger + --relayer-ledger-address-index RELAYER_LEDGER_ADDRESS_INDEX + 🔐 the index of the address when using Ledger --guardian GUARDIAN the address of the guradian --guardian-service-url GUARDIAN_SERVICE_URL the url of the guardian service --guardian-2fa-code GUARDIAN_2FA_CODE the 2fa code for the guardian - --relayer RELAYER the address of the relayer - --inner-transactions INNER_TRANSACTIONS a json file containing the inner transactions; should only be provided - when creating the relayer's transaction - --inner-transactions-outfile INNER_TRANSACTIONS_OUTFILE - where to save the transaction as an inner transaction (default: - stdout) --options OPTIONS the transaction options (default: 0) --send ✓ whether to broadcast the transaction (default: False) --simulate whether to simulate the transaction (default: False) @@ -840,15 +865,19 @@ options: --value VALUE the value to transfer (default: 0) --chain CHAIN the chain identifier --version VERSION the transaction version (default: 2) + --relayer RELAYER the bech32 address of the relayer + --relayer-pem RELAYER_PEM 🔑 the PEM file, if keyfile not provided + --relayer-pem-index RELAYER_PEM_INDEX 🔑 the index in the PEM file (default: 0) + --relayer-keyfile RELAYER_KEYFILE 🔑 a JSON keyfile, if PEM not provided + --relayer-passfile RELAYER_PASSFILE 🔑 a file containing keyfile's password, if keyfile provided + --relayer-ledger 🔐 bool flag for signing transaction using ledger + --relayer-ledger-account-index RELAYER_LEDGER_ACCOUNT_INDEX + 🔐 the index of the account when using Ledger + --relayer-ledger-address-index RELAYER_LEDGER_ADDRESS_INDEX + 🔐 the index of the address when using Ledger --guardian GUARDIAN the address of the guradian --guardian-service-url GUARDIAN_SERVICE_URL the url of the guardian service --guardian-2fa-code GUARDIAN_2FA_CODE the 2fa code for the guardian - --relayer RELAYER the address of the relayer - --inner-transactions INNER_TRANSACTIONS a json file containing the inner transactions; should only be provided - when creating the relayer's transaction - --inner-transactions-outfile INNER_TRANSACTIONS_OUTFILE - where to save the transaction as an inner transaction (default: - stdout) --options OPTIONS the transaction options (default: 0) --send ✓ whether to broadcast the transaction (default: False) --simulate whether to simulate the transaction (default: False) @@ -894,15 +923,19 @@ options: --value VALUE the value to transfer (default: 0) --chain CHAIN the chain identifier --version VERSION the transaction version (default: 2) + --relayer RELAYER the bech32 address of the relayer + --relayer-pem RELAYER_PEM 🔑 the PEM file, if keyfile not provided + --relayer-pem-index RELAYER_PEM_INDEX 🔑 the index in the PEM file (default: 0) + --relayer-keyfile RELAYER_KEYFILE 🔑 a JSON keyfile, if PEM not provided + --relayer-passfile RELAYER_PASSFILE 🔑 a file containing keyfile's password, if keyfile provided + --relayer-ledger 🔐 bool flag for signing transaction using ledger + --relayer-ledger-account-index RELAYER_LEDGER_ACCOUNT_INDEX + 🔐 the index of the account when using Ledger + --relayer-ledger-address-index RELAYER_LEDGER_ADDRESS_INDEX + 🔐 the index of the address when using Ledger --guardian GUARDIAN the address of the guradian --guardian-service-url GUARDIAN_SERVICE_URL the url of the guardian service --guardian-2fa-code GUARDIAN_2FA_CODE the 2fa code for the guardian - --relayer RELAYER the address of the relayer - --inner-transactions INNER_TRANSACTIONS a json file containing the inner transactions; should only be provided - when creating the relayer's transaction - --inner-transactions-outfile INNER_TRANSACTIONS_OUTFILE - where to save the transaction as an inner transaction (default: - stdout) --options OPTIONS the transaction options (default: 0) --send ✓ whether to broadcast the transaction (default: False) --simulate whether to simulate the transaction (default: False) @@ -948,15 +981,19 @@ options: --value VALUE the value to transfer (default: 0) --chain CHAIN the chain identifier --version VERSION the transaction version (default: 2) + --relayer RELAYER the bech32 address of the relayer + --relayer-pem RELAYER_PEM 🔑 the PEM file, if keyfile not provided + --relayer-pem-index RELAYER_PEM_INDEX 🔑 the index in the PEM file (default: 0) + --relayer-keyfile RELAYER_KEYFILE 🔑 a JSON keyfile, if PEM not provided + --relayer-passfile RELAYER_PASSFILE 🔑 a file containing keyfile's password, if keyfile provided + --relayer-ledger 🔐 bool flag for signing transaction using ledger + --relayer-ledger-account-index RELAYER_LEDGER_ACCOUNT_INDEX + 🔐 the index of the account when using Ledger + --relayer-ledger-address-index RELAYER_LEDGER_ADDRESS_INDEX + 🔐 the index of the address when using Ledger --guardian GUARDIAN the address of the guradian --guardian-service-url GUARDIAN_SERVICE_URL the url of the guardian service --guardian-2fa-code GUARDIAN_2FA_CODE the 2fa code for the guardian - --relayer RELAYER the address of the relayer - --inner-transactions INNER_TRANSACTIONS a json file containing the inner transactions; should only be provided - when creating the relayer's transaction - --inner-transactions-outfile INNER_TRANSACTIONS_OUTFILE - where to save the transaction as an inner transaction (default: - stdout) --options OPTIONS the transaction options (default: 0) --send ✓ whether to broadcast the transaction (default: False) --simulate whether to simulate the transaction (default: False) @@ -1002,15 +1039,19 @@ options: --value VALUE the value to transfer (default: 0) --chain CHAIN the chain identifier --version VERSION the transaction version (default: 2) + --relayer RELAYER the bech32 address of the relayer + --relayer-pem RELAYER_PEM 🔑 the PEM file, if keyfile not provided + --relayer-pem-index RELAYER_PEM_INDEX 🔑 the index in the PEM file (default: 0) + --relayer-keyfile RELAYER_KEYFILE 🔑 a JSON keyfile, if PEM not provided + --relayer-passfile RELAYER_PASSFILE 🔑 a file containing keyfile's password, if keyfile provided + --relayer-ledger 🔐 bool flag for signing transaction using ledger + --relayer-ledger-account-index RELAYER_LEDGER_ACCOUNT_INDEX + 🔐 the index of the account when using Ledger + --relayer-ledger-address-index RELAYER_LEDGER_ADDRESS_INDEX + 🔐 the index of the address when using Ledger --guardian GUARDIAN the address of the guradian --guardian-service-url GUARDIAN_SERVICE_URL the url of the guardian service --guardian-2fa-code GUARDIAN_2FA_CODE the 2fa code for the guardian - --relayer RELAYER the address of the relayer - --inner-transactions INNER_TRANSACTIONS a json file containing the inner transactions; should only be provided - when creating the relayer's transaction - --inner-transactions-outfile INNER_TRANSACTIONS_OUTFILE - where to save the transaction as an inner transaction (default: - stdout) --options OPTIONS the transaction options (default: 0) --send ✓ whether to broadcast the transaction (default: False) --simulate whether to simulate the transaction (default: False) @@ -1094,15 +1135,19 @@ options: --value VALUE the value to transfer (default: 0) --chain CHAIN the chain identifier --version VERSION the transaction version (default: 2) + --relayer RELAYER the bech32 address of the relayer + --relayer-pem RELAYER_PEM 🔑 the PEM file, if keyfile not provided + --relayer-pem-index RELAYER_PEM_INDEX 🔑 the index in the PEM file (default: 0) + --relayer-keyfile RELAYER_KEYFILE 🔑 a JSON keyfile, if PEM not provided + --relayer-passfile RELAYER_PASSFILE 🔑 a file containing keyfile's password, if keyfile provided + --relayer-ledger 🔐 bool flag for signing transaction using ledger + --relayer-ledger-account-index RELAYER_LEDGER_ACCOUNT_INDEX + 🔐 the index of the account when using Ledger + --relayer-ledger-address-index RELAYER_LEDGER_ADDRESS_INDEX + 🔐 the index of the address when using Ledger --guardian GUARDIAN the address of the guradian --guardian-service-url GUARDIAN_SERVICE_URL the url of the guardian service --guardian-2fa-code GUARDIAN_2FA_CODE the 2fa code for the guardian - --relayer RELAYER the address of the relayer - --inner-transactions INNER_TRANSACTIONS a json file containing the inner transactions; should only be provided - when creating the relayer's transaction - --inner-transactions-outfile INNER_TRANSACTIONS_OUTFILE - where to save the transaction as an inner transaction (default: - stdout) --options OPTIONS the transaction options (default: 0) --send ✓ whether to broadcast the transaction (default: False) --simulate whether to simulate the transaction (default: False) @@ -1167,15 +1212,19 @@ options: --value VALUE the value to transfer (default: 0) --chain CHAIN the chain identifier --version VERSION the transaction version (default: 2) + --relayer RELAYER the bech32 address of the relayer + --relayer-pem RELAYER_PEM 🔑 the PEM file, if keyfile not provided + --relayer-pem-index RELAYER_PEM_INDEX 🔑 the index in the PEM file (default: 0) + --relayer-keyfile RELAYER_KEYFILE 🔑 a JSON keyfile, if PEM not provided + --relayer-passfile RELAYER_PASSFILE 🔑 a file containing keyfile's password, if keyfile provided + --relayer-ledger 🔐 bool flag for signing transaction using ledger + --relayer-ledger-account-index RELAYER_LEDGER_ACCOUNT_INDEX + 🔐 the index of the account when using Ledger + --relayer-ledger-address-index RELAYER_LEDGER_ADDRESS_INDEX + 🔐 the index of the address when using Ledger --guardian GUARDIAN the address of the guradian --guardian-service-url GUARDIAN_SERVICE_URL the url of the guardian service --guardian-2fa-code GUARDIAN_2FA_CODE the 2fa code for the guardian - --relayer RELAYER the address of the relayer - --inner-transactions INNER_TRANSACTIONS a json file containing the inner transactions; should only be provided - when creating the relayer's transaction - --inner-transactions-outfile INNER_TRANSACTIONS_OUTFILE - where to save the transaction as an inner transaction (default: - stdout) --options OPTIONS the transaction options (default: 0) --send ✓ whether to broadcast the transaction (default: False) --simulate whether to simulate the transaction (default: False) @@ -1223,15 +1272,19 @@ options: --value VALUE the value to transfer (default: 0) --chain CHAIN the chain identifier --version VERSION the transaction version (default: 2) + --relayer RELAYER the bech32 address of the relayer + --relayer-pem RELAYER_PEM 🔑 the PEM file, if keyfile not provided + --relayer-pem-index RELAYER_PEM_INDEX 🔑 the index in the PEM file (default: 0) + --relayer-keyfile RELAYER_KEYFILE 🔑 a JSON keyfile, if PEM not provided + --relayer-passfile RELAYER_PASSFILE 🔑 a file containing keyfile's password, if keyfile provided + --relayer-ledger 🔐 bool flag for signing transaction using ledger + --relayer-ledger-account-index RELAYER_LEDGER_ACCOUNT_INDEX + 🔐 the index of the account when using Ledger + --relayer-ledger-address-index RELAYER_LEDGER_ADDRESS_INDEX + 🔐 the index of the address when using Ledger --guardian GUARDIAN the address of the guradian --guardian-service-url GUARDIAN_SERVICE_URL the url of the guardian service --guardian-2fa-code GUARDIAN_2FA_CODE the 2fa code for the guardian - --relayer RELAYER the address of the relayer - --inner-transactions INNER_TRANSACTIONS a json file containing the inner transactions; should only be provided - when creating the relayer's transaction - --inner-transactions-outfile INNER_TRANSACTIONS_OUTFILE - where to save the transaction as an inner transaction (default: - stdout) --options OPTIONS the transaction options (default: 0) --send ✓ whether to broadcast the transaction (default: False) --simulate whether to simulate the transaction (default: False) @@ -1279,15 +1332,19 @@ options: --value VALUE the value to transfer (default: 0) --chain CHAIN the chain identifier --version VERSION the transaction version (default: 2) + --relayer RELAYER the bech32 address of the relayer + --relayer-pem RELAYER_PEM 🔑 the PEM file, if keyfile not provided + --relayer-pem-index RELAYER_PEM_INDEX 🔑 the index in the PEM file (default: 0) + --relayer-keyfile RELAYER_KEYFILE 🔑 a JSON keyfile, if PEM not provided + --relayer-passfile RELAYER_PASSFILE 🔑 a file containing keyfile's password, if keyfile provided + --relayer-ledger 🔐 bool flag for signing transaction using ledger + --relayer-ledger-account-index RELAYER_LEDGER_ACCOUNT_INDEX + 🔐 the index of the account when using Ledger + --relayer-ledger-address-index RELAYER_LEDGER_ADDRESS_INDEX + 🔐 the index of the address when using Ledger --guardian GUARDIAN the address of the guradian --guardian-service-url GUARDIAN_SERVICE_URL the url of the guardian service --guardian-2fa-code GUARDIAN_2FA_CODE the 2fa code for the guardian - --relayer RELAYER the address of the relayer - --inner-transactions INNER_TRANSACTIONS a json file containing the inner transactions; should only be provided - when creating the relayer's transaction - --inner-transactions-outfile INNER_TRANSACTIONS_OUTFILE - where to save the transaction as an inner transaction (default: - stdout) --options OPTIONS the transaction options (default: 0) --send ✓ whether to broadcast the transaction (default: False) --simulate whether to simulate the transaction (default: False) @@ -1335,15 +1392,19 @@ options: --value VALUE the value to transfer (default: 0) --chain CHAIN the chain identifier --version VERSION the transaction version (default: 2) + --relayer RELAYER the bech32 address of the relayer + --relayer-pem RELAYER_PEM 🔑 the PEM file, if keyfile not provided + --relayer-pem-index RELAYER_PEM_INDEX 🔑 the index in the PEM file (default: 0) + --relayer-keyfile RELAYER_KEYFILE 🔑 a JSON keyfile, if PEM not provided + --relayer-passfile RELAYER_PASSFILE 🔑 a file containing keyfile's password, if keyfile provided + --relayer-ledger 🔐 bool flag for signing transaction using ledger + --relayer-ledger-account-index RELAYER_LEDGER_ACCOUNT_INDEX + 🔐 the index of the account when using Ledger + --relayer-ledger-address-index RELAYER_LEDGER_ADDRESS_INDEX + 🔐 the index of the address when using Ledger --guardian GUARDIAN the address of the guradian --guardian-service-url GUARDIAN_SERVICE_URL the url of the guardian service --guardian-2fa-code GUARDIAN_2FA_CODE the 2fa code for the guardian - --relayer RELAYER the address of the relayer - --inner-transactions INNER_TRANSACTIONS a json file containing the inner transactions; should only be provided - when creating the relayer's transaction - --inner-transactions-outfile INNER_TRANSACTIONS_OUTFILE - where to save the transaction as an inner transaction (default: - stdout) --options OPTIONS the transaction options (default: 0) --send ✓ whether to broadcast the transaction (default: False) --simulate whether to simulate the transaction (default: False) @@ -1391,15 +1452,19 @@ options: --value VALUE the value to transfer (default: 0) --chain CHAIN the chain identifier --version VERSION the transaction version (default: 2) + --relayer RELAYER the bech32 address of the relayer + --relayer-pem RELAYER_PEM 🔑 the PEM file, if keyfile not provided + --relayer-pem-index RELAYER_PEM_INDEX 🔑 the index in the PEM file (default: 0) + --relayer-keyfile RELAYER_KEYFILE 🔑 a JSON keyfile, if PEM not provided + --relayer-passfile RELAYER_PASSFILE 🔑 a file containing keyfile's password, if keyfile provided + --relayer-ledger 🔐 bool flag for signing transaction using ledger + --relayer-ledger-account-index RELAYER_LEDGER_ACCOUNT_INDEX + 🔐 the index of the account when using Ledger + --relayer-ledger-address-index RELAYER_LEDGER_ADDRESS_INDEX + 🔐 the index of the address when using Ledger --guardian GUARDIAN the address of the guradian --guardian-service-url GUARDIAN_SERVICE_URL the url of the guardian service --guardian-2fa-code GUARDIAN_2FA_CODE the 2fa code for the guardian - --relayer RELAYER the address of the relayer - --inner-transactions INNER_TRANSACTIONS a json file containing the inner transactions; should only be provided - when creating the relayer's transaction - --inner-transactions-outfile INNER_TRANSACTIONS_OUTFILE - where to save the transaction as an inner transaction (default: - stdout) --options OPTIONS the transaction options (default: 0) --send ✓ whether to broadcast the transaction (default: False) --simulate whether to simulate the transaction (default: False) @@ -1447,15 +1512,19 @@ options: --value VALUE the value to transfer (default: 0) --chain CHAIN the chain identifier --version VERSION the transaction version (default: 2) + --relayer RELAYER the bech32 address of the relayer + --relayer-pem RELAYER_PEM 🔑 the PEM file, if keyfile not provided + --relayer-pem-index RELAYER_PEM_INDEX 🔑 the index in the PEM file (default: 0) + --relayer-keyfile RELAYER_KEYFILE 🔑 a JSON keyfile, if PEM not provided + --relayer-passfile RELAYER_PASSFILE 🔑 a file containing keyfile's password, if keyfile provided + --relayer-ledger 🔐 bool flag for signing transaction using ledger + --relayer-ledger-account-index RELAYER_LEDGER_ACCOUNT_INDEX + 🔐 the index of the account when using Ledger + --relayer-ledger-address-index RELAYER_LEDGER_ADDRESS_INDEX + 🔐 the index of the address when using Ledger --guardian GUARDIAN the address of the guradian --guardian-service-url GUARDIAN_SERVICE_URL the url of the guardian service --guardian-2fa-code GUARDIAN_2FA_CODE the 2fa code for the guardian - --relayer RELAYER the address of the relayer - --inner-transactions INNER_TRANSACTIONS a json file containing the inner transactions; should only be provided - when creating the relayer's transaction - --inner-transactions-outfile INNER_TRANSACTIONS_OUTFILE - where to save the transaction as an inner transaction (default: - stdout) --options OPTIONS the transaction options (default: 0) --send ✓ whether to broadcast the transaction (default: False) --simulate whether to simulate the transaction (default: False) @@ -1502,15 +1571,19 @@ options: --value VALUE the value to transfer (default: 0) --chain CHAIN the chain identifier --version VERSION the transaction version (default: 2) + --relayer RELAYER the bech32 address of the relayer + --relayer-pem RELAYER_PEM 🔑 the PEM file, if keyfile not provided + --relayer-pem-index RELAYER_PEM_INDEX 🔑 the index in the PEM file (default: 0) + --relayer-keyfile RELAYER_KEYFILE 🔑 a JSON keyfile, if PEM not provided + --relayer-passfile RELAYER_PASSFILE 🔑 a file containing keyfile's password, if keyfile provided + --relayer-ledger 🔐 bool flag for signing transaction using ledger + --relayer-ledger-account-index RELAYER_LEDGER_ACCOUNT_INDEX + 🔐 the index of the account when using Ledger + --relayer-ledger-address-index RELAYER_LEDGER_ADDRESS_INDEX + 🔐 the index of the address when using Ledger --guardian GUARDIAN the address of the guradian --guardian-service-url GUARDIAN_SERVICE_URL the url of the guardian service --guardian-2fa-code GUARDIAN_2FA_CODE the 2fa code for the guardian - --relayer RELAYER the address of the relayer - --inner-transactions INNER_TRANSACTIONS a json file containing the inner transactions; should only be provided - when creating the relayer's transaction - --inner-transactions-outfile INNER_TRANSACTIONS_OUTFILE - where to save the transaction as an inner transaction (default: - stdout) --options OPTIONS the transaction options (default: 0) --send ✓ whether to broadcast the transaction (default: False) --simulate whether to simulate the transaction (default: False) @@ -1557,15 +1630,19 @@ options: --value VALUE the value to transfer (default: 0) --chain CHAIN the chain identifier --version VERSION the transaction version (default: 2) + --relayer RELAYER the bech32 address of the relayer + --relayer-pem RELAYER_PEM 🔑 the PEM file, if keyfile not provided + --relayer-pem-index RELAYER_PEM_INDEX 🔑 the index in the PEM file (default: 0) + --relayer-keyfile RELAYER_KEYFILE 🔑 a JSON keyfile, if PEM not provided + --relayer-passfile RELAYER_PASSFILE 🔑 a file containing keyfile's password, if keyfile provided + --relayer-ledger 🔐 bool flag for signing transaction using ledger + --relayer-ledger-account-index RELAYER_LEDGER_ACCOUNT_INDEX + 🔐 the index of the account when using Ledger + --relayer-ledger-address-index RELAYER_LEDGER_ADDRESS_INDEX + 🔐 the index of the address when using Ledger --guardian GUARDIAN the address of the guradian --guardian-service-url GUARDIAN_SERVICE_URL the url of the guardian service --guardian-2fa-code GUARDIAN_2FA_CODE the 2fa code for the guardian - --relayer RELAYER the address of the relayer - --inner-transactions INNER_TRANSACTIONS a json file containing the inner transactions; should only be provided - when creating the relayer's transaction - --inner-transactions-outfile INNER_TRANSACTIONS_OUTFILE - where to save the transaction as an inner transaction (default: - stdout) --options OPTIONS the transaction options (default: 0) --send ✓ whether to broadcast the transaction (default: False) --simulate whether to simulate the transaction (default: False) @@ -1613,15 +1690,19 @@ options: --value VALUE the value to transfer (default: 0) --chain CHAIN the chain identifier --version VERSION the transaction version (default: 2) + --relayer RELAYER the bech32 address of the relayer + --relayer-pem RELAYER_PEM 🔑 the PEM file, if keyfile not provided + --relayer-pem-index RELAYER_PEM_INDEX 🔑 the index in the PEM file (default: 0) + --relayer-keyfile RELAYER_KEYFILE 🔑 a JSON keyfile, if PEM not provided + --relayer-passfile RELAYER_PASSFILE 🔑 a file containing keyfile's password, if keyfile provided + --relayer-ledger 🔐 bool flag for signing transaction using ledger + --relayer-ledger-account-index RELAYER_LEDGER_ACCOUNT_INDEX + 🔐 the index of the account when using Ledger + --relayer-ledger-address-index RELAYER_LEDGER_ADDRESS_INDEX + 🔐 the index of the address when using Ledger --guardian GUARDIAN the address of the guradian --guardian-service-url GUARDIAN_SERVICE_URL the url of the guardian service --guardian-2fa-code GUARDIAN_2FA_CODE the 2fa code for the guardian - --relayer RELAYER the address of the relayer - --inner-transactions INNER_TRANSACTIONS a json file containing the inner transactions; should only be provided - when creating the relayer's transaction - --inner-transactions-outfile INNER_TRANSACTIONS_OUTFILE - where to save the transaction as an inner transaction (default: - stdout) --options OPTIONS the transaction options (default: 0) --send ✓ whether to broadcast the transaction (default: False) --simulate whether to simulate the transaction (default: False) @@ -1669,15 +1750,19 @@ options: --value VALUE the value to transfer (default: 0) --chain CHAIN the chain identifier --version VERSION the transaction version (default: 2) + --relayer RELAYER the bech32 address of the relayer + --relayer-pem RELAYER_PEM 🔑 the PEM file, if keyfile not provided + --relayer-pem-index RELAYER_PEM_INDEX 🔑 the index in the PEM file (default: 0) + --relayer-keyfile RELAYER_KEYFILE 🔑 a JSON keyfile, if PEM not provided + --relayer-passfile RELAYER_PASSFILE 🔑 a file containing keyfile's password, if keyfile provided + --relayer-ledger 🔐 bool flag for signing transaction using ledger + --relayer-ledger-account-index RELAYER_LEDGER_ACCOUNT_INDEX + 🔐 the index of the account when using Ledger + --relayer-ledger-address-index RELAYER_LEDGER_ADDRESS_INDEX + 🔐 the index of the address when using Ledger --guardian GUARDIAN the address of the guradian --guardian-service-url GUARDIAN_SERVICE_URL the url of the guardian service --guardian-2fa-code GUARDIAN_2FA_CODE the 2fa code for the guardian - --relayer RELAYER the address of the relayer - --inner-transactions INNER_TRANSACTIONS a json file containing the inner transactions; should only be provided - when creating the relayer's transaction - --inner-transactions-outfile INNER_TRANSACTIONS_OUTFILE - where to save the transaction as an inner transaction (default: - stdout) --options OPTIONS the transaction options (default: 0) --send ✓ whether to broadcast the transaction (default: False) --simulate whether to simulate the transaction (default: False) @@ -1726,15 +1811,19 @@ options: --value VALUE the value to transfer (default: 0) --chain CHAIN the chain identifier --version VERSION the transaction version (default: 2) + --relayer RELAYER the bech32 address of the relayer + --relayer-pem RELAYER_PEM 🔑 the PEM file, if keyfile not provided + --relayer-pem-index RELAYER_PEM_INDEX 🔑 the index in the PEM file (default: 0) + --relayer-keyfile RELAYER_KEYFILE 🔑 a JSON keyfile, if PEM not provided + --relayer-passfile RELAYER_PASSFILE 🔑 a file containing keyfile's password, if keyfile provided + --relayer-ledger 🔐 bool flag for signing transaction using ledger + --relayer-ledger-account-index RELAYER_LEDGER_ACCOUNT_INDEX + 🔐 the index of the account when using Ledger + --relayer-ledger-address-index RELAYER_LEDGER_ADDRESS_INDEX + 🔐 the index of the address when using Ledger --guardian GUARDIAN the address of the guradian --guardian-service-url GUARDIAN_SERVICE_URL the url of the guardian service --guardian-2fa-code GUARDIAN_2FA_CODE the 2fa code for the guardian - --relayer RELAYER the address of the relayer - --inner-transactions INNER_TRANSACTIONS a json file containing the inner transactions; should only be provided - when creating the relayer's transaction - --inner-transactions-outfile INNER_TRANSACTIONS_OUTFILE - where to save the transaction as an inner transaction (default: - stdout) --options OPTIONS the transaction options (default: 0) --send ✓ whether to broadcast the transaction (default: False) --simulate whether to simulate the transaction (default: False) From 69b652681c3d1439d2b06827bfd10b1619c1a106 Mon Sep 17 00:00:00 2001 From: Alexandru Popenta Date: Fri, 29 Nov 2024 14:56:39 +0200 Subject: [PATCH 82/90] add address hrp as a config entry --- multiversx_sdk_cli/accounts.py | 6 +++--- multiversx_sdk_cli/cli.py | 3 +++ multiversx_sdk_cli/cli_dns.py | 6 +++--- multiversx_sdk_cli/cli_wallet.py | 11 +++++++---- multiversx_sdk_cli/config.py | 5 +++++ multiversx_sdk_cli/constants.py | 3 +-- multiversx_sdk_cli/contracts.py | 6 +++--- multiversx_sdk_cli/dns.py | 9 +++++---- multiversx_sdk_cli/sign_verify.py | 4 ++-- multiversx_sdk_cli/transactions.py | 2 +- pyproject.toml | 4 ++-- requirements.txt | 3 ++- 12 files changed, 37 insertions(+), 25 deletions(-) diff --git a/multiversx_sdk_cli/accounts.py b/multiversx_sdk_cli/accounts.py index 489f03a7..33616067 100644 --- a/multiversx_sdk_cli/accounts.py +++ b/multiversx_sdk_cli/accounts.py @@ -6,7 +6,7 @@ TransactionComputer, UserSigner) from multiversx_sdk.network_providers.accounts import AccountOnNetwork -from multiversx_sdk_cli.constants import DEFAULT_HRP +from multiversx_sdk_cli.config import get_address_hrp from multiversx_sdk_cli.interfaces import IAccount, IAddress, ITransaction from multiversx_sdk_cli.ledger.config import compare_versions from multiversx_sdk_cli.ledger.ledger_app_handler import \ @@ -61,11 +61,11 @@ def __init__(self, if pem_file: pem_path = Path(pem_file).expanduser().resolve() self.signer = UserSigner.from_pem_file(pem_path, pem_index) - self.address = Address(self.signer.get_pubkey().buffer, DEFAULT_HRP) + self.address = Address(self.signer.get_pubkey().buffer, get_address_hrp()) elif key_file and password: key_file_path = Path(key_file).expanduser().resolve() self.signer = UserSigner.from_wallet(key_file_path, password) - self.address = Address(self.signer.get_pubkey().buffer, DEFAULT_HRP) + self.address = Address(self.signer.get_pubkey().buffer, get_address_hrp()) def sign_transaction(self, transaction: ITransaction) -> str: assert self.signer is not None diff --git a/multiversx_sdk_cli/cli.py b/multiversx_sdk_cli/cli.py index 79eacf20..76fe95e1 100644 --- a/multiversx_sdk_cli/cli.py +++ b/multiversx_sdk_cli/cli.py @@ -6,6 +6,7 @@ from typing import Any, List import argcomplete +from multiversx_sdk import LibraryConfig from rich.logging import RichHandler import multiversx_sdk_cli.cli_accounts @@ -53,6 +54,8 @@ def _do_main(cli_args: List[str]): logging.basicConfig(level="INFO", format='%(name)s: %(message)s', handlers=[RichHandler(show_time=False, rich_tracebacks=True)]) verify_deprecated_entries_in_config_file() + default_hrp = config.get_address_hrp() + LibraryConfig.default_address_hrp = default_hrp if not hasattr(args, "func"): parser.print_help() diff --git a/multiversx_sdk_cli/cli_dns.py b/multiversx_sdk_cli/cli_dns.py index 703f29a1..dbbc9c9b 100644 --- a/multiversx_sdk_cli/cli_dns.py +++ b/multiversx_sdk_cli/cli_dns.py @@ -1,11 +1,11 @@ from typing import Any, List -from multiversx_sdk import Address, ProxyNetworkProvider +from multiversx_sdk import ProxyNetworkProvider from prettytable import PrettyTable from multiversx_sdk_cli import cli_shared from multiversx_sdk_cli.config import get_config_for_network_providers -from multiversx_sdk_cli.constants import ADDRESS_ZERO_BECH32 +from multiversx_sdk_cli.constants import ADDRESS_ZERO_HEX from multiversx_sdk_cli.dns import (compute_dns_address_for_shard_id, dns_address_for_name, name_hash, register, registration_cost, resolve, validate_name, @@ -82,7 +82,7 @@ def dns_resolve(args: Any): config = get_config_for_network_providers() addr = resolve(args.name, ProxyNetworkProvider(url=args.proxy, config=config)) - if addr.to_hex() != Address.new_from_bech32(ADDRESS_ZERO_BECH32).to_hex(): + if addr.to_hex() != ADDRESS_ZERO_HEX: print(addr.to_bech32()) diff --git a/multiversx_sdk_cli/cli_wallet.py b/multiversx_sdk_cli/cli_wallet.py index eeae9ebb..18e1625b 100644 --- a/multiversx_sdk_cli/cli_wallet.py +++ b/multiversx_sdk_cli/cli_wallet.py @@ -10,7 +10,8 @@ from multiversx_sdk.core.address import get_shard_of_pubkey from multiversx_sdk_cli import cli_shared, utils -from multiversx_sdk_cli.constants import DEFAULT_HRP, NUMBER_OF_SHARDS +from multiversx_sdk_cli.config import get_address_hrp +from multiversx_sdk_cli.constants import NUMBER_OF_SHARDS from multiversx_sdk_cli.errors import (BadUserInput, KnownError, WalletGenerationError) from multiversx_sdk_cli.sign_verify import SignedMessage, sign_message @@ -54,7 +55,7 @@ def setup_parser(args: List[str], subparsers: Any) -> Any: ) sub.add_argument("--format", choices=WALLET_FORMATS, help="the format of the generated wallet file (default: %(default)s)", default=None) sub.add_argument("--outfile", help="the output path and base file name for the generated wallet files (default: %(default)s)", type=str) - sub.add_argument("--address-hrp", help=f"the human-readable part of the address, when format is {WALLET_FORMAT_KEYSTORE_SECRET_KEY} or {WALLET_FORMAT_PEM} (default: %(default)s)", type=str, default=DEFAULT_HRP) + sub.add_argument("--address-hrp", help=f"the human-readable part of the address, when format is {WALLET_FORMAT_KEYSTORE_SECRET_KEY} or {WALLET_FORMAT_PEM} (default: %(default)s)", type=str, default=get_address_hrp()) sub.add_argument("--shard", type=int, help="the shard in which the address will be generated; (default: random)") sub.set_defaults(func=wallet_new) @@ -69,7 +70,7 @@ def setup_parser(args: List[str], subparsers: Any) -> Any: sub.add_argument("--in-format", required=True, choices=WALLET_FORMATS, help="the format of the input file") sub.add_argument("--out-format", required=True, choices=WALLET_FORMATS_AND_ADDRESSES, help="the format of the output file") sub.add_argument("--address-index", help=f"the address index, if input format is {WALLET_FORMAT_RAW_MNEMONIC}, {WALLET_FORMAT_KEYSTORE_MNEMONIC} or {WALLET_FORMAT_PEM} (with multiple entries) and the output format is {WALLET_FORMAT_KEYSTORE_SECRET_KEY} or {WALLET_FORMAT_PEM}", type=int, default=0) - sub.add_argument("--address-hrp", help=f"the human-readable part of the address, when the output format is {WALLET_FORMAT_KEYSTORE_SECRET_KEY} or {WALLET_FORMAT_PEM} (default: %(default)s)", type=str, default=DEFAULT_HRP) + sub.add_argument("--address-hrp", help=f"the human-readable part of the address, when the output format is {WALLET_FORMAT_KEYSTORE_SECRET_KEY} or {WALLET_FORMAT_PEM} (default: %(default)s)", type=str, default=get_address_hrp()) sub.set_defaults(func=convert_wallet) sub = cli_shared.add_command_subparser( @@ -82,6 +83,7 @@ def setup_parser(args: List[str], subparsers: Any) -> Any: group = sub.add_mutually_exclusive_group(required=True) group.add_argument("--encode", action="store_true", help="whether to encode") group.add_argument("--decode", action="store_true", help="whether to decode") + sub.add_argument("--hrp", type=str, help="the human readable part; only used for encoding to bech32") sub.set_defaults(func=do_bech32) sub = cli_shared.add_command_subparser( @@ -288,7 +290,8 @@ def do_bech32(args: Any): value = args.value if encode: - address = Address.new_from_hex(value, DEFAULT_HRP) + hrp = args.hrp if args.hrp else get_address_hrp() + address = Address.new_from_hex(value, hrp) result = address.to_bech32() else: address = Address.new_from_bech32(value) diff --git a/multiversx_sdk_cli/config.py b/multiversx_sdk_cli/config.py index db067f65..621ab5b1 100644 --- a/multiversx_sdk_cli/config.py +++ b/multiversx_sdk_cli/config.py @@ -60,6 +60,10 @@ def get_value(name: str) -> str: return value +def get_address_hrp(): + return get_value("default_address_hrp") + + def set_value(name: str, value: Any): _guard_valid_name(name) data = read_file() @@ -162,6 +166,7 @@ def get_defaults() -> Dict[str, Any]: "dependencies.testwallets.urlTemplate.windows": "https://github.com/multiversx/mx-sdk-testwallets/archive/{TAG}.tar.gz", "dependencies.wasm-opt.tag": "0.112.0", "github_api_token": "", + "default_address_hrp": "erd" } diff --git a/multiversx_sdk_cli/constants.py b/multiversx_sdk_cli/constants.py index fabd8809..0f0e0dbc 100644 --- a/multiversx_sdk_cli/constants.py +++ b/multiversx_sdk_cli/constants.py @@ -9,7 +9,6 @@ DEFAULT_TX_VERSION = 2 -DEFAULT_HRP = "erd" -ADDRESS_ZERO_BECH32 = "erd1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq6gq4hu" +ADDRESS_ZERO_HEX = "0000000000000000000000000000000000000000000000000000000000000000" NUMBER_OF_SHARDS = 3 diff --git a/multiversx_sdk_cli/contracts.py b/multiversx_sdk_cli/contracts.py index 98885dc4..5f8214b9 100644 --- a/multiversx_sdk_cli/contracts.py +++ b/multiversx_sdk_cli/contracts.py @@ -11,7 +11,7 @@ from multiversx_sdk_cli import errors from multiversx_sdk_cli.accounts import Account -from multiversx_sdk_cli.constants import DEFAULT_HRP +from multiversx_sdk_cli.config import get_address_hrp from multiversx_sdk_cli.interfaces import IAddress logger = logging.getLogger("contracts") @@ -211,7 +211,7 @@ def _prepare_args_for_factory(self, arguments: List[str]) -> List[Any]: args.append(self._hex_to_bytes(arg)) elif arg.isnumeric(): args.append(int(arg)) - elif arg.startswith(DEFAULT_HRP): + elif arg.startswith(get_address_hrp()): args.append(Address.new_from_bech32(arg)) elif arg.lower() == FALSE_STR_LOWER: args.append(False) @@ -253,7 +253,7 @@ def _to_hex(arg: str): if arg.isnumeric(): return _prepare_decimal(arg) - elif arg.startswith(DEFAULT_HRP): + elif arg.startswith(get_address_hrp()): addr = Address.from_bech32(arg) return _prepare_hexadecimal(f"{HEX_PREFIX}{addr.hex()}") elif arg.lower() == FALSE_STR_LOWER or arg.lower() == TRUE_STR_LOWER: diff --git a/multiversx_sdk_cli/dns.py b/multiversx_sdk_cli/dns.py index 114b1a11..61e387c4 100644 --- a/multiversx_sdk_cli/dns.py +++ b/multiversx_sdk_cli/dns.py @@ -6,7 +6,8 @@ from multiversx_sdk_cli import cli_shared, utils from multiversx_sdk_cli.accounts import Account -from multiversx_sdk_cli.constants import ADDRESS_ZERO_BECH32, DEFAULT_HRP +from multiversx_sdk_cli.config import get_address_hrp +from multiversx_sdk_cli.constants import ADDRESS_ZERO_HEX from multiversx_sdk_cli.contracts import SmartContract from multiversx_sdk_cli.transactions import (compute_relayed_v1_data, do_prepare_transaction) @@ -36,10 +37,10 @@ def resolve(name: str, proxy: INetworkProvider) -> Address: ) if len(response) == 0: - return Address.from_bech32(ADDRESS_ZERO_BECH32) + return Address.new_from_hex(ADDRESS_ZERO_HEX, get_address_hrp()) result = response[0].get("returnDataParts")[0] - return Address.from_hex(result, DEFAULT_HRP) + return Address.new_from_hex(result, get_address_hrp()) def validate_name(name: str, shard_id: int, proxy: INetworkProvider): @@ -137,7 +138,7 @@ def compute_dns_address_for_shard_id(shard_id: int) -> Address: deployer_pubkey_prefix = InitialDNSAddress[:len(InitialDNSAddress) - ShardIdentiferLen] deployer_pubkey = deployer_pubkey_prefix + bytes([0, shard_id]) - deployer = Account(address=Address(deployer_pubkey, DEFAULT_HRP)) + deployer = Account(address=Address(deployer_pubkey, get_address_hrp())) deployer.nonce = 0 address_computer = AddressComputer(number_of_shards=3) contract_address = address_computer.compute_contract_address(deployer.address, deployer.nonce) diff --git a/multiversx_sdk_cli/sign_verify.py b/multiversx_sdk_cli/sign_verify.py index 09b45a55..77e4c77e 100644 --- a/multiversx_sdk_cli/sign_verify.py +++ b/multiversx_sdk_cli/sign_verify.py @@ -23,7 +23,7 @@ def verify_signature(self) -> bool: verifiable_message.signature = bytes.fromhex(self.signature) message_computer = MessageComputer() - verifier = UserVerifier.from_address(Address.from_bech32(self.address)) + verifier = UserVerifier.from_address(Address.new_from_bech32(self.address)) is_signed = verifier.verify(message_computer.compute_bytes_for_signing(verifiable_message), verifiable_message.signature) return is_signed @@ -37,4 +37,4 @@ def to_dictionary(self) -> Dict[str, str]: def sign_message(message: str, account: Account) -> SignedMessage: signature = account.sign_message(message.encode()) - return SignedMessage(account.address.bech32(), message, signature) + return SignedMessage(account.address.to_bech32(), message, signature) diff --git a/multiversx_sdk_cli/transactions.py b/multiversx_sdk_cli/transactions.py index 41937a50..91c0ae0a 100644 --- a/multiversx_sdk_cli/transactions.py +++ b/multiversx_sdk_cli/transactions.py @@ -136,7 +136,7 @@ def get_guardian_account_from_args(args: Any): account = Account(key_file=args.guardian_keyfile, password=password) elif args.guardian_ledger: address = do_get_ledger_address(account_index=args.guardian_ledger_account_index, address_index=args.guardian_ledger_address_index) - account = Account(address=Address.from_bech32(address)) + account = Account(address=Address.new_from_bech32(address)) else: raise errors.NoWalletProvided() diff --git a/pyproject.toml b/pyproject.toml index aa46997b..0002f4ee 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "hatchling.build" [project] name = "multiversx-sdk-cli" -version = "9.8.1" +version = "9.9.0" authors = [ { name="MultiversX" }, ] @@ -28,7 +28,7 @@ dependencies = [ "requests-cache", "rich==13.3.4", "argcomplete==3.2.2", - "multiversx-sdk==0.16.3" + "multiversx-sdk==0.19.0" ] [project.scripts] diff --git a/requirements.txt b/requirements.txt index 46320488..feaa5e80 100644 --- a/requirements.txt +++ b/requirements.txt @@ -10,4 +10,5 @@ requests-cache rich==13.3.4 argcomplete==3.2.2 -multiversx-sdk==0.16.3 +# multiversx-sdk==0.19.0 +git+https://github.com/multiversx/mx-sdk-py@main From 7cf6564a520d9000fdac30302034b9602567d72f Mon Sep 17 00:00:00 2001 From: Alexandru Popenta Date: Mon, 2 Dec 2024 10:29:08 +0200 Subject: [PATCH 83/90] reference latest sdk-py --- requirements.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index feaa5e80..0c7334d0 100644 --- a/requirements.txt +++ b/requirements.txt @@ -10,5 +10,4 @@ requests-cache rich==13.3.4 argcomplete==3.2.2 -# multiversx-sdk==0.19.0 -git+https://github.com/multiversx/mx-sdk-py@main +multiversx-sdk==0.19.0 From 0ee90361c0f6918ba27906a66b1996bf54da98d0 Mon Sep 17 00:00:00 2001 From: Alexandru Popenta Date: Mon, 2 Dec 2024 12:04:19 +0200 Subject: [PATCH 84/90] use default value for hrp argument --- multiversx_sdk_cli/cli_wallet.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/multiversx_sdk_cli/cli_wallet.py b/multiversx_sdk_cli/cli_wallet.py index 18e1625b..1f8b2082 100644 --- a/multiversx_sdk_cli/cli_wallet.py +++ b/multiversx_sdk_cli/cli_wallet.py @@ -83,7 +83,7 @@ def setup_parser(args: List[str], subparsers: Any) -> Any: group = sub.add_mutually_exclusive_group(required=True) group.add_argument("--encode", action="store_true", help="whether to encode") group.add_argument("--decode", action="store_true", help="whether to decode") - sub.add_argument("--hrp", type=str, help="the human readable part; only used for encoding to bech32") + sub.add_argument("--hrp", type=str, help="the human readable part; only used for encoding to bech32 (default: %(default)s)", default=get_address_hrp()) sub.set_defaults(func=do_bech32) sub = cli_shared.add_command_subparser( @@ -290,7 +290,7 @@ def do_bech32(args: Any): value = args.value if encode: - hrp = args.hrp if args.hrp else get_address_hrp() + hrp = args.hrp address = Address.new_from_hex(value, hrp) result = address.to_bech32() else: From 32603100b9f90ed709c5c0c01c66a408ddb2be9a Mon Sep 17 00:00:00 2001 From: Alexandru Popenta Date: Tue, 3 Dec 2024 13:32:53 +0200 Subject: [PATCH 85/90] fix hardcoded address to use config hrp --- .../delegation/staking_provider.py | 3 +- multiversx_sdk_cli/validators/core.py | 30 +++++++++---------- pyproject.toml | 2 +- 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/multiversx_sdk_cli/delegation/staking_provider.py b/multiversx_sdk_cli/delegation/staking_provider.py index 418418dc..977e7424 100644 --- a/multiversx_sdk_cli/delegation/staking_provider.py +++ b/multiversx_sdk_cli/delegation/staking_provider.py @@ -5,6 +5,7 @@ Transaction, ValidatorPublicKey) from multiversx_sdk.core.serializer import args_to_string +from multiversx_sdk_cli.config import get_address_hrp from multiversx_sdk_cli.errors import BadUsage from multiversx_sdk_cli.interfaces import IAddress, ITransaction from multiversx_sdk_cli.validators.validators_file import ValidatorsFile @@ -408,7 +409,7 @@ def prepare_transaction_for_setting_metadata(self, owner: IAccount, args: Any) - return tx def prepare_transaction_for_creating_delegation_contract_from_validator(self, owner: IAccount, args: Any) -> ITransaction: - receiver = "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqylllslmq6y6" + receiver = Address.new_from_hex("000000000000000000010000000000000000000000000000000000000004ffff", get_address_hrp()).to_bech32() max_cap = int(args.max_cap) fee = int(args.fee) data = "makeNewContractFromValidatorData@" + args_to_string([max_cap, fee]) diff --git a/multiversx_sdk_cli/validators/core.py b/multiversx_sdk_cli/validators/core.py index 0e6e9f95..f71d64ee 100644 --- a/multiversx_sdk_cli/validators/core.py +++ b/multiversx_sdk_cli/validators/core.py @@ -8,14 +8,14 @@ from multiversx_sdk_cli.accounts import Account from multiversx_sdk_cli.cli_password import load_password from multiversx_sdk_cli.config import (GAS_PER_DATA_BYTE, MIN_GAS_LIMIT, - MetaChainSystemSCsCost) + MetaChainSystemSCsCost, get_address_hrp) from multiversx_sdk_cli.contracts import prepare_execute_transaction_data from multiversx_sdk_cli.errors import BadUsage from multiversx_sdk_cli.validators.validators_file import ValidatorsFile logger = logging.getLogger("validators") -VALIDATORS_SMART_CONTRACT_ADDRESS = "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqplllst77y4l" +VALIDATORS_SMART_CONTRACT_ADDRESS_HEX = "000000000000000000010000000000000000000000000000000000000001ffff" def prepare_args_for_stake(args: Any): @@ -36,7 +36,7 @@ def prepare_args_for_stake(args: Any): data, gas_limit = prepare_transaction_data_for_stake(node_operator.address, validators_file_path, reward_address) args.data = data - args.receiver = VALIDATORS_SMART_CONTRACT_ADDRESS + args.receiver = Address.new_from_hex(VALIDATORS_SMART_CONTRACT_ADDRESS_HEX, get_address_hrp()).to_bech32() if args.estimate_gas: args.gas_limit = gas_limit @@ -74,7 +74,7 @@ def prepare_transaction_data_for_stake(node_operator_address: Address, validator def prepare_args_for_top_up(args: Any): args.data = 'stake' - args.receiver = VALIDATORS_SMART_CONTRACT_ADDRESS + args.receiver = Address.new_from_hex(VALIDATORS_SMART_CONTRACT_ADDRESS_HEX, get_address_hrp()).to_bech32() if args.estimate_gas: args.gas_limit = estimate_system_sc_call(args.data, MetaChainSystemSCsCost.STAKE, 1) @@ -83,7 +83,7 @@ def prepare_args_for_top_up(args: Any): def prepare_args_for_unstake(args: Any): parsed_keys, num_keys = utils.parse_keys(args.nodes_public_keys) args.data = 'unStake' + parsed_keys - args.receiver = VALIDATORS_SMART_CONTRACT_ADDRESS + args.receiver = Address.new_from_hex(VALIDATORS_SMART_CONTRACT_ADDRESS_HEX, get_address_hrp()).to_bech32() if args.estimate_gas: args.gas_limit = estimate_system_sc_call(args.data, MetaChainSystemSCsCost.UNSTAKE, num_keys) @@ -92,7 +92,7 @@ def prepare_args_for_unstake(args: Any): def prepare_args_for_unbond(args: Any): parsed_keys, num_keys = utils.parse_keys(args.nodes_public_keys) args.data = 'unBond' + parsed_keys - args.receiver = VALIDATORS_SMART_CONTRACT_ADDRESS + args.receiver = Address.new_from_hex(VALIDATORS_SMART_CONTRACT_ADDRESS_HEX, get_address_hrp()).to_bech32() if args.estimate_gas: args.gas_limit = estimate_system_sc_call(args.data, MetaChainSystemSCsCost.UNBOND, num_keys) @@ -101,7 +101,7 @@ def prepare_args_for_unbond(args: Any): def prepare_args_for_unjail(args: Any): parsed_keys, num_keys = utils.parse_keys(args.nodes_public_keys) args.data = 'unJail' + parsed_keys - args.receiver = VALIDATORS_SMART_CONTRACT_ADDRESS + args.receiver = Address.new_from_hex(VALIDATORS_SMART_CONTRACT_ADDRESS_HEX, get_address_hrp()).to_bech32() if args.estimate_gas: args.gas_limit = estimate_system_sc_call(args.data, MetaChainSystemSCsCost.UNJAIL, num_keys) @@ -110,7 +110,7 @@ def prepare_args_for_unjail(args: Any): def prepare_args_for_change_reward_address(args: Any): reward_address = Address.new_from_bech32(args.reward_address) args.data = 'changeRewardAddress@' + reward_address.hex() - args.receiver = VALIDATORS_SMART_CONTRACT_ADDRESS + args.receiver = Address.new_from_hex(VALIDATORS_SMART_CONTRACT_ADDRESS_HEX, get_address_hrp()).to_bech32() if args.estimate_gas: args.gas_limit = estimate_system_sc_call(args.data, MetaChainSystemSCsCost.CHANGE_REWARD_ADDRESS) @@ -118,7 +118,7 @@ def prepare_args_for_change_reward_address(args: Any): def prepare_args_for_claim(args: Any): args.data = 'claim' - args.receiver = VALIDATORS_SMART_CONTRACT_ADDRESS + args.receiver = Address.new_from_hex(VALIDATORS_SMART_CONTRACT_ADDRESS_HEX, get_address_hrp()).to_bech32() if args.estimate_gas: args.gas_limit = estimate_system_sc_call(args.data, MetaChainSystemSCsCost.CLAIM) @@ -128,7 +128,7 @@ def prepare_args_for_unstake_nodes(args: Any): parsed_keys, num_keys = utils.parse_keys(args.nodes_public_keys) args.data = 'unStakeNodes' + parsed_keys - args.receiver = VALIDATORS_SMART_CONTRACT_ADDRESS + args.receiver = Address.new_from_hex(VALIDATORS_SMART_CONTRACT_ADDRESS_HEX, get_address_hrp()).to_bech32() if args.estimate_gas: args.gas_limit = estimate_system_sc_call(args.data, MetaChainSystemSCsCost.UNSTAKE, num_keys) @@ -137,7 +137,7 @@ def prepare_args_for_unstake_tokens(args: Any): args.data = 'unStakeTokens' args.data += '@' + utils.str_int_to_hex_str(str(args.unstake_value)) - args.receiver = VALIDATORS_SMART_CONTRACT_ADDRESS + args.receiver = Address.new_from_hex(VALIDATORS_SMART_CONTRACT_ADDRESS_HEX, get_address_hrp()).to_bech32() if args.estimate_gas: args.gas_limit = estimate_system_sc_call(args.data, MetaChainSystemSCsCost.UNSTAKE_TOKENS) @@ -146,7 +146,7 @@ def prepare_args_for_unbond_nodes(args: Any): parsed_keys, num_keys = utils.parse_keys(args.nodes_public_keys) args.data = 'unBondNodes' + parsed_keys - args.receiver = VALIDATORS_SMART_CONTRACT_ADDRESS + args.receiver = Address.new_from_hex(VALIDATORS_SMART_CONTRACT_ADDRESS_HEX, get_address_hrp()).to_bech32() if args.estimate_gas: args.gas_limit = estimate_system_sc_call(args.data, MetaChainSystemSCsCost.UNBOND, num_keys) @@ -155,7 +155,7 @@ def prepare_args_for_unbond_tokens(args: Any): args.data = 'unBondTokens' args.data += '@' + utils.str_int_to_hex_str(str(args.unbond_value)) - args.receiver = VALIDATORS_SMART_CONTRACT_ADDRESS + args.receiver = Address.new_from_hex(VALIDATORS_SMART_CONTRACT_ADDRESS_HEX, get_address_hrp()).to_bech32() if args.estimate_gas: args.gas_limit = estimate_system_sc_call(args.data, MetaChainSystemSCsCost.UNBOND_TOKENS) @@ -163,7 +163,7 @@ def prepare_args_for_unbond_tokens(args: Any): def prepare_args_for_clean_registered_data(args: Any): args.data = 'cleanRegisteredData' - args.receiver = VALIDATORS_SMART_CONTRACT_ADDRESS + args.receiver = Address.new_from_hex(VALIDATORS_SMART_CONTRACT_ADDRESS_HEX, get_address_hrp()).to_bech32() if args.estimate_gas: args.gas_limit = estimate_system_sc_call(args.data, MetaChainSystemSCsCost.STAKE) @@ -172,7 +172,7 @@ def prepare_args_for_restake_unstaked_nodes(args: Any): parsed_keys, num_keys = utils.parse_keys(args.nodes_public_keys) args.data = 'reStakeUnStakedNodes' + parsed_keys - args.receiver = VALIDATORS_SMART_CONTRACT_ADDRESS + args.receiver = Address.new_from_hex(VALIDATORS_SMART_CONTRACT_ADDRESS_HEX, get_address_hrp()).to_bech32() if args.estimate_gas: args.gas_limit = estimate_system_sc_call(args.data, MetaChainSystemSCsCost.STAKE, num_keys) diff --git a/pyproject.toml b/pyproject.toml index 0002f4ee..b6e91c5e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "hatchling.build" [project] name = "multiversx-sdk-cli" -version = "9.9.0" +version = "9.9.1" authors = [ { name="MultiversX" }, ] From 6f0ae29abf6c821f3b884398eca583792530f815 Mon Sep 17 00:00:00 2001 From: Alexandru Popenta Date: Thu, 5 Dec 2024 17:13:22 +0200 Subject: [PATCH 86/90] add more detailed description --- multiversx_sdk_cli/cli_transactions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/multiversx_sdk_cli/cli_transactions.py b/multiversx_sdk_cli/cli_transactions.py index b9dc2bd6..06c7a0b9 100644 --- a/multiversx_sdk_cli/cli_transactions.py +++ b/multiversx_sdk_cli/cli_transactions.py @@ -60,7 +60,7 @@ def setup_parser(args: List[str], subparsers: Any) -> Any: sub = cli_shared.add_command_subparser(subparsers, "tx", "relay", f"Relay a previously saved transaction.{CLIOutputBuilder.describe()}") cli_shared.add_relayed_v3_wallet_args(args, sub) cli_shared.add_infile_arg(sub, what="a previously saved transaction") - cli_shared.add_outfile_arg(sub, what="the signed transaction") + cli_shared.add_outfile_arg(sub, what="the relayer signed transaction") cli_shared.add_broadcast_args(sub) cli_shared.add_proxy_arg(sub) sub.set_defaults(func=relay_transaction) From 6f6c04225161e0f243eb9b1e0c1d70fb2d84704d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrei=20B=C4=83ncioiu?= Date: Fri, 20 Dec 2024 15:42:27 +0200 Subject: [PATCH 87/90] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 881b9041..89d55637 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ Python Command Line Tools for interacting with MultiversX. [CLI](CLI.md) ## Distribution -[mxpy-up](https://docs.multiversx.com/sdk-and-tools/sdk-py/installing-mxpy/) and [PyPi](https://pypi.org/project/multiversx-sdk-cli/#history) +[pipx](https://docs.multiversx.com/sdk-and-tools/sdk-py/installing-mxpy/) [(PyPi)](https://pypi.org/project/multiversx-sdk-cli/#history) ## Development setup From c8b73134585ca64681a03b3cfa1ef01225c07d48 Mon Sep 17 00:00:00 2001 From: Alexandru Popenta Date: Thu, 9 Jan 2025 15:38:40 +0200 Subject: [PATCH 88/90] set correct options for ledger accounts --- multiversx_sdk_cli/accounts.py | 2 ++ multiversx_sdk_cli/transactions.py | 30 ++++++++++++++++++++---------- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/multiversx_sdk_cli/accounts.py b/multiversx_sdk_cli/accounts.py index 33616067..38060b92 100644 --- a/multiversx_sdk_cli/accounts.py +++ b/multiversx_sdk_cli/accounts.py @@ -96,6 +96,8 @@ def __init__(self, account_index: int = 0, address_index: int = 0) -> None: def sign_transaction(self, transaction: ITransaction) -> str: ledger_version = do_get_ledger_version() should_use_hash_signing = compare_versions(ledger_version, SIGN_USING_HASH_VERSION) >= 0 + + # TODO: This check will be removed in the next major release. if should_use_hash_signing: transaction.version = TX_HASH_SIGN_VERSION transaction.options = transaction.options | TX_HASH_SIGN_OPTIONS diff --git a/multiversx_sdk_cli/transactions.py b/multiversx_sdk_cli/transactions.py index ae5af090..2c58c4a7 100644 --- a/multiversx_sdk_cli/transactions.py +++ b/multiversx_sdk_cli/transactions.py @@ -2,15 +2,15 @@ import json import logging import time -from typing import Any, Dict, List, Optional, Protocol, TextIO +from typing import Any, Dict, List, Optional, Protocol, TextIO, Union from multiversx_sdk import (Address, Token, TokenComputer, TokenTransfer, Transaction, TransactionsConverter, TransactionsFactoryConfig, - TransferTransactionsFactory) + TransferTransactionsFactory, TransactionComputer) from multiversx_sdk_cli import errors -from multiversx_sdk_cli.accounts import Account, LedgerAccount +from multiversx_sdk_cli.accounts import Account, AccountBase, LedgerAccount from multiversx_sdk_cli.cli_password import (load_guardian_password, load_password) from multiversx_sdk_cli.cosign_transaction import cosign_transaction @@ -75,6 +75,10 @@ def do_prepare_transaction(args: Any) -> Transaction: tx.version = int(args.version) tx.options = int(args.options) + tx_computer = TransactionComputer() + if isinstance(account, LedgerAccount): + tx_computer.apply_options_for_hash_signing(tx) + if args.guardian: tx.guardian = args.guardian @@ -86,14 +90,25 @@ def do_prepare_transaction(args: Any) -> Transaction: if relayer_account.address.to_bech32() != tx.relayer: raise IncorrectWalletError("") + if isinstance(relayer_account, LedgerAccount): + tx_computer.apply_options_for_hash_signing(tx) + tx.relayer_signature = bytes.fromhex(relayer_account.sign_transaction(tx)) except NoWalletProvided: logger.warning("Relayer wallet not provided. Transaction will not be signed by relayer.") except IncorrectWalletError: raise IncorrectWalletError("Relayer wallet does not match the relayer's address set in the transaction.") + try: + guardian_account = get_guardian_account_from_args(args) + if isinstance(guardian_account, LedgerAccount): + tx_computer.apply_options_for_hash_signing(tx) + + except NoWalletProvided: + guardian_account = None + tx.signature = bytes.fromhex(account.sign_transaction(tx)) - tx = sign_tx_by_guardian(args, tx) + tx = sign_tx_by_guardian(args, tx, guardian_account) return tx @@ -141,12 +156,7 @@ def prepare_token_transfers(transfers: List[Any]) -> List[TokenTransfer]: return token_transfers -def sign_tx_by_guardian(args: Any, tx: Transaction) -> Transaction: - try: - guardian_account = get_guardian_account_from_args(args) - except NoWalletProvided: - guardian_account = None - +def sign_tx_by_guardian(args: Any, tx: Transaction, guardian_account: Union[AccountBase, None]) -> Transaction: if guardian_account: tx.guardian_signature = bytes.fromhex(guardian_account.sign_transaction(tx)) elif args.guardian: From 6d8fa484b522b8f20d9d91ab6ee6dbafc66f2547 Mon Sep 17 00:00:00 2001 From: Alexandru Popenta Date: Thu, 9 Jan 2025 15:45:17 +0200 Subject: [PATCH 89/90] bump version --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 0f04144e..18479392 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "hatchling.build" [project] name = "multiversx-sdk-cli" -version = "9.10.0" +version = "9.10.1" authors = [ { name="MultiversX" }, ] From f4eff4769b64a0387b91c9d9c965ce793b1f6b0c Mon Sep 17 00:00:00 2001 From: Alexandru Popenta Date: Tue, 21 Jan 2025 12:41:08 +0200 Subject: [PATCH 90/90] call sign-multiple-transactions when cosigning txs using TCS --- multiversx_sdk_cli/cosign_transaction.py | 12 +++++++----- pyproject.toml | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/multiversx_sdk_cli/cosign_transaction.py b/multiversx_sdk_cli/cosign_transaction.py index fce9e274..d63d71f0 100644 --- a/multiversx_sdk_cli/cosign_transaction.py +++ b/multiversx_sdk_cli/cosign_transaction.py @@ -1,4 +1,4 @@ -from typing import Any, Dict +from typing import Any import requests from multiversx_sdk import TransactionsConverter @@ -11,20 +11,22 @@ def cosign_transaction(transaction: ITransaction, service_url: str, guardian_cod tx_converter = TransactionsConverter() payload = { "code": f"{guardian_code}", - "transaction": tx_converter.transaction_to_dictionary(transaction) + "transactions": [tx_converter.transaction_to_dictionary(transaction)] } - url = f"{service_url}/sign-transaction" + # we call sign-multiple-transactions to be allowed a bigger payload (e.g. deploying large contracts) + url = f"{service_url}/sign-multiple-transactions" response = requests.post(url, json=payload) check_for_guardian_error(response.json()) - tx_as_dict = response.json()["data"]["transaction"] + # we only send 1 transaction + tx_as_dict = response.json()["data"]["transactions"][0] transaction.guardian_signature = bytes.fromhex(tx_as_dict["guardianSignature"]) return transaction -def check_for_guardian_error(response: Dict[str, Any]): +def check_for_guardian_error(response: dict[str, Any]): error = response["error"] if error: diff --git a/pyproject.toml b/pyproject.toml index 18479392..a2fc4738 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "hatchling.build" [project] name = "multiversx-sdk-cli" -version = "9.10.1" +version = "9.10.2" authors = [ { name="MultiversX" }, ]