41 lines
1.4 KiB
Java
41 lines
1.4 KiB
Java
package com.ruoyi.task;
|
|
|
|
import org.junit.Assert;
|
|
import org.junit.Test;
|
|
|
|
import java.util.Date;
|
|
|
|
/** 支付扫描链上交易时间窗口边界测试。 */
|
|
public class TronPaymentTaskTest {
|
|
private static final long CREATED_AT = 1_700_000_000_000L;
|
|
|
|
@Test
|
|
public void shouldAcceptTransactionInsidePaymentWindow() {
|
|
Assert.assertTrue(TronPaymentTask.isTransactionInPaymentWindow(
|
|
new Date(CREATED_AT), CREATED_AT + 60_000L));
|
|
}
|
|
|
|
@Test
|
|
public void shouldAllowFiveSecondsClockSkewBeforeCreation() {
|
|
Assert.assertTrue(TronPaymentTask.isTransactionInPaymentWindow(
|
|
new Date(CREATED_AT), CREATED_AT - 5_000L));
|
|
Assert.assertFalse(TronPaymentTask.isTransactionInPaymentWindow(
|
|
new Date(CREATED_AT), CREATED_AT - 5_001L));
|
|
}
|
|
|
|
@Test
|
|
public void shouldRejectTransactionAfterExpiration() {
|
|
Assert.assertTrue(TronPaymentTask.isTransactionInPaymentWindow(
|
|
new Date(CREATED_AT), CREATED_AT + 10L * 60L * 1000L));
|
|
Assert.assertFalse(TronPaymentTask.isTransactionInPaymentWindow(
|
|
new Date(CREATED_AT), CREATED_AT + 10L * 60L * 1000L + 1L));
|
|
}
|
|
|
|
@Test
|
|
public void shouldRejectMissingTime() {
|
|
Assert.assertFalse(TronPaymentTask.isTransactionInPaymentWindow(null, CREATED_AT));
|
|
Assert.assertFalse(TronPaymentTask.isTransactionInPaymentWindow(
|
|
new Date(CREATED_AT), 0L));
|
|
}
|
|
}
|