Skip to content

Commit

Permalink
Merge pull request #165 from skalenetwork/fix/SKALE-2555-handle-missi…
Browse files Browse the repository at this point in the history
…ng-debug-contracts

SKALE-2555 Add debug/prod contracts support
  • Loading branch information
dmytrotkk authored May 14, 2020
2 parents ea3b10c + f70fbbd commit c0f8cd8
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 9 deletions.
19 changes: 16 additions & 3 deletions skale/contracts_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from skale.utils.contract_info import ContractInfo
from skale.utils.contract_types import ContractTypes


CONTRACTS_INFO = [
ContractInfo('contract_manager', 'ContractManager',
contracts.ContractManager, ContractTypes.API, False),
Expand Down Expand Up @@ -48,14 +49,26 @@
ContractInfo('token_state', 'TokenState', contracts.TokenState,
ContractTypes.API, False),
ContractInfo('distributor', 'Distributor', contracts.Distributor,
ContractTypes.API, False),
ContractTypes.API, False)
]


DEBUG_CONTRACTS_INFO = [
ContractInfo('time_helpers_with_debug', 'TimeHelpersWithDebug', contracts.TimeHelpersWithDebug,
ContractTypes.API, False)
]


def get_contracts_info():
def get_contracts_info(contracts_data):
contracts_info = {}
for contract_info in CONTRACTS_INFO:
for contract_info in contracts_data:
contracts_info[contract_info.name] = contract_info
return contracts_info


def get_base_contracts_info():
return get_contracts_info(CONTRACTS_INFO)


def get_debug_contracts_info():
return get_contracts_info(DEBUG_CONTRACTS_INFO)
16 changes: 12 additions & 4 deletions skale/manager_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

import skale.contracts as contracts
from skale.wallets import BaseWallet
from skale.contracts_info import get_contracts_info
from skale.contracts_info import get_base_contracts_info, get_debug_contracts_info
from skale.utils.helper import get_abi
from skale.utils.web3_utils import get_provider
from skale.utils.exceptions import InvalidWalletError, EmptyWalletError
Expand All @@ -50,10 +50,9 @@ def __init__(self, endpoint, abi_filepath, wallet=None, provider_timeout=30):
self.web3.middleware_onion.inject(
geth_poa_middleware, layer=0) # todo: may cause issues
self.__contracts = {}
self.nonces = {}
if wallet:
self.wallet = wallet
self.__init_contracts(get_abi(abi_filepath), get_contracts_info())
self.__init_contracts(get_abi(abi_filepath))

@property
def gas_price(self):
Expand All @@ -73,9 +72,18 @@ def wallet(self, wallet):
raise InvalidWalletError(f'Wrong wallet class: {type(wallet).__name__}. \
Must be one of the BaseWallet subclasses')

def __init_contracts(self, abi, contracts_info):
def __is_debug_contracts(self, abi):
return abi.get('time_helpers_with_debug_address', None)

def __init_contracts(self, abi):
self.add_lib_contract('contract_manager',
contracts.ContractManager, abi)
self.__init_contracts_from_info(abi, get_base_contracts_info())
if self.__is_debug_contracts(abi):
logger.info('Debug contracts found in ABI file')
self.__init_contracts_from_info(abi, get_debug_contracts_info())

def __init_contracts_from_info(self, abi, contracts_info):
for name in contracts_info:
info = contracts_info[name]
if info.upgradeable:
Expand Down
4 changes: 2 additions & 2 deletions tests/main_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from skale.utils.web3_utils import init_web3
from skale.contracts import BaseContract
from skale.contracts.data.nodes_data import Nodes
from skale.contracts_info import CONTRACTS_INFO
from skale.contracts_info import CONTRACTS_INFO, DEBUG_CONTRACTS_INFO
from tests.constants import TEST_CONTRACT_NAME, ENDPOINT, TEST_ABI_FILEPATH, ETH_PRIVATE_KEY
from skale.utils.contracts_provision.main import _skip_evm_time

Expand All @@ -20,7 +20,7 @@ def test_lib_init():
skale = Skale(ENDPOINT, TEST_ABI_FILEPATH, wallet, provider_timeout=20)

lib_contracts = skale._Skale__contracts
assert len(lib_contracts) == len(CONTRACTS_INFO)
assert len(lib_contracts) == len(CONTRACTS_INFO) + len(DEBUG_CONTRACTS_INFO)

for lib_contract in lib_contracts.values():
assert issubclass(type(lib_contract), BaseContract)
Expand Down

0 comments on commit c0f8cd8

Please sign in to comment.