Skip to content

Commit cc26813

Browse files
committed
test: fix nil dereference
fixes tests TestLoopOutFailOffchain, TestLoopOutPaymentParameters
1 parent fe747a0 commit cc26813

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

loopout_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,18 @@ func testLoopOutPaymentParameters(t *testing.T) {
140140
// this to prevent a blocked channel in the mock.
141141
ctx.AssertRegisterConf(false, defaultConfirmations)
142142

143+
// Drive both payments to a terminal state so the async payment
144+
// goroutines complete and don't hit a nil status path.
145+
for _, p := range payments {
146+
select {
147+
case p.Updates <- lndclient.PaymentStatus{
148+
State: lnrpc.Payment_SUCCEEDED,
149+
}:
150+
case <-time.After(test.Timeout):
151+
t.Fatalf("could not send payment update")
152+
}
153+
}
154+
143155
// Cancel the swap. There is nothing else we need to assert. The payment
144156
// parameters don't play a role in the remainder of the swap process.
145157
cancel()

test/context.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ func (ctx *Context) AssertPaid(
151151
return done
152152
}
153153

154-
// Assert that client pays swap invoice.
154+
// Assert that the client pays swap invoice.
155155
for {
156156
var swapPayment RouterPaymentChannelMessage
157157
select {
@@ -171,7 +171,12 @@ func (ctx *Context) AssertPaid(
171171

172172
done := func(result error) {
173173
if result != nil {
174-
swapPayment.Errors <- result
174+
// Send a terminal FAILED status so the client
175+
// always receives a non-nil PaymentStatus and
176+
// won't dereference nil.
177+
swapPayment.Updates <- lndclient.PaymentStatus{
178+
State: lnrpc.Payment_FAILED,
179+
}
175180
return
176181
}
177182
swapPayment.Updates <- lndclient.PaymentStatus{

0 commit comments

Comments
 (0)