def test_stake_unbond_worker(click_runner, testerchain, manual_staker, manual_worker, agency_local_registry, stakeholder_configuration_file_location): testerchain.time_travel(periods=1) staker = Staker(is_me=True, checksum_address=manual_staker, registry=agency_local_registry) assert staker.worker_address == manual_worker init_args = ('stake', 'unbond-worker', '--config-file', stakeholder_configuration_file_location, '--staking-address', manual_staker, '--force') user_input = f'{INSECURE_DEVELOPMENT_PASSWORD}' result = click_runner.invoke(nucypher_cli, init_args, input=user_input, catch_exceptions=False) assert result.exit_code == 0 staker = Staker(is_me=True, checksum_address=manual_staker, registry=agency_local_registry) assert staker.worker_address == NULL_ADDRESS
def test_stake_detach_worker(click_runner, testerchain, manual_staker, manual_worker, stakeholder_configuration_file_location): staker = Staker(is_me=True, checksum_address=manual_staker, blockchain=testerchain) assert staker.worker_address == manual_worker init_args = ( 'stake', 'detach-worker', '--config-file', stakeholder_configuration_file_location, '--staking-address', manual_staker, ) user_input = f'{INSECURE_DEVELOPMENT_PASSWORD}' result = click_runner.invoke(nucypher_cli, init_args, input=user_input, catch_exceptions=False) assert result.exit_code == 0 staker = Staker(is_me=True, checksum_address=manual_staker, blockchain=testerchain) assert not staker.worker_address
def test_stake_detach_worker(click_runner, testerchain, token_economics, beneficiary, preallocation_escrow_agent, mock_allocation_registry, manual_worker, agency_local_registry, individual_allocation, stakeholder_configuration_file_location): staker_address = preallocation_escrow_agent.principal_contract.address staking_agent = ContractAgency.get_agent(StakingEscrowAgent, registry=agency_local_registry) assert manual_worker == staking_agent.get_worker_from_staker(staker_address=staker_address) testerchain.time_travel(periods=token_economics.minimum_worker_periods) init_args = ('stake', 'detach-worker', '--config-file', stakeholder_configuration_file_location, '--allocation-filepath', MOCK_INDIVIDUAL_ALLOCATION_FILEPATH, '--force') result = click_runner.invoke(nucypher_cli, init_args, input=INSECURE_DEVELOPMENT_PASSWORD, catch_exceptions=False) assert result.exit_code == 0 staker = Staker(is_me=True, checksum_address=beneficiary, individual_allocation=individual_allocation, registry=agency_local_registry) assert not staker.worker_address # Ok ok, let's set the worker again. init_args = ('stake', 'set-worker', '--config-file', stakeholder_configuration_file_location, '--allocation-filepath', MOCK_INDIVIDUAL_ALLOCATION_FILEPATH, '--worker-address', manual_worker, '--force') user_input = INSECURE_DEVELOPMENT_PASSWORD result = click_runner.invoke(nucypher_cli, init_args, input=user_input, catch_exceptions=False) assert result.exit_code == 0 staker = Staker(is_me=True, checksum_address=beneficiary, individual_allocation=individual_allocation, registry=agency_local_registry) assert staker.worker_address == manual_worker
def test_stake_in_idle_network(testerchain, token_economics, test_registry): # Let's fund a staker first token_agent = NucypherTokenAgent(registry=test_registry) token_airdrop(origin=testerchain.etherbase_account, addresses=testerchain.stakers_accounts, token_agent=token_agent, amount=DEVELOPMENT_TOKEN_AIRDROP_AMOUNT) account = testerchain.stakers_accounts[0] staker = Staker(is_me=True, checksum_address=account, registry=test_registry) # Mock TransactingPower consumption staker.transacting_power = TransactingPower( password=INSECURE_DEVELOPMENT_PASSWORD, account=staker.checksum_address) staker.transacting_power.activate() # Since StakingEscrow hasn't been activated yet, deposit should work but making a commitment must fail amount = token_economics.minimum_allowed_locked periods = token_economics.minimum_locked_periods staker.initialize_stake(amount=amount, lock_periods=periods) staker.bond_worker(account) with pytest.raises((TransactionFailed, ValueError)): staker.staking_agent.commit_to_next_period(worker_address=account)
def test_stake_winddown(click_runner, manual_staker, custom_filepath, testerchain, agency_local_registry, stakeholder_configuration_file_location): staker = Staker(domain=TEMPORARY_DOMAIN, checksum_address=manual_staker, registry=agency_local_registry) assert not staker.is_winding_down restake_args = ('stake', 'winddown', '--enable', '--config-file', str(stakeholder_configuration_file_location.absolute()), '--staking-address', manual_staker, '--force') result = click_runner.invoke(nucypher_cli, restake_args, input=INSECURE_DEVELOPMENT_PASSWORD, catch_exceptions=False) assert result.exit_code == 0 assert staker.is_winding_down assert "Successfully enabled" in result.output disable_args = ('stake', 'winddown', '--disable', '--config-file', str(stakeholder_configuration_file_location.absolute()), '--staking-address', manual_staker, '--force') result = click_runner.invoke(nucypher_cli, disable_args, input=INSECURE_DEVELOPMENT_PASSWORD, catch_exceptions=False) assert result.exit_code == 0 assert not staker.is_winding_down assert "Successfully disabled" in result.output
def test_stake_set_worker(click_runner, beneficiary, mock_allocation_registry, agency_local_registry, manual_worker, individual_allocation, stakeholder_configuration_file_location): init_args = ('stake', 'set-worker', '--config-file', stakeholder_configuration_file_location, '--allocation-filepath', MOCK_INDIVIDUAL_ALLOCATION_FILEPATH, '--worker-address', manual_worker, '--force') user_input = INSECURE_DEVELOPMENT_PASSWORD result = click_runner.invoke(nucypher_cli, init_args, input=user_input, catch_exceptions=False) assert result.exit_code == 0 staker = Staker(is_me=True, checksum_address=beneficiary, individual_allocation=individual_allocation, registry=agency_local_registry) assert staker.worker_address == manual_worker
def test_stake_prolong(click_runner, testerchain, agency_local_registry, manual_staker, manual_worker, stakeholder_configuration_file_location): prolong_args = ('stake', 'prolong', '--config-file', stakeholder_configuration_file_location, '--index', 0, '--lock-periods', 1, '--staking-address', manual_staker, '--force') staker = Staker(is_me=True, checksum_address=manual_staker, registry=agency_local_registry) staker.refresh_stakes() stake = staker.stakes[0] old_termination = stake.final_locked_period user_input = INSECURE_DEVELOPMENT_PASSWORD result = click_runner.invoke(nucypher_cli, prolong_args, input=user_input, catch_exceptions=False) assert result.exit_code == 0 # Ensure Integration with Stakes stake.sync() new_termination = stake.final_locked_period assert new_termination == old_termination + 1
def test_stake_snapshots(click_runner, manual_staker, custom_filepath, testerchain, agency_local_registry, stakeholder_configuration_file_location): staker = Staker(is_me=True, checksum_address=manual_staker, registry=agency_local_registry) assert staker.is_taking_snapshots restake_args = ('stake', 'snapshots', '--disable', '--config-file', stakeholder_configuration_file_location, '--staking-address', manual_staker, '--force') result = click_runner.invoke(nucypher_cli, restake_args, input=INSECURE_DEVELOPMENT_PASSWORD, catch_exceptions=False) assert result.exit_code == 0 assert not staker.is_taking_snapshots assert "Successfully disabled" in result.output disable_args = ('stake', 'snapshots', '--enable', '--config-file', stakeholder_configuration_file_location, '--staking-address', manual_staker, '--force') result = click_runner.invoke(nucypher_cli, disable_args, input=INSECURE_DEVELOPMENT_PASSWORD, catch_exceptions=False) assert result.exit_code == 0 assert staker.is_taking_snapshots assert "Successfully enabled" in result.output
def test_set_min_rate(click_runner, manual_staker, testerchain, agency_local_registry, stakeholder_configuration_file_location): _minimum, _default, maximum = FEE_RATE_RANGE min_rate = maximum - 1 staker = Staker(is_me=True, checksum_address=manual_staker, registry=agency_local_registry) assert staker.raw_min_fee_rate == 0 min_rate_in_gwei = Web3.fromWei(min_rate, 'gwei') restake_args = ('stake', 'set-min-rate', '--min-rate', min_rate_in_gwei, '--config-file', stakeholder_configuration_file_location, '--staking-address', manual_staker, '--force') result = click_runner.invoke(nucypher_cli, restake_args, input=INSECURE_DEVELOPMENT_PASSWORD, catch_exceptions=False) assert result.exit_code == 0 assert staker.raw_min_fee_rate == min_rate assert "successfully set" in result.output stake_args = ('stake', 'list', '--config-file', stakeholder_configuration_file_location) user_input = INSECURE_DEVELOPMENT_PASSWORD result = click_runner.invoke(nucypher_cli, stake_args, input=user_input, catch_exceptions=False) assert result.exit_code == 0 assert f"{prettify_eth_amount(min_rate)}" in result.output
def test_stake_in_idle_network(testerchain, token_economics, test_registry): # Let's fund a staker first token_agent = NucypherTokenAgent(registry=test_registry) tpower = TransactingPower(account=testerchain.etherbase_account, signer=Web3Signer(testerchain.client)) token_airdrop(transacting_power=tpower, addresses=testerchain.stakers_accounts, token_agent=token_agent, amount=DEVELOPMENT_TOKEN_AIRDROP_AMOUNT) account = testerchain.stakers_accounts[0] tpower = TransactingPower(account=account, signer=Web3Signer(testerchain.client)) staker = Staker(transacting_power=tpower, domain=TEMPORARY_DOMAIN, registry=test_registry) # Since StakingEscrow hasn't been activated yet, deposit should work but making a commitment must fail amount = token_economics.minimum_allowed_locked periods = token_economics.minimum_locked_periods staker.initialize_stake(amount=amount, lock_periods=periods) staker.bond_worker(account) with pytest.raises((TransactionFailed, ValueError)): staker.staking_agent.commit_to_next_period(transacting_power=tpower)
def surrogate_staker(mock_testerchain, test_registry, mock_staking_agent): address = mock_testerchain.etherbase_account staker = Staker(is_me=True, checksum_address=address, registry=test_registry) mock_staking_agent.get_all_stakes.return_value = [] return staker
def test_refund(click_runner, testerchain, agency_local_registry, token_economics): bidder = testerchain.client.accounts[2] worker_address = testerchain.unassigned_accounts[-1] # # WorkLock Staker-Worker # worklock_agent = ContractAgency.get_agent(WorkLockAgent, registry=agency_local_registry) # Bidder is now STAKER. Bond a worker. staker = Staker(is_me=True, checksum_address=bidder, registry=agency_local_registry) receipt = staker.bond_worker(worker_address=worker_address) assert receipt['status'] == 1 worker = Ursula(is_me=True, registry=agency_local_registry, checksum_address=bidder, worker_address=worker_address, rest_host=MOCK_IP_ADDRESS, rest_port=select_test_port(), db_filepath=tempfile.mkdtemp()) # Ensure there is work to do remaining_work = worklock_agent.get_remaining_work(checksum_address=bidder) assert remaining_work > 0 # Unlock transacting_power = worker._crypto_power.power_ups(TransactingPower) transacting_power.activate(password=INSECURE_DEVELOPMENT_PASSWORD) # Do some work for i in range(3): txhash = worker.commit_to_next_period() testerchain.wait_for_receipt(txhash) assert receipt['status'] == 1 testerchain.time_travel(periods=1) command = ('refund', '--participant-address', bidder, '--registry-filepath', agency_local_registry.filepath, '--provider', TEST_PROVIDER_URI, '--network', TEMPORARY_DOMAIN, '--force') user_input = f'{INSECURE_DEVELOPMENT_PASSWORD}\n' + 'Y\n' result = click_runner.invoke(worklock, command, input=user_input, catch_exceptions=False) assert result.exit_code == 0 # Less work to do... new_remaining_work = worklock_agent.get_remaining_work( checksum_address=bidder) assert new_remaining_work < remaining_work
def test_stake_restake(click_runner, manual_staker, custom_filepath, testerchain, agency_local_registry, stakeholder_configuration_file_location): staker = Staker(is_me=True, checksum_address=manual_staker, registry=agency_local_registry) assert staker.is_restaking restake_args = ('stake', 'restake', '--disable', '--config-file', stakeholder_configuration_file_location, '--staking-address', manual_staker, '--force') result = click_runner.invoke(nucypher_cli, restake_args, input=INSECURE_DEVELOPMENT_PASSWORD, catch_exceptions=False) assert result.exit_code == 0 assert not staker.is_restaking assert "Successfully disabled" in result.output staking_agent = ContractAgency.get_agent(StakingEscrowAgent, registry=agency_local_registry) current_period = staking_agent.get_current_period() release_period = current_period + 1 lock_args = ('stake', 'restake', '--lock-until', release_period, '--config-file', stakeholder_configuration_file_location, '--staking-address', manual_staker, '--force') result = click_runner.invoke(nucypher_cli, lock_args, input=INSECURE_DEVELOPMENT_PASSWORD, catch_exceptions=False) assert result.exit_code == 0 # Still not staking and the lock is enabled assert not staker.is_restaking assert staker.restaking_lock_enabled # CLI Output includes success message assert "Successfully enabled" in result.output assert str(release_period) in result.output # Wait until release period testerchain.time_travel(periods=1) assert not staker.restaking_lock_enabled assert not staker.is_restaking disable_args = ('stake', 'restake', '--enable', '--config-file', stakeholder_configuration_file_location, '--staking-address', manual_staker, '--force') result = click_runner.invoke(nucypher_cli, disable_args, input=INSECURE_DEVELOPMENT_PASSWORD, catch_exceptions=False) assert result.exit_code == 0 assert staker.is_restaking assert "Successfully enabled" in result.output
def test_stake_restake(click_runner, beneficiary, preallocation_escrow_agent, mock_allocation_registry, agency_local_registry, manual_worker, testerchain, individual_allocation, stakeholder_configuration_file_location): staker = Staker(is_me=True, checksum_address=beneficiary, registry=agency_local_registry, individual_allocation=individual_allocation) assert staker.is_restaking restake_args = ('stake', 'restake', '--disable', '--config-file', stakeholder_configuration_file_location, '--allocation-filepath', MOCK_INDIVIDUAL_ALLOCATION_FILEPATH, '--force') result = click_runner.invoke(nucypher_cli, restake_args, input=INSECURE_DEVELOPMENT_PASSWORD, catch_exceptions=False) assert result.exit_code == 0 assert not staker.is_restaking assert "Successfully disabled" in result.output disable_args = ('stake', 'restake', '--enable', '--config-file', stakeholder_configuration_file_location, '--allocation-filepath', MOCK_INDIVIDUAL_ALLOCATION_FILEPATH, '--force') result = click_runner.invoke(nucypher_cli, disable_args, input=INSECURE_DEVELOPMENT_PASSWORD, catch_exceptions=False) assert result.exit_code == 0 allocation_contract_address = preallocation_escrow_agent.principal_contract.address staking_agent = ContractAgency.get_agent(StakingEscrowAgent, registry=agency_local_registry) assert staking_agent.is_restaking(allocation_contract_address) staker = Staker(is_me=True, checksum_address=beneficiary, registry=agency_local_registry, individual_allocation=individual_allocation) assert staker.is_restaking assert "Successfully enabled" in result.output
def staker(testerchain, agency): token_agent, staking_agent, policy_agent = agency origin, staker_account, *everybody_else = testerchain.client.accounts token_airdrop(token_agent=token_agent, origin=testerchain.etherbase_account, addresses=[staker_account], amount=DEVELOPMENT_TOKEN_AIRDROP_AMOUNT) staker = Staker(checksum_address=staker_account, is_me=True, blockchain=testerchain) return staker
def confirm_airdrop(_results): recipient = testerchain.client.accounts[-1] staker = Staker(checksum_address=recipient, blockchain=testerchain, is_me=True) assert staker.token_balance == NU(15000, 'NU') # TODO: Airdrop Testnet Ethers? # new_eth_balance = original_eth_balance + testerchain.w3.fromWei(Felix.ETHER_AIRDROP_AMOUNT, 'ether') assert staker.eth_balance == original_eth_balance
def confirm_airdrop(_results): recipient = testerchain.client.accounts[-1] staker = Staker(registry=agency_local_registry, domain=TEMPORARY_DOMAIN, transacting_power=staker_power) assert staker.token_balance == NU(45000, 'NU') # TODO: Airdrop Testnet Ethers? new_eth_balance = original_eth_balance + testerchain.w3.fromWei( Felix.ETHER_AIRDROP_AMOUNT, 'ether') assert staker.eth_balance == new_eth_balance
def test_refund(click_runner, testerchain, agency_local_registry, token_economics): bidder = testerchain.unassigned_accounts[1] worker_address = testerchain.unassigned_accounts[-1] # # WorkLock Staker-Worker # worklock_agent = ContractAgency.get_agent(WorkLockAgent, registry=agency_local_registry) # Bidder is now STAKER. Bond a worker. staker = Staker(is_me=True, checksum_address=bidder, registry=agency_local_registry) receipt = staker.set_worker(worker_address=worker_address) assert receipt['status'] == 1 worker = Ursula(is_me=True, registry=agency_local_registry, checksum_address=bidder, worker_address=worker_address, rest_host=MOCK_IP_ADDRESS, rest_port=select_test_port()) # Ensure there is work to do remaining_work = worklock_agent.get_remaining_work(checksum_address=bidder) assert remaining_work > 0 # Do some work for i in range(3): receipt = worker.confirm_activity() assert receipt['status'] == 1 testerchain.time_travel(periods=1) command = ('refund', '--bidder-address', bidder, '--registry-filepath', agency_local_registry.filepath, '--provider', TEST_PROVIDER_URI, '--poa', '--force') user_input = f'{INSECURE_DEVELOPMENT_PASSWORD}\n' + 'Y\n' result = click_runner.invoke(worklock, command, input=user_input, catch_exceptions=False) assert result.exit_code == 0 # Less work to do... new_remaining_work = worklock_agent.get_remaining_work( checksum_address=bidder) assert new_remaining_work < remaining_work
def paint_accounts(emitter, wallet, registry): from nucypher.blockchain.eth.actors import Staker rows = list() for account in wallet.accounts: eth = str(Web3.fromWei(wallet.eth_balance(account), 'ether')) + " ETH" nu = str(NU.from_nunits(wallet.token_balance(account, registry))) staker = Staker(is_me=True, checksum_address=account, registry=registry) staker.stakes.refresh() is_staking = 'Yes' if bool(staker.stakes) else 'No' rows.append((is_staking, account, eth, nu)) headers = ('Staking', 'Account', 'ETH', 'NU') emitter.echo(tabulate.tabulate(rows, showindex=True, headers=headers, tablefmt="fancy_grid"))
def staker(testerchain, agency, test_registry, deployer_transacting_power): token_agent = ContractAgency.get_agent(NucypherTokenAgent, registry=test_registry) origin, staker_account, *everybody_else = testerchain.client.accounts staker_power = TransactingPower(account=staker_account, signer=Web3Signer(testerchain.client)) token_airdrop(token_agent=token_agent, transacting_power=deployer_transacting_power, addresses=[staker_account], amount=DEVELOPMENT_TOKEN_AIRDROP_AMOUNT) staker = Staker(domain=TEMPORARY_DOMAIN, transacting_power=staker_power, registry=test_registry) return staker
def stakers(testerchain, agency, token_economics): token_agent, _staking_agent, _policy_agent = agency blockchain = token_agent.blockchain # Mock Powerup consumption (Deployer) blockchain.transacting_power = TransactingPower( blockchain=blockchain, password=INSECURE_DEVELOPMENT_PASSWORD, account=blockchain.etherbase_account) blockchain.transacting_power.activate() token_airdrop(origin=blockchain.etherbase_account, addresses=blockchain.stakers_accounts, token_agent=token_agent, amount=DEVELOPMENT_TOKEN_AIRDROP_AMOUNT) stakers = list() for index, account in enumerate(blockchain.stakers_accounts): staker = Staker(is_me=True, checksum_address=account, blockchain=blockchain) # Mock TransactingPower consumption staker.blockchain.transacting_power = TransactingPower( blockchain=blockchain, password=INSECURE_DEVELOPMENT_PASSWORD, account=account) staker.blockchain.transacting_power.activate() min_stake, balance = token_economics.minimum_allowed_locked, staker.token_balance amount = random.randint(min_stake, balance) # for a random lock duration min_locktime, max_locktime = token_economics.minimum_locked_periods, token_economics.maximum_locked_periods periods = random.randint(min_locktime, max_locktime) staker.initialize_stake(amount=amount, lock_periods=periods) # We assume that the staker knows in advance the account of her worker worker_address = blockchain.ursula_account(index) staker.set_worker(worker_address=worker_address) stakers.append(staker) # Stake starts next period (or else signature validation will fail) blockchain.time_travel(periods=1) yield stakers
def idle_staker(testerchain, agency, test_registry): token_agent = ContractAgency.get_agent(NucypherTokenAgent, registry=test_registry) idle_staker_account = testerchain.unassigned_accounts[-2] transacting_power = TransactingPower(account=testerchain.etherbase_account, signer=Web3Signer(testerchain.client)) token_airdrop(transacting_power=transacting_power, addresses=[idle_staker_account], token_agent=token_agent, amount=DEVELOPMENT_TOKEN_AIRDROP_AMOUNT) # Prepare idle staker idle_staker = Staker(transacting_power=transacting_power, domain=TEMPORARY_DOMAIN, blockchain=testerchain) yield idle_staker
def paint_staking_accounts(emitter, signer, registry, domain): from nucypher.blockchain.eth.actors import Staker rows = list() blockchain = BlockchainInterfaceFactory.get_interface() 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))) 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)) headers = ('Staking', 'Account', 'ETH', 'NU') emitter.echo(tabulate.tabulate(rows, showindex=True, headers=headers, tablefmt="fancy_grid"))
def paint_accounts(emitter, balances, registry): from nucypher.blockchain.eth.actors import Staker rows = list() max_eth_len, max_nu_len = 0, 0 for address, balances in sorted(balances.items()): eth = str(Web3.fromWei(balances['ETH'], 'ether')) + " ETH" nu = str(NU.from_nunits(balances['NU'])) max_eth_len = max(max_eth_len, len(eth)) max_nu_len = max(max_nu_len, len(nu)) staker = Staker(is_me=True, checksum_address=address, registry=registry) staker.stakes.refresh() is_staking = 'Yes' if bool(staker.stakes) else 'No' rows.append((is_staking, address, eth, nu)) headers = ('Staking', 'Account', 'ETH', 'NU') emitter.echo(tabulate.tabulate(rows, showindex=True, headers=headers, tablefmt="fancy_grid"))
def idle_staker(testerchain, agency): token_agent, _staking_agent, _policy_agent = agency idle_staker_account = testerchain.unassigned_accounts[-2] # Mock Powerup consumption (Deployer) testerchain.transacting_power = TransactingPower(account=testerchain.etherbase_account) token_airdrop(origin=testerchain.etherbase_account, addresses=[idle_staker_account], token_agent=token_agent, amount=DEVELOPMENT_TOKEN_AIRDROP_AMOUNT) # Prepare idle staker idle_staker = Staker(is_me=True, checksum_address=idle_staker_account, blockchain=testerchain) yield idle_staker
def get_arrangement(self, arrangement_id: bytes) -> BlockchainArrangement: """Fetch published arrangements from the blockchain""" # Read from Blockchain blockchain_record = self.author.policy_agent.read().policies(arrangement_id) author_address, staker_address, rate, start_block, end_block, downtime_index = blockchain_record duration = end_block - start_block staker = Staker(address=staker_address, is_me=False) arrangement = BlockchainArrangement(alice=self.author, ursula=staker, value=rate*duration, # TODO Check the math/types here lock_periods=duration, expiration=end_block) arrangement.is_published = True return arrangement
def test_stake_bond_worker(click_runner, testerchain, agency_local_registry, manual_staker, manual_worker, stakeholder_configuration_file_location): init_args = ('stake', 'bond-worker', '--config-file', stakeholder_configuration_file_location, '--staking-address', manual_staker, '--worker-address', manual_worker, '--force') user_input = INSECURE_DEVELOPMENT_PASSWORD result = click_runner.invoke(nucypher_cli, init_args, input=user_input, catch_exceptions=False) assert result.exit_code == 0 staker = Staker(domain=TEMPORARY_DOMAIN, checksum_address=manual_staker, registry=agency_local_registry) assert staker.worker_address == manual_worker
def stakers(general_config, registry_options, staking_address, substakes): """Show relevant information about stakers.""" if substakes and not staking_address: raise click.BadOptionUsage( option_name="--substakes", message= "--substakes is only valid when used with --staking-address.") emitter, registry, blockchain = registry_options.setup( general_config=general_config) staking_agent = ContractAgency.get_agent(StakingEscrowAgent, registry=registry) stakers_list = [staking_address ] if staking_address else staking_agent.get_stakers() paint_stakers(emitter=emitter, stakers=stakers_list, registry=registry) if substakes: staker = Staker(registry=registry, domain=registry_options.network, checksum_address=staking_address) staker.stakes.refresh() paint_stakes(emitter=emitter, staker=staker, paint_unlocked=True)
def test_stake_set_worker(click_runner, testerchain, test_registry, manual_staker, manual_worker, stakeholder_configuration_file_location): init_args = ('stake', 'set-worker', '--config-file', stakeholder_configuration_file_location, '--staking-address', manual_staker, '--worker-address', manual_worker, '--no-sync', '--force') user_input = f'{INSECURE_DEVELOPMENT_PASSWORD}' result = click_runner.invoke(nucypher_cli, init_args, input=user_input, catch_exceptions=False) assert result.exit_code == 0 staker = Staker(is_me=True, checksum_address=manual_staker, registry=test_registry) assert staker.worker_address == manual_worker
def test_mint(click_runner, manual_staker, testerchain, agency_local_registry, stakeholder_configuration_file_location): testerchain.time_travel(periods=2) staker = Staker(is_me=True, checksum_address=manual_staker, registry=agency_local_registry) assert staker.mintable_periods() > 0 owned_tokens = staker.owned_tokens() mint_args = ('stake', 'mint', '--config-file', stakeholder_configuration_file_location, '--staking-address', manual_staker, '--force') result = click_runner.invoke(nucypher_cli, mint_args, input=INSECURE_DEVELOPMENT_PASSWORD, catch_exceptions=False) assert result.exit_code == 0 assert staker.owned_tokens() > owned_tokens assert staker.mintable_periods() == 0 assert SUCCESSFUL_MINTING in result.output