use of co.rsk.util.TimeProvider in project rskj by rsksmart.
the class BlockValidatorTest method blockTimeStampValidation.
private void blockTimeStampValidation(int validPeriod, long baseTimeStamp, BlockHeader header, Block block, NetworkParameters bitcoinNetworkParameters, boolean irisEnabled) {
TestSystemProperties testSystemProperties = blockTimeStampValidationProperties(irisEnabled);
TimeProvider timeProvider = mock(TimeProvider.class);
when(timeProvider.currentTimeMillis()).thenReturn(baseTimeStamp * 1000 + validPeriod);
BlockValidatorImpl validator = new BlockValidatorBuilder(testSystemProperties).addBlockTimeStampValidation(validPeriod, timeProvider, bitcoinNetworkParameters).build();
when(header.getTimestamp()).thenReturn(baseTimeStamp + 2 * validPeriod);
Assert.assertFalse(validator.isValid(block));
when(header.getTimestamp()).thenReturn(baseTimeStamp + validPeriod);
Assert.assertTrue(validator.isValid(block));
}
use of co.rsk.util.TimeProvider in project rskj by rsksmart.
the class SubmissionRateLimitHandlerTest method isSubmissionAllowed_WhenEnabledAndLimitNotExceeded_ThenShouldReturnTrue.
@Test
public void isSubmissionAllowed_WhenEnabledAndLimitNotExceeded_ThenShouldReturnTrue() {
TimeProvider timeProvider = mock(TimeProvider.class);
SubmissionRateLimitHandler handler = new SubmissionRateLimitHandler(1L, timeProvider);
doReturn(1L).when(timeProvider).currentTimeMillis();
assertTrue(handler.isSubmissionAllowed());
doReturn(2L).when(timeProvider).currentTimeMillis();
handler.onSubmit();
doReturn(3L).when(timeProvider).currentTimeMillis();
assertTrue(handler.isSubmissionAllowed());
}
use of co.rsk.util.TimeProvider in project rskj by rsksmart.
the class SubmissionRateLimitHandlerTest method isSubmissionAllowed_WhenDisabled_ThenShouldReturnTrue.
@Test
public void isSubmissionAllowed_WhenDisabled_ThenShouldReturnTrue() {
TimeProvider timeProvider = mock(TimeProvider.class);
SubmissionRateLimitHandler handler = new SubmissionRateLimitHandler(0L, timeProvider);
assertTrue(handler.isSubmissionAllowed());
verify(timeProvider, never()).currentTimeMillis();
}
use of co.rsk.util.TimeProvider in project rskj by rsksmart.
the class SubmissionRateLimitHandlerTest method isSubmissionAllowed_WhenEnabledAndLimitExceeded_ThenShouldReturnFalse.
@Test
public void isSubmissionAllowed_WhenEnabledAndLimitExceeded_ThenShouldReturnFalse() {
TimeProvider timeProvider = mock(TimeProvider.class);
SubmissionRateLimitHandler handler = new SubmissionRateLimitHandler(1L, timeProvider);
doReturn(1L).when(timeProvider).currentTimeMillis();
assertTrue(handler.isSubmissionAllowed());
doReturn(2L).when(timeProvider).currentTimeMillis();
handler.onSubmit();
doReturn(2L).when(timeProvider).currentTimeMillis();
assertFalse(handler.isSubmissionAllowed());
}
Aggregations