diff --git a/nucypher/blockchain/eth/actors.py b/nucypher/blockchain/eth/actors.py index 13898a1fd..93b33f843 100644 --- a/nucypher/blockchain/eth/actors.py +++ b/nucypher/blockchain/eth/actors.py @@ -1203,6 +1203,18 @@ class Worker(NucypherTokenActor): if start_working_now: 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 def eth_balance(self) -> Decimal: """Return this workers's current ETH balance""" diff --git a/tests/blockchain/eth/entities/actors/test_worker.py b/tests/blockchain/eth/entities/actors/test_worker.py index a1042eff7..5c06d674c 100644 --- a/tests/blockchain/eth/entities/actors/test_worker.py +++ b/tests/blockchain/eth/entities/actors/test_worker.py @@ -3,6 +3,7 @@ import pytest_twisted from twisted.internet import threads from twisted.internet.task import Clock +from nucypher.blockchain.eth.actors import Worker from nucypher.blockchain.eth.token import NU, WorkTracker from nucypher.crypto.powers import TransactingPower from nucypher.utilities.sandbox.constants import INSECURE_DEVELOPMENT_PASSWORD @@ -31,9 +32,15 @@ def test_worker_auto_confirmations(testerchain, 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 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 ursula = make_decentralized_ursulas(ursula_config=ursula_decentralized_test_config, stakers_addresses=[staker.checksum_address],