paymentsdb: rename assertPayments

This commit is contained in:
ziggie committed 2025-08-20 09:07:52 +02:00
1 parent 8726ba3d7c
commit 68a8cf199d
2 files changed
+39 -39

No files matched your search

+3 -3
View File
@@ -105,7 +105,7 @@ func TestKVPaymentsDBDeleteNonInFlight(t *testing.T) {
} }
// Verify the status is indeed Failed. // Verify the status is indeed Failed.
assertPaymentStatus( assertPaymentstatus(
t, paymentDB, info.PaymentIdentifier, t, paymentDB, info.PaymentIdentifier,
StatusFailed, StatusFailed,
) )
@@ -129,7 +129,7 @@ func TestKVPaymentsDBDeleteNonInFlight(t *testing.T) {
" got: %v", err) " got: %v", err)
} }
assertPaymentStatus( assertPaymentstatus(
t, paymentDB, info.PaymentIdentifier, t, paymentDB, info.PaymentIdentifier,
StatusSucceeded, StatusSucceeded,
) )
@@ -143,7 +143,7 @@ func TestKVPaymentsDBDeleteNonInFlight(t *testing.T) {
numSuccess++ numSuccess++
default: default:
assertPaymentStatus( assertPaymentstatus(
t, paymentDB, info.PaymentIdentifier, t, paymentDB, info.PaymentIdentifier,
StatusInFlight, StatusInFlight,
) )
+36 -36
View File
@@ -271,9 +271,9 @@ func assertPaymentInfo(t *testing.T, p DB, hash lntypes.Hash,
} }
} }
// assertPaymentStatus retrieves the status of the payment referred to by hash // assertPaymentstatus retrieves the status of the payment referred to by hash
// and compares it with the expected state. // and compares it with the expected state.
func assertPaymentStatus(t *testing.T, p DB, hash lntypes.Hash, func assertPaymentstatus(t *testing.T, p DB, hash lntypes.Hash,
expStatus PaymentStatus) { expStatus PaymentStatus) {
t.Helper() t.Helper()
@@ -292,11 +292,11 @@ func assertPaymentStatus(t *testing.T, p DB, hash lntypes.Hash,
} }
} }
// assertPayments is a helper function that given a slice of payment and // assertDBPayments is a helper function that given a slice of payment and
// indices for the slice asserts that exactly the same payments in the // indices for the slice asserts that exactly the same payments in the
// slice for the provided indices exist when fetching payments from the // slice for the provided indices exist when fetching payments from the
// database. // database.
func assertPayments(t *testing.T, paymentDB DB, payments []*payment) { func assertDBPayments(t *testing.T, paymentDB DB, payments []*payment) {
t.Helper() t.Helper()
response, err := paymentDB.QueryPayments( response, err := paymentDB.QueryPayments(
@@ -407,7 +407,7 @@ func testDeleteFailedAttempts(t *testing.T, keepFailedPaymentAttempts bool) {
createTestPayments(t, paymentDB, payments) createTestPayments(t, paymentDB, payments)
// Check that all payments are there as we added them. // Check that all payments are there as we added them.
assertPayments(t, paymentDB, payments) assertDBPayments(t, paymentDB, payments)
// Calling DeleteFailedAttempts on a failed payment should delete all // Calling DeleteFailedAttempts on a failed payment should delete all
// HTLCs. // HTLCs.
@@ -417,7 +417,7 @@ func testDeleteFailedAttempts(t *testing.T, keepFailedPaymentAttempts bool) {
if !keepFailedPaymentAttempts { if !keepFailedPaymentAttempts {
payments[0].htlcs = 0 payments[0].htlcs = 0
} }
assertPayments(t, paymentDB, payments) assertDBPayments(t, paymentDB, payments)
// Calling DeleteFailedAttempts on an in-flight payment should return // Calling DeleteFailedAttempts on an in-flight payment should return
// an error. // an error.
@@ -435,7 +435,7 @@ func testDeleteFailedAttempts(t *testing.T, keepFailedPaymentAttempts bool) {
// Since DeleteFailedAttempts returned an error, we should expect the // Since DeleteFailedAttempts returned an error, we should expect the
// payment to be unchanged. // payment to be unchanged.
assertPayments(t, paymentDB, payments) assertDBPayments(t, paymentDB, payments)
// Cleaning up a successful payment should remove failed htlcs. // Cleaning up a successful payment should remove failed htlcs.
require.NoError(t, paymentDB.DeleteFailedAttempts(payments[2].id)) require.NoError(t, paymentDB.DeleteFailedAttempts(payments[2].id))
@@ -445,7 +445,7 @@ func testDeleteFailedAttempts(t *testing.T, keepFailedPaymentAttempts bool) {
if !keepFailedPaymentAttempts { if !keepFailedPaymentAttempts {
payments[2].htlcs = 1 payments[2].htlcs = 1
} }
assertPayments(t, paymentDB, payments) assertDBPayments(t, paymentDB, payments)
// NOTE: In case the option keepFailedPaymentAttempts is set no delete // NOTE: In case the option keepFailedPaymentAttempts is set no delete
// operation are performed in general therefore we do NOT expect an // operation are performed in general therefore we do NOT expect an
@@ -569,7 +569,7 @@ func TestDeleteSinglePayment(t *testing.T) {
createTestPayments(t, paymentDB, payments) createTestPayments(t, paymentDB, payments)
// Check that all payments are there as we added them. // Check that all payments are there as we added them.
assertPayments(t, paymentDB, payments) assertDBPayments(t, paymentDB, payments)
// Delete HTLC attempts for first payment only. // Delete HTLC attempts for first payment only.
require.NoError(t, paymentDB.DeletePayment(payments[0].id, true)) require.NoError(t, paymentDB.DeletePayment(payments[0].id, true))
@@ -577,19 +577,19 @@ func TestDeleteSinglePayment(t *testing.T) {
// The first payment is the only altered one as its failed HTLC should // The first payment is the only altered one as its failed HTLC should
// have been removed but is still present as payment. // have been removed but is still present as payment.
payments[0].htlcs = 0 payments[0].htlcs = 0
assertPayments(t, paymentDB, payments) assertDBPayments(t, paymentDB, payments)
// Delete the first payment completely. // Delete the first payment completely.
require.NoError(t, paymentDB.DeletePayment(payments[0].id, false)) require.NoError(t, paymentDB.DeletePayment(payments[0].id, false))
// The first payment should have been deleted. // The first payment should have been deleted.
assertPayments(t, paymentDB, payments[1:]) assertDBPayments(t, paymentDB, payments[1:])
// Now delete the second payment completely. // Now delete the second payment completely.
require.NoError(t, paymentDB.DeletePayment(payments[1].id, false)) require.NoError(t, paymentDB.DeletePayment(payments[1].id, false))
// The Second payment should have been deleted. // The Second payment should have been deleted.
assertPayments(t, paymentDB, payments[2:]) assertDBPayments(t, paymentDB, payments[2:])
// Delete failed HTLC attempts for the third payment. // Delete failed HTLC attempts for the third payment.
require.NoError(t, paymentDB.DeletePayment(payments[2].id, true)) require.NoError(t, paymentDB.DeletePayment(payments[2].id, true))
@@ -597,27 +597,27 @@ func TestDeleteSinglePayment(t *testing.T) {
// Only the successful HTLC attempt should be left for the third // Only the successful HTLC attempt should be left for the third
// payment. // payment.
payments[2].htlcs = 1 payments[2].htlcs = 1
assertPayments(t, paymentDB, payments[2:]) assertDBPayments(t, paymentDB, payments[2:])
// Now delete the third payment completely. // Now delete the third payment completely.
require.NoError(t, paymentDB.DeletePayment(payments[2].id, false)) require.NoError(t, paymentDB.DeletePayment(payments[2].id, false))
// Only the last payment should be left. // Only the last payment should be left.
assertPayments(t, paymentDB, payments[3:]) assertDBPayments(t, paymentDB, payments[3:])
// Deleting HTLC attempts from InFlight payments should not work and an // Deleting HTLC attempts from InFlight payments should not work and an
// error returned. // error returned.
require.Error(t, paymentDB.DeletePayment(payments[3].id, true)) require.Error(t, paymentDB.DeletePayment(payments[3].id, true))
// The payment is InFlight and therefore should not have been altered. // The payment is InFlight and therefore should not have been altered.
assertPayments(t, paymentDB, payments[3:]) assertDBPayments(t, paymentDB, payments[3:])
// Finally deleting the InFlight payment should also not work and an // Finally deleting the InFlight payment should also not work and an
// error returned. // error returned.
require.Error(t, paymentDB.DeletePayment(payments[3].id, false)) require.Error(t, paymentDB.DeletePayment(payments[3].id, false))
// The payment is InFlight and therefore should not have been altered. // The payment is InFlight and therefore should not have been altered.
assertPayments(t, paymentDB, payments[3:]) assertDBPayments(t, paymentDB, payments[3:])
} }
// TestPaymentRegistrable checks the method `Registrable` behaves as expected // TestPaymentRegistrable checks the method `Registrable` behaves as expected
@@ -1240,7 +1240,7 @@ func TestKVPaymentsDBDeletePayments(t *testing.T) {
createTestPayments(t, paymentDB, payments) createTestPayments(t, paymentDB, payments)
// Check that all payments are there as we added them. // Check that all payments are there as we added them.
assertPayments(t, paymentDB, payments) assertDBPayments(t, paymentDB, payments)
// Delete HTLC attempts for failed payments only. // Delete HTLC attempts for failed payments only.
numPayments, err := paymentDB.DeletePayments(true, true) numPayments, err := paymentDB.DeletePayments(true, true)
@@ -1249,7 +1249,7 @@ func TestKVPaymentsDBDeletePayments(t *testing.T) {
// The failed payment is the only altered one. // The failed payment is the only altered one.
payments[0].htlcs = 0 payments[0].htlcs = 0
assertPayments(t, paymentDB, payments) assertDBPayments(t, paymentDB, payments)
// Delete failed attempts for all payments. // Delete failed attempts for all payments.
numPayments, err = paymentDB.DeletePayments(false, true) numPayments, err = paymentDB.DeletePayments(false, true)
@@ -1259,21 +1259,21 @@ func TestKVPaymentsDBDeletePayments(t *testing.T) {
// The failed attempts should be deleted, except for the in-flight // The failed attempts should be deleted, except for the in-flight
// payment, that shouldn't be altered until it has completed. // payment, that shouldn't be altered until it has completed.
payments[1].htlcs = 1 payments[1].htlcs = 1
assertPayments(t, paymentDB, payments) assertDBPayments(t, paymentDB, payments)
// Now delete all failed payments. // Now delete all failed payments.
numPayments, err = paymentDB.DeletePayments(true, false) numPayments, err = paymentDB.DeletePayments(true, false)
require.NoError(t, err) require.NoError(t, err)
require.EqualValues(t, 1, numPayments) require.EqualValues(t, 1, numPayments)
assertPayments(t, paymentDB, payments[1:]) assertDBPayments(t, paymentDB, payments[1:])
// Finally delete all completed payments. // Finally delete all completed payments.
numPayments, err = paymentDB.DeletePayments(false, false) numPayments, err = paymentDB.DeletePayments(false, false)
require.NoError(t, err) require.NoError(t, err)
require.EqualValues(t, 1, numPayments) require.EqualValues(t, 1, numPayments)
assertPayments(t, paymentDB, payments[2:]) assertDBPayments(t, paymentDB, payments[2:])
} }
// TestSwitchDoubleSend checks the ability of payment control to // TestSwitchDoubleSend checks the ability of payment control to
@@ -1292,7 +1292,7 @@ func TestSwitchDoubleSend(t *testing.T) {
require.NoError(t, err, "unable to send htlc message") require.NoError(t, err, "unable to send htlc message")
assertPaymentIndex(t, paymentDB, info.PaymentIdentifier) assertPaymentIndex(t, paymentDB, info.PaymentIdentifier)
assertPaymentStatus( assertPaymentstatus(
t, paymentDB, info.PaymentIdentifier, StatusInitiated, t, paymentDB, info.PaymentIdentifier, StatusInitiated,
) )
assertPaymentInfo( assertPaymentInfo(
@@ -1308,7 +1308,7 @@ func TestSwitchDoubleSend(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( assertPaymentstatus(
t, paymentDB, info.PaymentIdentifier, StatusInFlight, t, paymentDB, info.PaymentIdentifier, StatusInFlight,
) )
@@ -1334,7 +1334,7 @@ func TestSwitchDoubleSend(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( assertPaymentstatus(
t, paymentDB, info.PaymentIdentifier, StatusSucceeded, t, paymentDB, info.PaymentIdentifier, StatusSucceeded,
) )
@@ -1364,7 +1364,7 @@ func TestSwitchFail(t *testing.T) {
require.NoError(t, err, "unable to send htlc message") require.NoError(t, err, "unable to send htlc message")
assertPaymentIndex(t, paymentDB, info.PaymentIdentifier) assertPaymentIndex(t, paymentDB, info.PaymentIdentifier)
assertPaymentStatus( assertPaymentstatus(
t, paymentDB, info.PaymentIdentifier, StatusInitiated, t, paymentDB, info.PaymentIdentifier, StatusInitiated,
) )
assertPaymentInfo( assertPaymentInfo(
@@ -1377,7 +1377,7 @@ func TestSwitchFail(t *testing.T) {
require.NoError(t, err, "unable to fail payment hash") require.NoError(t, err, "unable to fail payment hash")
// Verify the status is indeed Failed. // Verify the status is indeed Failed.
assertPaymentStatus(t, paymentDB, info.PaymentIdentifier, StatusFailed) assertPaymentstatus(t, paymentDB, info.PaymentIdentifier, StatusFailed)
assertPaymentInfo( assertPaymentInfo(
t, paymentDB, info.PaymentIdentifier, info, &failReason, nil, t, paymentDB, info.PaymentIdentifier, info, &failReason, nil,
) )
@@ -1397,7 +1397,7 @@ func TestSwitchFail(t *testing.T) {
assertPaymentIndex(t, paymentDB, info.PaymentIdentifier) assertPaymentIndex(t, paymentDB, info.PaymentIdentifier)
assertNoIndex(t, paymentDB, payment.SequenceNum) assertNoIndex(t, paymentDB, payment.SequenceNum)
assertPaymentStatus( assertPaymentstatus(
t, paymentDB, info.PaymentIdentifier, StatusInitiated, t, paymentDB, info.PaymentIdentifier, StatusInitiated,
) )
assertPaymentInfo( assertPaymentInfo(
@@ -1420,7 +1420,7 @@ func TestSwitchFail(t *testing.T) {
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
assertPaymentStatus( assertPaymentstatus(
t, paymentDB, info.PaymentIdentifier, StatusInFlight, t, paymentDB, info.PaymentIdentifier, StatusInFlight,
) )
@@ -1435,7 +1435,7 @@ func TestSwitchFail(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( assertPaymentstatus(
t, paymentDB, info.PaymentIdentifier, StatusInFlight, t, paymentDB, info.PaymentIdentifier, StatusInFlight,
) )
@@ -1469,7 +1469,7 @@ func TestSwitchFail(t *testing.T) {
spew.Sdump(payment.HTLCs[0].Route), err) spew.Sdump(payment.HTLCs[0].Route), err)
} }
assertPaymentStatus( assertPaymentstatus(
t, paymentDB, info.PaymentIdentifier, StatusSucceeded, t, paymentDB, info.PaymentIdentifier, StatusSucceeded,
) )
@@ -1522,7 +1522,7 @@ func TestMultiShard(t *testing.T) {
} }
assertPaymentIndex(t, paymentDB, info.PaymentIdentifier) assertPaymentIndex(t, paymentDB, info.PaymentIdentifier)
assertPaymentStatus( assertPaymentstatus(
t, paymentDB, info.PaymentIdentifier, StatusInitiated, t, paymentDB, info.PaymentIdentifier, StatusInitiated,
) )
assertPaymentInfo( assertPaymentInfo(
@@ -1551,7 +1551,7 @@ func TestMultiShard(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)
} }
assertPaymentStatus( assertPaymentstatus(
t, paymentDB, info.PaymentIdentifier, t, paymentDB, info.PaymentIdentifier,
StatusInFlight, StatusInFlight,
) )
@@ -1595,7 +1595,7 @@ func TestMultiShard(t *testing.T) {
) )
// Payment should still be in-flight. // Payment should still be in-flight.
assertPaymentStatus( assertPaymentstatus(
t, paymentDB, info.PaymentIdentifier, StatusInFlight, t, paymentDB, info.PaymentIdentifier, StatusInFlight,
) )
@@ -1659,7 +1659,7 @@ func TestMultiShard(t *testing.T) {
// The payment is now considered pending fail, since // The payment is now considered pending fail, since
// there is still an active HTLC. // there is still an active HTLC.
assertPaymentStatus( assertPaymentstatus(
t, paymentDB, info.PaymentIdentifier, t, paymentDB, info.PaymentIdentifier,
StatusInFlight, StatusInFlight,
) )
@@ -1680,7 +1680,7 @@ func TestMultiShard(t *testing.T) {
) )
} }
assertPaymentStatus( assertPaymentstatus(
t, paymentDB, info.PaymentIdentifier, StatusInFlight, t, paymentDB, info.PaymentIdentifier, StatusInFlight,
) )
@@ -1763,7 +1763,7 @@ func TestMultiShard(t *testing.T) {
registerErr = ErrPaymentAlreadySucceeded registerErr = ErrPaymentAlreadySucceeded
} }
assertPaymentStatus( assertPaymentstatus(
t, paymentDB, info.PaymentIdentifier, finalStatus, t, paymentDB, info.PaymentIdentifier, finalStatus,
) )