Add worker_is_bonded static method and include in worker tests

pull/1697/head
tuxxy 2020-02-14 22:06:01 +01:00 committed by Kieran R. Prasch
parent 91d26f10cf
commit 44739108c6
2 changed files with 19 additions and 0 deletions

View File

@ -1203,6 +1203,18 @@ class Worker(NucypherTokenActor):
if start_working_now: if start_working_now:
self.work_tracker.start(act_now=False) self.work_tracker.start(act_now=False)
@staticmethod
def worker_is_bonded(worker_address: str, registry: 'BaseContractRegistry') -> bool:
"""
Checks that the Worker's bonded staking address isn't a null address
and returns a boolean.
"""
staking_agent = ContractAgency.get_agent(StakingEscrowAgent,
registry=registry)
staking_addr = staking_agent.get_staker_from_worker(worker_address)
return staking_addr != BlockchainInterface.NULL_ADDRESS
@property @property
def eth_balance(self) -> Decimal: def eth_balance(self) -> Decimal:
"""Return this workers's current ETH balance""" """Return this workers's current ETH balance"""

View File

@ -3,6 +3,7 @@ import pytest_twisted
from twisted.internet import threads from twisted.internet import threads
from twisted.internet.task import Clock from twisted.internet.task import Clock
from nucypher.blockchain.eth.actors import Worker
from nucypher.blockchain.eth.token import NU, WorkTracker from nucypher.blockchain.eth.token import NU, WorkTracker
from nucypher.crypto.powers import TransactingPower from nucypher.crypto.powers import TransactingPower
from nucypher.utilities.sandbox.constants import INSECURE_DEVELOPMENT_PASSWORD from nucypher.utilities.sandbox.constants import INSECURE_DEVELOPMENT_PASSWORD
@ -31,9 +32,15 @@ def test_worker_auto_confirmations(testerchain,
clock = Clock() clock = Clock()
WorkTracker.CLOCK = clock WorkTracker.CLOCK = clock
# Check that the worker is unbonded
assert not Worker.worker_is_bonded(worker_address, test_registry)
# Bond the Worker and Staker # Bond the Worker and Staker
staker.set_worker(worker_address=worker_address) staker.set_worker(worker_address=worker_address)
# Ensure the worker is now bonded
assert Worker.worker_is_bonded(worker_address, test_registry)
# Make the Worker # Make the Worker
ursula = make_decentralized_ursulas(ursula_config=ursula_decentralized_test_config, ursula = make_decentralized_ursulas(ursula_config=ursula_decentralized_test_config,
stakers_addresses=[staker.checksum_address], stakers_addresses=[staker.checksum_address],