Exemple #1
0
def test_hashing_committment_id(client_fixture, random_domain):
    name, salt = "aeternity.test", 10692426485854419779
    expected_committment = "cm_2by2qwnum96Z78WSFRJwhsC5qFzDgatrKk7PfH3yZ2wMBmsZF2"
    cid, salt = hashing.commitment_id(name, salt)
    assert expected_committment == cid

    domain = random_domain
    cid, salt = hashing.commitment_id(domain)
    cr = client_fixture.NODE_CLI.get_commitment_id(name=domain, salt=salt)
    assert cid == cr.commitment_id
Exemple #2
0
 def preclaim(self, account, fee=defaults.FEE, tx_ttl=defaults.TX_TTL):
     """
     Execute a name preclaim
     """
     # check which block we used to create the preclaim
     self.preclaimed_block_height = self.client.get_current_key_block_height(
     )
     # calculate the commitment id
     commitment_id, self.preclaim_salt = hashing.commitment_id(self.domain)
     # get the transaction builder
     txb = self.client.tx_builder
     # get the account nonce and ttl
     nonce, ttl = self.client._get_nonce_ttl(account.get_address(), tx_ttl)
     # create spend_tx
     tx = txb.tx_name_preclaim(account.get_address(), commitment_id, fee,
                               ttl, nonce)
     # sign the transaction
     tx_signed = self.client.sign_transaction(
         account, tx, metadata={"salt": self.preclaim_salt})
     # post the transaction to the chain
     self.client.broadcast_transaction(tx_signed)
     # update local status
     self.status = AEName.Status.PRECLAIMED
     self.preclaim_tx_hash = tx_signed.hash
     return tx_signed
def test_hashing_committment_id():

    tests = [
        {
            "domain": "aeternity.chain",
            "salt": 10692426485854419779,
            "commitment_id":
            "cm_j5Aa3senWdNskwSSHh3M182ucbqrAaSE5DVjejM8fBCgR97kq"
        },
        {
            "domain":
            "whatever.chain",
            "salt":
            4703192432112,
            "commitment_id":
            "cm_2Hd42FoCDfYxcG3MyZkiN9wXiBKfHHzBWycEvrazPYgoEh1ien"
        },
        {
            "domain": "aepps.chain",
            "salt": 723907012945811264198,
            "commitment_id":
            "cm_7aMmYzWVGK2t6gqWYD9WFbwHWaLzcux6t63i2J7VHPZfcuzjs"
        },
    ]

    for t in tests:
        cid, salt = hashing.commitment_id(t.get("domain"), t.get("salt"))
        assert t.get("commitment_id") == cid
def test_hashing_committment_id(random_domain):

    tests = [
        {
            "domain":
            "aeternity.test",
            "salt":
            10692426485854419779,
            "commitment_id":
            "cm_2by2qwnum96Z78WSFRJwhsC5qFzDgatrKk7PfH3yZ2wMBmsZF2"
        },
        {
            "domain": "whatever.test",
            "salt": 4703192432112,
            "commitment_id":
            "cm_2GDk2XGBEqgNKM2sz63EVhsWi6ZGxjR1M7TMFZQvcBUin1As6"
        },
        {
            "domain": "aepps.test",
            "salt": 723907012945811264198,
            "commitment_id":
            "cm_pQu4wAuiyhe1mHqZzh3yNA4JwBPaess3MY7MnZFG9vsFjD5yE"
        },
    ]

    for t in tests:
        cid, salt = hashing.commitment_id(t.get("domain"), t.get("salt"))
        assert t.get("commitment_id") == cid
def test_hashing_committment_id():

    tests = [
        {
            "domain":
            "aeternity.test",
            "salt":
            10692426485854419779,
            "commitment_id":
            "cm_2by2qwnum96Z78WSFRJwhsC5qFzDgatrKk7PfH3yZ2wMBmsZF2"
        },
        {
            "domain": "whatever.test",
            "salt": 4703192432112,
            "commitment_id":
            "cm_2GDk2XGBEqgNKM2sz63EVhsWi6ZGxjR1M7TMFZQvcBUin1As6"
        },
        {
            "domain": "aepps.test",
            "salt": 723907012945811264198,
            "commitment_id":
            "cm_pQu4wAuiyhe1mHqZzh3yNA4JwBPaess3MY7MnZFG9vsFjD5yE"
        },
        {
            "domain": "aeternity.aet",
            "salt": 10692426485854419779,
            "commitment_id":
            "cm_s7xYUEpNNz4v3BenNMBP9YknxYRNqBMNTWG99Vu6v1d8kXxuH"
        },
        {
            "domain":
            "whatever.aet",
            "salt":
            4703192432112,
            "commitment_id":
            "cm_2EoRHJoWoNv4EpZLxgWKBrvgmrbSvA5BxMvDSwPDc6CUYBqanb"
        },
        {
            "domain":
            "aepps.aet",
            "salt":
            723907012945811264198,
            "commitment_id":
            "cm_2gPm7nAvTQojYnVGDPEMZd6uJbkVbZ4aX1nbFm1NCE5HW3kHE6"
        },
    ]

    for t in tests:
        cid, salt = hashing.commitment_id(t.get("domain"), t.get("salt"))
        assert t.get("commitment_id") == cid
Exemple #6
0
 def claim(self,
           account,
           name_salt,
           preclaim_tx_hash,
           fee=defaults.FEE,
           tx_ttl=defaults.TX_TTL):
     self.preclaim_salt = name_salt
     # get the preclaim height
     try:
         pre_claim_tx = self.client.get_transaction_by_hash(
             hash=preclaim_tx_hash)
         self.preclaimed_block_height = pre_claim_tx.block_height
     except OpenAPIClientException:
         raise MissingPreclaim(
             f"Preclaim transaction {preclaim_tx_hash} not found")
     # if the commitment_id mismatch
     pre_claim_commitment_id = pre_claim_tx.tx.commitment_id
     commitment_id, _ = hashing.commitment_id(self.domain, salt=name_salt)
     if pre_claim_commitment_id != commitment_id:
         raise NameCommitmentIdMismatch(
             f"Committment id mismatch, wanted {pre_claim_commitment_id} got {commitment_id}"
         )
     # if the transaction has not been mined
     if self.preclaimed_block_height <= 0:
         raise NameTooEarlyClaim(
             f"The pre-claim transaction has not been mined yet")
     # get the current height
     current_height = self.client.get_current_key_block_height()
     safe_height = self.preclaimed_block_height + self.client.config.key_block_confirmation_num
     if current_height < safe_height:
         raise NameTooEarlyClaim(
             f"It is not safe to execute the name claim before height {safe_height}, current height: {current_height}"
         )
     # name encode name
     name = hashing.name_id(self.domain)
     # get the transaction builder
     txb = self.client.tx_builder
     # get the account nonce and ttl
     nonce, ttl = self.client._get_nonce_ttl(account.get_address(), tx_ttl)
     # create transaction
     tx = txb.tx_name_claim(account.get_address(), name, self.preclaim_salt,
                            fee, ttl, nonce)
     # sign the transaction
     tx_signed = self.client.sign_transaction(account, tx.tx)
     # post the transaction to the chain
     self.client.broadcast_transaction(tx_signed.tx, tx_signed.hash)
     # update status
     self.status = AEName.Status.CLAIMED
     return tx_signed
Exemple #7
0
def test_node_contract_signature_delegation(compiler_fixture, chain_fixture):
    compiler = compiler_fixture.COMPILER
    account = chain_fixture.ALICE
    bob = chain_fixture.BOB
    contract_native = ContractNative(client=chain_fixture.NODE_CLI,
                                     source=contractAens,
                                     compiler=compiler,
                                     account=account)
    contract_native.deploy()

    assert (contract_native.address is not None)

    # the contract_id
    contract_id = contract_native.address
    # node client
    ae_cli = contract_native.client

    # example name
    name = random_domain(length=15)
    c_id, salt = hashing.commitment_id(name, 9876)
    name_ttl = 500000
    client_ttl = 36000
    name_fee = utils.amount_to_aettos("20AE")
    print(f"name is {name}, commitment_id: {c_id}")

    # aens calls
    signature = ae_cli.delegate_name_preclaim_signature(account, contract_id)
    call, r = contract_native.signedPreclaim(account.get_address(), c_id,
                                             signature)
    assert (call.return_type == 'ok')
    ae_cli.wait_for_confirmation(call.tx_hash)

    signature = ae_cli.delegate_name_claim_signature(account, contract_id,
                                                     name)
    call, _ = contract_native.signedClaim(account.get_address(), name, salt,
                                          name_fee, signature)
    assert (call.return_type == 'ok')

    signature = ae_cli.delegate_name_transfer_signature(
        account, contract_id, name)
    call, _ = contract_native.signedTransfer(account.get_address(),
                                             bob.get_address(), name,
                                             signature)
    assert (call.return_type == 'ok')

    signature = ae_cli.delegate_name_revoke_signature(bob, contract_id, name)
    call, _ = contract_native.signedRevoke(bob.get_address(), name, signature)
    assert (call.return_type == 'ok')
def test_hashing_committment_id():

    tests = [
        {
            "domain": "aeternity.test",
            "salt": 10692426485854419779,
            "commitment_id": "cm_2by2qwnum96Z78WSFRJwhsC5qFzDgatrKk7PfH3yZ2wMBmsZF2"
        },
        {
            "domain": "whatever.test",
            "salt": 4703192432112,
            "commitment_id": "cm_2GDk2XGBEqgNKM2sz63EVhsWi6ZGxjR1M7TMFZQvcBUin1As6"
        },
        {
            "domain": "aepps.test",
            "salt": 723907012945811264198,
            "commitment_id": "cm_pQu4wAuiyhe1mHqZzh3yNA4JwBPaess3MY7MnZFG9vsFjD5yE"
        },
        {
            "domain": "aeternity.chain",
            "salt": 10692426485854419779,
            "commitment_id": "cm_j5Aa3senWdNskwSSHh3M182ucbqrAaSE5DVjejM8fBCgR97kq"
        },
        {
            "domain": "whatever.chain",
            "salt": 4703192432112,
            "commitment_id": "cm_2Hd42FoCDfYxcG3MyZkiN9wXiBKfHHzBWycEvrazPYgoEh1ien"
        },
        {
            "domain": "aepps.chain",
            "salt": 723907012945811264198,
            "commitment_id": "cm_7aMmYzWVGK2t6gqWYD9WFbwHWaLzcux6t63i2J7VHPZfcuzjs"
        },
    ]

    for t in tests:
        cid, salt = hashing.commitment_id(t.get("domain"), t.get("salt"))
        assert t.get("commitment_id") == cid
Exemple #9
0
    def preclaim(self,
                 account,
                 fee=defaults.FEE,
                 tx_ttl=defaults.TX_TTL) -> transactions.TxObject:
        """
        Execute a name pre-claim transaction

        :param account: the account performing the pre-claim
        :param fee: the fee for the transaction, [optional, calculated automatically]
        :param tx_ttl: relative number of blocks for the validity of the transaction

        :return: the TxObject of the pre-claim transaction including the parameters to
          calculate the commitment_id in the meta-data
        """
        # parse the fee
        fee = utils.amount_to_aettos(fee)
        # check which block we used to create the pre-claim
        self.preclaimed_block_height = self.client.get_current_key_block_height(
        )
        # calculate the commitment id
        commitment_id, self.preclaim_salt = hashing.commitment_id(self.domain)
        # get the transaction builder
        txb = self.client.tx_builder
        # get the account nonce and ttl
        nonce, ttl = self.client._get_nonce_ttl(account.get_address(), tx_ttl)
        # create spend_tx
        tx = txb.tx_name_preclaim(account.get_address(), commitment_id, fee,
                                  ttl, nonce)
        # sign the transaction
        tx_signed = self.client.sign_transaction(
            account, tx, metadata={"salt": self.preclaim_salt})
        # post the transaction to the chain
        self.client.broadcast_transaction(tx_signed)
        # update local status
        self.status = AEName.Status.PRECLAIMED
        self.preclaim_tx_hash = tx_signed.hash
        return tx_signed
Exemple #10
0
    def claim(self,
              preclaim_tx_hash,
              account,
              name_salt,
              name_fee=defaults.NAME_FEE,
              fee=defaults.FEE,
              tx_ttl=defaults.TX_TTL) -> transactions.TxObject:
        """
        Create and executes a claim transaction; performs a preliminary check
        to verify that the pre-claim exists and it has been confirmed

        :param preclaim_tx_hash: the transaction hash of the pre-claim transaction
        :param account: the account performing the transaction
        :param name_salt: the salt used to calculated the commitment_id in the pre-claim phase
        :param name_fee: the initial fee for the claim [optional, automatically calculated]
        :param fee: the fee for the transaction, [optional, calculated automatically]
        :param tx_ttl: relative number of blocks for the validity of the transaction

        :return: the TxObject of the claim

        :raises MissingPreclaim: if the pre-claim transaction cannot be found
        :raises NameCommitmentIdMismatch: if the commitment_id does not match the one from the pre-claim transaction
        :raises NameTooEarlyClaim: if the pre-claim transaction has not been confirmed yet
        :raises TypeError: if the value of the name_fee is not sufficient to successfully execute the claim
        """
        self.preclaim_salt = name_salt
        # parse the amounts
        name_fee, fee = utils._amounts_to_aettos(name_fee, fee)
        # get the pre-claim height
        try:
            pre_claim_tx = self.client.get_transaction_by_hash(
                hash=preclaim_tx_hash)
            self.preclaimed_block_height = pre_claim_tx.block_height
        except OpenAPIClientException:
            raise MissingPreclaim(
                f"Pre-claim transaction {preclaim_tx_hash} not found")
        # if the commitment_id mismatch
        pre_claim_commitment_id = pre_claim_tx.tx.commitment_id
        commitment_id, _ = hashing.commitment_id(self.domain, salt=name_salt)
        if pre_claim_commitment_id != commitment_id:
            raise NameCommitmentIdMismatch(
                f"Commitment id mismatch, wanted {pre_claim_commitment_id} got {commitment_id}"
            )
        # if the transaction has not been mined
        if self.preclaimed_block_height <= 0:
            raise NameTooEarlyClaim(
                f"The pre-claim transaction has not been mined yet")
        # get the current height
        current_height = self.client.get_current_key_block_height()
        safe_height = self.preclaimed_block_height + self.client.config.key_block_confirmation_num
        if current_height < safe_height:
            raise NameTooEarlyClaim(
                f"It is not safe to execute the name claim before height {safe_height}, current height: {current_height}"
            )
        # get the transaction builder
        txb = self.client.tx_builder
        # get the account nonce and ttl
        nonce, ttl = self.client._get_nonce_ttl(account.get_address(), tx_ttl)
        # create transaction
        # check the protocol version
        min_name_fee = AEName.get_minimum_name_fee(self.domain)
        if name_fee != defaults.NAME_FEE and name_fee < min_name_fee:
            raise TypeError(
                f"the provided fee {name_fee} is not enough to execute the claim, required: {min_name_fee}"
            )
        name_fee = max(min_name_fee, name_fee)
        tx = txb.tx_name_claim_v2(account.get_address(), self.domain,
                                  self.preclaim_salt, name_fee, fee, ttl,
                                  nonce)
        # sign the transaction
        tx_signed = self.client.sign_transaction(account, tx)
        # post the transaction to the chain
        self.client.broadcast_transaction(tx_signed)
        # update status
        self.status = AEName.Status.CLAIMED
        return tx_signed
Exemple #11
0
 def claim(self,
           preclaim_tx_hash,
           account,
           name_salt,
           name_fee=defaults.NAME_FEE,
           fee=defaults.FEE,
           tx_ttl=defaults.TX_TTL):
     self.preclaim_salt = name_salt
     # get the preclaim height
     try:
         pre_claim_tx = self.client.get_transaction_by_hash(
             hash=preclaim_tx_hash)
         self.preclaimed_block_height = pre_claim_tx.block_height
     except OpenAPIClientException:
         raise MissingPreclaim(
             f"Preclaim transaction {preclaim_tx_hash} not found")
     # first get the protocol version
     protocol = self.client.get_consensus_protocol_version()
     # if the commitment_id mismatch
     pre_claim_commitment_id = pre_claim_tx.tx.commitment_id
     commitment_id, _ = hashing.commitment_id(self.domain, salt=name_salt)
     if pre_claim_commitment_id != commitment_id:
         raise NameCommitmentIdMismatch(
             f"Commitment id mismatch, wanted {pre_claim_commitment_id} got {commitment_id}"
         )
     # if the transaction has not been mined
     if self.preclaimed_block_height <= 0:
         raise NameTooEarlyClaim(
             f"The pre-claim transaction has not been mined yet")
     # get the current height
     current_height = self.client.get_current_key_block_height()
     safe_height = self.preclaimed_block_height + self.client.config.key_block_confirmation_num
     if current_height < safe_height:
         raise NameTooEarlyClaim(
             f"It is not safe to execute the name claim before height {safe_height}, current height: {current_height}"
         )
     # get the transaction builder
     txb = self.client.tx_builder
     # get the account nonce and ttl
     nonce, ttl = self.client._get_nonce_ttl(account.get_address(), tx_ttl)
     # create transaction
     # check the protocol version
     if protocol < identifiers.PROTOCOL_LIMA:
         tx = txb.tx_name_claim(account.get_address(), self.domain,
                                self.preclaim_salt, fee, ttl, nonce)
     else:
         min_name_fee = AEName.get_minimum_name_fee(self.domain)
         if name_fee != defaults.NAME_FEE and name_fee < min_name_fee:
             raise TypeError(
                 f"the provided fee {name_fee} is not enough to execute the claim, required: {min_name_fee}"
             )
         name_fee = max(min_name_fee, name_fee)
         tx = txb.tx_name_claim_v2(account.get_address(), self.domain,
                                   self.preclaim_salt, name_fee, fee, ttl,
                                   nonce)
     # sign the transaction
     tx_signed = self.client.sign_transaction(account, tx)
     # post the transaction to the chain
     self.client.broadcast_transaction(tx_signed)
     # update status
     self.status = AEName.Status.CLAIMED
     return tx_signed