This repository has been archived by the owner on Dec 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 78
/
test_chain_id_cli_params.py
93 lines (79 loc) · 2.35 KB
/
test_chain_id_cli_params.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
"""Testing chain id CLI params"""
import subprocess
import pytest
from starkware.starknet.definitions.general_config import StarknetChainId
from starknet_devnet.devnet_config import CHAIN_IDS
from .account import invoke
from .shared import (
ABI_PATH,
CONTRACT_PATH,
PREDEPLOY_ACCOUNT_CLI_ARGS,
PREDEPLOYED_ACCOUNT_ADDRESS,
PREDEPLOYED_ACCOUNT_PRIVATE_KEY,
)
from .util import (
DevnetBackgroundProc,
assert_equal,
assert_transaction,
assert_tx_status,
call,
deploy,
read_stream,
terminate_and_wait,
)
ACTIVE_DEVNET = DevnetBackgroundProc()
@pytest.mark.parametrize(
"chain_id",
[member.name for member in StarknetChainId],
)
def test_chain_id_valid(chain_id):
"""Test if chain id works"""
proc = ACTIVE_DEVNET.start(
"--chain-id",
chain_id,
)
terminate_and_wait(proc)
assert proc.returncode == 0
@pytest.mark.parametrize(
"chain_id",
["", "mainnet2"],
)
def test_chain_id_invalid(chain_id):
"""Test if the invalid chain id fails"""
proc = ACTIVE_DEVNET.start(
"--chain-id",
chain_id,
stderr=subprocess.PIPE,
stdout=subprocess.PIPE,
)
assert (
f"Error: The value of --chain-id must be in {{{CHAIN_IDS}}}, got:"
in read_stream(proc.stderr)
)
assert proc.returncode == 1
@pytest.mark.usefixtures("run_devnet_in_background")
@pytest.mark.parametrize(
"run_devnet_in_background, chain_id",
[
([*PREDEPLOY_ACCOUNT_CLI_ARGS, "--chain-id", chain_id.name], chain_id)
for chain_id in StarknetChainId
],
indirect=True,
)
def test_deploy_and_invoke(chain_id):
"""Test deploy and invoke with MAINNET and TESTNET chain_id"""
deploy_info = deploy(CONTRACT_PATH, inputs=["0"])
assert_tx_status(deploy_info["tx_hash"], "ACCEPTED_ON_L2")
assert_transaction(deploy_info["tx_hash"], "ACCEPTED_ON_L2")
# increase and assert balance
invoke_tx_hash = invoke(
calls=[(deploy_info["address"], "increase_balance", [10, 20])],
account_address=PREDEPLOYED_ACCOUNT_ADDRESS,
private_key=PREDEPLOYED_ACCOUNT_PRIVATE_KEY,
chain_id=chain_id,
)
assert_transaction(invoke_tx_hash, "ACCEPTED_ON_L2")
value = call(
function="get_balance", address=deploy_info["address"], abi_path=ABI_PATH
)
assert_equal(value, "30", "Invoke+call failed!")