mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-08-24 12:44:34 +02:00
paymentsdb: declare helper functions and add comments
This commit is contained in:
@@ -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].
|
||||
|
@@ -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),
|
||||
|
Reference in New Issue
Block a user