From 2f12635da675a1420d99577d462e1960dfdb061b Mon Sep 17 00:00:00 2001 From: ivd Date: Fri, 4 Oct 2019 20:17:11 +0300 Subject: [PATCH 01/45] SKALE-1602 Setup tests for skale-node-cli commands --- core/config.py | 1 + core/user.py | 21 +++++--- setup.py | 2 + tests/conftest.py | 34 +++++++++++++ tests/helper.py | 20 ++++++++ tests/test_main.py | 119 +++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 190 insertions(+), 7 deletions(-) create mode 100644 tests/conftest.py create mode 100644 tests/helper.py create mode 100644 tests/test_main.py diff --git a/core/config.py b/core/config.py index c678df13..e9f5b683 100644 --- a/core/config.py +++ b/core/config.py @@ -28,6 +28,7 @@ CONFIG_FILENAME = '.skale-cli.yaml' CONFIG_FILEPATH = os.path.join(home, CONFIG_FILENAME) +SKALE_CLI_CONFIG_PATH = '.skale-cli.yaml' CURRENT_FILE_LOCATION = os.path.dirname(os.path.realpath(__file__)) diff --git a/core/user.py b/core/user.py index c529fc86..24f6213d 100644 --- a/core/user.py +++ b/core/user.py @@ -41,7 +41,6 @@ def register_user(config, username, password, token): response = post_request(url, data) if response is None: return None - if response.status_code == requests.codes.ok: cookies_text = pickle.dumps(response.cookies) config['cookies'] = cookies_text @@ -88,15 +87,23 @@ def logout_user(config): print(response.text) -def show_registration_token(short): +def get_registration_token_data(): try: with open(TOKENS_FILEPATH, encoding='utf-8') as data_file: - config = json.loads(data_file.read()) + return json.loads(data_file.read()) + except FileNotFoundError: + return None + + +def show_registration_token(short): + token_data = get_registration_token_data() + if token_data is not None: if short: - print(config["token"]) + print(token_data["token"]) else: - print(f'User registration token: {config["token"]}') - except FileNotFoundError: - err_msg = "Couldn't find registration tokens file. Check that node inited on this machine." + print(f'User registration token: {token_data["token"]}') + else: + err_msg = ("Couldn't find registration tokens file. " + "Check that node inited on this machine.") logger.error(err_msg) print(err_msg) diff --git a/setup.py b/setup.py index 45575584..aba38cde 100644 --- a/setup.py +++ b/setup.py @@ -3,6 +3,8 @@ from setuptools import setup + + def read(*parts): path = os.path.join(os.path.dirname(__file__), *parts) f = open(path, "r") diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 00000000..0eef7869 --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,34 @@ +# -*- coding: utf-8 -*- +# +# This file is part of SKALE.py +# +# Copyright (C) 2019 SKALE Labs +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with this program. If not, see . +""" SKALE config test """ + + +import mock +import pytest + + +@pytest.fixture +def config(): + config_mock = { + 'host': 'https://test.com', + 'cookies': {} + } + with mock.patch('readsettings.ReadSettings', + mock.MagicMock(return_value=config_mock)): + yield diff --git a/tests/helper.py b/tests/helper.py new file mode 100644 index 00000000..444fa85f --- /dev/null +++ b/tests/helper.py @@ -0,0 +1,20 @@ +import mock +from click.testing import CliRunner +from mock import Mock + + +def request_mock(response_mock): + request_mock = Mock(return_value=response_mock) + return request_mock + + +def run_command(command, params=[], input=''): + runner = CliRunner() + return runner.invoke(command, params, input=input) + + +def run_command_mock(mock_call_path, response_mock, + command, params=[], input=''): + with mock.patch(mock_call_path, + new=request_mock(response_mock)): + return run_command(command, params, input=input) diff --git a/tests/test_main.py b/tests/test_main.py new file mode 100644 index 00000000..1c7fd619 --- /dev/null +++ b/tests/test_main.py @@ -0,0 +1,119 @@ +import mock +import requests + +import cli.info as info +from main import version, attach, host, user_token, register, login +from tests.helper import run_command, run_command_mock + + +def test_version(config): + result = run_command(version, []) + expected = f'SKALE Node CLI version: {info.VERSION}\n' + assert result.output == expected + result = run_command(version, ['--short']) + assert result.output == f'{info.VERSION}\n' + + +def test_attach(): + result = run_command(attach) + assert result.exit_code == 2 + expected = 'Usage: attach [OPTIONS] HOST\nTry "attach --help" for help.\n\nError: Missing argument "HOST".\n' # noqa + assert result.output == expected + + result = run_command(attach, ['darova']) + assert result.exit_code == 0 + assert result.output == 'Provided SKALE node host is not valid\n' + + result = run_command(attach, ['http://127.0.0.1', '--skip-check']) + assert result.output == 'SKALE host: http://127.0.0.1:3007\n' + + +def test_host(): + result = run_command(host, []) + assert result.output == 'SKALE node host: http://127.0.0.1:3007\n' + result = run_command(host, ['--reset']) + assert result.output == 'Host removed, cookies cleaned.\n' + + +def test_user_token(config): + test_token = '231test-token' + with mock.patch('core.user.get_registration_token_data', + new=mock.MagicMock(return_value={'token': test_token})): + result = run_command(user_token, []) + assert result.output == f'User registration token: {test_token}\n' + result = run_command(user_token, ['--short']) + assert result.output == '231test-token\n' + + with mock.patch('core.user.get_registration_token_data', + new=mock.MagicMock(return_value=None)): + result = run_command(user_token, []) + assert result.exit_code == 0 + print(result.output) + assert result.output == ("Couldn't find registration tokens file. " + "Check that node inited on this machine.\n") + + +def test_register(config): + response_mock = mock.MagicMock() + response_mock.status_code = requests.codes.ok + response_mock.cookies = 'darova' + result = run_command_mock('core.user.post_request', + response_mock, + register, + input="test\n qwerty1\n token") + expected = ( + 'Enter username: test\n' + 'Enter password: \n' + 'Enter one-time token: \n' + 'User created: test\n' + 'Success, cookies saved.\n' + ) + assert result.exit_code == 0 + assert result.output == expected + + response_mock.status_code = -1 + response_mock.text = '{"errors": [{"msg": "Token not match"}]}' + result = run_command_mock('core.user.post_request', + response_mock, + register, + input="test\n qwerty1\n token") + assert result.exit_code == 0 + expected = ( + 'Enter username: test\n' + 'Enter password: \n' + 'Enter one-time token: \n' + 'Registration failed: {"errors": [{"msg": "Token not match"}]}\n' + ) + assert expected == result.output + + +def test_login(config): + response_mock = mock.MagicMock() + response_mock.status_code = requests.codes.ok + response_mock.cookies = 'darova' + result = run_command_mock('core.user.post_request', + response_mock, + login, + input="test\n qwerty1\n token") + expected = ( + 'Enter username: test\n' + 'Enter password: \n' + 'Success, cookies saved.\n' + ) + assert result.exit_code == 0 + assert result.output == expected + + response_mock.status_code = -1 + response_mock.text = 'Darova' + result = run_command_mock('core.user.post_request', + response_mock, + login, + input="test\n qwerty1\n token") + result = run_command(login, input="test\n qwerty1\n token") + assert result.exit_code == 0 + expected = ( + 'Enter username: test\n' + 'Enter password: \n' + 'Authorization failed: {"errors": [{"msg": "Token not match"}]}\n' + ) + assert expected == result.output From d4b995be8b74540dc6078f1dfa56b68ed88787b7 Mon Sep 17 00:00:00 2001 From: ivd Date: Sat, 5 Oct 2019 14:43:27 +0300 Subject: [PATCH 02/45] Add new test to cli/main_test.py --- core/user.py | 2 +- tests/{test_main.py => cli/main_test.py} | 68 +++++++++++++++++++++--- 2 files changed, 62 insertions(+), 8 deletions(-) rename tests/{test_main.py => cli/main_test.py} (65%) diff --git a/core/user.py b/core/user.py index 24f6213d..71bf6989 100644 --- a/core/user.py +++ b/core/user.py @@ -83,7 +83,7 @@ def logout_user(config): clean_cookies(config) print('Cookies removed') else: - print('Logout failed') + print('Logout failed:') print(response.text) diff --git a/tests/test_main.py b/tests/cli/main_test.py similarity index 65% rename from tests/test_main.py rename to tests/cli/main_test.py index 1c7fd619..927b6018 100644 --- a/tests/test_main.py +++ b/tests/cli/main_test.py @@ -2,7 +2,7 @@ import requests import cli.info as info -from main import version, attach, host, user_token, register, login +from main import version, attach, host, user_token, register, login, logout from tests.helper import run_command, run_command_mock @@ -56,7 +56,7 @@ def test_user_token(config): def test_register(config): response_mock = mock.MagicMock() response_mock.status_code = requests.codes.ok - response_mock.cookies = 'darova' + response_mock.cookies = 'cookies' result = run_command_mock('core.user.post_request', response_mock, register, @@ -90,7 +90,7 @@ def test_register(config): def test_login(config): response_mock = mock.MagicMock() response_mock.status_code = requests.codes.ok - response_mock.cookies = 'darova' + response_mock.cookies = 'simple-cookies' result = run_command_mock('core.user.post_request', response_mock, login, @@ -104,16 +104,70 @@ def test_login(config): assert result.output == expected response_mock.status_code = -1 - response_mock.text = 'Darova' + response_mock.text = '{"errors": [{"msg": "Test error"}]}' result = run_command_mock('core.user.post_request', response_mock, login, - input="test\n qwerty1\n token") - result = run_command(login, input="test\n qwerty1\n token") + input="test\n qwerty1") assert result.exit_code == 0 expected = ( 'Enter username: test\n' 'Enter password: \n' - 'Authorization failed: {"errors": [{"msg": "Token not match"}]}\n' + 'Authorization failed: {"errors": [{"msg": "Test error"}]}\n' + ) + print(result.output) + assert expected == result.output + + +def test_logout(): + response_mock = mock.MagicMock() + response_mock.status_code = requests.codes.ok + response_mock.cookies = 'simple-cookies' + result = run_command_mock('core.user.get_request', + response_mock, + logout, + input="test\n qwerty1\n token") + assert result.exit_code == 0 + expected = 'Cookies removed\n' + assert result.output == expected + + response_mock.status_code = -1 + response_mock.text = '{"errors": [{"msg": "Test error"}]}' + result = run_command_mock('core.user.get_request', + response_mock, + logout, + input="test\n qwerty1") + assert result.exit_code == 0 + expected = ( + 'Logout failed:\n' + '{"errors": [{"msg": "Test error"}]}\n' + ) + print(result.output) + assert expected == result.output + + +def test_wallet_info(): + response_mock = mock.MagicMock() + response_mock.status_code = requests.codes.ok + response_mock.json = mock.Mock(return_value={'data': 'wallet_data'}) + + result = run_command_mock('core.user.get_request', + response_mock, + logout) + assert result.exit_code == 0 + expected = 'Cookies removed\n' + assert result.output == expected + + response_mock.status_code = -1 + response_mock.text = '{"errors": [{"msg": "Test error"}]}' + result = run_command_mock('core.user.get_request', + response_mock, + logout, + input="test\n qwerty1") + assert result.exit_code == 0 + expected = ( + 'Logout failed:\n' + '{"errors": [{"msg": "Test error"}]}\n' ) + print(result.output) assert expected == result.output From e12e008cb28feaae1770d76b3994243311f4f8f7 Mon Sep 17 00:00:00 2001 From: ivd Date: Mon, 7 Oct 2019 21:22:56 +0300 Subject: [PATCH 03/45] Add new test to main cli commands --- core/helper.py | 18 +++++++----- core/wallet.py | 1 + main.py | 8 ++++-- tests/cli/main_test.py | 65 ++++++++++++++++++++++++------------------ tests/conftest.py | 15 ---------- tools/helper.py | 7 +++++ 6 files changed, 61 insertions(+), 53 deletions(-) diff --git a/core/helper.py b/core/helper.py index 4c018e63..1f8577d1 100644 --- a/core/helper.py +++ b/core/helper.py @@ -30,13 +30,14 @@ import logging.handlers as py_handlers from logging import Formatter -from readsettings import ReadSettings -from core.config import CONFIG_FILEPATH, TEXT_FILE, SKALE_NODE_UI_LOCALHOST, SKALE_NODE_UI_PORT, \ +from core.config import TEXT_FILE, SKALE_NODE_UI_LOCALHOST, SKALE_NODE_UI_PORT, \ LONG_LINE, URLS, HOST_OS, MAC_OS_SYSTEM_NAME from configs.cli_logger import LOG_FORMAT, LOG_BACKUP_COUNT, LOG_FILE_SIZE_BYTES, LOG_FILEPATH, \ DEBUG_LOG_FILEPATH +from tools.helper import session_config -config = ReadSettings(CONFIG_FILEPATH) + +config = session_config() logger = logging.getLogger(__name__) @@ -49,15 +50,18 @@ def safe_get_config(config, key): return None +def cookies_exists(): + return safe_get_config(config, 'cookies') is not None + + def login_required(f): @wraps(f) def inner(*args, **kwargs): - cookies_text = safe_get_config(config, 'cookies') - if not cookies_text: + if cookies_exists(): + return f(*args, **kwargs) + else: TEXTS = safe_load_texts() print(TEXTS['service']['unauthorized']) - else: - return f(*args, **kwargs) return inner diff --git a/core/wallet.py b/core/wallet.py index 7b9d04dc..a87fbb5c 100644 --- a/core/wallet.py +++ b/core/wallet.py @@ -37,6 +37,7 @@ def set_wallet_by_pk(private_key): def get_wallet_info(config, format): + assert False, config host, cookies = get_node_creds(config) url = construct_url(host, URLS['wallet_info']) diff --git a/main.py b/main.py index 73ab7fef..41b12ca8 100644 --- a/main.py +++ b/main.py @@ -21,7 +21,6 @@ import sys import logging import inspect -from readsettings import ReadSettings from cli import __version__ from cli.info import BUILD_DATETIME, COMMIT, BRANCH, OS, VERSION @@ -33,14 +32,16 @@ from core.helper import (login_required, safe_load_texts, local_only, no_node, init_default_logger) -from core.config import CONFIG_FILEPATH, LONG_LINE +from core.config import LONG_LINE from core.wallet import get_wallet_info, set_wallet_by_pk from core.user import (register_user, login_user, logout_user, show_registration_token) from core.host import (test_host, show_host, fix_url, reset_host, init_logs_dir) +from tools.helper import session_config -config = ReadSettings(CONFIG_FILEPATH) + +config = session_config() TEXTS = safe_load_texts() logger = logging.getLogger(__name__) @@ -164,6 +165,7 @@ def wallet(): @click.option('--format', '-f', type=click.Choice(['json', 'text'])) @login_required def wallet_info(format): + config = session_config() get_wallet_info(config, format) diff --git a/tests/cli/main_test.py b/tests/cli/main_test.py index 927b6018..eae90264 100644 --- a/tests/cli/main_test.py +++ b/tests/cli/main_test.py @@ -1,9 +1,30 @@ import mock +import pytest import requests import cli.info as info -from main import version, attach, host, user_token, register, login, logout + +from mock import MagicMock, Mock +from main import (user, version, attach, host, user_token, + register, login, wallet) from tests.helper import run_command, run_command_mock +import main + + +@pytest.fixture +def config(): + config_mock = { + 'host': 'https://test.com', + 'cookies': {'cookie_key': 'cookie_value'} + } + with mock.patch('tools.helper.session_config', + MagicMock(return_value=config_mock)): + yield + + +@pytest.fixture +def skip_auth(monkeypatch): + monkeypatch.setattr('core.helper.cookies_exists', Mock(return_value=True)) def test_version(config): @@ -38,14 +59,14 @@ def test_host(): def test_user_token(config): test_token = '231test-token' with mock.patch('core.user.get_registration_token_data', - new=mock.MagicMock(return_value={'token': test_token})): + new=MagicMock(return_value={'token': test_token})): result = run_command(user_token, []) assert result.output == f'User registration token: {test_token}\n' result = run_command(user_token, ['--short']) assert result.output == '231test-token\n' with mock.patch('core.user.get_registration_token_data', - new=mock.MagicMock(return_value=None)): + new=MagicMock(return_value=None)): result = run_command(user_token, []) assert result.exit_code == 0 print(result.output) @@ -54,7 +75,7 @@ def test_user_token(config): def test_register(config): - response_mock = mock.MagicMock() + response_mock = MagicMock() response_mock.status_code = requests.codes.ok response_mock.cookies = 'cookies' result = run_command_mock('core.user.post_request', @@ -88,7 +109,7 @@ def test_register(config): def test_login(config): - response_mock = mock.MagicMock() + response_mock = MagicMock() response_mock.status_code = requests.codes.ok response_mock.cookies = 'simple-cookies' result = run_command_mock('core.user.post_request', @@ -120,12 +141,13 @@ def test_login(config): def test_logout(): - response_mock = mock.MagicMock() + response_mock = MagicMock() response_mock.status_code = requests.codes.ok response_mock.cookies = 'simple-cookies' result = run_command_mock('core.user.get_request', response_mock, - logout, + user, + ['logout'], input="test\n qwerty1\n token") assert result.exit_code == 0 expected = 'Cookies removed\n' @@ -135,39 +157,26 @@ def test_logout(): response_mock.text = '{"errors": [{"msg": "Test error"}]}' result = run_command_mock('core.user.get_request', response_mock, - logout, + user, + ['logout'], input="test\n qwerty1") assert result.exit_code == 0 expected = ( 'Logout failed:\n' '{"errors": [{"msg": "Test error"}]}\n' ) - print(result.output) assert expected == result.output -def test_wallet_info(): - response_mock = mock.MagicMock() +def test_wallet_info(skip_auth, config): + response_mock = MagicMock({'host': 'test.com'}) response_mock.status_code = requests.codes.ok - response_mock.json = mock.Mock(return_value={'data': 'wallet_data'}) - + response_mock.json = Mock(return_value={'data': 'wallet_data'}) result = run_command_mock('core.user.get_request', response_mock, - logout) + main.wallet, + ['info']) assert result.exit_code == 0 expected = 'Cookies removed\n' - assert result.output == expected - - response_mock.status_code = -1 - response_mock.text = '{"errors": [{"msg": "Test error"}]}' - result = run_command_mock('core.user.get_request', - response_mock, - logout, - input="test\n qwerty1") - assert result.exit_code == 0 - expected = ( - 'Logout failed:\n' - '{"errors": [{"msg": "Test error"}]}\n' - ) print(result.output) - assert expected == result.output + assert result.output == expected diff --git a/tests/conftest.py b/tests/conftest.py index 0eef7869..9002a3c8 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -17,18 +17,3 @@ # You should have received a copy of the GNU Lesser General Public License # along with this program. If not, see . """ SKALE config test """ - - -import mock -import pytest - - -@pytest.fixture -def config(): - config_mock = { - 'host': 'https://test.com', - 'cookies': {} - } - with mock.patch('readsettings.ReadSettings', - mock.MagicMock(return_value=config_mock)): - yield diff --git a/tools/helper.py b/tools/helper.py index e27f7200..65a93930 100644 --- a/tools/helper.py +++ b/tools/helper.py @@ -25,6 +25,9 @@ import json from jinja2 import Environment +from readsettings import ReadSettings + +from core.config import CONFIG_FILEPATH logger = logging.getLogger(__name__) @@ -79,3 +82,7 @@ def read_file(path): def get_username(): return os.environ.get('USERNAME') or os.environ.get('USER') + + +def session_config(): + return ReadSettings(CONFIG_FILEPATH) From c93343d4af19067c20b5ef6733a5e4387d3cbd62 Mon Sep 17 00:00:00 2001 From: ivd Date: Tue, 8 Oct 2019 13:16:38 +0300 Subject: [PATCH 04/45] Add tests to all main cli commands --- .travis.yml | 14 ++++++--- core/config.py | 5 ++- core/helper.py | 7 +++-- core/wallet.py | 6 ++-- main.py | 6 +++- tests/cli/main_test.py | 69 +++++++++++++++++++++++++++++++----------- tests/conftest.py | 11 +++++++ 7 files changed, 86 insertions(+), 32 deletions(-) diff --git a/.travis.yml b/.travis.yml index dd485874..9773ef07 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,11 +5,17 @@ cache: pip install: - pip install -r requirements.txt - pip install -r requirements-dev.txt -before_script: - - "flake8 ." +install: + - pip install codecov pytest pytest-cov + - pip install -e . + - pip install -e .[dev] jobs: include: - #- stage: test + - stage: test + script: + - CONFIG_FILEPATH='.skale-cli.yaml' py.test tests/ + after_script: + - codecov -t $CODECOV_TOKEN - stage: deploy if: branch IN (develop, beta, stable, master) script: @@ -60,4 +66,4 @@ jobs: - master - stable - develop - - beta \ No newline at end of file + - beta diff --git a/core/config.py b/core/config.py index e9f5b683..469c3ee9 100644 --- a/core/config.py +++ b/core/config.py @@ -26,9 +26,8 @@ home = str(Path.home()) -CONFIG_FILENAME = '.skale-cli.yaml' -CONFIG_FILEPATH = os.path.join(home, CONFIG_FILENAME) -SKALE_CLI_CONFIG_PATH = '.skale-cli.yaml' +CONFIG_FILEPATH = os.environ.get('CONFIG_FILEPATH', None) or \ + os.path.join(home, '.skale-cli.yaml') CURRENT_FILE_LOCATION = os.path.dirname(os.path.realpath(__file__)) diff --git a/core/helper.py b/core/helper.py index 1f8577d1..5274bfc2 100644 --- a/core/helper.py +++ b/core/helper.py @@ -54,6 +54,10 @@ def cookies_exists(): return safe_get_config(config, 'cookies') is not None +def host_exists(): + return safe_get_config(config, 'host') is not None + + def login_required(f): @wraps(f) def inner(*args, **kwargs): @@ -69,8 +73,7 @@ def inner(*args, **kwargs): def local_only(f): @wraps(f) def inner(*args, **kwargs): - host = safe_get_config(config, 'host') - if host: + if host_exists(): print('This command couldn\'t be executed on the remote SKALE host.') else: if HOST_OS == MAC_OS_SYSTEM_NAME: diff --git a/core/wallet.py b/core/wallet.py index a87fbb5c..0211d8c4 100644 --- a/core/wallet.py +++ b/core/wallet.py @@ -37,7 +37,6 @@ def set_wallet_by_pk(private_key): def get_wallet_info(config, format): - assert False, config host, cookies = get_node_creds(config) url = construct_url(host, URLS['wallet_info']) @@ -45,9 +44,8 @@ def get_wallet_info(config, format): if response is None: return None - json = response.json() - data = json['data'] - + json_data = response.json() + data = json_data['data'] if format == 'json': print(data) else: diff --git a/main.py b/main.py index 41b12ca8..2fdbf323 100644 --- a/main.py +++ b/main.py @@ -41,7 +41,6 @@ from tools.helper import session_config -config = session_config() TEXTS = safe_load_texts() logger = logging.getLogger(__name__) @@ -79,6 +78,7 @@ def info(): @click.argument('host') @click.option('--skip-check', is_flag=True) def attach(host, skip_check): + config = session_config() host = fix_url(host) if not host: return @@ -93,6 +93,7 @@ def attach(host, skip_check): @cli.command('host', help="Get SKALE node endpoint") @click.option('--reset', is_flag=True) def host(reset): + config = session_config() if reset: reset_host(config) return @@ -132,6 +133,7 @@ def user_token(short): hide_input=True ) def register(username, password, token): + config = session_config() register_user(config, username, password, token) @@ -148,11 +150,13 @@ def register(username, password, token): hide_input=True ) def login(username, password): + config = session_config() login_user(config, username, password) @user.command('logout', help="Logout from SKALE node") def logout(): + config = session_config() logout_user(config) diff --git a/tests/cli/main_test.py b/tests/cli/main_test.py index eae90264..0256e668 100644 --- a/tests/cli/main_test.py +++ b/tests/cli/main_test.py @@ -8,23 +8,16 @@ from main import (user, version, attach, host, user_token, register, login, wallet) from tests.helper import run_command, run_command_mock -import main @pytest.fixture -def config(): - config_mock = { - 'host': 'https://test.com', - 'cookies': {'cookie_key': 'cookie_value'} - } - with mock.patch('tools.helper.session_config', - MagicMock(return_value=config_mock)): - yield +def skip_auth(monkeypatch): + monkeypatch.setattr('core.helper.cookies_exists', Mock(return_value=True)) @pytest.fixture -def skip_auth(monkeypatch): - monkeypatch.setattr('core.helper.cookies_exists', Mock(return_value=True)) +def skip_local_only(monkeypatch): + monkeypatch.setattr('core.helper.host_exists', Mock(return_value=False)) def test_version(config): @@ -56,7 +49,7 @@ def test_host(): assert result.output == 'Host removed, cookies cleaned.\n' -def test_user_token(config): +def test_user_token(skip_local_only): test_token = '231test-token' with mock.patch('core.user.get_registration_token_data', new=MagicMock(return_value={'token': test_token})): @@ -168,15 +161,55 @@ def test_logout(): assert expected == result.output -def test_wallet_info(skip_auth, config): - response_mock = MagicMock({'host': 'test.com'}) +def test_wallet_info(config): + response_data = { + 'data': { + 'address': 'simple_address', + 'eth_balance': 13, + 'skale_balance': 123 + } + } + response_mock = MagicMock() response_mock.status_code = requests.codes.ok - response_mock.json = Mock(return_value={'data': 'wallet_data'}) - result = run_command_mock('core.user.get_request', + response_mock.json = Mock(return_value=response_data) + result = run_command_mock('core.wallet.get_request', response_mock, - main.wallet, + wallet, ['info']) assert result.exit_code == 0 expected = 'Cookies removed\n' - print(result.output) + expected = ( + '--------------------------------------------------\n' + 'Address: simple_address\n' + 'ETH balance: 13 ETH\n' + 'SKALE balance: 123 SKALE\n' + '--------------------------------------------------\n' + ) assert result.output == expected + + result = run_command_mock('core.wallet.get_request', + response_mock, + wallet, + ['info', '--format', 'json']) + assert result.exit_code == 0 + expected = ( + "{'address': 'simple_address', " + "'eth_balance': 13, 'skale_balance': 123}\n" + ) + assert result.output == expected + + +def test_set_wallet(skip_local_only, skip_auth): + with mock.patch('skale.utils.helper.private_key_to_address', + MagicMock(return_value='0xaddress')): + with mock.patch('core.wallet.write_json'): + result = run_command(wallet, ['set'], + input=('0xabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcd' + 'eeabcdeabcdeabcdeabcdeabc')) + assert result.exit_code == 0 + print(repr(result.output)) + assert result.output == ( + 'Enter private key: \n' + 'Local wallet updated: ' + '0xECaf17d13C3c995284FCDBCc0f2f123eB92f60C6\n' + ) diff --git a/tests/conftest.py b/tests/conftest.py index 9002a3c8..47f86a70 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -17,3 +17,14 @@ # You should have received a copy of the GNU Lesser General Public License # along with this program. If not, see . """ SKALE config test """ + +import pytest +from readsettings import ReadSettings + + +@pytest.fixture +def config(monkeypatch): + TEST_PATH = '.skale-cli.yaml' + config = ReadSettings(TEST_PATH) + config['host'] = 'https://test.com' + config['cookies'] = b'\x80\x03}q\x00X\n\x00\x00\x00cookie_keyq\x01X\x0c\x00\x00\x00cookie_valueq\x02s.' # noqa From 64e785655dc23f426fe990c1ae9b231e93a55694 Mon Sep 17 00:00:00 2001 From: ivd Date: Tue, 8 Oct 2019 13:24:20 +0300 Subject: [PATCH 05/45] Fix travis duplicate install block --- .travis.yml | 4 ---- requirements-dev.txt | 3 ++- tests/cli/main_test.py | 3 ++- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index 9773ef07..dc93d0fd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,10 +5,6 @@ cache: pip install: - pip install -r requirements.txt - pip install -r requirements-dev.txt -install: - - pip install codecov pytest pytest-cov - - pip install -e . - - pip install -e .[dev] jobs: include: - stage: test diff --git a/requirements-dev.txt b/requirements-dev.txt index 36bedd3c..09b51f80 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,4 +1,5 @@ PyInstaller==3.5 boto3==1.9.233 flake8==3.7.8 -bumpversion==0.5.3 \ No newline at end of file +bumpversion==0.5.3 +pytest==5.2.1 diff --git a/tests/cli/main_test.py b/tests/cli/main_test.py index 0256e668..d5652a08 100644 --- a/tests/cli/main_test.py +++ b/tests/cli/main_test.py @@ -204,7 +204,8 @@ def test_set_wallet(skip_local_only, skip_auth): MagicMock(return_value='0xaddress')): with mock.patch('core.wallet.write_json'): result = run_command(wallet, ['set'], - input=('0xabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcd' + input=('0xabcdeabcdeabcdeabcdeabc' + 'deabcdeabcdeabcd' 'eeabcdeabcdeabcdeabcdeabc')) assert result.exit_code == 0 print(repr(result.output)) From 6695dbefd40a2d420bdc141a68eee8f6fb991ce8 Mon Sep 17 00:00:00 2001 From: ivd Date: Tue, 8 Oct 2019 14:07:15 +0300 Subject: [PATCH 06/45] Add run-tests.sh script --- .travis.yml | 4 +++- scripts/run-tests.sh | 6 ++++++ tests/cli/main_test.py | 26 +++++++++++--------------- 3 files changed, 20 insertions(+), 16 deletions(-) create mode 100755 scripts/run-tests.sh diff --git a/.travis.yml b/.travis.yml index dc93d0fd..1f705524 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,6 @@ language: python +os: linux +dist: bionic python: - '3.6' cache: pip @@ -9,7 +11,7 @@ jobs: include: - stage: test script: - - CONFIG_FILEPATH='.skale-cli.yaml' py.test tests/ + - bash scripts/run-tests.sh after_script: - codecov -t $CODECOV_TOKEN - stage: deploy diff --git a/scripts/run-tests.sh b/scripts/run-tests.sh new file mode 100755 index 00000000..0a8ecc0f --- /dev/null +++ b/scripts/run-tests.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" +PROJECT_DIR=$(dirname $DIR) + +CONFIG_FILEPATH='.skale-cli.yaml' py.test tests/ $@ diff --git a/tests/cli/main_test.py b/tests/cli/main_test.py index d5652a08..949b0d17 100644 --- a/tests/cli/main_test.py +++ b/tests/cli/main_test.py @@ -5,8 +5,7 @@ import cli.info as info from mock import MagicMock, Mock -from main import (user, version, attach, host, user_token, - register, login, wallet) +from main import (user, version, attach, host, wallet) from tests.helper import run_command, run_command_mock @@ -53,14 +52,14 @@ def test_user_token(skip_local_only): test_token = '231test-token' with mock.patch('core.user.get_registration_token_data', new=MagicMock(return_value={'token': test_token})): - result = run_command(user_token, []) + result = run_command(user, ['token']) assert result.output == f'User registration token: {test_token}\n' - result = run_command(user_token, ['--short']) + result = run_command(user, ['token', '--short']) assert result.output == '231test-token\n' with mock.patch('core.user.get_registration_token_data', new=MagicMock(return_value=None)): - result = run_command(user_token, []) + result = run_command(user, ['token']) assert result.exit_code == 0 print(result.output) assert result.output == ("Couldn't find registration tokens file. " @@ -73,7 +72,7 @@ def test_register(config): response_mock.cookies = 'cookies' result = run_command_mock('core.user.post_request', response_mock, - register, + user, ['register'], input="test\n qwerty1\n token") expected = ( 'Enter username: test\n' @@ -89,7 +88,7 @@ def test_register(config): response_mock.text = '{"errors": [{"msg": "Token not match"}]}' result = run_command_mock('core.user.post_request', response_mock, - register, + user, ['register'], input="test\n qwerty1\n token") assert result.exit_code == 0 expected = ( @@ -107,7 +106,7 @@ def test_login(config): response_mock.cookies = 'simple-cookies' result = run_command_mock('core.user.post_request', response_mock, - login, + user, ['login'], input="test\n qwerty1\n token") expected = ( 'Enter username: test\n' @@ -121,7 +120,7 @@ def test_login(config): response_mock.text = '{"errors": [{"msg": "Test error"}]}' result = run_command_mock('core.user.post_request', response_mock, - login, + user, ['login'], input="test\n qwerty1") assert result.exit_code == 0 expected = ( @@ -139,8 +138,7 @@ def test_logout(): response_mock.cookies = 'simple-cookies' result = run_command_mock('core.user.get_request', response_mock, - user, - ['logout'], + user, ['logout'], input="test\n qwerty1\n token") assert result.exit_code == 0 expected = 'Cookies removed\n' @@ -150,8 +148,7 @@ def test_logout(): response_mock.text = '{"errors": [{"msg": "Test error"}]}' result = run_command_mock('core.user.get_request', response_mock, - user, - ['logout'], + user, ['logout'], input="test\n qwerty1") assert result.exit_code == 0 expected = ( @@ -174,8 +171,7 @@ def test_wallet_info(config): response_mock.json = Mock(return_value=response_data) result = run_command_mock('core.wallet.get_request', response_mock, - wallet, - ['info']) + wallet, ['info']) assert result.exit_code == 0 expected = 'Cookies removed\n' expected = ( From 52a68f0be9008394379d4e9575f6fca4fa4fc0b8 Mon Sep 17 00:00:00 2001 From: ivd Date: Tue, 8 Oct 2019 16:44:20 +0300 Subject: [PATCH 07/45] Fix setup.py --- .travis.yml | 5 ++-- setup.py | 61 +++++++++++++++++++++++++++++++++++++----- tests/cli/main_test.py | 10 ------- tests/conftest.py | 12 +++++++++ 4 files changed, 68 insertions(+), 20 deletions(-) diff --git a/.travis.yml b/.travis.yml index 1f705524..ea0b037b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,7 @@ language: python os: linux dist: bionic -python: - - '3.6' +python: '3.6' cache: pip install: - pip install -r requirements.txt @@ -11,7 +10,7 @@ jobs: include: - stage: test script: - - bash scripts/run-tests.sh + - bash scripts/run-tests.sh after_script: - codecov -t $CODECOV_TOKEN - stage: deploy diff --git a/setup.py b/setup.py index aba38cde..4e0678bb 100644 --- a/setup.py +++ b/setup.py @@ -1,8 +1,6 @@ import os import re -from setuptools import setup - - +from setuptools import find_packages, setup def read(*parts): @@ -13,18 +11,67 @@ def read(*parts): def find_version(*file_paths): version_file = read(*file_paths) - version_match = re.search(r"^__version__ = ['\"]([^'\"]*)['\"]", version_file, re.M) + version_match = re.search(r"^__version__ = ['\"]([^'\"]*)['\"]", + version_file, re.M) if version_match: return version_match.group(1) raise RuntimeError("Couldn't parse version from file.") +extras_require = { + 'linter': [ + "flake8==3.4.1", + "isort>=4.2.15,<4.3.5", + ], + 'dev': [ + "bumpversion==0.5.3", + "pytest==5.2.1", + "boto3==1.9.233", + "twine==1.12.1", + "when-changed", + "pytest-cov==2.7.1" + ] +} + +extras_require['dev'] = ( + extras_require['linter'] + extras_require['dev'] +) + + setup( name='skale-node-cli', - # *IMPORTANT*: Don't manually change the version here. Use the 'bumpversion' utility. + # *IMPORTANT*: Don't manually change the version here. + # Use the 'bumpversion' utility instead. version=find_version("cli", "__init__.py"), include_package_data=True, + description='SKALE client tools', + long_description_markdown_filename='README.md', + author='SKALE Labs', + author_email='support@skalelabs.com', + url='https://github.com/skalenetwork/skale-node-cli', install_requires=[ - 'click', - ] + "click==7.0", + "confuse", + "readsettings==3.4.0", + "web3==4.9.2", + "texttable==1.6.2", + "python-dateutil==2.8.0", + "Jinja2==2.10.1", + "skale-py==0.82.0", + "eth-hash==0.2.0", + "pycryptodome==3.8.2", + "psutil==5.6.3" + ], + python_requires='>=3.6,<4', + extras_require=extras_require, + + keywords=['skale', 'cli'], + packages=find_packages(exclude=['tests']), + classifiers=[ + 'Development Status :: 2 - Pre-Alpha', + 'Intended Audience :: Developers', + 'License :: OSI Approved :: GNU Lesser General Public License v3 (LGPLv3)', + 'Natural Language :: English', + 'Programming Language :: Python :: 3.6', + ], ) diff --git a/tests/cli/main_test.py b/tests/cli/main_test.py index 949b0d17..c154c167 100644 --- a/tests/cli/main_test.py +++ b/tests/cli/main_test.py @@ -9,16 +9,6 @@ from tests.helper import run_command, run_command_mock -@pytest.fixture -def skip_auth(monkeypatch): - monkeypatch.setattr('core.helper.cookies_exists', Mock(return_value=True)) - - -@pytest.fixture -def skip_local_only(monkeypatch): - monkeypatch.setattr('core.helper.host_exists', Mock(return_value=False)) - - def test_version(config): result = run_command(version, []) expected = f'SKALE Node CLI version: {info.VERSION}\n' diff --git a/tests/conftest.py b/tests/conftest.py index 47f86a70..8421280a 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -19,9 +19,21 @@ """ SKALE config test """ import pytest + +from mock import Mock from readsettings import ReadSettings +@pytest.fixture +def skip_auth(monkeypatch): + monkeypatch.setattr('core.helper.cookies_exists', Mock(return_value=True)) + + +@pytest.fixture +def skip_local_only(monkeypatch): + monkeypatch.setattr('core.helper.host_exists', Mock(return_value=False)) + + @pytest.fixture def config(monkeypatch): TEST_PATH = '.skale-cli.yaml' From 37d0864bf5f94d7d3cd9153f4f683399238eca9d Mon Sep 17 00:00:00 2001 From: ivd Date: Tue, 8 Oct 2019 16:52:30 +0300 Subject: [PATCH 08/45] Change setup py requirements --- .travis.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index ea0b037b..4edb8d5d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,8 +4,9 @@ dist: bionic python: '3.6' cache: pip install: - - pip install -r requirements.txt - - pip install -r requirements-dev.txt + - pip install -e . + - pip install -e .[dev] + - python setup.py install jobs: include: - stage: test From e2b3c3ec37b76de770769aaef6fcb4804b86e500 Mon Sep 17 00:00:00 2001 From: ivd Date: Tue, 8 Oct 2019 21:06:11 +0300 Subject: [PATCH 09/45] Cover schains, containers and logs cli commands --- .travis.yml | 2 +- cli/node.py | 6 +-- tests/cli/containers_test.py | 73 +++++++++++++++++++++++++++++++++++ tests/cli/logs_test.py | 23 +++++++++++ tests/cli/main_test.py | 1 - tests/cli/schains_test.py | 75 ++++++++++++++++++++++++++++++++++++ tests/helper.py | 13 ++++++- 7 files changed, 187 insertions(+), 6 deletions(-) create mode 100644 tests/cli/containers_test.py create mode 100644 tests/cli/logs_test.py create mode 100644 tests/cli/schains_test.py diff --git a/.travis.yml b/.travis.yml index 4edb8d5d..e7892679 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,7 +6,7 @@ cache: pip install: - pip install -e . - pip install -e .[dev] - - python setup.py install + - export PYTHONPATH=$PYTHONPATH:$(pwd) jobs: include: - stage: test diff --git a/cli/node.py b/cli/node.py index 9236a5f2..b865992d 100644 --- a/cli/node.py +++ b/cli/node.py @@ -21,7 +21,6 @@ from urllib.parse import urlparse import click -from readsettings import ReadSettings from skale.utils.random_names.generator import generate_random_node_name @@ -30,10 +29,11 @@ from core.host import install_host_dependencies from core.helper import (abort_if_false, local_only, login_required, safe_load_texts) -from core.config import CONFIG_FILEPATH, DEFAULT_DB_USER, DEFAULT_DB_PORT +from core.config import DEFAULT_DB_USER, DEFAULT_DB_PORT from configs.node import DEFAULT_NODE_BASE_PORT +from tools.helper import session_config -config = ReadSettings(CONFIG_FILEPATH) +config = session_config() TEXTS = safe_load_texts() diff --git a/tests/cli/containers_test.py b/tests/cli/containers_test.py new file mode 100644 index 00000000..52db3ed4 --- /dev/null +++ b/tests/cli/containers_test.py @@ -0,0 +1,73 @@ +import requests + +from tests.helper import response_mock, run_command_mock +from cli.containers import ls, schains + + +RESPONSE_DATA = [ + { + 'image': 'image-skale', 'name': 'skale_schain_test', + 'state': { + 'Status': 'running', 'Running': True, 'Paused': False, + 'Restarting': False, 'OOMKilled': False, 'Dead': False, + 'Pid': 123, 'ExitCode': 0, 'Error': '', + 'StartedAt': '2019-10-08T13:59:54.52368097Z', + 'FinishedAt': '0001-01-01T00:00:00Z' + } + }, + { + 'image': 'image-skale', 'name': 'skale_schain_test2', + 'state': { + 'Status': 'running', 'Running': False, 'Paused': True, + 'Restarting': False, 'OOMKilled': False, 'Dead': False, + 'Pid': 124, 'ExitCode': 0, 'Error': '', + 'StartedAt': '2019-10-08T13:59:54.52368099Z', + 'FinishedAt': '0001-01-01T00:00:00Z' + } + } +] + + +def test_schains(skip_auth, config): + resp_mock = response_mock( + requests.codes.ok, + json_data={'data': RESPONSE_DATA, 'res': 1} + ) + result = run_command_mock('core.helper.get_request', resp_mock, schains) + assert result.exit_code == 0 + assert result.output == " Name Status Started At Image \n-------------------------------------------------------------------------------------\nskale_schain_test Running Oct 08 2019 13:59:54 image-skale\nskale_schain_test2 Running (Jan 01 1 00:00:00) Oct 08 2019 13:59:54 image-skale\n" # noqa + + resp_mock = response_mock( + requests.codes.ok, + json_data={'data': RESPONSE_DATA, 'res': 0} + ) + result = run_command_mock('core.helper.get_request', resp_mock, schains) + assert result.exit_code == 1 + assert result.output == ('----------------------------------' + '----------------\n') + + resp_mock = response_mock( + requests.codes.ok, + None + ) + result = run_command_mock('core.helper.get_request', resp_mock, schains) + assert result.exit_code == 1 + assert result.output == '' + + resp_mock = response_mock( + -1, + {'data': RESPONSE_DATA, 'res': 1} + ) + result = run_command_mock('core.helper.get_request', resp_mock, schains) + assert result.exit_code == 0 + assert result.output == 'Request failed, status code: -1\n' + + +def test_ls(): + resp_mock = response_mock( + requests.codes.ok, + json_data={'data': RESPONSE_DATA, 'res': 1} + ) + result = run_command_mock('core.helper.get_request', resp_mock, ls) + assert result.exit_code == 0 + assert result.output == ' Name Status Started At Image \n-------------------------------------------------------------------------------------\nskale_schain_test Running Oct 08 2019 13:59:54 image-skale\nskale_schain_test2 Running (Jan 01 1 00:00:00) Oct 08 2019 13:59:54 image-skale\n' # noqa diff --git a/tests/cli/logs_test.py b/tests/cli/logs_test.py new file mode 100644 index 00000000..e781fbfa --- /dev/null +++ b/tests/cli/logs_test.py @@ -0,0 +1,23 @@ +import mock +import requests + +from io import BytesIO +from tests.helper import response_mock, run_command +from cli.logs import dump + + +def test_get_schain_conget_schain_config(config, skip_auth): + response_data = {} + resp_mock = response_mock( + requests.codes.ok, + json_data={'data': response_data, 'res': 1}, + headers={ + 'Content-Disposition': 'attachment; filename="skale-logs-dump-2019-10-08-17:40:00.tar.gz"' # noqa + }, + raw=BytesIO() + ) + with mock.patch('requests.get') as req_get_mock: + req_get_mock.return_value.__enter__.return_value = resp_mock + result = run_command(dump, ['.']) + assert result.exit_code == 0 + assert result.output == 'File skale-logs-dump-2019-10-08-17:40:00.tar.gz downloaded\n' # noqa diff --git a/tests/cli/main_test.py b/tests/cli/main_test.py index c154c167..9bbade4e 100644 --- a/tests/cli/main_test.py +++ b/tests/cli/main_test.py @@ -1,5 +1,4 @@ import mock -import pytest import requests import cli.info as info diff --git a/tests/cli/schains_test.py b/tests/cli/schains_test.py new file mode 100644 index 00000000..34b6c19e --- /dev/null +++ b/tests/cli/schains_test.py @@ -0,0 +1,75 @@ +import requests + +from tests.helper import response_mock, run_command_mock +from cli.schains import get_schain_config, ls + + +def test_ls(skip_auth, config): + response_data = [ + { + 'name': 'test_schain1', 'owner': '0x123', + 'indexInOwnerList': 3, 'partOfNode': 0, + 'lifetime': 5, 'startDate': 1570115385, + 'deposit': 1000000000000000000, 'index': 3 + }, + { + 'name': 'crazy_cats1', + 'owner': '0x321', + 'indexInOwnerList': 8, 'partOfNode': 0, + 'lifetime': 5, 'startDate': 1570469410, + 'deposit': 1000000000000000000, 'index': 8 + } + ] + resp_mock = response_mock( + requests.codes.ok, + json_data={'data': response_data, 'res': 1} + ) + result = run_command_mock('core.helper.get_request', resp_mock, ls) + assert result.exit_code == 0 + print(repr(result.output)) + assert result.output == ' Name Owner Size Lifetime Created At Deposit \n-----------------------------------------------------------------------------------\ntest_schain1 0x123 0 5 Oct 03 2019 18:09:45 1000000000000000000\ncrazy_cats1 0x321 0 5 Oct 07 2019 20:30:10 1000000000000000000\n' # noqa + + +def test_get_schain_config(): + response_data = { + 'nodeInfo': { + 'nodeID': 2, 'nodeName': 'testnet-1', + 'basePort': 10011, 'httpRpcPort': 10009, + 'httpsRpcPort': 11118, 'wsRpcPort': 10118, + 'wssRpcPort': 13219, + 'bindIP': '123.123.123.123' + }, + 'sChain': { + 'schainID': 1, 'schainName': 'test1', + 'nodes': [ + {'nodeID': 2, + 'nodeName': 'testnet-1', + 'basePort': 10011, + 'httpRpcPort': 10013, + 'httpsRpcPort': 10018, + 'wsRpcPort': 10014, + 'wssRpcPort': 10019, + 'publicKey': 'public_key', + 'owner': '0xe3213', + 'schainIndex': 1, + 'ip': '213.13.123.13', + 'publicIP': '1.1.1.1' + }, + {'nodeID': 0, 'nodeName': 'testnet-2', + 'basePort': 10077, 'httpRpcPort': 10079, + 'httpsRpcPort': 10084, 'wsRpcPort': 10080, + 'wssRpcPort': 10085, + 'publicKey': 'public_key352', + 'owner': '0x323', + 'schainIndex': 2, 'ip': '2.2.2.2', + 'publicIP': '3.3.3.3' + }]} + } + resp_mock = response_mock( + requests.codes.ok, + json_data={'data': response_data, 'res': 1} + ) + result = run_command_mock('core.helper.get_request', resp_mock, + get_schain_config, ['test1']) + assert result.exit_code == 0 + assert result.output == "{'nodeInfo': {'basePort': 10011,\n 'bindIP': '123.123.123.123',\n 'httpRpcPort': 10009,\n 'httpsRpcPort': 11118,\n 'nodeID': 2,\n 'nodeName': 'testnet-1',\n 'wsRpcPort': 10118,\n 'wssRpcPort': 13219},\n 'sChain': {'nodes': [{'basePort': 10011,\n 'httpRpcPort': 10013,\n 'httpsRpcPort': 10018,\n 'ip': '213.13.123.13',\n 'nodeID': 2,\n 'nodeName': 'testnet-1',\n 'owner': '0xe3213',\n 'publicIP': '1.1.1.1',\n 'publicKey': 'public_key',\n 'schainIndex': 1,\n 'wsRpcPort': 10014,\n 'wssRpcPort': 10019},\n {'basePort': 10077,\n 'httpRpcPort': 10079,\n 'httpsRpcPort': 10084,\n 'ip': '2.2.2.2',\n 'nodeID': 0,\n 'nodeName': 'testnet-2',\n 'owner': '0x323',\n 'publicIP': '3.3.3.3',\n 'publicKey': 'public_key352',\n 'schainIndex': 2,\n 'wsRpcPort': 10080,\n 'wssRpcPort': 10085}],\n 'schainID': 1,\n 'schainName': 'test1'}}\n" # noqa diff --git a/tests/helper.py b/tests/helper.py index 444fa85f..09bcbcc1 100644 --- a/tests/helper.py +++ b/tests/helper.py @@ -1,6 +1,17 @@ import mock from click.testing import CliRunner -from mock import Mock +from mock import Mock, MagicMock + + +def response_mock(status_code=0, json_data=None, cookies=None, + headers=None, raw=None): + result = MagicMock() + result.status_code = status_code + result.json = MagicMock(return_value=json_data) + result.cookies = cookies + result.headers = headers + result.raw = raw + return result def request_mock(response_mock): From c443bbeee51fec53c2af938bfe5f11308378b377 Mon Sep 17 00:00:00 2001 From: ivd Date: Tue, 8 Oct 2019 21:10:59 +0300 Subject: [PATCH 10/45] Add ENV variable to travis --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index e7892679..a8d8d69f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,6 +7,7 @@ install: - pip install -e . - pip install -e .[dev] - export PYTHONPATH=$PYTHONPATH:$(pwd) + - export ENV=dev jobs: include: - stage: test From ffd164e28ac7161b350ed1d83be66ccda360c8b9 Mon Sep 17 00:00:00 2001 From: badrogger Date: Wed, 9 Oct 2019 13:32:31 +0300 Subject: [PATCH 11/45] Add running build.sh script in travis.yml Add removing temporary file --- .travis.yml | 1 + setup.py | 7 ++++--- tests/__init__.py | 0 tests/cli/logs_test.py | 12 ++++++++---- tests/cli/main_test.py | 4 ++-- 5 files changed, 15 insertions(+), 9 deletions(-) create mode 100644 tests/__init__.py diff --git a/.travis.yml b/.travis.yml index a8d8d69f..f87f91d2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,6 +8,7 @@ install: - pip install -e .[dev] - export PYTHONPATH=$PYTHONPATH:$(pwd) - export ENV=dev + - scripts/build.sh 1.0.0 test-branch jobs: include: - stage: test diff --git a/setup.py b/setup.py index 4e0678bb..2d2414c9 100644 --- a/setup.py +++ b/setup.py @@ -24,12 +24,13 @@ def find_version(*file_paths): "isort>=4.2.15,<4.3.5", ], 'dev': [ + "boto3==1.9.233", "bumpversion==0.5.3", + "PyInstaller==3.5", "pytest==5.2.1", - "boto3==1.9.233", + "pytest-cov==2.7.1", "twine==1.12.1", - "when-changed", - "pytest-cov==2.7.1" + "when-changed" ] } diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/cli/logs_test.py b/tests/cli/logs_test.py index e781fbfa..a077af54 100644 --- a/tests/cli/logs_test.py +++ b/tests/cli/logs_test.py @@ -1,3 +1,5 @@ +import os + import mock import requests @@ -7,12 +9,11 @@ def test_get_schain_conget_schain_config(config, skip_auth): - response_data = {} + archive_filename = 'skale-logs-dump-2019-10-08-17:40:00.tar.gz' resp_mock = response_mock( requests.codes.ok, - json_data={'data': response_data, 'res': 1}, headers={ - 'Content-Disposition': 'attachment; filename="skale-logs-dump-2019-10-08-17:40:00.tar.gz"' # noqa + 'Content-Disposition': f'attachment; filename="{archive_filename}"' }, raw=BytesIO() ) @@ -20,4 +21,7 @@ def test_get_schain_conget_schain_config(config, skip_auth): req_get_mock.return_value.__enter__.return_value = resp_mock result = run_command(dump, ['.']) assert result.exit_code == 0 - assert result.output == 'File skale-logs-dump-2019-10-08-17:40:00.tar.gz downloaded\n' # noqa + assert result.output == f'File {archive_filename} downloaded\n' + + if os.path.exists(archive_filename): + os.remove(archive_filename) diff --git a/tests/cli/main_test.py b/tests/cli/main_test.py index 9bbade4e..a01475f4 100644 --- a/tests/cli/main_test.py +++ b/tests/cli/main_test.py @@ -1,9 +1,9 @@ import mock import requests -import cli.info as info - from mock import MagicMock, Mock + +from cli import info from main import (user, version, attach, host, wallet) from tests.helper import run_command, run_command_mock From 7d07ec027535f37d9309fee1e456aa4aa6238922 Mon Sep 17 00:00:00 2001 From: badrogger Date: Wed, 9 Oct 2019 13:36:37 +0300 Subject: [PATCH 12/45] Fix permission error in .travis.yml --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index f87f91d2..2e6520c4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,7 +8,7 @@ install: - pip install -e .[dev] - export PYTHONPATH=$PYTHONPATH:$(pwd) - export ENV=dev - - scripts/build.sh 1.0.0 test-branch + - bash scripts/build.sh 1.0.0 test-branch jobs: include: - stage: test From d265bd090a7d401a5c33073b92439aef5e74878e Mon Sep 17 00:00:00 2001 From: badrogger Date: Wed, 9 Oct 2019 13:48:11 +0300 Subject: [PATCH 13/45] Remove codecov launching --- .travis.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 2e6520c4..3176ca08 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,14 +8,13 @@ install: - pip install -e .[dev] - export PYTHONPATH=$PYTHONPATH:$(pwd) - export ENV=dev + - export CONFIG_FILEPATH='.skale-cli.yml' - bash scripts/build.sh 1.0.0 test-branch jobs: include: - stage: test script: - bash scripts/run-tests.sh - after_script: - - codecov -t $CODECOV_TOKEN - stage: deploy if: branch IN (develop, beta, stable, master) script: From 60c44a2732285f167627046c7ce8365ae37c5d92 Mon Sep 17 00:00:00 2001 From: badrogger Date: Wed, 9 Oct 2019 14:03:34 +0300 Subject: [PATCH 14/45] Add temporary config file cleanup --- .travis.yml | 2 +- tests/conftest.py | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 3176ca08..63d1a906 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,7 +8,7 @@ install: - pip install -e .[dev] - export PYTHONPATH=$PYTHONPATH:$(pwd) - export ENV=dev - - export CONFIG_FILEPATH='.skale-cli.yml' + - export CONFIG_FILEPATH='.skale-cli.yaml' - bash scripts/build.sh 1.0.0 test-branch jobs: include: diff --git a/tests/conftest.py b/tests/conftest.py index 8421280a..992c074c 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -18,6 +18,9 @@ # along with this program. If not, see . """ SKALE config test """ + +import os + import pytest from mock import Mock @@ -40,3 +43,6 @@ def config(monkeypatch): config = ReadSettings(TEST_PATH) config['host'] = 'https://test.com' config['cookies'] = b'\x80\x03}q\x00X\n\x00\x00\x00cookie_keyq\x01X\x0c\x00\x00\x00cookie_valueq\x02s.' # noqa + yield + if os.path.exists(TEST_PATH): + os.remove(TEST_PATH) From 9094624bed13eaf9ca8357eafcafd4bed7fe3249 Mon Sep 17 00:00:00 2001 From: badrogger Date: Wed, 9 Oct 2019 15:08:26 +0300 Subject: [PATCH 15/45] Fix config rewriting --- .travis.yml | 2 -- cli/node.py | 3 +++ scripts/run-tests.sh | 2 +- tests/cli/main_test.py | 3 +-- tests/conftest.py | 14 +++++--------- tests/test-skale-cli.yaml | 3 +++ 6 files changed, 13 insertions(+), 14 deletions(-) create mode 100644 tests/test-skale-cli.yaml diff --git a/.travis.yml b/.travis.yml index 63d1a906..db122440 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,9 +6,7 @@ cache: pip install: - pip install -e . - pip install -e .[dev] - - export PYTHONPATH=$PYTHONPATH:$(pwd) - export ENV=dev - - export CONFIG_FILEPATH='.skale-cli.yaml' - bash scripts/build.sh 1.0.0 test-branch jobs: include: diff --git a/cli/node.py b/cli/node.py index b865992d..d56d01f6 100644 --- a/cli/node.py +++ b/cli/node.py @@ -81,6 +81,7 @@ def node(): @click.option('--format', '-f', type=click.Choice(['json', 'text'])) @login_required def node_info(format): + config = session_config() get_node_info(config, format) @@ -88,6 +89,7 @@ def node_info(format): @click.option('--format', '-f', type=click.Choice(['json', 'text'])) @login_required def node_about(format): + config = session_config() get_node_about(config, format) @@ -124,6 +126,7 @@ def node_about(format): @login_required # def register_node(name, p2p_ip, public_ip, port): def register_node(name, ip, port): + config = session_config() create_node(config, name, ip, ip, port) diff --git a/scripts/run-tests.sh b/scripts/run-tests.sh index 0a8ecc0f..48e216cb 100755 --- a/scripts/run-tests.sh +++ b/scripts/run-tests.sh @@ -3,4 +3,4 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" PROJECT_DIR=$(dirname $DIR) -CONFIG_FILEPATH='.skale-cli.yaml' py.test tests/ $@ +CONFIG_FILEPATH='tests/test-skale-cli.yaml' py.test tests/ $@ diff --git a/tests/cli/main_test.py b/tests/cli/main_test.py index a01475f4..499e09fd 100644 --- a/tests/cli/main_test.py +++ b/tests/cli/main_test.py @@ -121,7 +121,7 @@ def test_login(config): assert expected == result.output -def test_logout(): +def test_logout(config): response_mock = MagicMock() response_mock.status_code = requests.codes.ok response_mock.cookies = 'simple-cookies' @@ -162,7 +162,6 @@ def test_wallet_info(config): response_mock, wallet, ['info']) assert result.exit_code == 0 - expected = 'Cookies removed\n' expected = ( '--------------------------------------------------\n' 'Address: simple_address\n' diff --git a/tests/conftest.py b/tests/conftest.py index 992c074c..b795b76e 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -19,12 +19,11 @@ """ SKALE config test """ -import os - import pytest from mock import Mock from readsettings import ReadSettings +from core.config import CONFIG_FILEPATH @pytest.fixture @@ -39,10 +38,7 @@ def skip_local_only(monkeypatch): @pytest.fixture def config(monkeypatch): - TEST_PATH = '.skale-cli.yaml' - config = ReadSettings(TEST_PATH) - config['host'] = 'https://test.com' - config['cookies'] = b'\x80\x03}q\x00X\n\x00\x00\x00cookie_keyq\x01X\x0c\x00\x00\x00cookie_valueq\x02s.' # noqa - yield - if os.path.exists(TEST_PATH): - os.remove(TEST_PATH) + cli_config = ReadSettings(CONFIG_FILEPATH) + cli_config['host'] = 'https://test.com' + cli_config['cookies'] = b'\x80\x03}q\x00X\n\x00\x00\x00cookie_keyq\x01X\x0c\x00\x00\x00cookie_valueq\x02s.' # noqa + cli_config.save() diff --git a/tests/test-skale-cli.yaml b/tests/test-skale-cli.yaml new file mode 100644 index 00000000..8e098a7a --- /dev/null +++ b/tests/test-skale-cli.yaml @@ -0,0 +1,3 @@ +cookies: !!binary | + gAN9cQBYCgAAAGNvb2tpZV9rZXlxAVgMAAAAY29va2llX3ZhbHVlcQJzLg== +host: https://test.com From 9fac35fa0c107fb01481da0c4bbd8100545d4bb3 Mon Sep 17 00:00:00 2001 From: badrogger Date: Wed, 9 Oct 2019 16:58:50 +0300 Subject: [PATCH 16/45] Add tests to cli/node.py module --- core/node.py | 1 + tests/cli/main_test.py | 1 - tests/cli/node_test.py | 176 ++++++++++++++++++++++++++++++++++++++ tests/cli/schains_test.py | 8 +- 4 files changed, 183 insertions(+), 3 deletions(-) create mode 100644 tests/cli/node_test.py diff --git a/core/node.py b/core/node.py index ded98d79..4cf49f89 100644 --- a/core/node.py +++ b/core/node.py @@ -46,6 +46,7 @@ def create_node(config, name, p2p_ip, public_ip, port): response = post_request(url, data, cookies) if response is None: + print('Your request returned nothing. Something went wrong. Try again') return None if response.status_code == requests.codes.created: msg = 'Node registered in SKALE manager. For more info run: skale node info' diff --git a/tests/cli/main_test.py b/tests/cli/main_test.py index 499e09fd..0108a317 100644 --- a/tests/cli/main_test.py +++ b/tests/cli/main_test.py @@ -192,7 +192,6 @@ def test_set_wallet(skip_local_only, skip_auth): 'deabcdeabcdeabcd' 'eeabcdeabcdeabcdeabcdeabc')) assert result.exit_code == 0 - print(repr(result.output)) assert result.output == ( 'Enter private key: \n' 'Local wallet updated: ' diff --git a/tests/cli/node_test.py b/tests/cli/node_test.py new file mode 100644 index 00000000..6be1cce5 --- /dev/null +++ b/tests/cli/node_test.py @@ -0,0 +1,176 @@ +import mock +import requests + +from tests.helper import response_mock, run_command_mock +from cli.node import (register_node, init_node, update_node, + node_about, node_info) + + +def test_register_node(skip_auth, config): + resp_mock = response_mock(requests.codes.created) + result = run_command_mock( + 'core.node.post_request', + resp_mock, + register_node, + ['--name', 'test-node', '--ip', '0.0.0.0', '--port', '8080']) + assert result.exit_code == 0 + assert result.output == 'Node registered in SKALE manager. For more info run: skale node info\n' + + result = run_command_mock( + 'core.node.post_request', + None, + register_node, + ['--name', 'test-node2', '--ip', '0.0.0.0', '--port', '80']) + assert result.exit_code == 0 + assert result.output == 'Your request returned nothing. Something went wrong. Try again\n' + + resp_mock = response_mock(requests.codes.ok, + json_data={'errors': ['Strange error']}) + result = run_command_mock( + 'core.node.post_request', + resp_mock, + register_node, + ['--name', 'test-node2', '--ip', '0.0.0.0', '--port', '80']) + assert result.exit_code == 0 + assert result.output == '--------------------------------------------------\nStrange error\n--------------------------------------------------\n' # noqa + + +def test_register_node_with_prompted_ip(config, skip_auth): + resp_mock = response_mock(requests.codes.created) + result = run_command_mock( + 'core.node.post_request', + resp_mock, + register_node, + ['--name', 'test-node', '--port', '8080'], input='0.0.0.0\n') + assert result.exit_code == 0 + assert result.output == 'Enter node public IP: 0.0.0.0\nNode registered in SKALE manager. For more info run: skale node info\n' # noqa + + +def test_register_node_with_default_port_and_name(config, skip_auth): + resp_mock = response_mock(requests.codes.created) + result = run_command_mock( + 'core.node.post_request', + resp_mock, + register_node, + input='0.0.0.0\n') + assert result.exit_code == 0 + assert result.output == 'Enter node public IP: 0.0.0.0\nNode registered in SKALE manager. For more info run: skale node info\n' # noqa + + +def test_init_node(skip_local_only, config): + params = ['--ima-endpoint', 'https://0.0.0.0:8080', '--stream', 'stream', + '--github-token', 'token123', + '--docker-username', 'docker-test', + '--docker-password', 'qwerty123', + '--endpoint', 'ws://0.0.0.0:8080', '--db-user', 'user1', + '--db-password', 'pass123', '--db-root-password', 'pass123', + '--db-port', 8080, '--disk-mountpoint', '/dev/sda', + '--manager-url', '0.0.0.0:8080', '--ima-url', 'ws://0.0.0.0:8080', + '--dkg-url', '0.0.0.0:8080'] + resp_mock = response_mock(requests.codes.created) + with mock.patch('core.node.subprocess.run'), \ + mock.patch('cli.node.install_host_dependencies'), \ + mock.patch('core.node.prepare_host'), \ + mock.patch('core.node.init_data_dir'): + result = run_command_mock( + 'core.node.post_request', + resp_mock, + init_node, + params) + assert result.exit_code == 0 + assert result.output == '' + + +def test_init_node_invalid_url(skip_local_only, config): + params = ['--ima-endpoint', 'invalid_url', '--stream', 'stream', + '--github-token', 'token123', + '--docker-username', 'docker-test', + '--docker-password', 'qwerty123', + '--endpoint', 'ws://0.0.0.0:8080', '--db-user', 'user1', + '--db-password', 'pass123', '--db-root-password', 'pass123', + '--db-port', 8080, '--disk-mountpoint', '/dev/sda', + '--manager-url', '0.0.0.0:8080', '--ima-url', 'ws://0.0.0.0:8080', + '--dkg-url', '0.0.0.0:8080'] + resp_mock = response_mock(requests.codes.created) + with mock.patch('core.node.subprocess.run'), \ + mock.patch('cli.node.install_host_dependencies'), \ + mock.patch('core.node.prepare_host'), \ + mock.patch('core.node.init_data_dir'): + result = run_command_mock( + 'core.node.post_request', + resp_mock, + init_node, + params) + assert result.exit_code == 2 + assert result.output == 'Usage: init [OPTIONS]\nTry "init --help" for help.\n\nError: Invalid value for "--ima-endpoint": Expected valid url. Got invalid_url\n' # noqa + + +def test_update_node(skip_local_only, config): + params = ['--ima-endpoint', 'https://0.0.0.0:8080', + '--github-token', 'token123', + '--docker-username', 'docker-test', + '--docker-password', 'qwerty123', + '--endpoint', 'ws://0.0.0.0:8080', '--db-user', 'user1', + '--db-password', 'pass123', '--db-root-password', 'pass123', + '--db-port', 8080, + '--manager-url', '0.0.0.0:8080', '--ima-url', 'ws://0.0.0.0:8080', + '--dkg-url', '0.0.0.0:8080', '--yes'] + resp_mock = response_mock(requests.codes.created) + with mock.patch('core.node.subprocess.run'), \ + mock.patch('cli.node.install_host_dependencies'), \ + mock.patch('core.node.prepare_host'), \ + mock.patch('core.node.init_data_dir'): + result = run_command_mock( + 'core.node.post_request', + resp_mock, + update_node, + params) + assert result.exit_code == 0 + assert result.output == '' + + +def test_node_info_node_about(skip_auth, config): + response_data = { + 'libraries': { + 'javascript': 'N/A', 'python': '0.89.0'}, + 'contracts': { + 'token': '0x3', + 'manager': '0x23' + }, + 'network': { + 'endpoint': 'ws://0.0.0.0:8080' + }, + 'local_wallet': { + 'address': '0xf', + 'eth_balance_wei': '15', + 'skale_balance_wei': '84312304', + 'eth_balance': '2.424', + 'skale_balance': '323.123' + } + } + resp_mock = response_mock( + requests.codes.ok, + json_data={'data': response_data, 'res': 1} + ) + result = run_command_mock('core.core.get_request', resp_mock, node_about) + assert result.exit_code == 0 + assert result.output == "{'libraries': {'javascript': 'N/A', 'python': '0.89.0'}, 'contracts': {'token': '0x3', 'manager': '0x23'}, 'network': {'endpoint': 'ws://0.0.0.0:8080'}, 'local_wallet': {'address': '0xf', 'eth_balance_wei': '15', 'skale_balance_wei': '84312304', 'eth_balance': '2.424', 'skale_balance': '323.123'}}\n" # noqa + + +def test_node_info_node_info(skip_auth, config): + response_data = {'name': 'test', 'ip': '0.0.0.0', + 'publicIP': '1.1.1.1', + 'port': 10001, + 'publicKey': '0x7', + 'start_date': 1570114466, + 'leaving_date': 0, + 'last_reward_date': 1570628924, 'second_address': 0, + 'status': 2, 'id': 32, 'owner': '0x23'} + + resp_mock = response_mock( + requests.codes.ok, + json_data={'data': response_data, 'res': 1} + ) + result = run_command_mock('core.core.get_request', resp_mock, node_info) + assert result.exit_code == 0 + assert result.output == '--------------------------------------------------\nNode info\nName: test\nIP: 0.0.0.0\nPublic IP: 1.1.1.1\nPort: 10001\nStatus: Active\n--------------------------------------------------\n' # noqa diff --git a/tests/cli/schains_test.py b/tests/cli/schains_test.py index 34b6c19e..6053a908 100644 --- a/tests/cli/schains_test.py +++ b/tests/cli/schains_test.py @@ -1,3 +1,6 @@ +import os +import time + import requests from tests.helper import response_mock, run_command_mock @@ -5,6 +8,8 @@ def test_ls(skip_auth, config): + os.environ['TZ'] = 'Europe/London' + time.tzset() response_data = [ { 'name': 'test_schain1', 'owner': '0x123', @@ -26,8 +31,7 @@ def test_ls(skip_auth, config): ) result = run_command_mock('core.helper.get_request', resp_mock, ls) assert result.exit_code == 0 - print(repr(result.output)) - assert result.output == ' Name Owner Size Lifetime Created At Deposit \n-----------------------------------------------------------------------------------\ntest_schain1 0x123 0 5 Oct 03 2019 18:09:45 1000000000000000000\ncrazy_cats1 0x321 0 5 Oct 07 2019 20:30:10 1000000000000000000\n' # noqa + assert result.output == ' Name Owner Size Lifetime Created At Deposit \n-----------------------------------------------------------------------------------\ntest_schain1 0x123 0 5 Oct 03 2019 16:09:45 1000000000000000000\ncrazy_cats1 0x321 0 5 Oct 07 2019 18:30:10 1000000000000000000\n' # noqa def test_get_schain_config(): From 8a72891d1b0b157bba30103b50c9674fece8b816 Mon Sep 17 00:00:00 2001 From: badrogger Date: Wed, 9 Oct 2019 18:46:59 +0300 Subject: [PATCH 17/45] Add tests to cli/metrics.py Add license to new files --- cli/metrics.py | 12 ++++---- tests/cli/containers_test.py | 19 +++++++++++++ tests/cli/logs_test.py | 20 +++++++++++++ tests/cli/main_test.py | 20 +++++++++++++ tests/cli/metrics_test.py | 55 ++++++++++++++++++++++++++++++++++++ tests/cli/node_test.py | 19 +++++++++++++ tests/cli/schains_test.py | 19 +++++++++++++ tests/helper.py | 19 +++++++++++++ 8 files changed, 177 insertions(+), 6 deletions(-) create mode 100644 tests/cli/metrics_test.py diff --git a/cli/metrics.py b/cli/metrics.py index a8bf0119..4603daf0 100644 --- a/cli/metrics.py +++ b/cli/metrics.py @@ -36,19 +36,19 @@ def metrics(): @login_required def first(): print('Please wait - collecting metrics from blockchain...') - bounty_list = get('first-bounties') - if not bounty_list: + bounty_data = get('first-bounties') + if not bounty_data.get('bounties'): print('No bounties found') return - print_metrics(bounty_list) + print_metrics(bounty_data) @metrics.command(help="List of bounties and metrics for the last year") @login_required def last(): print('Please wait - collecting metrics from blockchain...') - bounty_list = get('last-bounties') - if not bounty_list: + bounty_data = get('last-bounties') + if not bounty_data.get('bounties'): print('No bounties found') return - print_metrics(bounty_list) + print_metrics(bounty_data) diff --git a/tests/cli/containers_test.py b/tests/cli/containers_test.py index 52db3ed4..b4034580 100644 --- a/tests/cli/containers_test.py +++ b/tests/cli/containers_test.py @@ -1,3 +1,22 @@ +# -*- coding: utf-8 -*- +# +# This file is part of skale-node-cli +# +# Copyright (C) 2019 SKALE Labs +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + import requests from tests.helper import response_mock, run_command_mock diff --git a/tests/cli/logs_test.py b/tests/cli/logs_test.py index a077af54..a0b5f176 100644 --- a/tests/cli/logs_test.py +++ b/tests/cli/logs_test.py @@ -1,3 +1,23 @@ +# -*- coding: utf-8 -*- +# +# This file is part of skale-node-cli +# +# Copyright (C) 2019 SKALE Labs +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + + import os import mock diff --git a/tests/cli/main_test.py b/tests/cli/main_test.py index 0108a317..a4b3b6b1 100644 --- a/tests/cli/main_test.py +++ b/tests/cli/main_test.py @@ -1,3 +1,23 @@ +# -*- coding: utf-8 -*- +# +# This file is part of skale-node-cli +# +# Copyright (C) 2019 SKALE Labs +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + + import mock import requests diff --git a/tests/cli/metrics_test.py b/tests/cli/metrics_test.py new file mode 100644 index 00000000..1cd4cf9c --- /dev/null +++ b/tests/cli/metrics_test.py @@ -0,0 +1,55 @@ +# -*- coding: utf-8 -*- +# +# This file is part of skale-node-cli +# +# Copyright (C) 2019 SKALE Labs +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +import requests + +from tests.helper import response_mock, run_command_mock +from cli.metrics import first, last + + +def test_metrics(skip_auth, config): + response_data = { + 'bounties': [ + ['2019-10-09 02:46:50', 4018775720164609053497, 0, 1], + ['2019-10-09 03:47:00', 4018775720164609053497, 0, 1], + ['2019-10-09 04:47:11', 4018775720164609053497, 0, 1], + ['2019-10-09 05:47:21', 4018775720164609053497, 0, 1], + ['2019-10-09 06:47:32', 4018775720164609053497, 0, 1] + ] + } + resp_mock = response_mock( + requests.codes.ok, + json_data={'data': response_data, 'res': 1} + ) + result = run_command_mock('core.helper.get_request', resp_mock, first) + assert result.exit_code == 0 + assert result.output == 'Please wait - collecting metrics from blockchain...\n Date Bounty Downtime Latency\n-----------------------------------------------------------------\n2019-10-09 02:46:50 4018775720164609053497 0 1 \n2019-10-09 03:47:00 4018775720164609053497 0 1 \n2019-10-09 04:47:11 4018775720164609053497 0 1 \n2019-10-09 05:47:21 4018775720164609053497 0 1 \n2019-10-09 06:47:32 4018775720164609053497 0 1 \n' # noqa + + result = run_command_mock('core.helper.get_request', resp_mock, first) + assert result.exit_code == 0 + assert result.output == 'Please wait - collecting metrics from blockchain...\n Date Bounty Downtime Latency\n-----------------------------------------------------------------\n2019-10-09 02:46:50 4018775720164609053497 0 1 \n2019-10-09 03:47:00 4018775720164609053497 0 1 \n2019-10-09 04:47:11 4018775720164609053497 0 1 \n2019-10-09 05:47:21 4018775720164609053497 0 1 \n2019-10-09 06:47:32 4018775720164609053497 0 1 \n' + + for func in (first, last): + resp_mock = response_mock( + requests.codes.ok, + json_data={'data': {'bounties': []}, 'res': 1} + ) + result = run_command_mock('core.helper.get_request', resp_mock, func) + assert result.exit_code == 0 + assert result.output == 'Please wait - collecting metrics from blockchain...\nNo bounties found\n' # noqa diff --git a/tests/cli/node_test.py b/tests/cli/node_test.py index 6be1cce5..2c330fce 100644 --- a/tests/cli/node_test.py +++ b/tests/cli/node_test.py @@ -1,3 +1,22 @@ +# -*- coding: utf-8 -*- +# +# This file is part of skale-node-cli +# +# Copyright (C) 2019 SKALE Labs +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + import mock import requests diff --git a/tests/cli/schains_test.py b/tests/cli/schains_test.py index 6053a908..df8e2e25 100644 --- a/tests/cli/schains_test.py +++ b/tests/cli/schains_test.py @@ -1,3 +1,22 @@ +# -*- coding: utf-8 -*- +# +# This file is part of skale-node-cli +# +# Copyright (C) 2019 SKALE Labs +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + import os import time diff --git a/tests/helper.py b/tests/helper.py index 09bcbcc1..1557737d 100644 --- a/tests/helper.py +++ b/tests/helper.py @@ -1,3 +1,22 @@ +# -*- coding: utf-8 -*- +# +# This file is part of skale-node-cli +# +# Copyright (C) 2019 SKALE Labs +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + import mock from click.testing import CliRunner from mock import Mock, MagicMock From 76dc9aaa01a5b441449cc75e5b1f08c3d9e54036 Mon Sep 17 00:00:00 2001 From: badrogger Date: Wed, 9 Oct 2019 18:53:55 +0300 Subject: [PATCH 18/45] Fix metrics_test.py flake8 error --- tests/cli/metrics_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/cli/metrics_test.py b/tests/cli/metrics_test.py index 1cd4cf9c..b4eef3ec 100644 --- a/tests/cli/metrics_test.py +++ b/tests/cli/metrics_test.py @@ -43,7 +43,7 @@ def test_metrics(skip_auth, config): result = run_command_mock('core.helper.get_request', resp_mock, first) assert result.exit_code == 0 - assert result.output == 'Please wait - collecting metrics from blockchain...\n Date Bounty Downtime Latency\n-----------------------------------------------------------------\n2019-10-09 02:46:50 4018775720164609053497 0 1 \n2019-10-09 03:47:00 4018775720164609053497 0 1 \n2019-10-09 04:47:11 4018775720164609053497 0 1 \n2019-10-09 05:47:21 4018775720164609053497 0 1 \n2019-10-09 06:47:32 4018775720164609053497 0 1 \n' + assert result.output == 'Please wait - collecting metrics from blockchain...\n Date Bounty Downtime Latency\n-----------------------------------------------------------------\n2019-10-09 02:46:50 4018775720164609053497 0 1 \n2019-10-09 03:47:00 4018775720164609053497 0 1 \n2019-10-09 04:47:11 4018775720164609053497 0 1 \n2019-10-09 05:47:21 4018775720164609053497 0 1 \n2019-10-09 06:47:32 4018775720164609053497 0 1 \n' # noqa for func in (first, last): resp_mock = response_mock( From 2edbb47c20a8f9a71ff702bef85bb9e67e934d58 Mon Sep 17 00:00:00 2001 From: badrogger Date: Wed, 9 Oct 2019 20:57:59 +0300 Subject: [PATCH 19/45] Add missing flake8 check --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index db122440..c40d7cf4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,6 +11,8 @@ install: jobs: include: - stage: test + before_script: + - flake8 . script: - bash scripts/run-tests.sh - stage: deploy From 89c4093bfc0a745c3320db9a8314d30c265247a6 Mon Sep 17 00:00:00 2001 From: ivd Date: Fri, 11 Oct 2019 09:04:26 +0300 Subject: [PATCH 20/45] Try without cli/node.py init options prompting --- cli/node.py | 22 +++++++++++----------- tests/cli/logs_test.py | 2 +- tests/cli/node_test.py | 10 +++++----- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/cli/node.py b/cli/node.py index d56d01f6..2bc3621d 100644 --- a/cli/node.py +++ b/cli/node.py @@ -135,33 +135,33 @@ def register_node(name, ip, port): @click.option( '--ima-endpoint', type=URL_TYPE, - prompt="Enter IMA endpoint to connect", + # prompt="Enter IMA endpoint to connect", help='IMA endpoint to connect' ) @click.option( # todo: tmp option - after stable release branch '--stream', - prompt="Enter stream for the SKALE node", + # prompt="Enter stream for the SKALE node", help='Stream that will be used for SKALE node setup (required)' ) @click.option( # todo: tmp option - remove after open source '--github-token', - prompt="Enter GitHub access token", + # prompt="Enter GitHub access token", help='GitHub access token to clone the repo (required)' ) @click.option( # todo: tmp option - remove after open source '--docker-username', - prompt="Enter DockerHub username", + # prompt="Enter DockerHub username", help='DockerHub username to pull images (required)' ) @click.option( # todo: tmp option - remove after open source '--docker-password', - prompt="Enter DockerHub password", + # prompt="Enter DockerHub password", help='DockerHub password to pull images (required)' ) @click.option( # todo: tmp option - remove after mainnet deploy '--endpoint', type=URL_TYPE, - prompt="Enter Mainnet RPC endpoint", + # prompt="Enter Mainnet RPC endpoint", help='RPC endpoint of the node in the network ' 'where SKALE manager is deployed' ) @@ -173,7 +173,7 @@ def register_node(name, ip, port): ) @click.option( '--db-password', - prompt="Enter password for node DB", + # prompt="Enter password for node DB", help='Password for node internal database (required)' ) @click.option( @@ -189,23 +189,23 @@ def register_node(name, ip, port): ) @click.option( '--disk-mountpoint', - prompt="Enter data disk mount point", + # prompt="Enter data disk mount point", help='Mount point of the disk to be used ' 'for storing sChains data (required)' ) @click.option( '--manager-url', - prompt="Enter URL to SKALE Manager contracts ABI and addresses", + # prompt="Enter URL to SKALE Manager contracts ABI and addresses", help='URL to SKALE Manager contracts ABI and addresses' ) @click.option( '--ima-url', - prompt="Enter URL to IMA contracts ABI and addresses", + # prompt="Enter URL to IMA contracts ABI and addresses", help='URL to IMA contracts ABI and addresses' ) @click.option( '--dkg-url', - prompt="Enter URL to DKG contracts ABI and addresses", + # prompt="Enter URL to DKG contracts ABI and addresses", help='URL to DKG contracts ABI and addresses' ) @click.option( diff --git a/tests/cli/logs_test.py b/tests/cli/logs_test.py index a0b5f176..9a3156ee 100644 --- a/tests/cli/logs_test.py +++ b/tests/cli/logs_test.py @@ -28,7 +28,7 @@ from cli.logs import dump -def test_get_schain_conget_schain_config(config, skip_auth): +def test_dump(config, skip_auth): archive_filename = 'skale-logs-dump-2019-10-08-17:40:00.tar.gz' resp_mock = response_mock( requests.codes.ok, diff --git a/tests/cli/node_test.py b/tests/cli/node_test.py index 2c330fce..3dec9e54 100644 --- a/tests/cli/node_test.py +++ b/tests/cli/node_test.py @@ -77,15 +77,15 @@ def test_register_node_with_default_port_and_name(config, skip_auth): def test_init_node(skip_local_only, config): - params = ['--ima-endpoint', 'https://0.0.0.0:8080', '--stream', 'stream', + params = ['--ima-endpoint', 'https://0.0.0.1:8080', '--stream', 'stream', '--github-token', 'token123', '--docker-username', 'docker-test', '--docker-password', 'qwerty123', - '--endpoint', 'ws://0.0.0.0:8080', '--db-user', 'user1', + '--endpoint', 'ws://0.0.0.1:8080', '--db-user', 'user1', '--db-password', 'pass123', '--db-root-password', 'pass123', - '--db-port', 8080, '--disk-mountpoint', '/dev/sda', - '--manager-url', '0.0.0.0:8080', '--ima-url', 'ws://0.0.0.0:8080', - '--dkg-url', '0.0.0.0:8080'] + '--db-port', 8087, '--disk-mountpoint', '/dev/sdp', + '--manager-url', '0.0.0.1:8080', '--ima-url', 'ws://0.0.0.1:8080', + '--dkg-url', '0.0.0.1:8080'] resp_mock = response_mock(requests.codes.created) with mock.patch('core.node.subprocess.run'), \ mock.patch('cli.node.install_host_dependencies'), \ From f9c27ea14b956ca7ba6fb3f67e30a498a584c447 Mon Sep 17 00:00:00 2001 From: ivd Date: Fri, 11 Oct 2019 09:10:13 +0300 Subject: [PATCH 21/45] Try skip first init test --- cli/node.py | 22 +++++++++++----------- tests/cli/node_test.py | 2 ++ 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/cli/node.py b/cli/node.py index 2bc3621d..d56d01f6 100644 --- a/cli/node.py +++ b/cli/node.py @@ -135,33 +135,33 @@ def register_node(name, ip, port): @click.option( '--ima-endpoint', type=URL_TYPE, - # prompt="Enter IMA endpoint to connect", + prompt="Enter IMA endpoint to connect", help='IMA endpoint to connect' ) @click.option( # todo: tmp option - after stable release branch '--stream', - # prompt="Enter stream for the SKALE node", + prompt="Enter stream for the SKALE node", help='Stream that will be used for SKALE node setup (required)' ) @click.option( # todo: tmp option - remove after open source '--github-token', - # prompt="Enter GitHub access token", + prompt="Enter GitHub access token", help='GitHub access token to clone the repo (required)' ) @click.option( # todo: tmp option - remove after open source '--docker-username', - # prompt="Enter DockerHub username", + prompt="Enter DockerHub username", help='DockerHub username to pull images (required)' ) @click.option( # todo: tmp option - remove after open source '--docker-password', - # prompt="Enter DockerHub password", + prompt="Enter DockerHub password", help='DockerHub password to pull images (required)' ) @click.option( # todo: tmp option - remove after mainnet deploy '--endpoint', type=URL_TYPE, - # prompt="Enter Mainnet RPC endpoint", + prompt="Enter Mainnet RPC endpoint", help='RPC endpoint of the node in the network ' 'where SKALE manager is deployed' ) @@ -173,7 +173,7 @@ def register_node(name, ip, port): ) @click.option( '--db-password', - # prompt="Enter password for node DB", + prompt="Enter password for node DB", help='Password for node internal database (required)' ) @click.option( @@ -189,23 +189,23 @@ def register_node(name, ip, port): ) @click.option( '--disk-mountpoint', - # prompt="Enter data disk mount point", + prompt="Enter data disk mount point", help='Mount point of the disk to be used ' 'for storing sChains data (required)' ) @click.option( '--manager-url', - # prompt="Enter URL to SKALE Manager contracts ABI and addresses", + prompt="Enter URL to SKALE Manager contracts ABI and addresses", help='URL to SKALE Manager contracts ABI and addresses' ) @click.option( '--ima-url', - # prompt="Enter URL to IMA contracts ABI and addresses", + prompt="Enter URL to IMA contracts ABI and addresses", help='URL to IMA contracts ABI and addresses' ) @click.option( '--dkg-url', - # prompt="Enter URL to DKG contracts ABI and addresses", + prompt="Enter URL to DKG contracts ABI and addresses", help='URL to DKG contracts ABI and addresses' ) @click.option( diff --git a/tests/cli/node_test.py b/tests/cli/node_test.py index 3dec9e54..adb229d5 100644 --- a/tests/cli/node_test.py +++ b/tests/cli/node_test.py @@ -18,6 +18,7 @@ # along with this program. If not, see . import mock +import pytest import requests from tests.helper import response_mock, run_command_mock @@ -76,6 +77,7 @@ def test_register_node_with_default_port_and_name(config, skip_auth): assert result.output == 'Enter node public IP: 0.0.0.0\nNode registered in SKALE manager. For more info run: skale node info\n' # noqa +@pytest.mark.skip def test_init_node(skip_local_only, config): params = ['--ima-endpoint', 'https://0.0.0.1:8080', '--stream', 'stream', '--github-token', 'token123', From 5b1ae2846f1f35f47a7b5183cf01ec1201fbb3e9 Mon Sep 17 00:00:00 2001 From: ivd Date: Fri, 11 Oct 2019 09:17:23 +0300 Subject: [PATCH 22/45] Try skip node update test --- tests/cli/node_test.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/cli/node_test.py b/tests/cli/node_test.py index adb229d5..722f7ca6 100644 --- a/tests/cli/node_test.py +++ b/tests/cli/node_test.py @@ -126,6 +126,7 @@ def test_init_node_invalid_url(skip_local_only, config): assert result.output == 'Usage: init [OPTIONS]\nTry "init --help" for help.\n\nError: Invalid value for "--ima-endpoint": Expected valid url. Got invalid_url\n' # noqa +@pytest.mark.skip def test_update_node(skip_local_only, config): params = ['--ima-endpoint', 'https://0.0.0.0:8080', '--github-token', 'token123', From 06cd39c9d777bb440f80d8c4aa10affc11822e99 Mon Sep 17 00:00:00 2001 From: ivd Date: Fri, 11 Oct 2019 09:32:20 +0300 Subject: [PATCH 23/45] Try to change mock path --- .flake8 | 2 +- tests/cli/node_test.py | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/.flake8 b/.flake8 index d5646fbb..d0ed9fc5 100644 --- a/.flake8 +++ b/.flake8 @@ -1,3 +1,3 @@ [flake8] max-line-length = 100 -exclude = .git,__pycache__,docs/source/conf.py,old,build,dist,venv \ No newline at end of file +exclude = .git,__pycache__,docs/source/conf.py,old,build,dist,venv diff --git a/tests/cli/node_test.py b/tests/cli/node_test.py index 722f7ca6..b6e4c3bb 100644 --- a/tests/cli/node_test.py +++ b/tests/cli/node_test.py @@ -77,7 +77,6 @@ def test_register_node_with_default_port_and_name(config, skip_auth): assert result.output == 'Enter node public IP: 0.0.0.0\nNode registered in SKALE manager. For more info run: skale node info\n' # noqa -@pytest.mark.skip def test_init_node(skip_local_only, config): params = ['--ima-endpoint', 'https://0.0.0.1:8080', '--stream', 'stream', '--github-token', 'token123', @@ -126,7 +125,6 @@ def test_init_node_invalid_url(skip_local_only, config): assert result.output == 'Usage: init [OPTIONS]\nTry "init --help" for help.\n\nError: Invalid value for "--ima-endpoint": Expected valid url. Got invalid_url\n' # noqa -@pytest.mark.skip def test_update_node(skip_local_only, config): params = ['--ima-endpoint', 'https://0.0.0.0:8080', '--github-token', 'token123', @@ -138,7 +136,7 @@ def test_update_node(skip_local_only, config): '--manager-url', '0.0.0.0:8080', '--ima-url', 'ws://0.0.0.0:8080', '--dkg-url', '0.0.0.0:8080', '--yes'] resp_mock = response_mock(requests.codes.created) - with mock.patch('core.node.subprocess.run'), \ + with mock.patch('subprocess.run'), \ mock.patch('cli.node.install_host_dependencies'), \ mock.patch('core.node.prepare_host'), \ mock.patch('core.node.init_data_dir'): From 4782cc52a651e5f8373c2eec03ad1b8cfee78075 Mon Sep 17 00:00:00 2001 From: ivd Date: Fri, 11 Oct 2019 09:37:02 +0300 Subject: [PATCH 24/45] Fix unused pytest error --- tests/cli/node_test.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/cli/node_test.py b/tests/cli/node_test.py index b6e4c3bb..d81194a3 100644 --- a/tests/cli/node_test.py +++ b/tests/cli/node_test.py @@ -18,7 +18,6 @@ # along with this program. If not, see . import mock -import pytest import requests from tests.helper import response_mock, run_command_mock From 60823c45f81be0a13baa4f8ce3c9b72f41574047 Mon Sep 17 00:00:00 2001 From: ivd Date: Fri, 11 Oct 2019 09:46:27 +0300 Subject: [PATCH 25/45] Try to change node init subprocess run mock --- tests/cli/node_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/cli/node_test.py b/tests/cli/node_test.py index d81194a3..9af6ee7c 100644 --- a/tests/cli/node_test.py +++ b/tests/cli/node_test.py @@ -87,7 +87,7 @@ def test_init_node(skip_local_only, config): '--manager-url', '0.0.0.1:8080', '--ima-url', 'ws://0.0.0.1:8080', '--dkg-url', '0.0.0.1:8080'] resp_mock = response_mock(requests.codes.created) - with mock.patch('core.node.subprocess.run'), \ + with mock.patch('subprocess.run'), \ mock.patch('cli.node.install_host_dependencies'), \ mock.patch('core.node.prepare_host'), \ mock.patch('core.node.init_data_dir'): From 0d4c997c3299ce22fb60c90031a30e1e9b18bb95 Mon Sep 17 00:00:00 2001 From: ivd Date: Fri, 11 Oct 2019 09:52:18 +0300 Subject: [PATCH 26/45] Try running test without subprocess calling --- core/node.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/core/node.py b/core/node.py index 4cf49f89..843bec6c 100644 --- a/core/node.py +++ b/core/node.py @@ -80,6 +80,7 @@ def init(mta_endpoint, git_branch, github_token, docker_username, docker_passwor init_data_dir() prepare_host(test_mode, disk_mountpoint) + return res = subprocess.run(['bash', INSTALL_SCRIPT], env=env) logging.info(f'Node init install script result: {res.stderr}, {res.stdout}') # todo: check execution result @@ -113,6 +114,7 @@ def update(ima_endpoint, github_token, docker_username, docker_password, endpoin 'IMA_CONTRACTS_INFO_URL': ima_url, 'DKG_CONTRACTS_INFO_URL': dkg_url } + return res_update_project = subprocess.run(['sudo', '-E', 'bash', UPDATE_NODE_PROJECT_SCRIPT], env=env) logging.info( f'Update node project script result: {res_update_project.stderr}, \ From 8586181a77b88b7e4866c82d50e8c589bddec6da Mon Sep 17 00:00:00 2001 From: ivd Date: Fri, 11 Oct 2019 09:56:55 +0300 Subject: [PATCH 27/45] Try running node init without preparation function calling --- core/node.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/node.py b/core/node.py index 843bec6c..dae55e22 100644 --- a/core/node.py +++ b/core/node.py @@ -77,10 +77,10 @@ def init(mta_endpoint, git_branch, github_token, docker_username, docker_passwor 'IMA_CONTRACTS_INFO_URL': ima_url, 'DKG_CONTRACTS_INFO_URL': dkg_url } + return init_data_dir() prepare_host(test_mode, disk_mountpoint) - return res = subprocess.run(['bash', INSTALL_SCRIPT], env=env) logging.info(f'Node init install script result: {res.stderr}, {res.stdout}') # todo: check execution result From 4210822083bc8e94f6f3cccc793f73f0b5eb9e56 Mon Sep 17 00:00:00 2001 From: ivd Date: Fri, 11 Oct 2019 10:02:57 +0300 Subject: [PATCH 28/45] Try skip only cli init test --- tests/cli/node_test.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/cli/node_test.py b/tests/cli/node_test.py index 9af6ee7c..d1a6efdd 100644 --- a/tests/cli/node_test.py +++ b/tests/cli/node_test.py @@ -17,6 +17,7 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . +import pytest import mock import requests @@ -76,6 +77,7 @@ def test_register_node_with_default_port_and_name(config, skip_auth): assert result.output == 'Enter node public IP: 0.0.0.0\nNode registered in SKALE manager. For more info run: skale node info\n' # noqa +@pytest.mark.skip def test_init_node(skip_local_only, config): params = ['--ima-endpoint', 'https://0.0.0.1:8080', '--stream', 'stream', '--github-token', 'token123', From 6c98c58c79fb6ac7a8105439bcd227be8d25f208 Mon Sep 17 00:00:00 2001 From: ivd Date: Fri, 11 Oct 2019 13:12:53 +0300 Subject: [PATCH 29/45] Try command that do nothing --- cli/node.py | 2 ++ core/node.py | 2 -- tests/cli/node_test.py | 3 +-- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/cli/node.py b/cli/node.py index d56d01f6..a6459b70 100644 --- a/cli/node.py +++ b/cli/node.py @@ -217,6 +217,7 @@ def init_node(ima_endpoint, install_deps, stream, github_token, docker_username, docker_password, endpoint, db_user, db_password, db_root_password, db_port, disk_mountpoint, manager_url, ima_url, dkg_url, test_mode): + return if install_deps: install_host_dependencies() if not db_root_password: @@ -320,6 +321,7 @@ def purge_node(): @local_only def update_node(ima_endpoint, github_token, docker_username, docker_password, endpoint, db_user, db_password, db_root_password, db_port, manager_url, ima_url, dkg_url): + return if not db_root_password: db_root_password = db_password update(ima_endpoint, github_token, docker_username, docker_password, endpoint, db_user, diff --git a/core/node.py b/core/node.py index dae55e22..4cf49f89 100644 --- a/core/node.py +++ b/core/node.py @@ -77,7 +77,6 @@ def init(mta_endpoint, git_branch, github_token, docker_username, docker_passwor 'IMA_CONTRACTS_INFO_URL': ima_url, 'DKG_CONTRACTS_INFO_URL': dkg_url } - return init_data_dir() prepare_host(test_mode, disk_mountpoint) @@ -114,7 +113,6 @@ def update(ima_endpoint, github_token, docker_username, docker_password, endpoin 'IMA_CONTRACTS_INFO_URL': ima_url, 'DKG_CONTRACTS_INFO_URL': dkg_url } - return res_update_project = subprocess.run(['sudo', '-E', 'bash', UPDATE_NODE_PROJECT_SCRIPT], env=env) logging.info( f'Update node project script result: {res_update_project.stderr}, \ diff --git a/tests/cli/node_test.py b/tests/cli/node_test.py index d1a6efdd..217a1e8b 100644 --- a/tests/cli/node_test.py +++ b/tests/cli/node_test.py @@ -17,7 +17,6 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -import pytest import mock import requests @@ -77,7 +76,7 @@ def test_register_node_with_default_port_and_name(config, skip_auth): assert result.output == 'Enter node public IP: 0.0.0.0\nNode registered in SKALE manager. For more info run: skale node info\n' # noqa -@pytest.mark.skip +# @pytest.mark.skip def test_init_node(skip_local_only, config): params = ['--ima-endpoint', 'https://0.0.0.1:8080', '--stream', 'stream', '--github-token', 'token123', From 1d87e1dcc5a49787185e804b96d05b2cd0001ecf Mon Sep 17 00:00:00 2001 From: Dmytro Tkachuk Date: Fri, 11 Oct 2019 13:24:16 +0300 Subject: [PATCH 30/45] SKALE-1653 new node_data location, restructure config dirs on host, refactor confiigs module --- cli/__init__.py | 2 +- cli/node.py | 26 +++------- configs/__init__.py | 70 ++++++++++++++++++++++++++ configs/cli_logger.py | 11 ++--- configs/node.py | 30 ------------ configs/resource_allocation.py | 3 +- configs/routes.py | 21 ++++++++ core/config.py | 90 ---------------------------------- core/core.py | 6 +-- core/helper.py | 10 ++-- core/host.py | 7 ++- core/node.py | 12 ++--- core/print_formatters.py | 2 +- core/user.py | 8 +-- core/validators.py | 4 +- core/wallet.py | 5 +- datafiles/install.sh | 16 +++--- main.py | 2 +- 18 files changed, 137 insertions(+), 188 deletions(-) delete mode 100644 configs/node.py create mode 100644 configs/routes.py delete mode 100644 core/config.py diff --git a/cli/__init__.py b/cli/__init__.py index 14288105..f68d72d2 100644 --- a/cli/__init__.py +++ b/cli/__init__.py @@ -1,4 +1,4 @@ -__version__ = '0.5.0' +__version__ = '0.6.0' if __name__ == "__main__": print(__version__) diff --git a/cli/node.py b/cli/node.py index 2da9e170..dedb15ba 100644 --- a/cli/node.py +++ b/cli/node.py @@ -30,8 +30,7 @@ from core.host import install_host_dependencies from core.helper import (abort_if_false, local_only, login_required, safe_load_texts) -from core.config import CONFIG_FILEPATH, DEFAULT_DB_USER, DEFAULT_DB_PORT -from configs.node import DEFAULT_NODE_BASE_PORT +from configs import CONFIG_FILEPATH, DEFAULT_DB_USER, DEFAULT_DB_PORT, DEFAULT_NODE_BASE_PORT config = ReadSettings(CONFIG_FILEPATH) TEXTS = safe_load_texts() @@ -200,11 +199,6 @@ def register_node(name, ip, port): prompt="Enter URL to IMA contracts ABI and addresses", help='URL to IMA contracts ABI and addresses' ) -@click.option( - '--dkg-url', - prompt="Enter URL to DKG contracts ABI and addresses", - help='URL to DKG contracts ABI and addresses' -) @click.option( '--filebeat-url', prompt="Enter URL to the Filebeat log server", @@ -217,16 +211,14 @@ def register_node(name, ip, port): @local_only def init_node(ima_endpoint, install_deps, stream, github_token, docker_username, docker_password, endpoint, db_user, db_password, db_root_password, db_port, disk_mountpoint, - manager_url, ima_url, dkg_url, filebeat_url, test_mode): + manager_url, ima_url, filebeat_url, test_mode): if install_deps: install_host_dependencies() if not db_root_password: db_root_password = db_password - - git_branch = stream - init(ima_endpoint, git_branch, github_token, docker_username, docker_password, endpoint, + init(ima_endpoint, stream, github_token, docker_username, docker_password, endpoint, db_user, db_password, db_root_password, db_port, disk_mountpoint, manager_url, ima_url, - dkg_url, filebeat_url, test_mode) + filebeat_url, test_mode) @node.command('purge', help="Uninstall SKALE node software from the machine") @@ -312,11 +304,6 @@ def purge_node(): prompt="Enter URL to IMA contracts ABI and addresses", help='URL to IMA contracts ABI and addresses' ) -@click.option( - '--dkg-url', - prompt="Enter URL to DKG contracts ABI and addresses", - help='URL to DKG contracts ABI and addresses' -) @click.option( '--filebeat-url', prompt="Enter URL to the Filebeat log server", @@ -324,9 +311,8 @@ def purge_node(): ) @local_only def update_node(ima_endpoint, github_token, docker_username, docker_password, endpoint, db_user, - db_password, db_root_password, db_port, manager_url, ima_url, dkg_url, - filebeat_url): + db_password, db_root_password, db_port, manager_url, ima_url, filebeat_url): if not db_root_password: db_root_password = db_password update(ima_endpoint, github_token, docker_username, docker_password, endpoint, db_user, - db_password, db_root_password, db_port, manager_url, ima_url, dkg_url, filebeat_url) + db_password, db_root_password, db_port, manager_url, ima_url, filebeat_url) diff --git a/configs/__init__.py b/configs/__init__.py index e69de29b..d7cd8cd0 100644 --- a/configs/__init__.py +++ b/configs/__init__.py @@ -0,0 +1,70 @@ +# -*- coding: utf-8 -*- +# +# This file is part of skale-node-cli +# +# Copyright (C) 2019 SKALE Labs +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +import os +import sys +import platform +from pathlib import Path +from configs.routes import ROUTES # noqa: F401 + +HOME_DIR = str(Path.home()) + +SKALE_DIR = os.path.join(HOME_DIR, '.skale') +PROJECT_PATH = os.path.join(SKALE_DIR, '.skale-node') +NODE_DATA_PATH = os.path.join(SKALE_DIR, 'node_data') +CONFIG_FILEPATH = os.path.join(SKALE_DIR, '.skale-cli.yaml') + +TOKENS_FILEPATH = os.path.join(NODE_DATA_PATH, 'tokens.json') +LOCAL_WALLET_FILEPATH = os.path.join(NODE_DATA_PATH, 'local_wallet.json') + +UNINSTALL_SCRIPT = os.path.join(PROJECT_PATH, 'scripts', 'uninstall.sh') +UPDATE_SCRIPT = os.path.join(PROJECT_PATH, 'scripts', 'update.sh') + + +ENV = os.environ.get('ENV') +CURRENT_FILE_LOCATION = os.path.dirname(os.path.realpath(__file__)) + +if ENV == 'dev': + PARDIR = os.path.join(CURRENT_FILE_LOCATION, os.pardir) +else: + PARDIR = os.path.join(sys._MEIPASS, 'data') + +TEXT_FILE = os.path.join(PARDIR, 'text.yml') +DATAFILES_FOLDER = os.path.join(PARDIR, 'datafiles') + +THIRDPARTY_FOLDER_PATH = os.path.join(DATAFILES_FOLDER, 'third_party') + +DEPENDENCIES_SCRIPT = os.path.join(DATAFILES_FOLDER, 'dependencies.sh') +INSTALL_SCRIPT = os.path.join(DATAFILES_FOLDER, 'install.sh') +INSTALL_CONVOY_SCRIPT = os.path.join(DATAFILES_FOLDER, 'install_convoy.sh') +UPDATE_NODE_PROJECT_SCRIPT = os.path.join(DATAFILES_FOLDER, 'update_node_project.sh') + +LONG_LINE = '-' * 50 + +SKALE_NODE_UI_PORT = 3007 +SKALE_NODE_UI_LOCALHOST = 'http://0.0.0.0' +DEFAULT_URL_SCHEME = 'http://' + +DEFAULT_DB_USER = 'root' +DEFAULT_DB_PORT = '3306' + +DEFAULT_NODE_BASE_PORT = 10000 + +HOST_OS = platform.system() +MAC_OS_SYSTEM_NAME = 'Darwin' diff --git a/configs/cli_logger.py b/configs/cli_logger.py index b23edc1e..cfc8db1c 100644 --- a/configs/cli_logger.py +++ b/configs/cli_logger.py @@ -18,7 +18,7 @@ # along with this program. If not, see . import os -from configs.node import HOME_DIR +from configs import SKALE_DIR LOG_FORMAT = '%(asctime)s - %(name)s - %(levelname)s - %(message)s' @@ -26,9 +26,6 @@ LOG_FILE_SIZE_BYTES = LOG_FILE_SIZE_MB * 1000000 LOG_BACKUP_COUNT = 1 -LOG_DATA_PATH = os.path.join(HOME_DIR, '.skale-cli-log') - -LOG_FILENAME = 'node-cli.log' -DEBUG_LOG_FILENAME = 'debug-node-cli.log' -LOG_FILEPATH = os.path.join(LOG_DATA_PATH, LOG_FILENAME) -DEBUG_LOG_FILEPATH = os.path.join(LOG_DATA_PATH, DEBUG_LOG_FILENAME) +LOG_DATA_PATH = os.path.join(SKALE_DIR, '.skale-cli-log') +LOG_FILEPATH = os.path.join(LOG_DATA_PATH, 'node-cli.log') +DEBUG_LOG_FILEPATH = os.path.join(LOG_DATA_PATH, 'debug-node-cli.log') diff --git a/configs/node.py b/configs/node.py deleted file mode 100644 index 596ef775..00000000 --- a/configs/node.py +++ /dev/null @@ -1,30 +0,0 @@ -# -*- coding: utf-8 -*- -# -# This file is part of skale-node-cli -# -# Copyright (C) 2019 SKALE Labs -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . - -import os -from pathlib import Path - -SKALE_VOLUME_PATH = '/skale_vol' -NODE_DATA_PATH = '/skale_node_data' -HOME_DIR = str(Path.home()) - -LOCAL_WALLET_FILENAME = 'local_wallet.json' -LOCAL_WALLET_FILEPATH = os.path.join(NODE_DATA_PATH, LOCAL_WALLET_FILENAME) - -DEFAULT_NODE_BASE_PORT = 10000 diff --git a/configs/resource_allocation.py b/configs/resource_allocation.py index be07a850..8f5e45f8 100644 --- a/configs/resource_allocation.py +++ b/configs/resource_allocation.py @@ -18,8 +18,7 @@ # along with this program. If not, see . import os -from configs.node import NODE_DATA_PATH -from core.config import THIRDPARTY_FOLDER_PATH, DATAFILES_FOLDER +from configs import NODE_DATA_PATH, THIRDPARTY_FOLDER_PATH, DATAFILES_FOLDER MEDIUM_DIVIDER = 1 SMALL_DIVIDER = 8 diff --git a/configs/routes.py b/configs/routes.py new file mode 100644 index 00000000..3f1bf176 --- /dev/null +++ b/configs/routes.py @@ -0,0 +1,21 @@ +ROUTES = { + 'login': '/login', + 'logout': '/logout', + 'register': '/join', + 'node_info': '/node-info', + 'node_about': '/about-node', + 'create_node': '/create-node', + 'test_host': '/test-host', + + 'wallet_info': '/load-wallet', + 'validators_info': '/validators-info', + + 'schains_containers': '/containers/schains/list', + 'node_schains': '/schains/list', + 'schain_config': '/schain-config', + 'skale_containers': '/containers/list', + + 'logs_dump': '/logs/dump', + 'first-bounties': '/first-bounties', + 'last-bounties': '/last-bounties' +} diff --git a/core/config.py b/core/config.py deleted file mode 100644 index c678df13..00000000 --- a/core/config.py +++ /dev/null @@ -1,90 +0,0 @@ -# -*- coding: utf-8 -*- -# -# This file is part of skale-node-cli -# -# Copyright (C) 2019 SKALE Labs -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . - -import sys -import os -import platform -from pathlib import Path - -ENV = os.environ.get('ENV') - -home = str(Path.home()) - -CONFIG_FILENAME = '.skale-cli.yaml' -CONFIG_FILEPATH = os.path.join(home, CONFIG_FILENAME) - -CURRENT_FILE_LOCATION = os.path.dirname(os.path.realpath(__file__)) - -if ENV == 'dev': - PARDIR = os.path.join(CURRENT_FILE_LOCATION, os.pardir) -else: - PARDIR = os.path.join(sys._MEIPASS, 'data') - -TEXT_FILE = os.path.join(PARDIR, 'text.yml') -DATAFILES_FOLDER = os.path.join(PARDIR, 'datafiles') - -THIRDPARTY_FOLDER_NAME = 'third_party' -THIRDPARTY_FOLDER_PATH = os.path.join(DATAFILES_FOLDER, THIRDPARTY_FOLDER_NAME) - -DEPENDENCIES_SCRIPT = os.path.join(DATAFILES_FOLDER, 'dependencies.sh') -INSTALL_SCRIPT = os.path.join(DATAFILES_FOLDER, 'install.sh') -INSTALL_CONVOY_SCRIPT = os.path.join(DATAFILES_FOLDER, 'install_convoy.sh') -UPDATE_NODE_PROJECT_SCRIPT = os.path.join(DATAFILES_FOLDER, 'update_node_project.sh') - -URLS = { - 'login': '/login', - 'logout': '/logout', - 'register': '/join', - 'node_info': '/node-info', - 'node_about': '/about-node', - 'create_node': '/create-node', - 'test_host': '/test-host', - - 'wallet_info': '/load-wallet', - 'validators_info': '/validators-info', - - 'schains_containers': '/containers/schains/list', - 'node_schains': '/schains/list', - 'schain_config': '/schain-config', - 'skale_containers': '/containers/list', - - 'logs_dump': '/logs/dump', - 'first-bounties': '/first-bounties', - 'last-bounties': '/last-bounties' -} - -LONG_LINE = '-' * 50 - -SKALE_NODE_UI_PORT = 3007 -SKALE_NODE_UI_LOCALHOST = 'http://0.0.0.0' -DEFAULT_URL_SCHEME = 'http://' - -SKALE_PROJECT_PATH = os.path.join('/skale', 'skale-node') -UNINSTALL_SCRIPT = os.path.join(SKALE_PROJECT_PATH, 'scripts', 'uninstall.sh') -UPDATE_SCRIPT = os.path.join(SKALE_PROJECT_PATH, 'scripts', 'update.sh') - -NODE_DATA_PATH = '/skale_node_data' -TOKENS_FILENAME = 'tokens.json' -TOKENS_FILEPATH = os.path.join(NODE_DATA_PATH, TOKENS_FILENAME) - -DEFAULT_DB_USER = 'root' -DEFAULT_DB_PORT = '3306' - -HOST_OS = platform.system() -MAC_OS_SYSTEM_NAME = 'Darwin' diff --git a/core/core.py b/core/core.py index e6a8eac1..02c0f7db 100644 --- a/core/core.py +++ b/core/core.py @@ -19,7 +19,7 @@ import inspect import requests -from core.config import URLS, LONG_LINE +from configs import LONG_LINE, ROUTES from core.helper import safe_load_texts, get_node_creds, construct_url, \ get_response_data, clean_cookies, get_request @@ -29,7 +29,7 @@ def get_node_info(config, format): host, cookies = get_node_creds(config) - url = construct_url(host, URLS['node_info']) + url = construct_url(host, ROUTES['node_info']) response = get_request(url, cookies) if response is None: return None @@ -52,7 +52,7 @@ def get_node_info(config, format): def get_node_about(config, format): host, cookies = get_node_creds(config) - url = construct_url(host, URLS['node_about']) + url = construct_url(host, ROUTES['node_about']) response = get_request(url, cookies) if response is None: diff --git a/core/helper.py b/core/helper.py index 4c018e63..365d8ef7 100644 --- a/core/helper.py +++ b/core/helper.py @@ -31,8 +31,8 @@ from logging import Formatter from readsettings import ReadSettings -from core.config import CONFIG_FILEPATH, TEXT_FILE, SKALE_NODE_UI_LOCALHOST, SKALE_NODE_UI_PORT, \ - LONG_LINE, URLS, HOST_OS, MAC_OS_SYSTEM_NAME +from configs import CONFIG_FILEPATH, TEXT_FILE, SKALE_NODE_UI_LOCALHOST, SKALE_NODE_UI_PORT, \ + LONG_LINE, HOST_OS, MAC_OS_SYSTEM_NAME, ROUTES from configs.cli_logger import LOG_FORMAT, LOG_BACKUP_COUNT, LOG_FILE_SIZE_BYTES, LOG_FILEPATH, \ DEBUG_LOG_FILEPATH @@ -161,7 +161,7 @@ def print_err_response(err_response): def get(url_name, params=None): host, cookies = get_node_creds(config) - url = construct_url(host, URLS[url_name]) + url = construct_url(host, ROUTES[url_name]) response = get_request(url, cookies, params) if response is None: @@ -181,7 +181,7 @@ def get(url_name, params=None): def download_log_file(name, type, schain): host, cookies = get_node_creds(config) - url = construct_url(host, URLS['log_download']) + url = construct_url(host, ROUTES['log_download']) params = { 'filename': name, 'type': type, @@ -202,7 +202,7 @@ def download_log_file(name, type, schain): def download_dump(path, container_name=None): host, cookies = get_node_creds(config) - url = construct_url(host, URLS['logs_dump']) + url = construct_url(host, ROUTES['logs_dump']) params = {} if container_name: params['container_name'] = container_name diff --git a/core/host.py b/core/host.py index dffe3467..7528b767 100644 --- a/core/host.py +++ b/core/host.py @@ -25,9 +25,8 @@ from core.resources import save_resource_allocation_config -from core.config import DEPENDENCIES_SCRIPT, URLS, SKALE_NODE_UI_PORT, DEFAULT_URL_SCHEME, \ - INSTALL_CONVOY_SCRIPT -from configs.node import NODE_DATA_PATH +from configs import DEPENDENCIES_SCRIPT, ROUTES, SKALE_NODE_UI_PORT, DEFAULT_URL_SCHEME, \ + INSTALL_CONVOY_SCRIPT, NODE_DATA_PATH from configs.cli_logger import LOG_DATA_PATH from configs.resource_allocation import DISK_MOUNTPOINT_FILEPATH, \ CONVOY_HELPER_SCRIPT_FILEPATH, CONVOY_SERVICE_TEMPLATE_PATH, CONVOY_SERVICE_PATH @@ -66,7 +65,7 @@ def reset_host(config): def test_host(host): - url = construct_url(host, URLS['test_host']) + url = construct_url(host, ROUTES['test_host']) try: response = requests.get(url) diff --git a/core/node.py b/core/node.py index 1c503d64..10c4000c 100644 --- a/core/node.py +++ b/core/node.py @@ -21,8 +21,8 @@ import logging import requests import subprocess -from core.config import INSTALL_SCRIPT, UNINSTALL_SCRIPT, UPDATE_SCRIPT, UPDATE_NODE_PROJECT_SCRIPT -from core.config import URLS +from configs import (INSTALL_SCRIPT, UNINSTALL_SCRIPT, UPDATE_SCRIPT, UPDATE_NODE_PROJECT_SCRIPT, + ROUTES) from core.helper import get_node_creds, construct_url, post_request, print_err_response from core.host import prepare_host, init_data_dir @@ -38,7 +38,7 @@ def create_node(config, name, p2p_ip, public_ip, port): 'publicIP': public_ip, 'port': port } - url = construct_url(host, URLS['create_node']) + url = construct_url(host, ROUTES['create_node']) try: # todo: tmp fix! response = post_request(url, data, cookies) @@ -58,7 +58,7 @@ def create_node(config, name, p2p_ip, public_ip, port): def init(mta_endpoint, git_branch, github_token, docker_username, docker_password, endpoint, db_user, db_password, db_root_password, db_port, disk_mountpoint, manager_url, ima_url, - dkg_url, filebeat_url, test_mode): + filebeat_url, test_mode): env = { **os.environ, 'MTA_ENDPOINT': mta_endpoint, @@ -74,7 +74,6 @@ def init(mta_endpoint, git_branch, github_token, docker_username, docker_passwor 'DISK_MOUNTPOINT': disk_mountpoint, 'MANAGER_CONTRACTS_INFO_URL': manager_url, 'IMA_CONTRACTS_INFO_URL': ima_url, - 'DKG_CONTRACTS_INFO_URL': dkg_url, 'FILEBEAT_HOST': filebeat_url, } init_data_dir() @@ -96,7 +95,7 @@ def deregister(): def update(ima_endpoint, github_token, docker_username, docker_password, endpoint, db_user, - db_password, db_root_password, db_port, manager_url, ima_url, dkg_url, filebeat_url): + db_password, db_root_password, db_port, manager_url, ima_url, filebeat_url): env = { **os.environ, 'IMA_ENDPOINT': ima_endpoint, @@ -111,7 +110,6 @@ def update(ima_endpoint, github_token, docker_username, docker_password, endpoin 'DISK_MOUNTPOINT': '/', 'MANAGER_CONTRACTS_INFO_URL': manager_url, 'IMA_CONTRACTS_INFO_URL': ima_url, - 'DKG_CONTRACTS_INFO_URL': dkg_url, 'FILEBEAT_HOST': filebeat_url, } res_update_project = subprocess.run(['sudo', '-E', 'bash', UPDATE_NODE_PROJECT_SCRIPT], env=env) diff --git a/core/print_formatters.py b/core/print_formatters.py index 5ea438a4..1a865edc 100644 --- a/core/print_formatters.py +++ b/core/print_formatters.py @@ -22,7 +22,7 @@ import texttable from dateutil import parser -from core.config import LONG_LINE +from configs import LONG_LINE def get_tty_width(): diff --git a/core/user.py b/core/user.py index c529fc86..d255e569 100644 --- a/core/user.py +++ b/core/user.py @@ -21,7 +21,7 @@ import logging import pickle import json -from core.config import URLS, TOKENS_FILEPATH +from configs import ROUTES, TOKENS_FILEPATH from core.helper import safe_get_config, construct_url, clean_cookies, get_localhost_endpoint, \ get_request, post_request @@ -37,7 +37,7 @@ def register_user(config, username, password, token): 'password': password, 'token': token } - url = construct_url(host, URLS['register']) + url = construct_url(host, ROUTES['register']) response = post_request(url, data) if response is None: return None @@ -60,7 +60,7 @@ def login_user(config, username, password): 'username': username, 'password': password } - url = construct_url(host, URLS['login']) + url = construct_url(host, ROUTES['login']) response = post_request(url, data) if response is None: return None @@ -75,7 +75,7 @@ def login_user(config, username, password): def logout_user(config): host = safe_get_config(config, 'host') - url = construct_url(host, URLS['logout']) + url = construct_url(host, ROUTES['logout']) response = get_request(url) if response is None: return None diff --git a/core/validators.py b/core/validators.py index 2dac8041..a6dc7cea 100644 --- a/core/validators.py +++ b/core/validators.py @@ -17,13 +17,13 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -from core.config import URLS +from configs import ROUTES from core.helper import get_node_creds, construct_url, get_request def get_validators_info(config, format): host, cookies = get_node_creds(config) - url = construct_url(host, URLS['validators_info']) + url = construct_url(host, ROUTES['validators_info']) response = get_request(url, cookies) if response is None: diff --git a/core/wallet.py b/core/wallet.py index 7b9d04dc..4d5c3bcb 100644 --- a/core/wallet.py +++ b/core/wallet.py @@ -22,10 +22,9 @@ from skale.utils.helper import private_key_to_address from web3 import Web3 -from core.config import URLS, LONG_LINE +from configs import ROUTES, LONG_LINE, LOCAL_WALLET_FILEPATH from core.helper import get_node_creds, construct_url, get_request from tools.helper import write_json -from configs.node import LOCAL_WALLET_FILEPATH def set_wallet_by_pk(private_key): @@ -38,7 +37,7 @@ def set_wallet_by_pk(private_key): def get_wallet_info(config, format): host, cookies = get_node_creds(config) - url = construct_url(host, URLS['wallet_info']) + url = construct_url(host, ROUTES['wallet_info']) response = get_request(url, cookies) if response is None: diff --git a/datafiles/install.sh b/datafiles/install.sh index 8e03cab9..6082a279 100644 --- a/datafiles/install.sh +++ b/datafiles/install.sh @@ -1,17 +1,18 @@ #!/usr/bin/env bash -REPO_NAME=skale-node +SKALE_DIR=~/.skale +SKALE_NODE_DIR_NAME=.skale-node +SKALE_NODE_DIR="$SKALE_DIR"/"$SKALE_NODE_DIR_NAME" -sudo mkdir -p /skale -#sudo chown -R $USER: /skale -cd /skale +mkdir -p $SKALE_DIR +cd $SKALE_DIR -sudo git clone -b $GIT_BRANCH https://$GITHUB_TOKEN\@github.com/skalenetwork/$REPO_NAME.git -#cp -f /tmp/data.json ./skale-node/config/data.json +rm -rf $SKALE_NODE_DIR +sudo git clone -b $GIT_BRANCH https://$GITHUB_TOKEN\@github.com/skalenetwork/skale-node.git .skale-node umount $DISK_MOUNTPOINT -cd /skale/$REPO_NAME/scripts +cd "$SKALE_NODE_DIR"/scripts export DOCKER_USERNAME=$DOCKER_USERNAME export DOCKER_PASSWORD=$DOCKER_PASSWORD @@ -22,7 +23,6 @@ export IMA_ENDPOINT=$IMA_ENDPOINT export MANAGER_CONTRACTS_INFO_URL=$MANAGER_CONTRACTS_INFO_URL export IMA_CONTRACTS_INFO_URL=$IMA_CONTRACTS_INFO_URL -export DKG_CONTRACTS_INFO_URL=$DKG_CONTRACTS_INFO_URL export DB_USER=$DB_USER export DB_PORT=$DB_PORT diff --git a/main.py b/main.py index 73ab7fef..a9c689ee 100644 --- a/main.py +++ b/main.py @@ -33,7 +33,7 @@ from core.helper import (login_required, safe_load_texts, local_only, no_node, init_default_logger) -from core.config import CONFIG_FILEPATH, LONG_LINE +from configs import CONFIG_FILEPATH, LONG_LINE from core.wallet import get_wallet_info, set_wallet_by_pk from core.user import (register_user, login_user, logout_user, show_registration_token) From 410c674adee4ec60ff00445d6f890c01ca3c64bf Mon Sep 17 00:00:00 2001 From: ivd Date: Fri, 11 Oct 2019 16:02:38 +0300 Subject: [PATCH 31/45] Fix cli/node freezing --- cli/node.py | 2 -- tests/cli/node_test.py | 25 +++++++++++++++++++++---- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/cli/node.py b/cli/node.py index 817b9665..96b7c5cd 100644 --- a/cli/node.py +++ b/cli/node.py @@ -221,7 +221,6 @@ def register_node(name, ip, port): def init_node(ima_endpoint, install_deps, stream, github_token, docker_username, docker_password, endpoint, db_user, db_password, db_root_password, db_port, disk_mountpoint, manager_url, ima_url, dkg_url, filebeat_url, test_mode): - return if install_deps: install_host_dependencies() if not db_root_password: @@ -330,7 +329,6 @@ def purge_node(): def update_node(ima_endpoint, github_token, docker_username, docker_password, endpoint, db_user, db_password, db_root_password, db_port, manager_url, ima_url, dkg_url, filebeat_url): - return if not db_root_password: db_root_password = db_password update(ima_endpoint, github_token, docker_username, docker_password, endpoint, db_user, diff --git a/tests/cli/node_test.py b/tests/cli/node_test.py index 217a1e8b..e0e07b5c 100644 --- a/tests/cli/node_test.py +++ b/tests/cli/node_test.py @@ -21,7 +21,7 @@ import requests from tests.helper import response_mock, run_command_mock -from cli.node import (register_node, init_node, update_node, +from cli.node import (register_node, init_node, purge_node, update_node, node_about, node_info) @@ -86,7 +86,8 @@ def test_init_node(skip_local_only, config): '--db-password', 'pass123', '--db-root-password', 'pass123', '--db-port', 8087, '--disk-mountpoint', '/dev/sdp', '--manager-url', '0.0.0.1:8080', '--ima-url', 'ws://0.0.0.1:8080', - '--dkg-url', '0.0.0.1:8080'] + '--dkg-url', '0.0.0.1:8080', + '--filebeat-url', 'http://0.0.0.1:8080'] resp_mock = response_mock(requests.codes.created) with mock.patch('subprocess.run'), \ mock.patch('cli.node.install_host_dependencies'), \ @@ -110,7 +111,8 @@ def test_init_node_invalid_url(skip_local_only, config): '--db-password', 'pass123', '--db-root-password', 'pass123', '--db-port', 8080, '--disk-mountpoint', '/dev/sda', '--manager-url', '0.0.0.0:8080', '--ima-url', 'ws://0.0.0.0:8080', - '--dkg-url', '0.0.0.0:8080'] + '--dkg-url', '0.0.0.0:8080', + '--filebeat-url', 'http://0.0.0.1:8080'] resp_mock = response_mock(requests.codes.created) with mock.patch('core.node.subprocess.run'), \ mock.patch('cli.node.install_host_dependencies'), \ @@ -125,6 +127,20 @@ def test_init_node_invalid_url(skip_local_only, config): assert result.output == 'Usage: init [OPTIONS]\nTry "init --help" for help.\n\nError: Invalid value for "--ima-endpoint": Expected valid url. Got invalid_url\n' # noqa +def test_purge(skip_local_only, config): + params = ['--yes'] + resp_mock = response_mock(requests.codes.created) + with mock.patch('core.node.subprocess.run'): + result = run_command_mock( + 'core.node.post_request', + resp_mock, + purge_node, + params + ) + assert result.exit_code == 0 + assert result.output == '' # noqa + + def test_update_node(skip_local_only, config): params = ['--ima-endpoint', 'https://0.0.0.0:8080', '--github-token', 'token123', @@ -134,7 +150,8 @@ def test_update_node(skip_local_only, config): '--db-password', 'pass123', '--db-root-password', 'pass123', '--db-port', 8080, '--manager-url', '0.0.0.0:8080', '--ima-url', 'ws://0.0.0.0:8080', - '--dkg-url', '0.0.0.0:8080', '--yes'] + '--dkg-url', '0.0.0.0:8080', '--yes', + '--filebeat-url', 'http://0.0.0.1:8080'] resp_mock = response_mock(requests.codes.created) with mock.patch('subprocess.run'), \ mock.patch('cli.node.install_host_dependencies'), \ From 57cd1ed10eae588167ab51d2019342314021ff5c Mon Sep 17 00:00:00 2001 From: ivd Date: Wed, 16 Oct 2019 13:51:15 +0300 Subject: [PATCH 32/45] Fix merging with develop core/config problems --- configs/__init__.py | 5 ++- core/config.py | 90 --------------------------------------------- tests/conftest.py | 2 +- tools/helper.py | 2 +- 4 files changed, 5 insertions(+), 94 deletions(-) delete mode 100644 core/config.py diff --git a/configs/__init__.py b/configs/__init__.py index d7cd8cd0..83937cce 100644 --- a/configs/__init__.py +++ b/configs/__init__.py @@ -27,8 +27,9 @@ SKALE_DIR = os.path.join(HOME_DIR, '.skale') PROJECT_PATH = os.path.join(SKALE_DIR, '.skale-node') -NODE_DATA_PATH = os.path.join(SKALE_DIR, 'node_data') -CONFIG_FILEPATH = os.path.join(SKALE_DIR, '.skale-cli.yaml') +NODE_DATA_PATH = os.path.join(SKALE_DIR, 'NODE_DATA_PATH') +CONFIG_FILEPATH = os.environ.get('CONFIG_FILEPATH') or \ + os.path.join(SKALE_DIR, '.skale-cli.yaml') TOKENS_FILEPATH = os.path.join(NODE_DATA_PATH, 'tokens.json') LOCAL_WALLET_FILEPATH = os.path.join(NODE_DATA_PATH, 'local_wallet.json') diff --git a/core/config.py b/core/config.py deleted file mode 100644 index 469c3ee9..00000000 --- a/core/config.py +++ /dev/null @@ -1,90 +0,0 @@ -# -*- coding: utf-8 -*- -# -# This file is part of skale-node-cli -# -# Copyright (C) 2019 SKALE Labs -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . - -import sys -import os -import platform -from pathlib import Path - -ENV = os.environ.get('ENV') - -home = str(Path.home()) - -CONFIG_FILEPATH = os.environ.get('CONFIG_FILEPATH', None) or \ - os.path.join(home, '.skale-cli.yaml') - -CURRENT_FILE_LOCATION = os.path.dirname(os.path.realpath(__file__)) - -if ENV == 'dev': - PARDIR = os.path.join(CURRENT_FILE_LOCATION, os.pardir) -else: - PARDIR = os.path.join(sys._MEIPASS, 'data') - -TEXT_FILE = os.path.join(PARDIR, 'text.yml') -DATAFILES_FOLDER = os.path.join(PARDIR, 'datafiles') - -THIRDPARTY_FOLDER_NAME = 'third_party' -THIRDPARTY_FOLDER_PATH = os.path.join(DATAFILES_FOLDER, THIRDPARTY_FOLDER_NAME) - -DEPENDENCIES_SCRIPT = os.path.join(DATAFILES_FOLDER, 'dependencies.sh') -INSTALL_SCRIPT = os.path.join(DATAFILES_FOLDER, 'install.sh') -INSTALL_CONVOY_SCRIPT = os.path.join(DATAFILES_FOLDER, 'install_convoy.sh') -UPDATE_NODE_PROJECT_SCRIPT = os.path.join(DATAFILES_FOLDER, 'update_node_project.sh') - -URLS = { - 'login': '/login', - 'logout': '/logout', - 'register': '/join', - 'node_info': '/node-info', - 'node_about': '/about-node', - 'create_node': '/create-node', - 'test_host': '/test-host', - - 'wallet_info': '/load-wallet', - 'validators_info': '/validators-info', - - 'schains_containers': '/containers/schains/list', - 'node_schains': '/schains/list', - 'schain_config': '/schain-config', - 'skale_containers': '/containers/list', - - 'logs_dump': '/logs/dump', - 'first-bounties': '/first-bounties', - 'last-bounties': '/last-bounties' -} - -LONG_LINE = '-' * 50 - -SKALE_NODE_UI_PORT = 3007 -SKALE_NODE_UI_LOCALHOST = 'http://0.0.0.0' -DEFAULT_URL_SCHEME = 'http://' - -SKALE_PROJECT_PATH = os.path.join('/skale', 'skale-node') -UNINSTALL_SCRIPT = os.path.join(SKALE_PROJECT_PATH, 'scripts', 'uninstall.sh') -UPDATE_SCRIPT = os.path.join(SKALE_PROJECT_PATH, 'scripts', 'update.sh') - -NODE_DATA_PATH = '/skale_node_data' -TOKENS_FILENAME = 'tokens.json' -TOKENS_FILEPATH = os.path.join(NODE_DATA_PATH, TOKENS_FILENAME) - -DEFAULT_DB_USER = 'root' -DEFAULT_DB_PORT = '3306' - -HOST_OS = platform.system() -MAC_OS_SYSTEM_NAME = 'Darwin' diff --git a/tests/conftest.py b/tests/conftest.py index b795b76e..13e623d0 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -23,7 +23,7 @@ from mock import Mock from readsettings import ReadSettings -from core.config import CONFIG_FILEPATH +from configs import CONFIG_FILEPATH @pytest.fixture diff --git a/tools/helper.py b/tools/helper.py index 65a93930..f9d56e33 100644 --- a/tools/helper.py +++ b/tools/helper.py @@ -27,7 +27,7 @@ from jinja2 import Environment from readsettings import ReadSettings -from core.config import CONFIG_FILEPATH +from configs import CONFIG_FILEPATH logger = logging.getLogger(__name__) From 2b8101535321674171be497c76d9cfdcac145890 Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Wed, 16 Oct 2019 12:57:52 +0000 Subject: [PATCH 33/45] Bump pycryptodome from 3.8.2 to 3.9.0 Bumps [pycryptodome](https://github.com/Legrandin/pycryptodome) from 3.8.2 to 3.9.0. - [Release notes](https://github.com/Legrandin/pycryptodome/releases) - [Changelog](https://github.com/Legrandin/pycryptodome/blob/master/Changelog.rst) - [Commits](https://github.com/Legrandin/pycryptodome/compare/v3.8.2...v3.9.0) Signed-off-by: dependabot-preview[bot] --- requirements.txt | 2 +- setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index bcd40651..ed601bda 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,6 +7,6 @@ python-dateutil==2.8.0 Jinja2==2.10.1 skale-py==0.82.0 eth-hash==0.2.0 -pycryptodome==3.8.2 +pycryptodome==3.9.0 psutil==5.6.3 diff --git a/setup.py b/setup.py index 2d2414c9..5ff6cdea 100644 --- a/setup.py +++ b/setup.py @@ -60,7 +60,7 @@ def find_version(*file_paths): "Jinja2==2.10.1", "skale-py==0.82.0", "eth-hash==0.2.0", - "pycryptodome==3.8.2", + "pycryptodome==3.9.0", "psutil==5.6.3" ], python_requires='>=3.6,<4', From cbf67937bbaf55ad6dbfa5d5c2a772864a66d729 Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Wed, 16 Oct 2019 12:57:52 +0000 Subject: [PATCH 34/45] Bump readsettings from 3.4.0 to 3.4.5 Bumps [readsettings](https://github.com/Richienb/readsettings-python) from 3.4.0 to 3.4.5. - [Release notes](https://github.com/Richienb/readsettings-python/releases) - [Commits](https://github.com/Richienb/readsettings-python/compare/3.4.0...3.4.5) Signed-off-by: dependabot-preview[bot] --- requirements.txt | 2 +- setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index bcd40651..78a94627 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,6 @@ click==7.0 confuse -readsettings==3.4.0 +readsettings==3.4.5 web3==4.9.2 texttable==1.6.2 python-dateutil==2.8.0 diff --git a/setup.py b/setup.py index 2d2414c9..b2146b8c 100644 --- a/setup.py +++ b/setup.py @@ -53,7 +53,7 @@ def find_version(*file_paths): install_requires=[ "click==7.0", "confuse", - "readsettings==3.4.0", + "readsettings==3.4.5", "web3==4.9.2", "texttable==1.6.2", "python-dateutil==2.8.0", From 6e8914c43c24f9a88b85bb34a5555000d4fe5887 Mon Sep 17 00:00:00 2001 From: Dmytro Tkachuk Date: Wed, 16 Oct 2019 16:12:45 +0300 Subject: [PATCH 35/45] SKALE-1653 fix update script --- datafiles/update_node_project.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/datafiles/update_node_project.sh b/datafiles/update_node_project.sh index 7265ff0e..05b985e9 100644 --- a/datafiles/update_node_project.sh +++ b/datafiles/update_node_project.sh @@ -1,6 +1,8 @@ #!/bin/bash -REPO_NAME=skale-node +SKALE_DIR=~/.skale +SKALE_NODE_DIR_NAME=.skale-node +SKALE_NODE_DIR="$SKALE_DIR"/"$SKALE_NODE_DIR_NAME" -cd /skale/$REPO_NAME +cd $SKALE_NODE_DIR sudo git pull From c1e7c7542e979f67e703de7f593df620242aa9b0 Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Thu, 17 Oct 2019 00:13:59 +0000 Subject: [PATCH 36/45] Bump pytest-cov from 2.7.1 to 2.8.1 Bumps [pytest-cov](https://github.com/pytest-dev/pytest-cov) from 2.7.1 to 2.8.1. - [Release notes](https://github.com/pytest-dev/pytest-cov/releases) - [Changelog](https://github.com/pytest-dev/pytest-cov/blob/master/CHANGELOG.rst) - [Commits](https://github.com/pytest-dev/pytest-cov/compare/v2.7.1...v2.8.1) Signed-off-by: dependabot-preview[bot] --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 2d2414c9..557c785b 100644 --- a/setup.py +++ b/setup.py @@ -28,7 +28,7 @@ def find_version(*file_paths): "bumpversion==0.5.3", "PyInstaller==3.5", "pytest==5.2.1", - "pytest-cov==2.7.1", + "pytest-cov==2.8.1", "twine==1.12.1", "when-changed" ] From ccb1614e5e416a1805c10ed2054cd3f27fca6136 Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Thu, 17 Oct 2019 00:15:06 +0000 Subject: [PATCH 37/45] Update isort requirement from <4.3.5,>=4.2.15 to >=4.2.15,<4.3.22 Updates the requirements on [isort](https://github.com/timothycrosley/isort) to permit the latest version. - [Release notes](https://github.com/timothycrosley/isort/releases) - [Changelog](https://github.com/timothycrosley/isort/blob/develop/CHANGELOG.md) - [Commits](https://github.com/timothycrosley/isort/compare/4.2.15...4.3.21) Signed-off-by: dependabot-preview[bot] --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 2d2414c9..93f0e777 100644 --- a/setup.py +++ b/setup.py @@ -21,7 +21,7 @@ def find_version(*file_paths): extras_require = { 'linter': [ "flake8==3.4.1", - "isort>=4.2.15,<4.3.5", + "isort>=4.2.15,<4.3.22", ], 'dev': [ "boto3==1.9.233", From b34d1759c2ac268797437a056108d51db1d1d38c Mon Sep 17 00:00:00 2001 From: Dmytro Tkachuk Date: Thu, 17 Oct 2019 13:21:28 +0300 Subject: [PATCH 38/45] SKALE-1653 update changelog --- CHANGELOG.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 19dd4aab..14b184bd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,17 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## Unreleased + + +### Added + + +### Changed + +- `--dkg-url` option for `node init` and `node update` commands removed + + ## [0.4.0] - 2019-10-03 From a5e6588f4cff138f961a922e2c335460b67a797a Mon Sep 17 00:00:00 2001 From: Dmytro Tkachuk Date: Thu, 17 Oct 2019 13:23:46 +0300 Subject: [PATCH 39/45] SKALE-1653 minor changes --- configs/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configs/__init__.py b/configs/__init__.py index d7cd8cd0..3dc45b56 100644 --- a/configs/__init__.py +++ b/configs/__init__.py @@ -24,8 +24,8 @@ from configs.routes import ROUTES # noqa: F401 HOME_DIR = str(Path.home()) - SKALE_DIR = os.path.join(HOME_DIR, '.skale') + PROJECT_PATH = os.path.join(SKALE_DIR, '.skale-node') NODE_DATA_PATH = os.path.join(SKALE_DIR, 'node_data') CONFIG_FILEPATH = os.path.join(SKALE_DIR, '.skale-cli.yaml') From 6800ff02a83f41048ff15839faf32553873e9db2 Mon Sep 17 00:00:00 2001 From: ivd Date: Thu, 17 Oct 2019 13:33:50 +0300 Subject: [PATCH 40/45] Fix configs.__init__ invalid node data path --- configs/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configs/__init__.py b/configs/__init__.py index d47b24a8..c1184da2 100644 --- a/configs/__init__.py +++ b/configs/__init__.py @@ -27,7 +27,7 @@ SKALE_DIR = os.path.join(HOME_DIR, '.skale') PROJECT_PATH = os.path.join(SKALE_DIR, '.skale-node') -NODE_DATA_PATH = os.path.join(SKALE_DIR, 'NODE_DATA_PATH') +NODE_DATA_PATH = os.path.join(SKALE_DIR, 'node_data') CONFIG_FILEPATH = os.environ.get('CONFIG_FILEPATH') or \ os.path.join(SKALE_DIR, '.skale-cli.yaml') From 44c4c222590b33a97236b86c3e06a36810c3fee1 Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Thu, 17 Oct 2019 12:39:29 +0000 Subject: [PATCH 41/45] Bump jinja2 from 2.10.1 to 2.10.3 Bumps [jinja2](https://github.com/pallets/jinja) from 2.10.1 to 2.10.3. - [Release notes](https://github.com/pallets/jinja/releases) - [Changelog](https://github.com/pallets/jinja/blob/master/CHANGES.rst) - [Commits](https://github.com/pallets/jinja/compare/2.10.1...2.10.3) Signed-off-by: dependabot-preview[bot] --- requirements.txt | 2 +- setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index ed601bda..1430a7ff 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,7 +4,7 @@ readsettings==3.4.0 web3==4.9.2 texttable==1.6.2 python-dateutil==2.8.0 -Jinja2==2.10.1 +Jinja2==2.10.3 skale-py==0.82.0 eth-hash==0.2.0 pycryptodome==3.9.0 diff --git a/setup.py b/setup.py index 5ff6cdea..e0209856 100644 --- a/setup.py +++ b/setup.py @@ -57,7 +57,7 @@ def find_version(*file_paths): "web3==4.9.2", "texttable==1.6.2", "python-dateutil==2.8.0", - "Jinja2==2.10.1", + "Jinja2==2.10.3", "skale-py==0.82.0", "eth-hash==0.2.0", "pycryptodome==3.9.0", From 2e2dc93a940082d6b129d0bd2613b898fcec6794 Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Thu, 17 Oct 2019 12:40:52 +0000 Subject: [PATCH 42/45] Bump twine from 1.12.1 to 2.0.0 Bumps [twine](https://github.com/pypa/twine) from 1.12.1 to 2.0.0. - [Release notes](https://github.com/pypa/twine/releases) - [Changelog](https://github.com/pypa/twine/blob/master/docs/changelog.rst) - [Commits](https://github.com/pypa/twine/compare/1.12.1...2.0.0) Signed-off-by: dependabot-preview[bot] --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 32aee03e..c2b1fbca 100644 --- a/setup.py +++ b/setup.py @@ -29,7 +29,7 @@ def find_version(*file_paths): "PyInstaller==3.5", "pytest==5.2.1", "pytest-cov==2.8.1", - "twine==1.12.1", + "twine==2.0.0", "when-changed" ] } From cf0e47fb6bac7b5719e17a2341d80dd39d8c4c15 Mon Sep 17 00:00:00 2001 From: ivd Date: Mon, 28 Oct 2019 15:22:13 +0200 Subject: [PATCH 43/45] Reraise exception in main.py for more clear error information --- main.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index aefe3df0..80a5bf01 100644 --- a/main.py +++ b/main.py @@ -210,4 +210,5 @@ def handle_exception(exc_type, exc_value, exc_traceback): try: cmd_collection() except Exception as err: - print(f'Command execution falied with {err}. Recheck your inputs') + print(f'Command execution falied. Recheck your inputs') + raise err From d814709e068cd3d1be57ba1c11479a3c61be7f3c Mon Sep 17 00:00:00 2001 From: Stan Kladko <13399135+kladkogex@users.noreply.github.com> Date: Tue, 29 Oct 2019 20:15:38 +0200 Subject: [PATCH 44/45] Create CODEOWNERS --- CODEOWNERS | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 CODEOWNERS diff --git a/CODEOWNERS b/CODEOWNERS new file mode 100644 index 00000000..002c1400 --- /dev/null +++ b/CODEOWNERS @@ -0,0 +1,2 @@ +* @dmitry-tk +* @kladkogex From 66db37d82be276199e6c39bcfd0d265600abe83f Mon Sep 17 00:00:00 2001 From: Stan Kladko <13399135+kladkogex@users.noreply.github.com> Date: Thu, 7 Nov 2019 12:18:48 +0200 Subject: [PATCH 45/45] Update CODEOWNERS --- CODEOWNERS | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/CODEOWNERS b/CODEOWNERS index 002c1400..38bf9a3e 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -1,2 +1 @@ -* @dmitry-tk -* @kladkogex +* @dmitry-tk @kladkogex