Skip to content

Commit 9e64bfd

Browse files
authored
Stop using sys.args logic in test (#1719)
* Stop using `sys.args` logic in test * Fix invalid tests
1 parent 26418ac commit 9e64bfd

9 files changed

Lines changed: 49 additions & 51 deletions

File tree

starknet_py/tests/e2e/client/full_node_test.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import dataclasses
2-
import sys
32
from unittest.mock import AsyncMock, patch
43

54
import pytest
@@ -33,7 +32,7 @@
3332
from starknet_py.net.full_node_client import _to_rpc_felt
3433
from starknet_py.net.models import StarknetChainId
3534
from starknet_py.tests.e2e.fixtures.constants import MAX_RESOURCE_BOUNDS
36-
from starknet_py.tests.e2e.fixtures.misc import load_contract
35+
from starknet_py.tests.e2e.fixtures.misc import _contract_dir, load_contract
3736

3837

3938
def _parse_event_name(event: str) -> str:
@@ -147,7 +146,7 @@ async def test_get_storage_at_incorrect_address_full_node_client(client):
147146

148147

149148
@pytest.mark.skipif(
150-
"--contract_dir=v1" in sys.argv,
149+
_contract_dir == "v1",
151150
reason="Contract exists only in v2 directory",
152151
)
153152
@pytest.mark.run_on_devnet
@@ -176,7 +175,7 @@ async def test_get_events_without_following_continuation_token(
176175

177176

178177
@pytest.mark.skipif(
179-
"--contract_dir=v1" in sys.argv,
178+
_contract_dir == "v1",
180179
reason="Contract exists only in v2 directory",
181180
)
182181
@pytest.mark.run_on_devnet
@@ -205,7 +204,7 @@ async def test_get_events_follow_continuation_token(
205204

206205

207206
@pytest.mark.skipif(
208-
"--contract_dir=v1" in sys.argv,
207+
_contract_dir == "v1",
209208
reason="Contract exists only in v2 directory",
210209
)
211210
@pytest.mark.run_on_devnet
@@ -232,7 +231,7 @@ async def test_get_events_nonexistent_event_name(
232231

233232

234233
@pytest.mark.skipif(
235-
"--contract_dir=v1" in sys.argv,
234+
_contract_dir == "v1",
236235
reason="Contract exists only in v2 directory",
237236
)
238237
@pytest.mark.run_on_devnet
@@ -285,7 +284,7 @@ async def test_get_events_with_two_events(
285284

286285

287286
@pytest.mark.skipif(
288-
"--contract_dir=v1" in sys.argv,
287+
_contract_dir == "v1",
289288
reason="Contract exists only in v2 directory",
290289
)
291290
@pytest.mark.run_on_devnet
@@ -316,7 +315,7 @@ async def test_get_events_start_from_continuation_token(
316315

317316

318317
@pytest.mark.skipif(
319-
"--contract_dir=v1" in sys.argv,
318+
_contract_dir == "v1",
320319
reason="Contract exists only in v2 directory",
321320
)
322321
@pytest.mark.run_on_devnet
@@ -339,7 +338,7 @@ async def test_get_events_no_params(
339338

340339

341340
@pytest.mark.skipif(
342-
"--contract_dir=v1" in sys.argv,
341+
_contract_dir == "v1",
343342
reason="Contract exists only in v2 directory",
344343
)
345344
@pytest.mark.run_on_devnet
@@ -620,7 +619,7 @@ async def test_trace_block_transactions_return_initial_reads(
620619

621620

622621
@pytest.mark.skipif(
623-
"--contract_dir=v1" in sys.argv,
622+
_contract_dir == "v1",
624623
reason="Contract exists only in v2 directory",
625624
)
626625
@pytest.mark.run_on_devnet

starknet_py/tests/e2e/contract_interaction/v1_interaction_test.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
1-
import sys
2-
31
import pytest
42

53
from starknet_py.cairo.felt import decode_shortstring, encode_shortstring
64
from starknet_py.contract import Contract
75
from starknet_py.tests.e2e.fixtures.constants import MAX_RESOURCE_BOUNDS
86
from starknet_py.tests.e2e.fixtures.contracts_v1 import deploy_v3_contract
7+
from starknet_py.tests.e2e.fixtures.misc import _contract_dir
98

109
# TODO (#1219): investigate why some of these tests fails for contracts_compiled_v1
1110

1211

1312
@pytest.mark.skipif(
14-
"--contract_dir=v1" in sys.argv,
13+
_contract_dir == "v1",
1514
reason="Contract exists only in v2 directory",
1615
)
1716
@pytest.mark.asyncio
@@ -57,7 +56,7 @@ async def test_general_v3_interaction(account, erc20_class_hash: int):
5756

5857

5958
@pytest.mark.skipif(
60-
"--contract_dir=v1" in sys.argv,
59+
_contract_dir == "v1",
6160
reason="Contract exists only in v2 directory",
6261
)
6362
@pytest.mark.asyncio
@@ -149,7 +148,7 @@ async def test_serializing_enum(account, test_enum_class_hash: int):
149148

150149

151150
@pytest.mark.skipif(
152-
"--contract_dir=v1" in sys.argv,
151+
_contract_dir == "v1",
153152
reason="Contract exists only in v2 directory",
154153
)
155154
@pytest.mark.asyncio
@@ -177,7 +176,7 @@ async def test_from_address_on_v1_contract(account, erc20_class_hash: int):
177176

178177

179178
@pytest.mark.skipif(
180-
"--contract_dir=v2" not in sys.argv,
179+
_contract_dir != "v2",
181180
reason="Contract exists only in v2 directory",
182181
)
183182
@pytest.mark.asyncio

starknet_py/tests/e2e/deploy/deployer_test.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
import sys
2-
31
import pytest
42

53
from starknet_py.contract import Contract
64
from starknet_py.hash.address import compute_address
75
from starknet_py.net.full_node_client import FullNodeClient
86
from starknet_py.net.udc_deployer.deployer import Deployer
97
from starknet_py.tests.e2e.fixtures.constants import MAX_RESOURCE_BOUNDS
8+
from starknet_py.tests.e2e.fixtures.misc import _contract_dir
109
from starknet_py.utils.constructor_args_translator import translate_constructor_args
1110

1211

@@ -27,7 +26,7 @@ async def test_default_deploy_with_class_hash(account, map_class_hash):
2726

2827

2928
@pytest.mark.skipif(
30-
"--contract_dir=v2" not in sys.argv,
29+
_contract_dir != "v2",
3130
reason="Contract exists only in v2 directory",
3231
)
3332
@pytest.mark.asyncio
@@ -64,7 +63,7 @@ async def test_constructor_arguments_contract_deploy_without_abi(
6463

6564

6665
@pytest.mark.skipif(
67-
"--contract_dir=v2" not in sys.argv,
66+
_contract_dir != "v2",
6867
reason="Contract exists only in v2 directory",
6968
)
7069
@pytest.mark.asyncio
@@ -117,7 +116,7 @@ async def test_constructor_arguments_contract_deploy(
117116

118117

119118
@pytest.mark.skipif(
120-
"--contract_dir=v1" in sys.argv,
119+
_contract_dir == "v1",
121120
reason="Contract exists only in v2 directory",
122121
)
123122
@pytest.mark.asyncio
@@ -179,7 +178,7 @@ async def test_address_computation(salt, pass_account_address, account, map_clas
179178

180179

181180
@pytest.mark.skipif(
182-
"--contract_dir=v2" not in sys.argv,
181+
_contract_dir != "v2",
183182
reason="Contract exists only in v2 directory",
184183
)
185184
@pytest.mark.asyncio
@@ -226,7 +225,7 @@ async def test_create_deployment_call_raw(
226225

227226

228227
@pytest.mark.skipif(
229-
"--contract_dir=v2" not in sys.argv,
228+
_contract_dir != "v2",
230229
reason="Contract exists only in v2 directory",
231230
)
232231
@pytest.mark.asyncio

starknet_py/tests/e2e/devnet_client/account_impersonate_test.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1-
import sys
2-
31
import pytest
42

53
from starknet_py.contract import Contract
64
from starknet_py.net.client_errors import ClientError
75
from starknet_py.tests.e2e.fixtures.constants import MAX_RESOURCE_BOUNDS
6+
from starknet_py.tests.e2e.fixtures.misc import _contract_dir
87

98

109
@pytest.mark.skipif(
11-
"--contract_dir=v2" not in sys.argv,
10+
_contract_dir != "v2",
1211
reason="Contract exists only in v2 directory",
1312
)
1413
@pytest.mark.asyncio
@@ -37,7 +36,7 @@ async def test_impersonate_account(
3736

3837

3938
@pytest.mark.skipif(
40-
"--contract_dir=v2" not in sys.argv,
39+
_contract_dir != "v2",
4140
reason="Contract exists only in v2 directory",
4241
)
4342
@pytest.mark.asyncio
@@ -62,7 +61,7 @@ async def test_auto_impersonate(
6261

6362

6463
@pytest.mark.skipif(
65-
"--contract_dir=v2" not in sys.argv,
64+
_contract_dir != "v2",
6665
reason="Contract exists only in v2 directory",
6766
)
6867
@pytest.mark.asyncio

starknet_py/tests/e2e/docs/guide/test_declaring_contracts.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
import sys
2-
31
import pytest
42

53
from starknet_py.net.client_models import ResourceBounds, ResourceBoundsMapping
4+
from starknet_py.tests.e2e.fixtures.misc import _contract_dir
65

76

87
@pytest.mark.skipif(
9-
"--contract_dir=v2" not in sys.argv,
8+
_contract_dir != "v2",
109
reason="Contract exists only in v2 directory",
1110
)
1211
@pytest.mark.asyncio
@@ -21,7 +20,7 @@ async def test_declaring_contracts(
2120

2221
resource_bounds = ResourceBoundsMapping(
2322
l1_gas=ResourceBounds(max_amount=int(1e5), max_price_per_unit=int(1e13)),
24-
l2_gas=ResourceBounds(max_amount=int(1e5), max_price_per_unit=int(1e13)),
23+
l2_gas=ResourceBounds(max_amount=int(1e10), max_price_per_unit=int(1e17)),
2524
l1_data_gas=ResourceBounds(max_amount=int(1e5), max_price_per_unit=int(1e13)),
2625
)
2726
declare_transaction = await account.sign_declare_v3(

starknet_py/tests/e2e/docs/guide/test_deploying_with_udc.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import sys
2-
31
import pytest
42

3+
from starknet_py.tests.e2e.fixtures.misc import _contract_dir
4+
55

66
@pytest.mark.skipif(
7-
"--contract_dir=v2" not in sys.argv,
7+
_contract_dir != "v2",
88
reason="Contract exists only in v2 directory",
99
)
1010
@pytest.mark.asyncio

starknet_py/tests/e2e/docs/guide/test_using_existing_contracts.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import sys
2-
31
import pytest
42

53
from starknet_py.tests.e2e.fixtures.constants import MAX_RESOURCE_BOUNDS
4+
from starknet_py.tests.e2e.fixtures.misc import _contract_dir
65

76
# docs-abi: start
87
abi = [
@@ -28,7 +27,7 @@
2827

2928

3029
@pytest.mark.skipif(
31-
"--contract_dir=v1" in sys.argv,
30+
_contract_dir == "v1",
3231
reason="Contract exists only in v2 directory",
3332
)
3433
@pytest.mark.asyncio

starknet_py/tests/e2e/docs/quickstart/test_using_account.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import os
2-
import sys
32

43
import pytest
54

65
from starknet_py.net.client_models import ResourceBoundsMapping
6+
from starknet_py.tests.e2e.fixtures.misc import _contract_dir
77

88
directory = os.path.dirname(__file__)
99

1010

1111
@pytest.mark.skipif(
12-
"--contract_dir=v2" not in sys.argv,
12+
_contract_dir != "v2",
1313
reason="Contract exists only in v2 directory",
1414
)
1515
@pytest.mark.asyncio
@@ -22,13 +22,10 @@ async def test_using_account(account, map_compiled_contract_and_class_hash_copy_
2222

2323
# docs: end
2424
# docs: start
25-
l1_resource_bounds = ResourceBounds(
26-
max_amount=int(1e5), max_price_per_unit=int(1e13)
27-
)
2825
resource_bounds = ResourceBoundsMapping(
29-
l1_gas=l1_resource_bounds,
30-
l2_gas=ResourceBounds.init_with_zeros(),
31-
l1_data_gas=ResourceBounds.init_with_zeros(),
26+
l1_gas=ResourceBounds(max_amount=int(1e5), max_price_per_unit=int(1e13)),
27+
l2_gas=ResourceBounds(max_amount=int(1e10), max_price_per_unit=int(1e17)),
28+
l1_data_gas=ResourceBounds(max_amount=int(1e5), max_price_per_unit=int(1e13)),
3229
)
3330
# Declare and deploy an example contract which implements a simple k-v store.
3431
# Contract.declare_v3 takes string containing a compiled contract (sierra) and
@@ -53,9 +50,9 @@ async def test_using_account(account, map_compiled_contract_and_class_hash_copy_
5350
# Adds a transaction to mutate the state of k-v store. The call goes through account proxy, because we've used
5451
# Account to create the contract object
5552
resource_bounds = ResourceBoundsMapping(
56-
l1_gas=l1_resource_bounds,
57-
l2_gas=ResourceBounds.init_with_zeros(),
58-
l1_data_gas=ResourceBounds.init_with_zeros(),
53+
l1_gas=ResourceBounds(max_amount=int(1e5), max_price_per_unit=int(1e13)),
54+
l2_gas=ResourceBounds(max_amount=int(1e10), max_price_per_unit=int(1e17)),
55+
l1_data_gas=ResourceBounds(max_amount=int(1e5), max_price_per_unit=int(1e13)),
5956
)
6057
await (
6158
await map_contract.functions["put"].invoke_v3(

starknet_py/tests/e2e/fixtures/misc.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import json
44
import random
5-
import sys
65
from pathlib import Path
76
from typing import Optional
87

@@ -23,6 +22,9 @@
2322
from starknet_py.tests.e2e.fixtures.constants import MOCK_DIR, TYPED_DATA_DIR
2423
from starknet_py.utils.typed_data import TypedData
2524

25+
# Populated in `pytest_configure` from the `--contract_dir` CLI option, before test modules are imported.
26+
_contract_dir: str = ""
27+
2628

2729
def pytest_addoption(parser):
2830
parser.addoption(
@@ -33,6 +35,11 @@ def pytest_addoption(parser):
3335
)
3436

3537

38+
def pytest_configure(config):
39+
global _contract_dir # pylint: disable=global-statement
40+
_contract_dir = config.getoption("contract_dir", default="")
41+
42+
3643
@pytest.fixture(
3744
params=[
3845
"typed_data_rev_0_example.json",
@@ -144,7 +151,7 @@ class UnknownArtifacts(BaseException):
144151

145152
def load_contract(contract_name: str, package: Optional[str] = None):
146153
if package is None:
147-
if "--contract_dir=v1" in sys.argv:
154+
if _contract_dir == "v1":
148155
package = "contracts_v1"
149156
else:
150157
package = "contracts_v2"

0 commit comments

Comments
 (0)