Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
fa422af
add new gateway methods
tomek0123456789 Aug 17, 2023
0c95240
changed get_state_update to match new implementation
tomek0123456789 Aug 17, 2023
cb6ce02
changed non prefixed hexes to felts
tomek0123456789 Aug 17, 2023
84184fa
update migration guide
tomek0123456789 Aug 18, 2023
bb4d34d
update migration guide
tomek0123456789 Aug 18, 2023
11b85fc
mark tests with non-prefixed hex running on devnet and testnet with `…
tomek0123456789 Aug 18, 2023
5c6bf4b
more tests marked as `xfail`
tomek0123456789 Aug 18, 2023
87901dc
more tests marked as `xfail`
tomek0123456789 Aug 18, 2023
18cd9e9
remove condition in docs `xfail` tests
tomek0123456789 Aug 18, 2023
938c683
lint
tomek0123456789 Aug 18, 2023
8382c37
review changes
tomek0123456789 Aug 21, 2023
2e21d43
add docs info
tomek0123456789 Aug 21, 2023
2de046b
change str() to cast() in get_public_key
tomek0123456789 Aug 21, 2023
ae69912
lint
tomek0123456789 Aug 21, 2023
51bf676
fighting with codecov vol. 1
tomek0123456789 Aug 21, 2023
dd758ff
fix poetry version to 1.5.1
tomek0123456789 Aug 21, 2023
d1652e9
fix #1155
tomek0123456789 Aug 21, 2023
ae1f0ba
lint
tomek0123456789 Aug 21, 2023
e77b938
fight with codecov vol. 2
tomek0123456789 Aug 21, 2023
a772e65
Merge branch 'development' of https://github.com/software-mansion/sta…
tomek0123456789 Aug 21, 2023
be63fae
i hate codecov
tomek0123456789 Aug 21, 2023
1e613da
fix docs
tomek0123456789 Aug 22, 2023
dcc3bd0
add docstrings
tomek0123456789 Aug 22, 2023
9f106b2
another docs fix
tomek0123456789 Aug 22, 2023
0a2f94b
fix #1159
tomek0123456789 Aug 22, 2023
3a58af5
i hate codecov vol.2
tomek0123456789 Aug 22, 2023
c106bd6
i hate codecov vol. 3
tomek0123456789 Aug 22, 2023
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
2 changes: 1 addition & 1 deletion .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- name: Install poetry
run: |
python -m pip install --upgrade pip
pip install poetry==1.5.1
pip install poetry
poetry config installer.modern-installation false

- name: Set up Python 3.9
Expand Down
12 changes: 9 additions & 3 deletions docs/migration_guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Migration guide
0.18.0 Migration guide
**********************

This version of starknet.py brings support Starknet 0.12.1 and `RPC v0.4.0 <https://github.com/starkware-libs/starknet-specs/releases/tag/v0.4.0>`!
This version of starknet.py brings support Starknet 0.12.1, 0.12.2 and `RPC v0.4.0 <https://github.com/starkware-libs/starknet-specs/releases/tag/v0.4.0>`_!


1. :class:`TransactionReceipt` dataclass properties have been changed (more details in RPC specification linked above).
Expand Down Expand Up @@ -33,7 +33,7 @@ This version of starknet.py brings support Starknet 0.12.1 and `RPC v0.4.0 <http

.. currentmodule:: starknet_py.net.client

5. Lowered ``check_interval`` parameter default value in :meth:``Client.wait_for_tx`` from 5 seconds to 2.
5. Lowered ``check_interval`` parameter default value in :meth:`Client.wait_for_tx` from 5 seconds to 2.

.. currentmodule:: starknet_py.net.client_models

Expand All @@ -43,9 +43,15 @@ This version of starknet.py brings support Starknet 0.12.1 and `RPC v0.4.0 <http

7. :func:`decode_shortstring` now is returned without ``\x00`` in front of the decoded string.

.. currentmodule:: starknet_py.net.gateway_client

8. Added two new methods to :class:`GatewayClient` - :meth:`GatewayClient.get_public_key` and :meth:`GatewayClient.get_signature`.
9. :meth:`GatewayClient.get_state_update` now accepts additional parameter - `include_block`.

.. currentmodule:: starknet_py.net.signer.stark_curve_signer

8. :class:`KeyPair` and :meth:`KeyPair.from_private_key` now can accept keys in string representation.
10. :class:`KeyPair` and :meth:`KeyPair.from_private_key` now can accept keys in string representation.


0.18.0 Bugfixes
---------------
Expand Down
6 changes: 6 additions & 0 deletions starknet_py/net/account/account_test.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import sys
from unittest.mock import AsyncMock, patch

import pytest
Expand Down Expand Up @@ -49,6 +50,11 @@ async def test_get_balance_default_token_address(net, call_contract):
assert call.to_addr == parse_address(FEE_CONTRACT_ADDRESS)


# TODO (#1154): remove line below
@pytest.mark.xfail(
"--client=gateway" in sys.argv,
reason="0.12.2 returns Felts in state_root, devnet returns NonPrefixedHex",
)
@pytest.mark.asyncio
async def test_account_get_balance(account, map_contract):
balance = await account.get_balance()
Expand Down
31 changes: 31 additions & 0 deletions starknet_py/net/client_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,16 @@ class PendingBlockStateUpdate:
state_diff: StateDiff


@dataclass
class StateUpdateWithBlock:
"""
Dataclass representing a change in state of a block with the block.
"""

block: GatewayBlock
state_update: BlockStateUpdate


@dataclass
class ContractCode:
"""
Expand Down Expand Up @@ -671,3 +681,24 @@ class TransactionStatusResponse:
transaction_status: TransactionStatus
finality_status: Optional[TransactionFinalityStatus] = None
execution_status: Optional[TransactionExecutionStatus] = None


@dataclass
class SignatureInput:
"""
Dataclass representing a signature input.
"""

block_hash: int
state_diff_commitment: int


@dataclass
class SignatureOnStateDiff:
"""
Dataclass representing signature on state diff commitment and block hash.
"""

block_number: int
signature: List[int]
signature_input: SignatureInput
66 changes: 59 additions & 7 deletions starknet_py/net/gateway_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
Hash,
SentTransactionResponse,
SierraContractClass,
SignatureOnStateDiff,
StateUpdateWithBlock,
Tag,
Transaction,
TransactionReceipt,
Expand Down Expand Up @@ -49,7 +51,9 @@
DeployAccountTransactionResponseSchema,
EstimatedFeeSchema,
SentTransactionSchema,
SignatureOnStateDiffSchema,
StarknetBlockSchema,
StateUpdateWithBlockSchema,
TransactionReceiptSchema,
TransactionStatusSchema,
TypesOfContractClassSchema,
Expand Down Expand Up @@ -143,21 +147,33 @@ async def get_state_update(
self,
block_hash: Optional[Union[Hash, Tag]] = None,
block_number: Optional[Union[int, Tag]] = None,
) -> BlockStateUpdate:
include_block: bool = False,
) -> Union[BlockStateUpdate, StateUpdateWithBlock]:
"""
Get the information about the result of executing the requested block
Get the information about the result of executing the requested block.

:param block_hash: Block's hash
:param block_number: Block's number (default "pending")
:return: BlockStateUpdate object representing changes in the requested block
:param block_hash: Block's hash.
:param block_number: Block's number (default "pending").
:param include_block: Flag deciding whether to include the queried block. Defaults to false.
:return: BlockStateUpdate object representing changes in the requested block.
"""
block_identifier = get_block_identifier(
block_hash=block_hash, block_number=block_number
)

params = {
"includeBlock": str(include_block).lower(),
**block_identifier,
}

res = await self._feeder_gateway_client.call(
method_name="get_state_update",
params=block_identifier,
method_name="get_state_update", params=params
)

if include_block:
return StateUpdateWithBlockSchema().load(
res, unknown=EXCLUDE
) # pyright: ignore
return BlockStateUpdateSchema().load(res, unknown=EXCLUDE) # pyright: ignore

async def get_storage_at(
Expand Down Expand Up @@ -461,6 +477,42 @@ async def get_full_contract(
res, unknown=EXCLUDE
) # pyright: ignore

async def get_signature(
self,
block_hash: Optional[Union[Hash, Tag]] = None,
block_number: Optional[Union[int, Tag]] = None,
) -> SignatureOnStateDiff:
"""
Information on what is this signature and how it is calulated here:
https://community.starknet.io/t/introducing-p2p-authentication-and-mismatch-resolution-in-v0-12-2/97993#signature-on-state-diff-commitment-and-block-hash-3

:param block_hash: Block's hash or literals `"pending"` or `"latest"`.
:param block_number: Block's number or literals `"pending"` or `"latest"`.

:return: Signature on state diff.
"""
block_identifier = get_block_identifier(
block_hash=block_hash, block_number=block_number
)
res = await self._feeder_gateway_client.call(
method_name="get_signature",
params={**block_identifier},
)
return SignatureOnStateDiffSchema().load(
res, unknown=EXCLUDE
) # pyright: ignore

async def get_public_key(self) -> str:
"""
Method returning current public key.

:return: Public key.
"""
public_key = await self._feeder_gateway_client.call(
method_name="get_public_key"
)
return cast(str, public_key)


def get_block_identifier(
block_hash: Optional[Union[Hash, Tag]] = None,
Expand Down
41 changes: 38 additions & 3 deletions starknet_py/net/schemas/gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
SierraContractClass,
SierraEntryPoint,
SierraEntryPointsByType,
SignatureInput,
SignatureOnStateDiff,
StateUpdateWithBlock,
StorageDiffItem,
TransactionReceipt,
TransactionStatusResponse,
Expand Down Expand Up @@ -258,7 +261,7 @@ class StarknetBlockSchema(Schema):
parent_block_hash = Felt(data_key="parent_block_hash", required=True)
block_number = fields.Integer(data_key="block_number")
status = BlockStatusField(data_key="status", required=True)
root = NonPrefixedHex(data_key="state_root")
root = Felt(data_key="state_root")
transactions = fields.List(
fields.Nested(TypesOfTransactionsSchema(unknown=EXCLUDE)),
data_key="transactions",
Expand Down Expand Up @@ -420,8 +423,8 @@ def make_dataclass(self, data, **kwargs) -> GatewayStateDiff:

class BlockStateUpdateSchema(Schema):
block_hash = Felt(data_key="block_hash", required=True)
new_root = NonPrefixedHex(data_key="new_root", required=True)
old_root = NonPrefixedHex(data_key="old_root", required=True)
new_root = Felt(data_key="new_root", required=True)
old_root = Felt(data_key="old_root", required=True)
state_diff = fields.Nested(StateDiffSchema(), data_key="state_diff", required=True)

@post_load
Expand All @@ -439,6 +442,17 @@ def fix_field(field: Dict, inner_class: Any) -> List[Any]:
return BlockStateUpdate(**data)


class StateUpdateWithBlockSchema(Schema):
block = fields.Nested(StarknetBlockSchema(), data_key="block", required=True)
state_update = fields.Nested(
BlockStateUpdateSchema(), data_key="state_update", required=True
)

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


class EntryPointSchema(Schema):
offset = Felt(data_key="offset", required=True)
selector = Felt(data_key="selector", required=True)
Expand Down Expand Up @@ -623,3 +637,24 @@ class TransactionStatusSchema(Schema):
@post_load
def make_result(self, data, **kwargs) -> TransactionStatusResponse:
return TransactionStatusResponse(**data)


class SignatureInputSchema(Schema):
block_hash = Felt(data_key="block_hash", required=True)
state_diff_commitment = Felt(data_key="state_diff_commitment", required=True)

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


class SignatureOnStateDiffSchema(Schema):
block_number = Felt(data_key="block_number", required=True)
signature = fields.List(Felt(), data_key="signature", required=True)
signature_input = fields.Nested(
SignatureInputSchema(), data_key="signature_input", required=True
)

@post_load
def make_dataclass(self, data, **kwargs) -> SignatureOnStateDiff:
return SignatureOnStateDiff(**data)
5 changes: 5 additions & 0 deletions starknet_py/net/signer/test_stark_curve_signer.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,8 @@ def test_key_pair():

assert isinstance(key_pair.public_key, int)
assert isinstance(key_pair.private_key, int)

key_pair = KeyPair.from_private_key("0x789")

assert isinstance(key_pair.public_key, int)
assert isinstance(key_pair.private_key, int)
6 changes: 6 additions & 0 deletions starknet_py/tests/e2e/account/account_test.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import sys
from typing import cast
from unittest.mock import AsyncMock, patch

Expand Down Expand Up @@ -148,6 +149,11 @@ async def test_get_class_hash_at(map_contract, account):
assert class_hash != 0


# TODO (#1154): remove line below
@pytest.mark.xfail(
"--client=gateway" in sys.argv,
reason="0.12.2 returns Felts in state_root, devnet returns NonPrefixedHex",
)
@pytest.mark.asyncio()
async def test_get_nonce(account, map_contract):
nonce = await account.get_nonce()
Expand Down
12 changes: 12 additions & 0 deletions starknet_py/tests/e2e/block_test.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import sys

import pytest

from starknet_py.contract import Contract
Expand All @@ -22,6 +24,11 @@ async def declare_contract(account: BaseAccount, compiled_contract: str):
await declare_result.wait_for_acceptance()


# TODO (#1154): remove line below
@pytest.mark.xfail(
"--client=gateway" in sys.argv,
reason="0.12.2 returns Felts in state_root, devnet returns NonPrefixedHex",
)
@pytest.mark.asyncio
async def test_pending_block(account, map_compiled_contract):
await declare_contract(account, map_compiled_contract)
Expand All @@ -35,6 +42,11 @@ async def test_pending_block(account, map_compiled_contract):
assert isinstance(blk, PendingStarknetBlock)


# TODO (#1154): remove line below
@pytest.mark.xfail(
"--client=gateway" in sys.argv,
reason="0.12.2 returns Felts in state_root, devnet returns NonPrefixedHex",
)
@pytest.mark.asyncio
async def test_latest_block(account, map_compiled_contract):
await declare_contract(account, map_compiled_contract)
Expand Down
Loading