Skip to content
This repository has been archived by the owner on Dec 1, 2023. It is now read-only.

Devnet predeployed accounts #192

Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
feat: use contract abi and address in call or invoke
  • Loading branch information
ericnordelo committed Sep 22, 2022
commit b57610fd1c61b2f9c0aa656c0255c1b367f7dc2b
6 changes: 4 additions & 2 deletions src/nile/core/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ def __init__(self, signer, network, predeployed_info=None):
)
return

self.abi_path = os.path.dirname(os.path.realpath(__file__)).replace("/core", "/artifacts/abis/Account.json")

if predeployed_info is not None:
self.address = predeployed_info["address"]
self.index = predeployed_info["index"]
Expand Down Expand Up @@ -93,11 +95,11 @@ def send(self, to, method, calldata, max_fee, nonce=None):
)

return call_or_invoke(
contract=self.address,
contract=self,
Copy link
Contributor

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 😅

Copy link
Member Author

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.

Copy link
Contributor

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!

Copy link
Contributor

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)

type="invoke",
method="__execute__",
params=calldata,
network=self.network,
signature=[str(sig_r), str(sig_s)],
max_fee=str(max_fee),
max_fee=str(max_fee)
)
7 changes: 6 additions & 1 deletion src/nile/core/call_or_invoke.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,19 @@
import subprocess

from nile import deployments
from nile.core import account
from nile.common import GATEWAYS, prepare_params


def call_or_invoke(
contract, type, method, params, network, signature=None, max_fee=None
):
"""Call or invoke functions of StarkNet smart contracts."""
address, abi = next(deployments.load(contract, network))
if isinstance(contract, account.Account):
address = hex(contract.address)
abi = contract.abi_path
else:
address, abi = next(deployments.load(contract, network))
Comment on lines +19 to +20
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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

Copy link
Member Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect!


command = [
"starknet",
Expand Down