|
1 | 1 | # pylint: disable=unused-variable |
2 | 2 | import pytest |
3 | 3 |
|
| 4 | +from starknet_py.common import create_sierra_compiled_contract |
4 | 5 | from starknet_py.contract import Contract |
5 | 6 | from starknet_py.net.account.account import Account |
| 7 | +from starknet_py.net.client_models import InvokeTransactionV3, ResourceBounds |
6 | 8 | 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 |
8 | 10 | from starknet_py.net.signer.stark_curve_signer import KeyPair |
| 11 | +from starknet_py.tests.e2e.fixtures.misc import ContractVersion, load_contract |
9 | 12 |
|
10 | 13 |
|
11 | 14 | def test_init(): |
@@ -51,18 +54,62 @@ async def test_from_address(account, contract_address): |
51 | 54 |
|
52 | 55 |
|
53 | 56 | @pytest.mark.asyncio |
54 | | -async def test_declare(account, custom_proxy): |
| 57 | +async def test_declare_v1(account, custom_proxy): |
55 | 58 | compiled_contract = custom_proxy |
56 | | - # docs-start: declare |
| 59 | + # docs-start: declare_v1 |
57 | 60 | declare_result = await Contract.declare_v1( |
58 | 61 | account=account, compiled_contract=compiled_contract, max_fee=int(1e15) |
59 | 62 | ) |
60 | | - # docs-end: declare |
| 63 | + # docs-end: declare_v1 |
61 | 64 |
|
62 | 65 |
|
63 | 66 | @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 |
66 | 113 | deploy_result = await Contract.deploy_contract_v1( |
67 | 114 | account=account, |
68 | 115 | class_hash=class_hash, |
@@ -91,7 +138,41 @@ async def test_deploy_contract(account, class_hash): |
91 | 138 | constructor_args={"value": 1}, |
92 | 139 | max_fee=int(1e15), |
93 | 140 | ) |
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 |
95 | 176 |
|
96 | 177 |
|
97 | 178 | def test_compute_address(custom_proxy): |
|
0 commit comments