From 282a688f9a654e6ad4fe8732a646c42a1597b4c5 Mon Sep 17 00:00:00 2001 From: Alexandru Popenta Date: Thu, 2 Nov 2023 15:27:19 +0200 Subject: [PATCH 1/7] fix core package version --- pyproject.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index d5d7ae7c..cec19286 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "hatchling.build" [project] name = "multiversx-sdk-cli" -version = "8.1.4" +version = "8.1.5" authors = [ { name="MultiversX" }, ] @@ -29,7 +29,7 @@ dependencies = [ "rich==13.3.4", "multiversx-sdk-network-providers>=0.11.0", "multiversx-sdk-wallet>=0.7.0, <0.8.0", - "multiversx-sdk-core>=0.5.0" + "multiversx-sdk-core==0.6.0" ] [tool.hatch.build] From feaab02488a3a89c4070d8743cc21e30059e450f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrei=20B=C4=83ncioiu?= Date: Wed, 8 Nov 2023 00:10:44 +0200 Subject: [PATCH 2/7] Adjust constraints of dependencies (sdk-network-providers). --- pyproject.toml | 4 ++-- requirements.txt | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index cec19286..f76d5e03 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "hatchling.build" [project] name = "multiversx-sdk-cli" -version = "8.1.5" +version = "8.1.6" authors = [ { name="MultiversX" }, ] @@ -27,7 +27,7 @@ dependencies = [ "semver", "requests-cache", "rich==13.3.4", - "multiversx-sdk-network-providers>=0.11.0", + "multiversx-sdk-network-providers>=0.11.0, <0.12.0", "multiversx-sdk-wallet>=0.7.0, <0.8.0", "multiversx-sdk-core==0.6.0" ] diff --git a/requirements.txt b/requirements.txt index 1038a8ac..3e411586 100644 --- a/requirements.txt +++ b/requirements.txt @@ -10,5 +10,5 @@ requests-cache rich==13.3.4 multiversx-sdk-core==0.6.0 -multiversx-sdk-network-providers>=0.11.0 -multiversx-sdk-wallet>=0.7.0, < 0.8.0 +multiversx-sdk-network-providers>=0.11.0, <0.12.0 +multiversx-sdk-wallet>=0.7.0, <0.8.0 From 882ed4a5c84bdcb7768726afb1ca632b4cc275a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrei=20B=C4=83ncioiu?= Date: Wed, 8 Nov 2023 10:20:22 +0200 Subject: [PATCH 3/7] Adjust tests. --- multiversx_sdk_cli/tests/shared.sh | 2 +- multiversx_sdk_cli/tests/test_proxy.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/multiversx_sdk_cli/tests/shared.sh b/multiversx_sdk_cli/tests/shared.sh index 57f3dda8..8ca40072 100755 --- a/multiversx_sdk_cli/tests/shared.sh +++ b/multiversx_sdk_cli/tests/shared.sh @@ -16,7 +16,7 @@ PROXY="${PROXY:-http://localhost:7950}" CHAIN_ID="${CHAIN_ID:-localnet}" TestUser=./testdata/testUser.pem TestUser2=./testdata/testUser2.pem -RUST_VERSION="nightly-2023-04-24" +RUST_VERSION="nightly-2023-05-26" cleanSandbox() { rm -rf ${SANDBOX} diff --git a/multiversx_sdk_cli/tests/test_proxy.py b/multiversx_sdk_cli/tests/test_proxy.py index cf570768..f781eb86 100644 --- a/multiversx_sdk_cli/tests/test_proxy.py +++ b/multiversx_sdk_cli/tests/test_proxy.py @@ -36,7 +36,7 @@ def test_query_contract(): [ "contract", "query", - "erd1qqqqqqqqqqqqqpgquykqja5c4v33zdmnwglj3jphqwrelzdn396qlc9g33", + "erd1qqqqqqqqqqqqqpgqpuz9r56ylk39x45cgqmaw2w8hfn47ft3d8ssavktr5", "--function", "getSum", "--proxy", @@ -57,7 +57,7 @@ def test_get_transaction(): "--proxy", "https://devnet-api.multiversx.com", "--hash", - "cbe2026b8d9c3ee75f2846ea8e0b646b19e6fca754e43edb4113757fc3350952", + "9e6ca966b18dc0317ff3be9b53be183ddb068a163769d286b2c1b1dff3ac00e5", ] ) From 8d9affea384a79a4cea985fc8979893e2c4de707 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrei=20B=C4=83ncioiu?= Date: Wed, 8 Nov 2023 10:41:18 +0200 Subject: [PATCH 4/7] Adjust test. --- multiversx_sdk_cli/tests/test_proxy.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/multiversx_sdk_cli/tests/test_proxy.py b/multiversx_sdk_cli/tests/test_proxy.py index f781eb86..a0ac0d94 100644 --- a/multiversx_sdk_cli/tests/test_proxy.py +++ b/multiversx_sdk_cli/tests/test_proxy.py @@ -28,7 +28,7 @@ def test_sync_nonce(): proxy = ProxyNetworkProvider("https://devnet-api.multiversx.com") account.sync_nonce(proxy) - assert account.nonce >= 11480 + assert account.nonce >= 42 def test_query_contract(): From 8c2e17839e4f20132e6450916853008f4e3f7f1e Mon Sep 17 00:00:00 2001 From: Alexandru Popenta Date: Wed, 22 Nov 2023 10:10:18 +0200 Subject: [PATCH 5/7] bump version and update dependencies --- pyproject.toml | 8 ++++---- requirements.txt | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 979d699f..1b9477cb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "hatchling.build" [project] name = "multiversx-sdk-cli" -version = "9.0.0b1" +version = "9.0.0" authors = [ { name="MultiversX" }, ] @@ -27,9 +27,9 @@ dependencies = [ "semver", "requests-cache", "rich==13.3.4", - "multiversx-sdk-network-providers<0.13.0", - "multiversx-sdk-wallet<0.9.0,", - "multiversx-sdk-core<0.8.0" + "multiversx-sdk-network-providers>=0.12.0,<0.13.0", + "multiversx-sdk-wallet>=0.8.0,<0.9.0,", + "multiversx-sdk-core>=0.7.0,<0.8.0" ] [tool.hatch.build] diff --git a/requirements.txt b/requirements.txt index ea54e91b..028aa23d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -9,6 +9,6 @@ semver requests-cache rich==13.3.4 -multiversx-sdk-core<0.8.0 -multiversx-sdk-network-providers<0.13.0 -multiversx-sdk-wallet<0.9.0 +multiversx-sdk-core>=0.7.0,<0.8.0 +multiversx-sdk-network-providers>=0.12.0,<0.13.0 +multiversx-sdk-wallet>=0.8.0,<0.9.0 From 80646608b79468d192c664966fc7358ec4848feb Mon Sep 17 00:00:00 2001 From: Alexandru Popenta Date: Fri, 24 Nov 2023 17:14:49 +0200 Subject: [PATCH 6/7] first part of fixes after review --- multiversx_sdk_cli/contracts.py | 4 ++-- multiversx_sdk_cli/tests/test_contracts.py | 19 ++++++++++++++++++- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/multiversx_sdk_cli/contracts.py b/multiversx_sdk_cli/contracts.py index efd8e2f3..13465f28 100644 --- a/multiversx_sdk_cli/contracts.py +++ b/multiversx_sdk_cli/contracts.py @@ -164,7 +164,7 @@ def query_contract( function: str, arguments: List[Any], value: int = 0, - caller: Optional[Address] = None + caller: Optional[IAddress] = None ) -> List[Any]: response_data = query_detailed(contract_address, proxy, function, arguments, value, caller) return_data = response_data.return_data @@ -172,7 +172,7 @@ def query_contract( def query_detailed(contract_address: IAddress, proxy: INetworkProvider, function: str, arguments: List[Any], - value: int = 0, caller: Optional[Address] = None) -> Any: + value: int = 0, caller: Optional[IAddress] = None) -> Any: arguments = arguments or [] # Temporary workaround, until we use sdk-core's serializer. prepared_arguments = [bytes.fromhex(_prepare_argument(arg)) for arg in arguments] diff --git a/multiversx_sdk_cli/tests/test_contracts.py b/multiversx_sdk_cli/tests/test_contracts.py index a5d2ecf6..733969a3 100644 --- a/multiversx_sdk_cli/tests/test_contracts.py +++ b/multiversx_sdk_cli/tests/test_contracts.py @@ -9,7 +9,8 @@ from multiversx_sdk_cli.accounts import Account from multiversx_sdk_cli.contract_verification import _create_request_signature from multiversx_sdk_cli.contracts import (_interpret_as_number_if_safely, - _prepare_argument) + _prepare_argument, + prepare_args_for_factory) logging.basicConfig(level=logging.INFO) @@ -66,3 +67,19 @@ def test_interpret_as_number_if_safely(): assert _interpret_as_number_if_safely("") == 0 assert _interpret_as_number_if_safely("0x5") == 5 assert _interpret_as_number_if_safely("FF") == 255 + + +def test_prepare_args_for_factories(): + args = [ + "0x5", "123", "false", "true", + "str:test-string", + "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th" + ] + + arguments = prepare_args_for_factory(args) + assert arguments[0] == b"\x05" + assert arguments[1] == 123 + assert arguments[2] == False + assert arguments[3] == True + assert arguments[4] == "test-string" + assert arguments[5].to_bech32() == "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th" From 5cfe31aba4a2fd1d549a93d5f99f01fd5d6103df Mon Sep 17 00:00:00 2001 From: Alexandru Popenta Date: Mon, 27 Nov 2023 12:08:30 +0200 Subject: [PATCH 7/7] fixes after review --- multiversx_sdk_cli/cli_contracts.py | 9 ++++----- multiversx_sdk_cli/contracts.py | 25 +++++++------------------ 2 files changed, 11 insertions(+), 23 deletions(-) diff --git a/multiversx_sdk_cli/cli_contracts.py b/multiversx_sdk_cli/cli_contracts.py index 9c5ff67d..5d6d1121 100644 --- a/multiversx_sdk_cli/cli_contracts.py +++ b/multiversx_sdk_cli/cli_contracts.py @@ -3,8 +3,7 @@ from pathlib import Path from typing import Any, List -from multiversx_sdk_core import (Address, AddressComputer, TokenComputer, - Transaction) +from multiversx_sdk_core import Address, AddressComputer, Transaction from multiversx_sdk_core.transaction_factories import TransactionsFactoryConfig from multiversx_sdk_network_providers.proxy_network_provider import \ ProxyNetworkProvider @@ -307,7 +306,7 @@ def deploy(args: Any): cli_shared.prepare_chain_id_in_args(args) config = TransactionsFactoryConfig(args.chain) - contract = SmartContract(config, TokenComputer()) + contract = SmartContract(config) address_computer = AddressComputer(NUMBER_OF_SHARDS) contract_address = address_computer.compute_contract_address(deployer=sender.address, deployment_nonce=sender.nonce) @@ -381,7 +380,7 @@ def call(args: Any): sender = _prepare_sender(args) config = TransactionsFactoryConfig(args.chain) - contract = SmartContract(config, TokenComputer()) + contract = SmartContract(config) contract_address = Address.new_from_bech32(args.contract) tx = contract.get_execute_transaction(sender, args) @@ -399,7 +398,7 @@ def upgrade(args: Any): sender = _prepare_sender(args) config = TransactionsFactoryConfig(args.chain) - contract = SmartContract(config, TokenComputer()) + contract = SmartContract(config) contract_address = Address.new_from_bech32(args.contract) tx = contract.get_upgrade_transaction(sender, args) diff --git a/multiversx_sdk_cli/contracts.py b/multiversx_sdk_cli/contracts.py index 13465f28..634cbdcb 100644 --- a/multiversx_sdk_cli/contracts.py +++ b/multiversx_sdk_cli/contracts.py @@ -3,7 +3,7 @@ from pathlib import Path from typing import Any, List, Optional, Protocol, Sequence -from multiversx_sdk_core import Transaction, TransactionPayload +from multiversx_sdk_core import TokenComputer, Transaction, TransactionPayload from multiversx_sdk_core.address import Address from multiversx_sdk_core.transaction_factories import \ SmartContractTransactionsFactory @@ -70,22 +70,9 @@ class IConfig(Protocol): gas_limit_per_byte: int -class IToken(Protocol): - identifier: str - nonce: int - - -class ITokenComputer(Protocol): - def is_fungible(self, token: IToken) -> bool: - ... - - def extract_identifier_from_extended_identifier(self, identifier: str) -> str: - ... - - class SmartContract: - def __init__(self, config: IConfig, token_computer: ITokenComputer): - self._factory = SmartContractTransactionsFactory(config, token_computer) + def __init__(self, config: IConfig): + self._factory = SmartContractTransactionsFactory(config, TokenComputer()) def get_deploy_transaction(self, owner: Account, args: Any) -> Transaction: arguments = args.arguments or [] @@ -175,9 +162,10 @@ def query_detailed(contract_address: IAddress, proxy: INetworkProvider, function value: int = 0, caller: Optional[IAddress] = None) -> Any: arguments = arguments or [] # Temporary workaround, until we use sdk-core's serializer. - prepared_arguments = [bytes.fromhex(_prepare_argument(arg)) for arg in arguments] + arguments_hex = [_prepare_argument(arg) for arg in arguments] + prepared_arguments_bytes = [bytes.fromhex(arg) for arg in arguments_hex] - query = ContractQuery(contract_address, function, value, prepared_arguments, caller) + query = ContractQuery(contract_address, function, value, prepared_arguments_bytes, caller) response = proxy.query_contract(query) # Temporary workaround, until we add "isSuccess" on the response class. @@ -252,6 +240,7 @@ def hex_to_bytes(arg: str): return bytes.fromhex(argument) +# only used for contract queries and stake operations def _prepare_argument(argument: Any): as_str = str(argument) as_hex = _to_hex(as_str)