Skip to content

Commit

Permalink
raise error when given string argument without prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
popenta committed Apr 17, 2024
1 parent c8b95fc commit ac6854e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion multiversx_sdk_cli/cli_contracts.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ def query(args: Any):

proxy = ProxyNetworkProvider(args.proxy)
function = args.function
arguments = args.arguments or []
arguments: List[Any] = args.arguments or []

result = query_contract(contract_address, proxy, function, arguments)
utils.dump_out_json(result)
Expand Down
2 changes: 2 additions & 0 deletions multiversx_sdk_cli/contracts.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,8 @@ def prepare_args_for_factory(arguments: List[str]) -> List[Any]:
args.append(True)
elif arg.startswith(STR_PREFIX):
args.append(arg[len(STR_PREFIX):])
else:
raise errors.BadUserInput(f"Unknown argument type for argument: `{arg}`. Use `mxpy contract <sub-command> --help` to check all supported arguments")

return args

Expand Down
27 changes: 27 additions & 0 deletions multiversx_sdk_cli/tests/test_cli_contracts.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,33 @@ def test_contract_deploy_without_required_arguments():
assert return_code


def test_contract_commands_argument_parameter():
alice = f"{parent}/testdata/alice.pem"
adder = f"{parent}/testdata/adder.wasm"

return_code = main([
"contract", "deploy",
"--bytecode", adder,
"--pem", alice,
"--nonce", "7",
"--chain", "D",
"--gas-limit", "5000000",
"--arguments", "invalidargument",
])
assert return_code

return_code = main([
"contract", "deploy",
"--bytecode", adder,
"--pem", alice,
"--nonce", "7",
"--chain", "D",
"--gas-limit", "5000000",
"--arguments", "str:invalidargument",
])
assert not return_code


def _read_stdout(capsys: Any) -> str:
return capsys.readouterr().out.strip()

Expand Down

0 comments on commit ac6854e

Please sign in to comment.