mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-08-30 23:53:41 +02:00
channeldb: validate feature dependencies when adding invoice
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/lightningnetwork/lnd/clock"
|
||||
"github.com/lightningnetwork/lnd/feature"
|
||||
"github.com/lightningnetwork/lnd/lntypes"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
"github.com/lightningnetwork/lnd/record"
|
||||
@@ -1658,3 +1659,30 @@ func TestDeleteInvoices(t *testing.T) {
|
||||
assertInvoiceCount(0)
|
||||
|
||||
}
|
||||
|
||||
// TestAddInvoiceInvalidFeatureDeps asserts that inserting an invoice with
|
||||
// invalid transitive feature dependencies fails with the appropriate error.
|
||||
func TestAddInvoiceInvalidFeatureDeps(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
db, cleanup, err := MakeTestDB()
|
||||
require.NoError(t, err, "unable to make test db")
|
||||
defer cleanup()
|
||||
|
||||
invoice, err := randInvoice(500)
|
||||
require.NoError(t, err)
|
||||
|
||||
invoice.Terms.Features = lnwire.NewFeatureVector(
|
||||
lnwire.NewRawFeatureVector(
|
||||
lnwire.TLVOnionPayloadOptional,
|
||||
lnwire.MPPOptional,
|
||||
),
|
||||
lnwire.Features,
|
||||
)
|
||||
|
||||
hash := invoice.Terms.PaymentPreimage.Hash()
|
||||
_, err = db.AddInvoice(invoice, hash)
|
||||
require.Error(t, err, feature.NewErrMissingFeatureDep(
|
||||
lnwire.PaymentAddrOptional,
|
||||
))
|
||||
}
|
||||
|
Reference in New Issue
Block a user