Implement and test nucypher stake detach-worker

pull/1163/head
David Núñez 2019-07-26 14:08:01 +02:00
parent 2a26d54e6d
commit a9f5c4a12b
2 changed files with 40 additions and 3 deletions

View File

@ -78,6 +78,7 @@ def stake(click_config,
accounts Show ETH and NU balances for stakeholder's accounts
sync Synchronize stake data with on-chain information
set-worker Bound a worker to a staker
detach-worker Detach worker currently bound to a staker
init Create a new stake
divide Create a new stake from part of an existing one
collect-reward Withdraw staking reward
@ -140,13 +141,18 @@ def stake(click_config,
emitter.echo("OK!", color='green')
return # Exit
elif action == 'set-worker':
elif action in ('set-worker', 'detach-worker'):
if not staking_address:
staking_address = select_stake(stakeholder=STAKEHOLDER, emitter=emitter).owner_address
if not worker_address:
worker_address = click.prompt("Enter worker address", type=EIP55_CHECKSUM_ADDRESS)
if action == 'set-worker':
if not worker_address:
worker_address = click.prompt("Enter worker address", type=EIP55_CHECKSUM_ADDRESS)
elif action == 'detach-worker':
if worker_address:
raise click.BadOptionUsage(message="detach-worker cannot be used together with --worker-address option")
worker_address = BlockchainInterface.NULL_ADDRESS
password = None
if not hw_wallet:

View File

@ -499,3 +499,34 @@ def test_collect_rewards_integration(click_runner,
# The burner wallet has the reward ethers
assert staker.token_agent.get_balance(address=staker_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,
'--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,
blockchain=testerchain)
assert not staker.worker_address