test: fix nil dereference

fixes tests TestLoopOutFailOffchain,
TestLoopOutPaymentParameters
This commit is contained in:
Slyghtning 2025-08-19 14:09:02 +02:00
parent fe747a0670
commit cc26813f24
No known key found for this signature in database
GPG key ID: F82D456EA023C9BF
2 changed files with 19 additions and 2 deletions

View file

@ -140,6 +140,18 @@ func testLoopOutPaymentParameters(t *testing.T) {
// this to prevent a blocked channel in the mock.
ctx.AssertRegisterConf(false, defaultConfirmations)
// Drive both payments to a terminal state so the async payment
// goroutines complete and don't hit a nil status path.
for _, p := range payments {
select {
case p.Updates <- lndclient.PaymentStatus{
State: lnrpc.Payment_SUCCEEDED,
}:
case <-time.After(test.Timeout):
t.Fatalf("could not send payment update")
}
}
// Cancel the swap. There is nothing else we need to assert. The payment
// parameters don't play a role in the remainder of the swap process.
cancel()

View file

@ -151,7 +151,7 @@ func (ctx *Context) AssertPaid(
return done
}
// Assert that client pays swap invoice.
// Assert that the client pays swap invoice.
for {
var swapPayment RouterPaymentChannelMessage
select {
@ -171,7 +171,12 @@ func (ctx *Context) AssertPaid(
done := func(result error) {
if result != nil {
swapPayment.Errors <- result
// Send a terminal FAILED status so the client
// always receives a non-nil PaymentStatus and
// won't dereference nil.
swapPayment.Updates <- lndclient.PaymentStatus{
State: lnrpc.Payment_FAILED,
}
return
}
swapPayment.Updates <- lndclient.PaymentStatus{