Skip to content

Commit 09029bf

Browse files
committed
test: allow custom fee estimates
1 parent 9f25fdd commit 09029bf

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

test/lnd_services_mock.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ import (
66
"time"
77

88
"github.com/btcsuite/btcd/chaincfg"
9-
"github.com/lightningnetwork/lnd/lntypes"
10-
"github.com/lightningnetwork/lnd/zpay32"
11-
129
"github.com/btcsuite/btcd/wire"
1310
"github.com/lightninglabs/loop/lndclient"
1411
"github.com/lightningnetwork/lnd/chainntnfs"
12+
"github.com/lightningnetwork/lnd/lntypes"
13+
"github.com/lightningnetwork/lnd/lnwallet"
14+
"github.com/lightningnetwork/lnd/zpay32"
1515
)
1616

1717
var testStartingHeight = int32(600)
@@ -20,7 +20,9 @@ var testStartingHeight = int32(600)
2020
// tests.
2121
func NewMockLnd() *LndMockServices {
2222
lightningClient := &mockLightningClient{}
23-
walletKit := &mockWalletKit{}
23+
walletKit := &mockWalletKit{
24+
feeEstimates: make(map[int32]lnwallet.SatPerKWeight),
25+
}
2426
chainNotifier := &mockChainNotifier{}
2527
signer := &mockSigner{}
2628
invoices := &mockInvoices{}
@@ -197,3 +199,9 @@ func (s *LndMockServices) DecodeInvoice(request string) (*zpay32.Invoice,
197199

198200
return zpay32.Decode(request, s.ChainParams)
199201
}
202+
203+
func (s *LndMockServices) SetFeeEstimate(confTarget int32,
204+
feeEstimate lnwallet.SatPerKWeight) {
205+
206+
s.WalletKit.(*mockWalletKit).feeEstimates[confTarget] = feeEstimate
207+
}

test/walletkit_mock.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,19 @@ import (
88
"github.com/btcsuite/btcd/chaincfg/chainhash"
99
"github.com/btcsuite/btcd/wire"
1010
"github.com/btcsuite/btcutil"
11+
"github.com/lightninglabs/loop/lndclient"
1112
"github.com/lightningnetwork/lnd/keychain"
1213
"github.com/lightningnetwork/lnd/lnwallet"
1314
)
1415

1516
type mockWalletKit struct {
16-
lnd *LndMockServices
17-
keyIndex int32
17+
lnd *LndMockServices
18+
keyIndex int32
19+
feeEstimates map[int32]lnwallet.SatPerKWeight
1820
}
1921

22+
var _ lndclient.WalletKitClient = (*mockWalletKit)(nil)
23+
2024
func (m *mockWalletKit) DeriveNextKey(ctx context.Context, family int32) (
2125
*keychain.KeyDescriptor, error) {
2226

@@ -87,9 +91,15 @@ func (m *mockWalletKit) SendOutputs(ctx context.Context, outputs []*wire.TxOut,
8791

8892
func (m *mockWalletKit) EstimateFee(ctx context.Context, confTarget int32) (
8993
lnwallet.SatPerKWeight, error) {
94+
9095
if confTarget <= 1 {
9196
return 0, errors.New("conf target must be greater than 1")
9297
}
9398

94-
return 10000, nil
99+
feeEstimate, ok := m.feeEstimates[confTarget]
100+
if !ok {
101+
return 10000, nil
102+
}
103+
104+
return feeEstimate, nil
95105
}

0 commit comments

Comments
 (0)