routerrpc: inject clock for testable expiry validation

Refactors payment request expiry validation to use an injected clock
dependency instead of calling time.Now() directly.
This commit is contained in:
Erick Cestari committed 2025-06-20 09:23:02 -03:00
1 parent a27bd69b9c
commit c01a66783f
3 files changed
+18 -4

No files matched your search

+6
View File
@@ -5,9 +5,11 @@ import (
"context"
"encoding/hex"
"testing"
"time"
"github.com/btcsuite/btcd/btcutil"
"github.com/btcsuite/btcd/chaincfg"
"github.com/lightningnetwork/lnd/lnmock"
"github.com/lightningnetwork/lnd/lnrpc"
"github.com/lightningnetwork/lnd/lnwire"
"github.com/lightningnetwork/lnd/record"
@@ -509,6 +511,9 @@ func TestExtractIntentFromSendRequest(t *testing.T) {
target, err := route.NewVertexFromBytes(destNodeBytes)
require.NoError(t, err)
mockClock := &lnmock.MockClock{}
mockClock.On("Now").Return(time.Date(2025, 3, 1, 13, 0, 0, 0, time.UTC))
testCases := []extractIntentTestCase{
{
name: "Time preference out of range",
@@ -706,6 +711,7 @@ func TestExtractIntentFromSendRequest(t *testing.T) {
return false
},
ActiveNetParams: &chaincfg.RegressionNetParams,
Clock: mockClock,
},
sendReq: &SendPaymentRequest{
Amt: int64(paymentAmount),