Skip to content

Commit

Permalink
Added cli validators test in pytest and CI for localnet dependent tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
cristure committed Oct 24, 2024
1 parent 2ed0645 commit c32d328
Show file tree
Hide file tree
Showing 2 changed files with 260 additions and 0 deletions.
63 changes: 63 additions & 0 deletions .github/workflows/test-localnet-tests.yml
Original file line number Diff line number Diff line change
@@ -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
197 changes: 197 additions & 0 deletions multiversx_sdk_cli/tests/test_cli_validators.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit c32d328

Please sign in to comment.