Search in sources :

Example 21 with Timestamp

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

the class BasicFcfsUsagePricesTest method getsTransferUsagePricesPastCurrentBeforeNextExpiry.

@Test
void getsTransferUsagePricesPastCurrentBeforeNextExpiry() throws Exception {
    // given:
    subject.loadPriceSchedules();
    Timestamp at = Timestamp.newBuilder().setSeconds(nextExpiry - 1).build();
    // when:
    Map<SubType, FeeData> actual = subject.pricesGiven(ContractCall, at);
    // then:
    assertEquals(nextContractCallPrices, actual);
}
Also used : SubType(com.hederahashgraph.api.proto.java.SubType) Timestamp(com.hederahashgraph.api.proto.java.Timestamp) FeeData(com.hederahashgraph.api.proto.java.FeeData) Test(org.junit.jupiter.api.Test)

Example 22 with Timestamp

use of com.hederahashgraph.api.proto.java.Timestamp 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 23 with Timestamp

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

the class PrecompilePricingUtilsTest method calculatesMinimumPrice.

@Test
void calculatesMinimumPrice() throws IOException {
    Timestamp timestamp = Timestamp.newBuilder().setSeconds(123456789).build();
    given(exchange.rate(timestamp)).willReturn(exchangeRate);
    given(assetLoader.loadCanonicalPrices()).willReturn(Map.of(HederaFunctionality.TokenAssociateToAccount, Map.of(SubType.DEFAULT, BigDecimal.valueOf(COST))));
    given(exchangeRate.getCentEquiv()).willReturn(CENTS_RATE);
    given(exchangeRate.getHbarEquiv()).willReturn(HBAR_RATE);
    PrecompilePricingUtils subject = new PrecompilePricingUtils(assetLoader, exchange);
    long price = subject.getMinimumPriceInTinybars(PrecompilePricingUtils.GasCostType.ASSOCIATE, timestamp);
    assertEquals(USD_TO_TINYCENTS.multiply(BigDecimal.valueOf(COST * HBAR_RATE / CENTS_RATE)).longValue(), price);
}
Also used : Timestamp(com.hederahashgraph.api.proto.java.Timestamp) Test(org.junit.jupiter.api.Test)

Example 24 with Timestamp

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

the class TestHelper method getDefaultCurrentTimestampUTC.

/**
 * Gets the current UTC timestamp with default winding back seconds.
 */
public static synchronized Timestamp getDefaultCurrentTimestampUTC() {
    Timestamp rv = ProtoCommonUtils.getCurrentTimestampUTC(DEFAULT_WIND_SEC);
    if (rv.getNanos() == lastNano) {
        try {
            Thread.sleep(0, 1);
        } catch (InterruptedException e) {
        }
        rv = ProtoCommonUtils.getCurrentTimestampUTC(DEFAULT_WIND_SEC);
        lastNano = rv.getNanos();
    }
    return rv;
}
Also used : Timestamp(com.hederahashgraph.api.proto.java.Timestamp)

Example 25 with Timestamp

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

the class ContractUpdateResourceUsage method usageGiven.

@Override
public FeeData usageGiven(TransactionBody txn, SigValueObj sigUsage, StateView view) throws InvalidTxBodyException {
    try {
        final var id = fromContractId(txn.getContractUpdateInstance().getContractID());
        Timestamp expiry = lookupAccountExpiry(id, view.accounts());
        return usageEstimator.getContractUpdateTxFeeMatrices(txn, expiry, sigUsage);
    } catch (Exception e) {
        log.debug("Unable to deduce ContractUpdate usage for {}, using defaults", txn.getTransactionID(), e);
        return FeeData.getDefaultInstance();
    }
}
Also used : Timestamp(com.hederahashgraph.api.proto.java.Timestamp) InvalidTxBodyException(com.hederahashgraph.exception.InvalidTxBodyException)

Aggregations

Timestamp (com.hederahashgraph.api.proto.java.Timestamp)26 Test (org.junit.jupiter.api.Test)12 Instant (java.time.Instant)8 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)8 EntityId (com.hedera.mirror.common.domain.entity.EntityId)5 DomainUtils (com.hedera.mirror.common.util.DomainUtils)5 Consumer (java.util.function.Consumer)5 Range (com.google.common.collect.Range)4 Entity (com.hedera.mirror.common.domain.entity.Entity)4 EntityType (com.hedera.mirror.common.domain.entity.EntityType)4 ACCOUNT (com.hedera.mirror.common.domain.entity.EntityType.ACCOUNT)4 NftTransferId (com.hedera.mirror.common.domain.token.NftTransferId)4 Transaction (com.hedera.mirror.common.domain.transaction.Transaction)4 AccountID (com.hederahashgraph.api.proto.java.AccountID)4 Duration (com.hederahashgraph.api.proto.java.Duration)4 ResponseCodeEnum (com.hederahashgraph.api.proto.java.ResponseCodeEnum)4 TransactionBody (com.hederahashgraph.api.proto.java.TransactionBody)4 TransactionRecord (com.hederahashgraph.api.proto.java.TransactionRecord)4 AbstractEntity (com.hedera.mirror.common.domain.entity.AbstractEntity)3 EntityIdEndec (com.hedera.mirror.common.domain.entity.EntityIdEndec)3