Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump Nile version to 0.7.1 #381

Merged
merged 5 commits into from
Jul 26, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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 setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ package_dir =

install_requires =
importlib-metadata>=4.0
cairo-nile==0.6.1
cairo-nile==0.7.0

[options.packages.find]
where = src
Expand Down
26 changes: 16 additions & 10 deletions tests/signers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from utils import to_uint
import eth_keys


class MockSigner():
"""
Utility for sending signed transactions to an Account on Starknet.
Expand Down Expand Up @@ -31,16 +32,17 @@ class MockSigner():
(contract_address, 'another_method', [arg_1, arg_2])
]
)

"""

def __init__(self, private_key):
self.signer = Signer(private_key)
self.public_key = self.signer.public_key
async def send_transaction(self, account, to, selector_name, calldata, nonce=None, max_fee=0):

async def send_transaction(self, account, to, selector_name, calldata, nonce=None, max_fee=1):
EvolveArt marked this conversation as resolved.
Show resolved Hide resolved
return await self.send_transactions(account, [(to, selector_name, calldata)], nonce, max_fee)

async def send_transactions(self, account, calls, nonce=None, max_fee=0):
async def send_transactions(self, account, calls, nonce=None, max_fee=1):
if nonce is None:
execution_info = await account.get_nonce().call()
nonce, = execution_info.result
Expand All @@ -51,20 +53,23 @@ async def send_transactions(self, account, calls, nonce=None, max_fee=0):
build_call[0] = hex(build_call[0])
build_calls.append(build_call)

(call_array, calldata, sig_r, sig_s) = self.signer.sign_transaction(hex(account.contract_address), build_calls, nonce, max_fee)
(call_array, calldata, sig_r, sig_s) = self.signer.sign_transaction(
hex(account.contract_address), build_calls, nonce, max_fee)
return await account.__execute__(call_array, calldata, nonce).invoke(signature=[sig_r, sig_s])


class MockEthSigner():
"""
Utility for sending signed transactions to an Account on Starknet, like MockSigner, but using a secp256k1 signature.
Parameters
----------
private_key : int

"""

def __init__(self, private_key):
self.signer = eth_keys.keys.PrivateKey(private_key)
self.eth_address = int(self.signer.public_key.to_checksum_address(),0)
self.signer = eth_keys.keys.PrivateKey(private_key)
self.eth_address = int(self.signer.public_key.to_checksum_address(), 0)

async def send_transaction(self, account, to, selector_name, calldata, nonce=None, max_fee=0):
return await self.send_transactions(account, [(to, selector_name, calldata)], nonce, max_fee)
Expand All @@ -84,8 +89,9 @@ async def send_transactions(self, account, calls, nonce=None, max_fee=0):
message_hash = get_transaction_hash(
account.contract_address, call_array, calldata, nonce, max_fee
)

signature = self.signer.sign_msg_hash((message_hash).to_bytes(32, byteorder="big"))

signature = self.signer.sign_msg_hash(
(message_hash).to_bytes(32, byteorder="big"))
sig_r = to_uint(signature.r)
sig_s = to_uint(signature.s)

Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ passenv =
PYTHONPATH
deps =
cairo-lang==0.9.0
cairo-nile==0.6.1
cairo-nile==0.7.0
pytest-xdist
# See https://github.com/starkware-libs/cairo-lang/issues/52
marshmallow-dataclass==8.5.3
Expand Down