Skip to content

Commit

Permalink
Apply other code review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
franciszekjob committed Jan 24, 2025
1 parent 6590944 commit 605b2b3
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 56 deletions.
2 changes: 1 addition & 1 deletion starknet_py/net/client_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1223,7 +1223,7 @@ class StorageProofResponse:
@dataclass
class MessageStatus:
transaction_hash: int
finality_status: TransactionFinalityStatus
finality_status: TransactionStatus
failure_reason: Optional[str] = None


Expand Down
2 changes: 1 addition & 1 deletion starknet_py/net/schemas/rpc/transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ def make_dataclass(self, data, **kwargs) -> DeployAccountTransactionResponse:

class MessageStatusSchema(Schema):
transaction_hash = NumberAsHex(data_key="transaction_hash", required=True)
finality_status = FinalityStatusField(data_key="finality_status", required=True)
finality_status = StatusField(data_key="finality_status", required=True)
failure_reason = fields.String(data_key="failure_reason", load_default=None)

@post_load
Expand Down
80 changes: 33 additions & 47 deletions starknet_py/tests/e2e/client/client_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# pylint: disable=too-many-arguments
import dataclasses
from unittest.mock import AsyncMock, Mock, patch

import pytest
Expand Down Expand Up @@ -154,17 +155,14 @@ async def test_estimate_fee_invoke(account, contract_address):
max_fee=MAX_FEE,
)
invoke_tx = await account.sign_for_fee_estimate(invoke_tx)
estimate_fee = await account.client.estimate_fee(tx=invoke_tx)
estimated_fee = await account.client.estimate_fee(tx=invoke_tx)

assert isinstance(estimate_fee, EstimatedFee)
assert estimate_fee.unit == PriceUnit.WEI
assert estimate_fee.overall_fee > 0
assert estimate_fee.l1_gas_price > 0
assert estimate_fee.l1_gas_consumed > 0
assert estimate_fee.l2_gas_price > 0
assert estimate_fee.l2_gas_consumed > 0
assert estimate_fee.l1_data_gas_price > 0
assert estimate_fee.l1_data_gas_consumed > 0
assert isinstance(estimated_fee, EstimatedFee)
assert estimated_fee.unit == PriceUnit.WEI
assert all(
getattr(estimated_fee, field.name) > 0
for field in dataclasses.fields(EstimatedFee)
)


@pytest.mark.asyncio
Expand All @@ -178,17 +176,14 @@ async def test_estimate_fee_invoke_v3(account, contract_address):
resource_bounds=ResourceBoundsMapping.init_with_zeros(),
)
invoke_tx = await account.sign_for_fee_estimate(invoke_tx)
estimate_fee = await account.client.estimate_fee(tx=invoke_tx)
estimated_fee = await account.client.estimate_fee(tx=invoke_tx)

assert isinstance(estimate_fee, EstimatedFee)
assert estimate_fee.unit == PriceUnit.FRI
assert estimate_fee.overall_fee > 0
assert estimate_fee.l1_gas_price > 0
assert estimate_fee.l1_gas_consumed > 0
assert estimate_fee.l2_gas_price > 0
assert estimate_fee.l2_gas_consumed > 0
assert estimate_fee.l1_data_gas_price > 0
assert estimate_fee.l1_data_gas_consumed > 0
assert isinstance(estimated_fee, EstimatedFee)
assert estimated_fee.unit == PriceUnit.FRI
assert all(
getattr(estimated_fee, field.name) > 0
for field in dataclasses.fields(EstimatedFee)
)


@pytest.mark.asyncio
Expand All @@ -202,32 +197,26 @@ async def test_estimate_fee_declare(
)

declare_tx = await account.sign_for_fee_estimate(declare_tx)
estimate_fee = await account.client.estimate_fee(tx=declare_tx)
estimated_fee = await account.client.estimate_fee(tx=declare_tx)

assert isinstance(estimate_fee, EstimatedFee)
assert estimate_fee.unit == PriceUnit.WEI
assert estimate_fee.overall_fee > 0
assert estimate_fee.l1_gas_price > 0
assert estimate_fee.l1_gas_consumed > 0
assert estimate_fee.l2_gas_price > 0
assert estimate_fee.l2_gas_consumed > 0
assert estimate_fee.l1_data_gas_price > 0
assert estimate_fee.l1_data_gas_consumed > 0
assert isinstance(estimated_fee, EstimatedFee)
assert estimated_fee.unit == PriceUnit.WEI
assert all(
getattr(estimated_fee, field.name) > 0
for field in dataclasses.fields(EstimatedFee)
)


@pytest.mark.asyncio
async def test_estimate_fee_deploy_account(client, deploy_account_transaction):
estimate_fee = await client.estimate_fee(tx=deploy_account_transaction)
estimated_fee = await client.estimate_fee(tx=deploy_account_transaction)

assert isinstance(estimate_fee, EstimatedFee)
assert estimate_fee.unit == PriceUnit.WEI
assert estimate_fee.overall_fee > 0
assert estimate_fee.l1_gas_price > 0
assert estimate_fee.l1_gas_consumed > 0
assert estimate_fee.l2_gas_price > 0
assert estimate_fee.l2_gas_consumed > 0
assert estimate_fee.l1_data_gas_price > 0
assert estimate_fee.l1_data_gas_consumed >= 0
assert isinstance(estimated_fee, EstimatedFee)
assert estimated_fee.unit == PriceUnit.WEI
assert all(
getattr(estimated_fee, field.name) > 0
for field in dataclasses.fields(EstimatedFee)
)


@pytest.mark.asyncio
Expand All @@ -253,13 +242,10 @@ async def test_estimate_fee_for_multiple_transactions(
for estimated_fee in estimated_fees:
assert isinstance(estimated_fee, EstimatedFee)
assert estimated_fee.unit == PriceUnit.WEI
assert estimated_fee.overall_fee > 0
assert estimated_fee.l1_gas_price > 0
assert estimated_fee.l1_gas_consumed > 0
assert estimated_fee.l2_gas_price > 0
assert estimated_fee.l2_gas_consumed > 0
assert estimated_fee.l1_data_gas_price > 0
assert estimated_fee.l1_data_gas_consumed > 0
assert all(
getattr(estimated_fee, field.name) > 0
for field in dataclasses.fields(EstimatedFee)
)


@pytest.mark.asyncio
Expand Down
11 changes: 4 additions & 7 deletions starknet_py/tests/e2e/tests_on_networks/client_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,13 +177,10 @@ async def test_estimate_message_fee(client_sepolia_testnet):
)

assert isinstance(estimated_message, EstimatedFee)
assert estimated_message.overall_fee > 0
assert estimated_message.l1_gas_price > 0
assert estimated_message.l1_gas_consumed > 0
assert estimated_message.l2_gas_price > 0
assert estimated_message.l2_gas_consumed > 0
assert estimated_message.l1_data_gas_price > 0
assert estimated_message.l1_data_gas_consumed >= 0
assert all(
getattr(estimated_message, field.name) > 0
for field in dataclasses.fields(EstimatedFee)
)
assert estimated_message.unit is not None


Expand Down

0 comments on commit 605b2b3

Please sign in to comment.