mulit: use kvdb.Backend for the kv payment db
Instead of the ChannelState struct we now use the kv backend interface for the payment kv database.
This commit is contained in:
8 files changed
+188
-62
No files matched your search
@@ -48,12 +48,18 @@ var (
|
||||
func TestControlTowerSubscribeUnknown(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
db := initDB(t, false)
|
||||
db := initDB(t)
|
||||
|
||||
pControl := NewControlTower(channeldb.NewKVPaymentsDB(db))
|
||||
paymentDB, err := channeldb.NewKVPaymentsDB(
|
||||
db,
|
||||
paymentsdb.WithKeepFailedPaymentAttempts(true),
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
pControl := NewControlTower(paymentDB)
|
||||
|
||||
// Subscription should fail when the payment is not known.
|
||||
_, err := pControl.SubscribePayment(lntypes.Hash{1})
|
||||
_, err = pControl.SubscribePayment(lntypes.Hash{1})
|
||||
require.ErrorIs(t, err, paymentsdb.ErrPaymentNotInitiated)
|
||||
}
|
||||
|
||||
@@ -62,9 +68,12 @@ func TestControlTowerSubscribeUnknown(t *testing.T) {
|
||||
func TestControlTowerSubscribeSuccess(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
db := initDB(t, false)
|
||||
db := initDB(t)
|
||||
|
||||
pControl := NewControlTower(channeldb.NewKVPaymentsDB(db))
|
||||
paymentDB, err := channeldb.NewKVPaymentsDB(db)
|
||||
require.NoError(t, err)
|
||||
|
||||
pControl := NewControlTower(paymentDB)
|
||||
|
||||
// Initiate a payment.
|
||||
info, attempt, preimg, err := genInfo()
|
||||
@@ -181,9 +190,15 @@ func TestKVPaymentsDBSubscribeFail(t *testing.T) {
|
||||
func TestKVPaymentsDBSubscribeAllSuccess(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
db := initDB(t, true)
|
||||
db := initDB(t)
|
||||
|
||||
pControl := NewControlTower(channeldb.NewKVPaymentsDB(db))
|
||||
paymentDB, err := channeldb.NewKVPaymentsDB(
|
||||
db,
|
||||
paymentsdb.WithKeepFailedPaymentAttempts(true),
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
pControl := NewControlTower(paymentDB)
|
||||
|
||||
// Initiate a payment.
|
||||
info1, attempt1, preimg1, err := genInfo()
|
||||
@@ -294,9 +309,15 @@ func TestKVPaymentsDBSubscribeAllSuccess(t *testing.T) {
|
||||
func TestKVPaymentsDBSubscribeAllImmediate(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
db := initDB(t, true)
|
||||
db := initDB(t)
|
||||
|
||||
pControl := NewControlTower(channeldb.NewKVPaymentsDB(db))
|
||||
paymentDB, err := channeldb.NewKVPaymentsDB(
|
||||
db,
|
||||
paymentsdb.WithKeepFailedPaymentAttempts(true),
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
pControl := NewControlTower(paymentDB)
|
||||
|
||||
// Initiate a payment.
|
||||
info, attempt, _, err := genInfo()
|
||||
@@ -331,9 +352,15 @@ func TestKVPaymentsDBSubscribeAllImmediate(t *testing.T) {
|
||||
func TestKVPaymentsDBUnsubscribeSuccess(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
db := initDB(t, true)
|
||||
db := initDB(t)
|
||||
|
||||
pControl := NewControlTower(channeldb.NewKVPaymentsDB(db))
|
||||
paymentDB, err := channeldb.NewKVPaymentsDB(
|
||||
db,
|
||||
paymentsdb.WithKeepFailedPaymentAttempts(true),
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
pControl := NewControlTower(paymentDB)
|
||||
|
||||
subscription1, err := pControl.SubscribeAllPayments()
|
||||
require.NoError(t, err, "expected subscribe to succeed, but got: %v")
|
||||
@@ -400,9 +427,17 @@ func TestKVPaymentsDBUnsubscribeSuccess(t *testing.T) {
|
||||
func testKVPaymentsDBSubscribeFail(t *testing.T, registerAttempt,
|
||||
keepFailedPaymentAttempts bool) {
|
||||
|
||||
db := initDB(t, keepFailedPaymentAttempts)
|
||||
db := initDB(t)
|
||||
|
||||
pControl := NewControlTower(channeldb.NewKVPaymentsDB(db))
|
||||
paymentDB, err := channeldb.NewKVPaymentsDB(
|
||||
db,
|
||||
paymentsdb.WithKeepFailedPaymentAttempts(
|
||||
keepFailedPaymentAttempts,
|
||||
),
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
pControl := NewControlTower(paymentDB)
|
||||
|
||||
// Initiate a payment.
|
||||
info, attempt, _, err := genInfo()
|
||||
@@ -518,11 +553,9 @@ func testKVPaymentsDBSubscribeFail(t *testing.T, registerAttempt,
|
||||
}
|
||||
}
|
||||
|
||||
func initDB(t *testing.T, keepFailedPaymentAttempts bool) *channeldb.DB {
|
||||
func initDB(t *testing.T) *channeldb.DB {
|
||||
return channeldb.OpenForTesting(
|
||||
t, t.TempDir(), channeldb.OptionKeepFailedPaymentAttempts(
|
||||
keepFailedPaymentAttempts,
|
||||
),
|
||||
t, t.TempDir(),
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user