コード例 #1
0
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
コード例 #2
0
ファイル: ursula.py プロジェクト: vepkenez/nucypher
def make_ursula_for_staker(staker: Staker,
                           worker_address: str,
                           blockchain: BlockchainInterface,
                           ursula_config: UrsulaConfiguration,
                           ursulas_to_learn_about: Optional[
                               List[Ursula]] = None,
                           confirm_activity: bool = False,
                           **ursula_overrides) -> Ursula:

    # Assign worker to this staker
    staker.set_worker(worker_address=worker_address)

    worker = make_decentralized_ursulas(
        ursula_config=ursula_config,
        blockchain=blockchain,
        stakers_addresses=[staker.checksum_address],
        workers_addresses=[worker_address],
        confirm_activity=confirm_activity,
        **ursula_overrides).pop()

    for ursula_to_learn_about in (ursulas_to_learn_about or []):
        worker.remember_node(ursula_to_learn_about)
        ursula_to_learn_about.remember_node(worker)

    return worker
コード例 #3
0
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
コード例 #4
0
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
コード例 #5
0
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
コード例 #6
0
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
コード例 #7
0
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
コード例 #8
0
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
コード例 #9
0
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
コード例 #10
0
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
コード例 #11
0
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
コード例 #12
0
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
コード例 #13
0
def select_stake(staker: Staker,
                 emitter: StdoutEmitter,
                 stakes_status: Stake.Status = Stake.Status.EDITABLE,
                 filter_function: Callable[[Stake], bool] = None) -> Stake:
    """Interactively select a stake or abort if there are no eligible stakes."""

    if stakes_status.is_child(Stake.Status.DIVISIBLE):
        emitter.echo(ONLY_DISPLAYING_DIVISIBLE_STAKES_NOTE, color='yellow')

    # Filter stakes by status
    stakes = staker.sorted_stakes(parent_status=stakes_status,
                                  filter_function=filter_function)
    if not stakes:
        emitter.echo(NO_STAKES_FOUND, color='red')
        raise click.Abort

    # Interactive Selection
    paint_unlocked = stakes_status.is_child(Stake.Status.UNLOCKED)
    paint_stakes(staker=staker,
                 emitter=emitter,
                 stakes=stakes,
                 paint_unlocked=paint_unlocked)
    indexed_stakes = {stake.index: stake for stake in stakes}
    indices = [str(index) for index in indexed_stakes.keys()]
    choice = click.prompt(SELECT_STAKE, type=click.Choice(indices))
    chosen_stake = indexed_stakes[int(choice)]
    return chosen_stake
コード例 #14
0
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
コード例 #15
0
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
コード例 #16
0
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)
コード例 #17
0
ファイル: test_staker.py プロジェクト: vepkenez/nucypher
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
コード例 #18
0
ファイル: staking.py プロジェクト: federico9256/nucypher
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"))
コード例 #19
0
def paint_staking_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.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"))
コード例 #20
0
ファイル: test_felix.py プロジェクト: pranav-singhal/nucypher
    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
コード例 #21
0
    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
コード例 #22
0
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)
コード例 #23
0
ファイル: conftest.py プロジェクト: piotr-roslaniec/nucypher
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
コード例 #24
0
ファイル: fixtures.py プロジェクト: piotr-roslaniec/nucypher
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
コード例 #25
0
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
コード例 #26
0
ファイル: fixtures.py プロジェクト: arjunhassard/nucypher
def stakers(testerchain, agency, token_economics, test_registry):
    token_agent, _staking_agent, _policy_agent = agency
    blockchain = token_agent.blockchain

    # Mock Powerup consumption (Deployer)
    blockchain.transacting_power = TransactingPower(
        password=INSECURE_DEVELOPMENT_PASSWORD,
        signer=Web3Signer(client=testerchain.client),
        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,
                        registry=test_registry)

        # Mock TransactingPower consumption
        staker.transacting_power = TransactingPower(
            password=INSECURE_DEVELOPMENT_PASSWORD,
            signer=Web3Signer(client=testerchain.client),
            account=account)
        staker.transacting_power.activate()

        amount = MIN_STAKE_FOR_TESTS + random.randrange(BONUS_TOKENS_FOR_TESTS)

        # for a random lock duration
        min_locktime, max_locktime = token_economics.minimum_locked_periods, token_economics.maximum_rewarded_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.bond_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
コード例 #27
0
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"))
コード例 #28
0
ファイル: policies.py プロジェクト: awesome-security/nucypher
    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
コード例 #29
0
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
コード例 #30
0
ファイル: status.py プロジェクト: piotr-roslaniec/nucypher
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)