From ad9735f048bba98de3d1ee83efa542d50aefda3a Mon Sep 17 00:00:00 2001 From: Dmytro Date: Fri, 11 Feb 2022 19:08:52 +0200 Subject: [PATCH 1/3] SKALE-4942 Add is_rotation_active function, add tests --- .github/workflows/test.yml | 2 +- skale/contracts/manager/node_rotation.py | 13 +++++++++- tests/manager/node_rotation_test.py | 33 ++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index fbeeba36..35f98de1 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -11,7 +11,7 @@ jobs: ETH_PRIVATE_KEY: ${{ secrets.ETH_PRIVATE_KEY }} ENDPOINT: ${{ secrets.ENDPOINT }} CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} - MANAGER_TAG: "1.9.0-develop.1" + MANAGER_TAG: "1.9.0-develop.8" steps: - uses: actions/checkout@v2 with: diff --git a/skale/contracts/manager/node_rotation.py b/skale/contracts/manager/node_rotation.py index 87368f4f..45178245 100644 --- a/skale/contracts/manager/node_rotation.py +++ b/skale/contracts/manager/node_rotation.py @@ -91,10 +91,21 @@ def get_schain_finish_ts(self, node_id: int, schain_name: str) -> int: finish_ts += rotation_delay return finish_ts - def is_rotation_in_progress(self, schain_name): + def is_rotation_in_progress(self, schain_name) -> bool: schain_id = self.schains.name_to_id(schain_name) return self.contract.functions.isRotationInProgress(schain_id).call() + def is_new_node_found(self, schain_name) -> bool: + schain_id = self.schains.name_to_id(schain_name) + return self.contract.functions.isNewNodeFound(schain_id).call() + + def is_rotation_active(self, schain_name) -> bool: + """ + The public function that tells whether rotation is in the active phase - the new group is + already generated + """ + return self.is_rotation_in_progress(schain_name) and self.is_new_node_found(schain_name) + def wait_for_new_node(self, schain_name): schain_id = self.schains.name_to_id(schain_name) return self.contract.functions.waitForNewNode(schain_id).call() diff --git a/tests/manager/node_rotation_test.py b/tests/manager/node_rotation_test.py index 625449f4..fd8013b7 100644 --- a/tests/manager/node_rotation_test.py +++ b/tests/manager/node_rotation_test.py @@ -3,7 +3,11 @@ import mock from skale.contracts.manager.node_rotation import Rotation +from skale.utils.contracts_provision.main import ( + cleanup_nodes_schains, create_schain, add_test4_schain_type +) from tests.constants import DEFAULT_SCHAIN_ID, DEFAULT_SCHAIN_NAME, DEFAULT_SCHAIN_INDEX +from tests.rotation_history.utils import set_up_nodes, run_dkg def test_get_rotation(skale): @@ -50,3 +54,32 @@ def test_is_rotation_in_progress(skale): def test_wait_for_new_node(skale): assert skale.node_rotation.wait_for_new_node(DEFAULT_SCHAIN_NAME) is False + + +def test_is_rotation_active(skale): + cleanup_nodes_schains(skale) + nodes, skale_instances = set_up_nodes(skale, 4) + add_test4_schain_type(skale) + name = create_schain(skale, random_name=True) + group_index = skale.web3.sha3(text=name) + + run_dkg(nodes, skale_instances, group_index) + + exiting_node_index = 1 + set_up_nodes(skale, 1) + + assert not skale.node_rotation.is_new_node_found(name) + assert not skale.node_rotation.is_rotation_in_progress(name) + assert not skale.node_rotation.is_rotation_active(name) + + skale.nodes.init_exit(nodes[exiting_node_index]['node_id']) + + assert not skale.node_rotation.is_new_node_found(name) + assert skale.node_rotation.is_rotation_in_progress(name) + assert not skale.node_rotation.is_rotation_active(name) + + skale_instances[exiting_node_index].manager.node_exit(nodes[exiting_node_index]['node_id']) + + assert skale.node_rotation.is_new_node_found(name) + assert skale.node_rotation.is_rotation_in_progress(name) + assert skale.node_rotation.is_rotation_active(name) From 7147a66dca8aa42549cbd36341c6f4dc33a2cf92 Mon Sep 17 00:00:00 2001 From: Dmytro Date: Fri, 11 Feb 2022 19:56:12 +0200 Subject: [PATCH 2/3] SKALE-4942 Fix tests - create new nodes for nodes tests --- skale/utils/contracts_provision/main.py | 14 ++++++++++++++ tests/manager/nodes_test.py | 18 ++++++++++++------ 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/skale/utils/contracts_provision/main.py b/skale/utils/contracts_provision/main.py index 4b1a3cd9..f9e7516d 100644 --- a/skale/utils/contracts_provision/main.py +++ b/skale/utils/contracts_provision/main.py @@ -151,6 +151,20 @@ def create_clean_schain(skale): return create_schain(skale, random_name=True) +def create_node(skale) -> str: + cleanup_nodes_schains(skale) + ip, public_ip, port, name = generate_random_node_data() + skale.manager.create_node( + ip=ip, + port=port, + name=name, + domain_name=DEFAULT_DOMAIN_NAME, + public_ip=public_ip, + wait_for=True + ) + return name + + def validator_exist(skale): return skale.validator_service.number_of_validators() > 0 diff --git a/tests/manager/nodes_test.py b/tests/manager/nodes_test.py index f49806e2..b6e9515a 100644 --- a/tests/manager/nodes_test.py +++ b/tests/manager/nodes_test.py @@ -13,6 +13,7 @@ from skale.contracts.manager.nodes import FIELDS, NodeStatus from skale.utils.exceptions import InvalidNodeIdError from skale.utils.contracts_provision import DEFAULT_DOMAIN_NAME +from skale.utils.contracts_provision.main import create_node from tests.constants import DEFAULT_NODE_HASH, DEFAULT_NODE_NAME, NOT_EXISTING_ID @@ -28,12 +29,14 @@ def public_key_from_private(key): def test_get(skale): - node = skale.nodes.get_by_name(DEFAULT_NODE_NAME) - node_id = skale.nodes.node_name_to_index(DEFAULT_NODE_NAME) + name = create_node(skale) + + node = skale.nodes.get_by_name(name) + node_id = skale.nodes.node_name_to_index(name) node_by_id = skale.nodes.get(node_id) assert list(node.keys()) == FIELDS assert [k for k, v in node.items() if v is None] == [] - assert node_by_id['name'] == DEFAULT_NODE_NAME + assert node_by_id['name'] == name socket.inet_ntoa(node_by_id['ip']) socket.inet_ntoa(node_by_id['publicIP']) @@ -104,14 +107,16 @@ def test_name_to_id(skale): def test_is_node_name_available(skale): - node = skale.nodes.get_by_name(DEFAULT_NODE_NAME) + name = create_node(skale) + node = skale.nodes.get_by_name(name) unused_name = 'unused_name' assert skale.nodes.is_node_name_available(node['name']) is False assert skale.nodes.is_node_name_available(unused_name) is True def test_is_node_ip_available(skale): - node = skale.nodes.get_by_name(DEFAULT_NODE_NAME) + name = create_node(skale) + node = skale.nodes.get_by_name(name) node_ip = Helper.ip_from_bytes(node['ip']) unused_ip = '123.123.231.123' @@ -136,7 +141,8 @@ def test_get_node_public_key(skale): def test_node_in_maintenance(skale): - node_id = skale.nodes.node_name_to_index(DEFAULT_NODE_NAME) + name = create_node(skale) + node_id = skale.nodes.node_name_to_index(name) assert skale.nodes.get_node_status(node_id) == NodeStatus.ACTIVE.value skale.nodes.set_node_in_maintenance(node_id) From 8c5d34e598f4d4acb6dd8df1df82eb8a4ee3f439 Mon Sep 17 00:00:00 2001 From: Dmytro Date: Tue, 15 Feb 2022 11:38:36 +0000 Subject: [PATCH 3/3] SKALE-4942 Fix schain internal tests --- tests/manager/schains_internal_test.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/manager/schains_internal_test.py b/tests/manager/schains_internal_test.py index 6acc9369..124a30df 100644 --- a/tests/manager/schains_internal_test.py +++ b/tests/manager/schains_internal_test.py @@ -22,6 +22,7 @@ def test_get_schains_number(skale): def test_get_schain_list_size(skale, empty_account): + create_clean_schain(skale) list_size = skale.schains_internal.get_schain_list_size(skale.wallet.address) empty_list_size = skale.schains_internal.get_schain_list_size(empty_account.address) @@ -30,6 +31,7 @@ def test_get_schain_list_size(skale, empty_account): def test_get_schain_id_by_index_for_owner(skale): + create_clean_schain(skale) schain_id = skale.schains_internal.get_schain_id_by_index_for_owner( skale.wallet.address, 0 )