def test_refund(click_runner, mocker, mock_worklock_agent, surrogate_bidder): # Spy on the corresponding CLI function we are testing mock_refund = mocker.spy(Bidder, 'refund_deposit') bidder_address = surrogate_bidder.checksum_address command = ('refund', '--participant-address', bidder_address, '--provider', MOCK_PROVIDER_URI, '--signer', MOCK_PROVIDER_URI, '--network', TEMPORARY_DOMAIN) user_input = INSECURE_DEVELOPMENT_PASSWORD + '\n' + YES result = click_runner.invoke(worklock, command, input=user_input, catch_exceptions=False) assert result.exit_code == 0 # Output assert CONFIRM_COLLECT_WORKLOCK_REFUND.format(bidder_address=bidder_address) in result.output # Bidder mock_refund.assert_called_once() assert_successful_transaction_echo(bidder_address=bidder_address, cli_output=result.output) # Transactions mock_worklock_agent.assert_only_transactions(allowed=[mock_worklock_agent.refund]) mock_worklock_agent.refund.assert_called_with(checksum_address=bidder_address)
def refund(general_config: GroupGeneralConfig, worklock_options: WorkLockOptions, force: bool, hw_wallet: bool): """Reclaim ETH unlocked by your work""" emitter, registry, blockchain = worklock_options.setup(general_config=general_config) bidder_address = worklock_options.get_bidder_address(emitter, registry) bidder = worklock_options.create_bidder(registry=registry, hw_wallet=hw_wallet) if not force: click.confirm(CONFIRM_COLLECT_WORKLOCK_REFUND.format(bidder_address=bidder_address), abort=True) emitter.echo(SUBMITTING_WORKLOCK_REFUND_REQUEST) receipt = bidder.refund_deposit() paint_receipt_summary(receipt=receipt, emitter=emitter, chain_name=bidder.staking_agent.blockchain.client.chain_name)