mirror of
https://github.com/lightninglabs/loop.git
synced 2026-08-13 12:33:03 +02:00
test: fix nil dereference
fixes tests TestLoopOutFailOffchain, TestLoopOutPaymentParameters
This commit is contained in:
parent
fe747a0670
commit
cc26813f24
2 changed files with 19 additions and 2 deletions
|
|
@ -140,6 +140,18 @@ func testLoopOutPaymentParameters(t *testing.T) {
|
||||||
// this to prevent a blocked channel in the mock.
|
// this to prevent a blocked channel in the mock.
|
||||||
ctx.AssertRegisterConf(false, defaultConfirmations)
|
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
|
// 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.
|
// parameters don't play a role in the remainder of the swap process.
|
||||||
cancel()
|
cancel()
|
||||||
|
|
|
||||||
|
|
@ -151,7 +151,7 @@ func (ctx *Context) AssertPaid(
|
||||||
return done
|
return done
|
||||||
}
|
}
|
||||||
|
|
||||||
// Assert that client pays swap invoice.
|
// Assert that the client pays swap invoice.
|
||||||
for {
|
for {
|
||||||
var swapPayment RouterPaymentChannelMessage
|
var swapPayment RouterPaymentChannelMessage
|
||||||
select {
|
select {
|
||||||
|
|
@ -171,7 +171,12 @@ func (ctx *Context) AssertPaid(
|
||||||
|
|
||||||
done := func(result error) {
|
done := func(result error) {
|
||||||
if result != nil {
|
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
|
return
|
||||||
}
|
}
|
||||||
swapPayment.Updates <- lndclient.PaymentStatus{
|
swapPayment.Updates <- lndclient.PaymentStatus{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue