From 0f696ea38ef3832448029eb8cf4819d798c67d81 Mon Sep 17 00:00:00 2001 From: Andrew Fleming Date: Wed, 3 Aug 2022 16:49:25 -0400 Subject: [PATCH 1/2] add no-wallet to account command (#160) --- src/nile/core/call_or_invoke.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/nile/core/call_or_invoke.py b/src/nile/core/call_or_invoke.py index 34c0c331..05036cea 100644 --- a/src/nile/core/call_or_invoke.py +++ b/src/nile/core/call_or_invoke.py @@ -44,6 +44,8 @@ def call_or_invoke( command.append("--max_fee") command.append(max_fee) + command.append("--no_wallet") + try: output = subprocess.check_output(command).strip().decode("utf-8") return output From 1d1bc85b551edcd177e281b1385e29c51cc258b4 Mon Sep 17 00:00:00 2001 From: Andrew Fleming Date: Wed, 3 Aug 2022 21:05:07 -0400 Subject: [PATCH 2/2] Improve error handling of account init with invalid key (#158) * add try/except for signer * fix msg * fix test --- src/nile/core/account.py | 13 +++++++++++-- tests/commands/test_account.py | 12 ++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/nile/core/account.py b/src/nile/core/account.py index a1d8efe5..303d2aeb 100644 --- a/src/nile/core/account.py +++ b/src/nile/core/account.py @@ -1,4 +1,5 @@ """Command to call or invoke StarkNet smart contracts.""" +import logging import os from dotenv import load_dotenv @@ -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)) diff --git a/tests/commands/test_account.py b/tests/commands/test_account.py index ff21208b..6efac1fa 100644 --- a/tests/commands/test_account.py +++ b/tests/commands/test_account.py @@ -1,4 +1,5 @@ """Tests for account commands.""" +import logging from unittest.mock import MagicMock, patch import pytest @@ -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()