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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations