Skip to content

Commit 78a153c

Browse files
Update docs (#1395)
1 parent 7745c9d commit 78a153c

File tree

8 files changed

+137
-86
lines changed

8 files changed

+137
-86
lines changed

starknet_py/net/full_node_client.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ def __init__(
9797
Client for interacting with Starknet json-rpc interface.
9898
9999
:param node_url: Url of the node providing rpc interface
100-
:param net: Starknet network identifier
101100
:param session: Aiohttp session to be used for request. If not provided, client will create a session for
102101
every request. When using a custom session, user is responsible for closing it manually.
103102
"""

starknet_py/tests/e2e/contract_interaction/declare_test.py

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,8 @@
11
import pytest
22

33
from starknet_py.contract import Contract
4-
from starknet_py.net.models import DeclareV2, DeclareV3
54
from starknet_py.tests.e2e.fixtures.constants import MAX_FEE, MAX_RESOURCE_BOUNDS_L1
6-
from starknet_py.tests.e2e.fixtures.misc import ContractVersion, load_contract
7-
8-
9-
@pytest.mark.asyncio
10-
async def test_contract_declare_v2(account):
11-
compiled_contract = load_contract(
12-
contract_name="TestContract", version=ContractVersion.V1
13-
)
14-
15-
declare_result = await Contract.declare_v2(
16-
account,
17-
compiled_contract=compiled_contract["sierra"],
18-
compiled_contract_casm=compiled_contract["casm"],
19-
max_fee=MAX_FEE,
20-
)
21-
await declare_result.wait_for_acceptance()
22-
23-
assert isinstance(declare_result.declare_transaction, DeclareV2)
24-
assert isinstance(declare_result.hash, int)
25-
assert isinstance(declare_result.class_hash, int)
26-
assert declare_result.compiled_contract == compiled_contract["sierra"]
27-
28-
29-
@pytest.mark.asyncio
30-
async def test_contract_declare_v3(account):
31-
contract = load_contract(contract_name="TestContract", version=ContractVersion.V2)
32-
declare_result = await Contract.declare_v3(
33-
account,
34-
compiled_contract=contract["sierra"],
35-
compiled_contract_casm=contract["casm"],
36-
l1_resource_bounds=MAX_RESOURCE_BOUNDS_L1,
37-
)
38-
await declare_result.wait_for_acceptance()
39-
40-
assert isinstance(declare_result.declare_transaction, DeclareV3)
41-
assert isinstance(declare_result.hash, int)
42-
assert isinstance(declare_result.class_hash, int)
43-
assert declare_result.compiled_contract == contract["sierra"]
5+
from starknet_py.tests.e2e.fixtures.misc import load_contract
446

457

468
@pytest.mark.asyncio

starknet_py/tests/e2e/contract_interaction/deploy_test.py

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
from starknet_py.common import create_sierra_compiled_contract
88
from starknet_py.contract import Contract, DeclareResult
9-
from starknet_py.net.client_models import InvokeTransactionV1, InvokeTransactionV3
9+
from starknet_py.net.client_models import InvokeTransactionV1
1010
from starknet_py.net.models import DeclareV2
1111
from starknet_py.tests.e2e.fixtures.constants import MAX_FEE, MAX_RESOURCE_BOUNDS_L1
1212
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
123123
assert class_hash == cairo1_hello_starknet_class_hash
124124

125125

126-
@pytest.mark.asyncio
127-
async def test_deploy_contract_v3(account, cairo1_hello_starknet_class_hash: int):
128-
compiled_contract = load_contract("HelloStarknet")["sierra"]
129-
abi = create_sierra_compiled_contract(
130-
compiled_contract=compiled_contract
131-
).parsed_abi
132-
133-
deploy_result = await Contract.deploy_contract_v3(
134-
class_hash=cairo1_hello_starknet_class_hash,
135-
account=account,
136-
abi=abi,
137-
l1_resource_bounds=MAX_RESOURCE_BOUNDS_L1,
138-
cairo_version=1,
139-
)
140-
await deploy_result.wait_for_acceptance()
141-
142-
contract = deploy_result.deployed_contract
143-
assert isinstance(contract.address, int)
144-
assert len(contract.functions) != 0
145-
146-
transaction = await account.client.get_transaction(tx_hash=deploy_result.hash)
147-
assert isinstance(transaction, InvokeTransactionV3)
148-
149-
class_hash = await account.client.get_class_hash_at(
150-
contract_address=contract.address
151-
)
152-
assert class_hash == cairo1_hello_starknet_class_hash
153-
154-
155126
@pytest.mark.asyncio
156127
async def test_general_simplified_deployment_flow(account, map_compiled_contract):
157128
declare_result = await Contract.declare_v1(

starknet_py/tests/e2e/docs/code_examples/test_account.py

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from starknet_py.constants import FEE_CONTRACT_ADDRESS
77
from starknet_py.hash.selector import get_selector_from_name
88
from starknet_py.net.account.account import Account
9-
from starknet_py.net.client_models import Call
9+
from starknet_py.net.client_models import Call, ResourceBounds
1010
from starknet_py.net.full_node_client import FullNodeClient
1111
from starknet_py.net.models import StarknetChainId
1212
from starknet_py.net.models.typed_data import TypedDataDict
@@ -25,8 +25,8 @@ def test_init():
2525

2626

2727
@pytest.mark.asyncio
28-
async def test_execute(account, contract_address):
29-
# docs-start: execute
28+
async def test_execute_v1(account, contract_address):
29+
# docs-start: execute_v1
3030
resp = await account.execute_v1(
3131
Call(
3232
to_addr=contract_address,
@@ -36,15 +36,40 @@ async def test_execute(account, contract_address):
3636
max_fee=int(1e15),
3737
)
3838
# or
39-
# docs-end: execute
39+
# docs-end: execute_v1
4040
call1 = call2 = Call(
4141
to_addr=contract_address,
4242
selector=get_selector_from_name("increase_balance"),
4343
calldata=[123],
4444
)
45-
# docs-start: execute
45+
# docs-start: execute_v1
4646
resp = await account.execute_v1(calls=[call1, call2], auto_estimate=True)
47-
# docs-end: execute
47+
# docs-end: execute_v1
48+
49+
50+
@pytest.mark.asyncio
51+
async def test_execute_v3(account, contract_address):
52+
# docs-start: execute_v3
53+
resp = await account.execute_v3(
54+
Call(
55+
to_addr=contract_address,
56+
selector=get_selector_from_name("increase_balance"),
57+
calldata=[123],
58+
),
59+
l1_resource_bounds=ResourceBounds(
60+
max_amount=int(1e5), max_price_per_unit=int(1e13)
61+
),
62+
)
63+
# or
64+
# docs-end: execute_v3
65+
call1 = call2 = Call(
66+
to_addr=contract_address,
67+
selector=get_selector_from_name("increase_balance"),
68+
calldata=[123],
69+
)
70+
# docs-start: execute_v3
71+
resp = await account.execute_v3(calls=[call1, call2], auto_estimate=True)
72+
# docs-end: execute_v3
4873

4974

5075
@pytest.mark.asyncio

starknet_py/tests/e2e/docs/code_examples/test_contract.py

Lines changed: 88 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
# pylint: disable=unused-variable
22
import pytest
33

4+
from starknet_py.common import create_sierra_compiled_contract
45
from starknet_py.contract import Contract
56
from starknet_py.net.account.account import Account
7+
from starknet_py.net.client_models import InvokeTransactionV3, ResourceBounds
68
from starknet_py.net.full_node_client import FullNodeClient
7-
from starknet_py.net.models import StarknetChainId
9+
from starknet_py.net.models import DeclareV2, DeclareV3, StarknetChainId
810
from starknet_py.net.signer.stark_curve_signer import KeyPair
11+
from starknet_py.tests.e2e.fixtures.misc import ContractVersion, load_contract
912

1013

1114
def test_init():
@@ -51,18 +54,62 @@ async def test_from_address(account, contract_address):
5154

5255

5356
@pytest.mark.asyncio
54-
async def test_declare(account, custom_proxy):
57+
async def test_declare_v1(account, custom_proxy):
5558
compiled_contract = custom_proxy
56-
# docs-start: declare
59+
# docs-start: declare_v1
5760
declare_result = await Contract.declare_v1(
5861
account=account, compiled_contract=compiled_contract, max_fee=int(1e15)
5962
)
60-
# docs-end: declare
63+
# docs-end: declare_v1
6164

6265

6366
@pytest.mark.asyncio
64-
async def test_deploy_contract(account, class_hash):
65-
# docs-start: deploy_contract
67+
async def test_declare_v2(account):
68+
compiled_contract = load_contract(
69+
contract_name="TestContract", version=ContractVersion.V1
70+
)
71+
# docs-start: declare_v2
72+
# here `compiled_contract` is a dict containing sierra and casm artifacts
73+
declare_result = await Contract.declare_v2(
74+
account,
75+
compiled_contract=compiled_contract["sierra"],
76+
compiled_contract_casm=compiled_contract["casm"],
77+
max_fee=int(1e15),
78+
)
79+
# docs-end: declare_v2
80+
await declare_result.wait_for_acceptance()
81+
82+
assert isinstance(declare_result.declare_transaction, DeclareV2)
83+
assert isinstance(declare_result.hash, int)
84+
assert isinstance(declare_result.class_hash, int)
85+
assert declare_result.compiled_contract == compiled_contract["sierra"]
86+
87+
88+
@pytest.mark.asyncio
89+
async def test_declare_v3(account):
90+
contract = load_contract(contract_name="TestContract", version=ContractVersion.V2)
91+
# docs-start: declare_v3
92+
# here `contract` is a dict containing sierra and casm artifacts
93+
declare_result = await Contract.declare_v3(
94+
account,
95+
compiled_contract=contract["sierra"],
96+
compiled_contract_casm=contract["casm"],
97+
l1_resource_bounds=ResourceBounds(
98+
max_amount=int(1e5), max_price_per_unit=int(1e13)
99+
),
100+
)
101+
# docs-end: declare_v3
102+
await declare_result.wait_for_acceptance()
103+
104+
assert isinstance(declare_result.declare_transaction, DeclareV3)
105+
assert isinstance(declare_result.hash, int)
106+
assert isinstance(declare_result.class_hash, int)
107+
assert declare_result.compiled_contract == contract["sierra"]
108+
109+
110+
@pytest.mark.asyncio
111+
async def test_deploy_contract_v1(account, class_hash):
112+
# docs-start: deploy_contract_v1
66113
deploy_result = await Contract.deploy_contract_v1(
67114
account=account,
68115
class_hash=class_hash,
@@ -91,7 +138,41 @@ async def test_deploy_contract(account, class_hash):
91138
constructor_args={"value": 1},
92139
max_fee=int(1e15),
93140
)
94-
# docs-end: deploy_contract
141+
# docs-end: deploy_contract_v1
142+
143+
144+
@pytest.mark.asyncio
145+
async def test_deploy_contract_v3(account, cairo1_hello_starknet_class_hash: int):
146+
compiled_contract = load_contract("HelloStarknet")["sierra"]
147+
# docs-start: deploy_contract_v3
148+
abi = create_sierra_compiled_contract(
149+
compiled_contract=compiled_contract
150+
).parsed_abi
151+
# docs-end: deploy_contract_v3
152+
class_hash = cairo1_hello_starknet_class_hash
153+
# docs-start: deploy_contract_v3
154+
deploy_result = await Contract.deploy_contract_v3(
155+
class_hash=class_hash,
156+
account=account,
157+
abi=abi,
158+
l1_resource_bounds=ResourceBounds(
159+
max_amount=int(1e5), max_price_per_unit=int(1e13)
160+
),
161+
)
162+
# docs-end: deploy_contract_v3
163+
await deploy_result.wait_for_acceptance()
164+
165+
contract = deploy_result.deployed_contract
166+
assert isinstance(contract.address, int)
167+
assert len(contract.functions) != 0
168+
169+
transaction = await account.client.get_transaction(tx_hash=deploy_result.hash)
170+
assert isinstance(transaction, InvokeTransactionV3)
171+
172+
class_hash = await account.client.get_class_hash_at(
173+
contract_address=contract.address
174+
)
175+
assert class_hash == cairo1_hello_starknet_class_hash
95176

96177

97178
def test_compute_address(custom_proxy):

starknet_py/tests/e2e/docs/code_examples/test_deployer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ def test_init():
1515
def test_create_contract_deployment_raw():
1616
deployer = Deployer()
1717

18-
# docs-start: create_deployment_call_raw
18+
# docs-start: create_contract_deployment_raw
1919
contract_deployment = deployer.create_contract_deployment_raw(
2020
class_hash=0x123, salt=1, raw_calldata=[3, 1, 2, 3]
2121
)
22-
# docs-end: create_deployment_call_raw
22+
# docs-end: create_contract_deployment_raw

starknet_py/tests/e2e/docs/code_examples/test_full_node_client.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# pylint: disable=unused-variable
22
import pytest
3+
from aiohttp import ClientSession
34

45
from starknet_py.contract import Contract
56
from starknet_py.hash.selector import get_selector_from_name
@@ -14,6 +15,18 @@ def test_init():
1415
# docs-end: init
1516

1617

18+
@pytest.mark.asyncio
19+
async def test_init_with_custom_client_session():
20+
# docs-start: init
21+
# or with custom client session
22+
session = ClientSession()
23+
client = FullNodeClient(node_url="https://your.node.url", session=session)
24+
# perform operations...
25+
# close the session
26+
await session.close()
27+
# docs-end: init
28+
29+
1730
@pytest.mark.asyncio
1831
async def test_get_block(client, block_with_declare_hash):
1932
# docs-start: get_block

starknet_py/tests/e2e/docs/guide/test_deploying_with_udc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ async def test_deploying_with_udc(
1717
salt = None
1818

1919
# docs: start
20-
# If you use mainnet/goerli/sepolia there is no need to explicitly specify
20+
# If you use mainnet/sepolia there is no need to explicitly specify
2121
# address of the deployer (default one will be used)
2222
deployer = Deployer()
2323

0 commit comments

Comments
 (0)