Skip to content

Commit

Permalink
Merge pull request #472 from skalenetwork/develop
Browse files Browse the repository at this point in the history
New beta version
  • Loading branch information
dmytrotkk authored Feb 2, 2022
2 parents f6467a3 + 8180bba commit 7582729
Show file tree
Hide file tree
Showing 86 changed files with 2,846 additions and 676 deletions.
2 changes: 1 addition & 1 deletion .flake8
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[flake8]
max-line-length = 100
exclude = .git,__pycache__,docs/source/conf.py,old,build,dist,venv,skale-manager
exclude = .git,__pycache__,docs/source/conf.py,old,build,dist,venv,node_modules,helper-scripts
58 changes: 37 additions & 21 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Test
on: [push, pull_request]

jobs:
test:
test_manager:
runs-on: ubuntu-latest
strategy:
matrix:
Expand All @@ -11,38 +11,54 @@ jobs:
ETH_PRIVATE_KEY: ${{ secrets.ETH_PRIVATE_KEY }}
ENDPOINT: ${{ secrets.ENDPOINT }}
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
MANAGER_TAG: "1.8.0-stable.0"
ALLOCATOR_TAG: "2.2.0-develop.4"
MANAGER_TAG: "1.9.0-develop.1"
steps:
- uses: actions/checkout@v2
with:
submodules: true
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}
- name: Checkout submodules
uses: textbook/git-checkout-submodule-action@master
with:
remote: true
- name: Install host dependencies
run: |
sudo apt-get update --fix-missing
sudo apt-get install libudev-dev
sudo apt-get install libusb-1.0-0-dev
run: bash ./scripts/install_host_dependencies.sh
- name: Install python dependencies
run: |
python -m pip install --upgrade pip
pip install -e .
pip install -e .[dev]
pip install codecov pytest-cov
run: bash ./scripts/install_python_dependencies.sh
- name: Lint with flake8
run: flake8 .
- name: Deploy manager contracts
run: |
flake8 .
- name: Deploy manager and allocator contracts
run: |
bash ./helper-scripts/deploy_test_allocator.sh
bash ./helper-scripts/deploy_test_manager.sh
- name: Run tests
run: |
bash ./scripts/run_tests.sh
bash ./scripts/run_manager_tests.sh
- name: Codecov
run: |
codecov -t $CODECOV_TOKEN
test_allocator:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.7]
env:
ETH_PRIVATE_KEY: ${{ secrets.ETH_PRIVATE_KEY }}
MANAGER_TAG: "1.8.2-develop.44"
ALLOCATOR_TAG: "2.2.0-develop.4"
steps:
- uses: actions/checkout@v2
with:
submodules: true
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}
- name: Install host dependencies
run: bash ./scripts/install_host_dependencies.sh
- name: Install python dependencies
run: bash ./scripts/install_python_dependencies.sh
- name: Deploy allocator contracts
run: |
bash ./helper-scripts/deploy_test_allocator.sh
- name: Run tests
run: |
bash ./scripts/run_allocator_tests.sh
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,6 @@ allocator_contracts_data/

.DS_Store

.vscode/
.vscode/

fake_multisig_data.json
6 changes: 6 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[pytest]
log_cli = 0
log_cli_level = INFO
log_cli_format = %(asctime)s [%(levelname)8s] %(message)s (%(filename)s:%(lineno)s)
log_cli_date_format=%Y-%m-%d %H:%M:%S
filterwarnings = ignore::DeprecationWarning
27 changes: 0 additions & 27 deletions scripts/deploy_manager.sh

This file was deleted.

5 changes: 5 additions & 0 deletions scripts/install_host_dependencies.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

sudo apt-get update --fix-missing
sudo apt-get install libudev-dev
sudo apt-get install libusb-1.0-0-dev
6 changes: 6 additions & 0 deletions scripts/install_python_dependencies.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash

python -m pip install --upgrade pip
pip install -e .
pip install -e .[dev]
pip install codecov pytest-cov
5 changes: 2 additions & 3 deletions scripts/run_tests.sh → scripts/run_allocator_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
PROJECT_DIR=$(dirname $DIR)

export ENDPOINT=${ENDPOINT:-http://localhost:8545}
export ENV=test

python $PROJECT_DIR/tests/prepare_data.py
python $PROJECT_DIR/tests/allocator/provision_contracts.py
py.test --cov=$PROJECT_DIR/ $PROJECT_DIR/tests/ $@
py.test --cov=$PROJECT_DIR/ $PROJECT_DIR/tests/allocator $@
9 changes: 9 additions & 0 deletions scripts/run_manager_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash

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

python $PROJECT_DIR/tests/prepare_data.py
py.test --cov=$PROJECT_DIR/ $PROJECT_DIR/tests/ --ignore $PROJECT_DIR/tests/allocator $@
18 changes: 8 additions & 10 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,20 @@

setup(
name='skale.py',
version='4.1',
version='5.7',
description='SKALE client tools',
long_description_markdown_filename='README.md',
author='SKALE Labs',
author_email='[email protected]',
url='https://github.com/skalenetwork/skale.py',
include_package_data=True,
install_requires=[
"web3==5.8.0",
"web3==5.25.0",
"asyncio==3.4.3",
"pyyaml==5.3.1",
"sgx.py==0.6b1"
"pyyaml==5.4",
"sgx.py==0.8dev3",
"eth-account==0.5.6",
"redis==3.5.3"
],

python_requires='>=3.7,<4',
Expand All @@ -52,14 +54,10 @@
keywords='skale',
packages=find_packages(exclude=['tests']),
classifiers=[
'Development Status :: 2 - Pre-Alpha',
'Development Status :: 5 - Production/Stable',
'Intended Audience :: Developers',
'License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)',
'Natural Language :: English',
'Programming Language :: Python :: 3.7',
],

package_data={ # Optional
'contracts': ['utils/contracts_data.json', 'envs/envs.yml', 'envs/aws.json'],
},
]
)
1 change: 1 addition & 0 deletions skale/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
from skale.skale_manager import SkaleManager as Skale # todo: deprecated naming, will be removed in skale.py v5

from skale.skale_allocator import SkaleAllocator
from skale.skale_ima import SkaleIma
2 changes: 2 additions & 0 deletions skale/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,5 @@
DEFAULT_GAS_LIMIT = int(os.getenv('DEFAULT_GAS_LIMIT') or 10 ** 7)
DEFAULT_GAS_PRICE_WEI = int(os.getenv('DEFAULT_GAS_PRICE_WEI') or 0)
LAST_BLOCK_FILE = os.getenv('LAST_BLOCK_FILE')
DEFAULT_GAS_MULTIPLIER = float(os.getenv('DEFAULT_GAS_MULTIPLIER') or 1.2)
DEFAULT_PRIORITY = int(os.getenv('DEFAULT_PRIORITY') or 5)
2 changes: 1 addition & 1 deletion skale/contracts/allocator/escrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class Escrow(BaseContract):
@property
@functools.lru_cache()
def allocator(self):
return self.skale.get_contract_by_name('allocator')
return self.skale.allocator

def init_beneficiary_contract(self, beneficiary_address: str):
beneficiary_escrow_address = self.allocator.get_escrow_address(beneficiary_address)
Expand Down
71 changes: 52 additions & 19 deletions skale/contracts/base_contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,21 @@
import logging
from functools import wraps

from web3 import Web3

import skale.config as config
from skale.transactions.result import (TxRes, check_balance_and_gas,
is_success, is_success_or_not_performed)
from skale.transactions.tools import make_dry_run_call, post_transaction
from skale.utils.account_tools import account_eth_balance_wei
from skale.utils.web3_utils import (wait_for_confirmation_blocks,
wait_for_receipt_by_blocks)
from web3 import Web3
from skale.utils.web3_utils import (
DEFAULT_BLOCKS_TO_WAIT,
MAX_WAITING_TIME,
wait_for_confirmation_blocks
)

from skale.utils.helper import to_camel_case


logger = logging.getLogger(__name__)

Expand All @@ -43,13 +50,26 @@ def execute_dry_run(skale, method, custom_gas_limit, value=0) -> tuple:

def transaction_method(transaction):
@wraps(transaction)
def wrapper(self, *args, wait_for=True,
wait_timeout=4, blocks_to_wait=50, gas_limit=None,
gas_price=None, nonce=None, value=0,
dry_run_only=False, skip_dry_run=False,
raise_for_status=True, confirmation_blocks=0, **kwargs):
def wrapper(
self,
*args,
wait_for=True,
blocks_to_wait=DEFAULT_BLOCKS_TO_WAIT,
timeout=MAX_WAITING_TIME,
gas_limit=None,
gas_price=None,
nonce=None,
value=0,
dry_run_only=False,
skip_dry_run=False,
raise_for_status=True,
multiplier=None,
priority=None,
confirmation_blocks=0,
**kwargs
):
method = transaction(self, *args, **kwargs)
dry_run_result, tx_hash, receipt = None, None, None
dry_run_result, tx, receipt = None, None, None

# Make dry_run and estimate gas limit
estimated_gas_limit = None
Expand All @@ -75,22 +95,19 @@ def wrapper(self, *args, wait_for=True,
is_success_or_not_performed(dry_run_result)

if rich_enough and should_send_transaction:
tx_hash = post_transaction(
tx = post_transaction(
self.skale.wallet, method, gas_limit,
gas_price, nonce, value
gas_price, nonce, value, multiplier, priority
)
if wait_for:
receipt = wait_for_receipt_by_blocks(
receipt = self.skale.wallet.wait(tx)
if confirmation_blocks:
wait_for_confirmation_blocks(
self.skale.web3,
tx_hash,
timeout=wait_timeout,
blocks_to_wait=blocks_to_wait
confirmation_blocks
)
if confirmation_blocks:
wait_for_confirmation_blocks(self.skale.web3,
confirmation_blocks)

tx_res = TxRes(dry_run_result, balance_check_result, tx_hash, receipt)
tx_res = TxRes(dry_run_result, balance_check_result, tx, receipt)

if raise_for_status:
tx_res.raise_for_status()
Expand All @@ -105,3 +122,19 @@ def __init__(self, skale, name, address, abi):
self.name = name
self.address = Web3.toChecksumAddress(address)
self.contract = skale.web3.eth.contract(address=self.address, abi=abi)

def __getattr__(self, attr):
"""Fallback for contract calls"""
logger.debug("Calling contract function: %s", attr)

def wrapper(*args, **kw):
logger.debug('called with %r and %r' % (args, kw))
camel_case_fn_name = to_camel_case(attr)
if hasattr(self.contract.functions, camel_case_fn_name):
return getattr(self.contract.functions,
camel_case_fn_name)(*args, **kw).call()
if hasattr(self.contract.functions, attr):
return getattr(self.contract.functions,
attr)(*args, **kw).call()
raise AttributeError(attr)
return wrapper
6 changes: 6 additions & 0 deletions skale/contracts/ima/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# flake8: noqa

from skale.contracts.contract_manager import ContractManager
from skale.contracts.base_contract import BaseContract, transaction_method

from skale.contracts.ima.linker import Linker
33 changes: 33 additions & 0 deletions skale/contracts/ima/linker.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) 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


class Linker(BaseContract):
@transaction_method
def connect_schain(
self,
schain_name: str,
mainnet_contracts: list
):
return self.contract.functions.connectSchain(
schain_name,
mainnet_contracts
)
5 changes: 5 additions & 0 deletions skale/contracts/manager/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
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.sync_manager import SyncManager

from skale.contracts.manager.test.time_helpers_with_debug import TimeHelpersWithDebug
Loading

0 comments on commit 7582729

Please sign in to comment.