コード例 #1
0
def test_bidding(testerchain, agency, token_economics, test_registry):
    min_allowed_bid = token_economics.worklock_min_allowed_bid
    max_bid = 2000 * min_allowed_bid
    small_bids = [
        random.randrange(min_allowed_bid, 2 * min_allowed_bid)
        for _ in range(10)
    ]
    total_small_bids = sum(small_bids)
    min_potential_whale_bid = (max_bid - total_small_bids) // 9
    whales_bids = [
        random.randrange(min_potential_whale_bid, max_bid) for _ in range(9)
    ]
    initial_bids = small_bids + whales_bids

    for i, bid in enumerate(initial_bids):
        bidder_address = testerchain.client.accounts[i]
        tpower = TransactingPower(account=bidder_address,
                                  signer=Web3Signer(testerchain.client))
        bidder = Bidder(registry=test_registry,
                        domain=TEMPORARY_DOMAIN,
                        transacting_power=tpower)

        assert bidder.get_deposited_eth == 0
        receipt = bidder.place_bid(value=bid)
        assert receipt['status'] == 1
        assert bidder.get_deposited_eth == bid
コード例 #2
0
ファイル: test_bidder.py プロジェクト: y3v63n/nucypher
def test_claim(testerchain, agency, token_economics, test_registry):
    bidder_address = testerchain.client.accounts[11]
    bidder = Bidder(checksum_address=bidder_address, registry=test_registry)
    staking_agent = ContractAgency.get_agent(StakingEscrowAgent,
                                             registry=test_registry)
    worklock_agent = ContractAgency.get_agent(WorkLockAgent,
                                              registry=test_registry)

    # Ensure that the bidder is not staking.
    locked_tokens = staking_agent.get_locked_tokens(
        staker_address=bidder.checksum_address, periods=10)
    assert locked_tokens == 0

    receipt = bidder.claim()
    assert receipt['status'] == 1

    # Cant claim more than once
    with pytest.raises(Bidder.ClaimError):
        _receipt = bidder.claim()

    assert bidder.get_deposited_eth > token_economics.worklock_min_allowed_bid
    assert bidder.completed_work == 0
    assert bidder.remaining_work <= token_economics.maximum_allowed_locked // 2
    assert bidder.refunded_work == 0

    # Ensure that the claimant is now the holder of an unbonded stake.
    locked_tokens = staking_agent.get_locked_tokens(
        staker_address=bidder.checksum_address, periods=10)
    assert locked_tokens <= token_economics.maximum_allowed_locked

    # Confirm the stake is unbonded
    worker_address = staking_agent.get_worker_from_staker(
        staker_address=bidder.checksum_address)
    assert worker_address == NULL_ADDRESS
コード例 #3
0
ファイル: test_bidder.py プロジェクト: renaynay/nucypher
def test_claim(testerchain, agency, token_economics, test_registry):
    bidder_address = testerchain.unassigned_accounts[0]
    bidder = Bidder(checksum_address=bidder_address, registry=test_registry)
    with pytest.raises(Bidder.BiddingIsOpen):
        _receipt = bidder.claim()

    # Wait until the bidding window closes...
    testerchain.time_travel(seconds=token_economics.bidding_duration+1)
    staking_agent = ContractAgency.get_agent(StakingEscrowAgent, registry=test_registry)

    # Ensure that the bidder is not staking.
    locked_tokens = staking_agent.get_locked_tokens(staker_address=bidder.checksum_address, periods=10)
    assert locked_tokens == 0

    receipt = bidder.claim()
    assert receipt['status'] == 1

    # Cant claim more than once
    with pytest.raises(Bidder.BidderError):
        _receipt = bidder.claim()

    assert bidder.get_deposited_eth == 40000000000000000000000
    assert bidder.completed_work == 0
    assert bidder.remaining_work == 500000000000000000000000
    assert bidder.refunded_work == 0

    # Ensure that the claimant is now the holder of an unbonded stake.
    locked_tokens = staking_agent.get_locked_tokens(staker_address=bidder.checksum_address, periods=10)
    assert locked_tokens == 1000000000000000000000000

    # Confirm the stake is unbonded
    worker_address = staking_agent.get_worker_from_staker(staker_address=bidder.checksum_address)
    assert worker_address == BlockchainInterface.NULL_ADDRESS
コード例 #4
0
ファイル: test_bidder.py プロジェクト: datanetworks/nucypher
def test_withdraw_compensation(testerchain, agency, token_economics, test_registry):
    bidder_address = testerchain.client.accounts[12]
    bidder = Bidder(checksum_address=bidder_address, registry=test_registry, signer=Web3Signer(testerchain.client))
    worklock_agent = ContractAgency.get_agent(WorkLockAgent, registry=test_registry)

    assert worklock_agent.get_available_compensation(checksum_address=bidder_address) > 0
    receipt = bidder.withdraw_compensation()
    assert receipt['status'] == 1
    assert worklock_agent.get_available_compensation(checksum_address=bidder_address) == 0
コード例 #5
0
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(registry=test_registry,
                    transacting_power=tpower,
                    domain=TEMPORARY_DOMAIN)
    whales = bidder.get_whales()

    # Simulate force refund
    new_whales = whales.copy()
    while new_whales:
        whales.update(new_whales)
        whales = bidder._reduce_bids(whales)
        new_whales = bidder.get_whales()

    bidder_address = testerchain.client.accounts[1]
    tpower = TransactingPower(account=bidder_address,
                              signer=Web3Signer(testerchain.client))
    bidder = Bidder(registry=test_registry,
                    transacting_power=tpower,
                    domain=TEMPORARY_DOMAIN)
    worklock_agent = ContractAgency.get_agent(WorkLockAgent,
                                              registry=test_registry)

    receipt = bidder.force_refund()
    assert receipt['status'] == 1
    assert not bidder.get_whales()
    assert not worklock_agent.bidders_checked()

    # Compare off-chain and on-chain calculations
    min_bid = token_economics.worklock_min_allowed_bid
    for whale, bonus in whales.items():
        contract_bid = worklock_agent.get_deposited_eth(whale)
        assert bonus == contract_bid - min_bid
コード例 #6
0
ファイル: test_bidder.py プロジェクト: renaynay/nucypher
def test_cancel_bid(testerchain, agency, token_economics, test_registry):
    bidder_address = testerchain.unassigned_accounts[1]
    bidder = Bidder(checksum_address=bidder_address, registry=test_registry)
    assert bidder.get_deposited_eth        # Bid
    receipt = bidder.cancel_bid()    # Cancel
    assert receipt['status'] == 1
    assert not bidder.get_deposited_eth    # No more bid

    # Can't cancel a bid twice in a row
    with pytest.raises((TransactionFailed, ValueError)):
        _receipt = bidder.cancel_bid()
コード例 #7
0
ファイル: test_bidder.py プロジェクト: y3v63n/nucypher
def test_cancel_bid(testerchain, agency, token_economics, test_registry):
    # Wait until the bidding window closes...
    testerchain.time_travel(seconds=token_economics.bidding_duration + 1)

    bidder_address = testerchain.client.accounts[1]
    bidder = Bidder(checksum_address=bidder_address, registry=test_registry)
    assert bidder.get_deposited_eth  # Bid
    receipt = bidder.cancel_bid()  # Cancel
    assert receipt['status'] == 1
    assert not bidder.get_deposited_eth  # No more bid

    # Can't cancel a bid twice in a row
    with pytest.raises((TransactionFailed, ValueError)):
        _receipt = bidder.cancel_bid()
コード例 #8
0
ファイル: test_bidder.py プロジェクト: datanetworks/nucypher
def test_verify_correctness(testerchain, agency, token_economics, test_registry):
    bidder_address = testerchain.client.accounts[0]
    bidder = Bidder(checksum_address=bidder_address, registry=test_registry, signer=Web3Signer(testerchain.client))
    worklock_agent = ContractAgency.get_agent(WorkLockAgent, registry=test_registry)

    assert not worklock_agent.bidders_checked()
    with pytest.raises(Bidder.ClaimError):
        _receipt = bidder.claim()

    receipts = bidder.verify_bidding_correctness(gas_limit=100000)
    assert worklock_agent.bidders_checked()
    assert worklock_agent.is_claiming_available()
    for iteration, receipt in receipts.items():
        assert receipt['status'] == 1
コード例 #9
0
ファイル: test_bidder.py プロジェクト: datanetworks/nucypher
def test_verify_correctness_before_refund(testerchain, agency, token_economics, test_registry):
    bidder_address = testerchain.client.accounts[0]
    bidder = Bidder(checksum_address=bidder_address, registry=test_registry, signer=Web3Signer(testerchain.client))
    worklock_agent = ContractAgency.get_agent(WorkLockAgent, registry=test_registry)

    with pytest.raises(Bidder.CancellationWindowIsOpen):
        _receipt = bidder.claim()

    # Wait until the cancellation window closes...
    testerchain.time_travel(seconds=token_economics.cancellation_window_duration+1)

    with pytest.raises(Bidder.BidderError):
        _receipt = bidder.verify_bidding_correctness(gas_limit=100000)
    assert not worklock_agent.bidders_checked()
    assert bidder.get_whales()
    assert not worklock_agent.is_claiming_available()
コード例 #10
0
def test_participant_status(click_runner, testerchain, agency_local_registry,
                            token_economics):

    tpower = TransactingPower(account=testerchain.client.accounts[2],
                              signer=Web3Signer(testerchain.client))
    bidder = Bidder(transacting_power=tpower,
                    domain=TEMPORARY_DOMAIN,
                    registry=agency_local_registry)

    command = ('status', '--registry-filepath', agency_local_registry.filepath,
               '--participant-address', bidder.checksum_address, '--provider',
               TEST_PROVIDER_URI, '--signer', TEST_PROVIDER_URI, '--network',
               TEMPORARY_DOMAIN)

    result = click_runner.invoke(worklock, command, catch_exceptions=False)
    assert result.exit_code == 0

    # Bidder-specific data is displayed
    assert bidder.checksum_address in result.output
    assert str(bidder.remaining_work) in result.output
    assert str(bidder.available_refund) in result.output

    # Worklock economics are displayed
    assert str(token_economics.worklock_boosting_refund_rate) in result.output
    assert str(NU.from_nunits(
        token_economics.worklock_supply)) in result.output
コード例 #11
0
    def __create_bidder(self,
                        registry,
                        domain: str,
                        transacting: bool = True,
                        hw_wallet: bool = False,
                        ) -> Bidder:

        is_clef = ClefSigner.is_valid_clef_uri(self.signer_uri)
        testnet = self.network != NetworksInventory.MAINNET
        signer = Signer.from_signer_uri(self.signer_uri, testnet=testnet) if self.signer_uri else None
        password_required = (not is_clef and not hw_wallet)
        if signer and transacting and password_required:
            client_password = get_client_password(checksum_address=self.bidder_address)
            signer.unlock_account(account=self.bidder_address, password=client_password)

        transacting_power = None
        if transacting:
            transacting_power = TransactingPower(account=self.bidder_address, signer=signer)
            transacting_power.unlock(password=client_password)

        bidder = Bidder(registry=registry,
                        transacting_power=transacting_power,
                        checksum_address=self.bidder_address if not transacting_power else None,
                        domain=domain)
        return bidder
コード例 #12
0
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(registry=test_registry,
                    transacting_power=tpower,
                    domain=TEMPORARY_DOMAIN)
    worklock_agent = ContractAgency.get_agent(WorkLockAgent,
                                              registry=test_registry)

    assert worklock_agent.get_available_compensation(
        checksum_address=bidder_address) > 0
    receipt = bidder.withdraw_compensation()
    assert receipt['status'] == 1
    assert worklock_agent.get_available_compensation(
        checksum_address=bidder_address) == 0
コード例 #13
0
def test_cancel_bid(testerchain, agency, token_economics, test_registry):
    # Wait until the bidding window closes...
    testerchain.time_travel(seconds=token_economics.bidding_duration + 1)

    bidder_address = testerchain.client.accounts[1]
    tpower = TransactingPower(account=bidder_address,
                              signer=Web3Signer(testerchain.client))
    bidder = Bidder(registry=test_registry,
                    transacting_power=tpower,
                    domain=TEMPORARY_DOMAIN)
    assert bidder.get_deposited_eth  # Bid
    receipt = bidder.cancel_bid()  # Cancel
    assert receipt['status'] == 1
    assert not bidder.get_deposited_eth  # No more bid

    # Can't cancel a bid twice in a row
    with pytest.raises((TransactionFailed, ValueError)):
        _receipt = bidder.cancel_bid()
コード例 #14
0
ファイル: test_bidder.py プロジェクト: renaynay/nucypher
def test_create_bidder(testerchain, test_registry, agency, token_economics):
    bidder_address = testerchain.unassigned_accounts[0]
    bidder = Bidder(checksum_address=bidder_address, registry=test_registry)
    assert bidder.checksum_address == bidder_address
    assert bidder.registry == test_registry

    assert not bidder.get_deposited_eth
    assert not bidder.completed_work
    assert not bidder.remaining_work
    assert not bidder.refunded_work
コード例 #15
0
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(registry=test_registry,
                    transacting_power=tpower,
                    domain=TEMPORARY_DOMAIN)
    remaining = bidder.remaining_work
    assert remaining
コード例 #16
0
ファイル: worklock.py プロジェクト: renaynay/nucypher
 def __create_bidder(self,
                     registry,
                     transacting: bool = False,
                     hw_wallet: bool = False):
     client_password = None
     if transacting and not hw_wallet:
         client_password = get_client_password(
             checksum_address=self.bidder_address)
     bidder = Bidder(checksum_address=self.bidder_address,
                     registry=registry,
                     client_password=client_password,
                     is_transacting=transacting)
     return bidder
コード例 #17
0
ファイル: test_bidder.py プロジェクト: y3v63n/nucypher
def test_bidding(testerchain, agency, token_economics, test_registry):
    min_allowed_bid = token_economics.worklock_min_allowed_bid
    max_bid = 2000 * min_allowed_bid
    small_bids = [
        random.randrange(min_allowed_bid, 2 * min_allowed_bid)
        for _ in range(10)
    ]
    total_small_bids = sum(small_bids)
    min_potential_whale_bid = (max_bid - total_small_bids) // 9
    whales_bids = [
        random.randrange(min_potential_whale_bid, max_bid) for _ in range(9)
    ]
    initial_bids = small_bids + whales_bids

    for i, bid in enumerate(initial_bids):
        bidder_address = testerchain.client.accounts[i]
        bidder = Bidder(checksum_address=bidder_address,
                        registry=test_registry)

        assert bidder.get_deposited_eth == 0
        receipt = bidder.place_bid(value=bid)
        assert receipt['status'] == 1
        assert bidder.get_deposited_eth == bid
コード例 #18
0
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(domain=TEMPORARY_DOMAIN,
                    registry=test_registry,
                    transacting_power=tpower)
    assert bidder.checksum_address == bidder_address
    assert bidder.registry == test_registry

    assert not bidder.get_deposited_eth
    assert not bidder.completed_work
    assert not bidder.remaining_work
    assert not bidder.refunded_work
コード例 #19
0
 def __create_bidder(self,
                     registry,
                     signer: Optional[Signer] = None,
                     transacting: bool = True,
                     hw_wallet: bool = False):
     client_password = None
     if transacting and not signer and not hw_wallet:
         client_password = get_client_password(checksum_address=self.bidder_address)
     bidder = Bidder(checksum_address=self.bidder_address,
                     registry=registry,
                     client_password=client_password,
                     signer=signer,
                     transacting=transacting)
     return bidder
コード例 #20
0
    def __create_bidder(self,
                        registry,
                        transacting: bool = True,
                        hw_wallet: bool = False) -> Bidder:

        client_password = None
        is_clef = ClefSigner.is_valid_clef_uri(self.signer_uri)
        if transacting and not is_clef and not hw_wallet:
            client_password = get_client_password(checksum_address=self.bidder_address)
        signer = Signer.from_signer_uri(self.signer_uri) if self.signer_uri else None
        bidder = Bidder(checksum_address=self.bidder_address,
                        registry=registry,
                        client_password=client_password,
                        signer=signer,
                        transacting=transacting)
        return bidder
コード例 #21
0
ファイル: test_bidder.py プロジェクト: renaynay/nucypher
def test_bidding(testerchain, agency, token_economics, test_registry):
    bidder_address = testerchain.unassigned_accounts[0]
    big_bid = token_economics.maximum_allowed_locked // 100
    bidder = Bidder(checksum_address=bidder_address, registry=test_registry)

    assert bidder.get_deposited_eth == 0
    receipt = bidder.place_bid(value=big_bid)
    assert receipt['status'] == 1
    assert bidder.get_deposited_eth == big_bid

    another_bidder_address = testerchain.unassigned_accounts[1]
    another_bid = token_economics.maximum_allowed_locked // 50
    another_bidder = Bidder(checksum_address=another_bidder_address, registry=test_registry)
    assert another_bidder.get_deposited_eth == 0
    receipt = another_bidder.place_bid(value=another_bid)
    assert receipt['status'] == 1
    assert another_bidder.get_deposited_eth == another_bid
コード例 #22
0
def test_participant_status(click_runner, testerchain, agency_local_registry,
                            token_economics):
    bidder = Bidder(checksum_address=testerchain.unassigned_accounts[1],
                    registry=agency_local_registry)

    command = ('status', '--registry-filepath', agency_local_registry.filepath,
               '--bidder-address', bidder.checksum_address, '--provider',
               TEST_PROVIDER_URI, '--poa')

    result = click_runner.invoke(worklock, command, catch_exceptions=False)
    assert result.exit_code == 0

    worklock_agent = ContractAgency.get_agent(WorkLockAgent,
                                              registry=agency_local_registry)

    # Bidder-specific data is displayed
    assert bidder.checksum_address in result.output
    assert str(bidder.remaining_work) in result.output
    assert str(bidder.available_refund) in result.output

    # Worklock economics are displayed
    assert str(token_economics.worklock_boosting_refund_rate) in result.output
    assert str(token_economics.worklock_supply) in result.output
コード例 #23
0
ファイル: test_bidder.py プロジェクト: datanetworks/nucypher
def test_get_remaining_work(testerchain, agency, token_economics, test_registry):
    bidder_address = testerchain.client.accounts[0]
    bidder = Bidder(checksum_address=bidder_address, registry=test_registry, signer=Web3Signer(testerchain.client))
    remaining = bidder.remaining_work
    assert remaining
コード例 #24
0
def surrogate_bidder(mock_testerchain, test_registry, mock_worklock_agent,
                     surrogate_transacting_power):
    bidder = Bidder(registry=test_registry,
                    transacting_power=surrogate_transacting_power,
                    domain=TEMPORARY_DOMAIN)
    return bidder
コード例 #25
0
 def create_bidder(self, registry):
     bidder = Bidder(checksum_address=self.bidder_address, registry=registry)
     return bidder
コード例 #26
0
ファイル: test_bidder.py プロジェクト: renaynay/nucypher
def test_get_remaining_work(testerchain, agency, token_economics, test_registry):
    bidder_address = testerchain.unassigned_accounts[0]
    bidder = Bidder(checksum_address=bidder_address, registry=test_registry)
    remaining = bidder.remaining_work
    assert remaining
コード例 #27
0
def surrogate_bidder(mock_testerchain, test_registry, mock_worklock_agent):
    address = mock_testerchain.etherbase_account
    signer = Web3Signer(mock_testerchain.client)
    bidder = Bidder(checksum_address=address, registry=test_registry, signer=signer)
    return bidder