Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added cli validators test in pytest and CI for localnet dependent tests. #454

Open
wants to merge 73 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 66 commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
c32d328
Added cli validators test in pytest and CI for localnet dependent tests.
cristure Oct 24, 2024
84efeb2
Added fixture for proxy polling.
cristure Oct 24, 2024
1685f02
try different endpoint for polling.
cristure Oct 24, 2024
f4e9c73
adding debug command.
cristure Oct 24, 2024
315e3b0
more debugging.
cristure Oct 24, 2024
39be1b4
make localnet run in background.
cristure Oct 24, 2024
18d6c71
added Dockerfile and integrated CI with docker.
cristure Oct 24, 2024
3f825a2
add checkout.
cristure Oct 24, 2024
99a198d
install python dependencies in order to trigger the tests.
cristure Oct 24, 2024
3d2be36
rename to localhost. possible issue with the loopback interface.
cristure Oct 24, 2024
beef139
debug commands
cristure Oct 24, 2024
95f1a15
more debugging.
cristure Oct 24, 2024
23b9961
add a sleep for debugging.
cristure Oct 24, 2024
ef9cdb2
trying to debug docker publishing in GHA.
cristure Oct 24, 2024
5043947
cosmetic changes
cristure Oct 24, 2024
4953eaa
move sleep above.
cristure Oct 24, 2024
a5ccb03
more debugging.
cristure Oct 24, 2024
7e889f1
increase timeout to 10 mins.
cristure Oct 24, 2024
0af4d95
check logs of docker localnet inside worker.
cristure Oct 24, 2024
05a7e57
fix CI and dockerfile by installing build-essential in the docker con…
cristure Oct 24, 2024
ec17dda
adding verbose command.
cristure Oct 24, 2024
1a4fe12
Fix deploy localnet job.
cristure Oct 25, 2024
900530f
fix whitespaces in multi-line command.
cristure Oct 25, 2024
17a08cf
fixing docker image and localnet setup.
cristure Oct 25, 2024
8359cbb
adding separate validators json file for docker tests.
cristure Oct 25, 2024
b43c31a
fixing Dockerfile
cristure Oct 25, 2024
bbe93e7
fix paths for validators_docker.json
cristure Oct 25, 2024
ad7e421
fix paths in validators_docker.json
cristure Oct 25, 2024
bfe909f
fix validators_docker.json
cristure Oct 25, 2024
83b76aa
fix yaml file.
cristure Oct 25, 2024
8804754
fix yaml file, round 2.
cristure Oct 25, 2024
d3d0d5c
add debug commands.
cristure Oct 25, 2024
9f9b8c0
debug home directory inside runner.
cristure Oct 25, 2024
79392ad
fix paths.
cristure Oct 25, 2024
d3f707d
more debugging.
cristure Oct 25, 2024
adaf45a
fix more paths.
cristure Oct 25, 2024
28fa958
add debug sleep.
cristure Oct 25, 2024
0e46464
cosmetic changes.
cristure Oct 25, 2024
7045c32
fix yaml file.
cristure Oct 25, 2024
5f0f807
remove docker
cristure Nov 4, 2024
7a1c8cb
fix mxpy commands in CI.
cristure Nov 4, 2024
6d2888e
cosmetic changes.
cristure Nov 4, 2024
685ca9e
debug strings
cristure Nov 4, 2024
7bdab1a
more debug commands.
cristure Nov 4, 2024
343ba6b
fix CI tests and remove docker naming.
cristure Nov 4, 2024
bf164f6
remove polling.
cristure Nov 4, 2024
e8137fa
cosmetic changes.
cristure Nov 4, 2024
3fb2a0e
fix unused fixture.
cristure Nov 4, 2024
af2c955
remove polling fixture.
cristure Nov 4, 2024
c7d799f
more debugging.
cristure Nov 4, 2024
5a274c4
show log in CI.
cristure Nov 4, 2024
42c1260
more debugging in CI.
cristure Nov 4, 2024
1ba5d85
more debugging in CI.
cristure Nov 4, 2024
25760e9
check logs in CI.
cristure Nov 4, 2024
fe180f0
rewrite setting up commands.
cristure Nov 4, 2024
61bf291
debug.
cristure Nov 4, 2024
4ce863e
more commands.
cristure Nov 4, 2024
380c08b
make nohup run in background.
cristure Nov 4, 2024
58e29a0
debug localnet config.
cristure Nov 4, 2024
31b6563
more debugging paths.
cristure Nov 4, 2024
92e6386
fix paths for ci validator keys file.
cristure Nov 4, 2024
e8c89e1
clean remaining commented code.
cristure Nov 4, 2024
0080690
added conftest and strict markers.
cristure Nov 4, 2024
69404f0
modified skip on windows marker.
cristure Nov 5, 2024
c2adbf2
fix skip_on_windows marker
cristure Nov 5, 2024
1b1a414
fix windows build
cristure Nov 5, 2024
4067411
remove duplicated bash tests and added teardown for localnet tests.
cristure Nov 5, 2024
572725d
Revert "remove duplicated bash tests and added teardown for localnet …
cristure Nov 5, 2024
eb42289
bring back bash tests as they are used in other tests.
cristure Nov 5, 2024
10ffa3c
added teardown for localnet.
cristure Nov 5, 2024
d382db0
clean unused bash tests.
cristure Nov 5, 2024
7ab16ba
remove cli tests for windows.
cristure Nov 6, 2024
ca1d4fd
remove deleted shell scripts.
cristure Nov 6, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
55 changes: 55 additions & 0 deletions .github/workflows/test-localnet-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
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: 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 > localnet.log 2>&1 & echo $! > localnet.pid
sleep 120

- name: Test localnet dependent tests
run: |
pytest -m require_localnet .

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the runner dies immediately after the test if finished from what I know. I don't think there is a need to teardown

10 changes: 10 additions & 0 deletions multiversx_sdk_cli/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import pytest

Check failure on line 1 in multiversx_sdk_cli/tests/conftest.py

View workflow job for this annotation

GitHub Actions / runner / mypy

[mypy] reported by reviewdog 🐶 Cannot find implementation or library stub for module named "pytest" [import-not-found] Raw Output: /home/runner/work/mx-sdk-py-cli/mx-sdk-py-cli/multiversx_sdk_cli/tests/conftest.py:1:1: error: Cannot find implementation or library stub for module named "pytest" [import-not-found]


# 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="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)
198 changes: 198 additions & 0 deletions multiversx_sdk_cli/tests/test_cli_validators.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
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"

proxy_url = "http://localhost:7950/network/config"
alice_pem = testdata_path / "alice.pem"
reward_address = "erd1k2s324ww2g0yj38qn2ch2jwctdy8mnfxep94q9arncc6xecg3xaq6mjse8"
bls_key = "e7beaa95b3877f47348df4dd1cb578a4f7cabf7a20bfeefe5cdd263878ff132b765e04fef6f40c93512b666c47ed7719b8902f6c922c04247989b7137e837cc81a62e54712471c97a2ddab75aa9c2f58f813ed4c0fa722bde0ab718bff382208"


@pytest.mark.require_localnet
def test_stake():
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_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
13 changes: 13 additions & 0 deletions multiversx_sdk_cli/tests/testdata/validators_ci.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"validators": [
{
"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/config/validatorKey.pem"
},
{
"pemFile": "~/work/mx-sdk-py-cli/mx-sdk-py-cli/localnet/validator02/config/validatorKey.pem"
}
]
}
3 changes: 2 additions & 1 deletion pytest.ini
Original file line number Diff line number Diff line change
@@ -1,6 +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 (select with '-m "require_localnet"')

log_cli = True
Loading