From bc184d44cbaa5fb377ade91a2f7b3c06433d5547 Mon Sep 17 00:00:00 2001 From: Pavel Yagunov Date: Thu, 2 May 2024 17:16:33 +0300 Subject: [PATCH 01/12] Added simple entry point tests --- .../test/functional_tests/test_entry_point.py | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 snet/cli/test/functional_tests/test_entry_point.py diff --git a/snet/cli/test/functional_tests/test_entry_point.py b/snet/cli/test/functional_tests/test_entry_point.py new file mode 100644 index 00000000..44bfa775 --- /dev/null +++ b/snet/cli/test/functional_tests/test_entry_point.py @@ -0,0 +1,69 @@ +import unittest +import os + + +class TestEntryPoint(unittest.TestCase): + def test_help(self): + exit_status = os.system('snet --help') + assert exit_status == 0 + + def test_identity(self): + exit_status = os.system('snet identity list') + assert exit_status == 0 + + def test_account(self): + exit_status = os.system('snet account -h') + assert exit_status == 0 + + def test_channel(self): + exit_status = os.system('snet channel -h') + assert exit_status == 0 + + def test_client(self): + exit_status = os.system('snet client -h') + assert exit_status == 0 + + def test_contract(self): + exit_status = os.system('snet contract -h') + assert exit_status == 0 + + def test_network(self): + exit_status = os.system('snet network list') + assert exit_status == 0 + + def test_organization(self): + exit_status = os.system('snet organization -h') + assert exit_status == 0 + + def test_sdk(self): + exit_status = os.system('snet sdk -h') + assert exit_status == 0 + + def test_service(self): + exit_status = os.system('snet service -h') + assert exit_status == 0 + + def test_session(self): + exit_status = os.system('snet session -h') + assert exit_status == 0 + + def test_set(self): + exit_status = os.system('snet set -h') + assert exit_status == 0 + + def test_treasurer(self): + exit_status = os.system('snet treasurer -h') + assert exit_status == 0 + + def test_unset(self): + exit_status = os.system('snet unset -h') + assert exit_status == 0 + + def test_version(self): + exit_status = os.system('snet version') + assert exit_status == 0 + + +if __name__ == '__main__': + unittest.main() + From 7a75825ffc043636d064ffc199cffcf2b727e522 Mon Sep 17 00:00:00 2001 From: Pavel Yagunov Date: Wed, 29 May 2024 18:36:04 +0300 Subject: [PATCH 02/12] Suppressed the eth-typing package`s warnings related to some new networks` ChainIds not being present in networks.py --- snet/cli/__init__.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/snet/cli/__init__.py b/snet/cli/__init__.py index 27025eb4..23f4beba 100644 --- a/snet/cli/__init__.py +++ b/snet/cli/__init__.py @@ -2,10 +2,16 @@ # PYTHON_ARGCOMPLETE_OK import sys +import warnings import argcomplete -from snet.cli import arguments +with warnings.catch_warnings(): + # Suppress the eth-typing package`s warnings related to some new networks + warnings.filterwarnings("ignore", "Network .* does not have a valid ChainId. eth-typing should be " + "updated with the latest networks.", UserWarning) + from snet.cli import arguments + from snet.cli.config import Config From e594ee303c458b2d153092bc1cb08a14ab34b17f Mon Sep 17 00:00:00 2001 From: mabredin Date: Mon, 17 Jun 2024 16:04:32 +0300 Subject: [PATCH 03/12] Add functionality for SDK --- README.md | 2 +- snet/cli/config.py | 55 +++++++++++++++++++++++++++++++++++++++------- 2 files changed, 48 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 0950e68b..bbde3ad2 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ The package is published in PyPI at the following link: |Package |Description | |----------------------------------------------|---------------------------------------------------------------------| -|[snet-cli](https://pypi.org/project/snet.cli/)|Command line interface to interact with the SingularityNET platform | +|[snet.cli](https://pypi.org/project/snet.cli/)|Command line interface to interact with the SingularityNET platform | ## License diff --git a/snet/cli/config.py b/snet/cli/config.py index 02089083..078322e5 100644 --- a/snet/cli/config.py +++ b/snet/cli/config.py @@ -1,13 +1,17 @@ from configparser import ConfigParser, ExtendedInterpolation from pathlib import Path +import sys default_snet_folder = Path("~").expanduser().joinpath(".snet") +DEFAULT_NETWORK = "sepolia" class Config(ConfigParser): - def __init__(self, _snet_folder=default_snet_folder): + def __init__(self, _snet_folder=default_snet_folder, sdk_config=None): super(Config, self).__init__(interpolation=ExtendedInterpolation(), delimiters=("=",)) self._config_file = _snet_folder.joinpath("config") + self.sdk_config = sdk_config + self.is_sdk = True if sdk_config else False if self._config_file.exists(): with open(self._config_file) as f: self.read_file(f) @@ -21,7 +25,7 @@ def get_session_network_name(self): def safe_get_session_identity_network_names(self): if "identity" not in self["session"]: - first_identity_message_and_exit() + first_identity_message_and_exit(is_sdk=self.is_sdk) session_identity = self["session"]["identity"] self._check_section("identity.%s" % session_identity) @@ -128,7 +132,7 @@ def set_network_field(self, network, key, value): self._get_network_section(network)[key] = str(value) self._persist() - def add_identity(self, identity_name, identity, out_f): + def add_identity(self, identity_name, identity, out_f=sys.stdout): identity_section = "identity.%s" % identity_name if identity_section in self: raise Exception("Identity section %s already exists in config" % identity_section) @@ -190,7 +194,18 @@ def create_default_config(self): "default_eth_rpc_endpoint": "https://sepolia.infura.io/v3/09027f4a13e841d48dbfefc67e7685d5", } self["ipfs"] = {"default_ipfs_endpoint": "/dns/ipfs.singularitynet.io/tcp/80/"} - self["session"] = {"network": "sepolia"} + network = self.get_param_from_sdk_config("network") + if network: + if network not in self.get_all_networks_names(): + raise Exception("Network '%s' is not in config" % network) + self["session"] = {"network": network} + else: + self["session"] = {"network": DEFAULT_NETWORK} + identity_name = self.get_param_from_sdk_config("identity_name") + identity_type = self.get_param_from_sdk_config("identity_type") + if identity_name and identity_type: + identity = self.setup_identity() + self.add_identity(identity_name, identity) self._persist() print("We've created configuration file with default values in: %s\n" % str(self._config_file)) @@ -203,10 +218,34 @@ def _persist(self): self.write(f) self._config_file.chmod(0o600) - -def first_identity_message_and_exit(): - print("\nPlease create your first identity by running 'snet identity create'.\n\n" - "The available identity types are:\n" + def get_param_from_sdk_config(self, param: str, alternative=None): + if self.sdk_config: + return self.sdk_config.get(param, alternative) + return None + + def setup_identity(self): + identity_type = self.get_param_from_sdk_config("identity_type") + private_key = self.get_param_from_sdk_config("private_key") + default_wallet_index = self.get_param_from_sdk_config("wallet_index", 0) + if not identity_type: + raise Exception("identity_type not passed") + if identity_type == "key": + identity = { + "identity_type": "key", + "private_key": private_key, + "default_wallet_index": default_wallet_index + } + # TODO: logic for other identity_type + return identity + + +def first_identity_message_and_exit(is_sdk=False): + if is_sdk: + print("\nPlease create your first identity by passing the 'identity_name'" + "and 'identity_type' parameters in the config.\n") + else: + print("\nPlease create your first identity by running 'snet identity create'.\n\n") + print("The available identity types are:\n" " - 'rpc' (yields to a required ethereum json-rpc endpoint for signing using a given wallet\n" " index)\n" " - 'mnemonic' (uses a required bip39 mnemonic for HDWallet/account derivation and signing\n" From 48209b75c4925a4238349cd2d91b3186ac87c8a1 Mon Sep 17 00:00:00 2001 From: mabredin Date: Tue, 18 Jun 2024 18:27:41 +0300 Subject: [PATCH 04/12] Add a message when passing an unavailable identity_type parameter --- snet/cli/config.py | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/snet/cli/config.py b/snet/cli/config.py index 078322e5..d56d4e6e 100644 --- a/snet/cli/config.py +++ b/snet/cli/config.py @@ -236,25 +236,33 @@ def setup_identity(self): "default_wallet_index": default_wallet_index } # TODO: logic for other identity_type + else: + print("\nThe identity_type parameter value you passed is not supported " + "by the sdk at this time.\n") + print("The available identity types are:\n" + " - 'key' (uses a required hex-encoded private key for signing)\n\n") + exit(1) return identity def first_identity_message_and_exit(is_sdk=False): if is_sdk: - print("\nPlease create your first identity by passing the 'identity_name'" + print("\nPlease create your first identity by passing the 'identity_name' " "and 'identity_type' parameters in the config.\n") + print("The available identity types are:\n" + " - 'key' (uses a required hex-encoded private key for signing)\n\n") else: print("\nPlease create your first identity by running 'snet identity create'.\n\n") - print("The available identity types are:\n" - " - 'rpc' (yields to a required ethereum json-rpc endpoint for signing using a given wallet\n" - " index)\n" - " - 'mnemonic' (uses a required bip39 mnemonic for HDWallet/account derivation and signing\n" - " using a given wallet index)\n" - " - 'key' (uses a required hex-encoded private key for signing)\n" - " - 'ledger' (yields to a required ledger nano s device for signing using a given wallet\n" - " index)\n" - " - 'trezor' (yields to a required trezor device for signing using a given wallet index)\n" - "\n") + print("The available identity types are:\n" + " - 'rpc' (yields to a required ethereum json-rpc endpoint for signing using a given wallet\n" + " index)\n" + " - 'mnemonic' (uses a required bip39 mnemonic for HDWallet/account derivation and signing\n" + " using a given wallet index)\n" + " - 'key' (uses a required hex-encoded private key for signing)\n" + " - 'ledger' (yields to a required ledger nano s device for signing using a given wallet\n" + " index)\n" + " - 'trezor' (yields to a required trezor device for signing using a given wallet index)\n" + "\n") exit(1) From 8f5387d529486cb1bdebde607976282428d6acde Mon Sep 17 00:00:00 2001 From: mabredin Date: Wed, 19 Jun 2024 13:12:09 +0300 Subject: [PATCH 05/12] Update version to 2.1.3 --- version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.py b/version.py index 4eabd0b3..e835b9d0 100644 --- a/version.py +++ b/version.py @@ -1 +1 @@ -__version__ = "2.1.2" +__version__ = "2.1.3" From c600a3b2e46bd65012bfb945bee2e1ddb31be5a3 Mon Sep 17 00:00:00 2001 From: Pavel Yagunov Date: Wed, 19 Jun 2024 17:03:48 +0300 Subject: [PATCH 06/12] changed asserts in the test_entry_point.py to unittest`s self.assertEqual --- .../test/functional_tests/test_entry_point.py | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/snet/cli/test/functional_tests/test_entry_point.py b/snet/cli/test/functional_tests/test_entry_point.py index 44bfa775..8bbeb6da 100644 --- a/snet/cli/test/functional_tests/test_entry_point.py +++ b/snet/cli/test/functional_tests/test_entry_point.py @@ -5,63 +5,63 @@ class TestEntryPoint(unittest.TestCase): def test_help(self): exit_status = os.system('snet --help') - assert exit_status == 0 + self.assertEqual(0, exit_status) def test_identity(self): exit_status = os.system('snet identity list') - assert exit_status == 0 + self.assertEqual(0, exit_status) def test_account(self): exit_status = os.system('snet account -h') - assert exit_status == 0 + self.assertEqual(0, exit_status) def test_channel(self): exit_status = os.system('snet channel -h') - assert exit_status == 0 + self.assertEqual(0, exit_status) def test_client(self): exit_status = os.system('snet client -h') - assert exit_status == 0 + self.assertEqual(0, exit_status) def test_contract(self): exit_status = os.system('snet contract -h') - assert exit_status == 0 + self.assertEqual(0, exit_status) def test_network(self): exit_status = os.system('snet network list') - assert exit_status == 0 + self.assertEqual(0, exit_status) def test_organization(self): exit_status = os.system('snet organization -h') - assert exit_status == 0 + self.assertEqual(0, exit_status) def test_sdk(self): exit_status = os.system('snet sdk -h') - assert exit_status == 0 + self.assertEqual(0, exit_status) def test_service(self): exit_status = os.system('snet service -h') - assert exit_status == 0 + self.assertEqual(0, exit_status) def test_session(self): exit_status = os.system('snet session -h') - assert exit_status == 0 + self.assertEqual(0, exit_status) def test_set(self): exit_status = os.system('snet set -h') - assert exit_status == 0 + self.assertEqual(0, exit_status) def test_treasurer(self): exit_status = os.system('snet treasurer -h') - assert exit_status == 0 + self.assertEqual(0, exit_status) def test_unset(self): exit_status = os.system('snet unset -h') - assert exit_status == 0 + self.assertEqual(0, exit_status) def test_version(self): exit_status = os.system('snet version') - assert exit_status == 0 + self.assertEqual(0, exit_status) if __name__ == '__main__': From df4821e27e13f65a909c7ce7c5d834005b267850 Mon Sep 17 00:00:00 2001 From: mabredin Date: Wed, 19 Jun 2024 18:30:08 +0300 Subject: [PATCH 07/12] Change URL validator Add validation when executing commands that contain URLs Remove unnecessary url validation package. Add unittest URL validation --- requirements.txt | 1 - snet/cli/commands/commands.py | 6 ++- snet/cli/commands/mpe_service.py | 4 +- snet/cli/metadata/organization.py | 4 +- .../unit_tests/test_mpe_service_metadata_1.py | 2 +- .../unit_tests/test_mpe_service_metadata_2.py | 2 +- .../cli/test/unit_tests/test_url_validator.py | 43 +++++++++++++++++++ snet/cli/utils/utils.py | 13 ++++++ 8 files changed, 68 insertions(+), 7 deletions(-) create mode 100644 snet/cli/test/unit_tests/test_url_validator.py diff --git a/requirements.txt b/requirements.txt index 7244342a..8defc27e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -19,5 +19,4 @@ jsonschema==4.0.0 eth-account==0.9.0 trezor==0.13.8 ledgerblue==0.1.48 -validators==0.28.1 snet.contracts==0.1.1 \ No newline at end of file diff --git a/snet/cli/commands/commands.py b/snet/cli/commands/commands.py index 68008e15..057286be 100644 --- a/snet/cli/commands/commands.py +++ b/snet/cli/commands/commands.py @@ -20,7 +20,7 @@ read_default_contract_address from snet.cli.utils.ipfs_utils import bytesuri_to_hash, get_from_ipfs_and_checkhash, \ hash_to_bytesuri, publish_file_in_ipfs -from snet.cli.utils.utils import DefaultAttributeObject, get_web3, serializable, type_converter, \ +from snet.cli.utils.utils import DefaultAttributeObject, get_web3, is_valid_url, serializable, type_converter, \ get_cli_version, bytes32_to_str @@ -392,6 +392,10 @@ def add_group(self): "Organization metadata json file not found ,Please check --metadata-file path ") raise e + for endpoint in self.args.endpoints: + if not is_valid_url(endpoint): + raise Exception(f"Invalid {endpoint} endpoint passed") + payment_storage_client = PaymentStorageClient(self.args.payment_channel_connection_timeout, self.args.payment_channel_request_timeout, self.args.endpoints) payment = Payment(self.args.payment_address, self.args.payment_expiration_threshold, diff --git a/snet/cli/commands/mpe_service.py b/snet/cli/commands/mpe_service.py index 7265bbec..50fdd8e3 100644 --- a/snet/cli/commands/mpe_service.py +++ b/snet/cli/commands/mpe_service.py @@ -12,7 +12,7 @@ from snet.cli.metadata.organization import OrganizationMetadata from snet.cli.metadata.service import MPEServiceMetadata, load_mpe_service_metadata, mpe_service_metadata_from_json from snet.cli.utils import ipfs_utils -from snet.cli.utils.utils import open_grpc_channel, type_converter +from snet.cli.utils.utils import is_valid_url, open_grpc_channel, type_converter class MPEServiceCommand(BlockchainCommand): @@ -120,6 +120,8 @@ def publish_proto_metadata_init(self): metadata.add_group(self.args.group_name) if self.args.endpoints: for endpoint in self.args.endpoints: + if not is_valid_url(endpoint): + raise Exception(f"Invalid {endpoint} endpoint passed") metadata.add_endpoint_to_group( self.args.group_name, endpoint) if self.args.fixed_price is not None: diff --git a/snet/cli/metadata/organization.py b/snet/cli/metadata/organization.py index b9f04684..1de99c39 100644 --- a/snet/cli/metadata/organization.py +++ b/snet/cli/metadata/organization.py @@ -3,7 +3,7 @@ from json import JSONEncoder import json -import validators +from snet.cli.utils.utils import is_valid_url class DefaultEncoder(JSONEncoder): @@ -34,7 +34,7 @@ def from_json(cls, json_data: dict): endpoints = json_data["endpoints"] if endpoints: for endpoint in endpoints: - if not validators.url(endpoint): + if not is_valid_url(endpoint): raise Exception("Invalid endpoint passed in json file") return cls(**json_data) diff --git a/snet/cli/test/unit_tests/test_mpe_service_metadata_1.py b/snet/cli/test/unit_tests/test_mpe_service_metadata_1.py index 0ab2b21f..9d8c9fe1 100644 --- a/snet/cli/test/unit_tests/test_mpe_service_metadata_1.py +++ b/snet/cli/test/unit_tests/test_mpe_service_metadata_1.py @@ -1,6 +1,6 @@ import unittest -from snet.snet_cli.metadata.service import MPEServiceMetadata +from snet.cli.metadata.service import MPEServiceMetadata class TestStringMethods(unittest.TestCase): diff --git a/snet/cli/test/unit_tests/test_mpe_service_metadata_2.py b/snet/cli/test/unit_tests/test_mpe_service_metadata_2.py index 0c264397..d218a9bf 100644 --- a/snet/cli/test/unit_tests/test_mpe_service_metadata_2.py +++ b/snet/cli/test/unit_tests/test_mpe_service_metadata_2.py @@ -6,7 +6,7 @@ import unittest from unittest.mock import patch -from snet.snet_cli.metadata.service import MPEServiceMetadata +from snet.cli.metadata.service import MPEServiceMetadata class TestMediaMethods(unittest.TestCase): diff --git a/snet/cli/test/unit_tests/test_url_validator.py b/snet/cli/test/unit_tests/test_url_validator.py new file mode 100644 index 00000000..1ae01a08 --- /dev/null +++ b/snet/cli/test/unit_tests/test_url_validator.py @@ -0,0 +1,43 @@ +import unittest + +from snet.cli.utils.utils import is_valid_url + + +class TestURLValidator(unittest.TestCase): + + def test_valid_urls(self): + valid_urls = [ + "https://www.example.com", + "http://example.com", + "ftp://ftp.example.com", + "https://localhost", + "http://127.0.0.1", + "https://[::1]", + "https://www.example.com", + "http://localhost:5432", + "https://192.168.20.20", + "https://192.168.20.20:8000", + "https://192.168.20.20:8001/get_objects", + "http://0.0.0.0:8000" + ] + for url in valid_urls: + with self.subTest(url=url): + self.assertTrue(is_valid_url(url)) + + def test_invalid_urls(self): + invalid_urls = [ + "www.example.com", + "http//example.com", + "://missing.scheme.com", + "http://", + "http://invalid_domain", + "ftp://-invalid.com", + "http://http://example.com" + ] + for url in invalid_urls: + with self.subTest(url=url): + self.assertFalse(is_valid_url(url)) + + +if __name__ == '__main__': + unittest.main() diff --git a/snet/cli/utils/utils.py b/snet/cli/utils/utils.py index c505b4fb..568bcc7a 100644 --- a/snet/cli/utils/utils.py +++ b/snet/cli/utils/utils.py @@ -2,6 +2,7 @@ import os import subprocess import functools +import re import sys import importlib.resources from importlib.metadata import distribution @@ -295,3 +296,15 @@ def find_file_by_keyword(directory, keyword): for file in files: if keyword in file: return file + + +def is_valid_url(url): + regex = re.compile( + r'^(?:http|ftp)s?://' + r'(?:(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+(?:[A-Z]{2,6}\.?|[A-Z0-9-]{2,}\.?)|' + r'localhost|' + r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}|' + r'\[?[A-F0-9]*:[A-F0-9:]+\]?)' + r'(?::\d+)?' + r'(?:/?|[/?]\S+)$', re.IGNORECASE) + return re.match(regex, url) is not None From 675eb80e83e4d53d0c7a8c53d3bd2f2cfd7592ab Mon Sep 17 00:00:00 2001 From: mabredin Date: Thu, 20 Jun 2024 11:25:40 +0300 Subject: [PATCH 08/12] Fix one line --- snet/cli/config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snet/cli/config.py b/snet/cli/config.py index d56d4e6e..4636d748 100644 --- a/snet/cli/config.py +++ b/snet/cli/config.py @@ -248,7 +248,7 @@ def setup_identity(self): def first_identity_message_and_exit(is_sdk=False): if is_sdk: print("\nPlease create your first identity by passing the 'identity_name' " - "and 'identity_type' parameters in the config.\n") + "and 'identity_type' parameters in SDK config.\n") print("The available identity types are:\n" " - 'key' (uses a required hex-encoded private key for signing)\n\n") else: From eac025da202d5cd92121186cecfea438ed34dbb1 Mon Sep 17 00:00:00 2001 From: Deralden <121487413+Deralden@users.noreply.github.com> Date: Thu, 20 Jun 2024 16:29:07 +0300 Subject: [PATCH 09/12] Github actions implementation_dev (#505) * Delete .circleci directory * gg * Update dev.yml * Update blockchain * Update reset_environment.sh * Update run_all_functional.sh * Update dev.yml * Update dev.yml * Delete .github/workflows/dev.yml * Update README.md * dev * Update dev.yml --- .circleci/config.yml | 109 ---------------------- .github/workflows/dev.yml | 73 +++++++++++++++ .github/workflows/master.yml | 73 +++++++++++++++ README.md | 4 - scripts/blockchain | 2 +- snet/cli/test/utils/reset_environment.sh | 2 +- snet/cli/test/utils/run_all_functional.sh | 6 +- 7 files changed, 151 insertions(+), 118 deletions(-) delete mode 100644 .circleci/config.yml create mode 100644 .github/workflows/dev.yml create mode 100644 .github/workflows/master.yml diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index c6f2d034..00000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,109 +0,0 @@ -version: 2 -jobs: - build: - docker: - - image: cimg/python:3.11.6-node - working_directory: ~/singnet/snet-cli - environment: - TRIGGER_BUILD_BRANCH: master - steps: - - run: - name: Update Node - command: | - node --version - python --version - curl https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash - export NVM_DIR="$HOME/.nvm" - [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm - [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" - source "$NVM_DIR/nvm.sh" - nvm install 18.18.2 - nvm alias default 18.18.2 - nvm use default - - run: - name: Install tools and ipfs - command: | - cd .. - sudo apt-get --allow-releaseinfo-change update - sudo apt-get -y install libudev-dev libusb-1.0-0-dev curl jq - # install IPFS - wget https://dist.ipfs.io/go-ipfs/v0.4.17/go-ipfs_v0.4.17_linux-amd64.tar.gz --no-check-certificate - tar xvfz go-ipfs_*.tar.gz - sudo cp ./go-ipfs/ipfs /usr/local/bin - - checkout - - run: - name: Install snet-cli - command: | - ./packages/snet_cli/scripts/blockchain install - sudo pip3 install -e ./packages/snet_cli - - run: - name: Install snet-sdk - command: | - ./packages/snet_cli/scripts/blockchain install - sudo pip3 install -e ./packages/sdk - - run: - name: Install platform-contracts from master - command: | - # Install platform-contracts (from master) - # we will deploy contracts from packages/snet_cli/test/utils/reset_enviroment.sh - cd .. - git clone https://github.com/singnet/platform-contracts - cd platform-contracts - sudo npm install -g node-gyp@8.4.1 - npm install sha3 - npm install - npm install ganache-cli@6.3.0 - npm run-script compile - - - run: - name: Build example service - command: | - cd ~/singnet - git clone https://github.com/singnet/example-service.git - cd example-service - pip3 install -r requirements.txt - sh buildproto.sh - - - - run: - name: Set up for snet daemon - command: | - cd .. - mkdir snet-daemon - cd snet-daemon - - wget https://github.com/singnet/snet-daemon/releases/download/v5.0.1/snet-daemon-v5.0.1-linux-amd64.tar.gz - tar -xvf snet-daemon-v5.0.1-linux-amd64.tar.gz - cd snet-daemon-v5.0.1-linux-amd64 - cp ~/singnet/snet-cli/packages/sdk/testcases/functional_tests/snetd.config.json ~/singnet/snet-daemon/snet-daemon-v5.0.1-linux-amd64 - - - - run: - name: Unit tests - command: | - sudo pip3 install nose - nosetests -v --with-doctest - - run: - name: Functional tests for snet-cli - command: | - cd .. - cd snet-cli - sudo npm install -g node-gyp@8.4.1 - bash -ex packages/snet_cli/test/utils/run_all_functional.sh - - - run: - name: Functional tests for sdk - command: | - bash -ex packages/sdk/testcases/utils/run_all_functional.sh - - run: - name: Trigger platform-pipeline build - command: | - if [ "$CIRCLE_BRANCH" == "$TRIGGER_BUILD_BRANCH" ] - then - curl -u ${CIRCLECI_PLATFORM_PIPELINE_TOKEN}: \ - -d build_parameters[CIRCLE_JOB]=build \ - -d build_parameters[PARENT_PROJECT_REPONAME]="$CIRCLE_PROJECT_REPONAME" \ - -d build_parameters[PARENT_BRANCH]="$CIRCLE_BRANCH" \ - -d build_parameters[PARENT_BUILD_URL]="$CIRCLE_BUILD_URL" \ - https://circleci.com/api/v1.1/project/github/singnet/platform-pipeline/tree/${TRIGGER_BUILD_BRANCH} - fi diff --git a/.github/workflows/dev.yml b/.github/workflows/dev.yml new file mode 100644 index 00000000..eb90f628 --- /dev/null +++ b/.github/workflows/dev.yml @@ -0,0 +1,73 @@ +name: tests_development +on: + # push: + # branches: [ "development" ] + pull_request: + branches: [ "development" ] + workflow_dispatch: + +jobs: + run_tests_development: + runs-on: ubuntu-latest + container: node:20-bookworm + steps: + + - name: install packs + run: | + apt update + apt install -y libudev-dev libusb-1.0-0-dev curl jq + apt install -y python3-pip python3.11-venv + + # - name: install ipfs + # run: | + # wget https://dist.ipfs.io/go-ipfs/v0.9.0/go-ipfs_v0.9.0_linux-amd64.tar.gz + # tar -xvzf go-ipfs_v0.9.0_linux-amd64.tar.gz + # bash go-ipfs/install.sh + # ipfs --version + # node --version + + - name: clone repo + uses: actions/checkout@v3 + + - name: install pip packages + run: | + pip3 install -r requirements.txt --break-system-packages + # pip3 install nose --break-system-packages + # pip3 uninstall pyreadline --break-system-packages + # pip3 install pyreadline3 --break-system-packages + + - name: install snet-cli + run: | + # ./scripts/blockchain install + pip3 install -e . --break-system-packages + + # - name: install platform-contracts + # run: | + # cd .. + # git clone https://github.com/singnet/platform-contracts.git + # cd platform-contracts + # npm install + # npm install ganache-cli + # npm run-script compile + + # - name: build example service + # run: | + # git clone https://github.com/singnet/example-service.git + # cd example-service + # pip3 install -r requirements.txt --break-system-packages + # sh buildproto.sh + + # - name: unit tests + # run: | + # cd ./snet/cli/test + # nosetests -v --with-doctest + + - name: functional tests for cli + run: | + export SNET_TEST_WALLET_PRIVATE_KEY=${{ secrets.PRIV_KEY }} + export SNET_TEST_INFURA_KEY=${{ secrets.INF_KEY }} + export FORMER_SNET_TEST_INFURA_KEY=${{ secrets.FORM_INF_KEY }} + export PIP_BREAK_SYSTEM_PACKAGES=1 + export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python + # sh -ex ./snet/cli/test/utils/run_all_functional.sh + python3 ./snet/cli/test/functional_tests/test_entry_point.py diff --git a/.github/workflows/master.yml b/.github/workflows/master.yml new file mode 100644 index 00000000..46e782c9 --- /dev/null +++ b/.github/workflows/master.yml @@ -0,0 +1,73 @@ +name: tests_master +on: + # push: + # branches: [ "master" ] + pull_request: + branches: [ "master" ] + workflow_dispatch: + +jobs: + run_tests_master: + runs-on: ubuntu-latest + container: node:20-bookworm + steps: + + - name: install packs + run: | + apt update + apt install -y libudev-dev libusb-1.0-0-dev curl jq + apt install -y python3-pip python3.11-venv + + # - name: install ipfs + # run: | + # wget https://dist.ipfs.io/go-ipfs/v0.9.0/go-ipfs_v0.9.0_linux-amd64.tar.gz + # tar -xvzf go-ipfs_v0.9.0_linux-amd64.tar.gz + # bash go-ipfs/install.sh + # ipfs --version + # node --version + + - name: clone repo + uses: actions/checkout@v3 + + - name: install pip packages + run: | + pip3 install -r requirements.txt --break-system-packages + # pip3 install nose --break-system-packages + # pip3 uninstall pyreadline --break-system-packages + # pip3 install pyreadline3 --break-system-packages + + - name: install snet-cli + run: | + # ./scripts/blockchain install + pip3 install -e . --break-system-packages + + # - name: install platform-contracts + # run: | + # cd .. + # git clone https://github.com/singnet/platform-contracts.git + # cd platform-contracts + # npm install + # npm install ganache-cli + # npm run-script compile + + # - name: build example service + # run: | + # git clone https://github.com/singnet/example-service.git + # cd example-service + # pip3 install -r requirements.txt --break-system-packages + # sh buildproto.sh + + # - name: unit tests + # run: | + # cd ./snet/cli/test + # nosetests -v --with-doctest + + - name: functional tests for cli + run: | + export SNET_TEST_WALLET_PRIVATE_KEY=${{ secrets.PRIV_KEY }} + export SNET_TEST_INFURA_KEY=${{ secrets.INF_KEY }} + export FORMER_SNET_TEST_INFURA_KEY=${{ secrets.FORM_INF_KEY }} + export PIP_BREAK_SYSTEM_PACKAGES=1 + export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python + # sh -ex ./snet/cli/test/utils/run_all_functional.sh + python3 ./snet/cli/test/functional_tests/test_entry_point.py diff --git a/README.md b/README.md index bbde3ad2..254bd0e4 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,3 @@ -# snet-cli - -[![CircleCI](https://circleci.com/gh/singnet/snet-cli.svg?style=svg)](https://circleci.com/gh/singnet/snet-cli) - SingularityNET CLI ## Package diff --git a/scripts/blockchain b/scripts/blockchain index c840c416..362be7b8 100755 --- a/scripts/blockchain +++ b/scripts/blockchain @@ -25,7 +25,7 @@ def main(): raise Exception("This script requires 'npm' to be installed and in your PATH") if target == "install": - shutil.rmtree(contract_json_dest_dir) + #shutil.rmtree(contract_json_dest_dir) subprocess.call([npm_location, "install"], cwd=blockchain_dir) diff --git a/snet/cli/test/utils/reset_environment.sh b/snet/cli/test/utils/reset_environment.sh index de7fb0b6..7f336018 100755 --- a/snet/cli/test/utils/reset_environment.sh +++ b/snet/cli/test/utils/reset_environment.sh @@ -55,5 +55,5 @@ snet set current_multipartyescrow_at 0x5c7a4290f6f8ff64c69eeffdfafc8644a4ec3a4e snet identity create snet-user rpc --network local snet session export PYTHONPATH=$cwd -python $cwd"/packages/snet_cli/test/functional_tests/mint/mint.py" +python $cwd"./snet/cli/test/functional_tests/mint/mint.py" snet account balance diff --git a/snet/cli/test/utils/run_all_functional.sh b/snet/cli/test/utils/run_all_functional.sh index 63c69ece..bd2402e2 100755 --- a/snet/cli/test/utils/run_all_functional.sh +++ b/snet/cli/test/utils/run_all_functional.sh @@ -1,5 +1,5 @@ -for f in packages/snet_cli/test/functional_tests/*.sh +for f in snet/cli/test/functional_tests/*.sh do - bash -ex packages/snet_cli/test/utils/reset_environment.sh --i-no-what-i-am-doing - bash -ex -c "cd packages/snet_cli/test/functional_tests; bash -ex `basename $f`" + bash -ex ./snet/cli/test/utils/reset_environment.sh --i-no-what-i-am-doing + bash -ex -c "cd snet/cli/test/functional_tests; bash -ex `basename $f`" done From c36c6e98878220a305b2914ba9756732789e10c3 Mon Sep 17 00:00:00 2001 From: kiruxaspb Date: Thu, 20 Jun 2024 17:46:30 +0300 Subject: [PATCH 10/12] fix test script --- snet/cli/test/utils/run_all_functional.sh | 7 ------- 1 file changed, 7 deletions(-) diff --git a/snet/cli/test/utils/run_all_functional.sh b/snet/cli/test/utils/run_all_functional.sh index 5adec7bb..2815a9cb 100755 --- a/snet/cli/test/utils/run_all_functional.sh +++ b/snet/cli/test/utils/run_all_functional.sh @@ -1,9 +1,3 @@ -<<<<<<< HEAD -for f in snet/cli/test/functional_tests/*.sh -do - bash -ex ./snet/cli/test/utils/reset_environment.sh --i-no-what-i-am-doing - bash -ex -c "cd snet/cli/test/functional_tests; bash -ex `basename $f`" -======= for f in snet/cli/test/functional_tests/script?_* do bash -ex ./snet/cli/test/utils/reset_environment.sh --i-no-what-i-am-doing @@ -14,5 +8,4 @@ for f in snet/cli/test/functional_tests/script??_* do bash -ex ./snet/cli/test/utils/reset_environment.sh --i-no-what-i-am-doing bash -ex -c "cd snet/cli/test/functional_tests; bash -ex `basename $f`" ->>>>>>> master done From bd5a17386a9bfa671ff3a18bd97e1554983d4921 Mon Sep 17 00:00:00 2001 From: Semyon Novikov Date: Wed, 17 Jul 2024 17:18:37 +0300 Subject: [PATCH 11/12] Update payment-channel-connection-timeout (#507) --- snet/cli/arguments.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snet/cli/arguments.py b/snet/cli/arguments.py index 5172a737..e9ce4b93 100644 --- a/snet/cli/arguments.py +++ b/snet/cli/arguments.py @@ -286,7 +286,7 @@ def add_organization_options(parser): p.add_argument("endpoints", nargs='*', help="Endpoints for the first group") p.add_argument("--payment-expiration-threshold", type=int, default=100, help="Payment Expiration threshold") p.add_argument("--payment-channel-storage-type", default="etcd", help="Storage channel for payment") - p.add_argument("--payment-channel-connection-timeout", default="100s", help="Payment channel connection timeout ") + p.add_argument("--payment-channel-connection-timeout", default="7s", help="Payment channel connection timeout ") p.add_argument("--payment-channel-request-timeout", default="5s", help="Payment channel request timeout") add_metadatafile_argument_for_org(p) add_p_registry_address_opt(p) From 7660f37de17141105e19606fbe3469c4e08f8ef0 Mon Sep 17 00:00:00 2001 From: Kirill Dvoretskov <65371121+kiruxaspb@users.noreply.github.com> Date: Tue, 30 Jul 2024 13:17:02 +0300 Subject: [PATCH 12/12] Upgrade version to 2.1.4 --- version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.py b/version.py index e835b9d0..df4be5e0 100644 --- a/version.py +++ b/version.py @@ -1 +1 @@ -__version__ = "2.1.3" +__version__ = "2.1.4"