Search in sources :

Example 1 with GrantedNftAllowance

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

the class CryptoOpsUsageTest method estimatesAdjustAsExpected.

@Test
void estimatesAdjustAsExpected() {
    givenAdjustOp();
    GrantedCryptoAllowance existingCryptoAllowances = GrantedCryptoAllowance.newBuilder().setSpender(proxy).setAmount(100L).build();
    GrantedTokenAllowance existingTokenAllowances = GrantedTokenAllowance.newBuilder().setSpender(proxy).setAmount(100L).setTokenId(IdUtils.asToken("0.0.1000")).build();
    GrantedNftAllowance existingNftAllowances = GrantedNftAllowance.newBuilder().setSpender(proxy).setTokenId(IdUtils.asToken("0.0.1000")).addAllSerialNumbers(List.of()).build();
    var expected = new UsageAccumulator();
    var baseMeta = new BaseTransactionMeta(0, 0);
    var opMeta = new CryptoAdjustAllowanceMeta(txn.getCryptoAdjustAllowance(), txn.getTransactionID().getTransactionValidStart().getSeconds());
    SigUsage sigUsage = new SigUsage(1, sigSize, 1);
    expected.resetForTransaction(baseMeta, sigUsage);
    Key oldKey = FileOpsUsage.asKey(KeyUtils.A_KEY_LIST.getKeyList());
    long oldExpiry = expiry - 1_234L;
    String oldMemo = "Lettuce";
    var ctx = ExtantCryptoContext.newBuilder().setCurrentExpiry(oldExpiry).setCurrentMemo(oldMemo).setCurrentKey(oldKey).setCurrentlyHasProxy(false).setCurrentNumTokenRels(numTokenRels).setCurrentMaxAutomaticAssociations(maxAutoAssociations).setCurrentCryptoAllowances(List.of(existingCryptoAllowances)).setCurrentNftAllowances(List.of(existingNftAllowances)).setCurrentTokenAllowances(List.of(existingTokenAllowances)).build();
    long msgBytesUsed = (adjustOp.getCryptoAllowancesCount() * CRYPTO_ALLOWANCE_SIZE) + (adjustOp.getTokenAllowancesCount() * TOKEN_ALLOWANCE_SIZE) + (adjustOp.getNftAllowancesCount() * NFT_ALLOWANCE_SIZE) + countSerials(adjustOp.getNftAllowancesList()) * LONG_SIZE;
    expected.addBpt(msgBytesUsed);
    long lifetime = ESTIMATOR_UTILS.relativeLifetime(txn, oldExpiry);
    var expectedAdjustedBytes = LONG_SIZE;
    // 3990128
    expected.addRbs(expectedAdjustedBytes * lifetime);
    var actual = new UsageAccumulator();
    subject.cryptoAdjustAllowanceUsage(sigUsage, baseMeta, opMeta, ctx, actual);
    assertEquals(expected, actual);
}
Also used : GrantedTokenAllowance(com.hederahashgraph.api.proto.java.GrantedTokenAllowance) BaseTransactionMeta(com.hedera.services.usage.BaseTransactionMeta) GrantedCryptoAllowance(com.hederahashgraph.api.proto.java.GrantedCryptoAllowance) SigUsage(com.hedera.services.usage.SigUsage) UsageAccumulator(com.hedera.services.usage.state.UsageAccumulator) ByteString(com.google.protobuf.ByteString) GrantedNftAllowance(com.hederahashgraph.api.proto.java.GrantedNftAllowance) Key(com.hederahashgraph.api.proto.java.Key) Test(org.junit.jupiter.api.Test)

Aggregations

ByteString (com.google.protobuf.ByteString)1 BaseTransactionMeta (com.hedera.services.usage.BaseTransactionMeta)1 SigUsage (com.hedera.services.usage.SigUsage)1 UsageAccumulator (com.hedera.services.usage.state.UsageAccumulator)1 GrantedCryptoAllowance (com.hederahashgraph.api.proto.java.GrantedCryptoAllowance)1 GrantedNftAllowance (com.hederahashgraph.api.proto.java.GrantedNftAllowance)1 GrantedTokenAllowance (com.hederahashgraph.api.proto.java.GrantedTokenAllowance)1 Key (com.hederahashgraph.api.proto.java.Key)1 Test (org.junit.jupiter.api.Test)1