Skip to content

Commit

Permalink
Merge pull request #566 from EvgeniyZZ/develop
Browse files Browse the repository at this point in the history
Add IMA perdeployed
  • Loading branch information
dmytrotkk authored Dec 23, 2024
2 parents 02886fc + 261fffe commit 7536fc5
Show file tree
Hide file tree
Showing 44 changed files with 1,863 additions and 21 deletions.
11 changes: 11 additions & 0 deletions scripts/run_ima_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash

set -e

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
PROJECT_DIR=$(dirname $DIR)
export ENDPOINT=${ENDPOINT:-http://localhost:8545}
export ENV=test


py.test $PROJECT_DIR/tests/ima $@
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"pyyaml==6.0",
"redis==5.0.3",
"sgx.py==0.9dev2",
"skale-contracts==1.0.1a5",
"skale-contracts==1.0.2a6",
"typing-extensions==4.9.0",
"web3==6.13.0"
],
Expand Down
1 change: 1 addition & 0 deletions skale/contracts/allocator_contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#
# 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.skale_allocator import SkaleAllocator

Expand Down
1 change: 1 addition & 0 deletions skale/contracts/base_contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#
# 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/>.

""" SKALE base contract class """
from __future__ import annotations
import logging
Expand Down
7 changes: 7 additions & 0 deletions skale/contracts/config_controller/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# flake8: noqa
from skale.contracts.base_contract import BaseContract, transaction_method
from skale.contracts.config_controller.config_controller import ConfigController

__all__ = [
'ConfigController'
]
151 changes: 151 additions & 0 deletions skale/contracts/config_controller/config_controller.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
# -*- coding: utf-8 -*-
#
# This file is part of SKALE.py
#
# Copyright (C) 2019-Present 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 eth_typing import ChecksumAddress
from skale.transactions.result import TxRes


class ConfigController(BaseContract):
"""Config controller contract"""

def default_admin_role(self) -> bytes:
return self.contract.functions.DEFAULT_ADMIN_ROLE().call()

def deployer_admin_role(self) -> bytes:
return self.contract.functions.DEPLOYER_ADMIN_ROLE().call()

def deployer_role(self) -> bytes:
return self.contract.functions.DEPLOYER_ROLE().call()

def mtm_admin_role(self) -> bytes:
return self.contract.functions.MTM_ADMIN_ROLE().call()

def allowed_origin_role(self, deployer: ChecksumAddress) -> bytes:
return self.contract.functions.allowedOriginRole(deployer).call()

def allowed_origin_role_admin(self, deployer: ChecksumAddress) -> bytes:
return self.contract.functions.allowedOriginRoleAdmin(deployer).call()

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

def get_role_admin(self, role: bytes) -> bytes:
return self.contract.functions.getRoleAdmin(role).call()

def get_role_member(self, role: bytes, index: int) -> bytes:
return self.contract.functions.getRoleMember(role, index).call()

def get_role_member_count(self, role: bytes) -> int:
return self.contract.functions.getRoleMemberCount(role).call()

def is_address_whitelisted(self, address: ChecksumAddress) -> bool:
return bool(self.contract.functions.isAddressWhitelisted(address).call())

def is_deployment_allowed(
self,
transaction_origin: ChecksumAddress,
deployer: ChecksumAddress
) -> bool:
return bool(self.contract.functions.isDeploymentAllowed(transaction_origin, deployer).call())

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

@transaction_method
def add_allowed_origin_role_admin(
self,
role: bytes,
address: ChecksumAddress
) -> TxRes:
return self.contract.functions.addAllowedOriginRoleAdmin(role, address)

@transaction_method
def allow_origin(
self,
transaction_origin: ChecksumAddress,
deployer: ChecksumAddress
) -> TxRes:
return self.contract.functions.allowOrigin(transaction_origin, deployer)

@transaction_method
def add_to_whitelist(self, address: ChecksumAddress) -> TxRes:
return self.contract.functions.addToWhitelist(address)

@transaction_method
def revoke_role(self, role: bytes, address: ChecksumAddress) -> TxRes:
return self.contract.functions.revokeRole(role, address)

@transaction_method
def renounce_role(self, role: bytes, address: ChecksumAddress) -> TxRes:
return self.contract.functions.renounceRole(role, address)

@transaction_method
def remove_allowed_origin_role_admin(
self,
role: bytes,
address: ChecksumAddress
) -> TxRes:
return self.contract.functions.removeAllowedOriginRoleAdmin(role, address)

@transaction_method
def forbid_origin(
self,
transaction_origin: ChecksumAddress,
deployer: ChecksumAddress
) -> TxRes:
return self.contract.functions.forbidOrigin(transaction_origin, deployer)

@transaction_method
def remove_from_whitelist(self, address: ChecksumAddress) -> TxRes:
return self.contract.functions.removeFromWhitelist(address)

@transaction_method
def enable_free_contract_deployment(self) -> TxRes:
return self.contract.functions.enableFreeContractDeployment()

@transaction_method
def disable_free_contract_deployment(self) -> TxRes:
return self.contract.functions.disableFreeContractDeployment()

def is_fcd_enabled(self) -> str:
return self.contract.functions.isFCDEnabled().call()

@transaction_method
def enable_mtm(self) -> TxRes:
return self.contract.functions.enableMTM()

@transaction_method
def disable_mtm(self) -> TxRes:
return self.contract.functions.disableMTM()

def is_mtm_enabled(self) -> str:
return self.contract.functions.isMTMEnabled().call()

def get_version(self) -> str:
return self.contract.functions.version().call()

@transaction_method
def set_version(self, new_version) -> TxRes:
return self.contract.functions.setVersion(new_version)
25 changes: 25 additions & 0 deletions skale/contracts/config_controller_contract.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
#
# This file is part of SKALE.py
#
# Copyright (C) 2019-Present 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
from skale.skale_config_controller import SkaleConfigController


class ConfigControllerContract(BaseContract[SkaleConfigController]):
pass
7 changes: 7 additions & 0 deletions skale/contracts/context/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# flake8: noqa
from skale.contracts.base_contract import BaseContract, transaction_method
from skale.contracts.context.context import Context

__all__ = [
'Context'
]
39 changes: 39 additions & 0 deletions skale/contracts/context/context.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# -*- coding: utf-8 -*-
#
# This file is part of SKALE.py
#
# Copyright (C) 2019-Present 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 eth_typing import ChecksumAddress
from skale.transactions.result import TxRes


class Context(BaseContract):
"""Context contract"""

def get_schain_name(self) -> str:
return self.contract.functions.getSchainName().call()

def get_schain_owner_address(self) -> bytes:
return self.contract.functions.getSchainOwnerAddress().call()

@transaction_method
def set_schain_owner_address(self, newOwner: ChecksumAddress) -> TxRes:
return self.contract.functions.setSchainOwnerAddress(newOwner)

def get_version(self) -> str:
return self.contract.functions.version().call()
25 changes: 25 additions & 0 deletions skale/contracts/context_contract.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
#
# This file is part of SKALE.py
#
# Copyright (C) 2019-Present 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
from skale.skale_context import SkaleContext


class ContextContract(BaseContract[SkaleContext]):
pass
7 changes: 7 additions & 0 deletions skale/contracts/etherbase/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# flake8: noqa
from skale.contracts.base_contract import BaseContract, transaction_method
from skale.contracts.etherbase.etherbase import Etherbase

__all__ = [
'Etherbase'
]
75 changes: 75 additions & 0 deletions skale/contracts/etherbase/etherbase.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# -*- coding: utf-8 -*-
#
# This file is part of SKALE.py
#
# Copyright (C) 2019-Present 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 eth_typing import ChecksumAddress
from skale.transactions.result import TxRes


class Etherbase(BaseContract):
"""Etherbase contract"""

def default_admin_role(self) -> bytes:
return self.contract.functions.DEFAULT_ADMIN_ROLE().call()

def ether_manager_role(self) -> bytes:
return self.contract.functions.ETHER_MANAGER_ROLE().call()

@transaction_method
def retrieve(self, address: ChecksumAddress) -> TxRes:
return self.contract.functions.retrieve(address)

@transaction_method
def partially_retrieve(self, address: ChecksumAddress, amount: int) -> TxRes:
return self.contract.functions.partiallyRetrieve(address, amount)

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

def get_role_admin(self, role: bytes) -> bytes:
return self.contract.functions.getRoleAdmin(role).call()

def get_role_member(self, role: bytes, index: int) -> bytes:
return self.contract.functions.getRoleMember(role, index).call()

def get_role_member_count(self, role: bytes) -> int:
return self.contract.functions.getRoleMemberCount(role).call()

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

@transaction_method
def revoke_role(self, role: bytes, address: ChecksumAddress) -> TxRes:
return self.contract.functions.revokeRole(role, address)

@transaction_method
def renounce_role(self, role: bytes, address: ChecksumAddress) -> TxRes:
return self.contract.functions.renounceRole(role, address)

def get_version(self) -> str:
return self.contract.functions.version().call()

@transaction_method
def set_version(self, new_version) -> TxRes:
return self.contract.functions.setVersion(new_version)
Loading

0 comments on commit 7536fc5

Please sign in to comment.