From b3e75c3828a4bf8f3d8a9f17854004adcd653f2f Mon Sep 17 00:00:00 2001 From: Andrei Bancioiu Date: Sat, 13 Jan 2024 23:09:40 +0200 Subject: [PATCH 1/6] Remove undesired warning message. --- multiversx_sdk_cli/cli_data.py | 2 -- pyproject.toml | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/multiversx_sdk_cli/cli_data.py b/multiversx_sdk_cli/cli_data.py index fe1de714..fc62fc0b 100644 --- a/multiversx_sdk_cli/cli_data.py +++ b/multiversx_sdk_cli/cli_data.py @@ -37,8 +37,6 @@ def setup_parser(subparsers: Any) -> Any: def parse(args: Any): - logger.warning("Always review --expression parameters before executing this command!") - file = Path(args.file).expanduser() expression: str = args.expression suffix = file.suffix diff --git a/pyproject.toml b/pyproject.toml index 47aeb3c9..5d74df73 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "hatchling.build" [project] name = "multiversx-sdk-cli" -version = "9.3.0" +version = "9.3.1" authors = [ { name="MultiversX" }, ] From 0d901a1119c4a94ef0ace2e98f8d7d6edc699f9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrei=20B=C4=83ncioiu?= Date: Mon, 15 Jan 2024 10:06:08 +0200 Subject: [PATCH 2/6] Fix links. --- multiversx_sdk_cli/cli.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/multiversx_sdk_cli/cli.py b/multiversx_sdk_cli/cli.py index fe2e996b..4c0a03b2 100644 --- a/multiversx_sdk_cli/cli.py +++ b/multiversx_sdk_cli/cli.py @@ -68,7 +68,10 @@ def setup_parser(args: List[str]): for interacting with the Blockchain (in general) and with Smart Contracts (in particular). mxpy targets a broad audience of users and developers. -https://docs.multiversx.com/sdk-and-tools/mxpy. + +See: + - https://docs.multiversx.com/sdk-and-tools/sdk-py + - https://docs.multiversx.com/sdk-and-tools/sdk-py/mxpy-cli """, formatter_class=argparse.RawDescriptionHelpFormatter ) From bbf9c131dd4980385c6b4cbaca80cd3ad01382cd Mon Sep 17 00:00:00 2001 From: Alexandru Popenta Date: Thu, 18 Jan 2024 14:49:13 +0200 Subject: [PATCH 3/6] implement config reset command --- CLI.md | 21 +++++++++++++++++++-- CLI.md.sh | 1 + multiversx_sdk_cli/cli_config.py | 23 +++++++++++++++++++++++ 3 files changed, 43 insertions(+), 2 deletions(-) diff --git a/CLI.md b/CLI.md index c7aa1e31..6f18244f 100644 --- a/CLI.md +++ b/CLI.md @@ -16,7 +16,10 @@ mxpy is part of the multiversx-sdk and consists of Command Line Tools and Python for interacting with the Blockchain (in general) and with Smart Contracts (in particular). mxpy targets a broad audience of users and developers. -https://docs.multiversx.com/sdk-and-tools/mxpy. + +See: + - https://docs.multiversx.com/sdk-and-tools/sdk-py + - https://docs.multiversx.com/sdk-and-tools/sdk-py/mxpy-cli COMMAND GROUPS: @@ -1293,7 +1296,7 @@ usage: mxpy config COMMAND [-h] ... Configure multiversx-sdk (default values etc.) COMMANDS: - {dump,get,set,delete,new,switch,list} + {dump,get,set,delete,new,switch,list,reset} OPTIONS: -h, --help show this help message and exit @@ -1308,6 +1311,7 @@ delete Deletes a configuration value. new Creates a new configuration. switch Switch to a different config list List available configs +reset Deletes the config file. Default config will be used. ``` ### Configuration.Dump @@ -1399,6 +1403,19 @@ usage: mxpy config list [-h] ... List available configs +options: + -h, --help show this help message and exit + +``` +### Configuration.Reset + + +``` +$ mxpy config reset --help +usage: mxpy config reset [-h] ... + +Deletes the config file. Default config will be used. + options: -h, --help show this help message and exit diff --git a/CLI.md.sh b/CLI.md.sh index db02f98f..c1b3ac8d 100755 --- a/CLI.md.sh +++ b/CLI.md.sh @@ -93,6 +93,7 @@ generate() { command "Configuration.New" "config new" command "Configuration.Switch" "config switch" command "Configuration.List" "config list" + command "Configuration.Reset" "config reset" group "Data" "data" command "Data.Dump" "data parse" diff --git a/multiversx_sdk_cli/cli_config.py b/multiversx_sdk_cli/cli_config.py index 5169ff20..b32496df 100644 --- a/multiversx_sdk_cli/cli_config.py +++ b/multiversx_sdk_cli/cli_config.py @@ -1,5 +1,7 @@ import logging +import os import sys +from pathlib import Path from typing import Any from multiversx_sdk_cli import cli_shared, config, utils @@ -40,6 +42,9 @@ def setup_parser(subparsers: Any) -> Any: sub = cli_shared.add_command_subparser(subparsers, "config", "list", "List available configs") sub.set_defaults(func=list_configs) + sub = cli_shared.add_command_subparser(subparsers, "config", "reset", "Deletes the config file. Default config will be used.") + sub.set_defaults(func=delete_config) + parser.epilog = cli_shared.build_group_epilog(subparsers) return subparsers @@ -93,3 +98,21 @@ def list_configs(args: Any): if config_name == data.get("active", "default"): config_name += "*" print(config_name) + + +def delete_config(args: Any): + config_file = config.resolve_config_path() + if not config_file.is_file(): + logger.info(f"Config file not found. Aborting...") + return + + confirm_continuation(config_file) + os.remove(config_file) + logger.info("Successfully deleted the config file") + + +def confirm_continuation(file: Path): + answer = input(f"The file `{str(file)}` will be deleted. Do you want to continue? (y/n)") + if answer.lower() not in ["y", "yes"]: + print("Confirmation not given. Stopping...") + exit(1) From 6a5a73d4ba7f710af19d6ce55f2037874848f32e Mon Sep 17 00:00:00 2001 From: Alexandru Popenta Date: Thu, 18 Jan 2024 15:28:31 +0200 Subject: [PATCH 4/6] fix tests --- multiversx_sdk_cli/cli.py | 7 ++- .../tests/test_cli_contracts.py | 6 +- .../tests/test_cli_staking_provider.py | 62 ++++++++++--------- multiversx_sdk_cli/tests/test_proxy.py | 10 +-- 4 files changed, 45 insertions(+), 40 deletions(-) diff --git a/multiversx_sdk_cli/cli.py b/multiversx_sdk_cli/cli.py index 4c0a03b2..91ca09d0 100644 --- a/multiversx_sdk_cli/cli.py +++ b/multiversx_sdk_cli/cli.py @@ -114,11 +114,12 @@ def verify_deprecated_entries_in_config_file(): if len(deprecated_keys) == 0: return - message = "The following entries are deprecated. Please remove them from the `mxpy.json` config file. \n" + config_path = config.resolve_config_path() + message = f"The following config entries are deprecated. Please access `{str(config_path)}` and remove them. \n" for entry in deprecated_keys: - message += f"{entry} \n" + message += f"-> {entry} \n" - ux.show_warning(message) + ux.show_warning(message.rstrip('\n')) if __name__ == "__main__": diff --git a/multiversx_sdk_cli/tests/test_cli_contracts.py b/multiversx_sdk_cli/tests/test_cli_contracts.py index 886454e9..ef5780bc 100644 --- a/multiversx_sdk_cli/tests/test_cli_contracts.py +++ b/multiversx_sdk_cli/tests/test_cli_contracts.py @@ -176,9 +176,8 @@ def test_contract_transfer_and_execute(capsys: Any): main([ "contract", "call", contract_address, "--pem", f"{parent}/testdata/testUser.pem", - "--proxy", "https://devnet-api.multiversx.com", "--chain", "D", - "--recall-nonce", + "--nonce", "7", "--gas-limit", "5000000", "--function", "add", "--arguments", "5", @@ -193,9 +192,8 @@ def test_contract_transfer_and_execute(capsys: Any): main([ "contract", "call", contract_address, "--pem", f"{parent}/testdata/testUser.pem", - "--proxy", "https://devnet-api.multiversx.com", "--chain", "D", - "--recall-nonce", + "--nonce", "77", "--gas-limit", "5000000", "--function", "add", "--arguments", "5", diff --git a/multiversx_sdk_cli/tests/test_cli_staking_provider.py b/multiversx_sdk_cli/tests/test_cli_staking_provider.py index d3bdcc60..3b3f8a10 100644 --- a/multiversx_sdk_cli/tests/test_cli_staking_provider.py +++ b/multiversx_sdk_cli/tests/test_cli_staking_provider.py @@ -15,11 +15,11 @@ def test_create_new_delegation_contract(capsys: Any): main([ "staking-provider", "create-new-delegation-contract", "--pem", str(alice), - "--recall-nonce", "--estimate-gas", + "--nonce", "7", "--estimate-gas", "--value", "1250000000000000000000", "--total-delegation-cap", "10000000000000000000000", "--service-fee", "100", - "--proxy", "https://testnet-api.multiversx.com" + "--chain", "T" ]) tx = get_transaction(capsys) data = tx["emittedTransactionData"] @@ -41,8 +41,8 @@ def test_add_nodes(capsys: Any): "--validators-file", str(validators_file), "--delegation-contract", "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqthllllsy5r6rh", "--pem", str(alice), - "--proxy", "https://testnet-api.multiversx.com", - "--recall-nonce", "--estimate-gas" + "--chain", "T", + "--nonce", "7", "--estimate-gas" ]) tx = get_transaction(capsys) data = tx["emittedTransactionData"] @@ -59,8 +59,8 @@ def test_remove_nodes(capsys: Any): "--bls-keys", f"{first_bls_key},{second_bls_key}", "--delegation-contract", "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqthllllsy5r6rh", "--pem", str(alice), - "--proxy", "https://testnet-api.multiversx.com", - "--recall-nonce", "--estimate-gas" + "--chain", "T", + "--nonce", "7", "--estimate-gas" ]) tx = get_transaction(capsys) data = tx["emittedTransactionData"] @@ -78,8 +78,8 @@ def test_stake_nodes(capsys: Any): "--bls-keys", f"{first_bls_key},{second_bls_key}", "--delegation-contract", "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqthllllsy5r6rh", "--pem", str(alice), - "--proxy", "https://testnet-api.multiversx.com", - "--recall-nonce", "--estimate-gas" + "--chain", "T", + "--nonce", "7", "--estimate-gas" ]) tx = get_transaction(capsys) data = tx["emittedTransactionData"] @@ -97,8 +97,8 @@ def test_unbond_nodes(capsys: Any): "--bls-keys", f"{first_bls_key},{second_bls_key}", "--delegation-contract", "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqthllllsy5r6rh", "--pem", str(alice), - "--proxy", "https://testnet-api.multiversx.com", - "--recall-nonce", "--estimate-gas" + "--chain", "T", + "--nonce", "7", "--estimate-gas" ]) tx = get_transaction(capsys) data = tx["emittedTransactionData"] @@ -116,8 +116,8 @@ def test_unstake_nodes(capsys: Any): "--bls-keys", f"{first_bls_key},{second_bls_key}", "--delegation-contract", "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqthllllsy5r6rh", "--pem", str(alice), - "--proxy", "https://testnet-api.multiversx.com", - "--recall-nonce", "--estimate-gas" + "--chain", "T", + "--nonce", "7", "--estimate-gas" ]) tx = get_transaction(capsys) data = tx["emittedTransactionData"] @@ -135,8 +135,8 @@ def test_unjail_nodes(capsys: Any): "--bls-keys", f"{first_bls_key},{second_bls_key}", "--delegation-contract", "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqthllllsy5r6rh", "--pem", str(alice), - "--proxy", "https://testnet-api.multiversx.com", - "--recall-nonce", "--estimate-gas" + "--chain", "T", + "--nonce", "7", "--estimate-gas" ]) tx = get_transaction(capsys) data = tx["emittedTransactionData"] @@ -154,8 +154,8 @@ def test_change_service_fee(capsys: Any): "--service-fee", "100", "--delegation-contract", "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqthllllsy5r6rh", "--pem", str(alice), - "--proxy", "https://testnet-api.multiversx.com", - "--recall-nonce", "--estimate-gas" + "--chain", "T", + "--nonce", "7", "--estimate-gas" ]) tx = get_transaction(capsys) data = tx["emittedTransactionData"] @@ -173,8 +173,8 @@ def test_modify_delegation_cap(capsys: Any): "--delegation-cap", "10000000000000000000000", "--delegation-contract", "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqthllllsy5r6rh", "--pem", str(alice), - "--proxy", "https://testnet-api.multiversx.com", - "--recall-nonce", "--estimate-gas" + "--chain", "T", + "--nonce", "7", "--estimate-gas" ]) tx = get_transaction(capsys) data = tx["emittedTransactionData"] @@ -192,8 +192,8 @@ def test_automatic_activation(capsys: Any): "--set", "--delegation-contract", "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqthllllsy5r6rh", "--pem", str(alice), - "--proxy", "https://testnet-api.multiversx.com", - "--recall-nonce", "--estimate-gas" + "--nonce", "7", "--estimate-gas", + "--chain", "T" ]) tx = get_transaction(capsys) data = tx["emittedTransactionData"] @@ -204,13 +204,16 @@ def test_automatic_activation(capsys: Any): assert transaction["receiver"] == "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqthllllsy5r6rh" assert transaction["gasLimit"] == 11096500 + # Clear the captured content + capsys.readouterr() + main([ "staking-provider", "automatic-activation", "--unset", "--delegation-contract", "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqthllllsy5r6rh", "--pem", str(alice), - "--proxy", "https://testnet-api.multiversx.com", - "--recall-nonce", "--estimate-gas" + "--nonce", "7", "--estimate-gas", + "--chain", "T" ]) tx = get_transaction(capsys) data = tx["emittedTransactionData"] @@ -228,8 +231,8 @@ def test_redelegate_cap(capsys: Any): "--set", "--delegation-contract", "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqthllllsy5r6rh", "--pem", str(alice), - "--proxy", "https://testnet-api.multiversx.com", - "--recall-nonce", "--estimate-gas" + "--nonce", "7", "--estimate-gas", + "--chain", "T" ]) tx = get_transaction(capsys) data = tx["emittedTransactionData"] @@ -240,13 +243,16 @@ def test_redelegate_cap(capsys: Any): assert transaction["receiver"] == "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqthllllsy5r6rh" assert transaction["gasLimit"] == 11108500 + # Clear the captured content + capsys.readouterr() + main([ "staking-provider", "redelegate-cap", "--unset", "--delegation-contract", "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqthllllsy5r6rh", "--pem", str(alice), - "--proxy", "https://testnet-api.multiversx.com", - "--recall-nonce", "--estimate-gas" + "--nonce", "7", "--estimate-gas", + "--chain", "T" ]) tx = get_transaction(capsys) data = tx["emittedTransactionData"] @@ -266,8 +272,8 @@ def test_set_metadata(capsys: Any): "--identifier", "TEST", "--delegation-contract", "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqthllllsy5r6rh", "--pem", str(alice), - "--proxy", "https://testnet-api.multiversx.com", - "--recall-nonce", "--estimate-gas" + "--nonce", "7", "--estimate-gas", + "--chain", "T" ]) tx = get_transaction(capsys) data = tx["emittedTransactionData"] diff --git a/multiversx_sdk_cli/tests/test_proxy.py b/multiversx_sdk_cli/tests/test_proxy.py index 3f234793..e49cb06c 100644 --- a/multiversx_sdk_cli/tests/test_proxy.py +++ b/multiversx_sdk_cli/tests/test_proxy.py @@ -22,7 +22,7 @@ def test_get_account(): def test_sync_nonce(): account = Account(address=Address.new_from_bech32("erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th")) - proxy = ProxyNetworkProvider("https://devnet-api.multiversx.com") + proxy = ProxyNetworkProvider("https://testnet-api.multiversx.com") account.sync_nonce(proxy) assert True if account.nonce else False @@ -32,11 +32,11 @@ def test_query_contract(): [ "contract", "query", - "erd1qqqqqqqqqqqqqpgqpuz9r56ylk39x45cgqmaw2w8hfn47ft3d8ssavktr5", + "erd1qqqqqqqqqqqqqpgq8z2zzyu30f4607hth0tfj5m3vpjvwrvvrawqw09jem", "--function", "getSum", "--proxy", - "https://devnet-api.multiversx.com", + "https://testnet-api.multiversx.com", ] ) assert False if result else True @@ -48,9 +48,9 @@ def test_get_transaction(): "tx", "get", "--proxy", - "https://devnet-api.multiversx.com", + "https://testnet-api.multiversx.com", "--hash", - "9e6ca966b18dc0317ff3be9b53be183ddb068a163769d286b2c1b1dff3ac00e5", + "bf63fdd7d74cbc78f1ec0fbad05f156984a5c995b782e1947352210dd80c5164", ] ) assert False if result else True From de793d3e096b3ecc6de2dff3310e63ab61a44dff Mon Sep 17 00:00:00 2001 From: Alexandru Popenta Date: Thu, 18 Jan 2024 17:15:51 +0200 Subject: [PATCH 5/6] strip whitespaces in confirmation answer --- multiversx_sdk_cli/cli_config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/multiversx_sdk_cli/cli_config.py b/multiversx_sdk_cli/cli_config.py index b32496df..2bd42622 100644 --- a/multiversx_sdk_cli/cli_config.py +++ b/multiversx_sdk_cli/cli_config.py @@ -113,6 +113,6 @@ def delete_config(args: Any): def confirm_continuation(file: Path): answer = input(f"The file `{str(file)}` will be deleted. Do you want to continue? (y/n)") - if answer.lower() not in ["y", "yes"]: + if answer.lower().strip() not in ["y", "yes"]: print("Confirmation not given. Stopping...") exit(1) From 885b9ea4adefc694c018bee2256c5813cb9d3be6 Mon Sep 17 00:00:00 2001 From: Alexandru Popenta Date: Fri, 19 Jan 2024 11:29:36 +0200 Subject: [PATCH 6/6] fixes after review --- multiversx_sdk_cli/cli_config.py | 11 ++--------- multiversx_sdk_cli/ux.py | 7 +++++++ pyproject.toml | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/multiversx_sdk_cli/cli_config.py b/multiversx_sdk_cli/cli_config.py index 2bd42622..d1439ac2 100644 --- a/multiversx_sdk_cli/cli_config.py +++ b/multiversx_sdk_cli/cli_config.py @@ -1,10 +1,10 @@ import logging import os import sys -from pathlib import Path from typing import Any from multiversx_sdk_cli import cli_shared, config, utils +from multiversx_sdk_cli.ux import confirm_continuation logger = logging.getLogger("cli.config") @@ -106,13 +106,6 @@ def delete_config(args: Any): logger.info(f"Config file not found. Aborting...") return - confirm_continuation(config_file) + confirm_continuation(f"The file `{str(config_file)}` will be deleted. Do you want to continue? (y/n)") os.remove(config_file) logger.info("Successfully deleted the config file") - - -def confirm_continuation(file: Path): - answer = input(f"The file `{str(file)}` will be deleted. Do you want to continue? (y/n)") - if answer.lower().strip() not in ["y", "yes"]: - print("Confirmation not given. Stopping...") - exit(1) diff --git a/multiversx_sdk_cli/ux.py b/multiversx_sdk_cli/ux.py index b91af251..f0177ea6 100644 --- a/multiversx_sdk_cli/ux.py +++ b/multiversx_sdk_cli/ux.py @@ -13,3 +13,10 @@ def show_critical_error(message: str): def show_warning(message: str): print(Panel(f"[yellow]{escape(message)}")) + + +def confirm_continuation(message: str): + answer = input(message) + if answer.lower().strip() not in ["y", "yes"]: + print("Confirmation not given. Stopping...") + exit(1) diff --git a/pyproject.toml b/pyproject.toml index 5d74df73..d550edf7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "hatchling.build" [project] name = "multiversx-sdk-cli" -version = "9.3.1" +version = "9.4.0" authors = [ { name="MultiversX" }, ]