Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented config reset command #401

Merged
merged 7 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions CLI.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions CLI.md.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
12 changes: 8 additions & 4 deletions multiversx_sdk_cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down Expand Up @@ -111,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__":
Expand Down
16 changes: 16 additions & 0 deletions multiversx_sdk_cli/cli_config.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import logging
import os
import sys
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")

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -93,3 +98,14 @@ 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(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")
2 changes: 0 additions & 2 deletions multiversx_sdk_cli/cli_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 2 additions & 4 deletions multiversx_sdk_cli/tests/test_cli_contracts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
62 changes: 34 additions & 28 deletions multiversx_sdk_cli/tests/test_cli_staking_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Proxy not needed here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, because we are not sending the transaction. We used the proxy just to get the nonce which in our test it's not really relevant.

])
tx = get_transaction(capsys)
data = tx["emittedTransactionData"]
Expand All @@ -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"]
Expand All @@ -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"]
Expand All @@ -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"]
Expand All @@ -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"]
Expand All @@ -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"]
Expand All @@ -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"]
Expand All @@ -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"]
Expand All @@ -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"]
Expand All @@ -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"]
Expand All @@ -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"]
Expand All @@ -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"]
Expand All @@ -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"]
Expand All @@ -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"]
Expand Down
10 changes: 5 additions & 5 deletions multiversx_sdk_cli/tests/test_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so do we change to testnet in tests? or it was just temporarly for testing

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because of the devnet situation, the tests we're failing, so that's why I switched to testnet. We can switch for now because it seems it'a a little bit more stable.

account.sync_nonce(proxy)
assert True if account.nonce else False

Expand All @@ -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
Expand All @@ -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
7 changes: 7 additions & 0 deletions multiversx_sdk_cli/ux.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "hatchling.build"

[project]
name = "multiversx-sdk-cli"
version = "9.3.0"
version = "9.4.0"
authors = [
{ name="MultiversX" },
]
Expand Down
Loading