Actors accept a transacting power or an address but not both + Cleanup.

pull/2572/head
Kieran Prasch 2021-02-22 21:41:56 -08:00
parent dcd8c9b12f
commit ba464989ba
26 changed files with 89 additions and 159 deletions

View File

@ -114,26 +114,26 @@ class BaseActor:
def __init__(self,
domain: Optional[str],
registry: BaseContractRegistry,
transacting_power: TransactingPower = None, # support non-transacting characters
checksum_address: ChecksumAddress = None):
transacting_power: TransactingPower = None,
checksum_address: ChecksumAddress = None
):
if not bool(checksum_address) ^ bool(transacting_power):
error = f'Pass transacting power or checksum address, got {checksum_address} and {transacting_power}.'
raise ValueError(error)
# TODO: Review this consistency check and simplify
# Note: If the base class implements multiple inheritance and already has a checksum address...
try:
if checksum_address:
parent_address = self.checksum_address # type: ChecksumAddress
parent_address = self.checksum_address # type: ChecksumAddress
if checksum_address is not None:
if parent_address != checksum_address:
raise ValueError("Can't have two different addresses.")
except AttributeError:
# This is an actor only, and not a full-fledged character.
if transacting_power:
self.checksum_address = transacting_power.account # type: ChecksumAddress
self.checksum_address = transacting_power.account
else:
self.checksum_address = checksum_address
self.transacting_power = transacting_power
# self.checksum_address = checksum_address # TODO: Something better, deal with inherited addresses
self.registry = registry
self.network = domain
self._saved_receipts = list() # track receipts of transmitted transactions
@ -509,14 +509,12 @@ class Staker(NucypherTokenActor):
class InsufficientTokens(StakerError):
pass
def __init__(self,
is_me: bool,
*args, **kwargs) -> None:
def __init__(self, transacting_power: TransactingPower = None, *args, **kwargs) -> None:
super().__init__(*args, **kwargs)
super().__init__(transacting_power=transacting_power, *args, **kwargs)
self.log = Logger("staker")
self.is_me = is_me
self.is_me = bool(transacting_power)
self._worker_address = None
# Blockchain
@ -1197,7 +1195,6 @@ class BlockchainPolicyAuthor(NucypherTokenActor):
"""Alice base class for blockchain operations, mocking up new policies!"""
def __init__(self,
checksum_address: ChecksumAddress,
rate: int = None,
duration_periods: int = None,
*args, **kwargs):
@ -1207,7 +1204,7 @@ class BlockchainPolicyAuthor(NucypherTokenActor):
be created from default values.
"""
super().__init__(checksum_address=checksum_address, *args, **kwargs)
super().__init__(*args, **kwargs)
# From defaults
self.staking_agent = ContractAgency.get_agent(StakingEscrowAgent, registry=self.registry)
@ -1291,8 +1288,8 @@ class Investigator(NucypherTokenActor):
anyone can report CFrags.
"""
def __init__(self, checksum_address: ChecksumAddress, *args, **kwargs):
super().__init__(checksum_address=checksum_address, *args, **kwargs)
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.adjudicator_agent = ContractAgency.get_agent(AdjudicatorAgent, registry=self.registry)
@save_receipt
@ -1300,9 +1297,9 @@ class Investigator(NucypherTokenActor):
receipt = self.adjudicator_agent.evaluate_cfrag(evidence=evidence, transacting_power=self.transacting_power)
return receipt
def was_this_evidence_evaluated(self, evidence) -> dict:
receipt = self.adjudicator_agent.was_this_evidence_evaluated(evidence=evidence)
return receipt
def was_this_evidence_evaluated(self, evidence) -> bool:
result = self.adjudicator_agent.was_this_evidence_evaluated(evidence=evidence)
return result
class StakeHolder:
@ -1352,9 +1349,7 @@ class StakeHolder:
if checksum_address not in self.signer.accounts:
raise ValueError(f"{checksum_address} is not a known client account.")
transacting_power = TransactingPower(account=checksum_address, signer=self.signer)
staker = Staker(is_me=True,
checksum_address=transacting_power.account,
transacting_power=transacting_power,
staker = Staker(transacting_power=transacting_power,
domain=self.domain,
registry=self.registry)
staker.refresh_stakes()

View File

@ -155,9 +155,8 @@ class NucypherTokenAgent(EthereumContractAgent):
contract_name: str = NUCYPHER_TOKEN_CONTRACT_NAME
@contract_api(CONTRACT_CALL)
def get_balance(self, address: Optional[ChecksumAddress] = None) -> NuNits:
def get_balance(self, address: ChecksumAddress) -> NuNits:
"""Get the NU balance (in NuNits) of a token holder address, or of this contract address"""
address = address if address is not None else self.contract_address
balance: int = self.contract.functions.balanceOf(address).call()
return NuNits(balance)

View File

@ -19,6 +19,8 @@ import random
from _pydecimal import Decimal
from collections import UserList
from enum import Enum
from eth_typing.evm import ChecksumAddress
from typing import Callable, Dict, Union
import maya
@ -791,7 +793,7 @@ class StakeList(UserList):
@validate_checksum_address
def __init__(self,
registry: BaseContractRegistry,
checksum_address: str = None, # allow for lazy setting
checksum_address: ChecksumAddress = None, # allow for lazy setting
*args, **kwargs):
super().__init__(*args, **kwargs)
@ -803,10 +805,7 @@ class StakeList(UserList):
self.__initial_period = NOT_STAKING
self.__terminal_period = NOT_STAKING
# "load-in": Read on-chain stakes
# Allow stake tracker to be initialized as an empty collection.
if checksum_address and not is_checksum_address(checksum_address):
raise ValueError(f'{checksum_address} is not a valid EIP-55 checksum address')
# "load-in" Read on-chain stakes
self.checksum_address = checksum_address
self.__updated = None

View File

@ -183,8 +183,9 @@ class Character(Learner):
raise ValueError('Provider URI is required to init a decentralized character.')
self.provider_uri = provider_uri
if not BlockchainInterfaceFactory.is_interface_initialized(provider_uri=provider_uri):
BlockchainInterfaceFactory.initialize_interface(provider_uri=provider_uri)
# TODO: Implicit / lazy blockchain connection here?
# if not BlockchainInterfaceFactory.is_interface_initialized(provider_uri=provider_uri):
# BlockchainInterfaceFactory.initialize_interface(provider_uri=provider_uri)
self.registry = registry or InMemoryContractRegistry.from_latest_publication(network=domain) # See #1580
else:

View File

@ -167,7 +167,6 @@ class Alice(Character, BlockchainPolicyAuthor):
self._crypto_power.consume_power_up(self.transacting_power)
BlockchainPolicyAuthor.__init__(self,
domain=self.domain,
checksum_address=checksum_address,
transacting_power=self.transacting_power,
registry=self.registry,
rate=rate,
@ -1074,8 +1073,8 @@ class Ursula(Teacher, Character, Worker):
availability_check: bool = False, # TODO: Remove from init
# Blockchain
checksum_address: str = None,
worker_address: str = None, # TODO: deprecate, and rename to "checksum_address"
checksum_address: ChecksumAddress = None,
worker_address: ChecksumAddress = None, # TODO: deprecate, and rename to "checksum_address"
client_password: str = None,
decentralized_identity_evidence=NOT_SIGNED,
@ -1132,8 +1131,9 @@ class Ursula(Teacher, Character, Worker):
try:
Worker.__init__(self,
is_me=is_me,
domain=self.domain,
transacting_power=self.transacting_power,
registry=self.registry,
checksum_address=checksum_address,
worker_address=worker_address)
except (Exception, self.WorkerError):
# TODO: Do not announce self to "other nodes" until this init is finished.

View File

@ -139,7 +139,7 @@ def select_client_account(emitter,
for index, account in enumerated_accounts.items():
row = [account]
if show_staking:
staker = Staker(is_me=True, domain=network, checksum_address=account, registry=registry)
staker = Staker(domain=network, checksum_address=account, registry=registry)
staker.refresh_stakes()
is_staking = 'Yes' if bool(staker.stakes) else 'No'
row.append(is_staking)

View File

@ -342,7 +342,10 @@ def accounts(general_config, staker_options, config_file):
"""Show ETH and NU balances for stakeholder's accounts."""
emitter = setup_emitter(general_config)
STAKEHOLDER = staker_options.create_character(emitter, config_file)
paint_staking_accounts(emitter=emitter, signer=STAKEHOLDER.signer, registry=STAKEHOLDER.registry)
paint_staking_accounts(emitter=emitter,
signer=STAKEHOLDER.signer,
registry=STAKEHOLDER.registry,
domain=STAKEHOLDER.domain)
@stake.command('bond-worker')

View File

@ -135,9 +135,9 @@ class WorkLockOptions:
transacting_power = TransactingPower(account=self.bidder_address, signer=signer)
transacting_power.unlock(password=client_password)
bidder = Bidder(checksum_address=self.bidder_address,
registry=registry,
bidder = Bidder(registry=registry,
transacting_power=transacting_power,
checksum_address=self.bidder_address if not transacting_power else None,
domain=domain)
return bidder

View File

@ -210,7 +210,7 @@ def paint_staking_confirmation(emitter, staker, receipt):
emitter.echo(POST_STAKING_ADVICE, color='green')
def paint_staking_accounts(emitter, signer, registry):
def paint_staking_accounts(emitter, signer, registry, domain):
from nucypher.blockchain.eth.actors import Staker
rows = list()
@ -218,9 +218,11 @@ def paint_staking_accounts(emitter, signer, registry):
token_agent = ContractAgency.get_agent(NucypherTokenAgent, registry=registry)
for account in signer.accounts:
eth = str(Web3.fromWei(blockchain.client.get_balance(account), 'ether')) + " ETH"
nu = str(NU.from_nunits(token_agent.get_balance(account, registry)))
nu = str(NU.from_nunits(token_agent.get_balance(account)))
staker = Staker(is_me=True, checksum_address=account, registry=registry)
staker = Staker(checksum_address=account,
domain=domain,
registry=registry)
staker.refresh_stakes()
is_staking = 'Yes' if bool(staker.stakes) else 'No'
rows.append((is_staking, account, eth, nu))

View File

@ -157,8 +157,7 @@ def paint_stakers(emitter, stakers: List[str], registry: BaseContractRegistry) -
emitter.echo('=' * (42 + 2 + 53))
for staker_address in stakers:
staker = Staker(is_me=False,
domain=TEMPORARY_DOMAIN,
staker = Staker(domain=TEMPORARY_DOMAIN,
checksum_address=staker_address,
registry=registry)
nickname = Nickname.from_seed(staker_address)

View File

@ -15,17 +15,15 @@ You should have received a copy of the GNU Affero General Public License
along with nucypher. If not, see <https://www.gnu.org/licenses/>.
"""
import os
from tempfile import TemporaryDirectory
import os
from constant_sorrow.constants import UNINITIALIZED_CONFIGURATION
from cryptography.hazmat.primitives.asymmetric import ec
from cryptography.hazmat.primitives.asymmetric.ec import EllipticCurve
from cryptography.x509 import Certificate
from tempfile import TemporaryDirectory
from nucypher.blockchain.eth.actors import StakeHolder
from nucypher.blockchain.eth.networks import NetworksInventory
from nucypher.blockchain.eth.signers import Signer
from nucypher.config.constants import (
DEFAULT_CONFIG_ROOT,
NUCYPHER_ENVVAR_WORKER_ETH_PASSWORD,
@ -328,9 +326,7 @@ class StakeHolderConfiguration(CharacterConfiguration):
@property
def dynamic_payload(self) -> dict:
testnet = self.domain != NetworksInventory.MAINNET
signer = Signer.from_signer_uri(self.signer_uri, testnet=testnet)
payload = dict(registry=self.registry, signer=signer)
payload = dict(registry=self.registry, signer=self.signer)
return payload
def _setup_node_storage(self, node_storage=None) -> None:

View File

@ -14,7 +14,7 @@ GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with nucypher. If not, see <https://www.gnu.org/licenses/>.
"""
from decimal import Decimal
import os
import re
@ -26,11 +26,11 @@ from constant_sorrow.constants import (
NO_KEYRING_ATTACHED,
UNINITIALIZED_CONFIGURATION
)
from decimal import Decimal
from eth_utils.address import is_checksum_address
from tempfile import TemporaryDirectory
from typing import Callable, List, Union, Optional
from umbral.signing import Signature
from web3 import Web3
from nucypher.blockchain.eth.interfaces import BlockchainInterfaceFactory
from nucypher.blockchain.eth.networks import NetworksInventory

View File

@ -888,7 +888,7 @@ class Learner:
# TODO: This whole section is weird; sprouts down have any of these things.
except sprout.StampNotSigned:
self.log.warn(f'Verification Failed - '
f'{sprout} stamp is unsigned.')
f'{sprout} {NOT_SIGNED}.')
except sprout.NotStaking:
self.log.warn(f'Verification Failed - '

View File

@ -36,9 +36,7 @@ def staker(testerchain, agency, test_registry, deployer_transacting_power):
transacting_power=deployer_transacting_power,
addresses=[staker_account],
amount=DEVELOPMENT_TOKEN_AIRDROP_AMOUNT)
staker = Staker(checksum_address=staker_account,
domain=TEMPORARY_DOMAIN,
is_me=True,
staker = Staker(domain=TEMPORARY_DOMAIN,
transacting_power=staker_power,
registry=test_registry)
return staker

View File

@ -32,8 +32,7 @@ from nucypher.blockchain.eth.constants import NULL_ADDRESS
def test_create_bidder(testerchain, test_registry, agency, token_economics):
bidder_address = testerchain.unassigned_accounts[0]
tpower = TransactingPower(account=bidder_address, signer=Web3Signer(testerchain.client))
bidder = Bidder(checksum_address=bidder_address,
domain=TEMPORARY_DOMAIN,
bidder = Bidder(domain=TEMPORARY_DOMAIN,
registry=test_registry,
transacting_power=tpower)
assert bidder.checksum_address == bidder_address
@ -57,8 +56,7 @@ def test_bidding(testerchain, agency, token_economics, test_registry):
for i, bid in enumerate(initial_bids):
bidder_address = testerchain.client.accounts[i]
tpower = TransactingPower(account=bidder_address, signer=Web3Signer(testerchain.client))
bidder = Bidder(checksum_address=bidder_address,
registry=test_registry,
bidder = Bidder(registry=test_registry,
domain=TEMPORARY_DOMAIN,
transacting_power=tpower)
@ -74,8 +72,7 @@ def test_cancel_bid(testerchain, agency, token_economics, test_registry):
bidder_address = testerchain.client.accounts[1]
tpower = TransactingPower(account=bidder_address, signer=Web3Signer(testerchain.client))
bidder = Bidder(checksum_address=bidder_address,
registry=test_registry,
bidder = Bidder(registry=test_registry,
transacting_power=tpower,
domain=TEMPORARY_DOMAIN)
assert bidder.get_deposited_eth # Bid
@ -91,8 +88,7 @@ def test_cancel_bid(testerchain, agency, token_economics, test_registry):
def test_get_remaining_work(testerchain, agency, token_economics, test_registry):
bidder_address = testerchain.client.accounts[0]
tpower = TransactingPower(account=bidder_address, signer=Web3Signer(testerchain.client))
bidder = Bidder(checksum_address=bidder_address,
registry=test_registry,
bidder = Bidder(registry=test_registry,
transacting_power=tpower,
domain=TEMPORARY_DOMAIN)
remaining = bidder.remaining_work
@ -102,8 +98,7 @@ def test_get_remaining_work(testerchain, agency, token_economics, test_registry)
def test_verify_correctness_before_refund(testerchain, agency, token_economics, test_registry):
bidder_address = testerchain.client.accounts[0]
tpower = TransactingPower(account=bidder_address, signer=Web3Signer(testerchain.client))
bidder = Bidder(checksum_address=bidder_address,
registry=test_registry,
bidder = Bidder(registry=test_registry,
transacting_power=tpower,
domain=TEMPORARY_DOMAIN)
worklock_agent = ContractAgency.get_agent(WorkLockAgent, registry=test_registry)
@ -124,8 +119,7 @@ def test_verify_correctness_before_refund(testerchain, agency, token_economics,
def test_force_refund(testerchain, agency, token_economics, test_registry):
bidder_address = testerchain.client.accounts[0]
tpower = TransactingPower(account=bidder_address, signer=Web3Signer(testerchain.client))
bidder = Bidder(checksum_address=bidder_address,
registry=test_registry,
bidder = Bidder(registry=test_registry,
transacting_power=tpower,
domain=TEMPORARY_DOMAIN)
whales = bidder.get_whales()
@ -139,8 +133,7 @@ def test_force_refund(testerchain, agency, token_economics, test_registry):
bidder_address = testerchain.client.accounts[1]
tpower = TransactingPower(account=bidder_address, signer=Web3Signer(testerchain.client))
bidder = Bidder(checksum_address=bidder_address,
registry=test_registry,
bidder = Bidder(registry=test_registry,
transacting_power=tpower,
domain=TEMPORARY_DOMAIN)
worklock_agent = ContractAgency.get_agent(WorkLockAgent, registry=test_registry)
@ -160,8 +153,7 @@ def test_force_refund(testerchain, agency, token_economics, test_registry):
def test_verify_correctness(testerchain, agency, token_economics, test_registry):
bidder_address = testerchain.client.accounts[0]
tpower = TransactingPower(account=bidder_address, signer=Web3Signer(testerchain.client))
bidder = Bidder(checksum_address=bidder_address,
registry=test_registry,
bidder = Bidder(registry=test_registry,
transacting_power=tpower,
domain=TEMPORARY_DOMAIN)
worklock_agent = ContractAgency.get_agent(WorkLockAgent, registry=test_registry)
@ -180,8 +172,7 @@ def test_verify_correctness(testerchain, agency, token_economics, test_registry)
def test_withdraw_compensation(testerchain, agency, token_economics, test_registry):
bidder_address = testerchain.client.accounts[12]
tpower = TransactingPower(account=bidder_address, signer=Web3Signer(testerchain.client))
bidder = Bidder(checksum_address=bidder_address,
registry=test_registry,
bidder = Bidder(registry=test_registry,
transacting_power=tpower,
domain=TEMPORARY_DOMAIN)
worklock_agent = ContractAgency.get_agent(WorkLockAgent, registry=test_registry)
@ -195,8 +186,7 @@ def test_withdraw_compensation(testerchain, agency, token_economics, test_regist
def test_claim(testerchain, agency, token_economics, test_registry):
bidder_address = testerchain.client.accounts[11]
tpower = TransactingPower(account=bidder_address, signer=Web3Signer(testerchain.client))
bidder = Bidder(checksum_address=bidder_address,
registry=test_registry,
bidder = Bidder(registry=test_registry,
transacting_power=tpower,
domain=TEMPORARY_DOMAIN)
staking_agent = ContractAgency.get_agent(StakingEscrowAgent, registry=test_registry)

View File

@ -21,10 +21,9 @@ import json
import pytest
import random
from nucypher.blockchain.eth.signers.software import Web3Signer
from nucypher.blockchain.eth.actors import ContractAdministrator
from nucypher.crypto.powers import TransactingPower
from tests.constants import INSECURE_DEVELOPMENT_PASSWORD, NUMBER_OF_ALLOCATIONS_IN_TESTS
from nucypher.blockchain.eth.signers.software import Web3Signer
from tests.constants import NUMBER_OF_ALLOCATIONS_IN_TESTS
# Prevents TesterBlockchain to be picked up by py.test as a test class
from tests.utils.blockchain import TesterBlockchain as _TesterBlockchain
@ -33,13 +32,8 @@ from tests.utils.blockchain import TesterBlockchain as _TesterBlockchain
@pytest.mark.usefixtures('testerchain')
def test_rapid_deployment(token_economics, test_registry, tmpdir, get_random_checksum_address):
blockchain = _TesterBlockchain(eth_airdrop=False,
test_accounts=4)
blockchain = _TesterBlockchain(eth_airdrop=False, test_accounts=4)
# TODO: #1092 - TransactingPower
blockchain.transacting_power = TransactingPower(password=INSECURE_DEVELOPMENT_PASSWORD,
signer=Web3Signer(blockchain.client),
account=blockchain.etherbase_account)
deployer_address = blockchain.etherbase_account
administrator = ContractAdministrator(deployer_address=deployer_address,

View File

@ -67,9 +67,7 @@ def test_investigator_requests_slashing(testerchain,
# Deposit: The staker deposits tokens in the StakingEscrow contract.
staker_tpower = TransactingPower(account=staker_account, signer=Web3Signer(testerchain.client))
staker = Staker(checksum_address=staker_account,
is_me=True,
transacting_power=staker_tpower,
staker = Staker(transacting_power=staker_tpower,
domain=TEMPORARY_DOMAIN,
registry=test_registry)
@ -91,8 +89,7 @@ def test_investigator_requests_slashing(testerchain,
bob_tpower = TransactingPower(account=bob_account, signer=Web3Signer(testerchain.client))
investigator = Investigator(registry=test_registry,
transacting_power=bob_tpower,
domain=TEMPORARY_DOMAIN,
checksum_address=bob_account)
domain=TEMPORARY_DOMAIN)
ursula = mock_ursula(testerchain, worker_account, mocker=mocker)
# Let's create a bad cfrag

View File

@ -71,9 +71,7 @@ def test_adjudicator_slashes(agency,
# Deposit: The staker deposits tokens in the StakingEscrow contract.
tpower = TransactingPower(account=staker_account, signer=Web3Signer(testerchain.client))
staker = Staker(checksum_address=staker_account,
is_me=True,
domain=TEMPORARY_DOMAIN,
staker = Staker(domain=TEMPORARY_DOMAIN,
registry=test_registry,
transacting_power=tpower)

View File

@ -130,10 +130,8 @@ def test_stake_in_idle_network(testerchain, token_economics, test_registry):
account = testerchain.stakers_accounts[0]
tpower = TransactingPower(account=account, signer=Web3Signer(testerchain.client))
staker = Staker(is_me=True,
transacting_power=tpower,
staker = Staker(transacting_power=tpower,
domain=TEMPORARY_DOMAIN,
checksum_address=account,
registry=test_registry)
# Since StakingEscrow hasn't been activated yet, deposit should work but making a commitment must fail

View File

@ -133,7 +133,6 @@ def test_collect_inflation_rewards(software_stakeholder, manual_worker, testerch
transacting_power=tpower,
domain=TEMPORARY_DOMAIN,
worker_address=manual_worker,
checksum_address=stake.staker_address,
registry=test_registry)
# Wait out stake lock periods, manually make a commitment once per period.

View File

@ -126,11 +126,9 @@ def test_run_felix(click_runner, testerchain, agency_local_registry):
recipient = testerchain.client.accounts[-1]
staker_power = TransactingPower(account=recipient, signer=Web3Signer(testerchain.client))
staker = Staker(checksum_address=recipient,
registry=agency_local_registry,
staker = Staker(registry=agency_local_registry,
domain=TEMPORARY_DOMAIN,
transacting_power=staker_power,
is_me=True)
transacting_power=staker_power)
original_eth_balance = staker.eth_balance
# Run the callbacks
@ -142,11 +140,9 @@ def test_run_felix(click_runner, testerchain, agency_local_registry):
def confirm_airdrop(_results):
recipient = testerchain.client.accounts[-1]
staker = Staker(checksum_address=recipient,
registry=agency_local_registry,
staker = Staker(registry=agency_local_registry,
domain=TEMPORARY_DOMAIN,
transacting_power=staker_power,
is_me=True)
transacting_power=staker_power)
assert staker.token_balance == NU(45000, 'NU')

View File

@ -232,10 +232,8 @@ def test_refund(click_runner, testerchain, agency_local_registry, token_economic
# Bidder is now STAKER. Bond a worker.
tpower = TransactingPower(account=bidder, signer=Web3Signer(testerchain.client))
staker = Staker(is_me=True,
transacting_power=tpower,
staker = Staker(transacting_power=tpower,
domain=TEMPORARY_DOMAIN,
checksum_address=bidder,
registry=agency_local_registry)
receipt = staker.bond_worker(worker_address=worker_address)
assert receipt['status'] == 1
@ -284,8 +282,7 @@ def test_participant_status(click_runner, testerchain, agency_local_registry, to
tpower = TransactingPower(account=testerchain.client.accounts[2],
signer=Web3Signer(testerchain.client))
bidder = Bidder(checksum_address=testerchain.client.accounts[2],
transacting_power=tpower,
bidder = Bidder(transacting_power=tpower,
domain=TEMPORARY_DOMAIN,
registry=agency_local_registry)

View File

@ -193,8 +193,7 @@ def test_stake_prolong(click_runner,
'--staking-address', manual_staker,
'--force')
staker = Staker(is_me=True,
domain=TEMPORARY_DOMAIN,
staker = Staker(domain=TEMPORARY_DOMAIN,
checksum_address=manual_staker,
registry=agency_local_registry)
staker.refresh_stakes()
@ -345,8 +344,7 @@ def test_stake_bond_worker(click_runner,
catch_exceptions=False)
assert result.exit_code == 0
staker = Staker(is_me=True,
domain=TEMPORARY_DOMAIN,
staker = Staker(domain=TEMPORARY_DOMAIN,
checksum_address=manual_staker,
registry=agency_local_registry)
assert staker.worker_address == manual_worker
@ -420,8 +418,7 @@ def test_stake_restake(click_runner,
agency_local_registry,
stakeholder_configuration_file_location):
staker = Staker(is_me=True,
domain=TEMPORARY_DOMAIN,
staker = Staker(domain=TEMPORARY_DOMAIN,
checksum_address=manual_staker,
registry=agency_local_registry)
assert staker.is_restaking
@ -475,8 +472,7 @@ def test_stake_winddown(click_runner,
agency_local_registry,
stakeholder_configuration_file_location):
staker = Staker(is_me=True,
domain=TEMPORARY_DOMAIN,
staker = Staker(domain=TEMPORARY_DOMAIN,
checksum_address=manual_staker,
registry=agency_local_registry)
assert not staker.is_winding_down
@ -517,8 +513,7 @@ def test_stake_snapshots(click_runner,
agency_local_registry,
stakeholder_configuration_file_location):
staker = Staker(is_me=True,
domain=TEMPORARY_DOMAIN,
staker = Staker(domain=TEMPORARY_DOMAIN,
checksum_address=manual_staker,
registry=agency_local_registry)
assert staker.is_taking_snapshots
@ -572,8 +567,7 @@ def test_collect_rewards_integration(click_runner,
staker_address = manual_staker
worker_address = manual_worker
staker = Staker(is_me=True,
domain=TEMPORARY_DOMAIN,
staker = Staker(domain=TEMPORARY_DOMAIN,
checksum_address=staker_address,
registry=agency_local_registry)
staker.refresh_stakes()
@ -739,8 +733,7 @@ def test_stake_unbond_worker(click_runner,
stakeholder_configuration_file_location):
testerchain.time_travel(periods=1)
staker = Staker(is_me=True,
domain=TEMPORARY_DOMAIN,
staker = Staker(domain=TEMPORARY_DOMAIN,
checksum_address=manual_staker,
registry=agency_local_registry)
@ -759,8 +752,7 @@ def test_stake_unbond_worker(click_runner,
catch_exceptions=False)
assert result.exit_code == 0
staker = Staker(is_me=True,
domain=TEMPORARY_DOMAIN,
staker = Staker(domain=TEMPORARY_DOMAIN,
checksum_address=manual_staker,
registry=agency_local_registry)
@ -775,8 +767,7 @@ def test_set_min_rate(click_runner,
_minimum, _default, maximum = FEE_RATE_RANGE
min_rate = maximum - 1
staker = Staker(is_me=True,
domain=TEMPORARY_DOMAIN,
staker = Staker(domain=TEMPORARY_DOMAIN,
checksum_address=manual_staker,
registry=agency_local_registry)
assert staker.raw_min_fee_rate == 0
@ -813,8 +804,7 @@ def test_mint(click_runner,
stakeholder_configuration_file_location):
testerchain.time_travel(periods=2)
staker = Staker(is_me=True,
domain=TEMPORARY_DOMAIN,
staker = Staker(domain=TEMPORARY_DOMAIN,
checksum_address=manual_staker,
registry=agency_local_registry)
assert staker.mintable_periods() > 0

View File

@ -58,7 +58,7 @@ def test_blockchain_ursula_stamp_verification_tolerance(blockchain_ursulas, mock
assert len(warnings) == 1
warning = warnings[0]['log_format']
assert str(unsigned) in warning
assert "stamp is unsigned" in warning # TODO: Cleanup logging templates
assert "Verification Failed" in warning # TODO: Cleanup logging templates
# TODO: Buckets! #567
# assert unsigned not in lonely_blockchain_learner.known_nodes
@ -102,9 +102,6 @@ def test_invalid_workers_tolerance(testerchain,
amount = token_economics.minimum_allowed_locked
periods = token_economics.minimum_locked_periods
# Mock Powerup consumption (Staker)
testerchain.transacting_power = TransactingPower(account=idle_staker.checksum_address)
idle_staker.initialize_stake(amount=amount, lock_periods=periods)
# Stake starts next period (or else signature validation will fail)
@ -138,8 +135,6 @@ def test_invalid_workers_tolerance(testerchain,
# The stake period has ended, and the staker wants her tokens back ("when lambo?").
# She withdraws up to the last penny (well, last nunit, actually).
# Mock Powerup consumption (Staker)
testerchain.transacting_power = TransactingPower(account=idle_staker.checksum_address)
idle_staker.mint()
testerchain.time_travel(periods=1)
i_want_it_all = staking_agent.owned_tokens(idle_staker.checksum_address)

View File

@ -517,10 +517,6 @@ def testerchain(_testerchain) -> TesterBlockchain:
testerchain.log.info("Airdropped {} ETH {} -> {}".format(eth_amount, tx['from'], tx['to']))
BlockchainInterfaceFactory.register_interface(interface=testerchain, force=True)
# Mock TransactingPower Consumption (Deployer)
testerchain.transacting_power = TransactingPower(password=INSECURE_DEVELOPMENT_PASSWORD,
signer=Web3Signer(client=testerchain.client),
account=testerchain.etherbase_account)
yield testerchain
@ -542,10 +538,6 @@ def deployer_transacting_power(testerchain):
def _make_agency(testerchain, test_registry, token_economics, deployer_transacting_power):
"""
Launch the big three contracts on provided chain,
make agents for each and return them.
"""
transacting_power = deployer_transacting_power
@ -608,10 +600,7 @@ def agency_local_registry(testerchain, agency, test_registry):
@pytest.fixture(scope="module")
def stakers(testerchain, agency, token_economics, test_registry, deployer_transacting_power):
token_agent = ContractAgency.get_agent(NucypherTokenAgent, registry=test_registry)
staking_agent = ContractAgency.get_agent(StakingEscrowAgent, registry=test_registry)
blockchain = token_agent.blockchain
token_airdrop(transacting_power=deployer_transacting_power,
addresses=blockchain.stakers_accounts,
token_agent=token_agent,
@ -622,10 +611,8 @@ def stakers(testerchain, agency, token_economics, test_registry, deployer_transa
tpower = TransactingPower(account=account, signer=Web3Signer(testerchain.client))
tpower.unlock(password=INSECURE_DEVELOPMENT_PASSWORD)
staker = Staker(is_me=True,
transacting_power=tpower,
staker = Staker(transacting_power=tpower,
domain=TEMPORARY_DOMAIN,
checksum_address=account,
registry=test_registry)
amount = MIN_STAKE_FOR_TESTS + random.randrange(BONUS_TOKENS_FOR_TESTS)
@ -694,10 +681,8 @@ def idle_staker(testerchain, agency, test_registry):
amount=DEVELOPMENT_TOKEN_AIRDROP_AMOUNT)
# Prepare idle staker
idle_staker = Staker(is_me=True,
transacting_power=transacting_power,
idle_staker = Staker(transacting_power=transacting_power,
domain=TEMPORARY_DOMAIN,
checksum_address=idle_staker_account,
blockchain=testerchain)
yield idle_staker

View File

@ -60,8 +60,7 @@ def surrogate_transacting_power(mock_testerchain):
@pytest.fixture()
def surrogate_bidder(mock_testerchain, test_registry, mock_worklock_agent, surrogate_transacting_power):
bidder = Bidder(checksum_address=surrogate_transacting_power.account,
registry=test_registry,
bidder = Bidder(registry=test_registry,
transacting_power=surrogate_transacting_power,
domain=TEMPORARY_DOMAIN)
return bidder