diff --git a/README.md b/README.md index 22077fcf..f6e12a13 100644 --- a/README.md +++ b/README.md @@ -123,6 +123,7 @@ A few things to notice here: 2. This created a `localhost.deployments.txt` file storing all data related to my deployment 3. The `--alias` parameter lets me create an unique identifier for future interactions, if no alias is set then the contract's address can be used as identifier 4. By default Nile works on local, but you can use the `--network` parameter to interact with `mainnet`, `goerli`, and the default `localhost`. +5. By default, the ABI corresponding to the contract will be registered with the deployment. To register a different ABI file, use the `--abi` parameter. ### `declare` diff --git a/src/nile/cli.py b/src/nile/cli.py index 0853b3fb..b16e3e84 100755 --- a/src/nile/cli.py +++ b/src/nile/cli.py @@ -82,9 +82,10 @@ def run(path, network): @click.argument("arguments", nargs=-1) @network_option @click.option("--alias") -def deploy(artifact, arguments, network, alias): +@click.option("--abi") +def deploy(artifact, arguments, network, alias, abi=None): """Deploy StarkNet smart contract.""" - deploy_command(artifact, arguments, network, alias) + deploy_command(artifact, arguments, network, alias, abi=abi) @cli.command() diff --git a/src/nile/core/deploy.py b/src/nile/core/deploy.py index ce293668..16a02ace 100644 --- a/src/nile/core/deploy.py +++ b/src/nile/core/deploy.py @@ -5,13 +5,13 @@ from nile.common import ABIS_DIRECTORY, BUILD_DIRECTORY, parse_information, run_command -def deploy(contract_name, arguments, network, alias, overriding_path=None): +def deploy(contract_name, arguments, network, alias, overriding_path=None, abi=None): """Deploy StarkNet smart contracts.""" logging.info(f"🚀 Deploying {contract_name}") base_path = ( overriding_path if overriding_path else (BUILD_DIRECTORY, ABIS_DIRECTORY) ) - abi = f"{base_path[1]}/{contract_name}.json" + register_abi = abi if abi is not None else f"{base_path[1]}/{contract_name}.json" output = run_command(contract_name, network, overriding_path, arguments=arguments) @@ -19,5 +19,5 @@ def deploy(contract_name, arguments, network, alias, overriding_path=None): 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 + deployments.register(address, register_abi, network, alias) + return address, register_abi diff --git a/src/nile/nre.py b/src/nile/nre.py index e9fc638b..5a6676d9 100644 --- a/src/nile/nre.py +++ b/src/nile/nre.py @@ -26,9 +26,13 @@ def declare(self, contract, alias=None, overriding_path=None): """Declare a smart contract class.""" return declare(contract, self.network, alias) - def deploy(self, contract, arguments=None, alias=None, overriding_path=None): + def deploy( + self, contract, arguments=None, alias=None, overriding_path=None, abi=None + ): """Deploy a smart contract.""" - return deploy(contract, arguments, self.network, alias, overriding_path) + return deploy( + contract, arguments, self.network, alias, overriding_path, abi=abi + ) def call(self, contract, method, params=None): """Call a view function in a smart contract.""" diff --git a/tests/commands/test_deploy.py b/tests/commands/test_deploy.py index 0e04bb9e..694f4a53 100644 --- a/tests/commands/test_deploy.py +++ b/tests/commands/test_deploy.py @@ -17,6 +17,7 @@ def tmp_working_dir(monkeypatch, tmp_path): NETWORK = "goerli" ALIAS = "alias" ABI = f"{ABIS_DIRECTORY}/{CONTRACT}.json" +ABI_OVERRIDE = f"{ABIS_DIRECTORY}/override.json" BASE_PATH = (BUILD_DIRECTORY, ABIS_DIRECTORY) PATH_OVERRIDE = ("artifacts2", ABIS_DIRECTORY) RUN_OUTPUT = b"output" @@ -26,32 +27,46 @@ def tmp_working_dir(monkeypatch, tmp_path): @pytest.mark.parametrize( - "args, exp_command", + "args, exp_command, exp_abi", [ ( [CONTRACT, ARGS, NETWORK, ALIAS], # args [CONTRACT, NETWORK, None], # expected command + ABI, # expected ABI ), ( [CONTRACT, ARGS, NETWORK, ALIAS, PATH_OVERRIDE], # args [CONTRACT, NETWORK, PATH_OVERRIDE], # expected command + ABI, # expected ABI + ), + ( + [CONTRACT, ARGS, NETWORK, ALIAS, None, ABI_OVERRIDE], # args + [CONTRACT, NETWORK, None], # expected command + ABI_OVERRIDE, # expected ABI + ), + ( + [CONTRACT, ARGS, NETWORK, ALIAS, PATH_OVERRIDE, ABI_OVERRIDE], # args + [CONTRACT, NETWORK, PATH_OVERRIDE], # expected command + ABI_OVERRIDE, # expected ABI ), ], ) @patch("nile.core.deploy.run_command", return_value=RUN_OUTPUT) @patch("nile.core.deploy.parse_information", return_value=[ADDRESS, TX_HASH]) @patch("nile.core.deploy.deployments.register") -def test_deploy(mock_register, mock_parse, mock_run_cmd, caplog, args, exp_command): +def test_deploy( + mock_register, mock_parse, mock_run_cmd, caplog, args, exp_command, exp_abi +): logging.getLogger().setLevel(logging.INFO) # check return values res = deploy(*args) - assert res == (ADDRESS, ABI) + assert res == (ADDRESS, exp_abi) # check internals mock_run_cmd.assert_called_once_with(*exp_command, arguments=ARGS) mock_parse.assert_called_once_with(RUN_OUTPUT) - mock_register.assert_called_once_with(ADDRESS, ABI, NETWORK, ALIAS) + mock_register.assert_called_once_with(ADDRESS, exp_abi, NETWORK, ALIAS) # check logs assert f"🚀 Deploying {CONTRACT}" in caplog.text