@@ -504,61 +504,86 @@ func testListPayments(ht *lntest.HarnessTest) {
504504 expected bool
505505 }
506506
507- // Create test cases to check the timestamp filters.
508- createCases := func (createTimeSeconds uint64 ) []testCase {
507+ // Create test cases with proper rounding for start and end dates.
508+ createCases := func (startTimeSeconds ,
509+ endTimeSeconds uint64 ) []testCase {
510+
509511 return []testCase {
510512 {
511513 // Use a start date same as the creation date
512- // should return us the item.
514+ // (truncated) should return us the item.
513515 name : "exact start date" ,
514- startDate : createTimeSeconds ,
516+ startDate : startTimeSeconds ,
515517 expected : true ,
516518 },
517519 {
518520 // Use an earlier start date should return us
519521 // the item.
520522 name : "earlier start date" ,
521- startDate : createTimeSeconds - 1 ,
523+ startDate : startTimeSeconds - 1 ,
522524 expected : true ,
523525 },
524526 {
525527 // Use a future start date should return us
526528 // nothing.
527529 name : "future start date" ,
528- startDate : createTimeSeconds + 1 ,
530+ startDate : startTimeSeconds + 1 ,
529531 expected : false ,
530532 },
531533 {
532534 // Use an end date same as the creation date
533- // should return us the item.
535+ // (ceiling) should return us the item.
534536 name : "exact end date" ,
535- endDate : createTimeSeconds ,
537+ endDate : endTimeSeconds ,
536538 expected : true ,
537539 },
538540 {
539541 // Use an end date in the future should return
540542 // us the item.
541543 name : "future end date" ,
542- endDate : createTimeSeconds + 1 ,
544+ endDate : endTimeSeconds + 1 ,
543545 expected : true ,
544546 },
545547 {
546548 // Use an earlier end date should return us
547549 // nothing.
548- name : "earlier end date" ,
549- endDate : createTimeSeconds - 1 ,
550+ name : "earlier end date" ,
551+ // The native sql backend has a higher
552+ // precision than the kv backend, the native sql
553+ // backend uses microseconds, the kv backend
554+ // when filtering uses seconds so we need to
555+ // subtract 2 seconds to ensure the payment is
556+ // not included.
557+ // We could also truncate before inserting
558+ // into the sql db but I rather relax this test
559+ // here.
560+ endDate : endTimeSeconds - 2 ,
550561 expected : false ,
551562 },
552563 }
553564 }
554565
555- // Get the payment creation time in seconds.
556- paymentCreateSeconds := uint64 (
557- p .CreationTimeNs / time .Second .Nanoseconds (),
566+ // Get the payment creation time in seconds, using different approaches
567+ // for start and end date comparisons to avoid rounding issues.
568+ creationTime := time .Unix (0 , p .CreationTimeNs )
569+
570+ // For start date comparisons: use truncation (floor) to include
571+ // payments from the beginning of that second.
572+ paymentCreateSecondsStart := uint64 (
573+ creationTime .Truncate (time .Second ).Unix (),
574+ )
575+
576+ // For end date comparisons: use ceiling to include payments up to the
577+ // end of that second.
578+ paymentCreateSecondsEnd := uint64 (
579+ (p .CreationTimeNs + time .Second .Nanoseconds () - 1 ) /
580+ time .Second .Nanoseconds (),
558581 )
559582
560583 // Create test cases from the payment creation time.
561- testCases := createCases (paymentCreateSeconds )
584+ testCases := createCases (
585+ paymentCreateSecondsStart , paymentCreateSecondsEnd ,
586+ )
562587
563588 // We now check the timestamp filters in `ListPayments`.
564589 for _ , tc := range testCases {
@@ -578,7 +603,9 @@ func testListPayments(ht *lntest.HarnessTest) {
578603 }
579604
580605 // Create test cases from the invoice creation time.
581- testCases = createCases (uint64 (invoice .CreationDate ))
606+ testCases = createCases (
607+ uint64 (invoice .CreationDate ), uint64 (invoice .CreationDate ),
608+ )
582609
583610 // We now do the same check for `ListInvoices`.
584611 for _ , tc := range testCases {
0 commit comments