mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-08-27 14:11:04 +02:00
multi: fix linter issues
This commit is contained in:
@@ -144,7 +144,9 @@ func TestKVPaymentsDBSwitchFail(t *testing.T) {
|
|||||||
attempt.AttemptID = 1
|
attempt.AttemptID = 1
|
||||||
_, err = paymentDB.RegisterAttempt(info.PaymentIdentifier, attempt)
|
_, err = paymentDB.RegisterAttempt(info.PaymentIdentifier, attempt)
|
||||||
require.NoError(t, err, "unable to send htlc message")
|
require.NoError(t, err, "unable to send htlc message")
|
||||||
assertPaymentStatus(t, paymentDB, info.PaymentIdentifier, StatusInFlight)
|
assertPaymentStatus(
|
||||||
|
t, paymentDB, info.PaymentIdentifier, StatusInFlight,
|
||||||
|
)
|
||||||
|
|
||||||
htlc = &htlcStatus{
|
htlc = &htlcStatus{
|
||||||
HTLCAttemptInfo: attempt,
|
HTLCAttemptInfo: attempt,
|
||||||
@@ -176,7 +178,9 @@ func TestKVPaymentsDBSwitchFail(t *testing.T) {
|
|||||||
spew.Sdump(payment.HTLCs[0].Route), err)
|
spew.Sdump(payment.HTLCs[0].Route), err)
|
||||||
}
|
}
|
||||||
|
|
||||||
assertPaymentStatus(t, paymentDB, info.PaymentIdentifier, StatusSucceeded)
|
assertPaymentStatus(
|
||||||
|
t, paymentDB, info.PaymentIdentifier, StatusSucceeded,
|
||||||
|
)
|
||||||
|
|
||||||
htlc.settle = &preimg
|
htlc.settle = &preimg
|
||||||
assertPaymentInfo(
|
assertPaymentInfo(
|
||||||
@@ -226,7 +230,9 @@ func TestKVPaymentsDBSwitchDoubleSend(t *testing.T) {
|
|||||||
// Record an attempt.
|
// Record an attempt.
|
||||||
_, err = paymentDB.RegisterAttempt(info.PaymentIdentifier, attempt)
|
_, err = paymentDB.RegisterAttempt(info.PaymentIdentifier, attempt)
|
||||||
require.NoError(t, err, "unable to send htlc message")
|
require.NoError(t, err, "unable to send htlc message")
|
||||||
assertPaymentStatus(t, paymentDB, info.PaymentIdentifier, StatusInFlight)
|
assertPaymentStatus(
|
||||||
|
t, paymentDB, info.PaymentIdentifier, StatusInFlight,
|
||||||
|
)
|
||||||
|
|
||||||
htlc := &htlcStatus{
|
htlc := &htlcStatus{
|
||||||
HTLCAttemptInfo: attempt,
|
HTLCAttemptInfo: attempt,
|
||||||
@@ -250,10 +256,14 @@ func TestKVPaymentsDBSwitchDoubleSend(t *testing.T) {
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
require.NoError(t, err, "error shouldn't have been received, got")
|
require.NoError(t, err, "error shouldn't have been received, got")
|
||||||
assertPaymentStatus(t, paymentDB, info.PaymentIdentifier, StatusSucceeded)
|
assertPaymentStatus(
|
||||||
|
t, paymentDB, info.PaymentIdentifier, StatusSucceeded,
|
||||||
|
)
|
||||||
|
|
||||||
htlc.settle = &preimg
|
htlc.settle = &preimg
|
||||||
assertPaymentInfo(t, paymentDB, info.PaymentIdentifier, info, nil, htlc)
|
assertPaymentInfo(
|
||||||
|
t, paymentDB, info.PaymentIdentifier, info, nil, htlc,
|
||||||
|
)
|
||||||
|
|
||||||
err = paymentDB.InitPayment(info.PaymentIdentifier, info)
|
err = paymentDB.InitPayment(info.PaymentIdentifier, info)
|
||||||
if !errors.Is(err, ErrAlreadyPaid) {
|
if !errors.Is(err, ErrAlreadyPaid) {
|
||||||
@@ -361,7 +371,9 @@ func TestKVPaymentsDBDeleteNonInFlight(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to send htlc message: %v", err)
|
t.Fatalf("unable to send htlc message: %v", err)
|
||||||
}
|
}
|
||||||
_, err = paymentDB.RegisterAttempt(info.PaymentIdentifier, attempt)
|
_, err = paymentDB.RegisterAttempt(
|
||||||
|
info.PaymentIdentifier, attempt,
|
||||||
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to send htlc message: %v", err)
|
t.Fatalf("unable to send htlc message: %v", err)
|
||||||
}
|
}
|
||||||
@@ -385,13 +397,18 @@ func TestKVPaymentsDBDeleteNonInFlight(t *testing.T) {
|
|||||||
|
|
||||||
// Fail the payment, which should moved it to Failed.
|
// Fail the payment, which should moved it to Failed.
|
||||||
failReason := FailureReasonNoRoute
|
failReason := FailureReasonNoRoute
|
||||||
_, err = paymentDB.Fail(info.PaymentIdentifier, failReason)
|
_, err = paymentDB.Fail(
|
||||||
|
info.PaymentIdentifier, failReason,
|
||||||
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to fail payment hash: %v", err)
|
t.Fatalf("unable to fail payment hash: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verify the status is indeed Failed.
|
// Verify the status is indeed Failed.
|
||||||
assertPaymentStatus(t, paymentDB, info.PaymentIdentifier, StatusFailed)
|
assertPaymentStatus(
|
||||||
|
t, paymentDB, info.PaymentIdentifier,
|
||||||
|
StatusFailed,
|
||||||
|
)
|
||||||
|
|
||||||
htlc.failure = &htlcFailure
|
htlc.failure = &htlcFailure
|
||||||
assertPaymentInfo(
|
assertPaymentInfo(
|
||||||
@@ -407,21 +424,30 @@ func TestKVPaymentsDBDeleteNonInFlight(t *testing.T) {
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("error shouldn't have been received, got: %v", err)
|
t.Fatalf("error shouldn't have been received,"+
|
||||||
|
" got: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
assertPaymentStatus(t, paymentDB, info.PaymentIdentifier, StatusSucceeded)
|
assertPaymentStatus(
|
||||||
|
t, paymentDB, info.PaymentIdentifier,
|
||||||
|
StatusSucceeded,
|
||||||
|
)
|
||||||
|
|
||||||
htlc.settle = &preimg
|
htlc.settle = &preimg
|
||||||
assertPaymentInfo(
|
assertPaymentInfo(
|
||||||
t, paymentDB, info.PaymentIdentifier, info, nil, htlc,
|
t, paymentDB, info.PaymentIdentifier, info, nil,
|
||||||
|
htlc,
|
||||||
)
|
)
|
||||||
|
|
||||||
numSuccess++
|
numSuccess++
|
||||||
} else {
|
} else {
|
||||||
assertPaymentStatus(t, paymentDB, info.PaymentIdentifier, StatusInFlight)
|
assertPaymentStatus(
|
||||||
|
t, paymentDB, info.PaymentIdentifier,
|
||||||
|
StatusInFlight,
|
||||||
|
)
|
||||||
assertPaymentInfo(
|
assertPaymentInfo(
|
||||||
t, paymentDB, info.PaymentIdentifier, info, nil, htlc,
|
t, paymentDB, info.PaymentIdentifier, info, nil,
|
||||||
|
htlc,
|
||||||
)
|
)
|
||||||
|
|
||||||
numInflight++
|
numInflight++
|
||||||
@@ -635,7 +661,8 @@ func TestKVPaymentsDBDeleteSinglePayment(t *testing.T) {
|
|||||||
// Delete failed HTLC attempts for the third payment.
|
// Delete failed HTLC attempts for the third payment.
|
||||||
require.NoError(t, db.DeletePayment(payments[2].id, true))
|
require.NoError(t, db.DeletePayment(payments[2].id, true))
|
||||||
|
|
||||||
// Only the successful HTLC attempt should be left for the third payment.
|
// Only the successful HTLC attempt should be left for the third
|
||||||
|
// payment.
|
||||||
payments[2].htlcs = 1
|
payments[2].htlcs = 1
|
||||||
assertPayments(t, db, payments[2:])
|
assertPayments(t, db, payments[2:])
|
||||||
|
|
||||||
@@ -724,7 +751,9 @@ func TestKVPaymentsDBMultiShard(t *testing.T) {
|
|||||||
a.AttemptID = i
|
a.AttemptID = i
|
||||||
attempts = append(attempts, &a)
|
attempts = append(attempts, &a)
|
||||||
|
|
||||||
_, err = paymentDB.RegisterAttempt(info.PaymentIdentifier, &a)
|
_, err = paymentDB.RegisterAttempt(
|
||||||
|
info.PaymentIdentifier, &a,
|
||||||
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to send htlc message: %v", err)
|
t.Fatalf("unable to send htlc message: %v", err)
|
||||||
}
|
}
|
||||||
@@ -737,7 +766,8 @@ func TestKVPaymentsDBMultiShard(t *testing.T) {
|
|||||||
HTLCAttemptInfo: &a,
|
HTLCAttemptInfo: &a,
|
||||||
}
|
}
|
||||||
assertPaymentInfo(
|
assertPaymentInfo(
|
||||||
t, paymentDB, info.PaymentIdentifier, info, nil, htlc,
|
t, paymentDB, info.PaymentIdentifier, info, nil,
|
||||||
|
htlc,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -771,7 +801,9 @@ func TestKVPaymentsDBMultiShard(t *testing.T) {
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Payment should still be in-flight.
|
// Payment should still be in-flight.
|
||||||
assertPaymentStatus(t, paymentDB, info.PaymentIdentifier, StatusInFlight)
|
assertPaymentStatus(
|
||||||
|
t, paymentDB, info.PaymentIdentifier, StatusInFlight,
|
||||||
|
)
|
||||||
|
|
||||||
// Depending on the test case, settle or fail the first attempt.
|
// Depending on the test case, settle or fail the first attempt.
|
||||||
a = attempts[0]
|
a = attempts[0]
|
||||||
@@ -795,7 +827,8 @@ func TestKVPaymentsDBMultiShard(t *testing.T) {
|
|||||||
// Assert that the HTLC has had the preimage recorded.
|
// Assert that the HTLC has had the preimage recorded.
|
||||||
htlc.settle = &preimg
|
htlc.settle = &preimg
|
||||||
assertPaymentInfo(
|
assertPaymentInfo(
|
||||||
t, paymentDB, info.PaymentIdentifier, info, nil, htlc,
|
t, paymentDB, info.PaymentIdentifier, info, nil,
|
||||||
|
htlc,
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
_, err := paymentDB.FailAttempt(
|
_, err := paymentDB.FailAttempt(
|
||||||
@@ -812,13 +845,16 @@ func TestKVPaymentsDBMultiShard(t *testing.T) {
|
|||||||
// Assert the failure was recorded.
|
// Assert the failure was recorded.
|
||||||
htlc.failure = &htlcFail
|
htlc.failure = &htlcFail
|
||||||
assertPaymentInfo(
|
assertPaymentInfo(
|
||||||
t, paymentDB, info.PaymentIdentifier, info, nil, htlc,
|
t, paymentDB, info.PaymentIdentifier, info, nil,
|
||||||
|
htlc,
|
||||||
)
|
)
|
||||||
|
|
||||||
// We also record a payment level fail, to move it into
|
// We also record a payment level fail, to move it into
|
||||||
// a terminal state.
|
// a terminal state.
|
||||||
failReason := FailureReasonNoRoute
|
failReason := FailureReasonNoRoute
|
||||||
_, err = paymentDB.Fail(info.PaymentIdentifier, failReason)
|
_, err = paymentDB.Fail(
|
||||||
|
info.PaymentIdentifier, failReason,
|
||||||
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to fail payment hash: %v", err)
|
t.Fatalf("unable to fail payment hash: %v", err)
|
||||||
}
|
}
|
||||||
@@ -846,7 +882,9 @@ func TestKVPaymentsDBMultiShard(t *testing.T) {
|
|||||||
require.ErrorIs(t, err, ErrPaymentPendingFailed)
|
require.ErrorIs(t, err, ErrPaymentPendingFailed)
|
||||||
}
|
}
|
||||||
|
|
||||||
assertPaymentStatus(t, paymentDB, info.PaymentIdentifier, StatusInFlight)
|
assertPaymentStatus(
|
||||||
|
t, paymentDB, info.PaymentIdentifier, StatusInFlight,
|
||||||
|
)
|
||||||
|
|
||||||
// Settle or fail the remaining attempt based on the testcase.
|
// Settle or fail the remaining attempt based on the testcase.
|
||||||
a = attempts[2]
|
a = attempts[2]
|
||||||
@@ -893,7 +931,9 @@ func TestKVPaymentsDBMultiShard(t *testing.T) {
|
|||||||
// write a terminal failure to the database without
|
// write a terminal failure to the database without
|
||||||
// syncing.
|
// syncing.
|
||||||
failReason := FailureReasonPaymentDetails
|
failReason := FailureReasonPaymentDetails
|
||||||
_, err = paymentDB.Fail(info.PaymentIdentifier, failReason)
|
_, err = paymentDB.Fail(
|
||||||
|
info.PaymentIdentifier, failReason,
|
||||||
|
)
|
||||||
require.NoError(t, err, "unable to fail")
|
require.NoError(t, err, "unable to fail")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1085,7 +1125,9 @@ func testDeleteFailedAttempts(t *testing.T, keepFailedPaymentAttempts bool) {
|
|||||||
// Calling DeleteFailedAttempts on an in-flight payment should return
|
// Calling DeleteFailedAttempts on an in-flight payment should return
|
||||||
// an error.
|
// an error.
|
||||||
if keepFailedPaymentAttempts {
|
if keepFailedPaymentAttempts {
|
||||||
require.NoError(t, paymentDB.DeleteFailedAttempts(payments[1].id))
|
require.NoError(
|
||||||
|
t, paymentDB.DeleteFailedAttempts(payments[1].id),
|
||||||
|
)
|
||||||
} else {
|
} else {
|
||||||
require.Error(t, paymentDB.DeleteFailedAttempts(payments[1].id))
|
require.Error(t, paymentDB.DeleteFailedAttempts(payments[1].id))
|
||||||
}
|
}
|
||||||
@@ -1107,10 +1149,14 @@ func testDeleteFailedAttempts(t *testing.T, keepFailedPaymentAttempts bool) {
|
|||||||
// DeleteFailedAttempts is ignored, even for non-existent
|
// DeleteFailedAttempts is ignored, even for non-existent
|
||||||
// payments, if the control tower is configured to keep failed
|
// payments, if the control tower is configured to keep failed
|
||||||
// HTLCs.
|
// HTLCs.
|
||||||
require.NoError(t, paymentDB.DeleteFailedAttempts(lntypes.ZeroHash))
|
require.NoError(
|
||||||
|
t, paymentDB.DeleteFailedAttempts(lntypes.ZeroHash),
|
||||||
|
)
|
||||||
} else {
|
} else {
|
||||||
// Attempting to cleanup a non-existent payment returns an error.
|
// Attempting to cleanup a non-existent payment returns an error.
|
||||||
require.Error(t, paymentDB.DeleteFailedAttempts(lntypes.ZeroHash))
|
require.Error(
|
||||||
|
t, paymentDB.DeleteFailedAttempts(lntypes.ZeroHash),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1364,7 +1410,9 @@ func assertPayments(t *testing.T, db *DB, payments []*payment) {
|
|||||||
|
|
||||||
// Make sure that the number of fetched payments is the same
|
// Make sure that the number of fetched payments is the same
|
||||||
// as expected.
|
// as expected.
|
||||||
require.Len(t, dbPayments, len(payments), "unexpected number of payments")
|
require.Len(
|
||||||
|
t, dbPayments, len(payments), "unexpected number of payments",
|
||||||
|
)
|
||||||
|
|
||||||
// Convert fetched payments of type MPPayment to our helper structure.
|
// Convert fetched payments of type MPPayment to our helper structure.
|
||||||
p := make([]*payment, len(dbPayments))
|
p := make([]*payment, len(dbPayments))
|
||||||
|
@@ -530,7 +530,9 @@ func TestQueryPayments(t *testing.T) {
|
|||||||
info.CreationTime = time.Unix(int64(i+1), 0)
|
info.CreationTime = time.Unix(int64(i+1), 0)
|
||||||
|
|
||||||
// Create a new payment entry in the database.
|
// Create a new payment entry in the database.
|
||||||
err = paymentDB.InitPayment(info.PaymentIdentifier, info)
|
err = paymentDB.InitPayment(
|
||||||
|
info.PaymentIdentifier, info,
|
||||||
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to initialize "+
|
t.Fatalf("unable to initialize "+
|
||||||
"payment in database: %v", err)
|
"payment in database: %v", err)
|
||||||
@@ -625,7 +627,9 @@ func TestFetchPaymentWithSequenceNumber(t *testing.T) {
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
// Create a new payment entry in the database.
|
// Create a new payment entry in the database.
|
||||||
err = paymentDB.InitPayment(noDuplicates.PaymentIdentifier, noDuplicates)
|
err = paymentDB.InitPayment(
|
||||||
|
noDuplicates.PaymentIdentifier, noDuplicates,
|
||||||
|
)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
// Fetch the payment so we can get its sequence nr.
|
// Fetch the payment so we can get its sequence nr.
|
||||||
@@ -639,7 +643,9 @@ func TestFetchPaymentWithSequenceNumber(t *testing.T) {
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
// Create a new payment entry in the database.
|
// Create a new payment entry in the database.
|
||||||
err = paymentDB.InitPayment(hasDuplicates.PaymentIdentifier, hasDuplicates)
|
err = paymentDB.InitPayment(
|
||||||
|
hasDuplicates.PaymentIdentifier, hasDuplicates,
|
||||||
|
)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
// Fetch the payment so we can get its sequence nr.
|
// Fetch the payment so we can get its sequence nr.
|
||||||
|
Reference in New Issue
Block a user