Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize CI #1553

Merged
merged 10 commits into from
Jan 21, 2025
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
Copy link
Collaborator Author

@franciszekjob franciszekjob Jan 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: The initial value of balance is 1777 when the contract is deployed. Previously, we assumed it was 1897, as other tests modified the balance value. This made the tests interdependent, relying on changes made by other tests. Now they use separate contract, ultimately enabling parallel execution.

Copy link
Collaborator Author

@franciszekjob franciszekjob Jan 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really think this test was meant to check storage after increasing balance - if so, we can easily add a test for invoke + check storage. However, then this is more a test for contract itself, not for our API.

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
29 changes: 29 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(
franciszekjob marked this conversation as resolved.
Show resolved Hide resolved
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,15 @@ def contract_address(prepare_network: Tuple[str, PreparedNetworkData]) -> int:
return prepared_data.contract_address


@pytest.fixture()
def contract_address_2(prepare_network: Tuple[str, PreparedNetworkData]) -> int:
franciszekjob marked this conversation as resolved.
Show resolved Hide resolved
"""
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 +182,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 +196,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
Loading