Skip to content

Commit

Permalink
Remove unnecessary cairo 0 tests (#1406)
Browse files Browse the repository at this point in the history
* Remove cairo 0 dependency from 'account' fixture

* Remove 'map_contract' declare test

* Remove 'compute_address' tests

* Remove 'test_broadcasted_txn_declare_v1' test

* Remove 'test_compute_declare_transaction_hash' test

* Remove 'test_sign_declare_transaction' test

* Remove 'test_sign_declare_transaction_auto_estimate' test

* Remove 'test_declare_compress_program' test

* Remove 'test_declare_contract_raises_on_sierra_contract_without_compiled_class_hash' test

* Update 'test_sign_transaction' test to DeclareV3

* Remove 'universal_deployer.cairo' code

* Update 'test_compute_class_hash' test

* Remove 'test_deserialize_proxy_abi' test

* Remove Contract.declare_v1 from docs

* Remove unused functions

* Remove 'test_compute_class_hash' for cairo 0

* Update 'test_general_simplified_deployment_flow' test

* Remove deprecated functionality and 'test_compute_hash' test

* Update 'test_estimate_fee_declare' test

* Update 'test_account_sign_without_execute'

* Remove redundant test 'test_general_simplified_deployment_flow'

* Update 'test_account_get_balance_strk'

* Update 'test_account_get_balance_eth'

* Update 'test_broadcasted_txn_invoke_v1'

* Update 'test_broadcasted_txn_invoke_v3'

* Remove proxy tests

* Remove proxy contracts cairo code

* Remove proxy fixtures

* Remove precompiled cairo 0 contract

* Change reason for test skipping

* Rename 'cairo1_hello_starknet_deploy' fixture
  • Loading branch information
kkawula authored Aug 1, 2024
1 parent 49fbb85 commit ccfeee7
Show file tree
Hide file tree
Showing 29 changed files with 61 additions and 14,289 deletions.
10 changes: 0 additions & 10 deletions starknet_py/abi/v0/parser_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,16 +189,6 @@ def test_missing_type_used(missing_name, input_dict):
AbiParser([input_dict]).parse()


def test_deserialize_proxy_abi():
# Contains all types of ABI apart from structures
abi = json.loads(
read_contract("oz_proxy_abi.json", directory=CONTRACTS_COMPILED_V0_DIR)
)
deserialized = AbiParser(abi).parse()

assert deserialized == fixtures.oz_proxy_abi


def test_deserialize_balance_struct_event_abi():
# Contains all types of ABI apart from structures
abi = json.loads(
Expand Down
1 change: 0 additions & 1 deletion starknet_py/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"starknet_py.tests.e2e.fixtures.misc",
"starknet_py.tests.e2e.fixtures.devnet",
"starknet_py.tests.e2e.fixtures.constants",
"starknet_py.tests.e2e.fixtures.proxy",
"starknet_py.tests.e2e.client.fixtures.transactions",
"starknet_py.tests.e2e.client.fixtures.prepare_network",
"starknet_py.tests.e2e.tests_on_networks.fixtures",
Expand Down
49 changes: 1 addition & 48 deletions starknet_py/contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
from starknet_py.common import create_compiled_contract, create_sierra_compiled_contract
from starknet_py.constants import DEFAULT_DEPLOYER_ADDRESS
from starknet_py.contract_utils import _extract_compiled_class_hash, _unpack_provider
from starknet_py.hash.address import compute_address
from starknet_py.hash.class_hash import compute_class_hash
from starknet_py.hash.selector import get_selector_from_name
from starknet_py.net.account.base_account import BaseAccount
from starknet_py.net.client import Client
Expand All @@ -43,10 +41,7 @@
serializer_for_function,
)
from starknet_py.serialization.factory import serializer_for_function_v1
from starknet_py.utils.constructor_args_translator import (
_is_abi_v2,
translate_constructor_args,
)
from starknet_py.utils.constructor_args_translator import _is_abi_v2
from starknet_py.utils.sync import add_sync_methods

# pylint: disable=too-many-lines
Expand Down Expand Up @@ -1059,48 +1054,6 @@ async def deploy_contract_v3(

return deploy_result

@staticmethod
def compute_address(
salt: int,
compiled_contract: str,
constructor_args: Optional[Union[List, Dict]] = None,
deployer_address: int = 0,
) -> int:
"""
Computes address for given Cairo 0 contract.
:param salt: int
:param compiled_contract: String containing compiled Cairo 0 contract.
:param constructor_args: A ``list`` or ``dict`` of arguments for the constructor.
:param deployer_address: Address of the deployer (if not provided default 0 is used).
:return: Contract's address.
"""

compiled = create_compiled_contract(compiled_contract)
assert compiled.abi is not None
translated_args = translate_constructor_args(
compiled.abi, constructor_args, cairo_version=0
)
return compute_address(
salt=salt,
class_hash=compute_class_hash(compiled),
constructor_calldata=translated_args,
deployer_address=deployer_address,
)

@staticmethod
def compute_contract_hash(compiled_contract: str) -> int:
"""
Computes hash for given contract.
:param compiled_contract: String containing compiled contract.
:return: Class_hash of the contract.
"""

contract_class = create_compiled_contract(compiled_contract)
return compute_class_hash(contract_class)

@classmethod
def _make_functions(
cls,
Expand Down
23 changes: 0 additions & 23 deletions starknet_py/contract_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,6 @@
from starknet_py.net.account.base_account import BaseAccount


def test_compute_hash(balance_contract):
assert (
Contract.compute_contract_hash(balance_contract)
== 0x7A98EAB69A2592EF5D3805990A43525D633DDC42B4D5B2524C7F38B7C59265F
)


def test_compute_address(constructor_with_arguments_compiled):
assert (
Contract.compute_address(
compiled_contract=constructor_with_arguments_compiled,
constructor_args=[
10,
(1, (2, 3)),
[1, 2, 3],
{"value": 12, "nested_struct": {"value": 99}},
],
salt=1111,
)
> 0
)


@pytest.mark.parametrize("param", ["_account", "class_hash", "compiled_contract"])
def test_declare_result_post_init(param, account):
kwargs = {
Expand Down
31 changes: 0 additions & 31 deletions starknet_py/hash/class_hash_test.py

This file was deleted.

20 changes: 0 additions & 20 deletions starknet_py/hash/transaction_test.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import pytest

from starknet_py.common import create_compiled_contract
from starknet_py.hash.transaction import (
CommonTransactionV3Fields,
TransactionHashPrefix,
compute_declare_transaction_hash,
compute_declare_v2_transaction_hash,
compute_declare_v3_transaction_hash,
compute_deploy_account_transaction_hash,
Expand All @@ -14,8 +12,6 @@
compute_transaction_hash,
)
from starknet_py.net.client_models import DAMode, ResourceBounds, ResourceBoundsMapping
from starknet_py.tests.e2e.fixtures.constants import CONTRACTS_COMPILED_V0_DIR
from starknet_py.tests.e2e.fixtures.misc import read_contract


@pytest.fixture(name="default_resource_bounds")
Expand Down Expand Up @@ -77,22 +73,6 @@ def test_compute_deploy_account_transaction_hash(data, expected_hash):
assert compute_deploy_account_transaction_hash(**data) == expected_hash


@pytest.mark.parametrize(
"contract_json, data",
[
("map_compiled.json", [3, 4, 5, 1, 7]),
("balance_compiled.json", [23, 24, 25, 26, 27]),
],
)
def test_compute_declare_transaction_hash(contract_json, data):
contract = read_contract(contract_json, directory=CONTRACTS_COMPILED_V0_DIR)
compiled_contract = create_compiled_contract(compiled_contract=contract)

declare_hash = compute_declare_transaction_hash(compiled_contract, *data)

assert declare_hash > 0


@pytest.mark.parametrize(
"data, expected_hash",
(
Expand Down
13 changes: 7 additions & 6 deletions starknet_py/net/account/account_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,13 @@ async def test_get_balance_default_token_address():


@pytest.mark.asyncio
async def test_account_get_balance_eth(account, map_contract):
async def test_account_get_balance_eth(account, hello_starknet_contract):
balance = await account.get_balance()
block = await account.client.get_block(block_number="latest")

await map_contract.functions["put"].invoke_v1(key=10, value=10, max_fee=MAX_FEE)

await hello_starknet_contract.functions["increase_balance"].invoke_v1(
amount=10, max_fee=MAX_FEE
)
new_balance = await account.get_balance()
old_balance = await account.get_balance(block_number=block.block_number)

Expand All @@ -55,12 +56,12 @@ async def test_account_get_balance_eth(account, map_contract):


@pytest.mark.asyncio
async def test_account_get_balance_strk(account, map_contract):
async def test_account_get_balance_strk(account, hello_starknet_contract):
balance = await account.get_balance(token_address=STRK_FEE_CONTRACT_ADDRESS)
block = await account.client.get_block(block_number="latest")

await map_contract.functions["put"].invoke_v3(
key=10, value=10, l1_resource_bounds=MAX_RESOURCE_BOUNDS_L1
await hello_starknet_contract.functions["increase_balance"].invoke_v3(
amount=10, l1_resource_bounds=MAX_RESOURCE_BOUNDS_L1
)

new_balance = await account.get_balance(token_address=STRK_FEE_CONTRACT_ADDRESS)
Expand Down
32 changes: 12 additions & 20 deletions starknet_py/net/client_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
from starknet_py.net.full_node_client import _to_storage_key
from starknet_py.net.http_client import RpcHttpClient, ServerError
from starknet_py.net.models.transaction import (
DeclareV1,
DeclareV2,
DeclareV3,
DeployAccountV1,
Expand Down Expand Up @@ -128,24 +127,13 @@ async def test_broadcasted_txn_declare_v2(


@pytest.mark.asyncio
async def test_broadcasted_txn_declare_v1(account, map_compiled_contract):
declare_v1 = await account.sign_declare_v1(
compiled_contract=map_compiled_contract,
max_fee=MAX_FEE,
)

brodcasted_txn = _create_broadcasted_txn(declare_v1)

assert brodcasted_txn["type"] == TransactionType.DECLARE.name

expected_keys = dataclasses.fields(DeclareV1)
assert all(key.name in brodcasted_txn for key in expected_keys)


@pytest.mark.asyncio
async def test_broadcasted_txn_invoke_v3(account, map_contract):
async def test_broadcasted_txn_invoke_v3(account, hello_starknet_contract):
invoke_tx = await account.sign_invoke_v3(
calls=Call(map_contract.address, get_selector_from_name("put"), [3, 4]),
calls=Call(
hello_starknet_contract.address,
get_selector_from_name("increaseBalance"),
[10],
),
l1_resource_bounds=MAX_RESOURCE_BOUNDS_L1,
)

Expand All @@ -158,9 +146,13 @@ async def test_broadcasted_txn_invoke_v3(account, map_contract):


@pytest.mark.asyncio
async def test_broadcasted_txn_invoke_v1(account, map_contract):
async def test_broadcasted_txn_invoke_v1(account, hello_starknet_contract):
invoke_tx = await account.sign_invoke_v1(
calls=Call(map_contract.address, get_selector_from_name("put"), [3, 4]),
calls=Call(
hello_starknet_contract.address,
get_selector_from_name("increaseBalance"),
[10],
),
max_fee=int(1e16),
)

Expand Down
31 changes: 0 additions & 31 deletions starknet_py/net/models/transaction_test.py

This file was deleted.

28 changes: 13 additions & 15 deletions starknet_py/net/signer/test_stark_curve_signer.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import pytest

from starknet_py.common import create_compiled_contract
from starknet_py.common import create_sierra_compiled_contract
from starknet_py.net.models import StarknetChainId
from starknet_py.net.models.transaction import DeclareV1, DeployAccountV1, InvokeV1
from starknet_py.net.models.transaction import DeclareV3, DeployAccountV1, InvokeV1
from starknet_py.net.signer.stark_curve_signer import KeyPair, StarkCurveSigner
from starknet_py.tests.e2e.fixtures.constants import CONTRACTS_COMPILED_V0_DIR
from starknet_py.tests.e2e.fixtures.misc import read_contract
from starknet_py.tests.e2e.fixtures.constants import MAX_RESOURCE_BOUNDS
from starknet_py.tests.e2e.fixtures.misc import load_contract

compiled_contract = read_contract(
"erc20_compiled.json", directory=CONTRACTS_COMPILED_V0_DIR
)
compiled_contract = load_contract("HelloStarknet")["sierra"]
sierra_contract_class = create_sierra_compiled_contract(compiled_contract)


@pytest.mark.parametrize(
Expand All @@ -32,15 +31,14 @@
nonce=23,
version=1,
),
DeclareV1(
contract_class=create_compiled_contract(
compiled_contract=compiled_contract
),
sender_address=123,
max_fee=10000,
DeclareV3(
contract_class=sierra_contract_class,
compiled_class_hash=0x1,
sender_address=0x123,
signature=[],
nonce=23,
version=1,
nonce=4,
version=3,
resource_bounds=MAX_RESOURCE_BOUNDS,
),
],
)
Expand Down
Loading

0 comments on commit ccfeee7

Please sign in to comment.