diff --git a/starknet_py/net/full_node_client.py b/starknet_py/net/full_node_client.py index 3c099970d..f29f4395d 100644 --- a/starknet_py/net/full_node_client.py +++ b/starknet_py/net/full_node_client.py @@ -97,7 +97,6 @@ def __init__( Client for interacting with Starknet json-rpc interface. :param node_url: Url of the node providing rpc interface - :param net: Starknet network identifier :param session: Aiohttp session to be used for request. If not provided, client will create a session for every request. When using a custom session, user is responsible for closing it manually. """ diff --git a/starknet_py/tests/e2e/contract_interaction/declare_test.py b/starknet_py/tests/e2e/contract_interaction/declare_test.py index 370f9a845..0acd91410 100644 --- a/starknet_py/tests/e2e/contract_interaction/declare_test.py +++ b/starknet_py/tests/e2e/contract_interaction/declare_test.py @@ -1,46 +1,8 @@ import pytest from starknet_py.contract import Contract -from starknet_py.net.models import DeclareV2, DeclareV3 from starknet_py.tests.e2e.fixtures.constants import MAX_FEE, MAX_RESOURCE_BOUNDS_L1 -from starknet_py.tests.e2e.fixtures.misc import ContractVersion, load_contract - - -@pytest.mark.asyncio -async def test_contract_declare_v2(account): - compiled_contract = load_contract( - contract_name="TestContract", version=ContractVersion.V1 - ) - - declare_result = await Contract.declare_v2( - account, - compiled_contract=compiled_contract["sierra"], - compiled_contract_casm=compiled_contract["casm"], - max_fee=MAX_FEE, - ) - await declare_result.wait_for_acceptance() - - assert isinstance(declare_result.declare_transaction, DeclareV2) - assert isinstance(declare_result.hash, int) - assert isinstance(declare_result.class_hash, int) - assert declare_result.compiled_contract == compiled_contract["sierra"] - - -@pytest.mark.asyncio -async def test_contract_declare_v3(account): - contract = load_contract(contract_name="TestContract", version=ContractVersion.V2) - declare_result = await Contract.declare_v3( - account, - compiled_contract=contract["sierra"], - compiled_contract_casm=contract["casm"], - l1_resource_bounds=MAX_RESOURCE_BOUNDS_L1, - ) - await declare_result.wait_for_acceptance() - - assert isinstance(declare_result.declare_transaction, DeclareV3) - assert isinstance(declare_result.hash, int) - assert isinstance(declare_result.class_hash, int) - assert declare_result.compiled_contract == contract["sierra"] +from starknet_py.tests.e2e.fixtures.misc import load_contract @pytest.mark.asyncio diff --git a/starknet_py/tests/e2e/contract_interaction/deploy_test.py b/starknet_py/tests/e2e/contract_interaction/deploy_test.py index 04176ccbb..e2d4ab85c 100644 --- a/starknet_py/tests/e2e/contract_interaction/deploy_test.py +++ b/starknet_py/tests/e2e/contract_interaction/deploy_test.py @@ -6,7 +6,7 @@ from starknet_py.common import create_sierra_compiled_contract from starknet_py.contract import Contract, DeclareResult -from starknet_py.net.client_models import InvokeTransactionV1, InvokeTransactionV3 +from starknet_py.net.client_models import InvokeTransactionV1 from starknet_py.net.models import DeclareV2 from starknet_py.tests.e2e.fixtures.constants import MAX_FEE, MAX_RESOURCE_BOUNDS_L1 from starknet_py.tests.e2e.fixtures.misc import load_contract @@ -123,35 +123,6 @@ async def test_deploy_contract_v1(account, cairo1_hello_starknet_class_hash: int assert class_hash == cairo1_hello_starknet_class_hash -@pytest.mark.asyncio -async def test_deploy_contract_v3(account, cairo1_hello_starknet_class_hash: int): - compiled_contract = load_contract("HelloStarknet")["sierra"] - abi = create_sierra_compiled_contract( - compiled_contract=compiled_contract - ).parsed_abi - - deploy_result = await Contract.deploy_contract_v3( - class_hash=cairo1_hello_starknet_class_hash, - account=account, - abi=abi, - l1_resource_bounds=MAX_RESOURCE_BOUNDS_L1, - cairo_version=1, - ) - await deploy_result.wait_for_acceptance() - - contract = deploy_result.deployed_contract - assert isinstance(contract.address, int) - assert len(contract.functions) != 0 - - transaction = await account.client.get_transaction(tx_hash=deploy_result.hash) - assert isinstance(transaction, InvokeTransactionV3) - - class_hash = await account.client.get_class_hash_at( - 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( diff --git a/starknet_py/tests/e2e/docs/code_examples/test_account.py b/starknet_py/tests/e2e/docs/code_examples/test_account.py index 2f32f4b78..ab40386c1 100644 --- a/starknet_py/tests/e2e/docs/code_examples/test_account.py +++ b/starknet_py/tests/e2e/docs/code_examples/test_account.py @@ -6,7 +6,7 @@ from starknet_py.constants import FEE_CONTRACT_ADDRESS from starknet_py.hash.selector import get_selector_from_name from starknet_py.net.account.account import Account -from starknet_py.net.client_models import Call +from starknet_py.net.client_models import Call, ResourceBounds from starknet_py.net.full_node_client import FullNodeClient from starknet_py.net.models import StarknetChainId from starknet_py.net.models.typed_data import TypedDataDict @@ -25,8 +25,8 @@ def test_init(): @pytest.mark.asyncio -async def test_execute(account, contract_address): - # docs-start: execute +async def test_execute_v1(account, contract_address): + # docs-start: execute_v1 resp = await account.execute_v1( Call( to_addr=contract_address, @@ -36,15 +36,40 @@ async def test_execute(account, contract_address): max_fee=int(1e15), ) # or - # docs-end: execute + # docs-end: execute_v1 call1 = call2 = Call( to_addr=contract_address, selector=get_selector_from_name("increase_balance"), calldata=[123], ) - # docs-start: execute + # docs-start: execute_v1 resp = await account.execute_v1(calls=[call1, call2], auto_estimate=True) - # docs-end: execute + # docs-end: execute_v1 + + +@pytest.mark.asyncio +async def test_execute_v3(account, contract_address): + # docs-start: execute_v3 + resp = await account.execute_v3( + Call( + to_addr=contract_address, + selector=get_selector_from_name("increase_balance"), + calldata=[123], + ), + l1_resource_bounds=ResourceBounds( + max_amount=int(1e5), max_price_per_unit=int(1e13) + ), + ) + # or + # docs-end: execute_v3 + call1 = call2 = Call( + to_addr=contract_address, + selector=get_selector_from_name("increase_balance"), + calldata=[123], + ) + # docs-start: execute_v3 + resp = await account.execute_v3(calls=[call1, call2], auto_estimate=True) + # docs-end: execute_v3 @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 14274a9c2..e969794cd 100644 --- a/starknet_py/tests/e2e/docs/code_examples/test_contract.py +++ b/starknet_py/tests/e2e/docs/code_examples/test_contract.py @@ -1,11 +1,14 @@ # pylint: disable=unused-variable import pytest +from starknet_py.common import create_sierra_compiled_contract from starknet_py.contract import Contract from starknet_py.net.account.account import Account +from starknet_py.net.client_models import InvokeTransactionV3, ResourceBounds from starknet_py.net.full_node_client import FullNodeClient -from starknet_py.net.models import StarknetChainId +from starknet_py.net.models import DeclareV2, DeclareV3, StarknetChainId from starknet_py.net.signer.stark_curve_signer import KeyPair +from starknet_py.tests.e2e.fixtures.misc import ContractVersion, load_contract def test_init(): @@ -51,18 +54,62 @@ async def test_from_address(account, contract_address): @pytest.mark.asyncio -async def test_declare(account, custom_proxy): +async def test_declare_v1(account, custom_proxy): compiled_contract = custom_proxy - # docs-start: declare + # docs-start: declare_v1 declare_result = await Contract.declare_v1( account=account, compiled_contract=compiled_contract, max_fee=int(1e15) ) - # docs-end: declare + # docs-end: declare_v1 @pytest.mark.asyncio -async def test_deploy_contract(account, class_hash): - # docs-start: deploy_contract +async def test_declare_v2(account): + compiled_contract = load_contract( + contract_name="TestContract", version=ContractVersion.V1 + ) + # docs-start: declare_v2 + # here `compiled_contract` is a dict containing sierra and casm artifacts + declare_result = await Contract.declare_v2( + account, + compiled_contract=compiled_contract["sierra"], + compiled_contract_casm=compiled_contract["casm"], + max_fee=int(1e15), + ) + # docs-end: declare_v2 + await declare_result.wait_for_acceptance() + + assert isinstance(declare_result.declare_transaction, DeclareV2) + assert isinstance(declare_result.hash, int) + assert isinstance(declare_result.class_hash, int) + assert declare_result.compiled_contract == compiled_contract["sierra"] + + +@pytest.mark.asyncio +async def test_declare_v3(account): + contract = load_contract(contract_name="TestContract", version=ContractVersion.V2) + # docs-start: declare_v3 + # here `contract` is a dict containing sierra and casm artifacts + declare_result = await Contract.declare_v3( + account, + compiled_contract=contract["sierra"], + compiled_contract_casm=contract["casm"], + l1_resource_bounds=ResourceBounds( + max_amount=int(1e5), max_price_per_unit=int(1e13) + ), + ) + # docs-end: declare_v3 + await declare_result.wait_for_acceptance() + + assert isinstance(declare_result.declare_transaction, DeclareV3) + assert isinstance(declare_result.hash, int) + assert isinstance(declare_result.class_hash, int) + assert declare_result.compiled_contract == contract["sierra"] + + +@pytest.mark.asyncio +async def test_deploy_contract_v1(account, class_hash): + # docs-start: deploy_contract_v1 deploy_result = await Contract.deploy_contract_v1( account=account, class_hash=class_hash, @@ -91,7 +138,41 @@ async def test_deploy_contract(account, class_hash): constructor_args={"value": 1}, max_fee=int(1e15), ) - # docs-end: deploy_contract + # docs-end: deploy_contract_v1 + + +@pytest.mark.asyncio +async def test_deploy_contract_v3(account, cairo1_hello_starknet_class_hash: int): + compiled_contract = load_contract("HelloStarknet")["sierra"] + # docs-start: deploy_contract_v3 + abi = create_sierra_compiled_contract( + compiled_contract=compiled_contract + ).parsed_abi + # docs-end: deploy_contract_v3 + class_hash = cairo1_hello_starknet_class_hash + # docs-start: deploy_contract_v3 + deploy_result = await Contract.deploy_contract_v3( + class_hash=class_hash, + account=account, + abi=abi, + l1_resource_bounds=ResourceBounds( + max_amount=int(1e5), max_price_per_unit=int(1e13) + ), + ) + # docs-end: deploy_contract_v3 + await deploy_result.wait_for_acceptance() + + contract = deploy_result.deployed_contract + assert isinstance(contract.address, int) + assert len(contract.functions) != 0 + + transaction = await account.client.get_transaction(tx_hash=deploy_result.hash) + assert isinstance(transaction, InvokeTransactionV3) + + class_hash = await account.client.get_class_hash_at( + contract_address=contract.address + ) + assert class_hash == cairo1_hello_starknet_class_hash def test_compute_address(custom_proxy): diff --git a/starknet_py/tests/e2e/docs/code_examples/test_deployer.py b/starknet_py/tests/e2e/docs/code_examples/test_deployer.py index b4bffa7e0..b2aded890 100644 --- a/starknet_py/tests/e2e/docs/code_examples/test_deployer.py +++ b/starknet_py/tests/e2e/docs/code_examples/test_deployer.py @@ -15,8 +15,8 @@ def test_init(): def test_create_contract_deployment_raw(): deployer = Deployer() - # docs-start: create_deployment_call_raw + # docs-start: create_contract_deployment_raw contract_deployment = deployer.create_contract_deployment_raw( class_hash=0x123, salt=1, raw_calldata=[3, 1, 2, 3] ) - # docs-end: create_deployment_call_raw + # docs-end: create_contract_deployment_raw diff --git a/starknet_py/tests/e2e/docs/code_examples/test_full_node_client.py b/starknet_py/tests/e2e/docs/code_examples/test_full_node_client.py index cd729b4fa..b3ab0147c 100644 --- a/starknet_py/tests/e2e/docs/code_examples/test_full_node_client.py +++ b/starknet_py/tests/e2e/docs/code_examples/test_full_node_client.py @@ -1,5 +1,6 @@ # pylint: disable=unused-variable import pytest +from aiohttp import ClientSession from starknet_py.contract import Contract from starknet_py.hash.selector import get_selector_from_name @@ -14,6 +15,18 @@ def test_init(): # docs-end: init +@pytest.mark.asyncio +async def test_init_with_custom_client_session(): + # docs-start: init + # or with custom client session + session = ClientSession() + client = FullNodeClient(node_url="https://your.node.url", session=session) + # perform operations... + # close the session + await session.close() + # docs-end: init + + @pytest.mark.asyncio async def test_get_block(client, block_with_declare_hash): # docs-start: get_block 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 e1a2451dc..9f81345ab 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 @@ -17,7 +17,7 @@ async def test_deploying_with_udc( salt = None # docs: start - # If you use mainnet/goerli/sepolia there is no need to explicitly specify + # If you use mainnet/sepolia there is no need to explicitly specify # address of the deployer (default one will be used) deployer = Deployer()