Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 3 additions & 3 deletions docs/migration_guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Version 0.18.3 of **starknet.py** comes with support for RPC 0.5.0!
------------------------

- Starknet - `0.12.2 <https://community.starknet.io/t/introducing-p2p-authentication-and-mismatch-resolution-in-v0-12-2/97993>`_
- RPC - `0.5.0 <https://github.com/starkware-libs/starknet-specs/releases/tag/v0.5.0>`_
- RPC - `0.5.1 <https://github.com/starkware-libs/starknet-specs/releases/tag/v0.5.1>`_


0.18.3 Breaking changes
Expand All @@ -36,8 +36,8 @@ Version 0.18.3 of **starknet.py** comes with support for RPC 0.5.0!
1. :class:`StarknetBlock`, :class:`StarknetBlockWithTxHashes`, :class:`PendingStarknetBlock` and :class:`PendingStarknetBlockWithTxHashes` now have two additional fields: ``starknet_version`` and ``l1_gas_price``.
2. :class:`PendingStarknetBlock` and :class:`PendingStarknetBlockWithTxHashes` fields ``timestamp``, ``sequencer_address`` and ``parent_block_hash`` are now required, not optional.
3. :class:`TransactionReceipt` now has an additional field - ``message_hash`` (for ``L1_HANDLER_TXN_RECEIPT``).
4. All optional fields in ``TransactionTrace`` classes are now required.
5. :class:`InvokeTransactionTrace`, :class:`DeclareTransactionTrace` and :class:`DeployAccountTransactionTrace` classes now have an additional field - ``state_diff``.
4. Most fields in ``TransactionTrace`` classes are now optional.
5. :class:`InvokeTransactionTrace`, :class:`DeclareTransactionTrace`, :class:`DeployAccountTransactionTrace` and :class:`L1HandlerTransactionTrace` classes now have an additional field - ``state_diff``.


|
Expand Down
12 changes: 12 additions & 0 deletions starknet_py/hash/address.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@ def compute_address(


def get_checksum_address(address: str) -> str:
"""
Outputs formatted checksum address.

Follows implementation of starknet.js. It is not compatible with EIP55 as it treats hex string as encoded number,
instead of encoding it as ASCII string.

:param address: Address to encode
:return: Checksum address
"""
if not address.lower().startswith(HEX_PREFIX):
raise ValueError(f"{address} is not a valid hexadecimal address.")

Expand All @@ -64,4 +73,7 @@ def get_checksum_address(address: str) -> str:


def is_checksum_address(address: str) -> bool:
"""
Checks if provided string is in a checksum address format.
"""
return get_checksum_address(address) == address
20 changes: 11 additions & 9 deletions starknet_py/net/client_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -842,6 +842,7 @@ class CallType(Enum):
Enum class representing call types.
"""

DELEGATE = "DELEGATE"
LIBRARY_CALL = "LIBRARY_CALL"
CALL = "CALL"

Expand Down Expand Up @@ -881,10 +882,10 @@ class InvokeTransactionTrace:
Dataclass representing a transaction trace of an INVOKE transaction.
"""

validate_invocation: FunctionInvocation
execute_invocation: Union[FunctionInvocation, RevertedFunctionInvocation]
fee_transfer_invocation: FunctionInvocation
state_diff: StateDiff
validate_invocation: Optional[FunctionInvocation] = None
fee_transfer_invocation: Optional[FunctionInvocation] = None
state_diff: Optional[StateDiff] = None


@dataclass
Expand All @@ -893,9 +894,9 @@ class DeclareTransactionTrace:
Dataclass representing a transaction trace of an DECLARE transaction.
"""

validate_invocation: FunctionInvocation
fee_transfer_invocation: FunctionInvocation
state_diff: StateDiff
validate_invocation: Optional[FunctionInvocation] = None
fee_transfer_invocation: Optional[FunctionInvocation] = None
state_diff: Optional[StateDiff] = None


@dataclass
Expand All @@ -904,10 +905,10 @@ class DeployAccountTransactionTrace:
Dataclass representing a transaction trace of an DEPLOY_ACCOUNT transaction.
"""

validate_invocation: FunctionInvocation
constructor_invocation: FunctionInvocation
fee_transfer_invocation: FunctionInvocation
state_diff: StateDiff
validate_invocation: Optional[FunctionInvocation] = None
fee_transfer_invocation: Optional[FunctionInvocation] = None
state_diff: Optional[StateDiff] = None


@dataclass
Expand All @@ -917,6 +918,7 @@ class L1HandlerTransactionTrace:
"""

function_invocation: FunctionInvocation
state_diff: Optional[StateDiff] = None


TransactionTrace = Union[
Expand Down
4 changes: 4 additions & 0 deletions starknet_py/net/full_node_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,10 @@ async def get_transaction(
return cast(Transaction, TypesOfTransactionsSchema().load(res, unknown=EXCLUDE))

async def get_l1_message_hash(self, tx_hash: Hash) -> Hash:
"""
:param tx_hash: Transaction's hash
:return: Message hash
"""
tx = await self.get_transaction(tx_hash)
if not isinstance(tx, L1HandlerTransaction):
raise TypeError(
Expand Down
27 changes: 18 additions & 9 deletions starknet_py/net/schemas/rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -667,18 +667,20 @@ def get_data_type(self, data):


class InvokeTransactionTraceSchema(Schema):
validate_invocation = fields.Nested(
FunctionInvocationSchema(), data_key="validate_invocation", load_default=None
)
execute_invocation = fields.Nested(
ExecuteInvocationSchema(), data_key="execute_invocation", required=True
)
validate_invocation = fields.Nested(
FunctionInvocationSchema(), data_key="validate_invocation", load_default=None
)
fee_transfer_invocation = fields.Nested(
FunctionInvocationSchema(),
data_key="fee_transfer_invocation",
load_default=None,
)
state_diff = fields.Nested(StateDiffSchema(), data_key="state_diff", required=True)
state_diff = fields.Nested(
StateDiffSchema(), data_key="state_diff", load_default=None
)

@post_load
def make_dataclass(self, data, **kwargs) -> InvokeTransactionTrace:
Expand All @@ -694,26 +696,30 @@ class DeclareTransactionTraceSchema(Schema):
data_key="fee_transfer_invocation",
load_default=None,
)
state_diff = fields.Nested(StateDiffSchema(), data_key="state_diff", required=True)
state_diff = fields.Nested(
StateDiffSchema(), data_key="state_diff", load_default=None
)

@post_load
def make_dataclass(self, data, **kwargs) -> DeclareTransactionTrace:
return DeclareTransactionTrace(**data)


class DeployAccountTransactionTraceSchema(Schema):
validate_invocation = fields.Nested(
FunctionInvocationSchema(), data_key="validate_invocation", load_default=None
)
constructor_invocation = fields.Nested(
FunctionInvocationSchema(), data_key="constructor_invocation", required=True
)
validate_invocation = fields.Nested(
FunctionInvocationSchema(), data_key="validate_invocation", load_default=None
)
fee_transfer_invocation = fields.Nested(
FunctionInvocationSchema(),
data_key="fee_transfer_invocation",
load_default=None,
)
state_diff = fields.Nested(StateDiffSchema(), data_key="state_diff", required=True)
state_diff = fields.Nested(
StateDiffSchema(), data_key="state_diff", load_default=None
)

@post_load
def make_dataclass(self, data, **kwargs) -> DeployAccountTransactionTrace:
Expand All @@ -724,6 +730,9 @@ class L1HandlerTransactionTraceSchema(Schema):
function_invocation = fields.Nested(
FunctionInvocationSchema(), data_key="function_invocation", required=True
)
state_diff = fields.Nested(
StateDiffSchema(), data_key="state_diff", load_default=None
)

@post_load
def make_dataclass(self, data, **kwargs) -> L1HandlerTransactionTrace:
Expand Down
15 changes: 7 additions & 8 deletions starknet_py/tests/e2e/tests_on_networks/trace_api_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,16 @@ async def test_trace_transaction_invoke(full_node_client_testnet):
invoke_tx_hash = 0xDC6B381884866DD6C4ACCDE75AA1FA7506E6B57612D3D3659F7B919EA07D7C
trace = await full_node_client_testnet.trace_transaction(tx_hash=invoke_tx_hash)

assert type(trace) == InvokeTransactionTrace
assert trace.state_diff is not None
assert type(trace) is InvokeTransactionTrace
assert trace.execute_invocation is not None


@pytest.mark.asyncio
async def test_trace_transaction_declare(full_node_client_testnet):
declare_tx_hash = 0x62DD22627065568C6E4BD619C511217456B5A82ACBDEAD7C3B5DFFF92209451
trace = await full_node_client_testnet.trace_transaction(tx_hash=declare_tx_hash)

assert type(trace) == DeclareTransactionTrace
assert trace.state_diff is not None
assert type(trace) is DeclareTransactionTrace


@pytest.mark.asyncio
Expand All @@ -70,8 +69,8 @@ async def test_trace_transaction_deploy_account(full_node_client_testnet):
tx_hash=deploy_account_tx_hash
)

assert type(trace) == DeployAccountTransactionTrace
assert trace.state_diff is not None
assert type(trace) is DeployAccountTransactionTrace
assert trace.constructor_invocation is not None


@pytest.mark.asyncio
Expand All @@ -81,7 +80,8 @@ async def test_trace_transaction_l1_handler(full_node_client_testnet):
)
trace = await full_node_client_testnet.trace_transaction(tx_hash=l1_handler_tx_hash)

assert type(trace) == L1HandlerTransactionTrace
assert type(trace) is L1HandlerTransactionTrace
assert trace.function_invocation is not None


@pytest.mark.asyncio
Expand Down Expand Up @@ -135,4 +135,3 @@ async def test_simulate_transactions_declare_on_network(

assert isinstance(simulated_txs[0].transaction_trace, DeclareTransactionTrace)
assert simulated_txs[0].fee_estimation.overall_fee > 0
assert simulated_txs[0].transaction_trace.validate_invocation is not None