Search in sources :

Example 6 with EntityNum

use of com.hedera.services.utils.EntityNum in project hedera-services by hashgraph.

the class ExpirableTxnRecord method deserializeAllowanceMaps.

private void deserializeAllowanceMaps(SerializableDataInputStream in) throws IOException {
    var numCryptoAllowances = in.readInt();
    if (numCryptoAllowances > 0) {
        cryptoAllowances = new TreeMap<>();
    }
    while (numCryptoAllowances-- > 0) {
        final EntityNum owner = EntityNum.fromLong(in.readLong());
        cryptoAllowances.put(owner, deserializeCryptoAllowances(in));
    }
    var numTokenAllowances = in.readInt();
    if (numTokenAllowances > 0) {
        fungibleTokenAllowances = new TreeMap<>();
    }
    while (numTokenAllowances-- > 0) {
        final EntityNum owner = EntityNum.fromLong(in.readLong());
        fungibleTokenAllowances.put(owner, deserializeFungibleTokenAllowances(in));
    }
    var numNftAllowances = in.readInt();
    if (numNftAllowances > 0) {
        nftAllowances = new TreeMap<>();
    }
    while (numNftAllowances-- > 0) {
        final EntityNum owner = EntityNum.fromLong(in.readLong());
        nftAllowances.put(owner, deserializeNftAllowances(in));
    }
}
Also used : EntityNum(com.hedera.services.utils.EntityNum)

Example 7 with EntityNum

use of com.hedera.services.utils.EntityNum in project hedera-services by hashgraph.

the class MerkleAccountTest method settersDelegate.

@Test
void settersDelegate() throws NegativeAccountBalanceException {
    subject = new MerkleAccount(List.of(delegate, new FCQueue<>(), new FCQueue<>()));
    given(delegate.getMaxAutomaticAssociations()).willReturn(maxAutoAssociations);
    subject.setExpiry(otherExpiry);
    subject.setBalance(otherBalance);
    subject.setAutoRenewSecs(otherAutoRenewSecs);
    subject.setDeleted(otherDeleted);
    subject.setSmartContract(otherSmartContract);
    subject.setReceiverSigRequired(otherReceiverSigRequired);
    subject.setMemo(otherMemo);
    subject.setProxy(otherProxy);
    subject.setAccountKey(otherKey);
    subject.setKey(new EntityNum(number));
    subject.setMaxAutomaticAssociations(maxAutoAssociations);
    subject.setAlreadyUsedAutomaticAssociations(alreadyUsedAutoAssociations);
    subject.setNftsOwned(2L);
    subject.setAlias(alias);
    subject.setNumContractKvPairs(kvPairs);
    subject.setCryptoAllowances(cryptoAllowances);
    subject.setFungibleTokenAllowances(fungibleTokenAllowances);
    subject.setNftAllowances(nftAllowances);
    verify(delegate).setExpiry(otherExpiry);
    verify(delegate).setAutoRenewSecs(otherAutoRenewSecs);
    verify(delegate).setDeleted(otherDeleted);
    verify(delegate).setSmartContract(otherSmartContract);
    verify(delegate).setReceiverSigRequired(otherReceiverSigRequired);
    verify(delegate).setMemo(otherMemo);
    verify(delegate).setProxy(otherProxy);
    verify(delegate).setAccountKey(otherKey);
    verify(delegate).setHbarBalance(otherBalance);
    verify(delegate).setNumber(number);
    verify(delegate).setMaxAutomaticAssociations(maxAutoAssociations);
    verify(delegate).setAlreadyUsedAutomaticAssociations(alreadyUsedAutoAssociations);
    verify(delegate).setNumContractKvPairs(kvPairs);
    verify(delegate).setNftsOwned(2L);
    verify(delegate).setAlias(alias);
    verify(delegate).setCryptoAllowances(cryptoAllowances);
    verify(delegate).setFungibleTokenAllowances(fungibleTokenAllowances);
    verify(delegate).setNftAllowances(nftAllowances);
}
Also used : EntityNum(com.hedera.services.utils.EntityNum) Test(org.junit.jupiter.api.Test)

Example 8 with EntityNum

use of com.hedera.services.utils.EntityNum in project hedera-services by hashgraph.

the class FeeCalcUtilsTest method returnsAccountExpiryIfAvail.

@Test
void returnsAccountExpiryIfAvail() {
    // setup:
    final var account = mock(MerkleAccount.class);
    final MerkleMap<EntityNum, MerkleAccount> accounts = mock(MerkleMap.class);
    Timestamp expected = Timestamp.newBuilder().setSeconds(Long.MAX_VALUE).build();
    given(account.getExpiry()).willReturn(Long.MAX_VALUE);
    given(accounts.get(key)).willReturn(account);
    assertEquals(expected, lookupAccountExpiry(key, accounts));
}
Also used : MerkleAccount(com.hedera.services.state.merkle.MerkleAccount) Timestamp(com.hederahashgraph.api.proto.java.Timestamp) EntityNum(com.hedera.services.utils.EntityNum) Test(org.junit.jupiter.api.Test)

Example 9 with EntityNum

use of com.hedera.services.utils.EntityNum in project hedera-services by hashgraph.

the class FcmCustomFeeSchedulesTest method testObjectContract.

@Test
void testObjectContract() {
    // given:
    MerkleMap<EntityNum, MerkleToken> secondMerkleMap = new MerkleMap<>();
    MerkleToken token = new MerkleToken();
    final var missingFees = List.of(FcCustomFee.fixedFee(50L, missingToken, feeCollector).asGrpc());
    token.setFeeScheduleFrom(missingFees);
    secondMerkleMap.put(EntityNum.fromLong(missingToken.num()), new MerkleToken());
    final var fees1 = new FcmCustomFeeSchedules(() -> tokens);
    final var fees2 = new FcmCustomFeeSchedules(() -> secondMerkleMap);
    // expect:
    assertNotEquals(fees1, fees2);
    assertNotEquals(fees1.hashCode(), fees2.hashCode());
}
Also used : MerkleToken(com.hedera.services.state.merkle.MerkleToken) MerkleMap(com.swirlds.merkle.map.MerkleMap) EntityNum(com.hedera.services.utils.EntityNum) Test(org.junit.jupiter.api.Test)

Example 10 with EntityNum

use of com.hedera.services.utils.EntityNum in project hedera-services by hashgraph.

the class GetTopicInfoAnswer method checkValidity.

@Override
public ResponseCodeEnum checkValidity(Query query, StateView view) {
    MerkleMap<EntityNum, MerkleTopic> topics = view.topics();
    ConsensusGetTopicInfoQuery op = query.getConsensusGetTopicInfo();
    return validityOf(op, topics);
}
Also used : ConsensusGetTopicInfoQuery(com.hederahashgraph.api.proto.java.ConsensusGetTopicInfoQuery) MerkleTopic(com.hedera.services.state.merkle.MerkleTopic) EntityNum(com.hedera.services.utils.EntityNum)

Aggregations

EntityNum (com.hedera.services.utils.EntityNum)23 Test (org.junit.jupiter.api.Test)15 MerkleAccount (com.hedera.services.state.merkle.MerkleAccount)9 MerkleMap (com.swirlds.merkle.map.MerkleMap)5 FcTokenAllowanceId (com.hedera.services.state.submerkle.FcTokenAllowanceId)4 MerkleToken (com.hedera.services.state.merkle.MerkleToken)3 EntityId (com.hedera.services.state.submerkle.EntityId)3 FcTokenAllowance (com.hedera.services.state.submerkle.FcTokenAllowance)3 ArrayList (java.util.ArrayList)3 TreeMap (java.util.TreeMap)3 ByteString (com.google.protobuf.ByteString)2 MutableStateChildren (com.hedera.services.context.MutableStateChildren)2 MerkleAccountTokens (com.hedera.services.state.merkle.MerkleAccountTokens)2 MerkleTokenRelStatus (com.hedera.services.state.merkle.MerkleTokenRelStatus)2 MerkleTopic (com.hedera.services.state.merkle.MerkleTopic)2 ExpirableTxnRecord (com.hedera.services.state.submerkle.ExpirableTxnRecord)2 AccountID (com.hederahashgraph.api.proto.java.AccountID)2 CryptoGetAccountBalanceQuery (com.hederahashgraph.api.proto.java.CryptoGetAccountBalanceQuery)2 MerkleDataInputStream (com.swirlds.common.merkle.io.MerkleDataInputStream)2 NetworkInfo (com.hedera.services.config.NetworkInfo)1