• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

lightningnetwork / lnd / 17236841262

26 Aug 2025 11:33AM UTC coverage: 66.228% (+8.9%) from 57.321%
17236841262

Pull #9147

github

web-flow
Merge 39fde1801 into 0c2f045f5
Pull Request #9147: [Part 1|3] Introduce SQL Payment schema into LND

129 of 1847 new or added lines in 13 files covered. (6.98%)

20 existing lines in 7 files now uncovered.

136069 of 205456 relevant lines covered (66.23%)

21357.68 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

92.16
/payments/db/test_helpers_kv.go
1
//go:build !test_db_sqlite && !test_db_postgres
2

3
package paymentsdb
4

5
import (
6
        "bytes"
7
        "testing"
8

9
        "github.com/btcsuite/btcwallet/walletdb"
10
        "github.com/lightningnetwork/lnd/kvdb"
11
        "github.com/lightningnetwork/lnd/lntypes"
12
        "github.com/stretchr/testify/require"
13
)
14

15
// assertNoIndex checks that an index for the sequence number provided does not
16
// exist.
17
func assertNoIndex(t *testing.T, p DB, seqNr uint64) {
1✔
18
        t.Helper()
1✔
19

1✔
20
        // This is only used for the kv implementation.
1✔
21
        kvPaymentDB, ok := p.(*KVStore)
1✔
22
        if !ok {
1✔
NEW
23
                return
×
NEW
24
        }
×
25

26
        _, err := fetchPaymentIndexEntry(t, kvPaymentDB, seqNr)
1✔
27
        require.Equal(t, ErrNoSequenceNrIndex, err)
1✔
28
}
29

30
// assertPaymentIndex looks up the index for a payment in the db and checks
31
// that its payment hash matches the expected hash passed in.
32
func assertPaymentIndex(t *testing.T, p DB, expectedHash lntypes.Hash) {
7✔
33
        t.Helper()
7✔
34

7✔
35
        // This is only used for the kv implementation.
7✔
36
        kvPaymentDB, ok := p.(*KVStore)
7✔
37
        if !ok {
7✔
NEW
38
                return
×
NEW
39
        }
×
40

41
        // Lookup the payment so that we have its sequence number and check
42
        // that is has correctly been indexed in the payment indexes bucket.
43
        pmt, err := kvPaymentDB.FetchPayment(expectedHash)
7✔
44
        require.NoError(t, err)
7✔
45

7✔
46
        hash, err := fetchPaymentIndexEntry(t, kvPaymentDB, pmt.SequenceNum)
7✔
47
        require.NoError(t, err)
7✔
48
        require.Equal(t, expectedHash, *hash)
7✔
49
}
50

51
// fetchPaymentIndexEntry gets the payment hash for the sequence number provided
52
// from our payment indexes bucket.
53
func fetchPaymentIndexEntry(t *testing.T, p *KVStore,
54
        sequenceNumber uint64) (*lntypes.Hash, error) {
8✔
55

8✔
56
        t.Helper()
8✔
57

8✔
58
        var hash lntypes.Hash
8✔
59

8✔
60
        if err := kvdb.View(p.db, func(tx walletdb.ReadTx) error {
16✔
61
                indexBucket := tx.ReadBucket(paymentsIndexBucket)
8✔
62
                key := make([]byte, 8)
8✔
63
                byteOrder.PutUint64(key, sequenceNumber)
8✔
64

8✔
65
                indexValue := indexBucket.Get(key)
8✔
66
                if indexValue == nil {
9✔
67
                        return ErrNoSequenceNrIndex
1✔
68
                }
1✔
69

70
                r := bytes.NewReader(indexValue)
7✔
71

7✔
72
                var err error
7✔
73
                hash, err = deserializePaymentIndex(r)
7✔
74

7✔
75
                return err
7✔
76
        }, func() {
8✔
77
                hash = lntypes.Hash{}
8✔
78
        }); err != nil {
9✔
79
                return nil, err
1✔
80
        }
1✔
81

82
        return &hash, nil
7✔
83
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc