コード例 #1
0
ファイル: test_cli.py プロジェクト: noandrea/aepp-sdk-python
def test_cli_name_auction(chain_fixture, tempdir):
    if chain_fixture.NODE_CLI.get_consensus_protocol_version(
    ) < identifiers.PROTOCOL_LIMA:
        pytest.skip("name auction is only supported after Lima HF")
        return
    node_cli = chain_fixture.NODE_CLI
    account_alice_path = _account_path(tempdir, chain_fixture.ALICE)
    account_bob_path = _account_path(tempdir, chain_fixture.BOB)
    # get a domain that is under auction scheme
    domain = random_domain(
        length=9,
        tld='chain' if chain_fixture.NODE_CLI.get_consensus_protocol_version()
        >= identifiers.PROTOCOL_LIMA else 'test')
    # let alice preclaim a name
    j = call_aecli('name', 'pre-claim', '--password', 'aeternity_bc',
                   account_alice_path, domain, '--wait')
    # retrieve the salt and the transaction hash
    salt = j.get("metadata", {}).get("salt")
    preclaim_hash = j.get("hash")
    # test that they are what we expect to be
    assert (isinstance(salt, int))
    assert (salt > 0)
    assert (utils.is_valid_hash(preclaim_hash, identifiers.TRANSACTION_HASH))
    # wait for confirmation
    chain_fixture.NODE_CLI.wait_for_confirmation(preclaim_hash)
    # now run the claim
    j = call_aecli('name', 'claim', account_alice_path, domain, '--password',
                   'aeternity_bc', '--name-salt', f"{salt}",
                   '--preclaim-tx-hash', preclaim_hash, '--wait')
    assert (utils.is_valid_hash(j.get("hash"), identifiers.TRANSACTION_HASH))
    # check that the tx was mined
    claim_height = chain_fixture.NODE_CLI.get_transaction_by_hash(
        hash=j.get('hash')).block_height
    assert (isinstance(claim_height, int) and claim_height > 0)
    # now we have a first claim
    # this is the name fee and the end block
    name_fee = AEName.compute_bid_fee(domain)
    aucion_end = AEName.compute_auction_end_block(domain, claim_height)
    print(
        f"Name {domain}, name_fee {name_fee}, claim height: {claim_height}, auction_end: {aucion_end}"
    )
    # now make another bid
    # first compute the new name fee
    name_fee = AEName.compute_bid_fee(domain, name_fee)
    j = call_aecli('name', 'bid', account_bob_path, domain, f'{name_fee}',
                   '--password', 'aeternity_bc', '--wait')
    assert (utils.is_valid_hash(j.get("hash"), identifiers.TRANSACTION_HASH))
    # check that the tx was mined
    claim_height = chain_fixture.NODE_CLI.get_transaction_by_hash(
        hash=j.get('hash')).block_height
    assert (isinstance(claim_height, int) and claim_height > 0)
    aucion_end = AEName.compute_auction_end_block(domain, claim_height)
    print(
        f"Name {domain}, name_fee {name_fee}, claim height: {claim_height}, auction_end: {aucion_end}"
    )
    name = chain_fixture.NODE_CLI.AEName(domain)
    # name should still be available
    assert (name.is_available())
コード例 #2
0
ファイル: test_aens.py プロジェクト: noandrea/aepp-sdk-python
def test_name_auction(chain_fixture):
    if chain_fixture.NODE_CLI.get_consensus_protocol_version() < PROTOCOL_LIMA:
        skip("name auction is only supported after Lima HF")
        return
    try:
        domain = random_domain(length=12)
        node_cli = chain_fixture.NODE_CLI
        name = node_cli.AEName(domain)
        assert name.status == AEName.Status.UNKNOWN
        name.update_status()
        assert name.status == AEName.Status.AVAILABLE
        preclaim = name.preclaim(chain_fixture.ALICE)
        assert name.status == AEName.Status.PRECLAIMED
        node_cli.wait_for_confirmation(preclaim.hash)
        claim_tx = name.claim(preclaim.hash, chain_fixture.ALICE,
                              preclaim.metadata.salt)
        print(claim_tx)
        assert name.status == AEName.Status.CLAIMED
        # bob will make another bid
        name2 = node_cli.AEName(domain)
        bid = AEName.compute_bid_fee(domain)
        bid_tx = name2.bid(chain_fixture.BOB, bid)
        print("BID TX", bid_tx)
        # get the tx height
        bid_h = node_cli.wait_for_transaction(bid_tx.hash)
        print(f"BOB BID Height is  {bid_h}")
        # now we should wait to see that bob gets the name
        bid_ends = AEName.compute_auction_end_block(domain, bid_h)
        #
        print(f"BID STARTED AT {bid_h} WILL END AT {bid_ends}")
    except Exception as e:
        print(e)
        assert e is None