From cdd7873b07e4ad62e3ea8bfe23aeb845fd7ab29f Mon Sep 17 00:00:00 2001 From: 0xca11ab1e <105989135+ca11ab1e@users.noreply.github.com> Date: Thu, 2 Jun 2022 10:13:56 +0200 Subject: [PATCH 01/13] Reduce `subprocess` verbosity on call, or involke, error --- src/nile/core/call_or_invoke.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/nile/core/call_or_invoke.py b/src/nile/core/call_or_invoke.py index 86a621f4..dc59a588 100644 --- a/src/nile/core/call_or_invoke.py +++ b/src/nile/core/call_or_invoke.py @@ -1,4 +1,5 @@ """Command to call or invoke StarkNet smart contracts.""" +import contextlib import os import subprocess @@ -37,4 +38,6 @@ def call_or_invoke(contract, type, method, params, network, signature=None): command.append("--signature") command.extend(signature) - return subprocess.check_output(command).strip().decode("utf-8") + with contextlib.suppress(subprocess.CalledProcessError): + return subprocess.check_output(command).strip().decode("utf-8") + return "" From 0293d872d1cb04a4b0fac26b098fe3915e60dc3c Mon Sep 17 00:00:00 2001 From: JulissaDantes Date: Fri, 1 Jul 2022 21:28:28 +0000 Subject: [PATCH 02/13] testing --- setup.cfg | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/setup.cfg b/setup.cfg index 531731df..fc68cfd6 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,5 +1,5 @@ [metadata] -name = cairo-nile +name = juli-nile version = attr: nile.__version__ description = StarkNet/Cairo development toolbelt author = Martin Triay @@ -7,7 +7,7 @@ author_email = martriay@gmail.com license = MIT long_description = file: README.md long_description_content_type = text/markdown; charset=UTF-8 -url = https://github.com/martriay/nile +url = https://github.com/ca11ab1e/nile/tree/fix-117-reduce-subprocess-verbosity-on-error platforms = any classifiers = Programming Language :: Python :: 3.8 From 613f804a339e92ed30933bc391418f4f73b9e77b Mon Sep 17 00:00:00 2001 From: JulissaDantes Date: Fri, 1 Jul 2022 17:37:53 -0400 Subject: [PATCH 03/13] Update __init__.py --- src/nile/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nile/__init__.py b/src/nile/__init__.py index 336bed0b..cfe82bb5 100644 --- a/src/nile/__init__.py +++ b/src/nile/__init__.py @@ -6,6 +6,6 @@ import importlib_metadata try: - __version__ = importlib_metadata.version("cairo-nile") + __version__ = importlib_metadata.version("juli-nile") except importlib_metadata.PackageNotFoundError: __version__ = None From 892e97b4141025370a22c603cabb1c18ce0e28d7 Mon Sep 17 00:00:00 2001 From: JulissaDantes Date: Mon, 4 Jul 2022 17:27:38 +0000 Subject: [PATCH 04/13] Include new parameter --- src/nile/core/node.py | 2 +- tests/test_cli.py | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/nile/core/node.py b/src/nile/core/node.py index fa5ebb03..638c1a00 100644 --- a/src/nile/core/node.py +++ b/src/nile/core/node.py @@ -18,7 +18,7 @@ def node(host="127.0.0.1", port=5000): json.dump(gateway, f) # Start network - subprocess.check_call(["starknet-devnet", "--host", host, "--port", str(port)]) + subprocess.check_call(["starknet-devnet", "--host", host, "--port", str(port), "--lite-mode"]) except FileNotFoundError: print("") diff --git a/tests/test_cli.py b/tests/test_cli.py index 2bfdb824..0e0009c2 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -144,6 +144,9 @@ def test_node(args, expected): gateway = json.load(f) assert gateway.get(network) == expected + print(check_node(p, seconds, gateway_url)) + assert false + @pytest.mark.parametrize( "args", From b12668e667180126e7a90bce8d9a12fd28fb36dd Mon Sep 17 00:00:00 2001 From: JulissaDantes Date: Wed, 6 Jul 2022 18:41:04 +0000 Subject: [PATCH 05/13] Update account to return hash and add tests for lite mode --- src/nile/core/account.py | 7 ++++--- src/nile/core/deploy.py | 4 ++-- tests/commands/test_account.py | 11 ++++++----- tests/test_cli.py | 16 ++++++++++------ 4 files changed, 22 insertions(+), 16 deletions(-) diff --git a/src/nile/core/account.py b/src/nile/core/account.py index b34b6b21..64e86b00 100644 --- a/src/nile/core/account.py +++ b/src/nile/core/account.py @@ -28,9 +28,10 @@ def __init__(self, signer, network): self.address = signer_data["address"] self.index = signer_data["index"] else: - address, index = self.deploy() + address, index, tx_hash = self.deploy() self.address = address self.index = index + self.creation_hash = tx_hash def deploy(self): """Deploy an Account contract for the given private key.""" @@ -38,7 +39,7 @@ def deploy(self): pt = os.path.dirname(os.path.realpath(__file__)).replace("/core", "") overriding_path = (f"{pt}/artifacts", f"{pt}/artifacts/abis") - address, _ = deploy( + address, _,tx_hash = deploy( "Account", [str(self.signer.public_key)], self.network, @@ -48,7 +49,7 @@ def deploy(self): accounts.register(self.signer.public_key, address, index, self.network) - return address, index + return address, index, tx_hash def send(self, to, method, calldata, nonce=None): """Execute a tx going through an Account contract.""" diff --git a/src/nile/core/deploy.py b/src/nile/core/deploy.py index 77188018..6cec7de1 100644 --- a/src/nile/core/deploy.py +++ b/src/nile/core/deploy.py @@ -30,14 +30,14 @@ def deploy(contract_name, arguments, network, alias, overriding_path=None): os.environ["STARKNET_NETWORK"] = "alpha-goerli" else: command.append(f"--gateway_url={GATEWAYS.get(network)}") - + output = subprocess.check_output(command) address, tx_hash = parse_deployment(output) logging.info(f"⏳ ️Deployment of {contract_name} successfully sent at {address}") logging.info(f"🧾 Transaction hash: {tx_hash}") deployments.register(address, abi, network, alias) - return address, abi + return address, abi, tx_hash def parse_deployment(x): diff --git a/tests/commands/test_account.py b/tests/commands/test_account.py index eaf2e580..72ecc6df 100644 --- a/tests/commands/test_account.py +++ b/tests/commands/test_account.py @@ -9,6 +9,7 @@ NETWORK = "goerli" MOCK_ADDRESS = "0x123" MOCK_INDEX = 0 +MOCK_HASH = "0x0" @pytest.fixture(autouse=True) @@ -19,7 +20,7 @@ def tmp_working_dir(monkeypatch, tmp_path): @patch("nile.core.account.Account.deploy") def test_account_init(mock_deploy): - mock_deploy.return_value = MOCK_ADDRESS, MOCK_INDEX + mock_deploy.return_value = MOCK_ADDRESS, MOCK_INDEX, MOCK_HASH account = Account(KEY, NETWORK) assert account.address == MOCK_ADDRESS @@ -39,7 +40,7 @@ def test_account_multiple_inits_with_same_key(): assert account2.index == 1 -@patch("nile.core.account.deploy", return_value=(1, 2)) +@patch("nile.core.account.deploy", return_value=(1, 2, 3)) def test_deploy(mock_deploy): account = Account(KEY, NETWORK) with patch("nile.core.account.os.path.dirname") as mock_path: @@ -57,7 +58,7 @@ def test_deploy(mock_deploy): ) -@patch("nile.core.account.deploy", return_value=(MOCK_ADDRESS, MOCK_INDEX)) +@patch("nile.core.account.deploy", return_value=(MOCK_ADDRESS, MOCK_INDEX, MOCK_HASH)) @patch("nile.core.account.accounts.register") def test_deploy_accounts_register(mock_register, mock_deploy): account = Account(KEY, NETWORK) @@ -70,7 +71,7 @@ def test_deploy_accounts_register(mock_register, mock_deploy): @patch("nile.core.account.call_or_invoke") def test_send_nonce_call(mock_call): account = Account(KEY, NETWORK) - contract_address, _ = account.deploy() + contract_address, *_ = account.deploy() # Instead of creating and populating a tmp .txt file, this uses the # deployed account address (contract_address) as the target @@ -91,7 +92,7 @@ def test_send_nonce_call(mock_call): ) def test_send_sign_transaction_and_execute(callarray, calldata): account = Account(KEY, NETWORK) - contract_address, _ = account.deploy() + contract_address, *_ = account.deploy() sig_r, sig_s = [999, 888] return_signature = [callarray, calldata, sig_r, sig_s] diff --git a/tests/test_cli.py b/tests/test_cli.py index 0e0009c2..c0604f9f 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -14,7 +14,7 @@ import pytest from click.testing import CliRunner - +from nile.core.account import Account from nile.cli import cli from nile.common import ( ABIS_DIRECTORY, @@ -23,6 +23,7 @@ NODE_FILENAME, ) +KEY = "TEST_KEY" RESOURCES_DIR = Path(__file__).parent / "resources" MOCK_HASH = "0x123" @@ -116,9 +117,10 @@ def test_compile(args, expected): reason="Issue in cairo-lang. " "See https://github.com/starkware-libs/cairo-lang/issues/27", ) -def test_node(args, expected): +@patch("nile.utils.debug.subprocess") +def test_node(mock_subprocess, args, expected): # Node life - seconds = 8 + seconds = 50 if args == []: host, port = "127.0.0.1", 5000 @@ -133,6 +135,11 @@ def test_node(args, expected): p = create_process(target=start_node, args=(seconds, args)) p.start() + # Test node is runing on lite mode + account = Account(KEY, network) + account.deploy() + + assert account.creation_hash == "0x0" # Check node heartbeat and assert that it is running status = check_node(p, seconds, gateway_url) p.join() @@ -144,9 +151,6 @@ def test_node(args, expected): gateway = json.load(f) assert gateway.get(network) == expected - print(check_node(p, seconds, gateway_url)) - assert false - @pytest.mark.parametrize( "args", From 30f593a373e0f1a97904c253a86aa2f9491b1b40 Mon Sep 17 00:00:00 2001 From: JulissaDantes Date: Wed, 6 Jul 2022 19:45:48 +0000 Subject: [PATCH 06/13] Update test time --- tests/test_cli.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_cli.py b/tests/test_cli.py index c0604f9f..e83815a6 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -120,7 +120,7 @@ def test_compile(args, expected): @patch("nile.utils.debug.subprocess") def test_node(mock_subprocess, args, expected): # Node life - seconds = 50 + seconds = 60 if args == []: host, port = "127.0.0.1", 5000 @@ -129,7 +129,7 @@ def test_node(mock_subprocess, args, expected): network = host gateway_url = f"http://{host}:{port}/" - + # Spawn process to start StarkNet local network with specified port # i.e. $ nile node --host localhost --port 5001 p = create_process(target=start_node, args=(seconds, args)) From ffbff688918fc7c9debde933bc0d41a8df80e2bd Mon Sep 17 00:00:00 2001 From: JulissaDantes Date: Mon, 11 Jul 2022 12:05:40 +0000 Subject: [PATCH 07/13] Changes after merge --- tests/commands/test_deploy.py | 2 +- tests/test_cli.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/commands/test_deploy.py b/tests/commands/test_deploy.py index 0e04bb9e..235164ce 100644 --- a/tests/commands/test_deploy.py +++ b/tests/commands/test_deploy.py @@ -46,7 +46,7 @@ def test_deploy(mock_register, mock_parse, mock_run_cmd, caplog, args, exp_comma # check return values res = deploy(*args) - assert res == (ADDRESS, ABI) + assert res == (ADDRESS, ABI, TX_HASH) # check internals mock_run_cmd.assert_called_once_with(*exp_command, arguments=ARGS) diff --git a/tests/test_cli.py b/tests/test_cli.py index 43735a0f..921c06f9 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -120,7 +120,7 @@ def test_compile(args, expected): @patch("nile.utils.debug.subprocess") def test_node(mock_subprocess, args, expected): # Node life - seconds = 60 + seconds = 8 if args == []: host, port = "127.0.0.1", 5050 From 8fa5d1a76b7e81850a7bbc747d2636a40ca416a5 Mon Sep 17 00:00:00 2001 From: JulissaDantes Date: Tue, 12 Jul 2022 18:57:36 +0000 Subject: [PATCH 08/13] Improve format --- src/nile/core/account.py | 2 +- src/nile/core/node.py | 4 +++- tests/test_cli.py | 4 ++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/nile/core/account.py b/src/nile/core/account.py index b769e10d..bd16ab33 100644 --- a/src/nile/core/account.py +++ b/src/nile/core/account.py @@ -39,7 +39,7 @@ def deploy(self): pt = os.path.dirname(os.path.realpath(__file__)).replace("/core", "") overriding_path = (f"{pt}/artifacts", f"{pt}/artifacts/abis") - address, _,tx_hash = deploy( + address, _, tx_hash = deploy( "Account", [str(self.signer.public_key)], self.network, diff --git a/src/nile/core/node.py b/src/nile/core/node.py index ccb460e4..3bf86c56 100644 --- a/src/nile/core/node.py +++ b/src/nile/core/node.py @@ -21,7 +21,9 @@ def node(host="127.0.0.1", port=5050): json.dump(gateway, f) # Start network - subprocess.check_call(["starknet-devnet", "--host", host, "--port", str(port), "--lite-mode"]) + subprocess.check_call( + ["starknet-devnet", "--host", host, "--port", str(port), "--lite-mode"] + ) except FileNotFoundError: print("") diff --git a/tests/test_cli.py b/tests/test_cli.py index 921c06f9..debb4161 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -133,7 +133,7 @@ def test_node(mock_subprocess, args, expected): network = host gateway_url = f"http://{host}:{port}/" - + # Spawn process to start StarkNet local network with specified port # i.e. $ nile node --host localhost --port 5001 p = create_process(target=start_node, args=(seconds, args)) @@ -142,7 +142,7 @@ def test_node(mock_subprocess, args, expected): # Test node is runing on lite mode account = Account(KEY, network) account.deploy() - + assert account.creation_hash == "0x0" # Check node heartbeat and assert that it is running status = check_node(p, seconds, gateway_url) From d78d3343b60fec4007d507b0568b1eedf50641d9 Mon Sep 17 00:00:00 2001 From: JulissaDantes Date: Wed, 13 Jul 2022 21:03:55 +0000 Subject: [PATCH 09/13] Fix typo --- tests/test_cli.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_cli.py b/tests/test_cli.py index debb4161..03118187 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -120,7 +120,7 @@ def test_compile(args, expected): @patch("nile.utils.debug.subprocess") def test_node(mock_subprocess, args, expected): # Node life - seconds = 8 + seconds = 15 if args == []: host, port = "127.0.0.1", 5050 @@ -139,7 +139,7 @@ def test_node(mock_subprocess, args, expected): p = create_process(target=start_node, args=(seconds, args)) p.start() - # Test node is runing on lite mode + # Test node is running on lite mode account = Account(KEY, network) account.deploy() From 646a990ed1d05b79c7db1baa21f2859f9ec35dd0 Mon Sep 17 00:00:00 2001 From: Andrew Date: Sat, 23 Jul 2022 20:39:01 -0400 Subject: [PATCH 10/13] add lite-mode param --- README.md | 33 ++++++++++++++++++----- src/nile/__init__.py | 2 +- src/nile/cli.py | 8 ++++-- src/nile/core/account.py | 7 +++-- src/nile/core/deploy.py | 2 +- src/nile/core/node.py | 20 ++++++++------ tests/commands/test_account.py | 11 ++++---- tests/commands/test_deploy.py | 2 +- tests/commands/test_node.py | 48 ++++++++++++++++++++++++++++++++++ tests/test_cli.py | 11 ++------ 10 files changed, 105 insertions(+), 39 deletions(-) create mode 100644 tests/commands/test_node.py diff --git a/README.md b/README.md index 8d5ac3e4..a8fc7bf2 100644 --- a/README.md +++ b/README.md @@ -46,15 +46,34 @@ This command creates the project directory structure and installs `cairo-lang`, Run a local [`starknet-devnet`](https://github.com/Shard-Labs/starknet-devnet/) node: -```sh +```text +nile node [--host HOST] [--port PORT] [--lite_mode] + +optional arguments: +--host HOST Specify the address to listen at; defaults to + 127.0.0.1 (use the address the program outputs on + start) +--port PORT Specify the port to listen at; defaults to 5050 +--lite-mode Applies all lite-mode optimizations by disabling + features such as block hash calculation and deploy + hash +``` + +```text nile node - * Serving Flask app 'starknet_devnet.server' (lazy loading) - * Environment: production - WARNING: This is a development server. Do not use it in a production deployment. - Use a production WSGI server instead. - * Debug mode: off - * Running on http://127.0.0.1:5050/ (Press CTRL+C to quit) +Account #0 +Address: 0x877b050406a54adb5940227e51265a201e467e520ca85dc7f024abd03dcc61 +Public key: 0x256b8dc218586160ef80d3454a7cd51046271fbf091bd6779e3513304f22156 +Private key: 0xb204ff062d85674b467789f07826bb2 + +... + +Initial balance of each account: 1000000000000000000000 WEI +Seed to replicate this account sequence: 2128506880 +WARNING: Use these accounts and their keys ONLY for local testing. DO NOT use them on mainnet or other live networks because you will LOSE FUNDS. + + * Listening on http://127.0.0.1:5050/ (Press CTRL+C to quit) ``` ### `compile` diff --git a/src/nile/__init__.py b/src/nile/__init__.py index cfe82bb5..336bed0b 100644 --- a/src/nile/__init__.py +++ b/src/nile/__init__.py @@ -6,6 +6,6 @@ import importlib_metadata try: - __version__ = importlib_metadata.version("juli-nile") + __version__ = importlib_metadata.version("cairo-nile") except importlib_metadata.PackageNotFoundError: __version__ = None diff --git a/src/nile/cli.py b/src/nile/cli.py index f9edb046..bccd83aa 100755 --- a/src/nile/cli.py +++ b/src/nile/cli.py @@ -195,7 +195,8 @@ def clean(): @cli.command() @click.option("--host", default="127.0.0.1") @click.option("--port", default=5050) -def node(host, port): +@click.option("--lite_mode", is_flag=True) +def node(host, port, lite_mode): """Start StarkNet local network. $ nile node @@ -203,8 +204,11 @@ def node(host, port): $ nile node --host HOST --port 5001 Start StarkNet network on address HOST listening at port 5001 + + $ nile node --lite_mode + Start StarkNet network on lite-mode """ - node_command(host, port) + node_command(host, port, lite_mode) @cli.command() diff --git a/src/nile/core/account.py b/src/nile/core/account.py index bd16ab33..a1d8efe5 100644 --- a/src/nile/core/account.py +++ b/src/nile/core/account.py @@ -28,10 +28,9 @@ def __init__(self, signer, network): self.address = signer_data["address"] self.index = signer_data["index"] else: - address, index, tx_hash = self.deploy() + address, index = self.deploy() self.address = address self.index = index - self.creation_hash = tx_hash def deploy(self): """Deploy an Account contract for the given private key.""" @@ -39,7 +38,7 @@ def deploy(self): pt = os.path.dirname(os.path.realpath(__file__)).replace("/core", "") overriding_path = (f"{pt}/artifacts", f"{pt}/artifacts/abis") - address, _, tx_hash = deploy( + address, _ = deploy( "Account", [str(self.signer.public_key)], self.network, @@ -49,7 +48,7 @@ def deploy(self): accounts.register(self.signer.public_key, address, index, self.network) - return address, index, tx_hash + return address, index def send(self, to, method, calldata, max_fee, nonce=None): """Execute a tx going through an Account contract.""" diff --git a/src/nile/core/deploy.py b/src/nile/core/deploy.py index 01cc8225..ce293668 100644 --- a/src/nile/core/deploy.py +++ b/src/nile/core/deploy.py @@ -20,4 +20,4 @@ def deploy(contract_name, arguments, network, alias, overriding_path=None): logging.info(f"🧾 Transaction hash: {tx_hash}") deployments.register(address, abi, network, alias) - return address, abi, tx_hash + return address, abi diff --git a/src/nile/core/node.py b/src/nile/core/node.py index 3bf86c56..117b6c37 100644 --- a/src/nile/core/node.py +++ b/src/nile/core/node.py @@ -1,11 +1,12 @@ """Command to start StarkNet local network.""" import json +import logging import subprocess from nile.common import NODE_FILENAME -def node(host="127.0.0.1", port=5050): +def node(host="127.0.0.1", port=5050, lite_mode=False): """Start StarkNet local network.""" try: # Save host and port information to be used by other commands @@ -20,13 +21,16 @@ def node(host="127.0.0.1", port=5050): with open(file, "w+") as f: json.dump(gateway, f) + command = ["starknet-devnet", "--host", host, "--port", str(port)] + + if lite_mode: + command.append("--lite-mode") + # Start network - subprocess.check_call( - ["starknet-devnet", "--host", host, "--port", str(port), "--lite-mode"] - ) + subprocess.check_call(command) except FileNotFoundError: - print("") - print("😰 Could not find starknet-devnet, is it installed? Try with:\n") - print(" pip install starknet-devnet") - print("") + logging.error( + "\n\n😰 Could not find starknet-devnet, is it installed? Try with:\n" + " pip install starknet-devnet" + ) diff --git a/tests/commands/test_account.py b/tests/commands/test_account.py index badb2e77..ff21208b 100644 --- a/tests/commands/test_account.py +++ b/tests/commands/test_account.py @@ -9,7 +9,6 @@ NETWORK = "goerli" MOCK_ADDRESS = "0x123" MOCK_INDEX = 0 -MOCK_HASH = "0x0" @pytest.fixture(autouse=True) @@ -20,7 +19,7 @@ def tmp_working_dir(monkeypatch, tmp_path): @patch("nile.core.account.Account.deploy") def test_account_init(mock_deploy): - mock_deploy.return_value = MOCK_ADDRESS, MOCK_INDEX, MOCK_HASH + mock_deploy.return_value = MOCK_ADDRESS, MOCK_INDEX account = Account(KEY, NETWORK) assert account.address == MOCK_ADDRESS @@ -40,7 +39,7 @@ def test_account_multiple_inits_with_same_key(): assert account2.index == 1 -@patch("nile.core.account.deploy", return_value=(1, 2, 3)) +@patch("nile.core.account.deploy", return_value=(1, 2)) def test_deploy(mock_deploy): account = Account(KEY, NETWORK) with patch("nile.core.account.os.path.dirname") as mock_path: @@ -58,7 +57,7 @@ def test_deploy(mock_deploy): ) -@patch("nile.core.account.deploy", return_value=(MOCK_ADDRESS, MOCK_INDEX, MOCK_HASH)) +@patch("nile.core.account.deploy", return_value=(MOCK_ADDRESS, MOCK_INDEX)) @patch("nile.core.account.accounts.register") def test_deploy_accounts_register(mock_register, mock_deploy): account = Account(KEY, NETWORK) @@ -71,7 +70,7 @@ def test_deploy_accounts_register(mock_register, mock_deploy): @patch("nile.core.account.call_or_invoke") def test_send_nonce_call(mock_call): account = Account(KEY, NETWORK) - contract_address, *_ = account.deploy() + contract_address, _ = account.deploy() # Instead of creating and populating a tmp .txt file, this uses the # deployed account address (contract_address) as the target @@ -92,7 +91,7 @@ def test_send_nonce_call(mock_call): ) def test_send_sign_transaction_and_execute(callarray, calldata): account = Account(KEY, NETWORK) - contract_address, *_ = account.deploy() + contract_address, _ = account.deploy() sig_r, sig_s = [999, 888] return_signature = [callarray, calldata, sig_r, sig_s] diff --git a/tests/commands/test_deploy.py b/tests/commands/test_deploy.py index 235164ce..0e04bb9e 100644 --- a/tests/commands/test_deploy.py +++ b/tests/commands/test_deploy.py @@ -46,7 +46,7 @@ def test_deploy(mock_register, mock_parse, mock_run_cmd, caplog, args, exp_comma # check return values res = deploy(*args) - assert res == (ADDRESS, ABI, TX_HASH) + assert res == (ADDRESS, ABI) # check internals mock_run_cmd.assert_called_once_with(*exp_command, arguments=ARGS) diff --git a/tests/commands/test_node.py b/tests/commands/test_node.py new file mode 100644 index 00000000..ceb8a05b --- /dev/null +++ b/tests/commands/test_node.py @@ -0,0 +1,48 @@ +"""Tests for node command.""" +import logging +from unittest.mock import patch + +import pytest + +from nile.core.node import node + +HOSTS = ["127.0.0.1", "goerli"] +PORTS = ["5050", "5001"] +LITE = "--lite-mode" + + +@pytest.fixture(autouse=True) +def tmp_working_dir(monkeypatch, tmp_path): + monkeypatch.chdir(tmp_path) + return tmp_path + + +@pytest.mark.parametrize( + "args, host, port, mode", + [ + ([], HOSTS[0], PORTS[0], None), + ([HOSTS[1], PORTS[1]], HOSTS[1], PORTS[1], None), + ([HOSTS[1], PORTS[1], LITE], HOSTS[1], PORTS[1], LITE), + ], +) +@patch("nile.core.node.subprocess.check_call") +def test_node_call(mock_subprocess, args, host, port, mode): + node(*args) + + command = ["starknet-devnet", "--host", host, "--port", port] + if mode: + command.append(mode) + mock_subprocess.assert_called_once_with(command) + + +@patch("nile.core.node.subprocess.check_call") +def test_node_error(mock_subprocess, caplog): + logging.getLogger().setLevel(logging.INFO) + + mock_subprocess.side_effect = FileNotFoundError + + node() + assert ( + "\n\n😰 Could not find starknet-devnet, is it installed? Try with:\n" + " pip install starknet-devnet" + ) in caplog.text diff --git a/tests/test_cli.py b/tests/test_cli.py index 03118187..365a9654 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -14,7 +14,7 @@ import pytest from click.testing import CliRunner -from nile.core.account import Account + from nile.cli import cli from nile.common import ( ABIS_DIRECTORY, @@ -23,7 +23,6 @@ NODE_FILENAME, ) -KEY = "TEST_KEY" RESOURCES_DIR = Path(__file__).parent / "resources" MOCK_HASH = "0x123" @@ -117,8 +116,7 @@ def test_compile(args, expected): reason="Issue in cairo-lang. " "See https://github.com/starkware-libs/cairo-lang/issues/27", ) -@patch("nile.utils.debug.subprocess") -def test_node(mock_subprocess, args, expected): +def test_node(args, expected): # Node life seconds = 15 @@ -139,11 +137,6 @@ def test_node(mock_subprocess, args, expected): p = create_process(target=start_node, args=(seconds, args)) p.start() - # Test node is running on lite mode - account = Account(KEY, network) - account.deploy() - - assert account.creation_hash == "0x0" # Check node heartbeat and assert that it is running status = check_node(p, seconds, gateway_url) p.join() From dca90b9a9083ba856362af4db5cd4669f5feb94b Mon Sep 17 00:00:00 2001 From: Andrew Date: Sat, 23 Jul 2022 20:48:06 -0400 Subject: [PATCH 11/13] fix setup --- setup.cfg | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/setup.cfg b/setup.cfg index fc68cfd6..531731df 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,5 +1,5 @@ [metadata] -name = juli-nile +name = cairo-nile version = attr: nile.__version__ description = StarkNet/Cairo development toolbelt author = Martin Triay @@ -7,7 +7,7 @@ author_email = martriay@gmail.com license = MIT long_description = file: README.md long_description_content_type = text/markdown; charset=UTF-8 -url = https://github.com/ca11ab1e/nile/tree/fix-117-reduce-subprocess-verbosity-on-error +url = https://github.com/martriay/nile platforms = any classifiers = Programming Language :: Python :: 3.8 From 343a4422ffa23d6c576f5570b2a28d9285211eee Mon Sep 17 00:00:00 2001 From: Andrew Fleming Date: Fri, 29 Jul 2022 16:11:12 -0400 Subject: [PATCH 12/13] Update README.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Martín Triay --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 5258b3f6..2fd33c4d 100644 --- a/README.md +++ b/README.md @@ -55,8 +55,8 @@ optional arguments: start) --port PORT Specify the port to listen at; defaults to 5050 --lite-mode Applies all lite-mode optimizations by disabling - features such as block hash calculation and deploy - hash + features such as block hash and deploy hash + calculation ``` ```text From 3cbbcdb22259da8585a1d9307321e35c581f93e4 Mon Sep 17 00:00:00 2001 From: Andrew Date: Mon, 1 Aug 2022 01:02:24 -0400 Subject: [PATCH 13/13] clean up test --- tests/commands/test_node.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/commands/test_node.py b/tests/commands/test_node.py index ceb8a05b..c42b2d2e 100644 --- a/tests/commands/test_node.py +++ b/tests/commands/test_node.py @@ -6,8 +6,8 @@ from nile.core.node import node -HOSTS = ["127.0.0.1", "goerli"] -PORTS = ["5050", "5001"] +HOST = "127.0.0.1" +PORT = "5050" LITE = "--lite-mode" @@ -18,20 +18,20 @@ def tmp_working_dir(monkeypatch, tmp_path): @pytest.mark.parametrize( - "args, host, port, mode", + "args", [ - ([], HOSTS[0], PORTS[0], None), - ([HOSTS[1], PORTS[1]], HOSTS[1], PORTS[1], None), - ([HOSTS[1], PORTS[1], LITE], HOSTS[1], PORTS[1], LITE), + ([]), + ([HOST, PORT]), + ([HOST, PORT, LITE]), ], ) @patch("nile.core.node.subprocess.check_call") -def test_node_call(mock_subprocess, args, host, port, mode): +def test_node_call(mock_subprocess, args): node(*args) - command = ["starknet-devnet", "--host", host, "--port", port] - if mode: - command.append(mode) + command = ["starknet-devnet", "--host", HOST, "--port", PORT] + if LITE in args: + command.append(LITE) mock_subprocess.assert_called_once_with(command)