Search in sources :

Example 16 with TokenID

use of com.hederahashgraph.api.proto.java.TokenID in project hedera-services by hashgraph.

the class DissociatePrecompileSuite method dissociatePrecompileHasExpectedSemanticsForDeletedTokens.

/* -- Not specifically required in the HTS Precompile Test Plan -- */
public HapiApiSpec dissociatePrecompileHasExpectedSemanticsForDeletedTokens() {
    final String tbdUniqToken = "UniqToBeDeleted";
    final String zeroBalanceFrozen = "0bFrozen";
    final String zeroBalanceUnfrozen = "0bUnfrozen";
    final String nonZeroBalanceFrozen = "1bFrozen";
    final String nonZeroBalanceUnfrozen = "1bUnfrozen";
    final long initialSupply = 100L;
    final long nonZeroXfer = 10L;
    final var firstMeta = ByteString.copyFrom("FIRST".getBytes(StandardCharsets.UTF_8));
    final var secondMeta = ByteString.copyFrom("SECOND".getBytes(StandardCharsets.UTF_8));
    final var thirdMeta = ByteString.copyFrom("THIRD".getBytes(StandardCharsets.UTF_8));
    final AtomicReference<AccountID> accountID = new AtomicReference<>();
    final AtomicReference<AccountID> treasuryID = new AtomicReference<>();
    final AtomicReference<AccountID> zeroBalanceFrozenID = new AtomicReference<>();
    final AtomicReference<AccountID> zeroBalanceUnfrozenID = new AtomicReference<>();
    final AtomicReference<AccountID> nonZeroBalanceFrozenID = new AtomicReference<>();
    final AtomicReference<AccountID> nonZeroBalanceUnfrozenID = new AtomicReference<>();
    final AtomicReference<TokenID> tbdTokenID = new AtomicReference<>();
    final AtomicReference<TokenID> tbdUniqueTokenID = new AtomicReference<>();
    return defaultHapiSpec("DissociatePrecompileHasExpectedSemanticsForDeletedTokens").given(newKeyNamed(MULTI_KEY), cryptoCreate(ACCOUNT).balance(10 * ONE_HUNDRED_HBARS).exposingCreatedIdTo(accountID::set), fileCreate(THE_CONTRACT), updateLargeFile(ACCOUNT, THE_CONTRACT, extractByteCode(ContractResources.ASSOCIATE_DISSOCIATE_CONTRACT)), cryptoCreate(TOKEN_TREASURY).balance(10 * ONE_HUNDRED_HBARS).exposingCreatedIdTo(treasuryID::set), tokenCreate(TBD_TOKEN).adminKey(MULTI_KEY).supplyKey(MULTI_KEY).initialSupply(initialSupply).treasury(TOKEN_TREASURY).freezeKey(MULTI_KEY).freezeDefault(true).exposingCreatedIdTo(id -> tbdTokenID.set(asToken(id))), tokenCreate(tbdUniqToken).tokenType(TokenType.NON_FUNGIBLE_UNIQUE).treasury(TOKEN_TREASURY).adminKey(MULTI_KEY).supplyKey(MULTI_KEY).initialSupply(0).exposingCreatedIdTo(id -> tbdUniqueTokenID.set(asToken(id))), cryptoCreate(zeroBalanceFrozen).balance(10 * ONE_HUNDRED_HBARS).exposingCreatedIdTo(zeroBalanceFrozenID::set), cryptoCreate(zeroBalanceUnfrozen).balance(10 * ONE_HUNDRED_HBARS).exposingCreatedIdTo(zeroBalanceUnfrozenID::set), cryptoCreate(nonZeroBalanceFrozen).balance(10 * ONE_HUNDRED_HBARS).exposingCreatedIdTo(nonZeroBalanceFrozenID::set), cryptoCreate(nonZeroBalanceUnfrozen).balance(10 * ONE_HUNDRED_HBARS).exposingCreatedIdTo(nonZeroBalanceUnfrozenID::set)).when(withOpContext((spec, opLog) -> allRunFor(spec, contractCreate(THE_CONTRACT).bytecode(THE_CONTRACT).gas(GAS_TO_OFFER), tokenAssociate(zeroBalanceFrozen, TBD_TOKEN), tokenAssociate(zeroBalanceUnfrozen, TBD_TOKEN), tokenAssociate(nonZeroBalanceFrozen, TBD_TOKEN), tokenAssociate(nonZeroBalanceUnfrozen, TBD_TOKEN), mintToken(tbdUniqToken, List.of(firstMeta, secondMeta, thirdMeta)), getAccountInfo(TOKEN_TREASURY).hasOwnedNfts(3), tokenUnfreeze(TBD_TOKEN, zeroBalanceUnfrozen), tokenUnfreeze(TBD_TOKEN, nonZeroBalanceUnfrozen), tokenUnfreeze(TBD_TOKEN, nonZeroBalanceFrozen), cryptoTransfer(moving(nonZeroXfer, TBD_TOKEN).between(TOKEN_TREASURY, nonZeroBalanceFrozen)), cryptoTransfer(moving(nonZeroXfer, TBD_TOKEN).between(TOKEN_TREASURY, nonZeroBalanceUnfrozen)), tokenFreeze(TBD_TOKEN, nonZeroBalanceFrozen), getAccountBalance(TOKEN_TREASURY).hasTokenBalance(TBD_TOKEN, initialSupply - 2 * nonZeroXfer), tokenDelete(TBD_TOKEN), tokenDelete(tbdUniqToken), contractCall(THE_CONTRACT, SINGLE_TOKEN_DISSOCIATE, asAddress(zeroBalanceFrozenID.get()), asAddress(tbdTokenID.get())).payingWith(zeroBalanceFrozen).alsoSigningWithFullPrefix(MULTI_KEY).gas(GAS_TO_OFFER).via("dissociateZeroBalanceFrozenTxn"), getTxnRecord("dissociateZeroBalanceFrozenTxn").andAllChildRecords().logged(), contractCall(THE_CONTRACT, SINGLE_TOKEN_DISSOCIATE, asAddress(zeroBalanceUnfrozenID.get()), asAddress(tbdTokenID.get())).payingWith(zeroBalanceUnfrozen).alsoSigningWithFullPrefix(MULTI_KEY).gas(GAS_TO_OFFER).via("dissociateZeroBalanceUnfrozenTxn"), getTxnRecord("dissociateZeroBalanceUnfrozenTxn").andAllChildRecords().logged(), contractCall(THE_CONTRACT, SINGLE_TOKEN_DISSOCIATE, asAddress(nonZeroBalanceFrozenID.get()), asAddress(tbdTokenID.get())).payingWith(nonZeroBalanceFrozen).alsoSigningWithFullPrefix(MULTI_KEY).gas(GAS_TO_OFFER).via("dissociateNonZeroBalanceFrozenTxn"), getTxnRecord("dissociateNonZeroBalanceFrozenTxn").andAllChildRecords().logged(), contractCall(THE_CONTRACT, SINGLE_TOKEN_DISSOCIATE, asAddress(nonZeroBalanceUnfrozenID.get()), asAddress(tbdTokenID.get())).payingWith(nonZeroBalanceUnfrozen).alsoSigningWithFullPrefix(MULTI_KEY).gas(GAS_TO_OFFER).via("dissociateNonZeroBalanceUnfrozenTxn"), getTxnRecord("dissociateNonZeroBalanceUnfrozenTxn").andAllChildRecords().logged(), contractCall(THE_CONTRACT, SINGLE_TOKEN_DISSOCIATE, asAddress(treasuryID.get()), asAddress(tbdUniqueTokenID.get())).alsoSigningWithFullPrefix(MULTI_KEY).gas(GAS_TO_OFFER).payingWith(TOKEN_TREASURY)))).then(childRecordsCheck("dissociateZeroBalanceFrozenTxn", SUCCESS, recordWith().status(SUCCESS)), childRecordsCheck("dissociateZeroBalanceUnfrozenTxn", SUCCESS, recordWith().status(SUCCESS)), childRecordsCheck("dissociateNonZeroBalanceFrozenTxn", SUCCESS, recordWith().status(SUCCESS)), childRecordsCheck("dissociateNonZeroBalanceUnfrozenTxn", SUCCESS, recordWith().status(SUCCESS)), getAccountInfo(zeroBalanceFrozen).hasNoTokenRelationship(TBD_TOKEN), getAccountInfo(zeroBalanceUnfrozen).hasNoTokenRelationship(TBD_TOKEN), getAccountInfo(nonZeroBalanceFrozen).hasNoTokenRelationship(TBD_TOKEN), getAccountInfo(nonZeroBalanceUnfrozen).hasNoTokenRelationship(TBD_TOKEN), getAccountInfo(TOKEN_TREASURY).hasToken(relationshipWith(TBD_TOKEN)).hasNoTokenRelationship(tbdUniqToken).hasOwnedNfts(0), getAccountBalance(TOKEN_TREASURY).hasTokenBalance(TBD_TOKEN, initialSupply - 2 * nonZeroXfer));
}
Also used : SINGLE_TOKEN_DISSOCIATE(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.SINGLE_TOKEN_DISSOCIATE) TxnVerbs.cryptoCreate(com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoCreate) TxnVerbs.cryptoTransfer(com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoTransfer) TxnVerbs.tokenDelete(com.hedera.services.bdd.spec.transactions.TxnVerbs.tokenDelete) QueryVerbs.getTxnRecord(com.hedera.services.bdd.spec.queries.QueryVerbs.getTxnRecord) QueryVerbs.getAccountInfo(com.hedera.services.bdd.spec.queries.QueryVerbs.getAccountInfo) ExpectedTokenRel.relationshipWith(com.hedera.services.bdd.spec.queries.crypto.ExpectedTokenRel.relationshipWith) HapiApiSpec.defaultHapiSpec(com.hedera.services.bdd.spec.HapiApiSpec.defaultHapiSpec) TBD_TOKEN(com.hedera.services.bdd.suites.token.TokenAssociationSpecs.TBD_TOKEN) TxnVerbs.contractCall(com.hedera.services.bdd.spec.transactions.TxnVerbs.contractCall) UtilVerbs.newKeyNamed(com.hedera.services.bdd.spec.utilops.UtilVerbs.newKeyNamed) TransactionRecordAsserts.recordWith(com.hedera.services.bdd.spec.assertions.TransactionRecordAsserts.recordWith) MULTIPLE_TOKENS_DISSOCIATE(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.MULTIPLE_TOKENS_DISSOCIATE) SUCCESS(com.hederahashgraph.api.proto.java.ResponseCodeEnum.SUCCESS) StandardCharsets(java.nio.charset.StandardCharsets) Utils.extractByteCode(com.hedera.services.bdd.suites.contract.Utils.extractByteCode) ByteString(com.google.protobuf.ByteString) List(java.util.List) Logger(org.apache.logging.log4j.Logger) NotNull(org.jetbrains.annotations.NotNull) HapiApiSpec(com.hedera.services.bdd.spec.HapiApiSpec) TxnVerbs.tokenAssociate(com.hedera.services.bdd.spec.transactions.TxnVerbs.tokenAssociate) UtilVerbs.withOpContext(com.hedera.services.bdd.spec.utilops.UtilVerbs.withOpContext) FREEZABLE_TOKEN_ON_BY_DEFAULT(com.hedera.services.bdd.suites.token.TokenAssociationSpecs.FREEZABLE_TOKEN_ON_BY_DEFAULT) NESTED_TOKEN_DISSOCIATE(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.NESTED_TOKEN_DISSOCIATE) AtomicReference(java.util.concurrent.atomic.AtomicReference) ContractResources(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources) TokenMovement.moving(com.hedera.services.bdd.spec.transactions.token.TokenMovement.moving) UtilVerbs.childRecordsCheck(com.hedera.services.bdd.spec.utilops.UtilVerbs.childRecordsCheck) HapiApiSuite(com.hedera.services.bdd.suites.HapiApiSuite) HapiPropertySource.asDotDelimitedLongArray(com.hedera.services.bdd.spec.HapiPropertySource.asDotDelimitedLongArray) AccountID(com.hederahashgraph.api.proto.java.AccountID) TxnVerbs.mintToken(com.hedera.services.bdd.spec.transactions.TxnVerbs.mintToken) TxnVerbs.tokenCreate(com.hedera.services.bdd.spec.transactions.TxnVerbs.tokenCreate) ResponseCodeEnum(com.hederahashgraph.api.proto.java.ResponseCodeEnum) TxnVerbs.tokenFreeze(com.hedera.services.bdd.spec.transactions.TxnVerbs.tokenFreeze) UtilVerbs.updateLargeFile(com.hedera.services.bdd.spec.utilops.UtilVerbs.updateLargeFile) QueryVerbs.getAccountBalance(com.hedera.services.bdd.spec.queries.QueryVerbs.getAccountBalance) VANILLA_TOKEN(com.hedera.services.bdd.suites.token.TokenAssociationSpecs.VANILLA_TOKEN) CustomSpecAssert.allRunFor(com.hedera.services.bdd.spec.utilops.CustomSpecAssert.allRunFor) TokenType(com.hederahashgraph.api.proto.java.TokenType) TxnVerbs.fileCreate(com.hedera.services.bdd.spec.transactions.TxnVerbs.fileCreate) KNOWABLE_TOKEN(com.hedera.services.bdd.suites.token.TokenAssociationSpecs.KNOWABLE_TOKEN) TokenID(com.hederahashgraph.api.proto.java.TokenID) Utils.asAddress(com.hedera.services.bdd.suites.contract.Utils.asAddress) TxnVerbs.contractCreate(com.hedera.services.bdd.spec.transactions.TxnVerbs.contractCreate) FUNGIBLE_COMMON(com.hederahashgraph.api.proto.java.TokenType.FUNGIBLE_COMMON) LogManager(org.apache.logging.log4j.LogManager) TxnVerbs.tokenUnfreeze(com.hedera.services.bdd.spec.transactions.TxnVerbs.tokenUnfreeze) AccountID(com.hederahashgraph.api.proto.java.AccountID) AtomicReference(java.util.concurrent.atomic.AtomicReference) ByteString(com.google.protobuf.ByteString) TokenID(com.hederahashgraph.api.proto.java.TokenID)

Example 17 with TokenID

use of com.hederahashgraph.api.proto.java.TokenID in project hedera-services by hashgraph.

the class PureTransferSemanticChecks method validateTokenTransferSemantics.

ResponseCodeEnum validateTokenTransferSemantics(List<TokenTransferList> tokenTransfersList) {
    if (tokenTransfersList.isEmpty()) {
        return OK;
    }
    ResponseCodeEnum validity;
    final Set<TokenID> uniqueTokens = new HashSet<>();
    for (var tokenTransfers : tokenTransfersList) {
        validity = validateScopedTransferSemantics(uniqueTokens, tokenTransfers);
        if (validity != OK) {
            return validity;
        }
    }
    if (uniqueTokens.size() < tokenTransfersList.size()) {
        return TOKEN_ID_REPEATED_IN_TOKEN_LIST;
    }
    return OK;
}
Also used : ResponseCodeEnum(com.hederahashgraph.api.proto.java.ResponseCodeEnum) TokenID(com.hederahashgraph.api.proto.java.TokenID) HashSet(java.util.HashSet)

Example 18 with TokenID

use of com.hederahashgraph.api.proto.java.TokenID in project hedera-services by hashgraph.

the class MerkleAccountPropertyTest method gettersAndSettersWork.

@Test
void gettersAndSettersWork() throws Exception {
    final boolean origIsDeleted = false;
    final boolean origIsReceiverSigReq = false;
    final boolean origIsContract = false;
    final long origBalance = 1L;
    final long origAutoRenew = 1L;
    final long origNumNfts = 123L;
    final long origExpiry = 1L;
    final int origMaxAutoAssociations = 10;
    final int origAlreadyUsedAutoAssociations = 7;
    final var origKey = SignedTxnFactory.DEFAULT_PAYER_KT.asKey();
    final String origMemo = "a";
    final var origProxy = AccountID.getDefaultInstance();
    final List<ExpirableTxnRecord> origRecords = new ArrayList<>();
    origRecords.add(expirableRecord(ResponseCodeEnum.MODIFYING_IMMUTABLE_CONTRACT));
    origRecords.add(expirableRecord(ResponseCodeEnum.INVALID_PAYER_SIGNATURE));
    final List<ExpirableTxnRecord> origPayerRecords = new ArrayList<>();
    origPayerRecords.add(expirableRecord(ResponseCodeEnum.INVALID_CHUNK_NUMBER));
    origPayerRecords.add(expirableRecord(ResponseCodeEnum.INSUFFICIENT_TX_FEE));
    final boolean newIsDeleted = true;
    final boolean newIsReceiverSigReq = true;
    final boolean newIsContract = true;
    final long newBalance = 2L;
    final long newAutoRenew = 2L;
    final long newExpiry = 2L;
    final long newNumNfts = 321L;
    final int newMaxAutoAssociations = 15;
    final int newAlreadyUsedAutoAssociations = 11;
    final JKey newKey = new JKeyList();
    final String newMemo = "b";
    final EntityId newProxy = new EntityId(0, 0, 2);
    final var oldAlias = ByteString.copyFromUtf8("then");
    final var newAlias = ByteString.copyFromUtf8("now");
    final int oldNumKvPairs = 123;
    final int newNumKvPairs = 123;
    final long initialAllowance = 100L;
    final AccountID payer = AccountID.newBuilder().setAccountNum(12345L).build();
    final AccountID owner = AccountID.newBuilder().setAccountNum(12347L).build();
    final EntityNum payerNum = EntityNum.fromAccountId(payer);
    final TokenID fungibleTokenID = TokenID.newBuilder().setTokenNum(1234L).build();
    final TokenID nonFungibleTokenID = TokenID.newBuilder().setTokenNum(1235L).build();
    final FcTokenAllowanceId fungibleAllowanceId = FcTokenAllowanceId.from(EntityNum.fromTokenId(fungibleTokenID), payerNum);
    final FcTokenAllowanceId nftAllowanceId = FcTokenAllowanceId.from(EntityNum.fromTokenId(nonFungibleTokenID), payerNum);
    final TreeMap<EntityNum, Long> cryptoAllowances = new TreeMap<>() {

        {
            put(payerNum, initialAllowance);
        }
    };
    final TreeMap<FcTokenAllowanceId, Long> fungibleAllowances = new TreeMap<>() {

        {
            put(fungibleAllowanceId, initialAllowance);
        }
    };
    final TreeMap<FcTokenAllowanceId, FcTokenAllowance> nftAllowances = new TreeMap<>() {

        {
            put(fungibleAllowanceId, FcTokenAllowance.from(true));
            put(nftAllowanceId, FcTokenAllowance.from(List.of(1L, 2L)));
        }
    };
    final var account = new HederaAccountCustomizer().key(JKey.mapKey(origKey)).expiry(origExpiry).proxy(EntityId.fromGrpcAccountId(origProxy)).autoRenewPeriod(origAutoRenew).isDeleted(origIsDeleted).alias(oldAlias).memo(origMemo).isSmartContract(origIsContract).isReceiverSigRequired(origIsReceiverSigReq).customizing(new MerkleAccount());
    account.setNumContractKvPairs(oldNumKvPairs);
    account.setNftsOwned(origNumNfts);
    account.setBalance(origBalance);
    account.records().offer(origPayerRecords.get(0));
    account.records().offer(origPayerRecords.get(1));
    account.setMaxAutomaticAssociations(origMaxAutoAssociations);
    account.setAlreadyUsedAutomaticAssociations(origAlreadyUsedAutoAssociations);
    final var adminKey = TOKEN_ADMIN_KT.asJKeyUnchecked();
    final var unfrozenToken = new MerkleToken(Long.MAX_VALUE, 100, 1, "UnfrozenToken", "UnfrozenTokenName", false, true, new EntityId(1, 2, 3));
    unfrozenToken.setFreezeKey(adminKey);
    unfrozenToken.setKycKey(adminKey);
    final var frozenToken = new MerkleToken(Long.MAX_VALUE, 100, 1, "FrozenToken", "FrozenTokenName", true, false, new EntityId(1, 2, 3));
    frozenToken.setFreezeKey(adminKey);
    frozenToken.setKycKey(adminKey);
    ALIAS.setter().accept(account, newAlias);
    IS_DELETED.setter().accept(account, newIsDeleted);
    IS_RECEIVER_SIG_REQUIRED.setter().accept(account, newIsReceiverSigReq);
    IS_SMART_CONTRACT.setter().accept(account, newIsContract);
    BALANCE.setter().accept(account, newBalance);
    AUTO_RENEW_PERIOD.setter().accept(account, newAutoRenew);
    EXPIRY.setter().accept(account, newExpiry);
    KEY.setter().accept(account, newKey);
    MEMO.setter().accept(account, newMemo);
    PROXY.setter().accept(account, newProxy);
    NUM_NFTS_OWNED.setter().accept(account, newNumNfts);
    MAX_AUTOMATIC_ASSOCIATIONS.setter().accept(account, newMaxAutoAssociations);
    ALREADY_USED_AUTOMATIC_ASSOCIATIONS.setter().accept(account, newAlreadyUsedAutoAssociations);
    NUM_CONTRACT_KV_PAIRS.setter().accept(account, newNumKvPairs);
    CRYPTO_ALLOWANCES.setter().accept(account, cryptoAllowances);
    FUNGIBLE_TOKEN_ALLOWANCES.setter().accept(account, fungibleAllowances);
    NFT_ALLOWANCES.setter().accept(account, nftAllowances);
    assertEquals(newIsDeleted, IS_DELETED.getter().apply(account));
    assertEquals(newIsReceiverSigReq, IS_RECEIVER_SIG_REQUIRED.getter().apply(account));
    assertEquals(newIsContract, IS_SMART_CONTRACT.getter().apply(account));
    assertEquals(newBalance, BALANCE.getter().apply(account));
    assertEquals(newAutoRenew, AUTO_RENEW_PERIOD.getter().apply(account));
    assertEquals(newExpiry, EXPIRY.getter().apply(account));
    assertEquals(newKey, KEY.getter().apply(account));
    assertEquals(newMemo, MEMO.getter().apply(account));
    assertEquals(newProxy, PROXY.getter().apply(account));
    assertEquals(newNumNfts, NUM_NFTS_OWNED.getter().apply(account));
    assertEquals(newAlreadyUsedAutoAssociations, ALREADY_USED_AUTOMATIC_ASSOCIATIONS.getter().apply(account));
    assertEquals(newMaxAutoAssociations, MAX_AUTOMATIC_ASSOCIATIONS.getter().apply(account));
    assertEquals(newAlias, ALIAS.getter().apply(account));
    assertEquals(newNumKvPairs, NUM_CONTRACT_KV_PAIRS.getter().apply(account));
    assertEquals(cryptoAllowances, CRYPTO_ALLOWANCES.getter().apply(account));
    assertEquals(fungibleAllowances, FUNGIBLE_TOKEN_ALLOWANCES.getter().apply(account));
    assertEquals(nftAllowances, NFT_ALLOWANCES.getter().apply(account));
}
Also used : ExpirableTxnRecord(com.hedera.services.state.submerkle.ExpirableTxnRecord) JKeyList(com.hedera.services.legacy.core.jproto.JKeyList) AccountID(com.hederahashgraph.api.proto.java.AccountID) MerkleToken(com.hedera.services.state.merkle.MerkleToken) ArrayList(java.util.ArrayList) MerkleAccount(com.hedera.services.state.merkle.MerkleAccount) ByteString(com.google.protobuf.ByteString) TreeMap(java.util.TreeMap) EntityNum(com.hedera.services.utils.EntityNum) EntityId(com.hedera.services.state.submerkle.EntityId) FcTokenAllowanceId(com.hedera.services.state.submerkle.FcTokenAllowanceId) JKey(com.hedera.services.legacy.core.jproto.JKey) TokenID(com.hederahashgraph.api.proto.java.TokenID) FcTokenAllowance(com.hedera.services.state.submerkle.FcTokenAllowance) HederaAccountCustomizer(com.hedera.services.ledger.accounts.HederaAccountCustomizer) Test(org.junit.jupiter.api.Test)

Example 19 with TokenID

use of com.hederahashgraph.api.proto.java.TokenID in project hedera-services by hashgraph.

the class BaseHederaLedgerTestHelper method addToLedger.

protected void addToLedger(AccountID id, long balance, Map<TokenID, TokenInfo> tokenInfo) {
    when(accountsLedger.get(id, EXPIRY)).thenReturn(1_234_567_890L);
    when(accountsLedger.get(id, PROXY)).thenReturn(new EntityId(0, 0, 1_234L));
    when(accountsLedger.get(id, AUTO_RENEW_PERIOD)).thenReturn(7776000L);
    when(accountsLedger.get(id, BALANCE)).thenReturn(balance);
    when(accountsLedger.get(id, IS_DELETED)).thenReturn(false);
    when(accountsLedger.get(id, IS_RECEIVER_SIG_REQUIRED)).thenReturn(true);
    when(accountsLedger.get(id, IS_SMART_CONTRACT)).thenReturn(false);
    when(accountsLedger.get(id, MAX_AUTOMATIC_ASSOCIATIONS)).thenReturn(8);
    when(accountsLedger.get(id, ALREADY_USED_AUTOMATIC_ASSOCIATIONS)).thenReturn(5);
    when(accountsLedger.exists(id)).thenReturn(true);
    var tokens = new MerkleAccountTokens();
    tokens.associateAll(tokenInfo.keySet());
    when(accountsLedger.get(id, TOKENS)).thenReturn(tokens);
    // and:
    for (TokenID tId : tokenInfo.keySet()) {
        var info = tokenInfo.get(tId);
        var relationship = BackingTokenRels.asTokenRel(id, tId);
        when(tokenRelsLedger.get(relationship, TOKEN_BALANCE)).thenReturn(info.balance);
    }
}
Also used : EntityId(com.hedera.services.state.submerkle.EntityId) MerkleAccountTokens(com.hedera.services.state.merkle.MerkleAccountTokens) TokenID(com.hederahashgraph.api.proto.java.TokenID)

Example 20 with TokenID

use of com.hederahashgraph.api.proto.java.TokenID in project hedera-services by hashgraph.

the class SeqNoEntityIdSourceTest method returnsExpectedTokenId.

@Test
void returnsExpectedTokenId() {
    given(seqNo.getAndIncrement()).willReturn(555L);
    // when:
    TokenID newId = subject.newTokenId(sponsor);
    // then:
    assertEquals(asToken("1.2.555"), newId);
}
Also used : TokenID(com.hederahashgraph.api.proto.java.TokenID) Test(org.junit.jupiter.api.Test)

Aggregations

TokenID (com.hederahashgraph.api.proto.java.TokenID)24 AccountID (com.hederahashgraph.api.proto.java.AccountID)11 Test (org.junit.jupiter.api.Test)9 TokenTransferList (com.hederahashgraph.api.proto.java.TokenTransferList)7 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)6 ResponseCodeEnum (com.hederahashgraph.api.proto.java.ResponseCodeEnum)5 TokenUpdateTransactionBody (com.hederahashgraph.api.proto.java.TokenUpdateTransactionBody)5 TransactionBody (com.hederahashgraph.api.proto.java.TransactionBody)5 ByteString (com.google.protobuf.ByteString)4 AbstractEntity (com.hedera.mirror.common.domain.entity.AbstractEntity)4 EntityId (com.hedera.mirror.common.domain.entity.EntityId)4 RecordItem (com.hedera.mirror.common.domain.transaction.RecordItem)4 Transaction (com.hedera.mirror.common.domain.transaction.Transaction)4 TransactionRecord (com.hederahashgraph.api.proto.java.TransactionRecord)4 Range (com.google.common.collect.Range)3 Entity (com.hedera.mirror.common.domain.entity.Entity)3 EntityIdEndec (com.hedera.mirror.common.domain.entity.EntityIdEndec)3 EntityType (com.hedera.mirror.common.domain.entity.EntityType)3 ACCOUNT (com.hedera.mirror.common.domain.entity.EntityType.ACCOUNT)3 NftTransferId (com.hedera.mirror.common.domain.token.NftTransferId)3