Beispiel #1
0
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
Beispiel #2
0
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())
Beispiel #3
0
def inspect_name(domain):
    try:
        name = AEName(domain, client=_epoch_cli())
        name.update_status()
        info = [('Status', name.status)]
        if len(name.pointers) > 0:
            info.append(('Pointers', name.pointers))
            info.append(('TTL', name.name_ttl))
        _pp(info)
    except Exception as e:
        print(e)
def name_revoke(ctx):
    # retrieve the domain from the context
    domain = ctx.obj.get(CTX_AET_DOMAIN)
    # retrieve the keypair
    kp, _ = _keypair()
    name = AEName(domain)
    name.update_status()
    if name.status == AEName.Status.AVAILABLE:
        print("Domain is available, nothing to revoke")
        exit(0)
    tx = name.revoke(kp)
    _pp([('Transaction hash', tx.tx_hash)],
        title=f"Name {domain} status {name.status}")
def inspect_name(domain):
    try:
        name = AEName(domain, client=_epoch_cli())
        name.update_status()
        _pp([
            ('Status', name.status),
            ('Name hash', name.name_hash),
            ('Pointers', name.pointers),
            ('TTL', name.name_ttl),
        ])

    except Exception as e:
        print(e)
def test_name_update():
    client = EpochClient()
    # claim a domain
    domain = random_domain()
    name = AEName(domain)
    name.full_claim_blocking(keypair)
    client.wait_for_next_block()
    client.wait_for_next_block()
    assert not AEName(domain).is_available(), 'The name should be claimed now'
    name.update_status()
    transaction = name.update(keypair, target=client.get_pubkey())
    client.wait_for_next_block()
    name.update_status()
    assert name.pointers != [], 'Pointers should not be empty'
    assert name.pointers['account_pubkey'] == client.get_pubkey()
def name_update(ctx, address, name_ttl, ttl):
    """
    Update a name pointer
    """
    # retrieve the domain from the context
    domain = ctx.obj.get(CTX_AET_DOMAIN)
    # retrieve the keypair
    kp, _ = _keypair()
    name = AEName(domain)
    name.update_status()
    if name.status != AEName.Status.CLAIMED:
        print(f"Domain is {name.status} and cannot be transferred")
        exit(0)
    tx = name.update(kp, target=address, name_ttl=name_ttl, tx_ttl=ttl)
    _pp([('Transaction hash', tx.tx_hash)],
        title=f"Name {domain} status {name.status}")
def name_transfer(ctx, address):
    """
    Transfer a name to another account
    """
    # retrieve the domain from the context
    domain = ctx.obj.get(CTX_AET_DOMAIN)
    # retrieve the keypair
    kp, _ = _keypair()
    name = AEName(domain)
    name.update_status()
    if name.status != AEName.Status.CLAIMED:
        print(f"Domain is {name.status} and cannot be transferred")
        exit(0)
    tx = name.transfer_ownership(kp, address)
    _pp([('Transaction hash', tx.tx_hash)],
        title=f"Name {domain} status {name.status}")
def test_name_claim_lifecycle():
    domain = random_domain()
    name = AEName(domain)
    assert name.status == AEName.Status.UNKNOWN
    name.update_status()
    assert name.status == AEName.Status.AVAILABLE
    name.preclaim(keypair)
    assert name.status == AEName.Status.PRECLAIMED
    name.claim_blocking(keypair)
    assert name.status == AEName.Status.CLAIMED
def name_register(ctx, name_ttl, ttl):
    try:
        # retrieve the domain from the context
        domain = ctx.obj.get(CTX_AET_DOMAIN)
        # retrieve the keypair
        kp, _ = _keypair()
        name = AEName(domain, client=_epoch_cli())
        name.update_status()
        if name.status != AEName.Status.AVAILABLE:
            print("Domain not available")
            exit(0)
        tx = name.full_claim_blocking(kp, name_ttl=name_ttl, tx_ttl=ttl)
        _pp([
            ("Transaction hash", tx.tx_hash),
        ],
            title=f"Name {domain} claimed")
    except Exception as e:
        _ppe(e)
def test_revocation():
    domain = random_domain()
    name = AEName(domain)
    name.full_claim_blocking(keypair)
    EpochClient().wait_for_next_block()
    name.revoke()
    assert name.status == AEName.Status.REVOKED
    EpochClient().wait_for_next_block()
    assert AEName(domain).is_available()
def test_name_status_unavailable():
    # claim a domain
    domain = random_domain()
    occupy_name = AEName(domain)
    occupy_name.full_claim_blocking(keypair)
    # wait for the state to propagate in the block chain
    EpochClient().wait_for_next_block()
    same_name = AEName(domain)
    assert not same_name.is_available()
def test_name_update():
    client = EpochClient()
    # claim a domain
    domain = random_domain()
    print(f"domain is {domain}")
    name = AEName(domain)
    print("Claim name ", domain)
    name.full_claim_blocking(keypair, name_ttl=70)
    print("got next block")
    client.wait_n_blocks(2)
    print("got next block")
    assert not AEName(domain).is_available(), 'The name should be claimed now'
    name.update_status()
    client.wait_n_blocks(2)
    name.update_status()
    print("claimed name", name)
    assert name.pointers != [], 'Pointers should not be empty'
    assert name.pointers['account_pubkey'] == keypair.get_address()
Beispiel #14
0
def name_register(ctx, name_ttl):
    # retrieve the domain from the context
    domain = ctx.obj.get(CTX_AET_DOMAIN)
    # retrieve the keypair
    kp, _ = _keypair()
    name = AEName(domain)
    name.update_status()
    if name.status != AEName.Status.AVAILABLE:
        print("Domain not available")
        exit(0)
    name.full_claim_blocking(kp, name_ttl=name_ttl)
    print(f"Name {domain} claimed")
    pass
def test_committment():
    domain = random_domain()
    name = AEName(domain)
    cl = name._get_commitment_hash()
    cr = name.client.cli.get_commitment_hash(name=name.domain, salt=name.preclaim_salt)
    assert cl == cr.commitment
def test_transfer_ownership():
    client = EpochClient()
    name = AEName(random_domain())
    name.full_claim_blocking(keypair)
    assert name.status == AEName.Status.CLAIMED
    client.wait_for_next_block()

    new_key_pair = KeyPair.generate()
    # put some coins into the account so the account is in the state tree
    # otherwise it couldn't become the owner of an address.
    client.spend(keypair, new_key_pair.get_address(), 1)
    client.wait_for_next_block()
    # now transfer the name to the other account
    name.transfer_ownership(keypair, new_key_pair.get_address())
    assert name.status == AEName.Status.TRANSFERRED
    client.wait_for_next_block()
    # try changing the target using that new keypair
    name.update_status()
    name.update(new_key_pair, target=keypair.get_address())
    client.wait_for_next_block()
    name.update_status()
    assert name.pointers != [], 'Pointers should not be empty'
    assert name.pointers['account_pubkey'] == new_key_pair.get_address()
def test_name_validation_fails():
    with raises(ValueError):
        AEName('test.lol')
def test_name_validation_succeeds():
    AEName('test.aet')
from aeternity.aens import AEName
from aeternity.config import Config

Config.set_defaults(
    Config(external_host=3013, internal_host=3113, websocket_host=3114))

name = AEName('foobar.aet')
if name.is_available():
    name.preclaim()
    name.claim_blocking()
    name.update(target='ak$deadbeef')
def test_name_hashing():
    assert AEName.calculate_name_hash(
        'welghmolql.aet'
    ) == 'nm$2KrC4asc6fdv82uhXDwfiqB1TY2htjhnzwzJJKLxidyMymJRUQ'
def test_name_status_availavle():
    name = AEName(random_domain())
    assert name.status == AEName.Status.UNKNOWN
    name.update_status()
    assert name.status == AEName.Status.AVAILABLE
def test_name_is_available():
    name = AEName(random_domain())
    assert name.is_available()