Search in sources :

Example 16 with Timestamp

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

the class UtilityTest method instantToTimestamp.

@ParameterizedTest(name = "with seconds {0} and nanos {1}")
@CsvSource({ "1569936354, 901", "0, 901", "1569936354, 0", "0,0" })
void instantToTimestamp(long seconds, int nanos) {
    Instant instant = Instant.ofEpochSecond(seconds).plusNanos(nanos);
    Timestamp test = Utility.instantToTimestamp(instant);
    assertAll(() -> assertEquals(instant.getEpochSecond(), test.getSeconds()), () -> assertEquals(instant.getNano(), test.getNanos()));
}
Also used : Instant(java.time.Instant) Timestamp(com.hederahashgraph.api.proto.java.Timestamp) CsvSource(org.junit.jupiter.params.provider.CsvSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 17 with Timestamp

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

the class SmartContractFeeBuilder method getContractUpdateStorageBytesSec.

private long getContractUpdateStorageBytesSec(TransactionBody txBody, Timestamp contractExpiryTime) {
    long storageSize = 0;
    ContractUpdateTransactionBody contractUpdateTxBody = txBody.getContractUpdateInstance();
    if (contractUpdateTxBody.hasAdminKey()) {
        storageSize += getAccountKeyStorageSize(contractUpdateTxBody.getAdminKey());
    }
    if (contractUpdateTxBody.getMemo() != null) {
        storageSize += contractUpdateTxBody.getMemoBytes().size();
    }
    Instant expirationTime = RequestBuilder.convertProtoTimeStamp(contractExpiryTime);
    Timestamp txValidStartTimestamp = txBody.getTransactionID().getTransactionValidStart();
    Instant txValidStartTime = RequestBuilder.convertProtoTimeStamp(txValidStartTimestamp);
    Duration duration = Duration.between(txValidStartTime, expirationTime);
    long seconds = Math.min(duration.getSeconds(), MAX_ENTITY_LIFETIME);
    storageSize = storageSize * seconds;
    return storageSize;
}
Also used : Instant(java.time.Instant) Duration(java.time.Duration) ContractUpdateTransactionBody(com.hederahashgraph.api.proto.java.ContractUpdateTransactionBody) Timestamp(com.hederahashgraph.api.proto.java.Timestamp)

Example 18 with Timestamp

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

the class RequestBuilderTest method assertGetFileUpdateBuilder.

@Test
void assertGetFileUpdateBuilder() throws InvalidProtocolBufferException {
    Timestamp fileExpiration = Timestamp.newBuilder().setSeconds(123_456L).build();
    var transaction = RequestBuilder.getFileUpdateBuilder(accountId.getAccountNum(), accountId.getRealmNum(), accountId.getShardNum(), nodeId.getAccountNum(), nodeId.getRealmNum(), nodeId.getShardNum(), transactionFee, startTime, fileExpiration, transactionDuration, generateRecord, memo, hash, fileID, keyList);
    var tb = TransactionBody.parseFrom(transaction.getBodyBytes());
    assertEquals(memo, tb.getMemo());
    assertEquals(generateRecord, tb.getGenerateRecord());
    assertEquals(transactionFee, tb.getTransactionFee());
    assertEquals(startTime, tb.getTransactionID().getTransactionValidStart());
    assertEquals(transactionDuration, tb.getTransactionValidDuration());
    assertEquals(transactionFee, tb.getTransactionFee());
    assertEquals(hash, tb.getFileUpdate().getContents());
    assertEquals(fileID, tb.getFileUpdate().getFileID());
    assertEquals(keyList, tb.getFileUpdate().getKeys());
    assertEquals(fileExpiration, tb.getFileUpdate().getExpirationTime());
    assertEquals(nodeId.getAccountNum(), tb.getNodeAccountID().getAccountNum());
    assertEquals(nodeId.getRealmNum(), tb.getNodeAccountID().getRealmNum());
    assertEquals(nodeId.getShardNum(), tb.getNodeAccountID().getShardNum());
    assertEquals(accountId.getAccountNum(), tb.getTransactionID().getAccountID().getAccountNum());
    assertEquals(accountId.getRealmNum(), tb.getTransactionID().getAccountID().getRealmNum());
    assertEquals(accountId.getShardNum(), tb.getTransactionID().getAccountID().getShardNum());
}
Also used : Timestamp(com.hederahashgraph.api.proto.java.Timestamp) Test(org.junit.jupiter.api.Test)

Example 19 with Timestamp

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

the class RequestBuilderTest method assertGetFileCreateBuilder.

@Test
void assertGetFileCreateBuilder() throws InvalidProtocolBufferException {
    Timestamp fileExpiration = Timestamp.newBuilder().setSeconds(123_456L).build();
    List<Key> keyList = List.of(validED25519Key);
    var transaction = RequestBuilder.getFileCreateBuilder(accountId.getAccountNum(), accountId.getRealmNum(), accountId.getShardNum(), nodeId.getAccountNum(), nodeId.getRealmNum(), nodeId.getShardNum(), transactionFee, startTime, transactionDuration, generateRecord, memo, hash, fileExpiration, keyList);
    var tb = TransactionBody.parseFrom(transaction.getBodyBytes());
    assertEquals(memo, tb.getMemo());
    assertEquals(generateRecord, tb.getGenerateRecord());
    assertEquals(transactionFee, tb.getTransactionFee());
    assertEquals(startTime, tb.getTransactionID().getTransactionValidStart());
    assertEquals(transactionDuration, tb.getTransactionValidDuration());
    assertEquals(transactionFee, tb.getTransactionFee());
    assertEquals(hash, tb.getFileCreate().getContents());
    assertEquals(fileExpiration, tb.getFileCreate().getExpirationTime());
    assertEquals(nodeId.getAccountNum(), tb.getNodeAccountID().getAccountNum());
    assertEquals(nodeId.getRealmNum(), tb.getNodeAccountID().getRealmNum());
    assertEquals(nodeId.getShardNum(), tb.getNodeAccountID().getShardNum());
    assertEquals(accountId.getAccountNum(), tb.getTransactionID().getAccountID().getAccountNum());
    assertEquals(accountId.getRealmNum(), tb.getTransactionID().getAccountID().getRealmNum());
    assertEquals(accountId.getShardNum(), tb.getTransactionID().getAccountID().getShardNum());
}
Also used : Timestamp(com.hederahashgraph.api.proto.java.Timestamp) Key(com.hederahashgraph.api.proto.java.Key) Test(org.junit.jupiter.api.Test)

Example 20 with Timestamp

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

the class BasicFcfsUsagePricesTest method getsTransferUsagePricesAtCurrent.

@Test
void getsTransferUsagePricesAtCurrent() {
    // given:
    subject.loadPriceSchedules();
    Timestamp at = Timestamp.newBuilder().setSeconds(currentExpiry - 1).build();
    // when:
    Map<SubType, FeeData> actual = subject.pricesGiven(ContractCall, at);
    // then:
    assertEquals(currentContractCallPrices, 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)

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