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