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

Commit

Permalink
Merge branch 'main' into fix-117-reduce-subprocess-verbosity-on-error
Browse files Browse the repository at this point in the history
  • Loading branch information
martriay committed Aug 4, 2022
2 parents 81f1d80 + 1d1bc85 commit 654e032
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/nile/core/account.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Command to call or invoke StarkNet smart contracts."""
import logging
import os

from dotenv import load_dotenv
Expand All @@ -20,8 +21,16 @@ class Account:

def __init__(self, signer, network):
"""Get or deploy an Account contract for the given private key."""
self.signer = Signer(int(os.environ[signer]))
self.network = network
try:
self.signer = Signer(int(os.environ[signer]))
self.network = network
except KeyError:
logging.error(
f"\n❌ Cannot find {signer} in env."
"\nCheck spelling and that it exists."
"\nTry moving the .env to the root of your project."
)
return

if accounts.exists(str(self.signer.public_key), network):
signer_data = next(accounts.load(str(self.signer.public_key), network))
Expand Down
2 changes: 2 additions & 0 deletions src/nile/core/call_or_invoke.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ def call_or_invoke(
command.append("--max_fee")
command.append(max_fee)

command.append("--no_wallet")

try:
with contextlib.suppress(subprocess.CalledProcessError):
return subprocess.check_output(command).strip().decode("utf-8")
Expand Down
12 changes: 12 additions & 0 deletions tests/commands/test_account.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tests for account commands."""
import logging
from unittest.mock import MagicMock, patch

import pytest
Expand Down Expand Up @@ -27,6 +28,17 @@ def test_account_init(mock_deploy):
mock_deploy.assert_called_once()


def test_account_init_bad_key(caplog):
logging.getLogger().setLevel(logging.INFO)

Account("BAD_KEY", NETWORK)
assert (
"\n❌ Cannot find BAD_KEY in env."
"\nCheck spelling and that it exists."
"\nTry moving the .env to the root of your project."
) in caplog.text


def test_account_multiple_inits_with_same_key():
account = Account(KEY, NETWORK)
account.deploy()
Expand Down

0 comments on commit 654e032

Please sign in to comment.