Skip to content

Commit

Permalink
Merge pull request #422 from skalenetwork/enhancement/SKALE-4300-add-…
Browse files Browse the repository at this point in the history
…all-roles

SKALE-4300 Add all roles, update tests provision, update SM version
  • Loading branch information
dmytrotkk authored Jun 15, 2021
2 parents 1d15724 + fc421df commit 269cc00
Show file tree
Hide file tree
Showing 11 changed files with 175 additions and 26 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
ETH_PRIVATE_KEY: ${{ secrets.ETH_PRIVATE_KEY }}
ENDPOINT: ${{ secrets.ENDPOINT }}
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
MANAGER_TAG: "1.8.0-develop.44"
MANAGER_TAG: "1.8.1-develop.6"
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
Expand Down Expand Up @@ -44,7 +44,7 @@ jobs:
python-version: [3.7]
env:
ETH_PRIVATE_KEY: ${{ secrets.ETH_PRIVATE_KEY }}
MANAGER_TAG: "1.8.0-develop.44"
MANAGER_TAG: "1.8.1-develop.6"
ALLOCATOR_TAG: "2.2.0-develop.4"
steps:
- uses: actions/checkout@v2
Expand Down
3 changes: 3 additions & 0 deletions skale/contracts/manager/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
from skale.contracts.manager.dkg import DKG
from skale.contracts.manager.key_storage import KeyStorage

from skale.contracts.manager.bounty_v2 import BountyV2
from skale.contracts.manager.punisher import Punisher

from skale.contracts.manager.wallets import Wallets

from skale.contracts.manager.test.time_helpers_with_debug import TimeHelpersWithDebug
33 changes: 33 additions & 0 deletions skale/contracts/manager/bounty_v2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# -*- coding: utf-8 -*-
#
# This file is part of SKALE.py
#
# Copyright (C) 2021 SKALE Labs
#
# SKALE.py 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.
#
# SKALE.py 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 Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with SKALE.py. If not, see <https://www.gnu.org/licenses/>.

from skale.contracts.base_contract import BaseContract, transaction_method
from skale.transactions.result import TxRes


class BountyV2(BaseContract):
@transaction_method
def grant_role(self, role: bytes, owner: str) -> TxRes:
return self.contract.functions.grantRole(role, owner)

def has_role(self, role: bytes, address: str) -> bool:
return self.contract.functions.hasRole(role, address).call()

def bounty_reduction_manager_role(self):
return self.contract.functions.BOUNTY_REDUCTION_MANAGER_ROLE().call()
14 changes: 12 additions & 2 deletions skale/contracts/manager/delegation/token_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
# You should have received a copy of the GNU Affero General Public License
# along with SKALE.py. If not, see <https://www.gnu.org/licenses/>.

from skale.contracts.base_contract import BaseContract
from skale.contracts.base_contract import BaseContract, transaction_method
from skale.transactions.result import TxRes


class TokenState(BaseContract):
Expand All @@ -30,5 +31,14 @@ def get_and_update_locked_amount(self, holder_address: str) -> int:
:returns:
:rtype: int
"""

return self.contract.functions.getAndUpdateLockedAmount(holder_address).call()

@transaction_method
def grant_role(self, role: bytes, owner: str) -> TxRes:
return self.contract.functions.grantRole(role, owner)

def has_role(self, role: bytes, address: str) -> bool:
return self.contract.functions.hasRole(role, address).call()

def locker_manager_role(self):
return self.contract.functions.LOCKER_MANAGER_ROLE().call()
4 changes: 2 additions & 2 deletions skale/contracts/manager/dkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def pre_response(
secret_key_contribution: list
):
return self.contract.functions.preResponse(
schainHash=group_index,
group_index,
fromNodeIndex=from_node_index,
verificationVector=verification_vector,
verificationVectorMult=verification_vector_mult,
Expand All @@ -73,7 +73,7 @@ def response(
multiplied_share: G2Point
):
return self.contract.functions.response(
schainHash=group_index,
group_index,
fromNodeIndex=from_node_index,
secretNumber=secret_number,
multipliedShare=multiplied_share
Expand Down
14 changes: 13 additions & 1 deletion skale/contracts/manager/node_rotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
""" NodeRotation.sol functions """

import functools
from skale.contracts.base_contract import BaseContract

from skale.contracts.base_contract import BaseContract, transaction_method
from skale.transactions.result import TxRes


class NodeRotation(BaseContract):
Expand Down Expand Up @@ -58,3 +60,13 @@ def is_rotation_in_progress(self, 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()

@transaction_method
def grant_role(self, role: bytes, owner: str) -> TxRes:
return self.contract.functions.grantRole(role, owner)

def has_role(self, role: bytes, address: str) -> bool:
return self.contract.functions.hasRole(role, address).call()

def debugger_role(self):
return self.contract.functions.DEBUGGER_ROLE().call()
15 changes: 15 additions & 0 deletions skale/contracts/manager/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
from web3.exceptions import BadFunctionCallOutput

from skale.contracts.base_contract import BaseContract, transaction_method
from skale.transactions.result import TxRes

from skale.utils.exceptions import InvalidNodeIdError
from skale.utils.helper import format_fields

Expand Down Expand Up @@ -155,3 +157,16 @@ def set_domain_name(self, node_id: int, domain_name: str):

def get_domain_name(self, node_id: int):
return self.contract.functions.getNodeDomainName(node_id).call()

@transaction_method
def grant_role(self, role: bytes, owner: str) -> TxRes:
return self.contract.functions.grantRole(role, owner)

def has_role(self, role: bytes, address: str) -> bool:
return self.contract.functions.hasRole(role, address).call()

def node_manager_role(self):
return self.contract.functions.NODE_MANAGER_ROLE().call()

def compliance_role(self):
return self.contract.functions.COMPLIANCE_ROLE().call()
33 changes: 33 additions & 0 deletions skale/contracts/manager/punisher.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# -*- coding: utf-8 -*-
#
# This file is part of SKALE.py
#
# Copyright (C) 2021 SKALE Labs
#
# SKALE.py 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.
#
# SKALE.py 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 Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with SKALE.py. If not, see <https://www.gnu.org/licenses/>.

from skale.contracts.base_contract import BaseContract, transaction_method
from skale.transactions.result import TxRes


class Punisher(BaseContract):
@transaction_method
def grant_role(self, role: bytes, owner: str) -> TxRes:
return self.contract.functions.grantRole(role, owner)

def has_role(self, role: bytes, address: str) -> bool:
return self.contract.functions.hasRole(role, address).call()

def forgiver_role(self):
return self.contract.functions.FORGIVER_ROLE().call()
7 changes: 5 additions & 2 deletions skale/contracts/manager/schains_internal.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,11 @@ def add_schain_type(
def grant_role(self, role: bytes, address: str) -> TxRes:
return self.contract.functions.grantRole(role, address)

def has_role(self, role: bytes, address: str) -> bool:
return self.contract.functions.hasRole(role, address).call()

def schain_type_manager_role(self) -> bytes:
return self.contract.functions.SCHAIN_TYPE_MANAGER_ROLE().call()

def has_role(self, role: bytes, address: str) -> bool:
return self.contract.functions.hasRole(role, address).call()
def debugger_role(self):
return self.contract.functions.DEBUGGER_ROLE().call()
4 changes: 4 additions & 0 deletions skale/skale_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@
ContractTypes.API, False),
ContractInfo('wallets', 'Wallets', contracts.Wallets,
ContractTypes.API, True),
ContractInfo('bounty_v2', 'Bounty', contracts.BountyV2,
ContractTypes.API, True),
ContractInfo('punisher', 'Punisher', contracts.Punisher,
ContractTypes.API, True),
]


Expand Down
70 changes: 53 additions & 17 deletions skale/utils/contracts_provision/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,31 +39,69 @@ def _skip_evm_time(web3, seconds) -> int:


def add_test_permissions(skale):
add_all_permissions(skale, skale.wallet.address)


def add_all_permissions(skale, address):
default_admin_role = skale.manager.default_admin_role()
if not skale.manager.has_role(default_admin_role, address):
skale.manager.grant_role(default_admin_role, address)

schain_creator_role = skale.schains.schain_creator_role()
if not skale.schains.has_role(schain_creator_role, address):
skale.schains.grant_role(schain_creator_role, address)

schain_deleter_role = skale.manager.schain_deleter_role()
if not skale.manager.has_role(schain_deleter_role, address):
skale.manager.grant_role(schain_deleter_role, address)

bounty_reduction_manager_role = skale.bounty_v2.bounty_reduction_manager_role()
if not skale.bounty_v2.has_role(bounty_reduction_manager_role, address):
skale.bounty_v2.grant_role(bounty_reduction_manager_role, address)

locker_manager_role = skale.token_state.locker_manager_role()
if not skale.token_state.has_role(locker_manager_role, address):
skale.token_state.grant_role(locker_manager_role, address)

schain_type_manager_role = skale.schains_internal.schain_type_manager_role()
if not skale.schains_internal.has_role(schain_type_manager_role, skale.wallet.address):
skale.schains_internal.grant_role(schain_type_manager_role, skale.wallet.address)
if not skale.schains_internal.has_role(schain_type_manager_role, address):
skale.schains_internal.grant_role(schain_type_manager_role, address)

validator_manager_role = skale.validator_service.validator_manager_role()
if not skale.validator_service.has_role(validator_manager_role, skale.wallet.address):
skale.validator_service.grant_role(validator_manager_role, skale.wallet.address)
if not skale.validator_service.has_role(validator_manager_role, address):
skale.validator_service.grant_role(validator_manager_role, address)

node_manager_role = skale.nodes.node_manager_role()
if not skale.nodes.has_role(node_manager_role, address):
skale.nodes.grant_role(node_manager_role, address)

compliance_role = skale.nodes.compliance_role()
if not skale.nodes.has_role(compliance_role, address):
skale.nodes.grant_role(compliance_role, address)

constants_holder_role = skale.constants_holder.constants_holder_role()
if not skale.constants_holder.has_role(constants_holder_role, skale.wallet.address):
skale.constants_holder.grant_role(constants_holder_role, skale.wallet.address)
if not skale.constants_holder.has_role(constants_holder_role, address):
skale.constants_holder.grant_role(constants_holder_role, address)

schain_deleter_role = skale.manager.schain_deleter_role()
if not skale.manager.has_role(schain_deleter_role, skale.wallet.address):
skale.manager.grant_role(schain_deleter_role, skale.wallet.address)
debugger_role = skale.node_rotation.debugger_role()
if not skale.node_rotation.has_role(debugger_role, address):
skale.node_rotation.grant_role(debugger_role, address)

debugger_schains_role = skale.schains_internal.debugger_role()
if not skale.schains_internal.has_role(debugger_schains_role, address):
skale.schains_internal.grant_role(debugger_schains_role, address)

forgiver_role = skale.punisher.forgiver_role()
if not skale.punisher.has_role(forgiver_role, address):
skale.punisher.grant_role(forgiver_role, address)

delegation_period_setter_role = skale.delegation_period_manager.delegation_period_setter_role()
if not skale.delegation_period_manager.has_role(delegation_period_setter_role,
skale.wallet.address):
skale.delegation_period_manager.grant_role(
delegation_period_setter_role, skale.wallet.address)
if not skale.delegation_period_manager.has_role(delegation_period_setter_role, address):
skale.delegation_period_manager.grant_role(delegation_period_setter_role, address)

penalty_setter_role = skale.slashing_table.penalty_setter_role()
if not skale.slashing_table.has_role(penalty_setter_role, skale.wallet.address):
skale.slashing_table.grant_role(penalty_setter_role, skale.wallet.address)
if not skale.slashing_table.has_role(penalty_setter_role, address):
skale.slashing_table.grant_role(penalty_setter_role, address)


def add_test_schain_type(skale) -> TxRes:
Expand Down Expand Up @@ -206,8 +244,6 @@ def create_schain(skale, schain_name=DEFAULT_SCHAIN_NAME):
_ = skale.schains.get_schain_price(
type_of_nodes, lifetime_seconds
)
skale.schains.grant_role(skale.schains.schain_creator_role(),
skale.wallet.address)
skale.schains.add_schain_by_foundation(
lifetime_seconds,
type_of_nodes,
Expand Down

0 comments on commit 269cc00

Please sign in to comment.