diff --git a/pyproject.toml b/pyproject.toml index ed189bae6..2814749f7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -73,14 +73,14 @@ test = [ ] test_ci = ["test_ci_v1", "test_ci_v2"] -test_ci_v1 = "coverage run -a -m pytest --contract_dir=v1 starknet_py --ignore=starknet_py/tests/e2e/docs --ignore=starknet_py/tests/e2e/tests_on_networks" -test_ci_v2 = "coverage run -a -m pytest --contract_dir=v2 starknet_py --ignore=starknet_py/tests/e2e/docs --ignore=starknet_py/tests/e2e/tests_on_networks" +test_ci_v1 = "coverage run -a -m pytest -n auto --contract_dir=v1 starknet_py --ignore=starknet_py/tests/e2e/docs --ignore=starknet_py/tests/e2e/tests_on_networks" +test_ci_v2 = "coverage run -a -m pytest -n auto --contract_dir=v2 starknet_py --ignore=starknet_py/tests/e2e/docs --ignore=starknet_py/tests/e2e/tests_on_networks" test_ci_on_networks = "coverage run -a -m pytest --contract_dir=v2 starknet_py/tests/e2e/tests_on_networks" test_ci_docs = ["test_ci_docs_v1", "test_ci_docs_v2"] -test_ci_docs_v1 = "coverage run -a -m pytest --contract_dir=v1 starknet_py/tests/e2e/docs" -test_ci_docs_v2 = "coverage run -a -m pytest --contract_dir=v2 starknet_py/tests/e2e/docs" +test_ci_docs_v1 = "coverage run -a -m pytest -n auto --contract_dir=v1 starknet_py/tests/e2e/docs" +test_ci_docs_v2 = "coverage run -a -m pytest -n auto --contract_dir=v2 starknet_py/tests/e2e/docs" test_report = "coverage report -m" test_html.shell = "coverage html && open ./htmlcov/index.html" diff --git a/starknet_py/tests/e2e/client/client_test.py b/starknet_py/tests/e2e/client/client_test.py index 5d140b695..83a7dff5f 100644 --- a/starknet_py/tests/e2e/client/client_test.py +++ b/starknet_py/tests/e2e/client/client_test.py @@ -110,14 +110,14 @@ async def test_get_block_by_number( @pytest.mark.asyncio -async def test_get_storage_at(client, contract_address): +async def test_get_storage_at(client, contract_address_2): storage = await client.get_storage_at( - contract_address=contract_address, + contract_address=contract_address_2, key=get_storage_var_address("balance"), block_hash="latest", ) - assert storage == 1897 + assert storage == 1777 @pytest.mark.asyncio @@ -241,16 +241,16 @@ async def test_estimate_fee_for_multiple_transactions( @pytest.mark.asyncio -async def test_call_contract(client, contract_address): +async def test_call_contract(client, contract_address_2): call = Call( - to_addr=contract_address, + to_addr=contract_address_2, selector=get_selector_from_name("get_balance"), calldata=[], ) result = await client.call_contract(call, block_number="latest") - assert result == [1897] + assert result == [1777] @pytest.mark.asyncio diff --git a/starknet_py/tests/e2e/client/fixtures/prepare_net_for_gateway_test.py b/starknet_py/tests/e2e/client/fixtures/prepare_net_for_gateway_test.py index 94587985a..423ecbf25 100755 --- a/starknet_py/tests/e2e/client/fixtures/prepare_net_for_gateway_test.py +++ b/starknet_py/tests/e2e/client/fixtures/prepare_net_for_gateway_test.py @@ -14,6 +14,7 @@ class PreparedNetworkData: # pylint: disable=too-many-instance-attributes class_hash: int contract_address: int + contract_address_2: int invoke_transaction_hash: int block_with_invoke_number: int declare_transaction_hash: int @@ -29,6 +30,7 @@ async def prepare_net_for_tests( deploy_account_details: AccountToBeDeployedDetails, transaction_hash: int, contract: Contract, + contract_2: Contract, declare_class_hash: int, ) -> PreparedNetworkData: # pylint: disable=too-many-locals @@ -42,9 +44,17 @@ async def prepare_net_for_tests( ) await invoke_res.wait_for_acceptance() + invoke_res_2 = await contract_2.functions["increase_balance"].invoke_v3( + amount=1777, l1_resource_bounds=MAX_RESOURCE_BOUNDS_L1 + ) + await invoke_res_2.wait_for_acceptance() + block_with_invoke_number = ( await account.client.get_transaction_receipt(invoke_res.hash) ).block_number + block_with_invoke_number_2 = ( + await account.client.get_transaction_receipt(invoke_res_2.hash) + ).block_number address, key_pair, salt, class_hash = deploy_account_details deploy_account_tx = await get_deploy_account_transaction( @@ -64,6 +74,7 @@ async def prepare_net_for_tests( block_with_deploy_account_hash = declare_account_receipt.block_hash assert block_with_invoke_number is not None + assert block_with_invoke_number_2 is not None assert block_with_declare_number is not None assert block_with_declare_hash is not None assert block_with_deploy_account_number is not None @@ -72,6 +83,7 @@ async def prepare_net_for_tests( return PreparedNetworkData( class_hash=declare_class_hash, contract_address=contract.address, + contract_address_2=contract_2.address, invoke_transaction_hash=invoke_res.hash, block_with_invoke_number=block_with_invoke_number, declare_transaction_hash=transaction_hash, diff --git a/starknet_py/tests/e2e/client/fixtures/prepare_network.py b/starknet_py/tests/e2e/client/fixtures/prepare_network.py index ed7f049b8..7f3d33f52 100644 --- a/starknet_py/tests/e2e/client/fixtures/prepare_network.py +++ b/starknet_py/tests/e2e/client/fixtures/prepare_network.py @@ -48,6 +48,24 @@ async def deployed_balance_contract( return deploy_result.deployed_contract +@pytest_asyncio.fixture(scope="package") +async def deployed_balance_contract_2( + account: BaseAccount, + balance_class_and_transaction_hash, + balance_abi, +) -> Contract: + class_hash, _ = balance_class_and_transaction_hash + deploy_result = await Contract.deploy_contract_v3( + account=account, + abi=balance_abi, + class_hash=class_hash, + l1_resource_bounds=MAX_RESOURCE_BOUNDS_L1, + ) + await deploy_result.wait_for_acceptance() + + return deploy_result.deployed_contract + + @pytest.fixture(scope="package") def balance_abi() -> List: compiled_contract = create_sierra_compiled_contract( @@ -139,6 +157,18 @@ def contract_address(prepare_network: Tuple[str, PreparedNetworkData]) -> int: return prepared_data.contract_address +# `contract_address` was used in other tests, which modified its storage values. This overlap +# caused test interdependencies, leading to inconsistent results in `test_get_storage_at` +# and `test_call_contract`, hence the introduction of `contract_address_2`. +@pytest.fixture() +def contract_address_2(prepare_network: Tuple[str, PreparedNetworkData]) -> int: + """ + Returns an address of the deployed contract + """ + _, prepared_data = prepare_network + return prepared_data.contract_address_2 + + @pytest.fixture() def class_hash(prepare_network: Tuple[str, PreparedNetworkData]) -> int: """ @@ -155,6 +185,7 @@ async def prepare_network( deploy_account_details_factory: AccountToBeDeployedDetailsFactory, balance_class_and_transaction_hash: Tuple[int, int], deployed_balance_contract: Contract, + deployed_balance_contract_2: Contract, ) -> AsyncGenerator[Tuple[str, PreparedNetworkData], None]: """ Adds transactions to the network. Returns network address and PreparedNetworkData @@ -168,6 +199,7 @@ async def prepare_network( deploy_account_details=details, transaction_hash=transaction_hash, contract=deployed_balance_contract, + contract_2=deployed_balance_contract_2, declare_class_hash=class_hash, )