paymentsdb: declare helper functions and add comments
What changed, and why it matters
This commit only touches test files. It adds t.Helper() declarations to test helper functions and adds two TODO comments about making tests database-agnostic. There are no changes to production code, no security fixes, and no behavior changes.
No security action needed. This is a routine test code maintenance commit.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff modifies payments/db/kv_store_test.go and payments/db/payment_test.go. It adds t.Helper() to several test helper functions (fetchPaymentIndexEntry, makeFakeInfo, createTestPayments, assertRouteEqual, genPreimage) and updates their callers to pass *testing.T. It also adds two TODO comments about making tests database-agnostic. No production code is changed.
Changed components
payments/db/kv_store_test.gopayments/db/payment_test.goInspect captured patch +20 / −6
diff --git a/payments/db/kv_store_test.go b/payments/db/kv_store_test.go
index b3d7887..caa46b5 100644
--- a/payments/db/kv_store_test.go
+++ b/payments/db/kv_store_test.go
@@ -20,6 +20,8 @@ import (
// TestKVStoreDeleteNonInFlight checks that calling DeletePayments only
// deletes payments from the database that are not in-flight.
+//
+// TODO(ziggie): Make this test db agnostic.
func TestKVStoreDeleteNonInFlight(t *testing.T) {
t.Parallel()
@@ -249,9 +251,11 @@ type htlcStatus struct {
// fetchPaymentIndexEntry gets the payment hash for the sequence number provided
// from our payment indexes bucket.
-func fetchPaymentIndexEntry(_ *testing.T, p *KVStore,
+func fetchPaymentIndexEntry(t *testing.T, p *KVStore,
sequenceNumber uint64) (*lntypes.Hash, error) {
+ t.Helper()
+
var hash lntypes.Hash
if err := kvdb.View(p.db, func(tx walletdb.ReadTx) error {
@@ -319,6 +323,8 @@ func assertNoIndex(t *testing.T, p DB, seqNr uint64) {
func makeFakeInfo(t *testing.T) (*PaymentCreationInfo,
*HTLCAttemptInfo) {
+ t.Helper()
+
var preimg lntypes.Preimage
copy(preimg[:], rev[:])
@@ -677,6 +683,8 @@ func putDuplicatePayment(t *testing.T, duplicateBucket kvdb.RwBucket,
// TestQueryPayments tests retrieval of payments with forwards and reversed
// queries.
+//
+// TODO(ziggie): Make this test db agnostic.
func TestQueryPayments(t *testing.T) {
// Define table driven test for QueryPayments.
// Test payments have sequence indices [1, 3, 4, 5, 6, 7].
diff --git a/payments/db/payment_test.go b/payments/db/payment_test.go
index ea5fcb8..fcd82af 100644
--- a/payments/db/payment_test.go
+++ b/payments/db/payment_test.go
@@ -112,6 +112,8 @@ type payment struct {
// the payments slice. Each payment will receive one failed HTLC and another
// HTLC depending on the final status of the payment provided.
func createTestPayments(t *testing.T, p DB, payments []*payment) {
+ t.Helper()
+
attemptID := uint64(0)
for i := 0; i < len(payments); i++ {
@@ -193,7 +195,9 @@ func createTestPayments(t *testing.T, p DB, payments []*payment) {
// assertRouteEquals compares to routes for equality and returns an error if
// they are not equal.
-func assertRouteEqual(a, b *route.Route) error {
+func assertRouteEqual(t *testing.T, a, b *route.Route) error {
+ t.Helper()
+
if !reflect.DeepEqual(a, b) {
return fmt.Errorf("HTLCAttemptInfos don't match: %v vs %v",
spew.Sdump(a), spew.Sdump(b))
@@ -239,7 +243,7 @@ func assertPaymentInfo(t *testing.T, p DB, hash lntypes.Hash,
}
htlc := payment.HTLCs[a.AttemptID]
- if err := assertRouteEqual(&htlc.Route, &a.Route); err != nil {
+ if err := assertRouteEqual(t, &htlc.Route, &a.Route); err != nil {
t.Fatal("routes do not match")
}
@@ -331,7 +335,9 @@ func assertDBPayments(t *testing.T, paymentDB DB, payments []*payment) {
}
// genPreimage generates a random preimage.
-func genPreimage() ([32]byte, error) {
+func genPreimage(t *testing.T) ([32]byte, error) {
+ t.Helper()
+
var preimage [32]byte
if _, err := io.ReadFull(rand.Reader, preimage[:]); err != nil {
return preimage, err
@@ -344,7 +350,7 @@ func genPreimage() ([32]byte, error) {
func genInfo(t *testing.T) (*PaymentCreationInfo, *HTLCAttemptInfo,
lntypes.Preimage, error) {
- preimage, err := genPreimage()
+ preimage, err := genPreimage(t)
if err != nil {
return nil, nil, preimage, fmt.Errorf("unable to "+
"generate preimage: %v", err)
@@ -1466,7 +1472,7 @@ func TestSwitchFail(t *testing.T) {
len(payment.HTLCs))
}
- err = assertRouteEqual(&payment.HTLCs[0].Route, &attempt.Route)
+ err = assertRouteEqual(t, &payment.HTLCs[0].Route, &attempt.Route)
if err != nil {
t.Fatalf("unexpected route returned: %v vs %v: %v",
spew.Sdump(attempt.Route),
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.