Skip to content

Commit

Permalink
Added fixture for proxy polling.
Browse files Browse the repository at this point in the history
  • Loading branch information
cristure committed Oct 24, 2024
1 parent c32d328 commit 84efeb2
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 14 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/test-localnet-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ jobs:
echo "The localnet failed to process blocks."
exit 1
fi
ls
- name: Test localnet dependent tests
run: |
Expand Down
56 changes: 44 additions & 12 deletions multiversx_sdk_cli/tests/test_cli_validators.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import requests
import time
import pytest

from pathlib import Path
Expand All @@ -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
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down
1 change: 1 addition & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 84efeb2

Please sign in to comment.