Skip to content

Commit

Permalink
Merge branch 'development' into fix-unskip-account-execution-test
Browse files Browse the repository at this point in the history
  • Loading branch information
baitcode authored Jan 23, 2025
2 parents ed82cd5 + 39af414 commit e828f93
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 10 deletions.
8 changes: 4 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
12 changes: 6 additions & 6 deletions starknet_py/tests/e2e/client/client_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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(
Expand All @@ -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
Expand All @@ -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,
Expand Down
32 changes: 32 additions & 0 deletions starknet_py/tests/e2e/client/fixtures/prepare_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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:
"""
Expand All @@ -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
Expand All @@ -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,
)

Expand Down

0 comments on commit e828f93

Please sign in to comment.