Skip to content

Commit d2d2820

Browse files
Restore auto estimation in tests (#1590) [skip ci]
* Remove todos; Restore multiplier params * Remove changes related with amount multipliers params * Fix linting * Add `InnerCallExecutionResources`; Fix tests * Update migration guide * Update field types in `EstimatedFeeSchema`
1 parent 4acdbdb commit d2d2820

File tree

11 files changed

+84
-106
lines changed

11 files changed

+84
-106
lines changed

docs/migration_guide.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
Migration guide
22
===============
33

4+
**********************
5+
0.26.1 Migration guide
6+
**********************
7+
8+
0.26.1 Bugfixes
9+
---------------
10+
11+
.. py:currentmodule:: starknet_py.net.client_models
12+
13+
1. In :class:`FunctionInvocation`, ``execution_resources`` field is now of type :class:`InnerCallExecutionResources`.
14+
415
**********************
516
0.26.0 Migration guide
617
**********************

starknet_py/net/client_models.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,16 @@ class TransactionFinalityStatus(Enum):
419419
ACCEPTED_ON_L1 = "ACCEPTED_ON_L1"
420420

421421

422+
@dataclass
423+
class InnerCallExecutionResources:
424+
"""
425+
Dataclass representing the resource consumed by an inner call (does not account for state diffs).
426+
"""
427+
428+
l1_gas: int
429+
l2_gas: int
430+
431+
422432
@dataclass
423433
class ExecutionResources:
424434
"""
@@ -1023,7 +1033,7 @@ class FunctionInvocation:
10231033
calls: List["FunctionInvocation"]
10241034
events: List[OrderedEvent]
10251035
messages: List[OrderedMessage]
1026-
execution_resources: ExecutionResources
1036+
execution_resources: InnerCallExecutionResources
10271037
is_reverted: bool
10281038

10291039

starknet_py/net/schemas/rpc/general.py

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,23 @@
11
from marshmallow import fields, post_load
22

3-
from starknet_py.net.client_models import EstimatedFee, ExecutionResources
4-
from starknet_py.net.schemas.common import Felt, PriceUnitField
3+
from starknet_py.net.client_models import (
4+
EstimatedFee,
5+
ExecutionResources,
6+
InnerCallExecutionResources,
7+
)
8+
from starknet_py.net.schemas.common import PriceUnitField, Uint64, Uint128
59
from starknet_py.utils.schema import Schema
610

711

12+
class InnerCallExecutionResourcesSchema(Schema):
13+
l1_gas = fields.Integer(data_key="l1_gas", required=True)
14+
l2_gas = fields.Integer(data_key="l2_gas", required=True)
15+
16+
@post_load
17+
def make_dataclass(self, data, **kwargs) -> InnerCallExecutionResources:
18+
return InnerCallExecutionResources(**data)
19+
20+
821
class ExecutionResourcesSchema(Schema):
922
l1_gas = fields.Integer(data_key="l1_gas", required=True)
1023
l1_data_gas = fields.Integer(data_key="l1_data_gas", required=True)
@@ -16,13 +29,13 @@ def make_dataclass(self, data, **kwargs) -> ExecutionResources:
1629

1730

1831
class EstimatedFeeSchema(Schema):
19-
l1_gas_consumed = Felt(data_key="l1_gas_consumed", required=True)
20-
l1_gas_price = Felt(data_key="l1_gas_price", required=True)
21-
l2_gas_consumed = Felt(data_key="l2_gas_consumed", required=True)
22-
l2_gas_price = Felt(data_key="l2_gas_price", required=True)
23-
l1_data_gas_consumed = Felt(data_key="l1_data_gas_consumed", required=True)
24-
l1_data_gas_price = Felt(data_key="l1_data_gas_price", required=True)
25-
overall_fee = Felt(data_key="overall_fee", required=True)
32+
l1_gas_consumed = Uint64(data_key="l1_gas_consumed", required=True)
33+
l1_gas_price = Uint128(data_key="l1_gas_price", required=True)
34+
l2_gas_consumed = Uint64(data_key="l2_gas_consumed", required=True)
35+
l2_gas_price = Uint128(data_key="l2_gas_price", required=True)
36+
l1_data_gas_consumed = Uint64(data_key="l1_data_gas_consumed", required=True)
37+
l1_data_gas_price = Uint128(data_key="l1_data_gas_price", required=True)
38+
overall_fee = Uint128(data_key="overall_fee", required=True)
2639
unit = PriceUnitField(data_key="unit", required=True)
2740

2841
@post_load

starknet_py/net/schemas/rpc/trace_api.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from starknet_py.net.schemas.rpc.general import (
1919
EstimatedFeeSchema,
2020
ExecutionResourcesSchema,
21+
InnerCallExecutionResourcesSchema,
2122
)
2223
from starknet_py.utils.schema import Schema
2324

@@ -67,7 +68,7 @@ class FunctionInvocationSchema(Schema):
6768
fields.Nested(OrderedMessageSchema()), data_key="messages", required=True
6869
)
6970
execution_resources = fields.Nested(
70-
ExecutionResourcesSchema(),
71+
InnerCallExecutionResourcesSchema(),
7172
data_key="execution_resources",
7273
required=True,
7374
)

starknet_py/tests/e2e/account/account_test.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,6 @@ async def test_sign_invoke_v3(account, calls):
235235

236236

237237
@pytest.mark.asyncio
238-
@pytest.mark.skip("TODO(#1558)")
239238
async def test_sign_invoke_v3_auto_estimate(account, map_contract):
240239
signed_tx = await account.sign_invoke_v3(
241240
Call(map_contract.address, get_selector_from_name("put"), [3, 4]),
@@ -249,9 +248,12 @@ async def test_sign_invoke_v3_auto_estimate(account, map_contract):
249248
assert len(signed_tx.signature) == 2
250249

251250
assert isinstance(signed_tx.resource_bounds, ResourceBoundsMapping)
252-
assert signed_tx.resource_bounds.l1_gas.max_amount > 0
251+
assert signed_tx.resource_bounds.l1_gas.max_amount >= 0
253252
assert signed_tx.resource_bounds.l1_gas.max_price_per_unit > 0
254-
assert signed_tx.resource_bounds.l2_gas == ResourceBounds.init_with_zeros()
253+
assert signed_tx.resource_bounds.l2_gas.max_amount >= 0
254+
assert signed_tx.resource_bounds.l2_gas.max_price_per_unit > 0
255+
assert signed_tx.resource_bounds.l1_data_gas.max_amount >= 0
256+
assert signed_tx.resource_bounds.l1_data_gas.max_price_per_unit > 0
255257

256258

257259
@pytest.mark.asyncio
@@ -278,7 +280,6 @@ async def test_sign_declare_v3(
278280

279281

280282
@pytest.mark.asyncio
281-
@pytest.mark.skip("TODO(#1558)")
282283
async def test_sign_declare_v3_auto_estimate(
283284
account, sierra_minimal_compiled_contract_and_class_hash
284285
):
@@ -298,9 +299,12 @@ async def test_sign_declare_v3_auto_estimate(
298299
assert len(signed_tx.signature) == 2
299300

300301
assert isinstance(signed_tx.resource_bounds, ResourceBoundsMapping)
301-
assert signed_tx.resource_bounds.l1_gas.max_amount > 0
302+
assert signed_tx.resource_bounds.l1_gas.max_amount >= 0
302303
assert signed_tx.resource_bounds.l1_gas.max_price_per_unit > 0
303-
assert signed_tx.resource_bounds.l2_gas == ResourceBounds.init_with_zeros()
304+
assert signed_tx.resource_bounds.l2_gas.max_amount >= 0
305+
assert signed_tx.resource_bounds.l2_gas.max_price_per_unit > 0
306+
assert signed_tx.resource_bounds.l1_data_gas.max_amount >= 0
307+
assert signed_tx.resource_bounds.l1_data_gas.max_price_per_unit > 0
304308

305309

306310
@pytest.mark.asyncio
@@ -328,7 +332,6 @@ async def test_sign_deploy_account_v3(account):
328332

329333

330334
@pytest.mark.asyncio
331-
@pytest.mark.skip("TODO(#1558)")
332335
async def test_sign_deploy_account_v3_auto_estimate(
333336
account, account_with_validate_deploy_class_hash
334337
):
@@ -346,9 +349,12 @@ async def test_sign_deploy_account_v3_auto_estimate(
346349
assert len(signed_tx.signature) == 2
347350

348351
assert isinstance(signed_tx.resource_bounds, ResourceBoundsMapping)
349-
assert signed_tx.resource_bounds.l1_gas.max_amount > 0
352+
assert signed_tx.resource_bounds.l1_gas.max_amount >= 0
350353
assert signed_tx.resource_bounds.l1_gas.max_price_per_unit > 0
351-
assert signed_tx.resource_bounds.l2_gas == ResourceBounds.init_with_zeros()
354+
assert signed_tx.resource_bounds.l2_gas.max_amount >= 0
355+
assert signed_tx.resource_bounds.l2_gas.max_price_per_unit > 0
356+
assert signed_tx.resource_bounds.l1_data_gas.max_amount >= 0
357+
assert signed_tx.resource_bounds.l1_data_gas.max_price_per_unit > 0
352358

353359

354360
@pytest.mark.asyncio

starknet_py/tests/e2e/cairo1v2_test.py

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,11 @@ async def declare_deploy_hello2(account) -> Tuple[DeclareResult, DeployResult]:
2121
account=account,
2222
compiled_contract=contract["sierra"],
2323
compiled_contract_casm=contract["casm"],
24-
# TODO(#1558): Use auto estimation
25-
resource_bounds=MAX_RESOURCE_BOUNDS,
24+
auto_estimate=True,
2625
)
2726
await declare_result.wait_for_acceptance()
2827

29-
deploy_result = await declare_result.deploy_v3(
30-
# TODO(#1558): Use auto estimation
31-
resource_bounds=MAX_RESOURCE_BOUNDS,
32-
)
28+
deploy_result = await declare_result.deploy_v3(auto_estimate=True)
3329
await deploy_result.wait_for_acceptance()
3430

3531
return declare_result, deploy_result
@@ -49,13 +45,11 @@ async def test_deploy_cairo2(contract):
4945

5046
@pytest.mark.asyncio
5147
async def test_cairo2_interaction(contract):
52-
# TODO(#1558): Use auto estimation
5348
invoke_res = await contract.functions["increase_balance"].invoke_v3(
54-
amount=100, resource_bounds=MAX_RESOURCE_BOUNDS
49+
amount=100, auto_estimate=True
5550
)
5651
await invoke_res.wait_for_acceptance()
5752

58-
# TODO (#1558): Use auto estimation
5953
invoke_res = await contract.functions["increase_balance"].invoke_v3(
6054
amount=100, resource_bounds=MAX_RESOURCE_BOUNDS
6155
)
@@ -67,9 +61,8 @@ async def test_cairo2_interaction(contract):
6761

6862
@pytest.mark.asyncio
6963
async def test_cairo2_interaction2(contract):
70-
# TODO (#1558): Use auto estimation
7164
invoke_res = await contract.functions["increase_balance_u8"].invoke_v3(
72-
255, resource_bounds=MAX_RESOURCE_BOUNDS
65+
255, auto_estimate=True
7366
)
7467
await invoke_res.wait_for_acceptance()
7568

@@ -97,9 +90,8 @@ async def test_cairo2_u256(contract):
9790

9891
@pytest.mark.asyncio
9992
async def test_cairo2_contract_address(contract):
100-
# TODO (#1558): Use auto estimation
10193
invoke_res = await contract.functions["set_ca"].invoke_v3(
102-
address=contract.account.address, resource_bounds=MAX_RESOURCE_BOUNDS
94+
address=contract.account.address, auto_estimate=True
10395
)
10496
await invoke_res.wait_for_acceptance()
10597

@@ -109,29 +101,26 @@ async def test_cairo2_contract_address(contract):
109101

110102
@pytest.mark.asyncio
111103
async def test_cairo2_interaction3(contract):
112-
# TODO (#1558): Use auto estimation
113104
invoke_res = await contract.functions["increase_balance"].invoke_v3(
114-
100, resource_bounds=MAX_RESOURCE_BOUNDS
105+
100, auto_estimate=True
115106
)
116107
await invoke_res.wait_for_acceptance()
117108
(balance,) = await contract.functions["get_balance"].call()
118109
key = get_storage_var_address("balance")
119110
storage = await contract.client.get_storage_at(contract.address, key)
120111
assert storage == balance
121112

122-
# TODO (#1558): Use auto estimation
123113
invoke_res = await contract.functions["set_ca"].invoke_v3(
124-
contract.account.address, resource_bounds=MAX_RESOURCE_BOUNDS
114+
contract.account.address, auto_estimate=True
125115
)
126116
await invoke_res.wait_for_acceptance()
127117
(ca,) = await contract.functions["get_ca"].call() # pylint: disable=invalid-name
128118
key = get_storage_var_address("ca")
129119
storage = await contract.client.get_storage_at(contract.address, key)
130120
assert storage == ca
131121

132-
# TODO (#1558): Use auto estimation
133122
invoke_res = await contract.functions["set_status"].invoke_v3(
134-
True, resource_bounds=MAX_RESOURCE_BOUNDS
123+
True, auto_estimate=True
135124
)
136125
await invoke_res.wait_for_acceptance()
137126
(status,) = await contract.functions["get_status"].call()
@@ -144,8 +133,7 @@ async def test_cairo2_interaction3(contract):
144133
"address": contract.account.address,
145134
"is_claimed": True,
146135
},
147-
# TODO (#1558): Use auto estimation
148-
resource_bounds=MAX_RESOURCE_BOUNDS,
136+
auto_estimate=True,
149137
)
150138
await invoke_res.wait_for_acceptance()
151139
(user1,) = await contract.functions["get_user1"].call()
@@ -178,10 +166,7 @@ async def test_cairo2_echo_struct(contract):
178166

179167
@pytest.mark.asyncio
180168
async def test_cairo2_echo_complex_struct(contract):
181-
# TODO (#1558): Use auto estimation
182-
invoke_result = await contract.functions["set_bet"].invoke_v3(
183-
resource_bounds=MAX_RESOURCE_BOUNDS
184-
)
169+
invoke_result = await contract.functions["set_bet"].invoke_v3(auto_estimate=True)
185170
await invoke_result.wait_for_acceptance()
186171

187172
(bet,) = await contract.functions["get_bet"].call(1)

0 commit comments

Comments
 (0)