use of com.hedera.services.usage.state.UsageAccumulator in project hedera-services by hashgraph.
the class CryptoOpsUsageTest method estimatesApprovalAsExpected.
@Test
void estimatesApprovalAsExpected() {
givenApprovalOp();
var expected = new UsageAccumulator();
var baseMeta = new BaseTransactionMeta(0, 0);
var opMeta = new CryptoApproveAllowanceMeta(txn.getCryptoApproveAllowance(), 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(Collections.emptyList()).setCurrentNftAllowances(Collections.emptyList()).setCurrentTokenAllowances(Collections.emptyList()).build();
long msgBytesUsed = (approveOp.getCryptoAllowancesCount() * CRYPTO_ALLOWANCE_SIZE) + (approveOp.getTokenAllowancesCount() * TOKEN_ALLOWANCE_SIZE) + (approveOp.getNftAllowancesCount() * NFT_ALLOWANCE_SIZE) + countSerials(approveOp.getNftAllowancesList()) * LONG_SIZE;
expected.addBpt(msgBytesUsed);
long lifetime = ESTIMATOR_UTILS.relativeLifetime(txn, oldExpiry);
expected.addRbs(msgBytesUsed * lifetime);
var actual = new UsageAccumulator();
subject.cryptoApproveAllowanceUsage(sigUsage, baseMeta, opMeta, ctx, actual);
assertEquals(expected, actual);
}
use of com.hedera.services.usage.state.UsageAccumulator in project hedera-services by hashgraph.
the class OpsTransferUsageTest method matchesWithLegacyEstimate.
@Test
void matchesWithLegacyEstimate() {
givenOp();
// and given legacy estimate:
final var expected = FeeData.newBuilder().setNetworkdata(FeeComponents.newBuilder().setConstant(1).setBpt(18047).setVpt(3).setRbh(1)).setNodedata(FeeComponents.newBuilder().setConstant(1).setBpt(18047).setVpt(1).setBpr(4)).setServicedata(FeeComponents.newBuilder().setConstant(1).setRbh(904)).build();
// when:
final var accum = new UsageAccumulator();
subject.cryptoTransferUsage(sigUsage, new CryptoTransferMeta(tokenMultiplier, 3, 7, 0), new BaseTransactionMeta(memo.getBytes().length, 3), accum);
// then:
assertEquals(expected, feeDataFrom(accum));
}
use of com.hedera.services.usage.state.UsageAccumulator in project hedera-services by hashgraph.
the class HapiCryptoUpdate method feeFor.
@Override
protected long feeFor(HapiApiSpec spec, Transaction txn, int numPayerKeys) throws Throwable {
try {
final CryptoGetInfoResponse.AccountInfo info = lookupInfo(spec);
FeeCalculator.ActivityMetrics metricsCalc = (_txn, svo) -> {
var ctx = ExtantCryptoContext.newBuilder().setCurrentNumTokenRels(info.getTokenRelationshipsCount()).setCurrentExpiry(info.getExpirationTime().getSeconds()).setCurrentMemo(info.getMemo()).setCurrentKey(info.getKey()).setCurrentlyHasProxy(info.hasProxyAccountID()).setCurrentMaxAutomaticAssociations(info.getMaxAutomaticTokenAssociations()).build();
var baseMeta = new BaseTransactionMeta(_txn.getMemoBytes().size(), 0);
var opMeta = new CryptoUpdateMeta(_txn.getCryptoUpdateAccount(), _txn.getTransactionID().getTransactionValidStart().getSeconds());
var accumulator = new UsageAccumulator();
cryptoOpsUsage.cryptoUpdateUsage(suFrom(svo), baseMeta, opMeta, ctx, accumulator);
return AdapterUtils.feeDataFrom(accumulator);
};
return spec.fees().forActivityBasedOp(HederaFunctionality.CryptoUpdate, metricsCalc, txn, numPayerKeys);
} catch (Throwable ignore) {
return HapiApiSuite.ONE_HBAR;
}
}
use of com.hedera.services.usage.state.UsageAccumulator in project hedera-services by hashgraph.
the class HapiTokenMint method usageEstimate.
private FeeData usageEstimate(TransactionBody txn, SigValueObj svo) throws Throwable {
UsageAccumulator accumulator = new UsageAccumulator();
long lifetime = 0L;
if (subType == SubType.TOKEN_NON_FUNGIBLE_UNIQUE) {
lifetime = info.getExpiry().getSeconds() - txn.getTransactionID().getTransactionValidStart().getSeconds();
}
final var tokenBurnMeta = TOKEN_OPS_USAGE_UTILS.tokenMintUsageFrom(txn, subType, lifetime);
final var baseTransactionMeta = new BaseTransactionMeta(txn.getMemoBytes().size(), 0);
TokenOpsUsage tokenOpsUsage = new TokenOpsUsage();
tokenOpsUsage.tokenMintUsage(suFrom(svo), baseTransactionMeta, tokenBurnMeta, accumulator);
return AdapterUtils.feeDataFrom(accumulator);
}
use of com.hedera.services.usage.state.UsageAccumulator in project hedera-services by hashgraph.
the class HapiTokenPause method usageEstimate.
private FeeData usageEstimate(TransactionBody txn, SigValueObj svo) {
UsageAccumulator accumulator = new UsageAccumulator();
final var tokenPauseMeta = TOKEN_OPS_USAGE_UTILS.tokenPauseUsageFrom();
final var baseTransactionMeta = new BaseTransactionMeta(txn.getMemoBytes().size(), 0);
TokenOpsUsage tokenOpsUsage = new TokenOpsUsage();
tokenOpsUsage.tokenPauseUsage(suFrom(svo), baseTransactionMeta, tokenPauseMeta, accumulator);
return AdapterUtils.feeDataFrom(accumulator);
}
Aggregations