Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
841e566
Add `test_init_with_custom_client_session`; Rename `test_execute` to …
franciszekjob Jul 15, 2024
b247a94
Remove `net` param from `FullNodeClient.__init__()` docstring
franciszekjob Jul 15, 2024
95f4e76
Remove goerli mention
franciszekjob Jul 15, 2024
09759f7
Fix `test_create_contract_deployment_raw()` docs
franciszekjob Jul 15, 2024
765d0ec
Fix `test_deploy_contract` docs
franciszekjob Jul 15, 2024
8e56d24
Fix declare v1 docs
franciszekjob Jul 15, 2024
cabb515
Add missing `docs-end` to `deploy_contract_v1`
franciszekjob Jul 15, 2024
2f71007
Restructure execute v1 docs example
franciszekjob Jul 16, 2024
c16222b
Add docs examples for declare v2, v3 and deploy contract v3
franciszekjob Jul 17, 2024
8c316a2
Merge branch 'development' of https://github.com/software-mansion/sta…
franciszekjob Jul 17, 2024
fe344d5
Update starknet_py/tests/e2e/docs/code_examples/test_contract.py
franciszekjob Jul 17, 2024
2cf8f3b
Add comment and remove `cairo_version` param in declare v3 example
franciszekjob Jul 18, 2024
7644363
Merge branch 'franciszekjob/1354-update-docs' of https://github.com/s…
franciszekjob Jul 18, 2024
456cd9e
Update starknet_py/tests/e2e/docs/code_examples/test_contract.py
franciszekjob Jul 18, 2024
2e6d39b
Merge branch 'development' of https://github.com/software-mansion/sta…
franciszekjob Jul 18, 2024
96d1db0
Include creation of abi in `test_deploy_contract_v3`
franciszekjob Jul 18, 2024
9d2e4f9
Add `test_execute_v3`
franciszekjob Jul 18, 2024
530d541
Update starknet_py/tests/e2e/docs/code_examples/test_contract.py
franciszekjob Jul 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion starknet_py/net/full_node_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
"""
Expand Down
40 changes: 1 addition & 39 deletions starknet_py/tests/e2e/contract_interaction/declare_test.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
31 changes: 1 addition & 30 deletions starknet_py/tests/e2e/contract_interaction/deploy_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down
37 changes: 31 additions & 6 deletions starknet_py/tests/e2e/docs/code_examples/test_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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
Expand Down
95 changes: 88 additions & 7 deletions starknet_py/tests/e2e/docs/code_examples/test_contract.py
Original file line number Diff line number Diff line change
@@ -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():
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions starknet_py/tests/e2e/docs/code_examples/test_deployer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
13 changes: 13 additions & 0 deletions starknet_py/tests/e2e/docs/code_examples/test_full_node_client.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down