Search in sources :

Example 1 with TimeProvider

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));
}
Also used : TimeProvider(co.rsk.util.TimeProvider) TestSystemProperties(co.rsk.config.TestSystemProperties)

Example 2 with TimeProvider

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());
}
Also used : TimeProvider(co.rsk.util.TimeProvider) Test(org.junit.Test)

Example 3 with TimeProvider

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();
}
Also used : TimeProvider(co.rsk.util.TimeProvider) Test(org.junit.Test)

Example 4 with TimeProvider

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());
}
Also used : TimeProvider(co.rsk.util.TimeProvider) Test(org.junit.Test)

Aggregations

TimeProvider (co.rsk.util.TimeProvider)4 Test (org.junit.Test)3 TestSystemProperties (co.rsk.config.TestSystemProperties)1