-
Notifications
You must be signed in to change notification settings - Fork 76
Devnet predeployed accounts #192
Devnet predeployed accounts #192
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work, @ericnordelo! I left some comments and questions :)
You can use it either from the cli: | ||
|
||
```sh | ||
nile get-accounts --predeployed | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we send txs from a predeployed account through the CLI?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can't now, but it is an interesting idea. Maybe it will be worth modifying the send command (with a predeployed flag or similar) to allow sending tx through predeployed accounts? I'm curious about both your opinions on this @andrew-fleming @martriay
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assumed as much, just confirming. What do you think about removing the CLI snippet and the You can use it either from the cli
? I don't think there's any value from running the command in the CLI and it might avoid users (or me) asking if we can send txs from the predeployeds through the CLI
Maybe it will be worth modifying the send command (with a predeployed flag or similar) to allow sending tx through predeployed accounts
Hmm it sounds like it'd be great to consider. I wouldn't include it in this PR though, that seems like a down-the-road feature
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But you can use it from the cli, just not to send transactions. You can list the predeployed accounts from the cli, as you can do with registered accounts running nile get-accounts
, so I think thee snippet still makes sense.
@@ -234,9 +237,13 @@ def debug(tx_hash, network, contracts_file): | |||
|
|||
@cli.command() | |||
@network_option | |||
def get_accounts(network): | |||
@click.option("--predeployed/--registered", default=False) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be a good idea to give a quick mention to the default registered
flag in the docs—probably in the get-accounts
command
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was checking Click, and as you can check here, Click always wants you to provide an enable and disable flag so that you can change the default later, but just for this, the disable flag is not necessary and is not required from CLI, so I thought that with documenting the --predeployed is enough, because is never needed to pass the --registered flag. Let me know what you think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that's reasonable. Documenting --predeployed
seems like enough
# Starknet CLI requires an hex string for get nonce command | ||
if not str(contract_address).startswith("0x"): | ||
contract_address = hex(int(contract_address)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a reminder for us to remove get_nonce
here after #197 (assuming we merge that PR first)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, and also I just noticed that this method shouldn't receive anything not being an int in contract address (the design patter for hex and int we are trying to follow), so this parser should be refactored accordingly too.
def __init__(self, signer, network): | ||
def __init__(self, signer, network, predeployed_info=None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it'd be extremely helpful to others (as well as ourselves) if we make an issue for adding params and return values in our docstrings
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree, I've just created it #209 .
self.abi_path = os.path.dirname(os.path.realpath(__file__)).replace( | ||
"/core", "/artifacts/abis/Account.json" | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
target_address, _ = next(deployments.load(to, self.network)) or to | ||
target_address, _ = next(deployments.load(hex_address(to), self.network)) or to | ||
# Work with integers internally | ||
target_address = normalize_number(target_address) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
target_address = normalize_number(target_address) | |
target_address = hex(target_address) |
normalize_number
gave me a lot of trouble here. I think using hex
is the way to go
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What troubles did you find? Using hex here is against the pattern we agreed, we should use int internally. Anyway, normalize_number is not necessary here because deployments.load always returns an int (being compliant with the pattern). I removed it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe the issues were from how I was hacking the deployments.load
when trying to get it to work locally. With the latest updates to the PR, everything's running well
@@ -84,7 +100,7 @@ def send(self, to, method, calldata, max_fee, nonce=None): | |||
) | |||
|
|||
return call_or_invoke( | |||
contract=self.address, | |||
contract=self, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This threw me off for a bit 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think is better to pass the account instance to avoid passing a lot of extra parameters like the ABI (that was required for predeployed accounts). All these params are in the instance already. Suggestions are welcome to address this, of course.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed on this being a better approach. Well done!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is causing a circular dependency, i'm rolling it back in #268
____________________________________________________ ERROR collecting tests/commands/test_get_balance.py ____________________________________________________
ImportError while importing test module '/home/nile/tests/commands/test_get_balance.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/usr/lib/python3.8/importlib/__init__.py:127: in import_module
return _bootstrap._gcd_import(name[level:], package, level)
tests/commands/test_get_balance.py:7: in <module>
from nile.utils.get_balance import get_balance
.tox/default/lib/python3.8/site-packages/nile/utils/get_balance.py:3: in <module>
from nile.core.call_or_invoke import call_or_invoke
.tox/default/lib/python3.8/site-packages/nile/core/call_or_invoke.py:6: in <module>
from nile.core import account
.tox/default/lib/python3.8/site-packages/nile/core/account.py:20: in <module>
from nile.core.call_or_invoke import call_or_invoke
E ImportError: cannot import name 'call_or_invoke' from partially initialized module 'nile.core.call_or_invoke' (most likely due to a circular import) (/home/nile/.tox/default/lib/python3.8/site-packages/nile/core/call_or_invoke.py)
else: | ||
address, abi = next(deployments.load(contract, network)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
else: | |
address, abi = next(deployments.load(contract, network)) | |
else: | |
address, abi = next(deployments.load(contract, network)) | |
address = hex(address) |
I believe the address
should also be converted to hex
. When I try to script a basic get_balance
query, I'm receiving a type error:
TypeError: expected str, bytes or os.PathLike object, not int
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added it outside the if/else for both branches before calling the starknet cli.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perfect!
src/nile/utils/__init__.py
Outdated
|
||
|
||
def hex_address(number): | ||
"""Normalize hex or int to int.""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hex_address
is trying to be a normalized number 🥸
tests/test_signer.py
Outdated
build_calls = [] | ||
for call in calls: | ||
build_call = list(call) | ||
build_call[0] = hex(build_call[0]) | ||
build_calls.append(build_call) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we don't need to hexify the first arg, we can remove all this and just pass calls
to get_raw_invoke
and sign_transaction
Also, let's remember to update MockSigner
and MockEthSigner
in Contracts before the next release since they use the same build_calls
logic
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent improvements! Looks good to go
…predeployed-accounts-#137
Add
get_predeployed_accounts
method and logic tocli
andnre
(compatible with starknet-devnet).