Search in sources :

Example 1 with ExchangeRates

use of com.hedera.services.state.submerkle.ExchangeRates in project hedera-services by hashgraph.

the class MerkleNetworkContextTest method setup.

@BeforeEach
void setup() {
    congestionStarts = new Instant[] { Instant.ofEpochSecond(1_234_567L, 54321L), Instant.ofEpochSecond(1_234_789L, 12345L) };
    consensusTimeOfLastHandledTxn = Instant.ofEpochSecond(1_234_567L, 54321L);
    lastMidnightBoundaryCheck = consensusTimeOfLastHandledTxn.minusSeconds(123L);
    seqNo = mock(SequenceNumber.class);
    given(seqNo.current()).willReturn(1234L);
    seqNoCopy = mock(SequenceNumber.class);
    given(seqNo.copy()).willReturn(seqNoCopy);
    midnightRateSet = new ExchangeRates(1, 14, 1_234_567L, 1, 15, 2_345_678L);
    midnightRateSetCopy = midnightRateSet.copy();
    usageSnapshots = new DeterministicThrottle.UsageSnapshot[] { new DeterministicThrottle.UsageSnapshot(123L, consensusTimeOfLastHandledTxn), new DeterministicThrottle.UsageSnapshot(456L, consensusTimeOfLastHandledTxn.plusSeconds(1L)) };
    gasLimitDeterministicThrottle = new GasLimitDeterministicThrottle(1234);
    gasLimitUsageSnapshot = new DeterministicThrottle.UsageSnapshot(1234L, consensusTimeOfLastHandledTxn);
    serdes = mock(DomainSerdes.class, RETURNS_DEEP_STUBS);
    MerkleNetworkContext.serdes = serdes;
    subject = new MerkleNetworkContext(consensusTimeOfLastHandledTxn, seqNo, lastScannedEntity, midnightRateSet);
    subject.setUsageSnapshots(usageSnapshots);
    subject.setGasThrottleUsageSnapshot(gasLimitUsageSnapshot);
    subject.setCongestionLevelStarts(congestionStarts());
    subject.setStateVersion(stateVersion);
    subject.updateAutoRenewSummaryCounts((int) entitiesScannedThisSecond, (int) entitiesTouchedThisSecond);
    subject.setLastMidnightBoundaryCheck(lastMidnightBoundaryCheck);
    subject.setPreparedUpdateFileNum(preparedUpdateFileNum);
    subject.setPreparedUpdateFileHash(preparedUpdateFileHash);
}
Also used : SequenceNumber(com.hedera.services.state.submerkle.SequenceNumber) ExchangeRates(com.hedera.services.state.submerkle.ExchangeRates) DomainSerdes(com.hedera.services.state.serdes.DomainSerdes) GasLimitDeterministicThrottle(com.hedera.services.throttles.GasLimitDeterministicThrottle) DeterministicThrottle(com.hedera.services.throttles.DeterministicThrottle) GasLimitDeterministicThrottle(com.hedera.services.throttles.GasLimitDeterministicThrottle) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with ExchangeRates

use of com.hedera.services.state.submerkle.ExchangeRates in project hedera-services by hashgraph.

the class NetworkCtxManagerTest method advancesClockAsExpectedWhenPassingMidnightAfterBoundaryCheckIntervalElapsedFromLastCheck.

@Test
void advancesClockAsExpectedWhenPassingMidnightAfterBoundaryCheckIntervalElapsedFromLastCheck() {
    // setup:
    var oldMidnightRates = new ExchangeRates(1, 12, 1_234_567L, 1, 15, 2_345_678L);
    var curRates = new ExchangeRates(1, 120, 1_234_567L, 1, 150, 2_345_678L);
    // and:
    subject.setShouldUpdateMidnightRates(shouldUpdateMidnightRates);
    Instant lastBoundaryCheck = sometimeNextDay.minusSeconds(mockDynamicProps.ratesMidnightCheckInterval());
    given(shouldUpdateMidnightRates.test(lastBoundaryCheck, sometimeNextDay)).willReturn(true);
    given(exchange.activeRates()).willReturn(curRates.toGrpc());
    given(networkCtx.lastMidnightBoundaryCheck()).willReturn(lastBoundaryCheck);
    given(networkCtx.midnightRates()).willReturn(oldMidnightRates);
    given(networkCtx.consensusTimeOfLastHandledTxn()).willReturn(sometime);
    // when:
    subject.advanceConsensusClockTo(sometimeNextDay);
    // then:
    verify(networkCtx).setConsensusTimeOfLastHandledTxn(sometimeNextDay);
    verify(networkCtx).setLastMidnightBoundaryCheck(sometimeNextDay);
    assertEquals(oldMidnightRates, curRates);
}
Also used : Instant(java.time.Instant) ExchangeRates(com.hedera.services.state.submerkle.ExchangeRates) Test(org.junit.jupiter.api.Test)

Example 3 with ExchangeRates

use of com.hedera.services.state.submerkle.ExchangeRates in project hedera-services by hashgraph.

the class CurrencyCallbacksTest method ratesCbAsExpectedWithExistingMidnightRates.

@Test
void ratesCbAsExpectedWithExistingMidnightRates() {
    // setup:
    curMidnightRates = new ExchangeRates(1, 120, 1_234_567L, 1, 150, 2_345_678L);
    // and:
    var rates = new ExchangeRates(1, 12, 1_234_567L, 1, 15, 2_345_678L);
    var grpcRates = rates.toGrpc();
    given(midnightRates.get()).willReturn(curMidnightRates);
    // when:
    subject.exchangeRatesCb().accept(grpcRates);
    // then:
    verify(exchange).updateRates(grpcRates);
    assertNotEquals(curMidnightRates, rates);
}
Also used : ExchangeRates(com.hedera.services.state.submerkle.ExchangeRates) Test(org.junit.jupiter.api.Test)

Example 4 with ExchangeRates

use of com.hedera.services.state.submerkle.ExchangeRates in project hedera-services by hashgraph.

the class CurrencyCallbacksTest method ratesCbAsExpectedWithMissingMidnightRates.

@Test
void ratesCbAsExpectedWithMissingMidnightRates() {
    // setup:
    curMidnightRates = new ExchangeRates();
    // and:
    var rates = new ExchangeRates(1, 12, 1_234_567L, 1, 15, 2_345_678L);
    var grpcRates = rates.toGrpc();
    given(midnightRates.get()).willReturn(curMidnightRates);
    // when:
    subject.exchangeRatesCb().accept(grpcRates);
    // then:
    verify(exchange).updateRates(grpcRates);
    assertEquals(curMidnightRates, rates);
}
Also used : ExchangeRates(com.hedera.services.state.submerkle.ExchangeRates) Test(org.junit.jupiter.api.Test)

Example 5 with ExchangeRates

use of com.hedera.services.state.submerkle.ExchangeRates in project hedera-services by hashgraph.

the class TxnReceiptTest method scheduleCreateInterconversionWorks.

@Test
void scheduleCreateInterconversionWorks() {
    final var scheduleId = IdUtils.asSchedule("0.0.123");
    final var receipt = TransactionReceipt.newBuilder().setExchangeRate(new ExchangeRates().toGrpc()).setScheduleID(scheduleId).setScheduledTransactionID(scheduledTxnId).build();
    final var cut = TxnReceipt.fromGrpc(receipt);
    final var back = TxnReceipt.convert(cut);
    assertEquals(receipt, back);
}
Also used : ExchangeRates(com.hedera.services.state.submerkle.ExchangeRates) Test(org.junit.jupiter.api.Test)

Aggregations

ExchangeRates (com.hedera.services.state.submerkle.ExchangeRates)5 Test (org.junit.jupiter.api.Test)4 DomainSerdes (com.hedera.services.state.serdes.DomainSerdes)1 SequenceNumber (com.hedera.services.state.submerkle.SequenceNumber)1 DeterministicThrottle (com.hedera.services.throttles.DeterministicThrottle)1 GasLimitDeterministicThrottle (com.hedera.services.throttles.GasLimitDeterministicThrottle)1 Instant (java.time.Instant)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1