@@ -18,6 +18,7 @@ import (
1818 "github.com/lightningnetwork/lnd/chainntnfs"
1919 "github.com/lightningnetwork/lnd/keychain"
2020 "github.com/lightningnetwork/lnd/lntypes"
21+ "github.com/lightningnetwork/lnd/lnwallet/chainfee"
2122 "github.com/stretchr/testify/require"
2223)
2324
@@ -1746,20 +1747,64 @@ func testSweepFetcher(t *testing.T, store testStore,
17461747 )
17471748 require .NoError (t , err )
17481749
1750+ swapHash := lntypes.Hash {1 , 1 , 1 }
1751+
1752+ // Provide min fee rate for the sweep.
1753+ feeRate := chainfee .SatPerKWeight (30000 )
1754+ amt := btcutil .Amount (1_000_000 )
1755+ weight := lntypes .WeightUnit (445 ) // Weight for 1-to-1 tx.
1756+ bumpedFee := feeRate + 100
1757+ expectedFee := bumpedFee .FeeForWeight (weight )
1758+
1759+ swap := & loopdb.LoopOutContract {
1760+ SwapContract : loopdb.SwapContract {
1761+ CltvExpiry : 222 ,
1762+ AmountRequested : amt ,
1763+ ProtocolVersion : loopdb .ProtocolVersionMuSig2 ,
1764+ HtlcKeys : loopdb.HtlcKeys {
1765+ SenderScriptKey : senderKey ,
1766+ ReceiverScriptKey : receiverKey ,
1767+ SenderInternalPubKey : senderKey ,
1768+ ReceiverInternalPubKey : receiverKey ,
1769+ },
1770+ },
1771+ DestAddr : destAddr ,
1772+ SwapInvoice : swapInvoice ,
1773+ SweepConfTarget : 321 ,
1774+ }
1775+
1776+ htlc , err := utils .GetHtlc (
1777+ swapHash , & swap .SwapContract , lnd .ChainParams ,
1778+ )
1779+ require .NoError (t , err )
1780+
1781+ sweepInfo := & SweepInfo {
1782+ ConfTarget : 123 ,
1783+ Timeout : 111 ,
1784+ SwapInvoicePaymentAddr : * swapPaymentAddr ,
1785+ MinFeeRate : feeRate ,
1786+ ProtocolVersion : loopdb .ProtocolVersionMuSig2 ,
1787+ HTLCKeys : loopdb.HtlcKeys {
1788+ SenderScriptKey : senderKey ,
1789+ ReceiverScriptKey : receiverKey ,
1790+ SenderInternalPubKey : senderKey ,
1791+ ReceiverInternalPubKey : receiverKey ,
1792+ },
1793+ HTLC : * htlc ,
1794+ HTLCSuccessEstimator : htlc .AddSuccessToEstimator ,
1795+ DestAddr : destAddr ,
1796+ }
1797+
17491798 sweepFetcher := & sweepFetcherMock {
17501799 store : map [lntypes.Hash ]* SweepInfo {
1751- {1 , 1 , 1 }: {
1752- ConfTarget : 123 ,
1753- Timeout : 111 ,
1754- SwapInvoicePaymentAddr : * swapPaymentAddr ,
1755- },
1800+ swapHash : sweepInfo ,
17561801 },
17571802 }
17581803
17591804 // Create a sweep request.
17601805 sweepReq := SweepRequest {
1761- SwapHash : lntypes. Hash { 1 , 1 , 1 } ,
1762- Value : 111 ,
1806+ SwapHash : swapHash ,
1807+ Value : amt ,
17631808 Outpoint : wire.OutPoint {
17641809 Hash : chainhash.Hash {1 , 1 },
17651810 Index : 1 ,
@@ -1770,23 +1815,13 @@ func testSweepFetcher(t *testing.T, store testStore,
17701815 // Create a swap in the DB. It is needed to satisfy SQL constraints in
17711816 // case of SQL test. The data is not actually used, since we pass sweep
17721817 // fetcher, so put different conf target to make sure it is not used.
1773- swap := & loopdb.LoopOutContract {
1774- SwapContract : loopdb.SwapContract {
1775- CltvExpiry : 222 ,
1776- AmountRequested : 222 ,
1777- },
1778-
1779- DestAddr : destAddr ,
1780- SwapInvoice : swapInvoice ,
1781- SweepConfTarget : 321 ,
1782- }
1783- err = store .CreateLoopOut (ctx , sweepReq .SwapHash , swap )
1818+ err = store .CreateLoopOut (ctx , swapHash , swap )
17841819 require .NoError (t , err )
17851820 store .AssertLoopOutStored ()
17861821
17871822 batcher := NewBatcher (lnd .WalletKit , lnd .ChainNotifier , lnd .Signer ,
1788- testMuSig2SignSweep , nil , lnd .ChainParams , batcherStore ,
1789- sweepFetcher )
1823+ testMuSig2SignSweep , testVerifySchnorrSig , lnd .ChainParams ,
1824+ batcherStore , sweepFetcher )
17901825
17911826 var wg sync.WaitGroup
17921827 wg .Add (1 )
@@ -1811,7 +1846,7 @@ func testSweepFetcher(t *testing.T, store testStore,
18111846 // batch.
18121847 require .Eventually (t , func () bool {
18131848 // Make sure that the sweep was stored
1814- if ! batcherStore .AssertSweepStored (sweepReq . SwapHash ) {
1849+ if ! batcherStore .AssertSweepStored (swapHash ) {
18151850 return false
18161851 }
18171852
@@ -1832,6 +1867,12 @@ func testSweepFetcher(t *testing.T, store testStore,
18321867 return batch .cfg .batchConfTarget == 123
18331868 }, test .Timeout , eventuallyCheckFrequency )
18341869
1870+ // Get the published transaction and check the fee rate.
1871+ tx := <- lnd .TxPublishChannel
1872+ out := btcutil .Amount (tx .TxOut [0 ].Value )
1873+ gotFee := amt - out
1874+ require .Equal (t , expectedFee , gotFee , "fees don't match" )
1875+
18351876 // Make sure we have stored the batch.
18361877 batches , err := batcherStore .FetchUnconfirmedSweepBatches (ctx )
18371878 require .NoError (t , err )
0 commit comments