diff --git a/test/test_cli.py b/test/test_cli.py index 53c34fa97..7faadce72 100644 --- a/test/test_cli.py +++ b/test/test_cli.py @@ -27,10 +27,20 @@ NONEXISTENT_TX_HASH = "0x12345678910111213" BALANCE_KEY = "916907772491729262376534102982219947830828984996257231353398618781993312401" +@pytest.fixture(autouse=True) +def run_before_and_after_test(): + """Run devnet before and kill it after the test run""" + # before test + devnet_proc = run_devnet_in_background(sleep_seconds=20) + + yield + + # after test + devnet_proc.kill() + @pytest.mark.cli def test_starknet_cli(): """Test devnet with CLI""" - devnet_proc = run_devnet_in_background(sleep_seconds=15) deploy_info = deploy(CONTRACT_PATH, ["0"]) print("Deployment:", deploy_info) @@ -102,4 +112,3 @@ def test_starknet_cli(): assert_events(salty_invoke_tx_hash, "test/expected/invoke_receipt_event.json") assert_failing_deploy(contract_path=FAILING_CONTRACT_PATH) - devnet_proc.kill() diff --git a/test/test_cli_auth.py b/test/test_cli_auth.py index 7b6478e3b..e5a1dfd16 100644 --- a/test/test_cli_auth.py +++ b/test/test_cli_auth.py @@ -2,6 +2,7 @@ Tests how signed interaction with a Starknet contract. """ import pytest + from .util import ( run_devnet_in_background, assert_block, assert_equal, assert_receipt, @@ -13,7 +14,6 @@ CONTRACT_PATH = f"{ARTIFACTS_PATH}/auth_contract.cairo/auth_contract.json" ABI_PATH = f"{ARTIFACTS_PATH}/auth_contract.cairo/auth_contract_abi.json" -run_devnet_in_background(sleep_seconds=1) # PRIVATE_KEY = "12345" PUBLIC_KEY = "1628448741648245036800002906075225705100596136133912895015035902954123957052" INITIAL_BALANCE = "1000" @@ -24,11 +24,21 @@ ] BALANCE_KEY = "142452623821144136554572927896792266630776240502820879601186867231282346767" +@pytest.fixture(autouse=True) +def run_before_and_after_test(): + """Run devnet before and kill it after the test run""" + # before test + devnet_proc = run_devnet_in_background(sleep_seconds=20) + + yield + + # after test + devnet_proc.kill() @pytest.mark.cli def test_starknet_cli_auth(): """Test CLI auth in devnet""" - devnet_proc = run_devnet_in_background(sleep_seconds=1) + deploy_info = deploy(CONTRACT_PATH, [PUBLIC_KEY, INITIAL_BALANCE]) print("Deployment:", deploy_info) @@ -60,5 +70,3 @@ def test_starknet_cli_auth(): assert_storage(deploy_info["address"], BALANCE_KEY, "0x14c9") assert_transaction(invoke_tx_hash, "ACCEPTED_ON_L2", expected_signature=SIGNATURE) assert_receipt(invoke_tx_hash, "test/expected/invoke_receipt_auth.json") - - devnet_proc.kill() diff --git a/test/test_cli_lite.py b/test/test_cli_lite.py index 69a5b8916..f3d30bed2 100644 --- a/test/test_cli_lite.py +++ b/test/test_cli_lite.py @@ -25,10 +25,20 @@ NONEXISTENT_TX_HASH = "0x12345678910111213" BALANCE_KEY = "916907772491729262376534102982219947830828984996257231353398618781993312401" +@pytest.fixture(autouse=True) +def run_before_and_after_test(): + """Run devnet before and kill it after the test run""" + # before test + devnet_proc = run_devnet_in_background(sleep_seconds=20) + + yield + + # after test + devnet_proc.kill() + @pytest.mark.cli def test_starknet_cli(): """Test devnet with CLI""" - devnet_proc = run_devnet_in_background(sleep_seconds=1) deploy_info = deploy(CONTRACT_PATH, ["0"]) print("Deployment:", deploy_info) @@ -81,5 +91,3 @@ def test_starknet_cli(): assert_equal(value, "40 60", "Checking complex input failed!") assert_failing_deploy(contract_path=FAILING_CONTRACT_PATH) - - devnet_proc.kill() diff --git a/test/util.py b/test/util.py index 81d07b130..fcd2db94a 100644 --- a/test/util.py +++ b/test/util.py @@ -26,6 +26,7 @@ def run_devnet_in_background(*args, sleep_seconds=3): command = ["poetry", "run", "starknet-devnet", "--host", HOST, "--port", PORT, *args] # pylint: disable=consider-using-with proc = subprocess.Popen(command, close_fds=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + time.sleep(sleep_seconds) atexit.register(proc.kill) return proc