Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
cptartur committed Oct 18, 2022
2 parents 1baf80a + 38769bc commit 13fe9f0
Show file tree
Hide file tree
Showing 11 changed files with 369 additions and 331 deletions.
590 changes: 302 additions & 288 deletions poetry.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "starknet-py"
version = "0.6.3-alpha"
version = "0.7.0-alpha"
description = "A python SDK for StarkNet"
authors = ["Tomasz Rejowski <[email protected]>", "Jakub Ptak <[email protected]>"]
include = ["starknet_py", "starknet_py/utils/crypto/libcrypto_c_exports.*"]
Expand All @@ -21,7 +21,7 @@ enum-tools = {extras = ["sphinx"], version = "0.9.0", optional = true}
crypto-cpp-py = "^1.0.4"
marshmallow = "^3.15.0"
marshmallow-oneofschema = "^3.0.1"
cairo-lang = "0.10.0"
cairo-lang = "0.10.1"
typing-extensions = "^4.3.0"

[tool.poetry.extras]
Expand All @@ -41,7 +41,7 @@ pytest-mock = "^3.6.1"
pytest-xdist = "^2.5.0"
web3 = {extras=["tester"], version="6.0.0b4"}
pyright = "^1.1.270"
starknet-devnet = "^0.3.3"
starknet-devnet = {git = "https://github.com/Shard-Labs/starknet-devnet.git", rev = "373cb165e36cad3edce7d38f9d7ccc9ea516687b"}

[tool.poe.tasks]
test = ["test_unit", "test_e2e", "test_docs"]
Expand Down
34 changes: 17 additions & 17 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
aiohttp==3.8.1 ; python_version >= "3.8" and python_version < "3.10"
aiohttp==3.8.3 ; python_version >= "3.8" and python_version < "3.10"
aiosignal==1.2.0 ; python_version >= "3.8" and python_version < "3.10"
alabaster==0.7.12 ; python_version >= "3.8" and python_version < "3.10"
apeye==1.2.0 ; python_version >= "3.8" and python_version < "3.10"
Expand All @@ -13,16 +13,16 @@ beautifulsoup4==4.11.1 ; python_version >= "3.8" and python_version < "3.10"
bitarray==1.2.2 ; python_version >= "3.8" and python_version < "3.10"
cachecontrol[filecache]==0.12.11 ; python_version >= "3.8" and python_version < "3.10"
cachetools==5.2.0 ; python_version >= "3.8" and python_version < "3.10"
cairo-lang==0.10.0 ; python_version >= "3.8" and python_version < "3.10"
certifi==2022.6.15.1 ; python_version >= "3.8" and python_version < "3.10"
cairo-lang==0.10.1 ; python_version >= "3.8" and python_version < "3.10"
certifi==2022.9.24 ; python_version >= "3.8" and python_version < "3.10"
charset-normalizer==2.1.1 ; python_version >= "3.8" and python_version < "3.10"
colorama==0.4.5 ; python_version >= "3.8" and python_version < "3.10" and sys_platform == "win32"
crypto-cpp-py==1.0.4 ; python_version >= "3.8" and python_version < "3.10"
cssutils==2.6.0 ; python_version >= "3.8" and python_version < "3.10"
cytoolz==0.12.0 ; python_version >= "3.8" and python_version < "3.10" and implementation_name == "cpython"
dict2css==0.3.0 ; python_version >= "3.8" and python_version < "3.10"
docutils==0.17.1 ; python_version >= "3.8" and python_version < "3.10"
domdf-python-tools==3.3.0 ; python_version >= "3.8" and python_version < "3.10"
domdf-python-tools==3.5.0 ; python_version >= "3.8" and python_version < "3.10"
ecdsa==0.18.0 ; python_version >= "3.8" and python_version < "3.10"
enum-tools[sphinx]==0.9.0 ; python_version >= "3.8" and python_version < "3.10"
eth-abi==3.0.1 ; python_version >= "3.8" and python_version < "3.10"
Expand All @@ -32,26 +32,26 @@ eth-hash[pycryptodome]==0.3.3 ; python_version >= "3.8" and python_version < "3.
eth-keyfile==0.6.0 ; python_version >= "3.8" and python_version < "3.10"
eth-keys==0.4.0 ; python_version >= "3.8" and python_version < "3.10"
eth-rlp==0.3.0 ; python_version >= "3.8" and python_version < "3.10"
eth-typing==3.1.0 ; python_version >= "3.8" and python_version < "3.10"
eth-typing==3.2.0 ; python_version >= "3.8" and python_version < "3.10"
eth-utils==2.0.0 ; python_version >= "3.8" and python_version < "3.10"
fastecdsa==2.2.3 ; python_version >= "3.8" and python_version < "3.10"
frozendict==1.2 ; python_version >= "3.8" and python_version < "3.10"
frozenlist==1.3.1 ; python_version >= "3.8" and python_version < "3.10"
hexbytes==0.2.3 ; python_version >= "3.8" and python_version < "3.10"
hexbytes==0.3.0 ; python_version >= "3.8" and python_version < "3.10"
html5lib==1.1 ; python_version >= "3.8" and python_version < "3.10"
idna==3.3 ; python_version >= "3.8" and python_version < "3.10"
idna==3.4 ; python_version >= "3.8" and python_version < "3.10"
imagesize==1.4.1 ; python_version >= "3.8" and python_version < "3.10"
importlib-metadata==4.12.0 ; python_version >= "3.8" and python_version < "3.10"
importlib-resources==5.9.0 ; python_version >= "3.8" and python_version < "3.9"
importlib-metadata==5.0.0 ; python_version >= "3.8" and python_version < "3.10"
importlib-resources==5.10.0 ; python_version >= "3.8" and python_version < "3.9"
iniconfig==1.1.1 ; python_version >= "3.8" and python_version < "3.10"
ipfshttpclient==0.8.0a2 ; python_version >= "3.8" and python_version < "3.10"
jinja2==3.1.2 ; python_version >= "3.8" and python_version < "3.10"
jsonschema==4.16.0 ; python_version >= "3.8" and python_version < "3.10"
lark-parser==0.12.0 ; python_version >= "3.8" and python_version < "3.10"
lark==1.1.3 ; python_version >= "3.8" and python_version < "3.10"
lockfile==0.12.2 ; python_version >= "3.8" and python_version < "3.10"
lru-dict==1.1.8 ; python_version >= "3.8" and python_version < "3.10"
markupsafe==2.1.1 ; python_version >= "3.8" and python_version < "3.10"
marshmallow-dataclass==8.5.8 ; python_version >= "3.8" and python_version < "3.10"
marshmallow-dataclass==8.5.9 ; python_version >= "3.8" and python_version < "3.10"
marshmallow-enum==1.5.1 ; python_version >= "3.8" and python_version < "3.10"
marshmallow-oneofschema==3.0.1 ; python_version >= "3.8" and python_version < "3.10"
marshmallow==3.17.1 ; python_version >= "3.8" and python_version < "3.10"
Expand All @@ -62,23 +62,23 @@ multidict==6.0.2 ; python_version >= "3.8" and python_version < "3.10"
mypy-extensions==0.4.3 ; python_version >= "3.8" and python_version < "3.10"
natsort==8.2.0 ; python_version >= "3.8" and python_version < "3.10"
netaddr==0.8.0 ; python_version >= "3.8" and python_version < "3.10"
numpy==1.23.3 ; python_version >= "3.8" and python_version < "3.10"
numpy==1.23.4 ; python_version >= "3.8" and python_version < "3.10"
packaging==21.3 ; python_version >= "3.8" and python_version < "3.10"
parsimonious==0.8.1 ; python_version >= "3.8" and python_version < "3.10"
pipdeptree==2.3.1 ; python_version >= "3.8" and python_version < "3.10"
pkgutil-resolve-name==1.3.10 ; python_version >= "3.8" and python_version < "3.9"
platformdirs==2.5.2 ; python_version >= "3.8" and python_version < "3.10"
pluggy==1.0.0 ; python_version >= "3.8" and python_version < "3.10"
prometheus-client==0.14.1 ; python_version >= "3.8" and python_version < "3.10"
protobuf==3.20.1 ; python_version >= "3.8" and python_version < "3.10"
prometheus-client==0.15.0 ; python_version >= "3.8" and python_version < "3.10"
protobuf==3.20.3 ; python_version >= "3.8" and python_version < "3.10"
py==1.11.0 ; python_version >= "3.8" and python_version < "3.10"
pycryptodome==3.15.0 ; python_version >= "3.8" and python_version < "3.10"
pygments==2.13.0 ; python_version >= "3.8" and python_version < "3.10"
pyparsing==3.0.9 ; python_version >= "3.8" and python_version < "3.10"
pyrsistent==0.18.1 ; python_version >= "3.8" and python_version < "3.10"
pytest-asyncio==0.19.0 ; python_version >= "3.8" and python_version < "3.10"
pytest==6.2.5 ; python_version >= "3.8" and python_version < "3.10"
pytz==2022.2.1 ; python_version >= "3.8" and python_version < "3.10"
pytz==2022.4 ; python_version >= "3.8" and python_version < "3.10"
pywin32==304 ; python_version >= "3.8" and python_version < "3.10" and platform_system == "Windows"
pyyaml==6.0 ; python_version >= "3.8" and python_version < "3.10"
requests==2.28.1 ; python_version >= "3.8" and python_version < "3.10"
Expand All @@ -101,7 +101,7 @@ sphinxcontrib-jsmath==1.0.1 ; python_version >= "3.8" and python_version < "3.10
sphinxcontrib-qthelp==1.0.3 ; python_version >= "3.8" and python_version < "3.10"
sphinxcontrib-serializinghtml==1.1.5 ; python_version >= "3.8" and python_version < "3.10"
sympy==1.11.1 ; python_version >= "3.8" and python_version < "3.10"
tabulate==0.8.10 ; python_version >= "3.8" and python_version < "3.10"
tabulate==0.9.0 ; python_version >= "3.8" and python_version < "3.10"
toml==0.10.2 ; python_version >= "3.8" and python_version < "3.10"
toolz==0.12.0 ; python_version >= "3.8" and python_version < "3.10" and implementation_name == "pypy" or python_version >= "3.8" and python_version < "3.10" and implementation_name == "cpython"
typeguard==2.13.3 ; python_version >= "3.8" and python_version < "3.10"
Expand All @@ -113,4 +113,4 @@ web3==6.0.0b4 ; python_version >= "3.8" and python_version < "3.10"
webencodings==0.5.1 ; python_version >= "3.8" and python_version < "3.10"
websockets==10.3 ; python_version >= "3.8" and python_version < "3.10"
yarl==1.8.1 ; python_version >= "3.8" and python_version < "3.10"
zipp==3.8.1 ; python_version >= "3.8" and python_version < "3.10"
zipp==3.9.0 ; python_version >= "3.8" and python_version < "3.10"
8 changes: 4 additions & 4 deletions starknet_py/contract_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,20 @@
"""

EXPECTED_HASH = (
59796004090676193477156334357335769146616822222924884531861796638754858565
1688292534598790451057949508467835030243564096848945341781421603734773995268
)


EXPECTED_HASH_WITH_IMPORTS = (
1660283819326006729930852394676591088728841641287494160212970585278003471330
2467085149317457155287279889794209231367583529927798195223162392957233886584
)

EXPECTED_ADDRESS = (
1137929495741405662588620210985073364961683439179866224790109707037343317227
1369811099254663530533007926088345455337409146333603828325880844112617234253
)

EXPECTED_ADDRESS_WITH_IMPORTS = (
2215802380634391255523792220475859318374841631894501575098737573407681278580
1539179502839850929772015442738227060010315268355136760060396349750739505823
)

search_path = contracts_dir
Expand Down
16 changes: 15 additions & 1 deletion starknet_py/net/client_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class TransactionType(Enum):
INVOKE = "INVOKE"
DEPLOY = "DEPLOY"
DECLARE = "DECLARE"
DEPLOY_ACCOUNT = "DEPLOY_ACCOUNT"
L1_HANDLER = "L1_HANDLER"


Expand Down Expand Up @@ -104,7 +105,8 @@ class InvokeTransaction(Transaction):

contract_address: int
calldata: List[int]
entry_point_selector: int
# This field is always None for transactions with version = 1
entry_point_selector: Optional[int] = None
nonce: Optional[int] = None


Expand All @@ -130,6 +132,18 @@ class DeployTransaction(Transaction):
class_hash: int


@dataclass
class DeployAccountTransaction(Transaction):
"""
Dataclass representing deploy account transaction
"""

contract_address_salt: int
class_hash: int
constructor_calldata: List[int]
nonce: int


@dataclass
class L1HandlerTransaction(Transaction):
"""
Expand Down
2 changes: 2 additions & 0 deletions starknet_py/net/models/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
Deploy as D,
Transaction as T,
Declare as DCL,
DeployAccount as DAC,
)
from starkware.starknet.core.os.transaction_hash.transaction_hash import (
calculate_transaction_hash_common,
Expand All @@ -28,6 +29,7 @@
Transaction = as_our_module(T)
TransactionType = as_our_module(TT)
Declare = as_our_module(DCL)
DeployAccount = as_our_module(DAC)


def compute_invoke_hash(
Expand Down
17 changes: 16 additions & 1 deletion starknet_py/net/schemas/gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
Event,
DeclareTransactionResponse,
DeployTransactionResponse,
DeployAccountTransaction,
L1HandlerTransaction,
)
from starknet_py.net.schemas.common import (
Expand Down Expand Up @@ -79,7 +80,7 @@ class TransactionSchema(Schema):
class InvokeTransactionSchema(TransactionSchema):
contract_address = Felt(data_key="contract_address", required=True)
calldata = fields.List(Felt(), data_key="calldata", required=True)
entry_point_selector = Felt(data_key="entry_point_selector", required=True)
entry_point_selector = Felt(data_key="entry_point_selector", load_default=None)
nonce = Felt(data_key="nonce", load_default=None)

@post_load
Expand Down Expand Up @@ -109,6 +110,19 @@ def make_dataclass(self, data, **kwargs) -> DeclareTransaction:
return DeclareTransaction(**data)


class DeployAccountTransactionSchema(TransactionSchema):
contract_address_salt = Felt(data_key="contract_address_salt", required=True)
class_hash = Felt(data_key="class_hash", required=True)
constructor_calldata = fields.List(
Felt(), data_key="constructor_calldata", required=True
)
nonce = Felt(data_key="nonce", required=True)

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


class L1HandlerTransactionSchema(TransactionSchema):
contract_address = Felt(data_key="contract_address", required=True)
calldata = fields.List(Felt(), data_key="calldata", required=True)
Expand All @@ -126,6 +140,7 @@ class TypesOfTransactionsSchema(OneOfSchema):
"INVOKE_FUNCTION": InvokeTransactionSchema,
"DECLARE": DeclareTransactionSchema,
"DEPLOY": DeployTransactionSchema,
"DEPLOY_ACCOUNT": DeployAccountTransactionSchema,
"L1_HANDLER": L1HandlerTransactionSchema,
}

Expand Down
2 changes: 2 additions & 0 deletions starknet_py/net/schemas/rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ class TypesOfTransactionsSchema(OneOfSchema):
"INVOKE": InvokeTransactionSchema,
"DECLARE": DeclareTransactionSchema,
"DEPLOY": DeployTransactionSchema,
# FIXME add proper handling/serialization
"DEPLOY_ACCOUNT": None,
}


Expand Down
12 changes: 6 additions & 6 deletions starknet_py/tests/e2e/client/client_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,14 @@ async def test_get_declare_transaction(
assert transaction.sender_address == sender_address[transaction.version]


# TODO: change gateway_client to clients when devnet support v1 transactions
# invoke_transaction_hash is a hash of the v1 transaction (full_node_client.get_transaction will fail)
@pytest.mark.asyncio
async def test_get_invoke_transaction(
client,
gateway_client,
invoke_transaction_hash,
):
transaction = await client.get_transaction(invoke_transaction_hash)
transaction = await gateway_client.get_transaction(invoke_transaction_hash)

assert isinstance(transaction, InvokeTransaction)
assert any(data == 1234 for data in transaction.calldata)
Expand All @@ -90,7 +92,6 @@ async def test_get_block_by_hash(
block_with_deploy_number,
contract_address,
class_hash,
default_gateway_gas_price,
):
block = await client.get_block(block_hash=block_with_deploy_hash)

Expand All @@ -110,7 +111,7 @@ async def test_get_block_by_hash(
)

if isinstance(client, GatewayClient):
assert block.gas_price == default_gateway_gas_price
assert block.gas_price > 0


@pytest.mark.asyncio
Expand All @@ -121,7 +122,6 @@ async def test_get_block_by_number(
block_with_deploy_hash,
contract_address,
class_hash,
default_gateway_gas_price,
):
block = await client.get_block(block_number=block_with_deploy_number)

Expand All @@ -141,7 +141,7 @@ async def test_get_block_by_number(
)

if isinstance(client, GatewayClient):
assert block.gas_price == default_gateway_gas_price
assert block.gas_price > 0


@pytest.mark.asyncio
Expand Down
2 changes: 2 additions & 0 deletions starknet_py/tests/e2e/client/full_node_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ async def test_pending_transactions(full_node_client):
assert pending_transactions[0].max_fee == 0


@pytest.mark.run_on_devnet
@pytest.mark.asyncio
async def test_state_update_full_node_client(
full_node_client,
Expand All @@ -166,6 +167,7 @@ async def test_state_update_full_node_client(
assert class_hash in state_update.declared_contracts


@pytest.mark.run_on_devnet
@pytest.mark.asyncio
async def test_get_storage_at_incorrect_address_full_node_client(full_node_client):
with pytest.raises(ClientError, match="Contract not found"):
Expand Down
11 changes: 0 additions & 11 deletions starknet_py/tests/e2e/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import pytest
import pytest_asyncio
from starkware.crypto.signature.signature import get_random_private_key
from starkware.starknet.definitions.general_config import StarknetGeneralConfig

from starknet_py.net import KeyPair, AccountClient
from starknet_py.net.client import Client
Expand Down Expand Up @@ -463,13 +462,3 @@ async def cairo_serializer(gateway_account_client: AccountClient) -> CairoSerial
contract = deployment_result.deployed_contract

return CairoSerializer(identifier_manager=contract.data.identifier_manager)


@pytest_asyncio.fixture(name="default_gateway_gas_price", scope="module")
def default_gateway_gas_price() -> int:
"""
Returns the default min gas price from the StarknetGeneralConfig.
Useful for asserting that the gas price appears in the block response from
the GatewayClient.
"""
return StarknetGeneralConfig().min_gas_price

0 comments on commit 13fe9f0

Please sign in to comment.