diff --git a/multiversx_sdk_cli/cli_contracts.py b/multiversx_sdk_cli/cli_contracts.py index 88460db0..cb8ea41e 100644 --- a/multiversx_sdk_cli/cli_contracts.py +++ b/multiversx_sdk_cli/cli_contracts.py @@ -242,7 +242,7 @@ def _add_arguments_arg(sub: Any): help="arguments for the contract transaction, as [number, bech32-address, ascii string, " "boolean] or hex-encoded. E.g. --arguments 42 0x64 1000 0xabba str:TOK-a1c2ef true erd1[..]") sub.add_argument("--arguments-file", type=str, help="a json file containing the arguments. ONLY if abi file is provided. " - "E.g. { 'to': 'erd1...', 'amount': 10000000000 }") + "E.g. [{ 'to': 'erd1...', 'amount': 10000000000 }]") def _add_token_transfers_args(sub: Any): @@ -328,13 +328,13 @@ def deploy(args: Any): abi = Abi.load(Path(args.abi)) if args.abi else None contract = SmartContract(config, abi) - arguments, args_from_file = _get_contract_arguments(args) + arguments, should_prepare_args = _get_contract_arguments(args) tx = contract.prepare_deploy_transaction( owner=sender, bytecode=Path(args.bytecode), arguments=arguments, - args_from_file=args_from_file, + should_prepare_args=should_prepare_args, upgradeable=args.metadata_upgradeable, readable=args.metadata_readable, payable=args.metadata_payable, @@ -383,7 +383,7 @@ def call(args: Any): abi = Abi.load(Path(args.abi)) if args.abi else None contract = SmartContract(config, abi) - arguments, args_from_file = _get_contract_arguments(args) + arguments, should_prepare_args = _get_contract_arguments(args) contract_address = Address.new_from_bech32(args.contract) tx = contract.prepare_execute_transaction( @@ -391,7 +391,7 @@ def call(args: Any): contract=contract_address, function=args.function, arguments=arguments, - args_from_file=args_from_file, + should_prepare_args=should_prepare_args, gas_limit=int(args.gas_limit), value=int(args.value), transfers=args.token_transfers, @@ -416,7 +416,7 @@ def upgrade(args: Any): abi = Abi.load(Path(args.abi)) if args.abi else None contract = SmartContract(config, abi) - arguments, args_from_file = _get_contract_arguments(args) + arguments, should_prepare_args = _get_contract_arguments(args) contract_address = Address.new_from_bech32(args.contract) tx = contract.prepare_upgrade_transaction( @@ -424,7 +424,7 @@ def upgrade(args: Any): contract=contract_address, bytecode=Path(args.bytecode), arguments=arguments, - args_from_file=args_from_file, + should_prepare_args=should_prepare_args, upgradeable=args.metadata_upgradeable, readable=args.metadata_readable, payable=args.metadata_payable, @@ -461,12 +461,15 @@ def _get_contract_arguments(args: Any) -> Tuple[List[Any], bool]: json_args = json.loads(Path(args.arguments_file).expanduser().read_text()) if args.arguments_file else None if json_args and args.arguments: - raise Exception("Both '--arguments' and '--arguments-file' provided.") + raise Exception("Provide either '--arguments' or '--arguments-file'.") if json_args: - return json_args, True + if not args.abi: + raise Exception("Can't use '--arguments-file' without providing the Abi file.") + + return json_args, False else: - return args.arguments, False + return args.arguments, True def _send_or_simulate(tx: Transaction, contract_address: IAddress, args: Any): diff --git a/multiversx_sdk_cli/contracts.py b/multiversx_sdk_cli/contracts.py index 820ca009..5ebd8fe2 100644 --- a/multiversx_sdk_cli/contracts.py +++ b/multiversx_sdk_cli/contracts.py @@ -82,7 +82,7 @@ def prepare_deploy_transaction(self, owner: Account, bytecode: Path, arguments: Union[List[Any], None], - args_from_file: bool, + should_prepare_args: bool, upgradeable: bool, readable: bool, payable: bool, @@ -94,7 +94,7 @@ def prepare_deploy_transaction(self, options: int, guardian: str) -> Transaction: args = arguments if arguments else [] - if not args_from_file: + if should_prepare_args: args = self.prepare_args_for_factory(args) tx = self._factory.create_transaction_for_deploy( @@ -121,7 +121,7 @@ def prepare_execute_transaction(self, contract: Address, function: str, arguments: Union[List[Any], None], - args_from_file: bool, + should_prepare_args: bool, gas_limit: int, value: int, transfers: Union[List[str], None], @@ -132,7 +132,7 @@ def prepare_execute_transaction(self, token_transfers = self._prepare_token_transfers(transfers) if transfers else [] args = arguments if arguments else [] - if not args_from_file: + if should_prepare_args: args = self.prepare_args_for_factory(args) tx = self._factory.create_transaction_for_execute( @@ -157,7 +157,7 @@ def prepare_upgrade_transaction(self, contract: IAddress, bytecode: Path, arguments: Union[List[str], None], - args_from_file: bool, + should_prepare_args: bool, upgradeable: bool, readable: bool, payable: bool, @@ -169,7 +169,7 @@ def prepare_upgrade_transaction(self, options: int, guardian: str) -> Transaction: args = arguments if arguments else [] - if not args_from_file: + if should_prepare_args: args = self.prepare_args_for_factory(args) tx = self._factory.create_transaction_for_upgrade( @@ -279,12 +279,12 @@ def _interpret_as_number_if_safely(as_hex: str) -> Optional[int]: Makes sure the string can be safely converted to an int (and then back to a string). See: - - https://stackoverflow.com/questions/73693104/valueerror-exceeds-the-limit-4300-for-integer-string-conversion + - https://stackoverflow.com/questions/73693104/valueerror-exceeds-the-limit-4300-for-integer-string-conversion - https://github.com/python/cpython/issues/95778 """ try: return int(str(int(as_hex or "0", 16))) - except: + except Exception: return None diff --git a/multiversx_sdk_cli/tests/test_cli_contracts.py b/multiversx_sdk_cli/tests/test_cli_contracts.py index a19f3453..acaea1da 100644 --- a/multiversx_sdk_cli/tests/test_cli_contracts.py +++ b/multiversx_sdk_cli/tests/test_cli_contracts.py @@ -107,7 +107,7 @@ def test_contract_deploy(): str(output_file), ] ) - assert Path.is_file(output_file) == True + assert Path.is_file(output_file) def test_contract_upgrade(): @@ -136,7 +136,7 @@ def test_contract_upgrade(): str(output_file), ] ) - assert Path.is_file(output_file) == True + assert Path.is_file(output_file) def test_contract_call(): @@ -165,7 +165,7 @@ def test_contract_call(): str(output_file), ] ) - assert Path.is_file(output_file) == True + assert Path.is_file(output_file) def test_contract_transfer_and_execute(capsys: Any):