Skip to content

Commit

Permalink
Restructure fixtures in tests (#1468)
Browse files Browse the repository at this point in the history
* Rename 'fee_contract_abi' -> 'cairo_0_fee_contract_abi'

* Rename 'cairo_1_erc20_class_hash' -> 'erc20_class_hash'

* Rename 'cairo1_token_bridge_class_hash' -> 'token_bridge_class_hash'

* Rename 'cairo1_test_option_class_hash' -> 'test_option_class_hash'

* Rename 'cairo1_test_enum_class_hash' -> 'test_enum_class_hash'

* Rename 'cairo_1_hello_starknet_class_hash_tx_hash' -> 'hello_starknet_class_hash_tx_hash'

* Rename 'cairo_1hello_starknet_class_hash' -> 'hello_starknet_class_hash'

* Rename 'cairo_1_hello_starknet_tx_hash' -> 'hello_starknet_tx_hash'

* Rename 'cairo1_minimal_contract_class_hash' -> 'minimal_contract_class_hash'

* Move cairo 1 fixtures to proper dir

* Remove unused function

* Lint

* Update docsstring in 'deploy_v1_contract' function

* Update 'load_contract' function argument

* Rename 'cairo1_hello_starknet_deploy' -> 'hello_starknet_contract'

* Rename 'cairo1_hello_starknet_abi' -> 'hello_starknet_abi'

* Remove unnecessary name

* Update 'load_contract'  function argument

* Update 'erc20_contract' name

* Remove unnecessary argument

* Rename 'argent_cairo1_account_class_hash' -> 'argent_account_class_hash'

* Rename function 'declare_cairo1_contract' to 'declare_contract'

* Rename 'declare_cairo1_account' -> 'account_declare_class_hash'

* Rename 'argent_cairo1_account' -> 'argent_account'

* Remove 'cairo1' word from a few tests

* Remove default cairo version param.

* Remove unnecessary argument name
  • Loading branch information
kkawula authored Sep 3, 2024
1 parent fed2346 commit 1447509
Show file tree
Hide file tree
Showing 14 changed files with 242 additions and 279 deletions.
24 changes: 12 additions & 12 deletions starknet_py/tests/e2e/account/account_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -703,8 +703,8 @@ async def test_sign_deploy_account_v1_for_fee_estimation(


@pytest.mark.asyncio
async def test_sign_transaction_custom_nonce(account, cairo1_hello_starknet_class_hash):
deployment = Deployer().create_contract_deployment(cairo1_hello_starknet_class_hash)
async def test_sign_transaction_custom_nonce(account, hello_starknet_class_hash):
deployment = Deployer().create_contract_deployment(hello_starknet_class_hash)
deploy_tx = await account.sign_invoke_v1(deployment.call, max_fee=MAX_FEE)

new_balance = 30
Expand Down Expand Up @@ -733,13 +733,13 @@ async def test_sign_transaction_custom_nonce(account, cairo1_hello_starknet_clas


@pytest.mark.asyncio
async def test_argent_cairo1_account_deploy(
async def test_argent_account_deploy(
client,
argent_cairo1_account_class_hash,
argent_account_class_hash,
deploy_account_details_factory,
):
address, key_pair, salt, class_hash = await deploy_account_details_factory.get(
class_hash=argent_cairo1_account_class_hash, argent_calldata=True
class_hash=argent_account_class_hash, argent_calldata=True
)

deploy_result = await Account.deploy_account_v1(
Expand All @@ -765,17 +765,17 @@ async def test_argent_cairo1_account_deploy(


@pytest.mark.asyncio
async def test_argent_cairo1_account_execute(
async def test_argent_account_execute(
deployed_balance_contract,
argent_cairo1_account: BaseAccount,
argent_account: BaseAccount,
):
# verify that initial balance is 0
get_balance_call = Call(
to_addr=deployed_balance_contract.address,
selector=get_selector_from_name("get_balance"),
calldata=[],
)
get_balance = await argent_cairo1_account.client.call_contract(
get_balance = await argent_account.client.call_contract(
call=get_balance_call, block_number="latest"
)

Expand All @@ -787,11 +787,11 @@ async def test_argent_cairo1_account_execute(
selector=get_selector_from_name("increase_balance"),
calldata=[value],
)
execute = await argent_cairo1_account.execute_v1(
execute = await argent_account.execute_v1(
calls=increase_balance_by_20_call, max_fee=MAX_FEE
)
await argent_cairo1_account.client.wait_for_tx(tx_hash=execute.transaction_hash)
receipt = await argent_cairo1_account.client.get_transaction_receipt(
await argent_account.client.wait_for_tx(tx_hash=execute.transaction_hash)
receipt = await argent_account.client.get_transaction_receipt(
tx_hash=execute.transaction_hash
)

Expand All @@ -803,7 +803,7 @@ async def test_argent_cairo1_account_execute(
selector=get_selector_from_name("get_balance"),
calldata=[],
)
get_balance = await argent_cairo1_account.client.call_contract(
get_balance = await argent_account.client.call_contract(
call=get_balance_call, block_number="latest"
)

Expand Down
19 changes: 8 additions & 11 deletions starknet_py/tests/e2e/client/client_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# pylint: disable=too-many-arguments
from typing import Tuple
from unittest.mock import AsyncMock, Mock, patch

import pytest
Expand Down Expand Up @@ -525,11 +524,9 @@ async def test_state_update_deployed_contracts(


@pytest.mark.asyncio
async def test_get_class_by_hash_sierra_program(
client, cairo1_hello_starknet_class_hash: int
):
async def test_get_class_by_hash_sierra_program(client, hello_starknet_class_hash: int):
contract_class = await client.get_class_by_hash(
class_hash=cairo1_hello_starknet_class_hash
class_hash=hello_starknet_class_hash
)

assert isinstance(contract_class.parsed_abi, list)
Expand All @@ -543,10 +540,10 @@ async def test_get_class_by_hash_sierra_program(
@pytest.mark.asyncio
async def test_get_declare_v2_transaction(
client,
cairo1_hello_starknet_class_hash_tx_hash: Tuple[int, int],
hello_starknet_class_hash_tx_hash,
declare_v2_hello_starknet: DeclareV2,
):
(class_hash, tx_hash) = cairo1_hello_starknet_class_hash_tx_hash
(class_hash, tx_hash) = hello_starknet_class_hash_tx_hash

transaction = await client.get_transaction(tx_hash=tx_hash)

Expand All @@ -566,11 +563,11 @@ async def test_get_declare_v2_transaction(
@pytest.mark.asyncio
async def test_get_block_with_declare_v2(
client,
cairo1_hello_starknet_class_hash_tx_hash: Tuple[int, int],
hello_starknet_class_hash_tx_hash,
declare_v2_hello_starknet: DeclareV2,
block_with_declare_v2_number: int,
):
(class_hash, tx_hash) = cairo1_hello_starknet_class_hash_tx_hash
(class_hash, tx_hash) = hello_starknet_class_hash_tx_hash

block = await client.get_block(block_number=block_with_declare_v2_number)

Expand All @@ -593,7 +590,7 @@ async def test_get_block_with_declare_v2(
@pytest.mark.asyncio
async def test_get_new_state_update(
client,
cairo1_hello_starknet_class_hash: int,
hello_starknet_class_hash: int,
declare_v2_hello_starknet: DeclareV2,
block_with_declare_v2_number: int,
):
Expand All @@ -603,7 +600,7 @@ async def test_get_new_state_update(
assert state_update_first.state_diff.replaced_classes == []
assert (
DeclaredContractHash(
class_hash=cairo1_hello_starknet_class_hash,
class_hash=hello_starknet_class_hash,
compiled_class_hash=declare_v2_hello_starknet.compiled_class_hash,
)
in state_update_first.state_diff.declared_classes
Expand Down
4 changes: 2 additions & 2 deletions starknet_py/tests/e2e/client/fixtures/prepare_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
)
from starknet_py.tests.e2e.fixtures.accounts import AccountToBeDeployedDetailsFactory
from starknet_py.tests.e2e.fixtures.constants import MAX_RESOURCE_BOUNDS_L1
from starknet_py.tests.e2e.fixtures.contracts_v1 import declare_cairo1_contract
from starknet_py.tests.e2e.fixtures.contracts_v1 import declare_contract
from starknet_py.tests.e2e.fixtures.misc import load_contract


@pytest_asyncio.fixture(scope="package")
async def balance_class_and_transaction_hash(account: BaseAccount) -> Tuple[int, int]:
contract = load_contract("Balance")
class_hash, transaction_hash = await declare_cairo1_contract(
class_hash, transaction_hash = await declare_contract(
account,
contract["sierra"],
contract["casm"],
Expand Down
12 changes: 4 additions & 8 deletions starknet_py/tests/e2e/client/fixtures/transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ def block_with_deploy_account_number(

@pytest_asyncio.fixture(scope="package")
async def hello_starknet_deploy_transaction_address(
account: Account, cairo1_hello_starknet_class_hash
account: Account, hello_starknet_class_hash
) -> int:
deployer = Deployer()
contract_deployment = deployer.create_contract_deployment_raw(
class_hash=cairo1_hello_starknet_class_hash
class_hash=hello_starknet_class_hash
)
deploy_invoke_transaction = await account.sign_invoke_v1(
calls=contract_deployment.call, max_fee=MAX_FEE
Expand All @@ -83,13 +83,9 @@ async def hello_starknet_deploy_transaction_address(


@pytest_asyncio.fixture(scope="package")
async def block_with_declare_v2_number(
cairo1_hello_starknet_tx_hash: int, client
) -> int:
async def block_with_declare_v2_number(hello_starknet_tx_hash: int, client) -> int:
"""
Returns number of the block with DeclareV2 transaction
"""
declare_v2_receipt = await client.get_transaction_receipt(
cairo1_hello_starknet_tx_hash
)
declare_v2_receipt = await client.get_transaction_receipt(hello_starknet_tx_hash)
return declare_v2_receipt.block_number
10 changes: 6 additions & 4 deletions starknet_py/tests/e2e/client_devnet/fixtures/contracts.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import pytest_asyncio

from starknet_py.contract import Contract
from starknet_py.tests.e2e.fixtures.contracts import deploy_v1_contract
from starknet_py.tests.e2e.fixtures.contracts_v1 import declare_cairo1_contract
from starknet_py.tests.e2e.fixtures.contracts_v1 import (
declare_contract,
deploy_v1_contract,
)
from starknet_py.tests.e2e.fixtures.misc import load_contract


@pytest_asyncio.fixture(scope="package", name="f_string_contract_class_hash")
async def declare_string_contract(account_forked_devnet) -> int:
contract = load_contract("MyString")
class_hash, _ = await declare_cairo1_contract(
class_hash, _ = await declare_contract(
account_forked_devnet, contract["sierra"], contract["casm"]
)
return class_hash
Expand All @@ -29,7 +31,7 @@ async def deploy_string_contract(
@pytest_asyncio.fixture(scope="package", name="l1_l2_contract_class_hash")
async def declare_l1_l2_contract(account) -> int:
contract = load_contract("l1_l2")
class_hash, _ = await declare_cairo1_contract(
class_hash, _ = await declare_contract(
account, contract["sierra"], contract["casm"]
)
return class_hash
Expand Down
18 changes: 9 additions & 9 deletions starknet_py/tests/e2e/contract_interaction/deploy_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
@pytest.mark.asyncio
async def test_declare_deploy_v1(
account,
cairo1_minimal_contract_class_hash: int,
minimal_contract_class_hash: int,
):
compiled_contract = load_contract("MinimalContract")["sierra"]

declare_result = DeclareResult(
_account=account,
_client=account.client,
_cairo_version=1,
class_hash=cairo1_minimal_contract_class_hash,
class_hash=minimal_contract_class_hash,
compiled_contract=compiled_contract,
hash=0,
declare_transaction=Mock(spec=DeclareV2),
Expand All @@ -40,15 +40,15 @@ async def test_declare_deploy_v1(
@pytest.mark.asyncio
async def test_declare_deploy_v3(
account,
cairo1_minimal_contract_class_hash: int,
minimal_contract_class_hash: int,
):
compiled_contract = load_contract("MinimalContract")["sierra"]

declare_result = DeclareResult(
_account=account,
_client=account.client,
_cairo_version=1,
class_hash=cairo1_minimal_contract_class_hash,
class_hash=minimal_contract_class_hash,
compiled_contract=compiled_contract,
hash=0,
declare_transaction=Mock(spec=DeclareV2),
Expand All @@ -65,14 +65,14 @@ async def test_declare_deploy_v3(


@pytest.mark.asyncio
async def test_throws_on_wrong_abi(account, cairo1_minimal_contract_class_hash: int):
async def test_throws_on_wrong_abi(account, minimal_contract_class_hash: int):
compiled_contract = load_contract("MinimalContract")["sierra"]

declare_result = DeclareResult(
_account=account,
_client=account.client,
_cairo_version=1,
class_hash=cairo1_minimal_contract_class_hash,
class_hash=minimal_contract_class_hash,
compiled_contract=compiled_contract,
hash=0,
declare_transaction=Mock(spec=DeclareV2),
Expand All @@ -94,14 +94,14 @@ async def test_throws_on_wrong_abi(account, cairo1_minimal_contract_class_hash:


@pytest.mark.asyncio
async def test_deploy_contract_v1(account, cairo1_hello_starknet_class_hash: int):
async def test_deploy_contract_v1(account, hello_starknet_class_hash: int):
compiled_contract = load_contract("HelloStarknet")["sierra"]
abi = create_sierra_compiled_contract(
compiled_contract=compiled_contract
).parsed_abi

deploy_result = await Contract.deploy_contract_v1(
class_hash=cairo1_hello_starknet_class_hash,
class_hash=hello_starknet_class_hash,
account=account,
abi=abi,
max_fee=MAX_FEE,
Expand All @@ -120,4 +120,4 @@ async def test_deploy_contract_v1(account, cairo1_hello_starknet_class_hash: int
class_hash = await account.client.get_class_hash_at(
contract_address=contract.address
)
assert class_hash == cairo1_hello_starknet_class_hash
assert class_hash == hello_starknet_class_hash
22 changes: 11 additions & 11 deletions starknet_py/tests/e2e/contract_interaction/v1_interaction_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from starknet_py.cairo.felt import decode_shortstring, encode_shortstring
from starknet_py.contract import Contract
from starknet_py.tests.e2e.fixtures.constants import MAX_FEE
from starknet_py.tests.e2e.fixtures.contracts import deploy_v1_contract
from starknet_py.tests.e2e.fixtures.contracts_v1 import deploy_v1_contract

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

Expand All @@ -15,7 +15,7 @@
reason="Contract exists only in v2 directory",
)
@pytest.mark.asyncio
async def test_general_v1_interaction(account, cairo1_erc20_class_hash: int):
async def test_general_v1_interaction(account, erc20_class_hash: int):
calldata = {
"name_": encode_shortstring("erc20_basic"),
"symbol_": encode_shortstring("ERC20B"),
Expand All @@ -26,7 +26,7 @@ async def test_general_v1_interaction(account, cairo1_erc20_class_hash: int):
erc20 = await deploy_v1_contract(
account=account,
contract_name="ERC20",
class_hash=cairo1_erc20_class_hash,
class_hash=erc20_class_hash,
calldata=calldata,
)

Expand Down Expand Up @@ -61,11 +61,11 @@ async def test_general_v1_interaction(account, cairo1_erc20_class_hash: int):
reason="Contract exists only in v2 directory",
)
@pytest.mark.asyncio
async def test_serializing_struct(account, cairo1_token_bridge_class_hash: int):
async def test_serializing_struct(account, token_bridge_class_hash: int):
bridge = await deploy_v1_contract(
account=account,
contract_name="TokenBridge",
class_hash=cairo1_token_bridge_class_hash,
class_hash=token_bridge_class_hash,
calldata={"governor_address": account.address},
)

Expand All @@ -77,11 +77,11 @@ async def test_serializing_struct(account, cairo1_token_bridge_class_hash: int):


@pytest.mark.asyncio
async def test_serializing_option(account, cairo1_test_option_class_hash: int):
async def test_serializing_option(account, test_option_class_hash: int):
test_option = await deploy_v1_contract(
account=account,
contract_name="TestOption",
class_hash=cairo1_test_option_class_hash,
class_hash=test_option_class_hash,
)

(received_option,) = await test_option.functions["get_option_struct"].call()
Expand Down Expand Up @@ -112,11 +112,11 @@ async def test_serializing_option(account, cairo1_test_option_class_hash: int):


@pytest.mark.asyncio
async def test_serializing_enum(account, cairo1_test_enum_class_hash: int):
async def test_serializing_enum(account, test_enum_class_hash: int):
test_enum = await deploy_v1_contract(
account=account,
contract_name="TestEnum",
class_hash=cairo1_test_enum_class_hash,
class_hash=test_enum_class_hash,
)

(received_enum,) = await test_enum.functions["get_enum"].call()
Expand Down Expand Up @@ -153,7 +153,7 @@ async def test_serializing_enum(account, cairo1_test_enum_class_hash: int):
reason="Contract exists only in v2 directory",
)
@pytest.mark.asyncio
async def test_from_address_on_v1_contract(account, cairo1_erc20_class_hash: int):
async def test_from_address_on_v1_contract(account, erc20_class_hash: int):
calldata = {
"name_": encode_shortstring("erc20_basic"),
"symbol_": encode_shortstring("ERC20B"),
Expand All @@ -164,7 +164,7 @@ async def test_from_address_on_v1_contract(account, cairo1_erc20_class_hash: int
erc20 = await deploy_v1_contract(
account=account,
contract_name="ERC20",
class_hash=cairo1_erc20_class_hash,
class_hash=erc20_class_hash,
calldata=calldata,
)

Expand Down
6 changes: 3 additions & 3 deletions starknet_py/tests/e2e/declare/declare_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@


@pytest.mark.asyncio
async def test_declare_v2_tx(cairo1_minimal_contract_class_hash: int):
assert isinstance(cairo1_minimal_contract_class_hash, int)
assert cairo1_minimal_contract_class_hash != 0
async def test_declare_v2_tx(minimal_contract_class_hash: int):
assert isinstance(minimal_contract_class_hash, int)
assert minimal_contract_class_hash != 0


@pytest.mark.asyncio
Expand Down
Loading

0 comments on commit 1447509

Please sign in to comment.