Skip to content
This repository has been archived by the owner on Dec 15, 2023. It is now read-only.

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Diogo Ribeiro committed Mar 24, 2022
1 parent d712c0e commit c146eae
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 9 deletions.
13 changes: 11 additions & 2 deletions test/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()
16 changes: 12 additions & 4 deletions test/test_cli_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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"
Expand All @@ -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)

Expand Down Expand Up @@ -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()
14 changes: 11 additions & 3 deletions test/test_cli_lite.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()
1 change: 1 addition & 0 deletions test/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c146eae

Please sign in to comment.