use of com.hedera.services.usage.SigUsage in project hedera-services by hashgraph.
the class CryptoOpsUsageTest method accumulatesBptAndRbhAsExpectedForCryptoCreateWithoutMaxAutoAssociations.
@Test
void accumulatesBptAndRbhAsExpectedForCryptoCreateWithoutMaxAutoAssociations() {
givenCreationOpWithOutMaxAutoAssociaitons();
final ByteString canonicalSig = ByteString.copyFromUtf8("0123456789012345678901234567890123456789012345678901234567890123");
final SignatureMap onePairSigMap = SignatureMap.newBuilder().addSigPair(SignaturePair.newBuilder().setPubKeyPrefix(ByteString.copyFromUtf8("a")).setEd25519(canonicalSig)).build();
final SigUsage singleSigUsage = new SigUsage(1, onePairSigMap.getSerializedSize(), 1);
final var opMeta = new CryptoCreateMeta(txn.getCryptoCreateAccount());
final var baseMeta = new BaseTransactionMeta(memo.length(), 0);
var actual = new UsageAccumulator();
var expected = new UsageAccumulator();
var baseSize = memo.length() + getAccountKeyStorageSize(key) + BASIC_ENTITY_ID_SIZE;
expected.resetForTransaction(baseMeta, singleSigUsage);
expected.addBpt(baseSize + 2 * LONG_SIZE + BOOL_SIZE);
expected.addRbs((CRYPTO_ENTITY_SIZES.fixedBytesInAccountRepr() + baseSize) * secs);
expected.addNetworkRbs(BASIC_ENTITY_ID_SIZE * USAGE_PROPERTIES.legacyReceiptStorageSecs());
subject.cryptoCreateUsage(singleSigUsage, baseMeta, opMeta, actual);
assertEquals(expected, actual);
}
use of com.hedera.services.usage.SigUsage in project hedera-services by hashgraph.
the class CryptoOpsUsageTest method accumulatesBptAndRbhAsExpectedForCryptoCreateWithMaxAutoAssociations.
@Test
void accumulatesBptAndRbhAsExpectedForCryptoCreateWithMaxAutoAssociations() {
givenCreationOpWithMaxAutoAssociaitons();
final ByteString canonicalSig = ByteString.copyFromUtf8("0123456789012345678901234567890123456789012345678901234567890123");
final SignatureMap onePairSigMap = SignatureMap.newBuilder().addSigPair(SignaturePair.newBuilder().setPubKeyPrefix(ByteString.copyFromUtf8("a")).setEd25519(canonicalSig)).build();
final SigUsage singleSigUsage = new SigUsage(1, onePairSigMap.getSerializedSize(), 1);
final var opMeta = new CryptoCreateMeta(txn.getCryptoCreateAccount());
final var baseMeta = new BaseTransactionMeta(memo.length(), 0);
var actual = new UsageAccumulator();
var expected = new UsageAccumulator();
var baseSize = memo.length() + getAccountKeyStorageSize(key) + BASIC_ENTITY_ID_SIZE + INT_SIZE;
expected.resetForTransaction(baseMeta, singleSigUsage);
expected.addBpt(baseSize + 2 * LONG_SIZE + BOOL_SIZE);
expected.addRbs((CRYPTO_ENTITY_SIZES.fixedBytesInAccountRepr() + baseSize) * secs);
expected.addRbs(maxAutoAssociations * secs * CryptoOpsUsage.CREATE_SLOT_MULTIPLIER);
expected.addNetworkRbs(BASIC_ENTITY_ID_SIZE * USAGE_PROPERTIES.legacyReceiptStorageSecs());
subject.cryptoCreateUsage(singleSigUsage, baseMeta, opMeta, actual);
assertEquals(expected, actual);
}
use of com.hedera.services.usage.SigUsage 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);
}
use of com.hedera.services.usage.SigUsage 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);
}
Aggregations