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
2 changes: 1 addition & 1 deletion docs/contract.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Contract

.. autoclass:: PreparedFunctionCall
:exclude-members: __init__, __new__
:members: call, call_raw, invoke, call_sync, call_raw_sync, invoke_sync, hash, estimate_fee, estimate_fee_sync
:members: call, call_raw, invoke, call_sync, call_raw_sync, invoke_sync, estimate_fee, estimate_fee_sync

.. autoclass:: InvokeResult
:exclude-members: __init__, __new__
Expand Down
2 changes: 1 addition & 1 deletion docs/guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ signing algorithm, it is possible to create ``AccountClient`` with custom

.. literalinclude:: ../starknet_py/tests/e2e/docs/guide/test_custom_signer.py
:language: python
:lines: 11-33
:lines: 11-35
:dedent: 4


Expand Down
22 changes: 11 additions & 11 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ eth-typing==3.1.0; python_version >= "3.7" and python_version < "3.11" and pytho
eth-utils==2.0.0; python_version >= "3.7" and python_version < "3.11" and python_full_version >= "3.7.2"
fastecdsa==2.2.3; python_version >= "3.6" and python_full_version >= "3.7.2"
frozendict==1.2; python_version >= "3.6" and python_full_version >= "3.7.2"
frozenlist==1.3.0; python_version >= "3.7" and python_full_version >= "3.7.2" and python_version < "3.11"
hexbytes==0.2.2; python_version >= "3.7" and python_version < "3.11" and python_full_version >= "3.7.2"
frozenlist==1.3.1; python_version >= "3.7" and python_full_version >= "3.7.2" and python_version < "3.11"
hexbytes==0.2.3; python_version >= "3.7" and python_version < "3.11" and python_full_version >= "3.7.2"
html5lib==1.1; python_version >= "3.7" and python_full_version < "3.0.0" or python_version >= "3.7" and python_full_version >= "3.5.0"
idna==3.3; python_version >= "3.7" and python_version < "3.11" and python_full_version >= "3.7.2"
imagesize==1.4.1; python_version >= "3.6" and python_full_version < "3.0.0" or python_full_version >= "3.4.0" and python_version >= "3.6"
Expand All @@ -46,7 +46,7 @@ importlib-resources==5.9.0; python_full_version >= "3.7.2" and python_version <
iniconfig==1.1.1; python_version >= "3.6" and python_full_version >= "3.7.2"
ipfshttpclient==0.8.0a2; python_full_version >= "3.7.2" and python_version < "3.11" and python_version >= "3.6"
jinja2==3.1.2; python_version >= "3.7"
jsonschema==4.9.0; python_full_version >= "3.7.2" and python_version < "3.11" and python_version >= "3.7"
jsonschema==4.9.1; python_full_version >= "3.7.2" and python_version < "3.11" and python_version >= "3.7"
lark-parser==0.12.0; python_version >= "3.6" and python_full_version >= "3.7.2"
lockfile==0.12.2
lru-dict==1.1.8; python_full_version >= "3.7.2" and python_version < "3.11" and python_version >= "3.6"
Expand Down Expand Up @@ -78,7 +78,7 @@ pyparsing==3.0.9; python_version >= "3.7" and python_full_version >= "3.7.2"
pyrsistent==0.18.1; python_full_version >= "3.7.2" and python_version < "3.11" and python_version >= "3.7"
pytest-asyncio==0.16.0; python_version >= "3.6"
pytest==6.2.5; python_version >= "3.6"
pytz==2022.1; python_version >= "3.6"
pytz==2022.2; python_version >= "3.6"
pywin32==304; python_full_version >= "3.7.2" and python_version < "3.11" and platform_system == "Windows" and python_version >= "3.6"
pyyaml==6.0; python_version >= "3.6" and python_full_version >= "3.7.2"
requests==2.28.1; python_version >= "3.7" and python_version < "3.11" and python_full_version >= "3.7.2"
Expand Down
15 changes: 0 additions & 15 deletions starknet_py/contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import dataclasses
import sys
import warnings
from dataclasses import dataclass
from typing import (
List,
Expand Down Expand Up @@ -32,7 +31,6 @@
AddressRepresentation,
parse_address,
compute_address,
compute_invoke_hash,
)
from starknet_py.compile.compiler import StarknetCompilationSource
from starknet_py.transactions.deploy import make_deploy_tx
Expand Down Expand Up @@ -150,19 +148,6 @@ def __init__(
self.max_fee = max_fee
self.version = version

@property
def hash(self) -> int:
warnings.warn("Hash is deprecated and will be deleted in next releases")

return compute_invoke_hash(
contract_address=self._contract_data.address,
entry_point_selector=self.selector,
calldata=self.calldata,
chain_id=self._client.chain,
max_fee=self.max_fee if self.max_fee is not None else 0,
version=self.version,
)

async def call_raw(
self,
signature: Optional[Collection[int]] = None,
Expand Down
21 changes: 1 addition & 20 deletions starknet_py/contract_test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import pytest

from starknet_py.contract import Contract, PreparedFunctionCall, ContractData
from starknet_py.net.gateway_client import GatewayClient
from starknet_py.contract import Contract
from starknet_py.tests.e2e.conftest import directory_with_contracts

SOURCE = """
Expand Down Expand Up @@ -119,24 +118,6 @@ def test_compute_address_throws_on_no_source():
)


def test_transaction_hash():
call = PreparedFunctionCall(
calldata=[1234],
arguments={},
selector=1530486729947006463063166157847785599120665941190480211966374137237989315360,
client=GatewayClient("testnet"),
payload_transformer=None,
contract_data=ContractData(
address=0x03606DB92E563E41F4A590BC01C243E8178E9BA8C980F8E464579F862DA3537C,
abi=None,
identifier_manager=None,
),
version=0,
max_fee=0,
)
assert call.hash == 0xD0A52D6E77B836613B9F709AD7F4A88297697FEFBEF1ADA3C59692FF46702C


def test_no_valid_source():
with pytest.raises(ValueError) as v_err:
Contract.compute_contract_hash()
Expand Down
16 changes: 8 additions & 8 deletions starknet_py/net/account/account_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def __init__(
"Either a signer or a key_pair must be provided in AccountClient constructor"
)

if chain is None and client.chain is None and signer is None:
if chain is None and signer is None and client.chain is None:
raise ValueError("One of chain or signer must be provided")

self.address = parse_address(address)
Expand Down Expand Up @@ -274,12 +274,6 @@ async def _get_max_fee(
if max_fee is None:
raise ValueError("Max_fee must be specified when invoking a transaction")

if max_fee == 0:
warnings.warn(
"Transaction will fail with max_fee set to 0. Change it to a higher value.",
DeprecationWarning,
)

return max_fee

async def sign_transaction(
Expand Down Expand Up @@ -310,6 +304,12 @@ async def sign_transaction(
async def send_transaction(
self, transaction: InvokeFunction
) -> SentTransactionResponse:
if transaction.max_fee == 0:
warnings.warn(
"Transaction will fail with max_fee set to 0. Change it to a higher value.",
DeprecationWarning,
)

return await self.client.send_transaction(transaction=transaction)

async def execute(
Expand Down Expand Up @@ -382,7 +382,7 @@ async def create_account(
:param chain: ChainId of the chain used to create the default signer
:return: Instance of AccountClient which interacts with created account on given network
"""
if chain is None and client.chain is None and signer is None:
if chain is None and signer is None and client.chain is None:
raise ValueError("One of chain or signer must be provided")

if signer is None:
Expand Down
6 changes: 5 additions & 1 deletion starknet_py/net/full_node_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@ def __init__(
"""
self.url = node_url
self._client = RpcHttpClient(url=node_url, session=session)
self._chain = chain_from_network(net, chain)

if net in ["testnet", "mainnet"]:
chain = chain_from_network(net, chain)
self._chain = chain

self._net = net

@property
Expand Down
6 changes: 5 additions & 1 deletion starknet_py/net/gateway_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,11 @@ def __init__(
gateway_url = net["gateway_url"]

self._net = net
self._chain = chain_from_network(net, chain)

if net in ["testnet", "mainnet"]:
chain = chain_from_network(net, chain)
self._chain = chain

self._feeder_gateway_client = GatewayHttpClient(
url=feeder_gateway_url, session=session
)
Expand Down
2 changes: 1 addition & 1 deletion starknet_py/net/gateway_schemas/gateway_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ class TransactionReceiptSchema(Schema):
values=fields.Raw(),
data_key="transaction_failure_reason",
allow_none=True,
default=None,
load_default=None,
)
events = fields.List(
fields.Nested(EventSchema()), data_key="events", load_default=[]
Expand Down
9 changes: 2 additions & 7 deletions starknet_py/tests/e2e/account/account_client_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,19 +84,15 @@ async def test_estimate_fee_called(erc20_contract):

mocked_estimate_fee.return_value = result

await erc20_contract.functions["balanceOf"].prepare(
"1234", max_fee=0
).estimate_fee()
await erc20_contract.functions["balanceOf"].prepare("1234").estimate_fee()

mocked_estimate_fee.assert_called()


@pytest.mark.asyncio
async def test_estimated_fee_greater_than_zero(erc20_contract):
estimated_fee = (
await erc20_contract.functions["balanceOf"]
.prepare("1234", max_fee=0)
.estimate_fee()
await erc20_contract.functions["balanceOf"].prepare("1234").estimate_fee()
)

assert estimated_fee.overall_fee > 0
Expand Down Expand Up @@ -132,7 +128,6 @@ async def test_create_account_client_with_signer(run_devnet):
key_pair = KeyPair.from_private_key(1234)
client = GatewayClient(
net=run_devnet,
chain=StarknetChainId.TESTNET,
)
address = await deploy_account_contract(
client=client,
Expand Down
6 changes: 0 additions & 6 deletions starknet_py/tests/e2e/client/client_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from starkware.starknet.public.abi import get_selector_from_name
from starkware.starknet.services.api.gateway.transaction import DECLARE_SENDER_ADDRESS

from starknet_py.net.models import StarknetChainId
from starknet_py.net.client_models import (
TransactionStatus,
InvokeFunction,
Expand Down Expand Up @@ -349,11 +348,6 @@ async def test_get_class_by_hash(clients, class_hash):
assert contract_class.entry_points_by_type is not None


def test_chain_id(clients):
for client in clients:
assert client.chain == StarknetChainId.TESTNET


@pytest.mark.asyncio
async def test_wait_for_tx_accepted(gateway_client):
with patch(
Expand Down
33 changes: 6 additions & 27 deletions starknet_py/tests/e2e/client/gateway_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from starknet_py.net.client_models import TransactionStatusResponse, TransactionStatus
from starknet_py.net.gateway_client import GatewayClient
from starknet_py.net.models import StarknetChainId
from starknet_py.net.networks import TESTNET, MAINNET


Expand Down Expand Up @@ -54,29 +53,27 @@ async def test_get_transaction_status(invoke_transaction_hash, gateway_client):

# pylint: disable=protected-access
@pytest.mark.parametrize(
"net, net_address, chain",
"net, net_address",
(
(TESTNET, "https://alpha4.starknet.io", StarknetChainId.TESTNET),
(MAINNET, "https://alpha-mainnet.starknet.io", StarknetChainId.MAINNET),
(TESTNET, "https://alpha4.starknet.io"),
(MAINNET, "https://alpha-mainnet.starknet.io"),
),
)
def test_creating_client_from_predefined_network(net, net_address, chain):
def test_creating_client_from_predefined_network(net, net_address):
gateway_client = GatewayClient(net=net)

assert gateway_client.net == net
assert gateway_client._feeder_gateway_client.url == f"{net_address}/feeder_gateway"
assert gateway_client._gateway_client.url == f"{net_address}/gateway"
assert gateway_client.chain == chain


def test_creating_client_with_custom_net():
custom_net = "custom.net"
gateway_client = GatewayClient(net=custom_net, chain=StarknetChainId.TESTNET)
gateway_client = GatewayClient(net=custom_net)

assert gateway_client.net == custom_net
assert gateway_client._feeder_gateway_client.url == f"{custom_net}/feeder_gateway"
assert gateway_client._gateway_client.url == f"{custom_net}/gateway"
assert gateway_client.chain == StarknetChainId.TESTNET


def test_creating_client_with_custom_net_dict():
Expand All @@ -86,26 +83,8 @@ def test_creating_client_with_custom_net_dict():
"gateway_url": f"{custom_net}/gateway",
}

gateway_client = GatewayClient(net=net, chain=StarknetChainId.TESTNET)
gateway_client = GatewayClient(net=net)

assert gateway_client.net == net
assert gateway_client._feeder_gateway_client.url == net["feeder_gateway_url"]
assert gateway_client._gateway_client.url == net["gateway_url"]
assert gateway_client.chain == StarknetChainId.TESTNET


@pytest.mark.parametrize(
"net",
(
{
"feeder_gateway_url": "custom.net/feeder_gateway",
"gateway_url": "custom.net/gateway",
},
"custom.net",
),
)
def test_throwing_on_custom_net_without_chain(net):
with pytest.raises(ValueError) as err:
GatewayClient(net=net)

assert "Chain is required when not using predefined networks." == str(err.value)
Loading