Skip to content

Commit

Permalink
Don't create Escrow contract without beneficiary specification
Browse files Browse the repository at this point in the history
  • Loading branch information
DimaStebaev committed Apr 5, 2024
1 parent ec4a5c8 commit 6da3a2a
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 8 deletions.
8 changes: 3 additions & 5 deletions skale/contracts/allocator/escrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
def beneficiary_escrow(transaction):
@functools.wraps(transaction)
def wrapper(self, *args, beneficiary_address, **kwargs):
self.contract = self.init_beneficiary_contract(beneficiary_address)
self.contract = self.skale.instance.get_contract('Escrow', beneficiary_address)

Check warning on line 30 in skale/contracts/allocator/escrow.py

View check run for this annotation

Codecov / codecov/patch

skale/contracts/allocator/escrow.py#L30

Added line #L30 was not covered by tests
return transaction(self, *args, **kwargs)
return wrapper

Expand All @@ -38,10 +38,8 @@ class Escrow(BaseContract):
def allocator(self):
return self.skale.allocator

def init_beneficiary_contract(self, beneficiary_address: str):
beneficiary_escrow_address = self.allocator.get_escrow_address(beneficiary_address)
return Escrow(self.skale, f'escrow_{beneficiary_address}', beneficiary_escrow_address,
self.contract.abi).contract
def init_contract(self, skale, address, abi) -> None:
self.contract = None

Check warning on line 42 in skale/contracts/allocator/escrow.py

View check run for this annotation

Codecov / codecov/patch

skale/contracts/allocator/escrow.py#L42

Added line #L42 was not covered by tests

@beneficiary_escrow
@transaction_method
Expand Down
5 changes: 4 additions & 1 deletion skale/contracts/base_contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,10 @@ def __init__(self, skale, name, address, abi):
self.skale = skale
self.name = name
self.address = Web3.to_checksum_address(address)
self.contract = skale.web3.eth.contract(address=self.address, abi=abi)
self.init_contract(skale, address, abi)

def init_contract(self, skale, address, abi) -> None:
self.contract = skale.web3.eth.contract(address=address, abi=abi)

def __getattr__(self, attr):
"""Fallback for contract calls"""
Expand Down
11 changes: 11 additions & 0 deletions skale/skale_allocator.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@
#
# 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 __future__ import annotations

import logging
from typing import TYPE_CHECKING
from web3.constants import ADDRESS_ZERO

from skale.skale_base import SkaleBase
import skale.contracts.allocator as contracts
Expand All @@ -26,6 +29,9 @@
from skale.utils.contract_types import ContractTypes
from skale.utils.helper import get_contracts_info

if TYPE_CHECKING:
from eth_typing import ChecksumAddress

Check warning on line 33 in skale/skale_allocator.py

View check run for this annotation

Codecov / codecov/patch

skale/skale_allocator.py#L33

Added line #L33 was not covered by tests


logger = logging.getLogger(__name__)

Expand All @@ -50,5 +56,10 @@ class SkaleAllocator(SkaleBase):
def project_name(self) -> str:
return 'skale-allocator'

Check warning on line 57 in skale/skale_allocator.py

View check run for this annotation

Codecov / codecov/patch

skale/skale_allocator.py#L57

Added line #L57 was not covered by tests

def get_contract_address(self, name) -> ChecksumAddress:
if name == 'Escrow':
return ADDRESS_ZERO
return super().get_contract_address(name)

Check warning on line 62 in skale/skale_allocator.py

View check run for this annotation

Codecov / codecov/patch

skale/skale_allocator.py#L60-L62

Added lines #L60 - L62 were not covered by tests

def set_contracts_info(self):
self._SkaleBase__contracts_info = get_contracts_info(CONTRACTS_INFO)
4 changes: 2 additions & 2 deletions tests/allocator/skale_allocator_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def test_init_allocator():
wallet,
provider_timeout=20
)
assert len(skale_allocator._SkaleBase__contracts) == 1
assert len(skale_allocator._SkaleBase__contracts) == 0
assert skale_allocator.allocator
assert skale_allocator.escrow
assert len(skale_allocator._SkaleBase__contracts) == 3
assert len(skale_allocator._SkaleBase__contracts) == 2

0 comments on commit 6da3a2a

Please sign in to comment.