From dd83220317a89c96cdd2e0286a5649460323d181 Mon Sep 17 00:00:00 2001 From: jumpman <57270771+kkawula@users.noreply.github.com> Date: Tue, 30 Jul 2024 12:18:23 +0200 Subject: [PATCH 01/66] Merge branch 'kkawula/1334-remove-unnecessary-cairo-0-tests' --- starknet_py/abi/v0/parser_test.py | 10 -- starknet_py/conftest.py | 1 - starknet_py/contract.py | 49 +------ starknet_py/contract_test.py | 23 ---- starknet_py/hash/class_hash_test.py | 31 ----- starknet_py/hash/transaction_test.py | 20 --- starknet_py/net/account/account_test.py | 13 +- starknet_py/net/client_test.py | 32 ++--- starknet_py/net/models/transaction_test.py | 31 ----- .../net/signer/test_stark_curve_signer.py | 28 ++-- starknet_py/tests/e2e/account/account_test.py | 35 ----- starknet_py/tests/e2e/client/client_test.py | 12 +- .../e2e/contract_interaction/deploy_test.py | 17 --- starknet_py/tests/e2e/declare/declare_test.py | 12 +- .../e2e/docs/code_examples/test_contract.py | 19 --- .../test_account_sign_without_execute.py | 19 ++- .../e2e/docs/guide/test_resolving_proxies.py | 3 + starknet_py/tests/e2e/fixtures/accounts.py | 24 +--- starknet_py/tests/e2e/fixtures/contracts.py | 4 +- starknet_py/tests/e2e/fixtures/proxy.py | 129 ------------------ .../e2e/mock/contracts/argent_proxy.cairo | 73 ---------- .../tests/e2e/mock/contracts/oz_proxy.cairo | 91 ------------ .../e2e/mock/contracts/oz_proxy_custom.cairo | 91 ------------ .../mock/contracts/oz_proxy_impl_func.cairo | 99 -------------- .../mock/contracts/universal_deployer.cairo | 91 ------------ starknet_py/tests/e2e/proxy/__init__.py | 0 starknet_py/tests/e2e/proxy/proxy_test.py | 128 ----------------- 27 files changed, 62 insertions(+), 1023 deletions(-) delete mode 100644 starknet_py/hash/class_hash_test.py delete mode 100644 starknet_py/net/models/transaction_test.py delete mode 100644 starknet_py/tests/e2e/fixtures/proxy.py delete mode 100644 starknet_py/tests/e2e/mock/contracts/argent_proxy.cairo delete mode 100644 starknet_py/tests/e2e/mock/contracts/oz_proxy.cairo delete mode 100644 starknet_py/tests/e2e/mock/contracts/oz_proxy_custom.cairo delete mode 100644 starknet_py/tests/e2e/mock/contracts/oz_proxy_impl_func.cairo delete mode 100644 starknet_py/tests/e2e/mock/contracts/universal_deployer.cairo delete mode 100644 starknet_py/tests/e2e/proxy/__init__.py delete mode 100644 starknet_py/tests/e2e/proxy/proxy_test.py diff --git a/starknet_py/abi/v0/parser_test.py b/starknet_py/abi/v0/parser_test.py index 0509ea295..b20e3d958 100644 --- a/starknet_py/abi/v0/parser_test.py +++ b/starknet_py/abi/v0/parser_test.py @@ -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( diff --git a/starknet_py/conftest.py b/starknet_py/conftest.py index 396dad738..46289f528 100644 --- a/starknet_py/conftest.py +++ b/starknet_py/conftest.py @@ -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", diff --git a/starknet_py/contract.py b/starknet_py/contract.py index 0ce1d0369..d250938b2 100644 --- a/starknet_py/contract.py +++ b/starknet_py/contract.py @@ -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 @@ -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 @@ -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, diff --git a/starknet_py/contract_test.py b/starknet_py/contract_test.py index 275edab2f..313f6e3c4 100644 --- a/starknet_py/contract_test.py +++ b/starknet_py/contract_test.py @@ -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 = { diff --git a/starknet_py/hash/class_hash_test.py b/starknet_py/hash/class_hash_test.py deleted file mode 100644 index 58d60197d..000000000 --- a/starknet_py/hash/class_hash_test.py +++ /dev/null @@ -1,31 +0,0 @@ -# pylint: disable=line-too-long -# fmt: off -import copy - -import pytest - -from starknet_py.common import create_contract_class -from starknet_py.hash.class_hash import compute_class_hash -from starknet_py.tests.e2e.fixtures.constants import CONTRACTS_COMPILED_V0_DIR -from starknet_py.tests.e2e.fixtures.misc import read_contract - - -@pytest.mark.parametrize( - "contract_source, expected_class_hash", [ - ("balance_compiled.json", 0x7a98eab69a2592ef5d3805990a43525d633ddc42b4d5b2524c7f38b7c59265f), - ("map_compiled.json", 0x5eefff2c17c81fb81b1c34d2a9f324e7baf8c3099165b94d037a84b74b6900e), - ("erc20_compiled.json", 0x2c709fc176283331897d0c5f113ba64b00e1530c3e91103dcf1b05a056b1aa1), - ("oz_proxy_compiled.json", 0x382f95037fa7983ff69465b9d3f7394ce336870631066de682cf547dc1899dd), - ("argent_proxy_compiled.json", 0x743aa3636b7c795931e9c4ed56dc57e7edda223a66c09df04fda40f9ba4cd53), - ("universal_deployer_compiled.json", 0x710bb1f5ef7f208249a370372a7586b72a759fbd2923013b14bd7f2e51bc4c), - ("precompiled/oz_proxy_address_0.8.1_compiled.json", 0x413c36c287cb410d42f9e531563f68ac60a2913b5053608d640fb9b643acfe6), - ] -) -def test_compute_class_hash(contract_source, expected_class_hash): - compiled_contract = read_contract(contract_source, directory=CONTRACTS_COMPILED_V0_DIR) - contract_class = create_contract_class(compiled_contract) - initial_contract_class = copy.deepcopy(contract_class) - class_hash = compute_class_hash(contract_class) - - assert class_hash == expected_class_hash - assert contract_class == initial_contract_class diff --git a/starknet_py/hash/transaction_test.py b/starknet_py/hash/transaction_test.py index f255622ce..ed6c39f16 100644 --- a/starknet_py/hash/transaction_test.py +++ b/starknet_py/hash/transaction_test.py @@ -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, @@ -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") @@ -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", ( diff --git a/starknet_py/net/account/account_test.py b/starknet_py/net/account/account_test.py index 51a064341..ef559daaf 100644 --- a/starknet_py/net/account/account_test.py +++ b/starknet_py/net/account/account_test.py @@ -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, cairo1_hello_starknet_deploy): 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 cairo1_hello_starknet_deploy.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) @@ -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, cairo1_hello_starknet_deploy): 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 cairo1_hello_starknet_deploy.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) diff --git a/starknet_py/net/client_test.py b/starknet_py/net/client_test.py index 33fe39916..062219e05 100644 --- a/starknet_py/net/client_test.py +++ b/starknet_py/net/client_test.py @@ -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, @@ -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, cairo1_hello_starknet_deploy): invoke_tx = await account.sign_invoke_v3( - calls=Call(map_contract.address, get_selector_from_name("put"), [3, 4]), + calls=Call( + cairo1_hello_starknet_deploy.address, + get_selector_from_name("increaseBalance"), + [10], + ), l1_resource_bounds=MAX_RESOURCE_BOUNDS_L1, ) @@ -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, cairo1_hello_starknet_deploy): invoke_tx = await account.sign_invoke_v1( - calls=Call(map_contract.address, get_selector_from_name("put"), [3, 4]), + calls=Call( + cairo1_hello_starknet_deploy.address, + get_selector_from_name("increaseBalance"), + [10], + ), max_fee=int(1e16), ) diff --git a/starknet_py/net/models/transaction_test.py b/starknet_py/net/models/transaction_test.py deleted file mode 100644 index cba6dfc82..000000000 --- a/starknet_py/net/models/transaction_test.py +++ /dev/null @@ -1,31 +0,0 @@ -import re -import typing -from typing import cast - -from starknet_py.common import create_contract_class -from starknet_py.net.models.transaction import Declare, DeclareV1, DeclareV1Schema - - -def test_declare_compress_program(balance_contract): - contract_class = create_contract_class(balance_contract) - declare_transaction = DeclareV1( - contract_class=contract_class, - sender_address=0x1234, - max_fee=0x1111, - nonce=0x1, - signature=[0x1, 0x2], - version=1, - ) - - schema = DeclareV1Schema() - - serialized = typing.cast(dict, schema.dump(declare_transaction)) - # Pattern used in match taken from - # https://github.com/starkware-libs/starknet-specs/blob/df8cfb3da309f3d5dd08d804961e5a9ab8774945/api/starknet_api_openrpc.json#L1943 - assert re.match( - r"^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{2}==)?$", - serialized["contract_class"]["program"], - ) - - deserialized = cast(Declare, schema.load(serialized)) - assert deserialized.contract_class == contract_class diff --git a/starknet_py/net/signer/test_stark_curve_signer.py b/starknet_py/net/signer/test_stark_curve_signer.py index 8419ab012..423b7b54c 100644 --- a/starknet_py/net/signer/test_stark_curve_signer.py +++ b/starknet_py/net/signer/test_stark_curve_signer.py @@ -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( @@ -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, ), ], ) diff --git a/starknet_py/tests/e2e/account/account_test.py b/starknet_py/tests/e2e/account/account_test.py index f86458133..dc936887e 100644 --- a/starknet_py/tests/e2e/account/account_test.py +++ b/starknet_py/tests/e2e/account/account_test.py @@ -26,7 +26,6 @@ from starknet_py.net.full_node_client import FullNodeClient from starknet_py.net.models import StarknetChainId from starknet_py.net.models.transaction import ( - DeclareV1, DeclareV2, DeclareV3, DeployAccountV3, @@ -287,28 +286,6 @@ async def test_sign_invoke_v3_auto_estimate(account, map_contract): assert signed_tx.resource_bounds.l2_gas == ResourceBounds.init_with_zeros() -@pytest.mark.asyncio -async def test_sign_declare_transaction(account, map_compiled_contract): - signed_tx = await account.sign_declare_v1(map_compiled_contract, max_fee=MAX_FEE) - - assert isinstance(signed_tx, DeclareV1) - assert signed_tx.version == 1 - assert isinstance(signed_tx.signature, list) - assert len(signed_tx.signature) > 0 - assert signed_tx.max_fee == MAX_FEE - - -@pytest.mark.asyncio -async def test_sign_declare_transaction_auto_estimate(account, map_compiled_contract): - signed_tx = await account.sign_declare_v1(map_compiled_contract, auto_estimate=True) - - assert isinstance(signed_tx, DeclareV1) - assert signed_tx.version == 1 - assert isinstance(signed_tx.signature, list) - assert len(signed_tx.signature) > 0 - assert signed_tx.max_fee > 0 - - @pytest.mark.asyncio async def test_sign_declare_v2( account, sierra_minimal_compiled_contract_and_class_hash @@ -402,18 +379,6 @@ async def test_sign_declare_v3_auto_estimate( assert signed_tx.resource_bounds.l2_gas == ResourceBounds.init_with_zeros() -@pytest.mark.asyncio -async def test_declare_contract_raises_on_sierra_contract_without_compiled_class_hash( - account, sierra_minimal_compiled_contract_and_class_hash -): - compiled_contract, _ = sierra_minimal_compiled_contract_and_class_hash - with pytest.raises( - ValueError, - match="Signing sierra contracts requires using `sign_declare_v2` method.", - ): - await account.sign_declare_v1(compiled_contract=compiled_contract) - - @pytest.mark.asyncio async def test_sign_deploy_account_transaction(account): class_hash = 0x1234 diff --git a/starknet_py/tests/e2e/client/client_test.py b/starknet_py/tests/e2e/client/client_test.py index 851708c3e..0ab08c8ba 100644 --- a/starknet_py/tests/e2e/client/client_test.py +++ b/starknet_py/tests/e2e/client/client_test.py @@ -181,13 +181,15 @@ async def test_estimate_fee_invoke_v3(account, contract_address): @pytest.mark.asyncio -async def test_estimate_fee_declare(account): - declare_tx = await account.sign_declare_v1( - compiled_contract=read_contract( - "map_compiled.json", directory=CONTRACTS_COMPILED_V0_DIR - ), +async def test_estimate_fee_declare( + account, abi_types_compiled_contract_and_class_hash +): + declare_tx = await account.sign_declare_v2( + compiled_contract=abi_types_compiled_contract_and_class_hash[0], + compiled_class_hash=abi_types_compiled_contract_and_class_hash[1], max_fee=MAX_FEE, ) + declare_tx = await account.sign_for_fee_estimate(declare_tx) estimate_fee = await account.client.estimate_fee(tx=declare_tx) diff --git a/starknet_py/tests/e2e/contract_interaction/deploy_test.py b/starknet_py/tests/e2e/contract_interaction/deploy_test.py index e2d4ab85c..72c20100a 100644 --- a/starknet_py/tests/e2e/contract_interaction/deploy_test.py +++ b/starknet_py/tests/e2e/contract_interaction/deploy_test.py @@ -121,20 +121,3 @@ async def test_deploy_contract_v1(account, cairo1_hello_starknet_class_hash: int contract_address=contract.address ) assert class_hash == cairo1_hello_starknet_class_hash - - -@pytest.mark.asyncio -async def test_general_simplified_deployment_flow(account, map_compiled_contract): - declare_result = await Contract.declare_v1( - account=account, - compiled_contract=map_compiled_contract, - max_fee=MAX_FEE, - ) - await declare_result.wait_for_acceptance() - deployment = await declare_result.deploy_v1(max_fee=MAX_FEE) - await deployment.wait_for_acceptance() - - contract = deployment.deployed_contract - - assert isinstance(contract.address, int) - assert len(contract.functions) != 0 diff --git a/starknet_py/tests/e2e/declare/declare_test.py b/starknet_py/tests/e2e/declare/declare_test.py index bc9ffeb2e..9ed4f246a 100644 --- a/starknet_py/tests/e2e/declare/declare_test.py +++ b/starknet_py/tests/e2e/declare/declare_test.py @@ -2,17 +2,7 @@ from starknet_py.net.client_models import TransactionExecutionStatus from starknet_py.net.models.transaction import DeclareV3 -from starknet_py.tests.e2e.fixtures.constants import MAX_FEE, MAX_RESOURCE_BOUNDS_L1 - - -@pytest.mark.asyncio -async def test_declare_tx(account, map_compiled_contract): - declare_tx = await account.sign_declare_v1( - compiled_contract=map_compiled_contract, max_fee=MAX_FEE - ) - result = await account.client.declare(declare_tx) - - await account.client.wait_for_tx(tx_hash=result.transaction_hash) +from starknet_py.tests.e2e.fixtures.constants import MAX_RESOURCE_BOUNDS_L1 @pytest.mark.asyncio diff --git a/starknet_py/tests/e2e/docs/code_examples/test_contract.py b/starknet_py/tests/e2e/docs/code_examples/test_contract.py index e969794cd..f053f0e1f 100644 --- a/starknet_py/tests/e2e/docs/code_examples/test_contract.py +++ b/starknet_py/tests/e2e/docs/code_examples/test_contract.py @@ -53,16 +53,6 @@ async def test_from_address(account, contract_address): # docs-end: from_address -@pytest.mark.asyncio -async def test_declare_v1(account, custom_proxy): - compiled_contract = custom_proxy - # docs-start: declare_v1 - declare_result = await Contract.declare_v1( - account=account, compiled_contract=compiled_contract, max_fee=int(1e15) - ) - # docs-end: declare_v1 - - @pytest.mark.asyncio async def test_declare_v2(account): compiled_contract = load_contract( @@ -173,12 +163,3 @@ async def test_deploy_contract_v3(account, cairo1_hello_starknet_class_hash: int contract_address=contract.address ) assert class_hash == cairo1_hello_starknet_class_hash - - -def test_compute_address(custom_proxy): - compiled_contract = custom_proxy - # docs-start: compute_address - address = Contract.compute_address( - salt=1, compiled_contract=compiled_contract, constructor_args=[1, 2, [2]] - ) - # docs-end: compute_address diff --git a/starknet_py/tests/e2e/docs/guide/test_account_sign_without_execute.py b/starknet_py/tests/e2e/docs/guide/test_account_sign_without_execute.py index 02505fa59..f937db3b3 100644 --- a/starknet_py/tests/e2e/docs/guide/test_account_sign_without_execute.py +++ b/starknet_py/tests/e2e/docs/guide/test_account_sign_without_execute.py @@ -1,16 +1,21 @@ import pytest from starknet_py.net.account.account import Account -from starknet_py.net.models.transaction import DeclareV1, DeployAccountV1, InvokeV1 +from starknet_py.net.models.transaction import DeclareV2, DeployAccountV1, InvokeV1 @pytest.mark.asyncio -async def test_account_sign_without_execute(account, map_compiled_contract): +async def test_account_sign_without_execute( + account, sierra_minimal_compiled_contract_and_class_hash +): # pylint: disable=import-outside-toplevel assert isinstance(account, Account) address = selector = class_hash = salt = 0x1 calldata = [] - compiled_contract = map_compiled_contract + ( + compiled_contract, + compiled_class_hash, + ) = sierra_minimal_compiled_contract_and_class_hash max_fee = 100000 # docs: start @@ -21,8 +26,10 @@ async def test_account_sign_without_execute(account, map_compiled_contract): invoke_transaction = await account.sign_invoke_v1(call, max_fee=max_fee) # Create a signed Declare transaction - declare_transaction = await account.sign_declare_v1( - compiled_contract=compiled_contract, max_fee=max_fee + declare_transaction = await account.sign_declare_v2( + compiled_contract, + compiled_class_hash=compiled_class_hash, + auto_estimate=True, ) # Create a signed DeployAccount transaction @@ -35,5 +42,5 @@ async def test_account_sign_without_execute(account, map_compiled_contract): # docs: end assert isinstance(invoke_transaction, InvokeV1) - assert isinstance(declare_transaction, DeclareV1) + assert isinstance(declare_transaction, DeclareV2) assert isinstance(deploy_account_transaction, DeployAccountV1) diff --git a/starknet_py/tests/e2e/docs/guide/test_resolving_proxies.py b/starknet_py/tests/e2e/docs/guide/test_resolving_proxies.py index 8205574de..a5ee049cb 100644 --- a/starknet_py/tests/e2e/docs/guide/test_resolving_proxies.py +++ b/starknet_py/tests/e2e/docs/guide/test_resolving_proxies.py @@ -10,6 +10,9 @@ from starknet_py.proxy.proxy_check import ArgentProxyCheck, ProxyCheck +@pytest.mark.skip( + reason="This functionality is deprecated. Should be removed in the future." +) @pytest.mark.asyncio async def test_resolving_proxies( account, diff --git a/starknet_py/tests/e2e/fixtures/accounts.py b/starknet_py/tests/e2e/fixtures/accounts.py index 239301969..8983d6a64 100644 --- a/starknet_py/tests/e2e/fixtures/accounts.py +++ b/starknet_py/tests/e2e/fixtures/accounts.py @@ -79,31 +79,13 @@ async def mint_token_on_devnet(url: str, address: int, amount: int, unit: str): ) -@pytest_asyncio.fixture(scope="package") -async def address_and_private_key( - pre_deployed_account_with_validate_deploy: BaseAccount, - account_with_validate_deploy_class_hash: int, - devnet, -) -> Tuple[str, str]: - """ - Returns address and private key of an account, depending on the network. - """ - - return await devnet_account_details( - pre_deployed_account_with_validate_deploy, - account_with_validate_deploy_class_hash, - devnet, - ) - - @pytest.fixture(name="account", scope="package") -def full_node_account( - address_and_private_key: Tuple[str, str], client: FullNodeClient -) -> BaseAccount: +def full_node_account(client: FullNodeClient) -> BaseAccount: """ Returns a new Account created with FullNodeClient. """ - address, private_key = address_and_private_key + address = DEVNET_PRE_DEPLOYED_ACCOUNT_ADDRESS + private_key = DEVNET_PRE_DEPLOYED_ACCOUNT_PRIVATE_KEY return Account( address=address, diff --git a/starknet_py/tests/e2e/fixtures/contracts.py b/starknet_py/tests/e2e/fixtures/contracts.py index 453e16fd3..42ce69d7c 100644 --- a/starknet_py/tests/e2e/fixtures/contracts.py +++ b/starknet_py/tests/e2e/fixtures/contracts.py @@ -339,7 +339,7 @@ async def account_with_validate_deploy_class_hash( @pytest_asyncio.fixture(scope="package") async def argent_cairo1_account_class_hash( - pre_deployed_account_with_validate_deploy: BaseAccount, + account: BaseAccount, ) -> int: # Use precompiled argent account contracts # we don't have the source code for this contract @@ -350,7 +350,7 @@ async def argent_cairo1_account_class_hash( "argent_account.casm", directory=PRECOMPILED_CONTRACTS_DIR ) return await declare_cairo1_account( - account=pre_deployed_account_with_validate_deploy, + account=account, compiled_account_contract=compiled_contract, compiled_account_contract_casm=compiled_contract_casm, ) diff --git a/starknet_py/tests/e2e/fixtures/proxy.py b/starknet_py/tests/e2e/fixtures/proxy.py deleted file mode 100644 index 12f4e8ac9..000000000 --- a/starknet_py/tests/e2e/fixtures/proxy.py +++ /dev/null @@ -1,129 +0,0 @@ -# pylint: disable=redefined-outer-name - -import pytest -import pytest_asyncio - -from starknet_py.contract import Contract, DeployResult -from starknet_py.hash.selector import get_selector_from_name -from starknet_py.net.account.account import Account -from starknet_py.tests.e2e.fixtures.constants import CONTRACTS_COMPILED_V0_DIR, MAX_FEE -from starknet_py.tests.e2e.fixtures.misc import read_contract - - -@pytest.fixture( - params=["argent_proxy_compiled.json", "oz_proxy_compiled.json"], - scope="session", -) -def compiled_proxy(request) -> str: - """ - Returns source code of compiled proxy contract. - """ - return read_contract(request.param, directory=CONTRACTS_COMPILED_V0_DIR) - - -@pytest.fixture(scope="session") -def custom_proxy() -> str: - """ - Returns compiled source code of a custom proxy. - """ - return read_contract( - "oz_proxy_custom_compiled.json", directory=CONTRACTS_COMPILED_V0_DIR - ) - - -@pytest.fixture( - scope="session", - params=[ - "precompiled/oz_proxy_address_0.8.1_compiled.json", - ], -) -def old_proxy(request) -> str: - """ - Returns compiled (using starknet-compile 0.8.1) source code of proxy using address and delegate_call. - """ - return read_contract(request.param, directory=CONTRACTS_COMPILED_V0_DIR) - - -@pytest_asyncio.fixture( - name="proxy_oz_argent", - params=[ - ("oz_proxy_compiled.json", "map_compiled.json"), - ("argent_proxy_compiled.json", "map_compiled.json"), - ], -) -async def deploy_proxy_to_contract_oz_argent_eth( - request, account: Account -) -> DeployResult: - """ - Declares a contract and deploys a proxy (OZ, Argent, Eth) pointing to that contract. - """ - compiled_proxy_name, compiled_contract_name = request.param - return await deploy_proxy_to_contract( - compiled_proxy_name, compiled_contract_name, account - ) - - -@pytest_asyncio.fixture( - name="proxy_custom", params=[("oz_proxy_custom_compiled.json", "map_compiled.json")] -) -async def deploy_proxy_to_contract_custom(request, account: Account) -> DeployResult: - """ - Declares a contract and deploys a custom proxy pointing to that contract. - """ - compiled_proxy_name, compiled_contract_name = request.param - return await deploy_proxy_to_contract( - compiled_proxy_name, compiled_contract_name, account - ) - - -@pytest_asyncio.fixture( - name="proxy_impl_func", - params=[("oz_proxy_impl_func_compiled.json", "map_compiled.json")], -) -async def deploy_proxy_to_contract_impl_func(request, account: Account) -> DeployResult: - """ - Declares a contract and deploys a custom proxy pointing to that contract. - """ - compiled_proxy_name, compiled_contract_name = request.param - return await deploy_proxy_to_contract( - compiled_proxy_name, compiled_contract_name, account - ) - - -async def deploy_proxy_to_contract( - compiled_proxy_name: str, - compiled_contract_name: str, - account: Account, -) -> DeployResult: - """ - Declares a contract and deploys a proxy pointing to that contract. - """ - compiled_proxy = read_contract( - compiled_proxy_name, directory=CONTRACTS_COMPILED_V0_DIR - ) - compiled_contract = read_contract( - compiled_contract_name, directory=CONTRACTS_COMPILED_V0_DIR - ) - - declare_tx = await account.sign_declare_v1( - compiled_contract=compiled_contract, max_fee=MAX_FEE - ) - declare_result = await account.client.declare(declare_tx) - await account.client.wait_for_tx(declare_result.transaction_hash) - - declare_proxy_result = await Contract.declare_v1( - account=account, - compiled_contract=compiled_proxy, - max_fee=MAX_FEE, - ) - await declare_proxy_result.wait_for_acceptance() - deploy_result = await declare_proxy_result.deploy_v1( - constructor_args=[ - declare_result.class_hash, - get_selector_from_name("put"), - [69, 420], - ], - max_fee=MAX_FEE, - ) - await deploy_result.wait_for_acceptance() - return deploy_result diff --git a/starknet_py/tests/e2e/mock/contracts/argent_proxy.cairo b/starknet_py/tests/e2e/mock/contracts/argent_proxy.cairo deleted file mode 100644 index 691b304da..000000000 --- a/starknet_py/tests/e2e/mock/contracts/argent_proxy.cairo +++ /dev/null @@ -1,73 +0,0 @@ -%lang starknet - -from starkware.cairo.common.cairo_builtins import HashBuiltin -from starkware.starknet.common.syscalls import library_call, library_call_l1_handler - -from contracts.upgrade.Upgradable import _get_implementation, _set_implementation - -///////////////////// -// CONSTRUCTOR -///////////////////// - -@constructor -func constructor{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( - implementation: felt, selector: felt, calldata_len: felt, calldata: felt* -) { - _set_implementation(implementation); - library_call( - class_hash=implementation, - function_selector=selector, - calldata_size=calldata_len, - calldata=calldata, - ); - return (); -} - -///////////////////// -// EXTERNAL FUNCTIONS -///////////////////// - -@external -@raw_input -@raw_output -func __default__{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( - selector: felt, calldata_size: felt, calldata: felt* -) -> (retdata_size: felt, retdata: felt*) { - let (implementation) = _get_implementation(); - - let (retdata_size: felt, retdata: felt*) = library_call( - class_hash=implementation, - function_selector=selector, - calldata_size=calldata_size, - calldata=calldata, - ); - return (retdata_size=retdata_size, retdata=retdata); -} - -@l1_handler -@raw_input -func __l1_default__{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( - selector: felt, calldata_size: felt, calldata: felt* -) { - let (implementation) = _get_implementation(); - - library_call_l1_handler( - class_hash=implementation, - function_selector=selector, - calldata_size=calldata_size, - calldata=calldata, - ); - return (); -} - -///////////////////// -// VIEW FUNCTIONS -///////////////////// - -@view -func get_implementation{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}() -> ( - implementation: felt -) { - let (implementation) = _get_implementation(); - return (implementation=implementation); -} \ No newline at end of file diff --git a/starknet_py/tests/e2e/mock/contracts/oz_proxy.cairo b/starknet_py/tests/e2e/mock/contracts/oz_proxy.cairo deleted file mode 100644 index 99e72ac86..000000000 --- a/starknet_py/tests/e2e/mock/contracts/oz_proxy.cairo +++ /dev/null @@ -1,91 +0,0 @@ -// MIT License -// -// Copyright (c) 2021 OpenZeppelin -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. - -%lang starknet - -from starkware.cairo.common.cairo_builtins import HashBuiltin -from starkware.starknet.common.syscalls import library_call, library_call_l1_handler -from openzeppelin.upgrades.library import Proxy - -// @dev Cairo doesn't support native decoding like Solidity yet, -// that's why we pass three arguments for calldata instead of one -// @param implementation_hash the implementation contract hash -// @param selector the implementation initializer function selector -// @param calldata_len the calldata length for the initializer -// @param calldata an array of felt containing the raw calldata -@constructor -func constructor{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( - implementation_hash: felt, selector: felt, - calldata_len: felt, calldata: felt* -) { - alloc_locals; - Proxy._set_implementation_hash(implementation_hash); - - if (selector != 0) { - // Initialize proxy from implementation - library_call( - class_hash=implementation_hash, - function_selector=selector, - calldata_size=calldata_len, - calldata=calldata, - ); - } - - return (); -} - -// -// Fallback functions -// - -@external -@raw_input -@raw_output -func __default__{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( - selector: felt, calldata_size: felt, calldata: felt* -) -> (retdata_size: felt, retdata: felt*) { - let (class_hash) = Proxy.get_implementation_hash(); - - let (retdata_size: felt, retdata: felt*) = library_call( - class_hash=class_hash, - function_selector=selector, - calldata_size=calldata_size, - calldata=calldata, - ); - return (retdata_size, retdata); -} - -@l1_handler -@raw_input -func __l1_default__{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( - selector: felt, calldata_size: felt, calldata: felt* -) { - let (class_hash) = Proxy.get_implementation_hash(); - - library_call_l1_handler( - class_hash=class_hash, - function_selector=selector, - calldata_size=calldata_size, - calldata=calldata, - ); - return (); -} diff --git a/starknet_py/tests/e2e/mock/contracts/oz_proxy_custom.cairo b/starknet_py/tests/e2e/mock/contracts/oz_proxy_custom.cairo deleted file mode 100644 index f5091363b..000000000 --- a/starknet_py/tests/e2e/mock/contracts/oz_proxy_custom.cairo +++ /dev/null @@ -1,91 +0,0 @@ -// MIT License -// -// Copyright (c) 2021 OpenZeppelin -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. - -%lang starknet - -from starkware.cairo.common.cairo_builtins import HashBuiltin -from starkware.starknet.common.syscalls import library_call, library_call_l1_handler -from openzeppelin.upgrades.library_custom import Proxy - -// @dev Cairo doesn't support native decoding like Solidity yet, -// that's why we pass three arguments for calldata instead of one -// @param implementation_hash the implementation contract hash -// @param selector the implementation initializer function selector -// @param calldata_len the calldata length for the initializer -// @param calldata an array of felt containing the raw calldata -@constructor -func constructor{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( - implementation_hash: felt, selector: felt, - calldata_len: felt, calldata: felt* -) { - alloc_locals; - Proxy._set_implementation_hash(implementation_hash); - - if (selector != 0) { - // Initialize proxy from implementation - library_call( - class_hash=implementation_hash, - function_selector=selector, - calldata_size=calldata_len, - calldata=calldata, - ); - } - - return (); -} - -// -// Fallback functions -// - -@external -@raw_input -@raw_output -func __default__{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( - selector: felt, calldata_size: felt, calldata: felt* -) -> (retdata_size: felt, retdata: felt*) { - let (class_hash) = Proxy.get_implementation_hash(); - - let (retdata_size: felt, retdata: felt*) = library_call( - class_hash=class_hash, - function_selector=selector, - calldata_size=calldata_size, - calldata=calldata, - ); - return (retdata_size, retdata); -} - -@l1_handler -@raw_input -func __l1_default__{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( - selector: felt, calldata_size: felt, calldata: felt* -) { - let (class_hash) = Proxy.get_implementation_hash(); - - library_call_l1_handler( - class_hash=class_hash, - function_selector=selector, - calldata_size=calldata_size, - calldata=calldata, - ); - return (); -} diff --git a/starknet_py/tests/e2e/mock/contracts/oz_proxy_impl_func.cairo b/starknet_py/tests/e2e/mock/contracts/oz_proxy_impl_func.cairo deleted file mode 100644 index b81a9519c..000000000 --- a/starknet_py/tests/e2e/mock/contracts/oz_proxy_impl_func.cairo +++ /dev/null @@ -1,99 +0,0 @@ -// MIT License -// -// Copyright (c) 2021 OpenZeppelin -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. - -%lang starknet - -from starkware.cairo.common.cairo_builtins import HashBuiltin -from starkware.starknet.common.syscalls import library_call, library_call_l1_handler -from openzeppelin.upgrades.library import Proxy - -// @dev Cairo doesn't support native decoding like Solidity yet, -// that's why we pass three arguments for calldata instead of one -// @param implementation_hash the implementation contract hash -// @param selector the implementation initializer function selector -// @param calldata_len the calldata length for the initializer -// @param calldata an array of felt containing the raw calldata -@constructor -func constructor{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( - implementation_hash: felt, selector: felt, - calldata_len: felt, calldata: felt* -) { - alloc_locals; - Proxy._set_implementation_hash(implementation_hash); - - if (selector != 0) { - // Initialize proxy from implementation - library_call( - class_hash=implementation_hash, - function_selector=selector, - calldata_size=calldata_len, - calldata=calldata, - ); - } - - return (); -} - -// -// Fallback functions -// - -@external -@raw_input -@raw_output -func __default__{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( - selector: felt, calldata_size: felt, calldata: felt* -) -> (retdata_size: felt, retdata: felt*) { - let (class_hash) = Proxy.get_implementation_hash(); - - let (retdata_size: felt, retdata: felt*) = library_call( - class_hash=class_hash, - function_selector=selector, - calldata_size=calldata_size, - calldata=calldata, - ); - return (retdata_size, retdata); -} - -@l1_handler -@raw_input -func __l1_default__{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( - selector: felt, calldata_size: felt, calldata: felt* -) { - let (class_hash) = Proxy.get_implementation_hash(); - - library_call_l1_handler( - class_hash=class_hash, - function_selector=selector, - calldata_size=calldata_size, - calldata=calldata, - ); - return (); -} - -@view -func impl{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}() -> ( - implementation: felt -) { - let (implementation) = Proxy.get_implementation_hash(); - return (implementation=implementation); -} diff --git a/starknet_py/tests/e2e/mock/contracts/universal_deployer.cairo b/starknet_py/tests/e2e/mock/contracts/universal_deployer.cairo deleted file mode 100644 index 150e5765d..000000000 --- a/starknet_py/tests/e2e/mock/contracts/universal_deployer.cairo +++ /dev/null @@ -1,91 +0,0 @@ -// MIT License -// -// Copyright (c) 2021 OpenZeppelin -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. - -%lang starknet - -from starkware.starknet.common.syscalls import get_caller_address, deploy -from starkware.cairo.common.cairo_builtins import HashBuiltin -from starkware.cairo.common.hash import hash2 -from starkware.cairo.common.bool import FALSE, TRUE - -@event -func ContractDeployed( - address: felt, - deployer: felt, - unique: felt, - classHash: felt, - calldata_len: felt, - calldata: felt*, - salt: felt -) { -} - -@external -func deployContract{ - syscall_ptr: felt*, - pedersen_ptr: HashBuiltin*, - range_check_ptr -}( - classHash: felt, - salt: felt, - unique: felt, - calldata_len: felt, - calldata: felt* -) -> (address: felt) { - alloc_locals; - let (deployer) = get_caller_address(); - - local _salt; - local from_zero; - if (unique == TRUE) { - let (unique_salt) = hash2{hash_ptr=pedersen_ptr}(deployer, salt); - _salt = unique_salt; - from_zero = FALSE; - tempvar _pedersen = pedersen_ptr; - } else { - _salt = salt; - from_zero = TRUE; - tempvar _pedersen = pedersen_ptr; - } - - let pedersen_ptr = _pedersen; - - let (address) = deploy( - class_hash=classHash, - contract_address_salt=_salt, - constructor_calldata_size=calldata_len, - constructor_calldata=calldata, - deploy_from_zero=from_zero, - ); - - ContractDeployed.emit( - address=address, - deployer=deployer, - unique=unique, - classHash=classHash, - calldata_len=calldata_len, - calldata=calldata, - salt=salt - ); - - return (address=address); -} diff --git a/starknet_py/tests/e2e/proxy/__init__.py b/starknet_py/tests/e2e/proxy/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/starknet_py/tests/e2e/proxy/proxy_test.py b/starknet_py/tests/e2e/proxy/proxy_test.py deleted file mode 100644 index 770a41444..000000000 --- a/starknet_py/tests/e2e/proxy/proxy_test.py +++ /dev/null @@ -1,128 +0,0 @@ -from typing import Optional - -import pytest - -from starknet_py.contract import Contract -from starknet_py.hash.storage import get_storage_var_address -from starknet_py.net.client import Client -from starknet_py.net.client_errors import ContractNotFoundError -from starknet_py.net.models import Address -from starknet_py.proxy.contract_abi_resolver import ProxyResolutionError -from starknet_py.proxy.proxy_check import ProxyCheck -from starknet_py.tests.e2e.fixtures.constants import MAX_FEE - - -async def is_map_working_properly(map_contract: Contract, key: int, val: int) -> bool: - """Put (key, val) into map_contract's storage and check if value under the key is val""" - await ( - await map_contract.functions["put"].invoke_v1(key, val, max_fee=int(1e16)) - ).wait_for_acceptance() - (result,) = await map_contract.functions["get"].call(key=key) - return result == val - - -@pytest.mark.asyncio -async def test_contract_from_address_no_proxy(account, map_contract): - contract = await Contract.from_address( - address=map_contract.address, - provider=account, - ) - - assert contract.functions.keys() == {"put", "get"} - assert contract.address == map_contract.address - assert await is_map_working_properly(map_contract=contract, key=69, val=13) - - -@pytest.mark.asyncio -async def test_contract_from_address_with_proxy(account, proxy_oz_argent): - proxy_contract = await Contract.from_address( - address=proxy_oz_argent.deployed_contract.address, - provider=account, - ) - proxied_contract = await Contract.from_address( - address=proxy_oz_argent.deployed_contract.address, - provider=account, - proxy_config=True, - ) - - assert proxied_contract.functions.keys() == {"put", "get"} - assert proxied_contract.address == proxy_contract.address - assert await is_map_working_properly(map_contract=proxied_contract, key=69, val=13) - - -@pytest.mark.asyncio -async def test_contract_from_invalid_address(account): - with pytest.raises(ContractNotFoundError): - await Contract.from_address( - address=123, - provider=account, - ) - - -@pytest.mark.asyncio -async def test_contract_from_address_invalid_proxy_checks(account, proxy_custom): - message_regex = r"Couldn't resolve proxy using given ProxyChecks .*" - - with pytest.raises(ProxyResolutionError, match=message_regex): - await Contract.from_address( - address=proxy_custom.deployed_contract.address, - provider=account, - proxy_config=True, - ) - - -@pytest.mark.asyncio -async def test_contract_from_address_custom_proxy_check(account, proxy_custom): - class CustomProxyCheck(ProxyCheck): - async def implementation_address( - self, address: Address, client: Client - ) -> Optional[int]: - return None - - async def implementation_hash( - self, address: Address, client: Client - ) -> Optional[int]: - return await client.get_storage_at( - contract_address=address, - key=get_storage_var_address("Proxy_implementation_hash_custom"), - block_hash="latest", - ) - - contract = await Contract.from_address( - address=proxy_custom.deployed_contract.address, - provider=account, - proxy_config={"proxy_checks": [CustomProxyCheck()]}, - ) - - assert contract.functions.keys() == {"put", "get"} - assert contract.address == proxy_custom.deployed_contract.address - assert await is_map_working_properly(map_contract=contract, key=69, val=13) - - -@pytest.mark.asyncio -async def test_contract_from_address_with_old_address_proxy( - account, old_proxy, map_contract -): - declare_result = await Contract.declare_v1( - account=account, compiled_contract=old_proxy, max_fee=MAX_FEE - ) - await declare_result.wait_for_acceptance() - deploy_result = await declare_result.deploy_v1( - constructor_args={"implementation_address": map_contract.address}, - max_fee=MAX_FEE, - ) - await deploy_result.wait_for_acceptance() - - proxy_contract = await Contract.from_address( - address=deploy_result.deployed_contract.address, - provider=account, - ) - proxied_contract = await Contract.from_address( - address=deploy_result.deployed_contract.address, - provider=account, - proxy_config=True, - ) - - assert proxied_contract.functions.keys() == {"put", "get"} - assert proxied_contract.address == proxy_contract.address - assert await is_map_working_properly(map_contract=proxied_contract, key=69, val=13) From 7009e4f5de73828d77d8f7ed1087009a6f549b73 Mon Sep 17 00:00:00 2001 From: jumpman <57270771+kkawula@users.noreply.github.com> Date: Tue, 30 Jul 2024 12:21:10 +0200 Subject: [PATCH 02/66] Migrate tests to use cairo 1 ERC20 contract --- starknet_py/net/account/account.py | 2 +- starknet_py/tests/e2e/account/account_test.py | 21 +++++++++--------- .../guide/test_using_existing_contracts.py | 6 +++++ starknet_py/tests/e2e/fixtures/contracts.py | 22 +++++++++---------- .../tests/e2e/fixtures/contracts_v1.py | 18 +++++++++++++++ 5 files changed, 47 insertions(+), 22 deletions(-) diff --git a/starknet_py/net/account/account.py b/starknet_py/net/account/account.py index 18f493cf2..939ae5b9b 100644 --- a/starknet_py/net/account/account.py +++ b/starknet_py/net/account/account.py @@ -309,7 +309,7 @@ async def get_balance( low, high = await self._client.call_contract( Call( to_addr=parse_address(token_address), - selector=get_selector_from_name("balanceOf"), + selector=get_selector_from_name("balance_of"), calldata=[self.address], ), block_hash=block_hash, diff --git a/starknet_py/tests/e2e/account/account_test.py b/starknet_py/tests/e2e/account/account_test.py index dc936887e..fac734d02 100644 --- a/starknet_py/tests/e2e/account/account_test.py +++ b/starknet_py/tests/e2e/account/account_test.py @@ -1,9 +1,9 @@ +import sys from typing import cast from unittest.mock import AsyncMock, patch import pytest -from starknet_py.contract import Contract from starknet_py.hash.address import compute_address from starknet_py.hash.selector import get_selector_from_name from starknet_py.net.account.account import Account @@ -56,6 +56,10 @@ async def test_get_balance_throws_when_token_not_specified(account): await modified_account.get_balance() +@pytest.mark.skipif( + "--contract_dir=v2" not in sys.argv, + reason="Some cairo 1 contracts compiled with v1 compiler fail with new devnet-rs", +) @pytest.mark.asyncio async def test_balance_when_token_specified(account, erc20_contract): balance = await account.get_balance(erc20_contract.address) @@ -63,18 +67,15 @@ async def test_balance_when_token_specified(account, erc20_contract): assert balance == 200 +@pytest.mark.skipif( + "--contract_dir=v2" not in sys.argv, + reason="Some cairo 1 contracts compiled with v1 compiler fail with new devnet-rs", +) @pytest.mark.asyncio async def test_estimated_fee_greater_than_zero(account, erc20_contract): - erc20_contract = Contract( - address=erc20_contract.address, - abi=erc20_contract.data.abi, - provider=account, - cairo_version=0, - ) - estimated_fee = ( - await erc20_contract.functions["balanceOf"] - .prepare_invoke_v1("1234", max_fee=0) + await erc20_contract.functions["balance_of"] + .prepare_invoke_v1(account.address, max_fee=0) .estimate_fee(block_hash="latest") ) diff --git a/starknet_py/tests/e2e/docs/guide/test_using_existing_contracts.py b/starknet_py/tests/e2e/docs/guide/test_using_existing_contracts.py index ddcd50104..405701758 100644 --- a/starknet_py/tests/e2e/docs/guide/test_using_existing_contracts.py +++ b/starknet_py/tests/e2e/docs/guide/test_using_existing_contracts.py @@ -1,3 +1,5 @@ +import sys + import pytest # docs-abi: start @@ -23,6 +25,10 @@ # docs-abi: end +@pytest.mark.skipif( + "--contract_dir=v2" not in sys.argv, + reason="Some cairo 1 contracts compiled with v1 compiler fail with new devnet-rs", +) @pytest.mark.asyncio async def test_using_existing_contracts(account, erc20_contract): # pylint: disable=import-outside-toplevel,too-many-locals,unused-variable diff --git a/starknet_py/tests/e2e/fixtures/contracts.py b/starknet_py/tests/e2e/fixtures/contracts.py index 42ce69d7c..edc9df215 100644 --- a/starknet_py/tests/e2e/fixtures/contracts.py +++ b/starknet_py/tests/e2e/fixtures/contracts.py @@ -215,17 +215,17 @@ async def simple_storage_with_event_contract( return await deploy_contract(account, simple_storage_with_event_class_hash, abi) -@pytest_asyncio.fixture(name="erc20_contract", scope="package") -async def deploy_erc20_contract( - account: BaseAccount, - erc20_compiled_contract: str, - erc20_class_hash: int, -) -> Contract: - """ - Deploys erc20 contract and returns its instance. - """ - abi = create_compiled_contract(compiled_contract=erc20_compiled_contract).abi - return await deploy_contract(account, erc20_class_hash, abi) +# @pytest_asyncio.fixture(name="erc20_contract", scope="package") +# async def deploy_erc20_contract( +# account: BaseAccount, +# erc20_compiled_contract: str, +# erc20_class_hash: int, +# ) -> Contract: +# """ +# Deploys erc20 contract and returns its instance. +# """ +# abi = create_compiled_contract(compiled_contract=erc20_compiled_contract).abi +# return await deploy_contract(account, erc20_class_hash, abi) @pytest.fixture(scope="package") diff --git a/starknet_py/tests/e2e/fixtures/contracts_v1.py b/starknet_py/tests/e2e/fixtures/contracts_v1.py index a12df1f09..c8dfc4d58 100644 --- a/starknet_py/tests/e2e/fixtures/contracts_v1.py +++ b/starknet_py/tests/e2e/fixtures/contracts_v1.py @@ -4,6 +4,7 @@ import pytest import pytest_asyncio +from starknet_py.cairo.felt import encode_shortstring from starknet_py.common import create_casm_class from starknet_py.contract import Contract from starknet_py.hash.casm_class_hash import compute_casm_class_hash @@ -122,6 +123,23 @@ async def cairo1_token_bridge_class_hash(account: BaseAccount) -> int: return class_hash +@pytest_asyncio.fixture(scope="package", name="erc20_contract") +async def cairo1_erc20_deploy(account, cairo1_erc20_class_hash): + calldata = { + "name_": encode_shortstring("erc20_basic"), + "symbol_": encode_shortstring("ERC20B"), + "decimals_": 10, + "initial_supply": 200, + "recipient": account.address, + } + return await deploy_v1_contract( + account=account, + contract_name="ERC20", + class_hash=cairo1_erc20_class_hash, + calldata=calldata, + ) + + @pytest_asyncio.fixture(scope="package") async def cairo1_hello_starknet_deploy( account: BaseAccount, cairo1_hello_starknet_class_hash From 9c1e6457cb458a8088364d31f8a85d057d483c39 Mon Sep 17 00:00:00 2001 From: jumpman <57270771+kkawula@users.noreply.github.com> Date: Tue, 30 Jul 2024 12:26:09 +0200 Subject: [PATCH 03/66] Remove ERC20 contract cairo code and fixtures --- starknet_py/tests/e2e/fixtures/contracts.py | 40 ------------------- .../tests/e2e/mock/contracts/erc20.cairo | 27 ------------- 2 files changed, 67 deletions(-) delete mode 100644 starknet_py/tests/e2e/mock/contracts/erc20.cairo diff --git a/starknet_py/tests/e2e/fixtures/contracts.py b/starknet_py/tests/e2e/fixtures/contracts.py index edc9df215..d8a1d885a 100644 --- a/starknet_py/tests/e2e/fixtures/contracts.py +++ b/starknet_py/tests/e2e/fixtures/contracts.py @@ -80,14 +80,6 @@ def simple_storage_with_event_compiled_contract() -> str: ) -@pytest.fixture(scope="package") -def erc20_compiled_contract() -> str: - """ - Returns compiled erc20 contract. - """ - return read_contract("erc20_compiled.json", directory=CONTRACTS_COMPILED_V0_DIR) - - @pytest.fixture(scope="package") def constructor_with_arguments_compiled_contract() -> str: """ @@ -215,19 +207,6 @@ async def simple_storage_with_event_contract( return await deploy_contract(account, simple_storage_with_event_class_hash, abi) -# @pytest_asyncio.fixture(name="erc20_contract", scope="package") -# async def deploy_erc20_contract( -# account: BaseAccount, -# erc20_compiled_contract: str, -# erc20_class_hash: int, -# ) -> Contract: -# """ -# Deploys erc20 contract and returns its instance. -# """ -# abi = create_compiled_contract(compiled_contract=erc20_compiled_contract).abi -# return await deploy_contract(account, erc20_class_hash, abi) - - @pytest.fixture(scope="package") def eth_fee_contract(account: BaseAccount, fee_contract_abi) -> Contract: """ @@ -386,25 +365,6 @@ async def simple_storage_with_event_class_hash( return res.class_hash -@pytest_asyncio.fixture(scope="package") -async def erc20_class_hash(account: BaseAccount, erc20_compiled_contract: str) -> int: - """ - Returns class_hash of the erc20.cairo. - """ - declare = await account.sign_declare_v1( - compiled_contract=erc20_compiled_contract, - max_fee=int(1e16), - ) - res = await account.client.declare(declare) - await account.client.wait_for_tx(res.transaction_hash) - return res.class_hash - - -constructor_with_arguments_source = ( - CONTRACTS_DIR / "constructor_with_arguments.cairo" -).read_text("utf-8") - - @pytest.fixture(scope="package") def constructor_with_arguments_abi() -> List: """ diff --git a/starknet_py/tests/e2e/mock/contracts/erc20.cairo b/starknet_py/tests/e2e/mock/contracts/erc20.cairo deleted file mode 100644 index 1b532c5e8..000000000 --- a/starknet_py/tests/e2e/mock/contracts/erc20.cairo +++ /dev/null @@ -1,27 +0,0 @@ -%lang starknet -%builtins pedersen range_check - -from starkware.cairo.common.cairo_builtins import HashBuiltin -from starkware.cairo.common.uint256 import Uint256 - -@event -func Transfer(from_: felt, to: felt, value: Uint256) { -} - -@external -func transferFrom{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( - sender: felt, recipient: felt, amount: felt -) -> (success: felt) { - alloc_locals; - local success: felt = 1; - return (success,); -} - -@view -func balanceOf{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(account: felt) -> ( - balance: Uint256 -) { - alloc_locals; - local balance: Uint256 = Uint256(low=200, high=0); - return (balance,); -} From 9a01051222957719b61509f8fb86e02489c580c0 Mon Sep 17 00:00:00 2001 From: jumpman <57270771+kkawula@users.noreply.github.com> Date: Mon, 5 Aug 2024 11:29:41 +0200 Subject: [PATCH 04/66] Adapt tests to the cairo 1 --- .../guide/test_using_existing_contracts.py | 34 +++++++++++-------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/starknet_py/tests/e2e/docs/guide/test_using_existing_contracts.py b/starknet_py/tests/e2e/docs/guide/test_using_existing_contracts.py index 405701758..3ef79c7fc 100644 --- a/starknet_py/tests/e2e/docs/guide/test_using_existing_contracts.py +++ b/starknet_py/tests/e2e/docs/guide/test_using_existing_contracts.py @@ -47,28 +47,33 @@ async def test_using_existing_contracts(account, erc20_contract): # docs: start contract = await Contract.from_address(provider=account, address=address) - sender = "321" + sender = account.address recipient = "123" - + # docs: end + invocation = await contract.functions["increase_allowance"].invoke_v1( + sender, 200, max_fee=int(1e16) + ) + await invocation.wait_for_acceptance() + # docs: start # Using only positional arguments - invocation = await contract.functions["transferFrom"].invoke_v1( - sender, recipient, 10000, max_fee=int(1e16) + invocation = await contract.functions["transfer_from"].invoke_v1( + sender, recipient, 50, max_fee=int(1e16) ) # docs: end await invocation.wait_for_acceptance() # docs: start # Using only keyword arguments - invocation = await contract.functions["transferFrom"].invoke_v1( - sender=sender, recipient=recipient, amount=10000, max_fee=int(1e16) + invocation = await contract.functions["transfer_from"].invoke_v1( + sender=sender, recipient=recipient, amount=50, max_fee=int(1e16) ) # docs: end await invocation.wait_for_acceptance() # docs: start # Mixing positional with keyword arguments - invocation = await contract.functions["transferFrom"].invoke_v1( - sender, recipient, amount=10000, max_fee=int(1e16) + invocation = await contract.functions["transfer_from"].invoke_v1( + sender, recipient, amount=50, max_fee=int(1e16) ) # docs: end await invocation.wait_for_acceptance() @@ -76,19 +81,18 @@ async def test_using_existing_contracts(account, erc20_contract): # Creating a prepared function call with arguments # It is also possible to use `prepare_invoke_v3` - transfer = contract.functions["transferFrom"].prepare_invoke_v1( - sender, recipient, amount=10000, max_fee=int(1e16) + transfer = contract.functions["transfer_from"].prepare_invoke_v1( + sender, + recipient, + amount=50, + max_fee=int(1e16), ) invocation = await transfer.invoke() # Wait for tx await invocation.wait_for_acceptance() - (balance,) = await contract.functions["balanceOf"].call(recipient) - - # You can also use key access, call returns TupleDataclass which behaves similar to NamedTuple - result = await contract.functions["balanceOf"].call(recipient) - balance = result.balance + (balance,) = await contract.functions["balance_of"].call(recipient) # docs: end assert balance == 200 From 8c4418f1f74ba5715b07127c5df23a43d1d2ee45 Mon Sep 17 00:00:00 2001 From: jumpman <57270771+kkawula@users.noreply.github.com> Date: Mon, 5 Aug 2024 12:39:10 +0200 Subject: [PATCH 05/66] Merge 'development' --- starknet_py/net/client_test.py | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/starknet_py/net/client_test.py b/starknet_py/net/client_test.py index be6e02be2..8b081c825 100644 --- a/starknet_py/net/client_test.py +++ b/starknet_py/net/client_test.py @@ -126,21 +126,6 @@ async def test_broadcasted_txn_declare_v2( assert all(key.name in brodcasted_txn for key in expected_keys) -@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): invoke_tx = await account.sign_invoke_v3( From f43673a56de0fcbe7caea625bfc6ab0a74817170 Mon Sep 17 00:00:00 2001 From: jumpman <57270771+kkawula@users.noreply.github.com> Date: Mon, 5 Aug 2024 16:55:11 +0200 Subject: [PATCH 06/66] Fix test in Serilization Guide --- .../tests/e2e/docs/guide/test_serializing.py | 69 ++++++++++--------- 1 file changed, 38 insertions(+), 31 deletions(-) diff --git a/starknet_py/tests/e2e/docs/guide/test_serializing.py b/starknet_py/tests/e2e/docs/guide/test_serializing.py index b05b18da7..e76b8da1f 100644 --- a/starknet_py/tests/e2e/docs/guide/test_serializing.py +++ b/starknet_py/tests/e2e/docs/guide/test_serializing.py @@ -1,8 +1,7 @@ # pylint: disable=import-outside-toplevel, pointless-string-statement import json -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.misc import ContractVersion, load_contract def test_short_strings(): @@ -20,64 +19,72 @@ def test_short_strings(): def test_abi_parsing(): - raw_abi_string = read_contract( - "erc20_abi.json", directory=CONTRACTS_COMPILED_V0_DIR - ) + raw_abi_string = json.loads( + load_contract(contract_name="TestContract", version=ContractVersion.V2)[ + "sierra" + ] + )["abi"] # docs-serializer: start - from starknet_py.abi.v0 import AbiParser + from starknet_py.abi.v2 import AbiParser """ - @external - func transferFrom{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( - sender: felt, recipient: felt, amount: felt - ) -> (success: felt) { - alloc_locals; - local success: felt = 1; - return (success,); + #[external(v0)] + fn test(ref self: ContractState, ref arg: felt252, arg1: felt252, arg2: felt252) -> felt252 { + let mut x = self.my_storage_var.read(); + x += 1; + self.my_storage_var.write(x); + x + internal_func() } """ - erc20_abi = json.loads(raw_abi_string) - abi = AbiParser(erc20_abi).parse() + abi = AbiParser(raw_abi_string).parse() - from starknet_py.serialization import serializer_for_function + from starknet_py.serialization.factory import serializer_for_function_v1 # You can create serializer for function inputs/outputs by passing Abi.Function object to serializer_for_function - function_serializer = serializer_for_function(abi.functions["transferFrom"]) + function_serializer = serializer_for_function_v1(abi.functions["test"]) # You can call function serializer like you would a normal function - assert [111, 222, 333] == function_serializer.serialize( - sender=111, recipient=222, amount=333 - ) + assert [111, 222, 333] == function_serializer.serialize(arg=111, arg1=222, arg2=333) assert [111, 222, 333] == function_serializer.serialize(111, 222, 333) - assert [111, 222, 333] == function_serializer.serialize(111, 222, amount=333) + assert [111, 222, 333] == function_serializer.serialize(111, 222, arg2=333) - # You can use deserialized result from function serializer like a tuple, but it also has named properties + # You can use deserialized result from function serializer like a tuple result = function_serializer.deserialize([1]) assert 1 == result[0] - assert 1 == result.success - assert {"success": 1} == result.as_dict() (success,) = result assert 1 == success # docs-serializer: end + raw_abi_string = json.loads( + load_contract(contract_name="ERC20", version=ContractVersion.V2)["sierra"] + )["abi"] + abi = AbiParser(raw_abi_string).parse() + # docs-serializer: start + # docs-event: start from starknet_py.serialization import serializer_for_event """ - @event - func Transfer(from_: felt, to: felt, value: Uint256) { + #[event] + #[derive(Drop, starknet::Event)] + struct Approval { + owner: ContractAddress, + spender: ContractAddress, + value: u256, } """ - # You can create serializer for events by passing Abi.Event object to serializer_for_event - event_serializer = serializer_for_event(abi.events["Transfer"]) + event_serializer = serializer_for_event( + abi.events["contracts_v2::erc20::ERC20::Approval"] + ) + assert [1, 2, 3, 4] == event_serializer.serialize( - {"from_": 1, "to": 2, "value": 3 + 4 * 2**128} + {"owner": 1, "spedner": 2, "value": 3 + 4 * 2**128} ) assert { - "from_": 1, - "to": 2, + "owner": 1, + "spender": 2, "value": 3 + 4 * 2**128, } == event_serializer.deserialize([1, 2, 3, 4]).as_dict() # docs-event: end From 3b1658c8a49269ec263476bcc6e1ac0b903abd37 Mon Sep 17 00:00:00 2001 From: jumpman <57270771+kkawula@users.noreply.github.com> Date: Mon, 5 Aug 2024 17:08:48 +0200 Subject: [PATCH 07/66] Fix typo in 'test_abi_parsing' --- starknet_py/tests/e2e/docs/guide/test_serializing.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/starknet_py/tests/e2e/docs/guide/test_serializing.py b/starknet_py/tests/e2e/docs/guide/test_serializing.py index e76b8da1f..d33111473 100644 --- a/starknet_py/tests/e2e/docs/guide/test_serializing.py +++ b/starknet_py/tests/e2e/docs/guide/test_serializing.py @@ -80,7 +80,7 @@ def test_abi_parsing(): ) assert [1, 2, 3, 4] == event_serializer.serialize( - {"owner": 1, "spedner": 2, "value": 3 + 4 * 2**128} + {"owner": 1, "spender": 2, "value": 3 + 4 * 2**128} ) assert { "owner": 1, From 2adc084b08db13884aa982c8743a047f687db370 Mon Sep 17 00:00:00 2001 From: jumpman <57270771+kkawula@users.noreply.github.com> Date: Mon, 5 Aug 2024 17:31:40 +0200 Subject: [PATCH 08/66] Fix after merge --- starknet_py/net/client_test.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/starknet_py/net/client_test.py b/starknet_py/net/client_test.py index 8b081c825..e35d4152a 100644 --- a/starknet_py/net/client_test.py +++ b/starknet_py/net/client_test.py @@ -127,9 +127,13 @@ async def test_broadcasted_txn_declare_v2( @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, ) @@ -142,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), ) From 82e72423fcfa7e9480d25b0b3cb0cff7a32421dc Mon Sep 17 00:00:00 2001 From: jumpman <57270771+kkawula@users.noreply.github.com> Date: Mon, 5 Aug 2024 18:42:59 +0200 Subject: [PATCH 09/66] Remove 'constructor_with_arguments.cairo' and 'constructor_without_arguments.cairo' contracts --- starknet_py/tests/e2e/account/account_test.py | 17 ++++--- starknet_py/tests/e2e/fixtures/contracts.py | 21 --------- .../constructor_with_arguments.cairo | 44 ------------------- .../constructor_without_arguments.cairo | 6 --- 4 files changed, 8 insertions(+), 80 deletions(-) delete mode 100644 starknet_py/tests/e2e/mock/contracts/constructor_with_arguments.cairo delete mode 100644 starknet_py/tests/e2e/mock/contracts/constructor_without_arguments.cairo diff --git a/starknet_py/tests/e2e/account/account_test.py b/starknet_py/tests/e2e/account/account_test.py index d685aecb4..673812c10 100644 --- a/starknet_py/tests/e2e/account/account_test.py +++ b/starknet_py/tests/e2e/account/account_test.py @@ -1,4 +1,3 @@ -import sys from typing import cast from unittest.mock import AsyncMock, patch @@ -56,10 +55,10 @@ async def test_get_balance_throws_when_token_not_specified(account): await modified_account.get_balance() -@pytest.mark.skipif( - "--contract_dir=v2" not in sys.argv, - reason="Some cairo 1 contracts compiled with v1 compiler fail with new devnet-rs", -) +# @pytest.mark.skipif( +# "--contract_dir=v2" not in sys.argv, +# reason="Some cairo 1 contracts compiled with v1 compiler fail with new devnet-rs", +# ) @pytest.mark.asyncio async def test_balance_when_token_specified(account, erc20_contract): balance = await account.get_balance(erc20_contract.address) @@ -67,10 +66,10 @@ async def test_balance_when_token_specified(account, erc20_contract): assert balance == 200 -@pytest.mark.skipif( - "--contract_dir=v2" not in sys.argv, - reason="Some cairo 1 contracts compiled with v1 compiler fail with new devnet-rs", -) +# @pytest.mark.skipif( +# "--contract_dir=v2" not in sys.argv, +# reason="Some cairo 1 contracts compiled with v1 compiler fail with new devnet-rs", +# ) @pytest.mark.asyncio async def test_estimated_fee_greater_than_zero(account, erc20_contract): estimated_fee = ( diff --git a/starknet_py/tests/e2e/fixtures/contracts.py b/starknet_py/tests/e2e/fixtures/contracts.py index d8a1d885a..b7b032fb1 100644 --- a/starknet_py/tests/e2e/fixtures/contracts.py +++ b/starknet_py/tests/e2e/fixtures/contracts.py @@ -80,27 +80,6 @@ def simple_storage_with_event_compiled_contract() -> str: ) -@pytest.fixture(scope="package") -def constructor_with_arguments_compiled_contract() -> str: - """ - Returns compiled constructor_with_arguments contract. - """ - return read_contract( - "constructor_with_arguments_compiled.json", directory=CONTRACTS_COMPILED_V0_DIR - ) - - -@pytest.fixture(scope="package") -def constructor_without_arguments_compiled_contract() -> str: - """ - Returns compiled constructor_without_arguments contract. - """ - return read_contract( - "constructor_without_arguments_compiled.json", - directory=CONTRACTS_COMPILED_V0_DIR, - ) - - async def deploy_contract(account: BaseAccount, class_hash: int, abi: List) -> Contract: """ Deploys a contract and returns its instance. diff --git a/starknet_py/tests/e2e/mock/contracts/constructor_with_arguments.cairo b/starknet_py/tests/e2e/mock/contracts/constructor_with_arguments.cairo deleted file mode 100644 index c2f5c15a5..000000000 --- a/starknet_py/tests/e2e/mock/contracts/constructor_with_arguments.cairo +++ /dev/null @@ -1,44 +0,0 @@ -%lang starknet -%builtins pedersen range_check - -from starkware.cairo.common.cairo_builtins import HashBuiltin - -struct NestedStruct { - value: felt, -} - -struct TopStruct { - value: felt, - nested_struct: NestedStruct, -} - -@storage_var -func storage() -> (value: (felt, (felt, (felt, felt)), felt, TopStruct)) { -} - -func array_sum(arr: felt*, size) -> (sum: felt) { - if (size == 0) { - return (sum=0); - } - - // size is not zero. - let (sum_of_rest) = array_sum(arr=arr + 1, size=size - 1); - return (sum=[arr] + sum_of_rest); -} - -@constructor -func constructor{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( - single_value: felt, tuple: (felt, (felt, felt)), arr_len: felt, arr: felt*, dict: TopStruct -) { - let (arr_sum) = array_sum(arr, arr_len); - storage.write((single_value, tuple, arr_sum, dict)); - return (); -} - -@view -func get{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}() -> ( - single_value: felt, tuple: (felt, (felt, felt)), arr_sum: felt, dict: TopStruct -) { - let (value) = storage.read(); - return (value[0], value[1], value[2], value[3]); -} diff --git a/starknet_py/tests/e2e/mock/contracts/constructor_without_arguments.cairo b/starknet_py/tests/e2e/mock/contracts/constructor_without_arguments.cairo deleted file mode 100644 index edde83cf0..000000000 --- a/starknet_py/tests/e2e/mock/contracts/constructor_without_arguments.cairo +++ /dev/null @@ -1,6 +0,0 @@ -%lang starknet - -@constructor -func constructor{}() { - return (); -} From 301a8d4bbcc287e74fb2bd4fc403cd04b2ddfd21 Mon Sep 17 00:00:00 2001 From: jumpman <57270771+kkawula@users.noreply.github.com> Date: Tue, 6 Aug 2024 12:12:09 +0200 Subject: [PATCH 10/66] Add 'constructor_with_arguments.cairo' contract and update test_throws_when_calldata_not_provided --- starknet_py/tests/e2e/deploy/deployer_test.py | 10 ++++- .../tests/e2e/fixtures/contracts_v1.py | 9 ++++ .../src/constructor_with_arguments.cairo | 42 +++++++++++++++++++ .../tests/e2e/mock/contracts_v2/src/lib.cairo | 1 + 4 files changed, 60 insertions(+), 2 deletions(-) create mode 100644 starknet_py/tests/e2e/mock/contracts_v2/src/constructor_with_arguments.cairo diff --git a/starknet_py/tests/e2e/deploy/deployer_test.py b/starknet_py/tests/e2e/deploy/deployer_test.py index 5dc1784fe..9a0b6a74d 100644 --- a/starknet_py/tests/e2e/deploy/deployer_test.py +++ b/starknet_py/tests/e2e/deploy/deployer_test.py @@ -1,10 +1,12 @@ import pytest +from starknet_py.common import create_sierra_compiled_contract from starknet_py.contract import Contract from starknet_py.hash.address import compute_address from starknet_py.net.full_node_client import FullNodeClient from starknet_py.net.udc_deployer.deployer import Deployer from starknet_py.tests.e2e.fixtures.constants import MAX_FEE +from starknet_py.tests.e2e.fixtures.misc import load_contract from starknet_py.utils.constructor_args_translator import translate_constructor_args @@ -35,7 +37,11 @@ async def test_throws_when_calldata_provided_without_abi(map_class_hash): @pytest.mark.asyncio -async def test_throws_when_calldata_not_provided(constructor_with_arguments_abi): +async def test_throws_when_calldata_not_provided(): + contract = create_sierra_compiled_contract( + compiled_contract=load_contract("ConstructorWithArguments")["sierra"] + ) + deployer = Deployer() with pytest.raises( @@ -43,7 +49,7 @@ async def test_throws_when_calldata_not_provided(constructor_with_arguments_abi) match="Provided contract has a constructor and no arguments were provided.", ): deployer.create_contract_deployment( - class_hash=1234, abi=constructor_with_arguments_abi, cairo_version=0 + class_hash=1234, abi=contract.parsed_abi, cairo_version=1 ) diff --git a/starknet_py/tests/e2e/fixtures/contracts_v1.py b/starknet_py/tests/e2e/fixtures/contracts_v1.py index 61d96bb63..d8e1ccc2c 100644 --- a/starknet_py/tests/e2e/fixtures/contracts_v1.py +++ b/starknet_py/tests/e2e/fixtures/contracts_v1.py @@ -42,6 +42,15 @@ async def cairo1_erc20_class_hash(account: BaseAccount) -> int: return class_hash +@pytest_asyncio.fixture(scope="package") +async def cairo1_constructor_with_arguments_class_hash(account: BaseAccount) -> int: + contract = load_contract("ConstructorWithArguments") + class_hash, _ = await declare_cairo1_contract( + account, contract["sierra"], contract["casm"] + ) + return class_hash + + @pytest_asyncio.fixture(scope="package") async def declare_v2_hello_starknet(account: BaseAccount) -> DeclareV2: contract = load_contract("HelloStarknet") diff --git a/starknet_py/tests/e2e/mock/contracts_v2/src/constructor_with_arguments.cairo b/starknet_py/tests/e2e/mock/contracts_v2/src/constructor_with_arguments.cairo new file mode 100644 index 000000000..94464c322 --- /dev/null +++ b/starknet_py/tests/e2e/mock/contracts_v2/src/constructor_with_arguments.cairo @@ -0,0 +1,42 @@ +#[derive(Clone, Debug, PartialEq, Drop, Serde, starknet::Store)] +struct NestedStruct { + value: felt252, +} + +#[derive(Clone, Debug, PartialEq, Drop, Serde, starknet::Store)] +struct TopStruct { + value: felt252, + nested_struct: NestedStruct, +} + +#[starknet::contract] +mod ConstructorWithArguments { + use super::{TopStruct, NestedStruct}; + + #[storage] + struct Storage { + single_value: felt252, + tuple: (felt252, (felt252, felt252)), + arr_sum: felt252, + dict: TopStruct, + } + + #[constructor] + fn constructor(ref self: ContractState, single_value: felt252, tuple: (felt252, (felt252, felt252)), arr: Array, dict: TopStruct) { + let mut sum = 0; + + let count = arr.len(); + let mut i: usize = 0; + + while i != count { + let element: felt252 = arr[i].clone(); + sum += element; + i += 1; + }; + + self.single_value.write(single_value); + self.tuple.write(tuple); + self.arr_sum.write(sum); + self.dict.write(dict); + } +} \ No newline at end of file diff --git a/starknet_py/tests/e2e/mock/contracts_v2/src/lib.cairo b/starknet_py/tests/e2e/mock/contracts_v2/src/lib.cairo index 394bc11a4..33e16e5ff 100644 --- a/starknet_py/tests/e2e/mock/contracts_v2/src/lib.cairo +++ b/starknet_py/tests/e2e/mock/contracts_v2/src/lib.cairo @@ -5,6 +5,7 @@ mod hello2; mod minimal_contract; mod new_syntax_test_contract; mod string; +mod constructor_with_arguments; mod test_contract; mod test_enum; mod test_option; From 74e9360f34bc972ab6a2ecf50cc48188d7a49102 Mon Sep 17 00:00:00 2001 From: jumpman <57270771+kkawula@users.noreply.github.com> Date: Tue, 6 Aug 2024 12:57:34 +0200 Subject: [PATCH 11/66] Update 'test_constructor_arguments_contract_deploy' --- starknet_py/tests/e2e/deploy/deployer_test.py | 23 +++++++++++-------- .../src/constructor_with_arguments.cairo | 20 ++++++++++++---- 2 files changed, 28 insertions(+), 15 deletions(-) diff --git a/starknet_py/tests/e2e/deploy/deployer_test.py b/starknet_py/tests/e2e/deploy/deployer_test.py index 9a0b6a74d..2ce476391 100644 --- a/starknet_py/tests/e2e/deploy/deployer_test.py +++ b/starknet_py/tests/e2e/deploy/deployer_test.py @@ -68,17 +68,20 @@ async def test_throws_when_calldata_not_provided(): ) async def test_constructor_arguments_contract_deploy( account, - constructor_with_arguments_abi, - constructor_with_arguments_class_hash, + cairo1_constructor_with_arguments_class_hash, calldata, ): + contract = create_sierra_compiled_contract( + compiled_contract=load_contract("ConstructorWithArguments")["sierra"] + ) + deployer = Deployer(account_address=account.address) deploy_call, contract_address = deployer.create_contract_deployment( - class_hash=constructor_with_arguments_class_hash, - abi=constructor_with_arguments_abi, + class_hash=cairo1_constructor_with_arguments_class_hash, + abi=contract.parsed_abi, calldata=calldata, - cairo_version=0, + cairo_version=1, ) deploy_invoke_transaction = await account.sign_invoke_v1( @@ -89,14 +92,14 @@ async def test_constructor_arguments_contract_deploy( contract = Contract( address=contract_address, - abi=constructor_with_arguments_abi, + abi=contract.parsed_abi, provider=account, - cairo_version=0, + cairo_version=1, ) - result = await contract.functions["get"].call(block_number="latest") - - assert result == ( + result = (await contract.functions["get"].call(block_number="latest"))[0] + unwarpped_result = (result[0], result[1], result[2], dict(result[3])) + assert unwarpped_result == ( 10, (1, (2, 3)), sum([1, 2, 3]), diff --git a/starknet_py/tests/e2e/mock/contracts_v2/src/constructor_with_arguments.cairo b/starknet_py/tests/e2e/mock/contracts_v2/src/constructor_with_arguments.cairo index 94464c322..c219c9fa4 100644 --- a/starknet_py/tests/e2e/mock/contracts_v2/src/constructor_with_arguments.cairo +++ b/starknet_py/tests/e2e/mock/contracts_v2/src/constructor_with_arguments.cairo @@ -1,12 +1,12 @@ #[derive(Clone, Debug, PartialEq, Drop, Serde, starknet::Store)] -struct NestedStruct { - value: felt252, +pub struct NestedStruct { + pub value: felt252, } #[derive(Clone, Debug, PartialEq, Drop, Serde, starknet::Store)] -struct TopStruct { - value: felt252, - nested_struct: NestedStruct, +pub struct TopStruct { + pub value: felt252, + pub nested_struct: NestedStruct, } #[starknet::contract] @@ -39,4 +39,14 @@ mod ConstructorWithArguments { self.arr_sum.write(sum); self.dict.write(dict); } + + #[external(v0)] + fn get(self: @ContractState) -> (felt252, (felt252, (felt252, felt252)), felt252, TopStruct) { + let single_value = self.single_value.read(); + let tuple = self.tuple.read(); + let arr_sum = self.arr_sum.read(); + let dict = self.dict.read(); + + (single_value, tuple, arr_sum, dict) + } } \ No newline at end of file From 50bad8059647f1ded5ca5f08b26ee10199138eeb Mon Sep 17 00:00:00 2001 From: jumpman <57270771+kkawula@users.noreply.github.com> Date: Tue, 6 Aug 2024 13:28:53 +0200 Subject: [PATCH 12/66] Add skiping test while cairo v1 test dir is triggered --- starknet_py/tests/e2e/account/account_test.py | 17 +++++++++-------- starknet_py/tests/e2e/deploy/deployer_test.py | 10 ++++++++++ 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/starknet_py/tests/e2e/account/account_test.py b/starknet_py/tests/e2e/account/account_test.py index 673812c10..d685aecb4 100644 --- a/starknet_py/tests/e2e/account/account_test.py +++ b/starknet_py/tests/e2e/account/account_test.py @@ -1,3 +1,4 @@ +import sys from typing import cast from unittest.mock import AsyncMock, patch @@ -55,10 +56,10 @@ async def test_get_balance_throws_when_token_not_specified(account): await modified_account.get_balance() -# @pytest.mark.skipif( -# "--contract_dir=v2" not in sys.argv, -# reason="Some cairo 1 contracts compiled with v1 compiler fail with new devnet-rs", -# ) +@pytest.mark.skipif( + "--contract_dir=v2" not in sys.argv, + reason="Some cairo 1 contracts compiled with v1 compiler fail with new devnet-rs", +) @pytest.mark.asyncio async def test_balance_when_token_specified(account, erc20_contract): balance = await account.get_balance(erc20_contract.address) @@ -66,10 +67,10 @@ async def test_balance_when_token_specified(account, erc20_contract): assert balance == 200 -# @pytest.mark.skipif( -# "--contract_dir=v2" not in sys.argv, -# reason="Some cairo 1 contracts compiled with v1 compiler fail with new devnet-rs", -# ) +@pytest.mark.skipif( + "--contract_dir=v2" not in sys.argv, + reason="Some cairo 1 contracts compiled with v1 compiler fail with new devnet-rs", +) @pytest.mark.asyncio async def test_estimated_fee_greater_than_zero(account, erc20_contract): estimated_fee = ( diff --git a/starknet_py/tests/e2e/deploy/deployer_test.py b/starknet_py/tests/e2e/deploy/deployer_test.py index 2ce476391..d05916a76 100644 --- a/starknet_py/tests/e2e/deploy/deployer_test.py +++ b/starknet_py/tests/e2e/deploy/deployer_test.py @@ -1,3 +1,5 @@ +import sys + import pytest from starknet_py.common import create_sierra_compiled_contract @@ -36,6 +38,10 @@ async def test_throws_when_calldata_provided_without_abi(map_class_hash): ) +@pytest.mark.skipif( + "--contract_dir=v1" in sys.argv, + reason="Contract exists only in v2 directory", +) @pytest.mark.asyncio async def test_throws_when_calldata_not_provided(): contract = create_sierra_compiled_contract( @@ -53,6 +59,10 @@ async def test_throws_when_calldata_not_provided(): ) +@pytest.mark.skipif( + "--contract_dir=v1" in sys.argv, + reason="Contract exists only in v2 directory", +) @pytest.mark.asyncio @pytest.mark.parametrize( "calldata", From 46f4e6efb23389a89c595f056e2712d422a1fc67 Mon Sep 17 00:00:00 2001 From: jumpman <57270771+kkawula@users.noreply.github.com> Date: Tue, 6 Aug 2024 14:01:08 +0200 Subject: [PATCH 13/66] Update 'test_create_deployment_call_raw_supports_seed_0' and 'test_create_deployment_call_raw' --- starknet_py/tests/e2e/deploy/deployer_test.py | 38 +++++++++++++------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/starknet_py/tests/e2e/deploy/deployer_test.py b/starknet_py/tests/e2e/deploy/deployer_test.py index d05916a76..27287adc8 100644 --- a/starknet_py/tests/e2e/deploy/deployer_test.py +++ b/starknet_py/tests/e2e/deploy/deployer_test.py @@ -144,6 +144,10 @@ async def test_address_computation(salt, pass_account_address, account, map_clas assert computed_address == address_from_event +@pytest.mark.skipif( + "--contract_dir=v1" in sys.argv, + reason="Contract exists only in v2 directory", +) @pytest.mark.asyncio @pytest.mark.parametrize( "calldata", @@ -159,21 +163,24 @@ async def test_address_computation(salt, pass_account_address, account, map_clas ) async def test_create_deployment_call_raw( account, - constructor_with_arguments_abi, - constructor_with_arguments_class_hash, + cairo1_constructor_with_arguments_class_hash, calldata, ): + contract = create_sierra_compiled_contract( + compiled_contract=load_contract("ConstructorWithArguments")["sierra"] + ) + deployer = Deployer(account_address=account.address) raw_calldata = translate_constructor_args( - abi=constructor_with_arguments_abi, constructor_args=calldata, cairo_version=0 + abi=contract.parsed_abi, constructor_args=calldata, cairo_version=1 ) ( deploy_call, contract_address, ) = deployer.create_contract_deployment_raw( - class_hash=constructor_with_arguments_class_hash, + class_hash=cairo1_constructor_with_arguments_class_hash, raw_calldata=raw_calldata, ) @@ -187,12 +194,19 @@ async def test_create_deployment_call_raw( assert contract_address != 0 +@pytest.mark.skipif( + "--contract_dir=v1" in sys.argv, + reason="Contract exists only in v2 directory", +) @pytest.mark.asyncio async def test_create_deployment_call_raw_supports_seed_0( account, - constructor_with_arguments_abi, - constructor_with_arguments_class_hash, + cairo1_constructor_with_arguments_class_hash, ): + contract = create_sierra_compiled_contract( + compiled_contract=load_contract("ConstructorWithArguments")["sierra"] + ) + sample_calldata = { # the transactions have to be different for each account "single_value": 20 if isinstance(account.client, FullNodeClient) else 30, @@ -203,24 +217,24 @@ async def test_create_deployment_call_raw_supports_seed_0( deployer = Deployer() raw_calldata = translate_constructor_args( - abi=constructor_with_arguments_abi, + abi=contract.parsed_abi, constructor_args=sample_calldata, - cairo_version=0, + cairo_version=1, ) expected_address = compute_address( - class_hash=constructor_with_arguments_class_hash, + class_hash=cairo1_constructor_with_arguments_class_hash, constructor_calldata=raw_calldata, - salt=0, + salt=1, ) ( deploy_call, contract_address, ) = deployer.create_contract_deployment_raw( - class_hash=constructor_with_arguments_class_hash, + class_hash=cairo1_constructor_with_arguments_class_hash, raw_calldata=raw_calldata, - salt=0, + salt=1, ) deploy_invoke_transaction = await account.sign_invoke_v1( From ad05ad8a6cb7bbf802e2e3b3175d37a1fee53ae6 Mon Sep 17 00:00:00 2001 From: jumpman <57270771+kkawula@users.noreply.github.com> Date: Tue, 6 Aug 2024 14:24:36 +0200 Subject: [PATCH 14/66] Remove old 'constructor_with_arguments' fixture --- starknet_py/tests/e2e/deploy/deployer_test.py | 6 +++--- starknet_py/tests/e2e/fixtures/contracts.py | 16 ---------------- starknet_py/tests/e2e/fixtures/contracts_v1.py | 2 +- 3 files changed, 4 insertions(+), 20 deletions(-) diff --git a/starknet_py/tests/e2e/deploy/deployer_test.py b/starknet_py/tests/e2e/deploy/deployer_test.py index 27287adc8..f1e0d23b0 100644 --- a/starknet_py/tests/e2e/deploy/deployer_test.py +++ b/starknet_py/tests/e2e/deploy/deployer_test.py @@ -201,7 +201,7 @@ async def test_create_deployment_call_raw( @pytest.mark.asyncio async def test_create_deployment_call_raw_supports_seed_0( account, - cairo1_constructor_with_arguments_class_hash, + constructor_with_arguments_class_hash, ): contract = create_sierra_compiled_contract( compiled_contract=load_contract("ConstructorWithArguments")["sierra"] @@ -223,7 +223,7 @@ async def test_create_deployment_call_raw_supports_seed_0( ) expected_address = compute_address( - class_hash=cairo1_constructor_with_arguments_class_hash, + class_hash=constructor_with_arguments_class_hash, constructor_calldata=raw_calldata, salt=1, ) @@ -232,7 +232,7 @@ async def test_create_deployment_call_raw_supports_seed_0( deploy_call, contract_address, ) = deployer.create_contract_deployment_raw( - class_hash=cairo1_constructor_with_arguments_class_hash, + class_hash=constructor_with_arguments_class_hash, raw_calldata=raw_calldata, salt=1, ) diff --git a/starknet_py/tests/e2e/fixtures/contracts.py b/starknet_py/tests/e2e/fixtures/contracts.py index b7b032fb1..a1b7e3e4c 100644 --- a/starknet_py/tests/e2e/fixtures/contracts.py +++ b/starknet_py/tests/e2e/fixtures/contracts.py @@ -367,19 +367,3 @@ def constructor_with_arguments_compiled() -> str: return read_contract( "constructor_with_arguments_compiled.json", directory=CONTRACTS_COMPILED_V0_DIR ) - - -@pytest_asyncio.fixture(scope="package") -async def constructor_with_arguments_class_hash( - account: BaseAccount, constructor_with_arguments_compiled -) -> int: - """ - Returns a class_hash of the constructor_with_arguments.cairo. - """ - declare = await account.sign_declare_v1( - compiled_contract=constructor_with_arguments_compiled, - max_fee=int(1e16), - ) - res = await account.client.declare(declare) - await account.client.wait_for_tx(res.transaction_hash) - return res.class_hash diff --git a/starknet_py/tests/e2e/fixtures/contracts_v1.py b/starknet_py/tests/e2e/fixtures/contracts_v1.py index d8e1ccc2c..9c9d8f5c7 100644 --- a/starknet_py/tests/e2e/fixtures/contracts_v1.py +++ b/starknet_py/tests/e2e/fixtures/contracts_v1.py @@ -43,7 +43,7 @@ async def cairo1_erc20_class_hash(account: BaseAccount) -> int: @pytest_asyncio.fixture(scope="package") -async def cairo1_constructor_with_arguments_class_hash(account: BaseAccount) -> int: +async def constructor_with_arguments_class_hash(account: BaseAccount) -> int: contract = load_contract("ConstructorWithArguments") class_hash, _ = await declare_cairo1_contract( account, contract["sierra"], contract["casm"] From a0db46febec3ce693e39fd95c06338f47c9fa0ed Mon Sep 17 00:00:00 2001 From: jumpman <57270771+kkawula@users.noreply.github.com> Date: Tue, 6 Aug 2024 14:33:44 +0200 Subject: [PATCH 15/66] Update 'test_deploying_with_udc' --- .../e2e/docs/guide/test_deploying_with_udc.py | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/starknet_py/tests/e2e/docs/guide/test_deploying_with_udc.py b/starknet_py/tests/e2e/docs/guide/test_deploying_with_udc.py index 9f81345ab..673ca1f20 100644 --- a/starknet_py/tests/e2e/docs/guide/test_deploying_with_udc.py +++ b/starknet_py/tests/e2e/docs/guide/test_deploying_with_udc.py @@ -1,13 +1,24 @@ +import sys + import pytest +from starknet_py.common import create_sierra_compiled_contract +from starknet_py.tests.e2e.fixtures.misc import load_contract + +@pytest.mark.skipif( + "--contract_dir=v1" in sys.argv, + reason="Contract exists only in v2 directory", +) @pytest.mark.asyncio async def test_deploying_with_udc( account, map_class_hash, - constructor_with_arguments_abi, constructor_with_arguments_class_hash, ): + contract = create_sierra_compiled_contract( + compiled_contract=load_contract("ConstructorWithArguments")["sierra"] + ) # pylint: disable=unused-variable, import-outside-toplevel, too-many-locals # docs: start from starknet_py.net.udc_deployer.deployer import Deployer @@ -36,7 +47,7 @@ async def test_deploying_with_udc( # docs: end contract_with_constructor_class_hash = constructor_with_arguments_class_hash - contract_with_constructor_abi = constructor_with_arguments_abi + contract_with_constructor_abi = contract.parsed_abi # docs: start contract_constructor = """ @@ -55,8 +66,8 @@ async def test_deploying_with_udc( # Note that this method also returns address of the contract we want to deploy deploy_call, address = deployer.create_contract_deployment( class_hash=contract_with_constructor_class_hash, - abi=contract_with_constructor_abi, - cairo_version=0, + abi=contract.parsed_abi, + cairo_version=1, calldata={ "single_value": 10, "tuple": (1, (2, 3)), @@ -71,14 +82,14 @@ async def test_deploying_with_udc( # docs: end deploy_call, _ = deployer.create_contract_deployment( class_hash=contract_with_constructor_class_hash, - abi=contract_with_constructor_abi, + abi=contract.parsed_abi, calldata={ "single_value": 0, "tuple": (1, (2, 3)), "arr": [1], "dict": {"value": 12, "nested_struct": {"value": 99}}, }, - cairo_version=0, + cairo_version=1, ) # docs: start # Or signed and send with an account From c735a0d7d40cf0587c669a28bff2a28c21f02b22 Mon Sep 17 00:00:00 2001 From: jumpman <57270771+kkawula@users.noreply.github.com> Date: Tue, 6 Aug 2024 15:17:56 +0200 Subject: [PATCH 16/66] Update 'constructor_with_arguments_abi' and 'constructor_with_arguments_class_hash' fixture --- starknet_py/tests/e2e/deploy/deployer_test.py | 41 ++++++------------- .../e2e/docs/guide/test_deploying_with_udc.py | 13 ++---- starknet_py/tests/e2e/fixtures/contracts.py | 25 ----------- .../tests/e2e/fixtures/contracts_v1.py | 16 +++++++- 4 files changed, 31 insertions(+), 64 deletions(-) diff --git a/starknet_py/tests/e2e/deploy/deployer_test.py b/starknet_py/tests/e2e/deploy/deployer_test.py index f1e0d23b0..ca0ba7673 100644 --- a/starknet_py/tests/e2e/deploy/deployer_test.py +++ b/starknet_py/tests/e2e/deploy/deployer_test.py @@ -2,13 +2,11 @@ import pytest -from starknet_py.common import create_sierra_compiled_contract from starknet_py.contract import Contract from starknet_py.hash.address import compute_address from starknet_py.net.full_node_client import FullNodeClient from starknet_py.net.udc_deployer.deployer import Deployer from starknet_py.tests.e2e.fixtures.constants import MAX_FEE -from starknet_py.tests.e2e.fixtures.misc import load_contract from starknet_py.utils.constructor_args_translator import translate_constructor_args @@ -43,11 +41,7 @@ async def test_throws_when_calldata_provided_without_abi(map_class_hash): reason="Contract exists only in v2 directory", ) @pytest.mark.asyncio -async def test_throws_when_calldata_not_provided(): - contract = create_sierra_compiled_contract( - compiled_contract=load_contract("ConstructorWithArguments")["sierra"] - ) - +async def test_throws_when_calldata_not_provided(constructor_with_arguments_abi): deployer = Deployer() with pytest.raises( @@ -55,7 +49,7 @@ async def test_throws_when_calldata_not_provided(): match="Provided contract has a constructor and no arguments were provided.", ): deployer.create_contract_deployment( - class_hash=1234, abi=contract.parsed_abi, cairo_version=1 + class_hash=1234, abi=constructor_with_arguments_abi, cairo_version=1 ) @@ -78,18 +72,15 @@ async def test_throws_when_calldata_not_provided(): ) async def test_constructor_arguments_contract_deploy( account, - cairo1_constructor_with_arguments_class_hash, + constructor_with_arguments_abi, + constructor_with_arguments_class_hash, calldata, ): - contract = create_sierra_compiled_contract( - compiled_contract=load_contract("ConstructorWithArguments")["sierra"] - ) - deployer = Deployer(account_address=account.address) deploy_call, contract_address = deployer.create_contract_deployment( - class_hash=cairo1_constructor_with_arguments_class_hash, - abi=contract.parsed_abi, + class_hash=constructor_with_arguments_class_hash, + abi=constructor_with_arguments_abi, calldata=calldata, cairo_version=1, ) @@ -102,7 +93,7 @@ async def test_constructor_arguments_contract_deploy( contract = Contract( address=contract_address, - abi=contract.parsed_abi, + abi=constructor_with_arguments_abi, provider=account, cairo_version=1, ) @@ -163,24 +154,21 @@ async def test_address_computation(salt, pass_account_address, account, map_clas ) async def test_create_deployment_call_raw( account, - cairo1_constructor_with_arguments_class_hash, + constructor_with_arguments_abi, + constructor_with_arguments_class_hash, calldata, ): - contract = create_sierra_compiled_contract( - compiled_contract=load_contract("ConstructorWithArguments")["sierra"] - ) - deployer = Deployer(account_address=account.address) raw_calldata = translate_constructor_args( - abi=contract.parsed_abi, constructor_args=calldata, cairo_version=1 + abi=constructor_with_arguments_abi, constructor_args=calldata, cairo_version=1 ) ( deploy_call, contract_address, ) = deployer.create_contract_deployment_raw( - class_hash=cairo1_constructor_with_arguments_class_hash, + class_hash=constructor_with_arguments_class_hash, raw_calldata=raw_calldata, ) @@ -201,12 +189,9 @@ async def test_create_deployment_call_raw( @pytest.mark.asyncio async def test_create_deployment_call_raw_supports_seed_0( account, + constructor_with_arguments_abi, constructor_with_arguments_class_hash, ): - contract = create_sierra_compiled_contract( - compiled_contract=load_contract("ConstructorWithArguments")["sierra"] - ) - sample_calldata = { # the transactions have to be different for each account "single_value": 20 if isinstance(account.client, FullNodeClient) else 30, @@ -217,7 +202,7 @@ async def test_create_deployment_call_raw_supports_seed_0( deployer = Deployer() raw_calldata = translate_constructor_args( - abi=contract.parsed_abi, + abi=constructor_with_arguments_abi, constructor_args=sample_calldata, cairo_version=1, ) diff --git a/starknet_py/tests/e2e/docs/guide/test_deploying_with_udc.py b/starknet_py/tests/e2e/docs/guide/test_deploying_with_udc.py index 673ca1f20..6edd4d60c 100644 --- a/starknet_py/tests/e2e/docs/guide/test_deploying_with_udc.py +++ b/starknet_py/tests/e2e/docs/guide/test_deploying_with_udc.py @@ -2,9 +2,6 @@ import pytest -from starknet_py.common import create_sierra_compiled_contract -from starknet_py.tests.e2e.fixtures.misc import load_contract - @pytest.mark.skipif( "--contract_dir=v1" in sys.argv, @@ -14,11 +11,9 @@ async def test_deploying_with_udc( account, map_class_hash, + constructor_with_arguments_abi, constructor_with_arguments_class_hash, ): - contract = create_sierra_compiled_contract( - compiled_contract=load_contract("ConstructorWithArguments")["sierra"] - ) # pylint: disable=unused-variable, import-outside-toplevel, too-many-locals # docs: start from starknet_py.net.udc_deployer.deployer import Deployer @@ -47,7 +42,7 @@ async def test_deploying_with_udc( # docs: end contract_with_constructor_class_hash = constructor_with_arguments_class_hash - contract_with_constructor_abi = contract.parsed_abi + contract_with_constructor_abi = constructor_with_arguments_abi # docs: start contract_constructor = """ @@ -66,7 +61,7 @@ async def test_deploying_with_udc( # Note that this method also returns address of the contract we want to deploy deploy_call, address = deployer.create_contract_deployment( class_hash=contract_with_constructor_class_hash, - abi=contract.parsed_abi, + abi=constructor_with_arguments_abi, cairo_version=1, calldata={ "single_value": 10, @@ -82,7 +77,7 @@ async def test_deploying_with_udc( # docs: end deploy_call, _ = deployer.create_contract_deployment( class_hash=contract_with_constructor_class_hash, - abi=contract.parsed_abi, + abi=constructor_with_arguments_abi, calldata={ "single_value": 0, "tuple": (1, (2, 3)), diff --git a/starknet_py/tests/e2e/fixtures/contracts.py b/starknet_py/tests/e2e/fixtures/contracts.py index a1b7e3e4c..384277e1a 100644 --- a/starknet_py/tests/e2e/fixtures/contracts.py +++ b/starknet_py/tests/e2e/fixtures/contracts.py @@ -342,28 +342,3 @@ async def simple_storage_with_event_class_hash( res = await account.client.declare(declare) await account.client.wait_for_tx(res.transaction_hash) return res.class_hash - - -@pytest.fixture(scope="package") -def constructor_with_arguments_abi() -> List: - """ - Returns an abi of the constructor_with_arguments.cairo. - """ - compiled_contract = create_compiled_contract( - compiled_contract=read_contract( - "constructor_with_arguments_compiled.json", - directory=CONTRACTS_COMPILED_V0_DIR, - ) - ) - assert compiled_contract.abi is not None - return compiled_contract.abi - - -@pytest.fixture(scope="package") -def constructor_with_arguments_compiled() -> str: - """ - Returns a compiled constructor_with_arguments.cairo. - """ - return read_contract( - "constructor_with_arguments_compiled.json", directory=CONTRACTS_COMPILED_V0_DIR - ) diff --git a/starknet_py/tests/e2e/fixtures/contracts_v1.py b/starknet_py/tests/e2e/fixtures/contracts_v1.py index 9c9d8f5c7..2b854250e 100644 --- a/starknet_py/tests/e2e/fixtures/contracts_v1.py +++ b/starknet_py/tests/e2e/fixtures/contracts_v1.py @@ -1,11 +1,11 @@ # pylint: disable=redefined-outer-name -from typing import Tuple +from typing import List, Tuple import pytest import pytest_asyncio from starknet_py.cairo.felt import encode_shortstring -from starknet_py.common import create_casm_class +from starknet_py.common import create_casm_class, create_sierra_compiled_contract from starknet_py.contract import Contract from starknet_py.hash.casm_class_hash import compute_casm_class_hash from starknet_py.net.account.base_account import BaseAccount @@ -51,6 +51,18 @@ async def constructor_with_arguments_class_hash(account: BaseAccount) -> int: return class_hash +@pytest.fixture(scope="package") +def constructor_with_arguments_abi() -> List: + """ + Returns an abi of the constructor_with_arguments.cairo. + """ + compiled_contract = create_sierra_compiled_contract( + compiled_contract=load_contract("ConstructorWithArguments")["sierra"] + ) + assert compiled_contract.parsed_abi is not None + return compiled_contract.parsed_abi + + @pytest_asyncio.fixture(scope="package") async def declare_v2_hello_starknet(account: BaseAccount) -> DeclareV2: contract = load_contract("HelloStarknet") From 02c164736ed1dffdca6dc7ccc05a1ffb4562f130 Mon Sep 17 00:00:00 2001 From: jumpman <57270771+kkawula@users.noreply.github.com> Date: Tue, 6 Aug 2024 16:02:41 +0200 Subject: [PATCH 17/66] Update docs example --- .../e2e/docs/guide/test_deploying_with_udc.py | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/starknet_py/tests/e2e/docs/guide/test_deploying_with_udc.py b/starknet_py/tests/e2e/docs/guide/test_deploying_with_udc.py index 6edd4d60c..42f0dc2aa 100644 --- a/starknet_py/tests/e2e/docs/guide/test_deploying_with_udc.py +++ b/starknet_py/tests/e2e/docs/guide/test_deploying_with_udc.py @@ -46,14 +46,22 @@ async def test_deploying_with_udc( # docs: start contract_constructor = """ - @constructor - func constructor{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( - single_value: felt, tuple: (felt, (felt, felt)), arr_len: felt, arr: felt*, dict: TopStruct - ) { - let (arr_sum) = array_sum(arr, arr_len); - storage.write((single_value, tuple, arr_sum, dict)); - return (); - } + #[constructor] + fn constructor(ref self: ContractState, single_value: felt252, tuple: (felt252, (felt252, felt252)), arr: Array, dict: TopStruct) { + let mut sum = 0; + let count = arr.len(); + let mut i: usize = 0; + while i != count { + let element: felt252 = arr[i].clone(); + sum += element; + i += 1; + }; + + self.single_value.write(single_value); + self.tuple.write(tuple); + self.arr_sum.write(sum); + self.dict.write(dict); + } """ # If contract constructor accepts arguments, as shown above, From c7152f28af364a78398c47a2241a8defcc4c0468 Mon Sep 17 00:00:00 2001 From: jumpman <57270771+kkawula@users.noreply.github.com> Date: Tue, 6 Aug 2024 17:15:52 +0200 Subject: [PATCH 18/66] Add 'map' contract implementation in cairo 1 --- .../tests/e2e/mock/contracts_v1/src/lib.cairo | 1 + .../tests/e2e/mock/contracts_v1/src/map.cairo | 18 +++++++++++++ .../tests/e2e/mock/contracts_v2/src/lib.cairo | 1 + .../tests/e2e/mock/contracts_v2/src/map.cairo | 25 +++++++++++++++++++ 4 files changed, 45 insertions(+) create mode 100644 starknet_py/tests/e2e/mock/contracts_v1/src/map.cairo create mode 100644 starknet_py/tests/e2e/mock/contracts_v2/src/map.cairo diff --git a/starknet_py/tests/e2e/mock/contracts_v1/src/lib.cairo b/starknet_py/tests/e2e/mock/contracts_v1/src/lib.cairo index ad1f24f90..8aa389b47 100644 --- a/starknet_py/tests/e2e/mock/contracts_v1/src/lib.cairo +++ b/starknet_py/tests/e2e/mock/contracts_v1/src/lib.cairo @@ -8,3 +8,4 @@ mod test_contract; mod test_enum; mod test_option; mod token_bridge; +mod map; diff --git a/starknet_py/tests/e2e/mock/contracts_v1/src/map.cairo b/starknet_py/tests/e2e/mock/contracts_v1/src/map.cairo new file mode 100644 index 000000000..eb6c489e2 --- /dev/null +++ b/starknet_py/tests/e2e/mock/contracts_v1/src/map.cairo @@ -0,0 +1,18 @@ +#[contract] +mod Map { + + struct Storage { + storage: LegacyMap::, + } + + #[external] + fn put(key: felt252, value: felt252) { + storage::write(key, value); + } + + #[external] + fn get(key: felt252) -> felt252 { + storage::read(key) + } + +} \ No newline at end of file diff --git a/starknet_py/tests/e2e/mock/contracts_v2/src/lib.cairo b/starknet_py/tests/e2e/mock/contracts_v2/src/lib.cairo index 33e16e5ff..fa7c75276 100644 --- a/starknet_py/tests/e2e/mock/contracts_v2/src/lib.cairo +++ b/starknet_py/tests/e2e/mock/contracts_v2/src/lib.cairo @@ -10,3 +10,4 @@ mod test_contract; mod test_enum; mod test_option; mod token_bridge; +mod map; diff --git a/starknet_py/tests/e2e/mock/contracts_v2/src/map.cairo b/starknet_py/tests/e2e/mock/contracts_v2/src/map.cairo new file mode 100644 index 000000000..40a924aa1 --- /dev/null +++ b/starknet_py/tests/e2e/mock/contracts_v2/src/map.cairo @@ -0,0 +1,25 @@ +#[starknet::interface] +trait IMap { + fn put(ref self: TMapState, key: felt252, value: felt252); + fn get(self: @TMapState, key: felt252) -> felt252; +} + + +#[starknet::contract] +mod Map { + #[storage] + struct Storage { + storage: LegacyMap::, + } + + #[abi(embed_v0)] + impl Map of super::IMap { + fn put(ref self: ContractState, key: felt252, value: felt252) { + self.storage.write(key, value); + } + + fn get(self: @ContractState, key: felt252) -> felt252 { + self.storage.read(key) + } + } +} \ No newline at end of file From e1dceb28ab9f8f89345b47ab912a76513d503268 Mon Sep 17 00:00:00 2001 From: jumpman <57270771+kkawula@users.noreply.github.com> Date: Tue, 6 Aug 2024 17:18:37 +0200 Subject: [PATCH 19/66] Add fixtures for new contract --- .../tests/e2e/fixtures/contracts_v1.py | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/starknet_py/tests/e2e/fixtures/contracts_v1.py b/starknet_py/tests/e2e/fixtures/contracts_v1.py index 2b854250e..a50972d02 100644 --- a/starknet_py/tests/e2e/fixtures/contracts_v1.py +++ b/starknet_py/tests/e2e/fixtures/contracts_v1.py @@ -190,3 +190,35 @@ async def deploy_string_contract( contract_name="MyString", class_hash=string_contract_class_hash, ) + + +@pytest_asyncio.fixture(scope="package") +async def cairo1_map_contract_declare_hash(account: BaseAccount) -> int: + contract = load_contract(contract_name="Map") + class_hash, _ = await declare_cairo1_contract( + account, + contract["sierra"], + contract["casm"], + ) + return class_hash + + +@pytest_asyncio.fixture(scope="package", name="map_contract") +async def deploy_map_contract( + account: BaseAccount, cairo1_map_contract_declare_hash +) -> Contract: + return await deploy_v1_contract( + account=account, + contract_name="Map", + class_hash=cairo1_map_contract_declare_hash, + ) + + +@pytest_asyncio.fixture(scope="package") +async def cairo1_map_contract_abi() -> List: + contract = load_contract(contract_name="Map") + compiled_contract = create_sierra_compiled_contract( + compiled_contract=contract["sierra"] + ) + assert compiled_contract.parsed_abi is not None + return compiled_contract.parsed_abi From 518eafa88b18c851f2ab4c8a7291b036300ba5d8 Mon Sep 17 00:00:00 2001 From: jumpman <57270771+kkawula@users.noreply.github.com> Date: Tue, 6 Aug 2024 17:19:41 +0200 Subject: [PATCH 20/66] Remove 'map_contract_declare_hahs' fixutre --- starknet_py/tests/e2e/block_test.py | 34 ++++--------------- .../test_synchronous_full_node_client.py | 2 +- starknet_py/tests/e2e/fixtures/contracts.py | 14 -------- 3 files changed, 7 insertions(+), 43 deletions(-) diff --git a/starknet_py/tests/e2e/block_test.py b/starknet_py/tests/e2e/block_test.py index 5a6320986..a95a40d95 100644 --- a/starknet_py/tests/e2e/block_test.py +++ b/starknet_py/tests/e2e/block_test.py @@ -1,7 +1,5 @@ import pytest -from starknet_py.contract import Contract -from starknet_py.net.account.base_account import BaseAccount from starknet_py.net.client_models import ( BlockStatus, L1DAMode, @@ -11,31 +9,17 @@ StarknetBlockWithReceipts, StarknetBlockWithTxHashes, ) -from starknet_py.tests.e2e.fixtures.constants import MAX_FEE - - -async def declare_contract(account: BaseAccount, compiled_contract: str): - declare_result = await Contract.declare_v1( - account=account, - compiled_contract=compiled_contract, - max_fee=MAX_FEE, - ) - await declare_result.wait_for_acceptance() @pytest.mark.asyncio -async def test_pending_block(account, map_compiled_contract): - await declare_contract(account, map_compiled_contract) - +async def test_pending_block(account): blk = await account.client.get_block(block_number="pending") assert blk.transactions is not None assert isinstance(blk, PendingStarknetBlock) @pytest.mark.asyncio -async def test_latest_block(account, map_compiled_contract): - await declare_contract(account, map_compiled_contract) - +async def test_latest_block(account): blk = await account.client.get_block(block_number="latest") assert blk.block_hash assert blk.transactions is not None @@ -51,15 +35,12 @@ async def test_block_with_tx_hashes_pending(account): @pytest.mark.asyncio -async def test_block_with_tx_hashes_latest( - account, - map_contract_declare_hash, -): +async def test_block_with_tx_hashes_latest(account): blk = await account.client.get_block_with_tx_hashes(block_number="latest") assert isinstance(blk, StarknetBlockWithTxHashes) assert isinstance(blk.transactions, list) - assert map_contract_declare_hash in blk.transactions + assert blk.transactions is not None assert blk.block_hash is not None assert blk.parent_hash is not None assert blk.block_number is not None @@ -82,15 +63,12 @@ async def test_get_block_with_txs_pending(account): @pytest.mark.asyncio -async def test_get_block_with_txs_latest( - account, - map_contract_declare_hash, -): +async def test_get_block_with_txs_latest(account): blk = await account.client.get_block_with_txs(block_number="latest") assert isinstance(blk, StarknetBlock) assert isinstance(blk.transactions, list) - assert blk.transactions[0].hash == map_contract_declare_hash + assert blk.transactions[0].hash is not None assert blk.block_hash is not None assert blk.parent_hash is not None assert blk.block_number is not None diff --git a/starknet_py/tests/e2e/docs/quickstart/test_synchronous_full_node_client.py b/starknet_py/tests/e2e/docs/quickstart/test_synchronous_full_node_client.py index 4e5c8be57..30bdd5a5c 100644 --- a/starknet_py/tests/e2e/docs/quickstart/test_synchronous_full_node_client.py +++ b/starknet_py/tests/e2e/docs/quickstart/test_synchronous_full_node_client.py @@ -3,7 +3,7 @@ def test_synchronous_full_node_client( client, - map_contract_declare_hash, # pylint: disable=unused-argument + cairo1_map_contract_declare_hash, # pylint: disable=unused-argument ): # pylint: disable=unused-variable fixture_client = client diff --git a/starknet_py/tests/e2e/fixtures/contracts.py b/starknet_py/tests/e2e/fixtures/contracts.py index 384277e1a..28fbbc48b 100644 --- a/starknet_py/tests/e2e/fixtures/contracts.py +++ b/starknet_py/tests/e2e/fixtures/contracts.py @@ -157,20 +157,6 @@ async def map_contract( return await deploy_contract(account, map_class_hash, abi) -@pytest_asyncio.fixture(scope="package") -async def map_contract_declare_hash( - account: BaseAccount, - map_compiled_contract: str, -): - declare_result = await Contract.declare_v1( - account=account, - compiled_contract=map_compiled_contract, - max_fee=MAX_FEE, - ) - await declare_result.wait_for_acceptance() - return declare_result.hash - - @pytest_asyncio.fixture(scope="function") async def simple_storage_with_event_contract( account: BaseAccount, From a1c69b444395129f60cf5918a1f8f9a4e875287c Mon Sep 17 00:00:00 2001 From: jumpman <57270771+kkawula@users.noreply.github.com> Date: Tue, 6 Aug 2024 17:46:36 +0200 Subject: [PATCH 21/66] Replace old 'map_contract' fixture --- .../e2e/docs/quickstart/test_using_contract.py | 2 +- starknet_py/tests/e2e/fixtures/contracts.py | 13 ------------- starknet_py/tests/e2e/fixtures/contracts_v1.py | 2 +- 3 files changed, 2 insertions(+), 15 deletions(-) diff --git a/starknet_py/tests/e2e/docs/quickstart/test_using_contract.py b/starknet_py/tests/e2e/docs/quickstart/test_using_contract.py index ab6dc6e66..7ca51e2c0 100644 --- a/starknet_py/tests/e2e/docs/quickstart/test_using_contract.py +++ b/starknet_py/tests/e2e/docs/quickstart/test_using_contract.py @@ -34,7 +34,7 @@ async def test_using_contract(account, map_contract): address=contract_address, abi=abi, provider=account, - cairo_version=0, + cairo_version=1, ) # All exposed functions are available at contract.functions. diff --git a/starknet_py/tests/e2e/fixtures/contracts.py b/starknet_py/tests/e2e/fixtures/contracts.py index 28fbbc48b..00488da2a 100644 --- a/starknet_py/tests/e2e/fixtures/contracts.py +++ b/starknet_py/tests/e2e/fixtures/contracts.py @@ -144,19 +144,6 @@ async def deployed_balance_contract( return deploy_result.deployed_contract -@pytest_asyncio.fixture(scope="package") -async def map_contract( - account: BaseAccount, - map_compiled_contract: str, - map_class_hash: int, -) -> Contract: - """ - Deploys map contract and returns its instance. - """ - abi = create_compiled_contract(compiled_contract=map_compiled_contract).abi - return await deploy_contract(account, map_class_hash, abi) - - @pytest_asyncio.fixture(scope="function") async def simple_storage_with_event_contract( account: BaseAccount, diff --git a/starknet_py/tests/e2e/fixtures/contracts_v1.py b/starknet_py/tests/e2e/fixtures/contracts_v1.py index a50972d02..197bf34d2 100644 --- a/starknet_py/tests/e2e/fixtures/contracts_v1.py +++ b/starknet_py/tests/e2e/fixtures/contracts_v1.py @@ -204,7 +204,7 @@ async def cairo1_map_contract_declare_hash(account: BaseAccount) -> int: @pytest_asyncio.fixture(scope="package", name="map_contract") -async def deploy_map_contract( +async def map_contract( account: BaseAccount, cairo1_map_contract_declare_hash ) -> Contract: return await deploy_v1_contract( From e5d6b71222ddccde537b96e6f5c471f53b645d8b Mon Sep 17 00:00:00 2001 From: jumpman <57270771+kkawula@users.noreply.github.com> Date: Tue, 6 Aug 2024 18:39:56 +0200 Subject: [PATCH 22/66] Replace old 'map_class_hash' fixture --- starknet_py/tests/e2e/account/account_test.py | 17 ++++------------- .../test_synchronous_full_node_client.py | 2 +- starknet_py/tests/e2e/fixtures/contracts.py | 14 -------------- starknet_py/tests/e2e/fixtures/contracts_v1.py | 8 +++----- 4 files changed, 8 insertions(+), 33 deletions(-) diff --git a/starknet_py/tests/e2e/account/account_test.py b/starknet_py/tests/e2e/account/account_test.py index d685aecb4..f0fca6185 100644 --- a/starknet_py/tests/e2e/account/account_test.py +++ b/starknet_py/tests/e2e/account/account_test.py @@ -125,26 +125,17 @@ async def test_account_estimate_fee_for_declare_transaction( @pytest.mark.asyncio -async def test_account_estimate_fee_for_transactions( - account, map_compiled_contract, map_contract -): - declare_tx = await account.sign_declare_v1( - compiled_contract=map_compiled_contract, max_fee=MAX_FEE - ) - +async def test_account_estimate_fee_for_transactions(account, map_contract): invoke_tx = await account.sign_invoke_v3( calls=Call(map_contract.address, get_selector_from_name("put"), [3, 4]), l1_resource_bounds=MAX_RESOURCE_BOUNDS_L1, - nonce=(declare_tx.nonce + 1), ) - estimated_fee = await account.estimate_fee(tx=[declare_tx, invoke_tx]) + estimated_fee = await account.estimate_fee(tx=[invoke_tx]) - assert len(estimated_fee) == 2 + assert len(estimated_fee) == 1 assert isinstance(estimated_fee[0], EstimatedFee) - assert isinstance(estimated_fee[1], EstimatedFee) - assert estimated_fee[0].unit == PriceUnit.WEI - assert estimated_fee[1].unit == PriceUnit.FRI + assert estimated_fee[0].unit == PriceUnit.FRI assert isinstance(estimated_fee[0].overall_fee, int) assert estimated_fee[0].overall_fee > 0 assert ( diff --git a/starknet_py/tests/e2e/docs/quickstart/test_synchronous_full_node_client.py b/starknet_py/tests/e2e/docs/quickstart/test_synchronous_full_node_client.py index 30bdd5a5c..8f93d9caf 100644 --- a/starknet_py/tests/e2e/docs/quickstart/test_synchronous_full_node_client.py +++ b/starknet_py/tests/e2e/docs/quickstart/test_synchronous_full_node_client.py @@ -3,7 +3,7 @@ def test_synchronous_full_node_client( client, - cairo1_map_contract_declare_hash, # pylint: disable=unused-argument + map_class_hash, # pylint: disable=unused-argument ): # pylint: disable=unused-variable fixture_client = client diff --git a/starknet_py/tests/e2e/fixtures/contracts.py b/starknet_py/tests/e2e/fixtures/contracts.py index 00488da2a..0097c1ed9 100644 --- a/starknet_py/tests/e2e/fixtures/contracts.py +++ b/starknet_py/tests/e2e/fixtures/contracts.py @@ -287,20 +287,6 @@ async def argent_cairo1_account_class_hash( ) -@pytest_asyncio.fixture(scope="package") -async def map_class_hash(account: BaseAccount, map_compiled_contract: str) -> int: - """ - Returns class_hash of the map.cairo. - """ - declare = await account.sign_declare_v1( - compiled_contract=map_compiled_contract, - max_fee=int(1e16), - ) - res = await account.client.declare(declare) - await account.client.wait_for_tx(res.transaction_hash) - return res.class_hash - - @pytest_asyncio.fixture(scope="package") async def simple_storage_with_event_class_hash( account: BaseAccount, simple_storage_with_event_compiled_contract: str diff --git a/starknet_py/tests/e2e/fixtures/contracts_v1.py b/starknet_py/tests/e2e/fixtures/contracts_v1.py index 197bf34d2..8e66cad66 100644 --- a/starknet_py/tests/e2e/fixtures/contracts_v1.py +++ b/starknet_py/tests/e2e/fixtures/contracts_v1.py @@ -193,7 +193,7 @@ async def deploy_string_contract( @pytest_asyncio.fixture(scope="package") -async def cairo1_map_contract_declare_hash(account: BaseAccount) -> int: +async def map_class_hash(account: BaseAccount) -> int: contract = load_contract(contract_name="Map") class_hash, _ = await declare_cairo1_contract( account, @@ -204,13 +204,11 @@ async def cairo1_map_contract_declare_hash(account: BaseAccount) -> int: @pytest_asyncio.fixture(scope="package", name="map_contract") -async def map_contract( - account: BaseAccount, cairo1_map_contract_declare_hash -) -> Contract: +async def map_contract(account: BaseAccount, map_class_hash) -> Contract: return await deploy_v1_contract( account=account, contract_name="Map", - class_hash=cairo1_map_contract_declare_hash, + class_hash=map_class_hash, ) From 964a289de9daf5940d106c2f89101179d49c0176 Mon Sep 17 00:00:00 2001 From: jumpman <57270771+kkawula@users.noreply.github.com> Date: Tue, 6 Aug 2024 18:57:55 +0200 Subject: [PATCH 23/66] Update a few tests --- starknet_py/tests/e2e/account/account_test.py | 35 ++++++++----------- starknet_py/tests/e2e/client/client_test.py | 17 --------- .../docs/guide/test_declaring_contracts.py | 20 +++++++---- .../tests/e2e/fixtures/contracts_v1.py | 10 ++++++ 4 files changed, 38 insertions(+), 44 deletions(-) diff --git a/starknet_py/tests/e2e/account/account_test.py b/starknet_py/tests/e2e/account/account_test.py index f0fca6185..306528c77 100644 --- a/starknet_py/tests/e2e/account/account_test.py +++ b/starknet_py/tests/e2e/account/account_test.py @@ -88,9 +88,14 @@ async def test_estimated_fee_greater_than_zero(account, erc20_contract): @pytest.mark.asyncio -async def test_estimate_fee_for_declare_transaction(account, map_compiled_contract): - declare_tx = await account.sign_declare_v1( - compiled_contract=map_compiled_contract, max_fee=MAX_FEE +async def test_estimate_fee_for_declare_transaction( + account, map_compiled_contract_and_class_hash +): + (compiled_contract, class_hash) = map_compiled_contract_and_class_hash + declare_tx = await account.sign_declare_v3( + compiled_contract=compiled_contract, + compiled_class_hash=class_hash, + l1_resource_bounds=MAX_RESOURCE_BOUNDS_L1, ) estimated_fee = await account.client.estimate_fee(tx=declare_tx) @@ -106,10 +111,13 @@ async def test_estimate_fee_for_declare_transaction(account, map_compiled_contra @pytest.mark.asyncio async def test_account_estimate_fee_for_declare_transaction( - account, map_compiled_contract + account, map_compiled_contract_and_class_hash ): - declare_tx = await account.sign_declare_v1( - compiled_contract=map_compiled_contract, max_fee=MAX_FEE + (compiled_contract, class_hash) = map_compiled_contract_and_class_hash + declare_tx = await account.sign_declare_v3( + compiled_contract=compiled_contract, + compiled_class_hash=class_hash, + l1_resource_bounds=MAX_RESOURCE_BOUNDS_L1, ) estimated_fee = await account.estimate_fee(tx=declare_tx) @@ -651,21 +659,6 @@ async def test_sign_invoke_v3_for_fee_estimation(account, map_contract): assert estimation.overall_fee > 0 -@pytest.mark.asyncio -async def test_sign_declare_v1_for_fee_estimation(account, map_compiled_contract): - transaction = await account.sign_declare_v1( - compiled_contract=map_compiled_contract, max_fee=MAX_FEE - ) - - estimate_fee_transaction = await account.sign_for_fee_estimate(transaction) - assert estimate_fee_transaction.version == transaction.version + 2**128 - - estimation = await account.client.estimate_fee(estimate_fee_transaction) - assert isinstance(estimation, EstimatedFee) - assert estimation.unit == PriceUnit.WEI - assert estimation.overall_fee > 0 - - @pytest.mark.asyncio async def test_sign_deploy_account_v1_for_fee_estimation( client, deploy_account_details_factory diff --git a/starknet_py/tests/e2e/client/client_test.py b/starknet_py/tests/e2e/client/client_test.py index 0ab08c8ba..9238c1e16 100644 --- a/starknet_py/tests/e2e/client/client_test.py +++ b/starknet_py/tests/e2e/client/client_test.py @@ -383,23 +383,6 @@ async def test_wait_for_tx_unknown_error( await client.wait_for_tx(tx_hash="0x2137") -@pytest.mark.asyncio -async def test_declare_contract(account, map_compiled_contract): - declare_tx = await account.sign_declare_v1( - compiled_contract=map_compiled_contract, max_fee=MAX_FEE - ) - - client = account.client - result = await client.declare(declare_tx) - await client.wait_for_tx(result.transaction_hash) - transaction_receipt = await client.get_transaction_receipt(result.transaction_hash) - - assert transaction_receipt.execution_status == TransactionExecutionStatus.SUCCEEDED - assert transaction_receipt.transaction_hash - assert 0 < transaction_receipt.actual_fee.amount <= MAX_FEE - assert transaction_receipt.type == TransactionType.DECLARE - - @pytest.mark.asyncio async def test_custom_session_client(map_contract, devnet): # We must access protected `_client` to test session diff --git a/starknet_py/tests/e2e/docs/guide/test_declaring_contracts.py b/starknet_py/tests/e2e/docs/guide/test_declaring_contracts.py index 7335d6e8e..92f23f26b 100644 --- a/starknet_py/tests/e2e/docs/guide/test_declaring_contracts.py +++ b/starknet_py/tests/e2e/docs/guide/test_declaring_contracts.py @@ -1,15 +1,23 @@ import pytest +from starknet_py.net.client_models import ResourceBounds + @pytest.mark.asyncio -async def test_declaring_contracts(account, map_compiled_contract): - contract_compiled = map_compiled_contract +async def test_declaring_contracts(account, map_compiled_contract_and_class_hash): + (compiled_contract, class_hash) = map_compiled_contract_and_class_hash # docs: start - # Account.sign_declare_v1 takes contract source code or compiled contract and returns DeclareV1 transaction - # Similarly, Account.sign_declare_v2 and Account.sign_declare_v3 return DeclareV2 and DeclareV3 respectively - declare_transaction = await account.sign_declare_v1( - compiled_contract=contract_compiled, max_fee=int(1e16) + # Account.sign_declare_v2 and Account.sign_declare_v3 takes string containing a compiled contract (sierra) + # and a class hash (casm_class_hash) + # Returns DeclareV2 and DeclareV3 respectively + + declare_transaction = await account.sign_declare_v3( + compiled_contract=compiled_contract, + compiled_class_hash=class_hash, + l1_resource_bounds=ResourceBounds( + max_amount=5000, max_price_per_unit=int(1e12) + ), ) # To declare a contract, send Declare transaction with Client.declare method diff --git a/starknet_py/tests/e2e/fixtures/contracts_v1.py b/starknet_py/tests/e2e/fixtures/contracts_v1.py index 8e66cad66..02e59e550 100644 --- a/starknet_py/tests/e2e/fixtures/contracts_v1.py +++ b/starknet_py/tests/e2e/fixtures/contracts_v1.py @@ -220,3 +220,13 @@ async def cairo1_map_contract_abi() -> List: ) assert compiled_contract.parsed_abi is not None return compiled_contract.parsed_abi + + +@pytest.fixture(scope="package") +def map_compiled_contract_and_class_hash() -> Tuple[str, int]: + contract = load_contract("Map") + + return ( + contract["sierra"], + compute_casm_class_hash(create_casm_class(contract["casm"])), + ) From a7d664caee259f8479b0f5eafdc9166d192a6d95 Mon Sep 17 00:00:00 2001 From: jumpman <57270771+kkawula@users.noreply.github.com> Date: Tue, 6 Aug 2024 20:19:36 +0200 Subject: [PATCH 24/66] Update 'test_deploying_in_multicall' --- .../tests/e2e/docs/guide/test_deploying_in_multicall.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/starknet_py/tests/e2e/docs/guide/test_deploying_in_multicall.py b/starknet_py/tests/e2e/docs/guide/test_deploying_in_multicall.py index b62d03fcd..8df3252e6 100644 --- a/starknet_py/tests/e2e/docs/guide/test_deploying_in_multicall.py +++ b/starknet_py/tests/e2e/docs/guide/test_deploying_in_multicall.py @@ -1,10 +1,8 @@ import pytest -from starknet_py.common import create_compiled_contract - @pytest.mark.asyncio -async def test_deploying_in_multicall(account, map_class_hash, map_compiled_contract): +async def test_deploying_in_multicall(account, map_class_hash, cairo1_map_contract_abi): # pylint: disable=import-outside-toplevel, # docs: start from starknet_py.contract import Contract @@ -19,12 +17,12 @@ async def test_deploying_in_multicall(account, map_class_hash, map_compiled_cont ) # docs: end - map_abi = create_compiled_contract(compiled_contract=map_compiled_contract).abi + map_abi = cairo1_map_contract_abi # docs: start # Address of the `map` contract is known here, so we can create its instance! map_contract = Contract( - address=address, abi=map_abi, provider=account, cairo_version=0 + address=address, abi=map_abi, provider=account, cairo_version=1 ) # And now we can prepare a call From 2b8520b9f7456756808aaaa6131d322dd5e0a17e Mon Sep 17 00:00:00 2001 From: jumpman <57270771+kkawula@users.noreply.github.com> Date: Tue, 6 Aug 2024 20:47:57 +0200 Subject: [PATCH 25/66] Remove 'Simple declare and deploy' paragraph from docs --- docs/guide/deploying_contracts.rst | 11 ------ .../guide/test_simple_declare_and_deploy.py | 35 ------------------- 2 files changed, 46 deletions(-) delete mode 100644 starknet_py/tests/e2e/docs/guide/test_simple_declare_and_deploy.py diff --git a/docs/guide/deploying_contracts.rst b/docs/guide/deploying_contracts.rst index bd63067d1..a3780c6d7 100644 --- a/docs/guide/deploying_contracts.rst +++ b/docs/guide/deploying_contracts.rst @@ -14,17 +14,6 @@ Here's an example how to use it. :dedent: 4 -Simple declare and deploy -------------------------- - -The simplest way of declaring and deploying contracts on the Starknet is to use the :ref:`Contract` class. -Under the hood, this flow first sends ``Declare`` transaction and then sends ``Invoke`` -through Universal Deployment Contract (UDC) to deploy a contract. - -.. codesnippet:: ../../starknet_py/tests/e2e/docs/guide/test_simple_declare_and_deploy.py - :language: python - :dedent: 4 - Simple deploy ------------- diff --git a/starknet_py/tests/e2e/docs/guide/test_simple_declare_and_deploy.py b/starknet_py/tests/e2e/docs/guide/test_simple_declare_and_deploy.py deleted file mode 100644 index c1d64a1d4..000000000 --- a/starknet_py/tests/e2e/docs/guide/test_simple_declare_and_deploy.py +++ /dev/null @@ -1,35 +0,0 @@ -import pytest - - -@pytest.mark.asyncio -async def test_simple_declare_and_deploy(account, map_compiled_contract): - # pylint: disable=import-outside-toplevel - # docs: start - from starknet_py.contract import Contract - - # docs: end - - compiled_contract = map_compiled_contract - # docs: start - - # To declare through Contract class you have to compile a contract and pass it - # to Contract.declare_v1 or Contract.declare_v3 - declare_result = await Contract.declare_v1( - account=account, compiled_contract=compiled_contract, max_fee=int(1e18) - ) - # Wait for the transaction - await declare_result.wait_for_acceptance() - - # After contract is declared it can be deployed - deploy_result = await declare_result.deploy_v1(max_fee=int(1e18)) - await deploy_result.wait_for_acceptance() - - # You can pass more arguments to the `deploy` method. Check `API` section to learn more - - # To interact with just deployed contract get its instance from the deploy_result - contract = deploy_result.deployed_contract - - # Now, any of the contract functions can be called - # docs: end - - assert contract.address != 0 From bf0be0d032599a08c95ddb5b3184cbd496cee8ff Mon Sep 17 00:00:00 2001 From: jumpman <57270771+kkawula@users.noreply.github.com> Date: Tue, 6 Aug 2024 21:23:47 +0200 Subject: [PATCH 26/66] Update docs example 'Quickstart - Using Account' --- .../e2e/docs/quickstart/test_using_account.py | 39 ++++++++++++++----- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/starknet_py/tests/e2e/docs/quickstart/test_using_account.py b/starknet_py/tests/e2e/docs/quickstart/test_using_account.py index 60a118ba6..7c3ad2c7a 100644 --- a/starknet_py/tests/e2e/docs/quickstart/test_using_account.py +++ b/starknet_py/tests/e2e/docs/quickstart/test_using_account.py @@ -2,25 +2,37 @@ import pytest -from starknet_py.tests.e2e.fixtures.constants import MAX_FEE +from starknet_py.net.client_models import ResourceBounds directory = os.path.dirname(__file__) @pytest.mark.asyncio -async def test_using_account(account, map_compiled_contract): +async def test_using_account(account, map_compiled_contract_and_class_hash): + (compiled_contract, class_hash) = map_compiled_contract_and_class_hash # pylint: disable=import-outside-toplevel, duplicate-code, too-many-locals # docs: start from starknet_py.contract import Contract # docs: end # docs: start + l1_resource_bounds = ResourceBounds( + max_amount=int(1e5), max_price_per_unit=int(1e13) + ) # Declare and deploy an example contract which implements a simple k-v store. - declare_result = await Contract.declare_v1( - account=account, compiled_contract=map_compiled_contract, max_fee=MAX_FEE + # Contract.declare_v3 takes string containing a compiled contract (sierra) and + # a class hash (casm_class_hash) or string containing a compiled contract (casm) + declare_result = await Contract.declare_v3( + account, + compiled_contract=compiled_contract, + compiled_class_hash=class_hash, + l1_resource_bounds=l1_resource_bounds, ) + await declare_result.wait_for_acceptance() - deploy_result = await declare_result.deploy_v1(max_fee=MAX_FEE) + deploy_result = await declare_result.deploy_v3( + l1_resource_bounds=l1_resource_bounds, + ) # Wait until deployment transaction is accepted await deploy_result.wait_for_acceptance() @@ -30,7 +42,13 @@ async def test_using_account(account, map_compiled_contract): # Adds a transaction to mutate the state of k-v store. The call goes through account proxy, because we've used # Account to create the contract object await ( - await map_contract.functions["put"].invoke_v1(k, v, max_fee=int(1e16)) + await map_contract.functions["put"].invoke_v3( + k, + v, + l1_resource_bounds=ResourceBounds( + max_amount=int(1e5), max_price_per_unit=int(1e13) + ), + ) ).wait_for_acceptance() # Retrieves the value, which is equal to 4324 in this case @@ -40,12 +58,15 @@ async def test_using_account(account, map_compiled_contract): # Creates a list of prepared function calls calls = [ - map_contract.functions["put"].prepare_invoke_v1(key=10, value=20), - map_contract.functions["put"].prepare_invoke_v1(key=30, value=40), + map_contract.functions["put"].prepare_invoke_v3(key=10, value=20), + map_contract.functions["put"].prepare_invoke_v3(key=30, value=40), ] # Executes only one transaction with prepared calls - transaction_response = await account.execute_v1(calls=calls, max_fee=int(1e16)) + transaction_response = await account.execute_v3( + calls=calls, + l1_resource_bounds=l1_resource_bounds, + ) await account.client.wait_for_tx(transaction_response.transaction_hash) # docs: end From dc814a2813d3c83001cb1f4b081988a0901d9374 Mon Sep 17 00:00:00 2001 From: jumpman <57270771+kkawula@users.noreply.github.com> Date: Tue, 6 Aug 2024 21:45:09 +0200 Subject: [PATCH 27/66] Update docs example 'Guide - test_simple_deploy --- .../tests/e2e/docs/guide/test_simple_deploy.py | 16 ++++++++++------ starknet_py/tests/e2e/fixtures/contracts_v1.py | 10 ++++++++++ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/starknet_py/tests/e2e/docs/guide/test_simple_deploy.py b/starknet_py/tests/e2e/docs/guide/test_simple_deploy.py index 8d3ba2c87..8d0d5b86e 100644 --- a/starknet_py/tests/e2e/docs/guide/test_simple_deploy.py +++ b/starknet_py/tests/e2e/docs/guide/test_simple_deploy.py @@ -1,18 +1,20 @@ import pytest -from starknet_py.common import create_compiled_contract +from starknet_py.net.client_models import ResourceBounds @pytest.mark.asyncio -async def test_simple_deploy(account, map_class_hash, map_compiled_contract): +async def test_simple_deploy( + account, cairo1_hello_starknet_class_hash, cairo1_hello_starknet_abi +): # pylint: disable=import-outside-toplevel # docs: start from starknet_py.contract import Contract # docs: end - class_hash = map_class_hash - abi = create_compiled_contract(compiled_contract=map_compiled_contract).abi + class_hash = cairo1_hello_starknet_class_hash + abi = cairo1_hello_starknet_abi # docs: start # To deploy contract just use `Contract.deploy_contract_v1` method @@ -25,12 +27,14 @@ async def test_simple_deploy(account, map_class_hash, map_compiled_contract): constructor_args = None # docs: start - deploy_result = await Contract.deploy_contract_v1( + deploy_result = await Contract.deploy_contract_v3( account=account, class_hash=class_hash, abi=abi, constructor_args=constructor_args, - max_fee=int(1e16), + l1_resource_bounds=ResourceBounds( + max_amount=int(1e5), max_price_per_unit=int(1e13) + ), ) # `Contract.deploy_contract_v1` and `Contract.deploy_contract_v3` methods have an optional parameter diff --git a/starknet_py/tests/e2e/fixtures/contracts_v1.py b/starknet_py/tests/e2e/fixtures/contracts_v1.py index 02e59e550..4a84a2ff0 100644 --- a/starknet_py/tests/e2e/fixtures/contracts_v1.py +++ b/starknet_py/tests/e2e/fixtures/contracts_v1.py @@ -84,6 +84,16 @@ async def cairo1_hello_starknet_class_hash_tx_hash( return resp.class_hash, resp.transaction_hash +@pytest_asyncio.fixture(scope="package") +async def cairo1_hello_starknet_abi() -> List: + contract = load_contract("HelloStarknet") + compiled_contract = create_sierra_compiled_contract( + compiled_contract=contract["sierra"] + ) + assert compiled_contract.parsed_abi is not None + return compiled_contract.parsed_abi + + @pytest.fixture(scope="package") def cairo1_hello_starknet_class_hash( cairo1_hello_starknet_class_hash_tx_hash: Tuple[int, int] From 8e9b9044635e9728fcc9bddff2d64dbfb1ee8f56 Mon Sep 17 00:00:00 2001 From: jumpman <57270771+kkawula@users.noreply.github.com> Date: Tue, 6 Aug 2024 21:46:47 +0200 Subject: [PATCH 28/66] Remove fixtures 'map_source_code' and 'map_compiled_contract' --- starknet_py/tests/e2e/fixtures/contracts.py | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/starknet_py/tests/e2e/fixtures/contracts.py b/starknet_py/tests/e2e/fixtures/contracts.py index 0097c1ed9..9a8eb4a5d 100644 --- a/starknet_py/tests/e2e/fixtures/contracts.py +++ b/starknet_py/tests/e2e/fixtures/contracts.py @@ -16,7 +16,6 @@ from starknet_py.net.udc_deployer.deployer import Deployer from starknet_py.tests.e2e.fixtures.constants import ( CONTRACTS_COMPILED_V0_DIR, - CONTRACTS_DIR, MAX_FEE, PRECOMPILED_CONTRACTS_DIR, STRK_FEE_CONTRACT_ADDRESS, @@ -28,22 +27,6 @@ ) -@pytest.fixture(scope="package") -def map_source_code() -> str: - """ - Returns source code of the map contract. - """ - return read_contract("map.cairo", directory=CONTRACTS_DIR) - - -@pytest.fixture(scope="package") -def map_compiled_contract() -> str: - """ - Returns compiled map contract. - """ - return read_contract("map_compiled.json", directory=CONTRACTS_COMPILED_V0_DIR) - - @pytest.fixture(scope="package") def sierra_minimal_compiled_contract_and_class_hash() -> Tuple[str, int]: """ From 44fb7c2f7406fd59a084e797a149c0f0c2732af2 Mon Sep 17 00:00:00 2001 From: jumpman <57270771+kkawula@users.noreply.github.com> Date: Tue, 6 Aug 2024 22:06:45 +0200 Subject: [PATCH 29/66] Fix PriceUnit assertion in 'test_account_estimate_fee_for_declare_transaction' --- starknet_py/tests/e2e/account/account_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/starknet_py/tests/e2e/account/account_test.py b/starknet_py/tests/e2e/account/account_test.py index 306528c77..76cfbb288 100644 --- a/starknet_py/tests/e2e/account/account_test.py +++ b/starknet_py/tests/e2e/account/account_test.py @@ -122,7 +122,7 @@ async def test_account_estimate_fee_for_declare_transaction( estimated_fee = await account.estimate_fee(tx=declare_tx) - assert estimated_fee.unit == PriceUnit.WEI + assert estimated_fee.unit == PriceUnit.FRI assert isinstance(estimated_fee.overall_fee, int) assert estimated_fee.overall_fee > 0 assert ( From a02e66374ab3cb89705ff93d45ca65c17dd78870 Mon Sep 17 00:00:00 2001 From: jumpman <57270771+kkawula@users.noreply.github.com> Date: Tue, 6 Aug 2024 22:15:23 +0200 Subject: [PATCH 30/66] Add docs test to skip because of redeclaration :( --- starknet_py/tests/e2e/docs/guide/test_declaring_contracts.py | 2 ++ starknet_py/tests/e2e/docs/quickstart/test_using_account.py | 2 ++ 2 files changed, 4 insertions(+) diff --git a/starknet_py/tests/e2e/docs/guide/test_declaring_contracts.py b/starknet_py/tests/e2e/docs/guide/test_declaring_contracts.py index 92f23f26b..b17a0484b 100644 --- a/starknet_py/tests/e2e/docs/guide/test_declaring_contracts.py +++ b/starknet_py/tests/e2e/docs/guide/test_declaring_contracts.py @@ -3,6 +3,8 @@ from starknet_py.net.client_models import ResourceBounds +# TODO (#1419): Fix contract redeclaration +@pytest.mark.skip(reason="Redeclaration occurred") @pytest.mark.asyncio async def test_declaring_contracts(account, map_compiled_contract_and_class_hash): (compiled_contract, class_hash) = map_compiled_contract_and_class_hash diff --git a/starknet_py/tests/e2e/docs/quickstart/test_using_account.py b/starknet_py/tests/e2e/docs/quickstart/test_using_account.py index 7c3ad2c7a..cc7c4cba1 100644 --- a/starknet_py/tests/e2e/docs/quickstart/test_using_account.py +++ b/starknet_py/tests/e2e/docs/quickstart/test_using_account.py @@ -7,6 +7,8 @@ directory = os.path.dirname(__file__) +# TODO (#1419): Fix contract redeclaration +@pytest.mark.skip(reason="Redeclaration occurred") @pytest.mark.asyncio async def test_using_account(account, map_compiled_contract_and_class_hash): (compiled_contract, class_hash) = map_compiled_contract_and_class_hash From 04c5850f7cc9ebb4c44de44e4a2cfc88d33aa403 Mon Sep 17 00:00:00 2001 From: jumpman <57270771+kkawula@users.noreply.github.com> Date: Tue, 6 Aug 2024 22:20:03 +0200 Subject: [PATCH 31/66] Remove map.cairo --- .../tests/e2e/mock/contracts/map.cairo | 25 ------------------- 1 file changed, 25 deletions(-) delete mode 100644 starknet_py/tests/e2e/mock/contracts/map.cairo diff --git a/starknet_py/tests/e2e/mock/contracts/map.cairo b/starknet_py/tests/e2e/mock/contracts/map.cairo deleted file mode 100644 index 9d7ddc268..000000000 --- a/starknet_py/tests/e2e/mock/contracts/map.cairo +++ /dev/null @@ -1,25 +0,0 @@ -// Declare this file as a Starknet contract and set the required -// builtins. -%lang starknet -%builtins pedersen range_check - -from starkware.cairo.common.cairo_builtins import HashBuiltin - -// Define a storage variable. -@storage_var -func storage(key: felt) -> (value: felt) { -} - -@external -func put{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(key: felt, value: felt) { - storage.write(key, value); - return (); -} - -@view -func get{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(key: felt) -> ( - res: felt -) { - let (value) = storage.read(key); - return (value,); -} From 6f57a8d03b101d8c782e4338e7c75c7b2b7c0ca3 Mon Sep 17 00:00:00 2001 From: jumpman <57270771+kkawula@users.noreply.github.com> Date: Tue, 6 Aug 2024 22:33:09 +0200 Subject: [PATCH 32/66] Remove 'replace_class.cairo' conatract and fixture --- .../tests/e2e/client/fixtures/transactions.py | 33 ++----------------- .../e2e/mock/contracts/replace_class.cairo | 11 ------- 2 files changed, 2 insertions(+), 42 deletions(-) delete mode 100644 starknet_py/tests/e2e/mock/contracts/replace_class.cairo diff --git a/starknet_py/tests/e2e/client/fixtures/transactions.py b/starknet_py/tests/e2e/client/fixtures/transactions.py index 27ca47a1c..6ac67e52a 100644 --- a/starknet_py/tests/e2e/client/fixtures/transactions.py +++ b/starknet_py/tests/e2e/client/fixtures/transactions.py @@ -1,5 +1,5 @@ # pylint: disable=redefined-outer-name -from typing import Tuple, cast +from typing import Tuple import pytest import pytest_asyncio @@ -12,8 +12,7 @@ from starknet_py.tests.e2e.client.fixtures.prepare_net_for_gateway_test import ( PreparedNetworkData, ) -from starknet_py.tests.e2e.fixtures.constants import CONTRACTS_COMPILED_V0_DIR, MAX_FEE -from starknet_py.tests.e2e.fixtures.misc import read_contract +from starknet_py.tests.e2e.fixtures.constants import MAX_FEE from starknet_py.tests.e2e.utils import ( get_deploy_account_details, get_deploy_account_transaction, @@ -94,31 +93,3 @@ async def block_with_declare_v2_number( cairo1_hello_starknet_tx_hash ) return declare_v2_receipt.block_number - - -@pytest_asyncio.fixture(scope="function") -async def replaced_class(account: Account, map_class_hash: int) -> Tuple[int, int, int]: - """ - Returns block_number, contract_address and class_hash of transaction replacing implementation. - """ - compiled_contract = read_contract( - "replace_class_compiled.json", directory=CONTRACTS_COMPILED_V0_DIR - ) - - declare_result = await ( - await Contract.declare_v1(account, compiled_contract, max_fee=MAX_FEE) - ).wait_for_acceptance() - - deploy_result = await ( - await declare_result.deploy_v1(max_fee=MAX_FEE) - ).wait_for_acceptance() - - contract = deploy_result.deployed_contract - - resp = await ( - await contract.functions["replace_implementation"].invoke_v1( - new_class=map_class_hash, max_fee=MAX_FEE - ) - ).wait_for_acceptance() - - return cast(int, resp.block_number), contract.address, map_class_hash diff --git a/starknet_py/tests/e2e/mock/contracts/replace_class.cairo b/starknet_py/tests/e2e/mock/contracts/replace_class.cairo deleted file mode 100644 index f20dca5c7..000000000 --- a/starknet_py/tests/e2e/mock/contracts/replace_class.cairo +++ /dev/null @@ -1,11 +0,0 @@ -%lang starknet -%builtins pedersen range_check - -from starkware.cairo.common.cairo_builtins import HashBuiltin -from starkware.starknet.common.syscalls import replace_class - -@external -func replace_implementation{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*}(new_class: felt) { - replace_class(new_class); - return (); -} From 7d163b07ec24138f56af7cafd9d765666d0c6952 Mon Sep 17 00:00:00 2001 From: jumpman <57270771+kkawula@users.noreply.github.com> Date: Tue, 6 Aug 2024 22:33:54 +0200 Subject: [PATCH 33/66] Remove unused fixture 'fixture_balance_contract' --- starknet_py/tests/e2e/fixtures/contracts.py | 8 -------- 1 file changed, 8 deletions(-) diff --git a/starknet_py/tests/e2e/fixtures/contracts.py b/starknet_py/tests/e2e/fixtures/contracts.py index 9a8eb4a5d..f836a84de 100644 --- a/starknet_py/tests/e2e/fixtures/contracts.py +++ b/starknet_py/tests/e2e/fixtures/contracts.py @@ -194,14 +194,6 @@ def fee_contract_abi(): ] -@pytest.fixture(name="balance_contract") -def fixture_balance_contract() -> str: - """ - Returns compiled code of the balance.cairo contract. - """ - return read_contract("balance_compiled.json", directory=CONTRACTS_COMPILED_V0_DIR) - - async def declare_account(account: BaseAccount, compiled_account_contract: str) -> int: """ Declares a specified account. From adfc532ba879ee020b01d7a0cb383526a6e8b47f Mon Sep 17 00:00:00 2001 From: jumpman <57270771+kkawula@users.noreply.github.com> Date: Wed, 7 Aug 2024 10:55:34 +0200 Subject: [PATCH 34/66] Upadte 'test_estimate_fee_for_multiple_transactions' --- starknet_py/tests/e2e/client/client_test.py | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/starknet_py/tests/e2e/client/client_test.py b/starknet_py/tests/e2e/client/client_test.py index 9238c1e16..3e5123b8b 100644 --- a/starknet_py/tests/e2e/client/client_test.py +++ b/starknet_py/tests/e2e/client/client_test.py @@ -229,16 +229,7 @@ async def test_estimate_fee_for_multiple_transactions( ) invoke_tx = await account.sign_for_fee_estimate(invoke_tx) - declare_tx = await account.sign_declare_v1( - compiled_contract=read_contract( - "map_compiled.json", directory=CONTRACTS_COMPILED_V0_DIR - ), - max_fee=MAX_FEE, - ) - declare_tx = dataclasses.replace(declare_tx, nonce=invoke_tx.nonce + 1) - declare_tx = await account.sign_for_fee_estimate(declare_tx) - - transactions = [invoke_tx, declare_tx, deploy_account_transaction] + transactions = [invoke_tx, deploy_account_transaction] estimated_fees = await client.estimate_fee(tx=transactions, block_number="latest") From b01371fa11846ff1c29a119bd0d32704b99dcea7 Mon Sep 17 00:00:00 2001 From: jumpman <57270771+kkawula@users.noreply.github.com> Date: Wed, 7 Aug 2024 10:59:45 +0200 Subject: [PATCH 35/66] Update 'test_simulate_transactions_declare' --- starknet_py/tests/e2e/client/client_test.py | 4 +--- .../tests/e2e/client/full_node_test.py | 20 +++++++++---------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/starknet_py/tests/e2e/client/client_test.py b/starknet_py/tests/e2e/client/client_test.py index 3e5123b8b..c45fd51e5 100644 --- a/starknet_py/tests/e2e/client/client_test.py +++ b/starknet_py/tests/e2e/client/client_test.py @@ -1,5 +1,4 @@ # pylint: disable=too-many-arguments -import dataclasses from typing import Tuple from unittest.mock import AsyncMock, Mock, patch @@ -37,8 +36,7 @@ from starknet_py.net.http_client import RpcHttpClient from starknet_py.net.models.transaction import DeclareV2 from starknet_py.net.udc_deployer.deployer import Deployer -from starknet_py.tests.e2e.fixtures.constants import CONTRACTS_COMPILED_V0_DIR, MAX_FEE -from starknet_py.tests.e2e.fixtures.misc import read_contract +from starknet_py.tests.e2e.fixtures.constants import MAX_FEE from starknet_py.transaction_errors import ( TransactionNotReceivedError, TransactionRejectedError, diff --git a/starknet_py/tests/e2e/client/full_node_test.py b/starknet_py/tests/e2e/client/full_node_test.py index b95f3cee2..eabf4af82 100644 --- a/starknet_py/tests/e2e/client/full_node_test.py +++ b/starknet_py/tests/e2e/client/full_node_test.py @@ -26,12 +26,8 @@ ) from starknet_py.net.full_node_client import _to_rpc_felt from starknet_py.net.models import StarknetChainId -from starknet_py.tests.e2e.fixtures.constants import CONTRACTS_COMPILED_V0_DIR -from starknet_py.tests.e2e.fixtures.misc import ( - ContractVersion, - load_contract, - read_contract, -) +from starknet_py.tests.e2e.fixtures.constants import MAX_RESOURCE_BOUNDS_L1 +from starknet_py.tests.e2e.fixtures.misc import ContractVersion, load_contract from starknet_py.tests.e2e.utils import create_empty_block @@ -470,11 +466,15 @@ async def test_simulate_transactions_invoke(account, deployed_balance_contract): @pytest.mark.asyncio -async def test_simulate_transactions_declare(account): - compiled_contract = read_contract( - "map_compiled.json", directory=CONTRACTS_COMPILED_V0_DIR +async def test_simulate_transactions_declare( + account, map_compiled_contract_and_class_hash +): + (compiled_contract, class_hash) = map_compiled_contract_and_class_hash + declare_tx = await account.sign_declare_v3( + compiled_contract=compiled_contract, + compiled_class_hash=class_hash, + l1_resource_bounds=MAX_RESOURCE_BOUNDS_L1, ) - declare_tx = await account.sign_declare_v1(compiled_contract, max_fee=int(1e16)) simulated_txs = await account.client.simulate_transactions( transactions=[declare_tx], block_number="latest" From 79390619e0348e519fc09b188ed38c2b26cfda7e Mon Sep 17 00:00:00 2001 From: jumpman <57270771+kkawula@users.noreply.github.com> Date: Wed, 7 Aug 2024 13:25:29 +0200 Subject: [PATCH 36/66] Remove 'test_simulate_transactions_declare' --- .../tests/e2e/client/full_node_test.py | 22 ------------------- 1 file changed, 22 deletions(-) diff --git a/starknet_py/tests/e2e/client/full_node_test.py b/starknet_py/tests/e2e/client/full_node_test.py index eabf4af82..db745e686 100644 --- a/starknet_py/tests/e2e/client/full_node_test.py +++ b/starknet_py/tests/e2e/client/full_node_test.py @@ -26,7 +26,6 @@ ) from starknet_py.net.full_node_client import _to_rpc_felt from starknet_py.net.models import StarknetChainId -from starknet_py.tests.e2e.fixtures.constants import MAX_RESOURCE_BOUNDS_L1 from starknet_py.tests.e2e.fixtures.misc import ContractVersion, load_contract from starknet_py.tests.e2e.utils import create_empty_block @@ -465,27 +464,6 @@ async def test_simulate_transactions_invoke(account, deployed_balance_contract): assert simulated_txs[0].transaction_trace.execution_resources is not None -@pytest.mark.asyncio -async def test_simulate_transactions_declare( - account, map_compiled_contract_and_class_hash -): - (compiled_contract, class_hash) = map_compiled_contract_and_class_hash - declare_tx = await account.sign_declare_v3( - compiled_contract=compiled_contract, - compiled_class_hash=class_hash, - l1_resource_bounds=MAX_RESOURCE_BOUNDS_L1, - ) - - simulated_txs = await account.client.simulate_transactions( - transactions=[declare_tx], block_number="latest" - ) - - assert isinstance(simulated_txs[0].transaction_trace, DeclareTransactionTrace) - assert simulated_txs[0].fee_estimation.overall_fee > 0 - assert simulated_txs[0].transaction_trace.validate_invocation is not None - assert simulated_txs[0].transaction_trace.execution_resources is not None - - @pytest.mark.asyncio async def test_simulate_transactions_two_txs(account, deployed_balance_contract): assert isinstance(deployed_balance_contract, Contract) From 7506f57aabda72bccc44b99f5d1bb618f37994dd Mon Sep 17 00:00:00 2001 From: jumpman <57270771+kkawula@users.noreply.github.com> Date: Wed, 7 Aug 2024 17:47:15 +0200 Subject: [PATCH 37/66] Update 'simple_storage_with_event' contract to cairo 1 --- .../tests/e2e/client/full_node_test.py | 6 +-- starknet_py/tests/e2e/fixtures/contracts.py | 37 +------------ .../tests/e2e/fixtures/contracts_v1.py | 21 ++++++++ .../contracts/simple_storage_with_event.cairo | 32 ------------ .../tests/e2e/mock/contracts_v1/src/lib.cairo | 1 + .../src/simple_storage_with_event.cairo | 39 ++++++++++++++ .../tests/e2e/mock/contracts_v2/src/lib.cairo | 1 + .../src/simple_storage_with_event.cairo | 52 +++++++++++++++++++ 8 files changed, 118 insertions(+), 71 deletions(-) delete mode 100644 starknet_py/tests/e2e/mock/contracts/simple_storage_with_event.cairo create mode 100644 starknet_py/tests/e2e/mock/contracts_v1/src/simple_storage_with_event.cairo create mode 100644 starknet_py/tests/e2e/mock/contracts_v2/src/simple_storage_with_event.cairo diff --git a/starknet_py/tests/e2e/client/full_node_test.py b/starknet_py/tests/e2e/client/full_node_test.py index db745e686..2c5ab64d0 100644 --- a/starknet_py/tests/e2e/client/full_node_test.py +++ b/starknet_py/tests/e2e/client/full_node_test.py @@ -35,9 +35,9 @@ def _parse_event_name(event: str) -> str: FUNCTION_ONE_NAME = "put" -EVENT_ONE_PARSED_NAME = _parse_event_name("put_called") +EVENT_ONE_PARSED_NAME = _parse_event_name("PutCalled") FUNCTION_TWO_NAME = "another_put" -EVENT_TWO_PARSED_NAME = _parse_event_name("another_put_called") +EVENT_TWO_PARSED_NAME = _parse_event_name("AnotherPutCalled") @pytest.mark.run_on_devnet @@ -147,7 +147,7 @@ async def test_get_events_without_following_continuation_token( simple_storage_with_event_contract: Contract, ): for i in range(4): - await simple_storage_with_event_contract.functions[FUNCTION_ONE_NAME].invoke_v1( + await simple_storage_with_event_contract.functions[FUNCTION_ONE_NAME].invoke_v3( i, i, auto_estimate=True ) diff --git a/starknet_py/tests/e2e/fixtures/contracts.py b/starknet_py/tests/e2e/fixtures/contracts.py index f836a84de..f09718f0b 100644 --- a/starknet_py/tests/e2e/fixtures/contracts.py +++ b/starknet_py/tests/e2e/fixtures/contracts.py @@ -4,11 +4,7 @@ import pytest import pytest_asyncio -from starknet_py.common import ( - create_casm_class, - create_compiled_contract, - create_sierra_compiled_contract, -) +from starknet_py.common import create_casm_class, create_sierra_compiled_contract from starknet_py.constants import FEE_CONTRACT_ADDRESS from starknet_py.contract import Contract from starknet_py.hash.casm_class_hash import compute_casm_class_hash @@ -127,21 +123,6 @@ async def deployed_balance_contract( return deploy_result.deployed_contract -@pytest_asyncio.fixture(scope="function") -async def simple_storage_with_event_contract( - account: BaseAccount, - simple_storage_with_event_compiled_contract: str, - simple_storage_with_event_class_hash: int, -) -> Contract: - """ - Deploys storage contract with an events and returns its instance. - """ - abi = create_compiled_contract( - compiled_contract=simple_storage_with_event_compiled_contract - ).abi - return await deploy_contract(account, simple_storage_with_event_class_hash, abi) - - @pytest.fixture(scope="package") def eth_fee_contract(account: BaseAccount, fee_contract_abi) -> Contract: """ @@ -260,19 +241,3 @@ async def argent_cairo1_account_class_hash( compiled_account_contract=compiled_contract, compiled_account_contract_casm=compiled_contract_casm, ) - - -@pytest_asyncio.fixture(scope="package") -async def simple_storage_with_event_class_hash( - account: BaseAccount, simple_storage_with_event_compiled_contract: str -): - """ - Returns class_hash of the simple_storage_with_event.cairo - """ - declare = await account.sign_declare_v1( - compiled_contract=simple_storage_with_event_compiled_contract, - max_fee=int(1e16), - ) - res = await account.client.declare(declare) - await account.client.wait_for_tx(res.transaction_hash) - return res.class_hash diff --git a/starknet_py/tests/e2e/fixtures/contracts_v1.py b/starknet_py/tests/e2e/fixtures/contracts_v1.py index 4a84a2ff0..41467d47c 100644 --- a/starknet_py/tests/e2e/fixtures/contracts_v1.py +++ b/starknet_py/tests/e2e/fixtures/contracts_v1.py @@ -240,3 +240,24 @@ def map_compiled_contract_and_class_hash() -> Tuple[str, int]: contract["sierra"], compute_casm_class_hash(create_casm_class(contract["casm"])), ) + + +@pytest_asyncio.fixture(scope="package") +async def simple_storage_with_event_class_hash(account: BaseAccount) -> int: + contract = load_contract("SimpleStorageWithEvent") + class_hash, _ = await declare_cairo1_contract( + account, contract["sierra"], contract["casm"] + ) + return class_hash + + +@pytest_asyncio.fixture(scope="function") +async def simple_storage_with_event_contract( + account: BaseAccount, + simple_storage_with_event_class_hash: int, +) -> Contract: + return await deploy_v1_contract( + account=account, + contract_name="SimpleStorageWithEvent", + class_hash=simple_storage_with_event_class_hash, + ) diff --git a/starknet_py/tests/e2e/mock/contracts/simple_storage_with_event.cairo b/starknet_py/tests/e2e/mock/contracts/simple_storage_with_event.cairo deleted file mode 100644 index bf612a8ec..000000000 --- a/starknet_py/tests/e2e/mock/contracts/simple_storage_with_event.cairo +++ /dev/null @@ -1,32 +0,0 @@ -%lang starknet -%builtins pedersen range_check - -from starkware.cairo.common.cairo_builtins import HashBuiltin - -@storage_var -func storage(key: felt) -> (value: felt) { -} - -@event -func put_called(key: felt, prev_value: felt, value: felt) { -} - -@event -func another_put_called(key: felt, prev_value: felt, value: felt, additional_value: felt) { -} - -@external -func put{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(key: felt, value: felt) { - let (prev_value) = storage.read(key); - put_called.emit(key=key, prev_value=prev_value, value=value); - storage.write(key, value); - return (); -} - -@external -func another_put{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(key: felt, value: felt) { - let (prev_value) = storage.read(key); - another_put_called.emit(key=key, prev_value=prev_value, value=value, additional_value=value); - storage.write(key, value); - return (); -} diff --git a/starknet_py/tests/e2e/mock/contracts_v1/src/lib.cairo b/starknet_py/tests/e2e/mock/contracts_v1/src/lib.cairo index 8aa389b47..cb0ed43d8 100644 --- a/starknet_py/tests/e2e/mock/contracts_v1/src/lib.cairo +++ b/starknet_py/tests/e2e/mock/contracts_v1/src/lib.cairo @@ -9,3 +9,4 @@ mod test_enum; mod test_option; mod token_bridge; mod map; +mod simple_storage_with_event; diff --git a/starknet_py/tests/e2e/mock/contracts_v1/src/simple_storage_with_event.cairo b/starknet_py/tests/e2e/mock/contracts_v1/src/simple_storage_with_event.cairo new file mode 100644 index 000000000..c6963bfe1 --- /dev/null +++ b/starknet_py/tests/e2e/mock/contracts_v1/src/simple_storage_with_event.cairo @@ -0,0 +1,39 @@ + + +#[contract] +mod SimpleStorageWithEvent { + + struct Storage { + map: LegacyMap::, + } + + #[event] + fn PutCalled ( + key: felt252, + prev_value: felt252, + value: felt252, + ){} + + #[event] + fn AnotherPutCalled( + key: felt252, + prev_value: felt252, + value: felt252, + additional_value: felt252, + ){} + + #[external] + fn put(key: felt252, value: felt252) { + let mut prev_value = map::read(key); + map::write(key, value); + PutCalled(key, prev_value, value); + } + + #[external] + fn another_put(key: felt252, value: felt252) { + let mut prev_value = map::read(key); + map::write(key, value); + AnotherPutCalled(key, prev_value, value, value); + } + +} \ No newline at end of file diff --git a/starknet_py/tests/e2e/mock/contracts_v2/src/lib.cairo b/starknet_py/tests/e2e/mock/contracts_v2/src/lib.cairo index fa7c75276..8d6b43d97 100644 --- a/starknet_py/tests/e2e/mock/contracts_v2/src/lib.cairo +++ b/starknet_py/tests/e2e/mock/contracts_v2/src/lib.cairo @@ -11,3 +11,4 @@ mod test_enum; mod test_option; mod token_bridge; mod map; +mod simple_storage_with_event; diff --git a/starknet_py/tests/e2e/mock/contracts_v2/src/simple_storage_with_event.cairo b/starknet_py/tests/e2e/mock/contracts_v2/src/simple_storage_with_event.cairo new file mode 100644 index 000000000..e64e44598 --- /dev/null +++ b/starknet_py/tests/e2e/mock/contracts_v2/src/simple_storage_with_event.cairo @@ -0,0 +1,52 @@ +#[starknet::interface] +trait ISimpleStorageWithEvent { + fn put(ref self: TContractState, key: felt252, value: felt252); + fn another_put(ref self: TContractState, key: felt252, value: felt252); +} + +#[derive(Drop, Clone, starknet::Event)] +struct PutCalled { + key: felt252, + prev_value: felt252, + value: felt252, +} + +#[derive(Drop, Clone, starknet::Event)] +struct AnotherPutCalled { + key: felt252, + prev_value: felt252, + value: felt252, + additional_value: felt252, +} + +#[starknet::contract] +pub mod SimpleStorageWithEvent { + use super::{PutCalled, AnotherPutCalled}; + + #[storage] + struct Storage { + map: LegacyMap::, + } + + #[event] + #[derive(Drop, Clone, starknet::Event)] + pub enum Event { + PutCalled: PutCalled, + AnotherPutCalled: AnotherPutCalled, + } + + #[abi(embed_v0)] + impl SimpleStorag of super::ISimpleStorageWithEvent { + fn put(ref self: ContractState, key: felt252, value: felt252) { + let mut prev_value = self.map.read(key); + self.map.write(key, value); + self.emit(PutCalled { key: key, prev_value: prev_value, value: value }); + } + + fn another_put(ref self: ContractState, key: felt252, value: felt252) { + let mut prev_value = self.map.read(key); + self.map.write(key, value); + self.emit(AnotherPutCalled { key: key, prev_value: prev_value, value: value, additional_value: value }); + } + } +} \ No newline at end of file From a134d2146dc04c6a7989eb56bce5bcdb529a1801 Mon Sep 17 00:00:00 2001 From: jumpman <57270771+kkawula@users.noreply.github.com> Date: Wed, 7 Aug 2024 18:17:08 +0200 Subject: [PATCH 38/66] Add test to skip reason='Some cairo 1 contracts compiled with v1 compiler fail with new devnet-rs' --- .../tests/e2e/client/full_node_test.py | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/starknet_py/tests/e2e/client/full_node_test.py b/starknet_py/tests/e2e/client/full_node_test.py index 2c5ab64d0..f437c1453 100644 --- a/starknet_py/tests/e2e/client/full_node_test.py +++ b/starknet_py/tests/e2e/client/full_node_test.py @@ -1,4 +1,5 @@ import dataclasses +import sys from unittest.mock import AsyncMock, patch import pytest @@ -140,6 +141,10 @@ async def test_get_storage_at_incorrect_address_full_node_client(client): ) +@pytest.mark.skipif( + "--contract_dir=v2" not in sys.argv, + reason="Some cairo 1 contracts compiled with v1 compiler fail with new devnet-rs", +) @pytest.mark.run_on_devnet @pytest.mark.asyncio async def test_get_events_without_following_continuation_token( @@ -165,6 +170,10 @@ async def test_get_events_without_following_continuation_token( assert events_response.continuation_token is not None +@pytest.mark.skipif( + "--contract_dir=v2" not in sys.argv, + reason="Some cairo 1 contracts compiled with v1 compiler fail with new devnet-rs", +) @pytest.mark.run_on_devnet @pytest.mark.asyncio async def test_get_events_follow_continuation_token( @@ -190,6 +199,10 @@ async def test_get_events_follow_continuation_token( assert events_response.continuation_token is None +@pytest.mark.skipif( + "--contract_dir=v2" not in sys.argv, + reason="Some cairo 1 contracts compiled with v1 compiler fail with new devnet-rs", +) @pytest.mark.run_on_devnet @pytest.mark.asyncio async def test_get_events_nonexistent_event_name( @@ -213,6 +226,10 @@ async def test_get_events_nonexistent_event_name( assert events_response.continuation_token is None +@pytest.mark.skipif( + "--contract_dir=v2" not in sys.argv, + reason="Some cairo 1 contracts compiled with v1 compiler fail with new devnet-rs", +) @pytest.mark.run_on_devnet @pytest.mark.asyncio async def test_get_events_with_two_events( @@ -262,6 +279,10 @@ async def test_get_events_with_two_events( assert event_one_two_events_response.continuation_token is None +@pytest.mark.skipif( + "--contract_dir=v2" not in sys.argv, + reason="Some cairo 1 contracts compiled with v1 compiler fail with new devnet-rs", +) @pytest.mark.run_on_devnet @pytest.mark.asyncio async def test_get_events_start_from_continuation_token( @@ -289,6 +310,10 @@ async def test_get_events_start_from_continuation_token( assert events_response.continuation_token == expected_continuation_token +@pytest.mark.skipif( + "--contract_dir=v2" not in sys.argv, + reason="Some cairo 1 contracts compiled with v1 compiler fail with new devnet-rs", +) @pytest.mark.run_on_devnet @pytest.mark.asyncio async def test_get_events_no_params( @@ -308,6 +333,10 @@ async def test_get_events_no_params( assert len(events_response.events) == default_chunk_size +@pytest.mark.skipif( + "--contract_dir=v2" not in sys.argv, + reason="Some cairo 1 contracts compiled with v1 compiler fail with new devnet-rs", +) @pytest.mark.run_on_devnet @pytest.mark.asyncio async def test_get_events_nonexistent_starting_block( From bc2f6a42d2f1c6a7ee0594fe1e09ee33b370e903 Mon Sep 17 00:00:00 2001 From: jumpman <57270771+kkawula@users.noreply.github.com> Date: Thu, 8 Aug 2024 13:29:17 +0200 Subject: [PATCH 39/66] Remove deprecated cairo 0 fixture 'simple_storage_with_event_compiled_contract' --- starknet_py/tests/e2e/fixtures/contracts.py | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/starknet_py/tests/e2e/fixtures/contracts.py b/starknet_py/tests/e2e/fixtures/contracts.py index f09718f0b..5ea6a7ff0 100644 --- a/starknet_py/tests/e2e/fixtures/contracts.py +++ b/starknet_py/tests/e2e/fixtures/contracts.py @@ -49,16 +49,6 @@ def abi_types_compiled_contract_and_class_hash() -> Tuple[str, int]: ) -@pytest.fixture(scope="package") -def simple_storage_with_event_compiled_contract() -> str: - """ - Returns compiled simple storage contract that emits an event. - """ - return read_contract( - "simple_storage_with_event_compiled.json", directory=CONTRACTS_COMPILED_V0_DIR - ) - - async def deploy_contract(account: BaseAccount, class_hash: int, abi: List) -> Contract: """ Deploys a contract and returns its instance. From 823f96cdaef29e94b8ea26991a3aaa153a2ae4dc Mon Sep 17 00:00:00 2001 From: jumpman <57270771+kkawula@users.noreply.github.com> Date: Thu, 8 Aug 2024 13:41:48 +0200 Subject: [PATCH 40/66] Remove cairo v1 version of 'simple_storage_with_event.cairo' contract --- .../tests/e2e/client/full_node_test.py | 28 ++++++------- .../tests/e2e/mock/contracts_v1/src/lib.cairo | 1 - .../src/simple_storage_with_event.cairo | 39 ------------------- 3 files changed, 14 insertions(+), 54 deletions(-) delete mode 100644 starknet_py/tests/e2e/mock/contracts_v1/src/simple_storage_with_event.cairo diff --git a/starknet_py/tests/e2e/client/full_node_test.py b/starknet_py/tests/e2e/client/full_node_test.py index f437c1453..ffecfe0a3 100644 --- a/starknet_py/tests/e2e/client/full_node_test.py +++ b/starknet_py/tests/e2e/client/full_node_test.py @@ -142,8 +142,8 @@ async def test_get_storage_at_incorrect_address_full_node_client(client): @pytest.mark.skipif( - "--contract_dir=v2" not in sys.argv, - reason="Some cairo 1 contracts compiled with v1 compiler fail with new devnet-rs", + "--contract_dir=v1" in sys.argv, + reason="Contract exists only in v2 directory", ) @pytest.mark.run_on_devnet @pytest.mark.asyncio @@ -171,8 +171,8 @@ async def test_get_events_without_following_continuation_token( @pytest.mark.skipif( - "--contract_dir=v2" not in sys.argv, - reason="Some cairo 1 contracts compiled with v1 compiler fail with new devnet-rs", + "--contract_dir=v1" in sys.argv, + reason="Contract exists only in v2 directory", ) @pytest.mark.run_on_devnet @pytest.mark.asyncio @@ -200,8 +200,8 @@ async def test_get_events_follow_continuation_token( @pytest.mark.skipif( - "--contract_dir=v2" not in sys.argv, - reason="Some cairo 1 contracts compiled with v1 compiler fail with new devnet-rs", + "--contract_dir=v1" in sys.argv, + reason="Contract exists only in v2 directory", ) @pytest.mark.run_on_devnet @pytest.mark.asyncio @@ -227,8 +227,8 @@ async def test_get_events_nonexistent_event_name( @pytest.mark.skipif( - "--contract_dir=v2" not in sys.argv, - reason="Some cairo 1 contracts compiled with v1 compiler fail with new devnet-rs", + "--contract_dir=v1" in sys.argv, + reason="Contract exists only in v2 directory", ) @pytest.mark.run_on_devnet @pytest.mark.asyncio @@ -280,8 +280,8 @@ async def test_get_events_with_two_events( @pytest.mark.skipif( - "--contract_dir=v2" not in sys.argv, - reason="Some cairo 1 contracts compiled with v1 compiler fail with new devnet-rs", + "--contract_dir=v1" in sys.argv, + reason="Contract exists only in v2 directory", ) @pytest.mark.run_on_devnet @pytest.mark.asyncio @@ -311,8 +311,8 @@ async def test_get_events_start_from_continuation_token( @pytest.mark.skipif( - "--contract_dir=v2" not in sys.argv, - reason="Some cairo 1 contracts compiled with v1 compiler fail with new devnet-rs", + "--contract_dir=v1" in sys.argv, + reason="Contract exists only in v2 directory", ) @pytest.mark.run_on_devnet @pytest.mark.asyncio @@ -334,8 +334,8 @@ async def test_get_events_no_params( @pytest.mark.skipif( - "--contract_dir=v2" not in sys.argv, - reason="Some cairo 1 contracts compiled with v1 compiler fail with new devnet-rs", + "--contract_dir=v1" in sys.argv, + reason="Contract exists only in v2 directory", ) @pytest.mark.run_on_devnet @pytest.mark.asyncio diff --git a/starknet_py/tests/e2e/mock/contracts_v1/src/lib.cairo b/starknet_py/tests/e2e/mock/contracts_v1/src/lib.cairo index cb0ed43d8..8aa389b47 100644 --- a/starknet_py/tests/e2e/mock/contracts_v1/src/lib.cairo +++ b/starknet_py/tests/e2e/mock/contracts_v1/src/lib.cairo @@ -9,4 +9,3 @@ mod test_enum; mod test_option; mod token_bridge; mod map; -mod simple_storage_with_event; diff --git a/starknet_py/tests/e2e/mock/contracts_v1/src/simple_storage_with_event.cairo b/starknet_py/tests/e2e/mock/contracts_v1/src/simple_storage_with_event.cairo deleted file mode 100644 index c6963bfe1..000000000 --- a/starknet_py/tests/e2e/mock/contracts_v1/src/simple_storage_with_event.cairo +++ /dev/null @@ -1,39 +0,0 @@ - - -#[contract] -mod SimpleStorageWithEvent { - - struct Storage { - map: LegacyMap::, - } - - #[event] - fn PutCalled ( - key: felt252, - prev_value: felt252, - value: felt252, - ){} - - #[event] - fn AnotherPutCalled( - key: felt252, - prev_value: felt252, - value: felt252, - additional_value: felt252, - ){} - - #[external] - fn put(key: felt252, value: felt252) { - let mut prev_value = map::read(key); - map::write(key, value); - PutCalled(key, prev_value, value); - } - - #[external] - fn another_put(key: felt252, value: felt252) { - let mut prev_value = map::read(key); - map::write(key, value); - AnotherPutCalled(key, prev_value, value, value); - } - -} \ No newline at end of file From 5e0ff7d48fd323f55dca9c0e480f38cea7f8e635 Mon Sep 17 00:00:00 2001 From: jumpman <57270771+kkawula@users.noreply.github.com> Date: Thu, 8 Aug 2024 13:56:52 +0200 Subject: [PATCH 41/66] Remove cairo v1 contracts that have events --- starknet_py/tests/e2e/account/account_test.py | 8 +- .../v1_interaction_test.py | 12 +- .../guide/test_using_existing_contracts.py | 4 +- .../e2e/mock/contracts_v1/src/erc20.cairo | 124 -------------- .../mock/contracts_v1/src/token_bridge.cairo | 161 ------------------ 5 files changed, 12 insertions(+), 297 deletions(-) delete mode 100644 starknet_py/tests/e2e/mock/contracts_v1/src/erc20.cairo delete mode 100644 starknet_py/tests/e2e/mock/contracts_v1/src/token_bridge.cairo diff --git a/starknet_py/tests/e2e/account/account_test.py b/starknet_py/tests/e2e/account/account_test.py index 76cfbb288..17c05dd62 100644 --- a/starknet_py/tests/e2e/account/account_test.py +++ b/starknet_py/tests/e2e/account/account_test.py @@ -57,8 +57,8 @@ async def test_get_balance_throws_when_token_not_specified(account): @pytest.mark.skipif( - "--contract_dir=v2" not in sys.argv, - reason="Some cairo 1 contracts compiled with v1 compiler fail with new devnet-rs", + "--contract_dir=v1" in sys.argv, + reason="Contract exists only in v2 directory", ) @pytest.mark.asyncio async def test_balance_when_token_specified(account, erc20_contract): @@ -68,8 +68,8 @@ async def test_balance_when_token_specified(account, erc20_contract): @pytest.mark.skipif( - "--contract_dir=v2" not in sys.argv, - reason="Some cairo 1 contracts compiled with v1 compiler fail with new devnet-rs", + "--contract_dir=v1" in sys.argv, + reason="Contract exists only in v2 directory", ) @pytest.mark.asyncio async def test_estimated_fee_greater_than_zero(account, erc20_contract): diff --git a/starknet_py/tests/e2e/contract_interaction/v1_interaction_test.py b/starknet_py/tests/e2e/contract_interaction/v1_interaction_test.py index fd8970e2a..fae8552e7 100644 --- a/starknet_py/tests/e2e/contract_interaction/v1_interaction_test.py +++ b/starknet_py/tests/e2e/contract_interaction/v1_interaction_test.py @@ -11,8 +11,8 @@ @pytest.mark.skipif( - "--contract_dir=v2" not in sys.argv, - reason="Some cairo 1 contracts compiled with v1 compiler fail with new devnet-rs", + "--contract_dir=v1" in sys.argv, + reason="Contract exists only in v2 directory", ) @pytest.mark.asyncio async def test_general_v1_interaction(account, cairo1_erc20_class_hash: int): @@ -57,8 +57,8 @@ async def test_general_v1_interaction(account, cairo1_erc20_class_hash: int): @pytest.mark.skipif( - "--contract_dir=v2" not in sys.argv, - reason="Some Cairo 1 contracts compiled with v1 compiler fail with new devnet-rs", + "--contract_dir=v1" in sys.argv, + reason="Contract exists only in v2 directory", ) @pytest.mark.asyncio async def test_serializing_struct(account, cairo1_token_bridge_class_hash: int): @@ -149,8 +149,8 @@ async def test_serializing_enum(account, cairo1_test_enum_class_hash: int): @pytest.mark.skipif( - "--contract_dir=v2" not in sys.argv, - reason="Some cairo 1 contracts compiled with v1 compiler fail with new devnet-rs", + "--contract_dir=v1" in sys.argv, + reason="Contract exists only in v2 directory", ) @pytest.mark.asyncio async def test_from_address_on_v1_contract(account, cairo1_erc20_class_hash: int): diff --git a/starknet_py/tests/e2e/docs/guide/test_using_existing_contracts.py b/starknet_py/tests/e2e/docs/guide/test_using_existing_contracts.py index 3ef79c7fc..5556bdd6e 100644 --- a/starknet_py/tests/e2e/docs/guide/test_using_existing_contracts.py +++ b/starknet_py/tests/e2e/docs/guide/test_using_existing_contracts.py @@ -26,8 +26,8 @@ @pytest.mark.skipif( - "--contract_dir=v2" not in sys.argv, - reason="Some cairo 1 contracts compiled with v1 compiler fail with new devnet-rs", + "--contract_dir=v1" in sys.argv, + reason="Contract exists only in v2 directory", ) @pytest.mark.asyncio async def test_using_existing_contracts(account, erc20_contract): diff --git a/starknet_py/tests/e2e/mock/contracts_v1/src/erc20.cairo b/starknet_py/tests/e2e/mock/contracts_v1/src/erc20.cairo deleted file mode 100644 index 6deafcdcc..000000000 --- a/starknet_py/tests/e2e/mock/contracts_v1/src/erc20.cairo +++ /dev/null @@ -1,124 +0,0 @@ -#[contract] -mod ERC20 { - use zeroable::Zeroable; - use starknet::get_caller_address; - use starknet::contract_address_const; - use starknet::ContractAddress; - - struct Storage { - name: felt252, - symbol: felt252, - decimals: u8, - total_supply: u256, - balances: LegacyMap::, - allowances: LegacyMap::<(ContractAddress, ContractAddress), u256>, - } - - #[event] - fn Transfer(from: ContractAddress, to: ContractAddress, value: u256) {} - - #[event] - fn Approval(owner: ContractAddress, spender: ContractAddress, value: u256) {} - - #[constructor] - fn constructor( - name_: felt252, - symbol_: felt252, - decimals_: u8, - initial_supply: u256, - recipient: ContractAddress - ) { - name::write(name_); - symbol::write(symbol_); - decimals::write(decimals_); - assert(!recipient.is_zero(), 'ERC20: mint to the 0 address'); - total_supply::write(initial_supply); - balances::write(recipient, initial_supply); - Transfer(contract_address_const::<0>(), recipient, initial_supply); - } - - #[view] - fn get_name() -> felt252 { - name::read() - } - - #[view] - fn get_symbol() -> felt252 { - symbol::read() - } - - #[view] - fn get_decimals() -> u8 { - decimals::read() - } - - #[view] - fn get_total_supply() -> u256 { - total_supply::read() - } - - #[view] - fn balance_of(account: ContractAddress) -> u256 { - balances::read(account) - } - - #[view] - fn allowance(owner: ContractAddress, spender: ContractAddress) -> u256 { - allowances::read((owner, spender)) - } - - #[external] - fn transfer(recipient: ContractAddress, amount: u256) { - let sender = get_caller_address(); - transfer_helper(sender, recipient, amount); - } - - #[external] - fn transfer_from(sender: ContractAddress, recipient: ContractAddress, amount: u256) { - let caller = get_caller_address(); - spend_allowance(sender, caller, amount); - transfer_helper(sender, recipient, amount); - } - - #[external] - fn approve(spender: ContractAddress, amount: u256) { - let caller = get_caller_address(); - approve_helper(caller, spender, amount); - } - - #[external] - fn increase_allowance(spender: ContractAddress, added_value: u256) { - let caller = get_caller_address(); - approve_helper(caller, spender, allowances::read((caller, spender)) + added_value); - } - - #[external] - fn decrease_allowance(spender: ContractAddress, subtracted_value: u256) { - let caller = get_caller_address(); - approve_helper(caller, spender, allowances::read((caller, spender)) - subtracted_value); - } - - fn transfer_helper(sender: ContractAddress, recipient: ContractAddress, amount: u256) { - assert(!sender.is_zero(), 'ERC20: transfer from 0'); - assert(!recipient.is_zero(), 'ERC20: transfer to 0'); - balances::write(sender, balances::read(sender) - amount); - balances::write(recipient, balances::read(recipient) + amount); - Transfer(sender, recipient, amount); - } - - fn spend_allowance(owner: ContractAddress, spender: ContractAddress, amount: u256) { - let current_allowance = allowances::read((owner, spender)); - let ONES_MASK = 0xffffffffffffffffffffffffffffffff_u128; - let is_unlimited_allowance = current_allowance.low == ONES_MASK - & current_allowance.high == ONES_MASK; - if !is_unlimited_allowance { - approve_helper(owner, spender, current_allowance - amount); - } - } - - fn approve_helper(owner: ContractAddress, spender: ContractAddress, amount: u256) { - assert(!spender.is_zero(), 'ERC20: approve from 0'); - allowances::write((owner, spender), amount); - Approval(owner, spender, amount); - } -} diff --git a/starknet_py/tests/e2e/mock/contracts_v1/src/token_bridge.cairo b/starknet_py/tests/e2e/mock/contracts_v1/src/token_bridge.cairo deleted file mode 100644 index a76dc708e..000000000 --- a/starknet_py/tests/e2e/mock/contracts_v1/src/token_bridge.cairo +++ /dev/null @@ -1,161 +0,0 @@ -use starknet::ContractAddress; -use serde::Serde; -use traits::Into; -use zeroable::Zeroable; - -#[abi] -trait IMintableToken { - fn permissioned_mint(account: ContractAddress, amount: u256); - fn permissioned_burn(account: ContractAddress, amount: u256); -} - -#[contract] -mod TokenBridge { - use array::ArrayTrait; - use integer::Felt252IntoU256; - use integer::U128IntoFelt252; - use option::OptionTrait; - use serde::Serde; - use starknet::ContractAddress; - use starknet::contract_address::ContractAddressZeroable; - use starknet::get_caller_address; - use starknet::EthAddress; - use starknet::EthAddressIntoFelt252; - use starknet::EthAddressSerde; - use starknet::EthAddressZeroable; - use starknet::syscalls::send_message_to_l1_syscall; - use super::IMintableTokenDispatcher; - use super::IMintableTokenDispatcherTrait; - use super::IMintableTokenLibraryDispatcher; - use traits::Into; - use zeroable::Zeroable; - - - const WITHDRAW_MESSAGE: felt252 = 0; - const CONTRACT_IDENTITY: felt252 = 'STARKGATE'; - const CONTRACT_VERSION: felt252 = 2; - - struct Storage { - // The address of the L2 governor of this contract. Only the governor can set the other - // storage variables. - governor: ContractAddress, - // The L1 bridge address. Zero when unset. - l1_bridge: felt252, - // The L2 token contract address. Zero when unset. - l2_token: ContractAddress, - } - - // An event that is emitted when set_l1_bridge is called. - // * l1_bridge_address is the new l1 bridge address. - #[event] - fn l1_bridge_set(l1_bridge_address: EthAddress) {} - - // An event that is emitted when set_l2_token is called. - // * l2_token_address is the new l2 token address. - #[event] - fn l2_token_set(l2_token_address: ContractAddress) {} - - // An event that is emitted when initiate_withdraw is called. - // * l1_recipient is the l1 recipient address. - // * amount is the amount to withdraw. - // * caller_address is the address from which the call was made. - #[event] - fn withdraw_initiated( - l1_recipient: EthAddress, amount: u256, caller_address: ContractAddress - ) {} - - // An event that is emitted when handle_deposit is called. - // * account is the recipient address. - // * amount is the amount to deposit. - #[event] - fn deposit_handled(account: ContractAddress, amount: u256) {} - - #[view] - fn get_version() -> felt252 { - CONTRACT_VERSION - } - - #[view] - fn get_identity() -> felt252 { - CONTRACT_IDENTITY - } - - #[constructor] - fn constructor(governor_address: ContractAddress) { - assert(governor_address.is_non_zero(), 'ZERO_GOVERNOR_ADDRESS'); - governor::write(governor_address); - } - - #[external] - fn set_l1_bridge(l1_bridge_address: EthAddress) { - // The call is restricted to the governor. - assert(get_caller_address() == governor::read(), 'GOVERNOR_ONLY'); - - assert(l1_bridge::read().is_zero(), 'L1_BRIDGE_ALREADY_INITIALIZED'); - assert(l1_bridge_address.is_non_zero(), 'ZERO_BRIDGE_ADDRESS'); - - l1_bridge::write(l1_bridge_address.into()); - l1_bridge_set(l1_bridge_address); - } - - #[external] - fn set_l2_token(l2_token_address: ContractAddress) { - // The call is restricted to the governor. - assert(get_caller_address() == governor::read(), 'GOVERNOR_ONLY'); - - assert(l2_token::read().is_zero(), 'L2_TOKEN_ALREADY_INITIALIZED'); - assert(l2_token_address.is_non_zero(), 'ZERO_TOKEN_ADDRESS'); - - l2_token::write(l2_token_address); - l2_token_set(l2_token_address); - } - - #[external] - fn initiate_withdraw(l1_recipient: EthAddress, amount: u256) { - // Call burn on l2_token contract. - let caller_address = get_caller_address(); - IMintableTokenDispatcher { - contract_address: read_initialized_l2_token() - }.permissioned_burn(account: caller_address, :amount); - - // Send the message. - let mut message_payload: Array = ArrayTrait::new(); - message_payload.append(WITHDRAW_MESSAGE); - message_payload.append(l1_recipient.into()); - message_payload.append(amount.low.into()); - message_payload.append(amount.high.into()); - - send_message_to_l1_syscall( - to_address: read_initialized_l1_bridge(), payload: message_payload.span() - ); - withdraw_initiated(:l1_recipient, :amount, :caller_address); - } - - #[l1_handler] - fn handle_deposit(from_address: felt252, account: ContractAddress, amount: u256) { - assert(from_address == l1_bridge::read(), 'EXPECTED_FROM_BRIDGE_ONLY'); - - // Call mint on l2_token contract. - IMintableTokenDispatcher { - contract_address: read_initialized_l2_token() - }.permissioned_mint(:account, :amount); - - deposit_handled(:account, :amount); - } - - // Helpers (internal functions) - - // Read l1_bridge and verify it's initialized. - fn read_initialized_l1_bridge() -> felt252 { - let l1_bridge_address = l1_bridge::read(); - assert(l1_bridge_address.is_non_zero(), 'UNINITIALIZED_L1_BRIDGE_ADDRESS'); - l1_bridge_address - } - - // Read l2_token and verify it's initialized. - fn read_initialized_l2_token() -> ContractAddress { - let l2_token_address = l2_token::read(); - assert(l2_token_address.is_non_zero(), 'UNINITIALIZED_TOKEN'); - l2_token_address - } -} From f6f15f0a3f49d39fdb038b7e3be338c08932b3e4 Mon Sep 17 00:00:00 2001 From: jumpman <57270771+kkawula@users.noreply.github.com> Date: Thu, 8 Aug 2024 13:59:08 +0200 Subject: [PATCH 42/66] Remove removed contracts from lib.cairo --- starknet_py/tests/e2e/mock/contracts_v1/src/lib.cairo | 2 -- 1 file changed, 2 deletions(-) diff --git a/starknet_py/tests/e2e/mock/contracts_v1/src/lib.cairo b/starknet_py/tests/e2e/mock/contracts_v1/src/lib.cairo index 8aa389b47..cb09f48dd 100644 --- a/starknet_py/tests/e2e/mock/contracts_v1/src/lib.cairo +++ b/starknet_py/tests/e2e/mock/contracts_v1/src/lib.cairo @@ -1,5 +1,4 @@ mod account; -mod erc20; mod hello_starknet; mod hello; mod minimal_contract; @@ -7,5 +6,4 @@ mod test_contract_declare; mod test_contract; mod test_enum; mod test_option; -mod token_bridge; mod map; From 73332dce1c24607bae1739901176bfa1e2fc94cc Mon Sep 17 00:00:00 2001 From: jumpman <57270771+kkawula@users.noreply.github.com> Date: Thu, 8 Aug 2024 14:50:14 +0200 Subject: [PATCH 43/66] Fix 'test_deserialize_abi' v1 --- starknet_py/abi/v1/schemas_test.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/starknet_py/abi/v1/schemas_test.py b/starknet_py/abi/v1/schemas_test.py index e098e9730..7a0765d13 100644 --- a/starknet_py/abi/v1/schemas_test.py +++ b/starknet_py/abi/v1/schemas_test.py @@ -11,11 +11,11 @@ "contract_name", [ "Account", - "ERC20", + "Hello", "HelloStarknet", "MinimalContract", "TestContract", - "TokenBridge", + "TestEnum", ], ) def test_deserialize_abi(contract_name): From 8995741ba02f68de895988674a59222579944985 Mon Sep 17 00:00:00 2001 From: jumpman <57270771+kkawula@users.noreply.github.com> Date: Thu, 8 Aug 2024 15:02:45 +0200 Subject: [PATCH 44/66] Fix 'test_evenet_serialization_v1' --- .../serialization/serialization_test.py | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/starknet_py/serialization/serialization_test.py b/starknet_py/serialization/serialization_test.py index d9f0a56ce..0ab5cb024 100644 --- a/starknet_py/serialization/serialization_test.py +++ b/starknet_py/serialization/serialization_test.py @@ -110,9 +110,23 @@ class Education(NamedTuple): ) parsed_abi = AbiParserV0(abi).parse() -abi_v1 = json.loads( - load_contract(contract_name="ERC20", version=ContractVersion.V1)["sierra"] -)["abi"] +abi_v1 = [ + { + "type": "event", + "name": "Approval", + "inputs": [ + { + "name": "owner", + "type": "core::starknet::contract_address::ContractAddress", + }, + { + "name": "spender", + "type": "core::starknet::contract_address::ContractAddress", + }, + {"name": "value", "type": "core::integer::u256"}, + ], + } +] parsed_abi_v1 = AbiParserV1(abi_v1).parse() abi_v2 = json.loads( From 1a5db99abfa98dacf6381634af8aa703d0c21694 Mon Sep 17 00:00:00 2001 From: jumpman <57270771+kkawula@users.noreply.github.com> Date: Thu, 8 Aug 2024 15:53:35 +0200 Subject: [PATCH 45/66] Fix 'test_throws_when_cairo1_without_compiled_contract_casm_and_class_hash' --- starknet_py/tests/e2e/contract_interaction/declare_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/starknet_py/tests/e2e/contract_interaction/declare_test.py b/starknet_py/tests/e2e/contract_interaction/declare_test.py index 0acd91410..dc9c81f36 100644 --- a/starknet_py/tests/e2e/contract_interaction/declare_test.py +++ b/starknet_py/tests/e2e/contract_interaction/declare_test.py @@ -13,7 +13,7 @@ async def test_throws_when_cairo1_without_compiled_contract_casm_and_class_hash( "For Cairo 1.0 contracts, either the 'compiled_class_hash' or the 'compiled_contract_casm' " "argument must be provided." ) - compiled_contract = load_contract("ERC20")["sierra"] + compiled_contract = load_contract("Hello")["sierra"] with pytest.raises(ValueError, match=error_message): await Contract.declare_v2( From db09b19293af5ea9c79878cedbbcdd4743362da2 Mon Sep 17 00:00:00 2001 From: jumpman <57270771+kkawula@users.noreply.github.com> Date: Fri, 9 Aug 2024 09:08:47 +0200 Subject: [PATCH 46/66] Fix 'test_throws_when_cairo1_without_compiled_contract_casm_and_class_hash' --- starknet_py/tests/e2e/contract_interaction/declare_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/starknet_py/tests/e2e/contract_interaction/declare_test.py b/starknet_py/tests/e2e/contract_interaction/declare_test.py index dc9c81f36..221028a46 100644 --- a/starknet_py/tests/e2e/contract_interaction/declare_test.py +++ b/starknet_py/tests/e2e/contract_interaction/declare_test.py @@ -13,7 +13,7 @@ async def test_throws_when_cairo1_without_compiled_contract_casm_and_class_hash( "For Cairo 1.0 contracts, either the 'compiled_class_hash' or the 'compiled_contract_casm' " "argument must be provided." ) - compiled_contract = load_contract("Hello")["sierra"] + compiled_contract = load_contract("Map")["sierra"] with pytest.raises(ValueError, match=error_message): await Contract.declare_v2( From e8da73f1074a0e61ac26989aa2726fad82b3c916 Mon Sep 17 00:00:00 2001 From: kkawula <57270771+kkawula@users.noreply.github.com> Date: Wed, 21 Aug 2024 13:42:11 +0200 Subject: [PATCH 47/66] Update starknet_py/tests/e2e/deploy/deployer_test.py Co-authored-by: ddoktorski <45050160+ddoktorski@users.noreply.github.com> --- starknet_py/tests/e2e/deploy/deployer_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/starknet_py/tests/e2e/deploy/deployer_test.py b/starknet_py/tests/e2e/deploy/deployer_test.py index ca0ba7673..fa43dbf90 100644 --- a/starknet_py/tests/e2e/deploy/deployer_test.py +++ b/starknet_py/tests/e2e/deploy/deployer_test.py @@ -54,7 +54,7 @@ async def test_throws_when_calldata_not_provided(constructor_with_arguments_abi) @pytest.mark.skipif( - "--contract_dir=v1" in sys.argv, + "--contract_dir=v2" not in sys.argv, reason="Contract exists only in v2 directory", ) @pytest.mark.asyncio From fa43f2c3144aa589550fa061e461184b15560c49 Mon Sep 17 00:00:00 2001 From: kkawula <57270771+kkawula@users.noreply.github.com> Date: Wed, 21 Aug 2024 13:27:10 +0200 Subject: [PATCH 48/66] Add newline --- .../e2e/mock/contracts_v2/src/constructor_with_arguments.cairo | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/starknet_py/tests/e2e/mock/contracts_v2/src/constructor_with_arguments.cairo b/starknet_py/tests/e2e/mock/contracts_v2/src/constructor_with_arguments.cairo index c219c9fa4..375c4a09e 100644 --- a/starknet_py/tests/e2e/mock/contracts_v2/src/constructor_with_arguments.cairo +++ b/starknet_py/tests/e2e/mock/contracts_v2/src/constructor_with_arguments.cairo @@ -49,4 +49,4 @@ mod ConstructorWithArguments { (single_value, tuple, arr_sum, dict) } -} \ No newline at end of file +} From 222e702b04f69e405c5a1439bc51ba0179f43d1f Mon Sep 17 00:00:00 2001 From: kkawula <57270771+kkawula@users.noreply.github.com> Date: Wed, 21 Aug 2024 13:47:54 +0200 Subject: [PATCH 49/66] Update test skip conditio to '--contract_dir=v2 not in sys.argv' --- .../tests/e2e/client_devnet/account_impersonate_test.py | 6 +++--- .../tests/e2e/contract_interaction/v1_interaction_test.py | 2 +- starknet_py/tests/e2e/deploy/deployer_test.py | 6 +++--- starknet_py/tests/e2e/docs/guide/test_deploying_with_udc.py | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/starknet_py/tests/e2e/client_devnet/account_impersonate_test.py b/starknet_py/tests/e2e/client_devnet/account_impersonate_test.py index 4e90f1818..644e60e34 100644 --- a/starknet_py/tests/e2e/client_devnet/account_impersonate_test.py +++ b/starknet_py/tests/e2e/client_devnet/account_impersonate_test.py @@ -7,7 +7,7 @@ @pytest.mark.skipif( - "--contract_dir=v1" in sys.argv, + "--contract_dir=v2" not in sys.argv, reason="Contract exists only in v2 directory", ) @pytest.mark.asyncio @@ -36,7 +36,7 @@ async def test_impersonate_account( @pytest.mark.skipif( - "--contract_dir=v1" in sys.argv, + "--contract_dir=v2" not in sys.argv, reason="Contract exists only in v2 directory", ) @pytest.mark.asyncio @@ -61,7 +61,7 @@ async def test_auto_impersonate( @pytest.mark.skipif( - "--contract_dir=v1" in sys.argv, + "--contract_dir=v2" not in sys.argv, reason="Contract exists only in v2 directory", ) @pytest.mark.asyncio diff --git a/starknet_py/tests/e2e/contract_interaction/v1_interaction_test.py b/starknet_py/tests/e2e/contract_interaction/v1_interaction_test.py index fd8970e2a..ea8e53a72 100644 --- a/starknet_py/tests/e2e/contract_interaction/v1_interaction_test.py +++ b/starknet_py/tests/e2e/contract_interaction/v1_interaction_test.py @@ -177,7 +177,7 @@ async def test_from_address_on_v1_contract(account, cairo1_erc20_class_hash: int @pytest.mark.skipif( - "--contract_dir=v1" in sys.argv, + "--contract_dir=v2" not in sys.argv, reason="Contract exists only in v2 directory", ) @pytest.mark.asyncio diff --git a/starknet_py/tests/e2e/deploy/deployer_test.py b/starknet_py/tests/e2e/deploy/deployer_test.py index fa43dbf90..bb4ab89e5 100644 --- a/starknet_py/tests/e2e/deploy/deployer_test.py +++ b/starknet_py/tests/e2e/deploy/deployer_test.py @@ -37,7 +37,7 @@ async def test_throws_when_calldata_provided_without_abi(map_class_hash): @pytest.mark.skipif( - "--contract_dir=v1" in sys.argv, + "--contract_dir=v2" not in sys.argv, reason="Contract exists only in v2 directory", ) @pytest.mark.asyncio @@ -136,7 +136,7 @@ async def test_address_computation(salt, pass_account_address, account, map_clas @pytest.mark.skipif( - "--contract_dir=v1" in sys.argv, + "--contract_dir=v2" not in sys.argv, reason="Contract exists only in v2 directory", ) @pytest.mark.asyncio @@ -183,7 +183,7 @@ async def test_create_deployment_call_raw( @pytest.mark.skipif( - "--contract_dir=v1" in sys.argv, + "--contract_dir=v2" not in sys.argv, reason="Contract exists only in v2 directory", ) @pytest.mark.asyncio diff --git a/starknet_py/tests/e2e/docs/guide/test_deploying_with_udc.py b/starknet_py/tests/e2e/docs/guide/test_deploying_with_udc.py index 42f0dc2aa..00dea4403 100644 --- a/starknet_py/tests/e2e/docs/guide/test_deploying_with_udc.py +++ b/starknet_py/tests/e2e/docs/guide/test_deploying_with_udc.py @@ -4,8 +4,8 @@ @pytest.mark.skipif( - "--contract_dir=v1" in sys.argv, - reason="Contract exists only in v2 directory", + "--contract_dir=v2" not in sys.argv, + reason="Contract exists onlgsty in v2 directory", ) @pytest.mark.asyncio async def test_deploying_with_udc( From b21be50c14f65d1d36bcce635ea4b7127d6e2ec6 Mon Sep 17 00:00:00 2001 From: kkawula <57270771+kkawula@users.noreply.github.com> Date: Wed, 21 Aug 2024 13:58:59 +0200 Subject: [PATCH 50/66] Add newline --- starknet_py/tests/e2e/mock/contracts_v1/src/map.cairo | 2 +- starknet_py/tests/e2e/mock/contracts_v2/src/map.cairo | 2 +- .../e2e/mock/contracts_v2/src/simple_storage_with_event.cairo | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/starknet_py/tests/e2e/mock/contracts_v1/src/map.cairo b/starknet_py/tests/e2e/mock/contracts_v1/src/map.cairo index eb6c489e2..38f27d0bc 100644 --- a/starknet_py/tests/e2e/mock/contracts_v1/src/map.cairo +++ b/starknet_py/tests/e2e/mock/contracts_v1/src/map.cairo @@ -15,4 +15,4 @@ mod Map { storage::read(key) } -} \ No newline at end of file +} diff --git a/starknet_py/tests/e2e/mock/contracts_v2/src/map.cairo b/starknet_py/tests/e2e/mock/contracts_v2/src/map.cairo index 40a924aa1..aa849d579 100644 --- a/starknet_py/tests/e2e/mock/contracts_v2/src/map.cairo +++ b/starknet_py/tests/e2e/mock/contracts_v2/src/map.cairo @@ -22,4 +22,4 @@ mod Map { self.storage.read(key) } } -} \ No newline at end of file +} diff --git a/starknet_py/tests/e2e/mock/contracts_v2/src/simple_storage_with_event.cairo b/starknet_py/tests/e2e/mock/contracts_v2/src/simple_storage_with_event.cairo index e64e44598..34fc806ac 100644 --- a/starknet_py/tests/e2e/mock/contracts_v2/src/simple_storage_with_event.cairo +++ b/starknet_py/tests/e2e/mock/contracts_v2/src/simple_storage_with_event.cairo @@ -49,4 +49,4 @@ pub mod SimpleStorageWithEvent { self.emit(AnotherPutCalled { key: key, prev_value: prev_value, value: value, additional_value: value }); } } -} \ No newline at end of file +} From 580eb5d6bb5bba42fd888aca58fd96827c3fa081 Mon Sep 17 00:00:00 2001 From: kkawula <57270771+kkawula@users.noreply.github.com> Date: Wed, 21 Aug 2024 14:44:37 +0200 Subject: [PATCH 51/66] Change example in docs - declare_v3 uses casm --- .../tests/e2e/docs/quickstart/test_using_account.py | 9 ++++++--- starknet_py/tests/e2e/fixtures/contracts_v1.py | 7 +++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/starknet_py/tests/e2e/docs/quickstart/test_using_account.py b/starknet_py/tests/e2e/docs/quickstart/test_using_account.py index cc7c4cba1..5867c5298 100644 --- a/starknet_py/tests/e2e/docs/quickstart/test_using_account.py +++ b/starknet_py/tests/e2e/docs/quickstart/test_using_account.py @@ -10,8 +10,11 @@ # TODO (#1419): Fix contract redeclaration @pytest.mark.skip(reason="Redeclaration occurred") @pytest.mark.asyncio -async def test_using_account(account, map_compiled_contract_and_class_hash): - (compiled_contract, class_hash) = map_compiled_contract_and_class_hash +async def test_using_account( + account, map_compiled_contract_casm, map_compiled_contract_and_class_hash +): + (compiled_contract, _) = map_compiled_contract_and_class_hash + compiled_contract_casm = map_compiled_contract_casm # pylint: disable=import-outside-toplevel, duplicate-code, too-many-locals # docs: start from starknet_py.contract import Contract @@ -27,7 +30,7 @@ async def test_using_account(account, map_compiled_contract_and_class_hash): declare_result = await Contract.declare_v3( account, compiled_contract=compiled_contract, - compiled_class_hash=class_hash, + compiled_contract_casm=compiled_contract_casm, l1_resource_bounds=l1_resource_bounds, ) diff --git a/starknet_py/tests/e2e/fixtures/contracts_v1.py b/starknet_py/tests/e2e/fixtures/contracts_v1.py index 41467d47c..830b71325 100644 --- a/starknet_py/tests/e2e/fixtures/contracts_v1.py +++ b/starknet_py/tests/e2e/fixtures/contracts_v1.py @@ -242,6 +242,13 @@ def map_compiled_contract_and_class_hash() -> Tuple[str, int]: ) +@pytest.fixture(scope="package") +def map_compiled_contract_casm() -> str: + contract = load_contract("Map") + + return contract["casm"] + + @pytest_asyncio.fixture(scope="package") async def simple_storage_with_event_class_hash(account: BaseAccount) -> int: contract = load_contract("SimpleStorageWithEvent") From 8b3da08b1c720603cc8503354350fbcf98d4628d Mon Sep 17 00:00:00 2001 From: kkawula <57270771+kkawula@users.noreply.github.com> Date: Mon, 26 Aug 2024 12:18:24 +0200 Subject: [PATCH 52/66] Add empty line for readability --- starknet_py/tests/e2e/docs/guide/test_serializing.py | 1 + 1 file changed, 1 insertion(+) diff --git a/starknet_py/tests/e2e/docs/guide/test_serializing.py b/starknet_py/tests/e2e/docs/guide/test_serializing.py index d33111473..cb5b88425 100644 --- a/starknet_py/tests/e2e/docs/guide/test_serializing.py +++ b/starknet_py/tests/e2e/docs/guide/test_serializing.py @@ -74,6 +74,7 @@ def test_abi_parsing(): value: u256, } """ + # You can create serializer for events by passing Abi.Event object to serializer_for_event event_serializer = serializer_for_event( abi.events["contracts_v2::erc20::ERC20::Approval"] From 099e7b87c6269afbef7ce7fb95abead965334587 Mon Sep 17 00:00:00 2001 From: kkawula <57270771+kkawula@users.noreply.github.com> Date: Mon, 26 Aug 2024 12:20:26 +0200 Subject: [PATCH 53/66] Remove unused assert --- starknet_py/tests/e2e/docs/guide/test_serializing.py | 1 - 1 file changed, 1 deletion(-) diff --git a/starknet_py/tests/e2e/docs/guide/test_serializing.py b/starknet_py/tests/e2e/docs/guide/test_serializing.py index cb5b88425..b0c5a058b 100644 --- a/starknet_py/tests/e2e/docs/guide/test_serializing.py +++ b/starknet_py/tests/e2e/docs/guide/test_serializing.py @@ -51,7 +51,6 @@ def test_abi_parsing(): # You can use deserialized result from function serializer like a tuple result = function_serializer.deserialize([1]) - assert 1 == result[0] (success,) = result assert 1 == success # docs-serializer: end From b86199c09310023c4ae51b00b601bc3db73073dc Mon Sep 17 00:00:00 2001 From: kkawula <57270771+kkawula@users.noreply.github.com> Date: Mon, 26 Aug 2024 12:24:08 +0200 Subject: [PATCH 54/66] Fix docs-start --- starknet_py/tests/e2e/docs/guide/test_serializing.py | 1 - 1 file changed, 1 deletion(-) diff --git a/starknet_py/tests/e2e/docs/guide/test_serializing.py b/starknet_py/tests/e2e/docs/guide/test_serializing.py index b0c5a058b..52dc18bc4 100644 --- a/starknet_py/tests/e2e/docs/guide/test_serializing.py +++ b/starknet_py/tests/e2e/docs/guide/test_serializing.py @@ -59,7 +59,6 @@ def test_abi_parsing(): load_contract(contract_name="ERC20", version=ContractVersion.V2)["sierra"] )["abi"] abi = AbiParser(raw_abi_string).parse() - # docs-serializer: start # docs-event: start from starknet_py.serialization import serializer_for_event From 9588d819f27fe3ebc9301dd5dedb1dbf5bbc87e3 Mon Sep 17 00:00:00 2001 From: kkawula <57270771+kkawula@users.noreply.github.com> Date: Mon, 26 Aug 2024 13:13:07 +0200 Subject: [PATCH 55/66] Fix typo 'devnet-rs' -> 'starknet-devnet-rs' --- starknet_py/tests/e2e/account/account_test.py | 4 ++-- .../tests/e2e/contract_interaction/v1_interaction_test.py | 6 +++--- .../tests/e2e/docs/guide/test_using_existing_contracts.py | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/starknet_py/tests/e2e/account/account_test.py b/starknet_py/tests/e2e/account/account_test.py index c65d3b398..03bde9513 100644 --- a/starknet_py/tests/e2e/account/account_test.py +++ b/starknet_py/tests/e2e/account/account_test.py @@ -58,7 +58,7 @@ async def test_get_balance_throws_when_token_not_specified(account): @pytest.mark.skipif( "--contract_dir=v2" not in sys.argv, - reason="Some cairo 1 contracts compiled with v1 compiler fail with new devnet-rs", + reason="Some cairo 1 contracts compiled with v1 compiler fail with new starknet-devnet-rs", ) @pytest.mark.asyncio async def test_balance_when_token_specified(account, erc20_contract): @@ -69,7 +69,7 @@ async def test_balance_when_token_specified(account, erc20_contract): @pytest.mark.skipif( "--contract_dir=v2" not in sys.argv, - reason="Some cairo 1 contracts compiled with v1 compiler fail with new devnet-rs", + reason="Some cairo 1 contracts compiled with v1 compiler fail with new starknet-devnet-rs", ) @pytest.mark.asyncio async def test_estimated_fee_greater_than_zero(account, erc20_contract): diff --git a/starknet_py/tests/e2e/contract_interaction/v1_interaction_test.py b/starknet_py/tests/e2e/contract_interaction/v1_interaction_test.py index ea8e53a72..5dee59df9 100644 --- a/starknet_py/tests/e2e/contract_interaction/v1_interaction_test.py +++ b/starknet_py/tests/e2e/contract_interaction/v1_interaction_test.py @@ -12,7 +12,7 @@ @pytest.mark.skipif( "--contract_dir=v2" not in sys.argv, - reason="Some cairo 1 contracts compiled with v1 compiler fail with new devnet-rs", + reason="Some cairo 1 contracts compiled with v1 compiler fail with new starknet-devnet-rs", ) @pytest.mark.asyncio async def test_general_v1_interaction(account, cairo1_erc20_class_hash: int): @@ -58,7 +58,7 @@ async def test_general_v1_interaction(account, cairo1_erc20_class_hash: int): @pytest.mark.skipif( "--contract_dir=v2" not in sys.argv, - reason="Some Cairo 1 contracts compiled with v1 compiler fail with new devnet-rs", + reason="Some Cairo 1 contracts compiled with v1 compiler fail with new starknet-devnet-rs", ) @pytest.mark.asyncio async def test_serializing_struct(account, cairo1_token_bridge_class_hash: int): @@ -150,7 +150,7 @@ async def test_serializing_enum(account, cairo1_test_enum_class_hash: int): @pytest.mark.skipif( "--contract_dir=v2" not in sys.argv, - reason="Some cairo 1 contracts compiled with v1 compiler fail with new devnet-rs", + reason="Some cairo 1 contracts compiled with v1 compiler fail with new starknet-devnet-rs", ) @pytest.mark.asyncio async def test_from_address_on_v1_contract(account, cairo1_erc20_class_hash: int): diff --git a/starknet_py/tests/e2e/docs/guide/test_using_existing_contracts.py b/starknet_py/tests/e2e/docs/guide/test_using_existing_contracts.py index 3ef79c7fc..2d3ebf9b1 100644 --- a/starknet_py/tests/e2e/docs/guide/test_using_existing_contracts.py +++ b/starknet_py/tests/e2e/docs/guide/test_using_existing_contracts.py @@ -27,7 +27,7 @@ @pytest.mark.skipif( "--contract_dir=v2" not in sys.argv, - reason="Some cairo 1 contracts compiled with v1 compiler fail with new devnet-rs", + reason="Some cairo 1 contracts compiled with v1 compiler fail with new starknet-devnet-rs", ) @pytest.mark.asyncio async def test_using_existing_contracts(account, erc20_contract): From 84802f9eb8ade3c02edfcc088ec17a3c217118e5 Mon Sep 17 00:00:00 2001 From: kkawula <57270771+kkawula@users.noreply.github.com> Date: Mon, 26 Aug 2024 14:27:40 +0200 Subject: [PATCH 56/66] Update starknet_py/tests/e2e/docs/guide/test_declaring_contracts.py Co-authored-by: Franciszek Job <54181625+franciszekjob@users.noreply.github.com> --- starknet_py/tests/e2e/docs/guide/test_declaring_contracts.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/starknet_py/tests/e2e/docs/guide/test_declaring_contracts.py b/starknet_py/tests/e2e/docs/guide/test_declaring_contracts.py index b17a0484b..8ae36b360 100644 --- a/starknet_py/tests/e2e/docs/guide/test_declaring_contracts.py +++ b/starknet_py/tests/e2e/docs/guide/test_declaring_contracts.py @@ -10,9 +10,9 @@ async def test_declaring_contracts(account, map_compiled_contract_and_class_hash (compiled_contract, class_hash) = map_compiled_contract_and_class_hash # docs: start - # Account.sign_declare_v2 and Account.sign_declare_v3 takes string containing a compiled contract (sierra) + # Account.sign_declare_v2 and Account.sign_declare_v3 take string containing a compiled contract (sierra) # and a class hash (casm_class_hash) - # Returns DeclareV2 and DeclareV3 respectively + # They return DeclareV2 and DeclareV3 respectively declare_transaction = await account.sign_declare_v3( compiled_contract=compiled_contract, From 51bb720bbaf1bdf63e797f8b66c79553f4216c40 Mon Sep 17 00:00:00 2001 From: kkawula <57270771+kkawula@users.noreply.github.com> Date: Mon, 26 Aug 2024 15:19:07 +0200 Subject: [PATCH 57/66] Scarb fmt --- starknet_py/tests/e2e/mock/contracts_v1/src/map.cairo | 4 +--- .../contracts_v2/src/constructor_with_arguments.cairo | 8 +++++++- .../tests/e2e/mock/contracts_v2/src/l1_l2.cairo | 10 ++++++---- .../contracts_v2/src/simple_storage_with_event.cairo | 7 ++++++- 4 files changed, 20 insertions(+), 9 deletions(-) diff --git a/starknet_py/tests/e2e/mock/contracts_v1/src/map.cairo b/starknet_py/tests/e2e/mock/contracts_v1/src/map.cairo index 38f27d0bc..fa2947dd8 100644 --- a/starknet_py/tests/e2e/mock/contracts_v1/src/map.cairo +++ b/starknet_py/tests/e2e/mock/contracts_v1/src/map.cairo @@ -1,8 +1,7 @@ #[contract] mod Map { - struct Storage { - storage: LegacyMap::, + storage: LegacyMap::, } #[external] @@ -14,5 +13,4 @@ mod Map { fn get(key: felt252) -> felt252 { storage::read(key) } - } diff --git a/starknet_py/tests/e2e/mock/contracts_v2/src/constructor_with_arguments.cairo b/starknet_py/tests/e2e/mock/contracts_v2/src/constructor_with_arguments.cairo index 375c4a09e..afd966512 100644 --- a/starknet_py/tests/e2e/mock/contracts_v2/src/constructor_with_arguments.cairo +++ b/starknet_py/tests/e2e/mock/contracts_v2/src/constructor_with_arguments.cairo @@ -22,7 +22,13 @@ mod ConstructorWithArguments { } #[constructor] - fn constructor(ref self: ContractState, single_value: felt252, tuple: (felt252, (felt252, felt252)), arr: Array, dict: TopStruct) { + fn constructor( + ref self: ContractState, + single_value: felt252, + tuple: (felt252, (felt252, felt252)), + arr: Array, + dict: TopStruct + ) { let mut sum = 0; let count = arr.len(); diff --git a/starknet_py/tests/e2e/mock/contracts_v2/src/l1_l2.cairo b/starknet_py/tests/e2e/mock/contracts_v2/src/l1_l2.cairo index 48c9c3724..1e8a9f058 100644 --- a/starknet_py/tests/e2e/mock/contracts_v2/src/l1_l2.cairo +++ b/starknet_py/tests/e2e/mock/contracts_v2/src/l1_l2.cairo @@ -69,7 +69,11 @@ mod l1_l2 { /// send the funds. #[external(v0)] fn withdraw_from_lib( - ref self: ContractState, user: felt252, amount: felt252, l1_address: felt252, message_sender_class_hash: starknet::ClassHash, + ref self: ContractState, + user: felt252, + amount: felt252, + l1_address: felt252, + message_sender_class_hash: starknet::ClassHash, ) { assert(amount.is_non_zero(), 'Amount must be positive'); @@ -89,9 +93,7 @@ mod l1_l2 { starknet::SyscallResultTrait::unwrap_syscall( starknet::library_call_syscall( - message_sender_class_hash, - selector!("send_withdraw_message"), - calldata.span(), + message_sender_class_hash, selector!("send_withdraw_message"), calldata.span(), ) ); } diff --git a/starknet_py/tests/e2e/mock/contracts_v2/src/simple_storage_with_event.cairo b/starknet_py/tests/e2e/mock/contracts_v2/src/simple_storage_with_event.cairo index 34fc806ac..f29bc8b0f 100644 --- a/starknet_py/tests/e2e/mock/contracts_v2/src/simple_storage_with_event.cairo +++ b/starknet_py/tests/e2e/mock/contracts_v2/src/simple_storage_with_event.cairo @@ -46,7 +46,12 @@ pub mod SimpleStorageWithEvent { fn another_put(ref self: ContractState, key: felt252, value: felt252) { let mut prev_value = self.map.read(key); self.map.write(key, value); - self.emit(AnotherPutCalled { key: key, prev_value: prev_value, value: value, additional_value: value }); + self + .emit( + AnotherPutCalled { + key: key, prev_value: prev_value, value: value, additional_value: value + } + ); } } } From 5d91ee428484b42988cf06f2b201138d410b92cc Mon Sep 17 00:00:00 2001 From: kkawula <57270771+kkawula@users.noreply.github.com> Date: Mon, 26 Aug 2024 15:21:22 +0200 Subject: [PATCH 58/66] Scarb fmt --- .../contracts_v2/src/constructor_with_arguments.cairo | 8 +++++++- .../tests/e2e/mock/contracts_v2/src/l1_l2.cairo | 10 ++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/starknet_py/tests/e2e/mock/contracts_v2/src/constructor_with_arguments.cairo b/starknet_py/tests/e2e/mock/contracts_v2/src/constructor_with_arguments.cairo index 375c4a09e..afd966512 100644 --- a/starknet_py/tests/e2e/mock/contracts_v2/src/constructor_with_arguments.cairo +++ b/starknet_py/tests/e2e/mock/contracts_v2/src/constructor_with_arguments.cairo @@ -22,7 +22,13 @@ mod ConstructorWithArguments { } #[constructor] - fn constructor(ref self: ContractState, single_value: felt252, tuple: (felt252, (felt252, felt252)), arr: Array, dict: TopStruct) { + fn constructor( + ref self: ContractState, + single_value: felt252, + tuple: (felt252, (felt252, felt252)), + arr: Array, + dict: TopStruct + ) { let mut sum = 0; let count = arr.len(); diff --git a/starknet_py/tests/e2e/mock/contracts_v2/src/l1_l2.cairo b/starknet_py/tests/e2e/mock/contracts_v2/src/l1_l2.cairo index 48c9c3724..1e8a9f058 100644 --- a/starknet_py/tests/e2e/mock/contracts_v2/src/l1_l2.cairo +++ b/starknet_py/tests/e2e/mock/contracts_v2/src/l1_l2.cairo @@ -69,7 +69,11 @@ mod l1_l2 { /// send the funds. #[external(v0)] fn withdraw_from_lib( - ref self: ContractState, user: felt252, amount: felt252, l1_address: felt252, message_sender_class_hash: starknet::ClassHash, + ref self: ContractState, + user: felt252, + amount: felt252, + l1_address: felt252, + message_sender_class_hash: starknet::ClassHash, ) { assert(amount.is_non_zero(), 'Amount must be positive'); @@ -89,9 +93,7 @@ mod l1_l2 { starknet::SyscallResultTrait::unwrap_syscall( starknet::library_call_syscall( - message_sender_class_hash, - selector!("send_withdraw_message"), - calldata.span(), + message_sender_class_hash, selector!("send_withdraw_message"), calldata.span(), ) ); } From 34e1b83b188c54be2b9a8ad9a26b0ff927c69b56 Mon Sep 17 00:00:00 2001 From: kkawula <57270771+kkawula@users.noreply.github.com> Date: Mon, 26 Aug 2024 15:49:25 +0200 Subject: [PATCH 59/66] Rename fixture 'cairo1_map_contract_abi' -> 'map_abi' --- .../tests/e2e/docs/guide/test_deploying_in_multicall.py | 4 +--- starknet_py/tests/e2e/fixtures/contracts_v1.py | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/starknet_py/tests/e2e/docs/guide/test_deploying_in_multicall.py b/starknet_py/tests/e2e/docs/guide/test_deploying_in_multicall.py index 8df3252e6..4236318f2 100644 --- a/starknet_py/tests/e2e/docs/guide/test_deploying_in_multicall.py +++ b/starknet_py/tests/e2e/docs/guide/test_deploying_in_multicall.py @@ -2,7 +2,7 @@ @pytest.mark.asyncio -async def test_deploying_in_multicall(account, map_class_hash, cairo1_map_contract_abi): +async def test_deploying_in_multicall(account, map_class_hash, map_abi): # pylint: disable=import-outside-toplevel, # docs: start from starknet_py.contract import Contract @@ -16,8 +16,6 @@ async def test_deploying_in_multicall(account, map_class_hash, cairo1_map_contra class_hash=map_class_hash ) # docs: end - - map_abi = cairo1_map_contract_abi # docs: start # Address of the `map` contract is known here, so we can create its instance! diff --git a/starknet_py/tests/e2e/fixtures/contracts_v1.py b/starknet_py/tests/e2e/fixtures/contracts_v1.py index 830b71325..d8069af05 100644 --- a/starknet_py/tests/e2e/fixtures/contracts_v1.py +++ b/starknet_py/tests/e2e/fixtures/contracts_v1.py @@ -223,7 +223,7 @@ async def map_contract(account: BaseAccount, map_class_hash) -> Contract: @pytest_asyncio.fixture(scope="package") -async def cairo1_map_contract_abi() -> List: +async def map_abi() -> List: contract = load_contract(contract_name="Map") compiled_contract = create_sierra_compiled_contract( compiled_contract=contract["sierra"] From 265350134bc135485fadeb54a90bb9272348592e Mon Sep 17 00:00:00 2001 From: kkawula <57270771+kkawula@users.noreply.github.com> Date: Tue, 27 Aug 2024 10:43:18 +0200 Subject: [PATCH 60/66] Move abi_v1 constatnt to abi fixture file --- .../serialization/serialization_test.py | 20 ++----------------- .../tests/e2e/fixtures/abi_v1_structures.py | 18 +++++++++++++++++ 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/starknet_py/serialization/serialization_test.py b/starknet_py/serialization/serialization_test.py index 0ab5cb024..b60a6363d 100644 --- a/starknet_py/serialization/serialization_test.py +++ b/starknet_py/serialization/serialization_test.py @@ -14,6 +14,7 @@ serializer_for_function, ) from starknet_py.serialization.tuple_dataclass import TupleDataclass +from starknet_py.tests.e2e.fixtures.abi_v1_structures import event_abi_v1 from starknet_py.tests.e2e.fixtures.constants import CONTRACTS_COMPILED_V0_DIR from starknet_py.tests.e2e.fixtures.misc import ( ContractVersion, @@ -110,24 +111,7 @@ class Education(NamedTuple): ) parsed_abi = AbiParserV0(abi).parse() -abi_v1 = [ - { - "type": "event", - "name": "Approval", - "inputs": [ - { - "name": "owner", - "type": "core::starknet::contract_address::ContractAddress", - }, - { - "name": "spender", - "type": "core::starknet::contract_address::ContractAddress", - }, - {"name": "value", "type": "core::integer::u256"}, - ], - } -] -parsed_abi_v1 = AbiParserV1(abi_v1).parse() +parsed_abi_v1 = AbiParserV1(event_abi_v1).parse() abi_v2 = json.loads( load_contract(contract_name="NewSyntaxTestContract", version=ContractVersion.V2)[ diff --git a/starknet_py/tests/e2e/fixtures/abi_v1_structures.py b/starknet_py/tests/e2e/fixtures/abi_v1_structures.py index a33a5ae3a..6332258fe 100644 --- a/starknet_py/tests/e2e/fixtures/abi_v1_structures.py +++ b/starknet_py/tests/e2e/fixtures/abi_v1_structures.py @@ -177,3 +177,21 @@ functions={}, defined_enums={}, ) + +event_abi_v1 = [ + { + "type": "event", + "name": "Approval", + "inputs": [ + { + "name": "owner", + "type": "core::starknet::contract_address::ContractAddress", + }, + { + "name": "spender", + "type": "core::starknet::contract_address::ContractAddress", + }, + {"name": "value", "type": "core::integer::u256"}, + ], + } +] From 51d82a0f6516c65166a1b878657b0c8a03eb00c7 Mon Sep 17 00:00:00 2001 From: kkawula <57270771+kkawula@users.noreply.github.com> Date: Tue, 27 Aug 2024 13:55:59 +0200 Subject: [PATCH 61/66] Fix 'test_get_block_with_txs_latest' --- starknet_py/tests/e2e/block_test.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/starknet_py/tests/e2e/block_test.py b/starknet_py/tests/e2e/block_test.py index 08f17aeb3..d51a4c9c0 100644 --- a/starknet_py/tests/e2e/block_test.py +++ b/starknet_py/tests/e2e/block_test.py @@ -1,7 +1,10 @@ +from typing import cast + import pytest from starknet_py.net.client_models import ( BlockStatus, + DeclareTransactionV2, L1DAMode, PendingStarknetBlock, PendingStarknetBlockWithTxHashes, @@ -64,15 +67,15 @@ async def test_get_block_with_txs_pending(account): assert isinstance(blk.transactions, list) -# TODO (#1419): Fix contract redeclaration -@pytest.mark.skip(reason="Redeclaration occurred") @pytest.mark.asyncio -async def test_get_block_with_txs_latest(account): +async def test_get_block_with_txs_latest(account, map_class_hash): + # pylint: disable=unused-argument + blk = await account.client.get_block_with_txs(block_number="latest") assert isinstance(blk, StarknetBlock) assert isinstance(blk.transactions, list) - assert blk.transactions[0].hash is not None + assert cast(DeclareTransactionV2, blk.transactions[0]).class_hash == map_class_hash assert blk.block_hash is not None assert blk.parent_hash is not None assert blk.block_number is not None From d72a94ecd121c36c7d94bc93dab02246f932a1d1 Mon Sep 17 00:00:00 2001 From: kkawula <57270771+kkawula@users.noreply.github.com> Date: Tue, 27 Aug 2024 14:16:24 +0200 Subject: [PATCH 62/66] Fix 'test_get_block_with_txs_latest' --- starknet_py/tests/e2e/block_test.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/starknet_py/tests/e2e/block_test.py b/starknet_py/tests/e2e/block_test.py index d51a4c9c0..869e983a5 100644 --- a/starknet_py/tests/e2e/block_test.py +++ b/starknet_py/tests/e2e/block_test.py @@ -1,10 +1,7 @@ -from typing import cast - import pytest from starknet_py.net.client_models import ( BlockStatus, - DeclareTransactionV2, L1DAMode, PendingStarknetBlock, PendingStarknetBlockWithTxHashes, @@ -75,7 +72,7 @@ async def test_get_block_with_txs_latest(account, map_class_hash): assert isinstance(blk, StarknetBlock) assert isinstance(blk.transactions, list) - assert cast(DeclareTransactionV2, blk.transactions[0]).class_hash == map_class_hash + assert blk.transactions[0].hash is not None assert blk.block_hash is not None assert blk.parent_hash is not None assert blk.block_number is not None From bb987c8c0ff6b42188812686049115643eedaf65 Mon Sep 17 00:00:00 2001 From: kkawula <57270771+kkawula@users.noreply.github.com> Date: Tue, 27 Aug 2024 14:19:24 +0200 Subject: [PATCH 63/66] Add TODO to 'test_get_block_with_txs_latest' --- starknet_py/tests/e2e/block_test.py | 1 + 1 file changed, 1 insertion(+) diff --git a/starknet_py/tests/e2e/block_test.py b/starknet_py/tests/e2e/block_test.py index 869e983a5..529071b57 100644 --- a/starknet_py/tests/e2e/block_test.py +++ b/starknet_py/tests/e2e/block_test.py @@ -64,6 +64,7 @@ async def test_get_block_with_txs_pending(account): assert isinstance(blk.transactions, list) +# TODO (#1419): Fix contract redeclaration @pytest.mark.asyncio async def test_get_block_with_txs_latest(account, map_class_hash): # pylint: disable=unused-argument From 839ccb98a719df57321a396ed95153429f656620 Mon Sep 17 00:00:00 2001 From: kkawula <57270771+kkawula@users.noreply.github.com> Date: Tue, 27 Aug 2024 15:16:57 +0200 Subject: [PATCH 64/66] Fix typo --- starknet_py/tests/e2e/docs/guide/test_deploying_with_udc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/starknet_py/tests/e2e/docs/guide/test_deploying_with_udc.py b/starknet_py/tests/e2e/docs/guide/test_deploying_with_udc.py index 00dea4403..d33490e59 100644 --- a/starknet_py/tests/e2e/docs/guide/test_deploying_with_udc.py +++ b/starknet_py/tests/e2e/docs/guide/test_deploying_with_udc.py @@ -5,7 +5,7 @@ @pytest.mark.skipif( "--contract_dir=v2" not in sys.argv, - reason="Contract exists onlgsty in v2 directory", + reason="Contract exists only in v2 directory", ) @pytest.mark.asyncio async def test_deploying_with_udc( From 79f8da3db3ea8f91a99dd9ae7ba3c1807350a236 Mon Sep 17 00:00:00 2001 From: kkawula <57270771+kkawula@users.noreply.github.com> Date: Tue, 27 Aug 2024 15:41:07 +0200 Subject: [PATCH 65/66] Update starknet_py/tests/e2e/fixtures/contracts_v1.py Co-authored-by: Franciszek Job <54181625+franciszekjob@users.noreply.github.com> --- starknet_py/tests/e2e/fixtures/contracts_v1.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/starknet_py/tests/e2e/fixtures/contracts_v1.py b/starknet_py/tests/e2e/fixtures/contracts_v1.py index d8069af05..ffb6e9f95 100644 --- a/starknet_py/tests/e2e/fixtures/contracts_v1.py +++ b/starknet_py/tests/e2e/fixtures/contracts_v1.py @@ -224,7 +224,7 @@ async def map_contract(account: BaseAccount, map_class_hash) -> Contract: @pytest_asyncio.fixture(scope="package") async def map_abi() -> List: - contract = load_contract(contract_name="Map") + contract = load_contract("Map") compiled_contract = create_sierra_compiled_contract( compiled_contract=contract["sierra"] ) From 6cc8ab4a1529541736d695d9536933152aa9bf8c Mon Sep 17 00:00:00 2001 From: kkawula <57270771+kkawula@users.noreply.github.com> Date: Tue, 27 Aug 2024 15:41:17 +0200 Subject: [PATCH 66/66] Update starknet_py/tests/e2e/fixtures/contracts_v1.py Co-authored-by: Franciszek Job <54181625+franciszekjob@users.noreply.github.com> --- starknet_py/tests/e2e/fixtures/contracts_v1.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/starknet_py/tests/e2e/fixtures/contracts_v1.py b/starknet_py/tests/e2e/fixtures/contracts_v1.py index ffb6e9f95..360aa1d9e 100644 --- a/starknet_py/tests/e2e/fixtures/contracts_v1.py +++ b/starknet_py/tests/e2e/fixtures/contracts_v1.py @@ -204,7 +204,7 @@ async def deploy_string_contract( @pytest_asyncio.fixture(scope="package") async def map_class_hash(account: BaseAccount) -> int: - contract = load_contract(contract_name="Map") + contract = load_contract("Map") class_hash, _ = await declare_cairo1_contract( account, contract["sierra"],