@@ -18,6 +18,7 @@ import (
18
18
"github.com/lightningnetwork/lnd/chainntnfs"
19
19
"github.com/lightningnetwork/lnd/keychain"
20
20
"github.com/lightningnetwork/lnd/lntypes"
21
+ "github.com/lightningnetwork/lnd/lnwallet/chainfee"
21
22
"github.com/stretchr/testify/require"
22
23
)
23
24
@@ -1746,20 +1747,64 @@ func testSweepFetcher(t *testing.T, store testStore,
1746
1747
)
1747
1748
require .NoError (t , err )
1748
1749
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
+
1749
1798
sweepFetcher := & sweepFetcherMock {
1750
1799
store : map [lntypes.Hash ]* SweepInfo {
1751
- {1 , 1 , 1 }: {
1752
- ConfTarget : 123 ,
1753
- Timeout : 111 ,
1754
- SwapInvoicePaymentAddr : * swapPaymentAddr ,
1755
- },
1800
+ swapHash : sweepInfo ,
1756
1801
},
1757
1802
}
1758
1803
1759
1804
// Create a sweep request.
1760
1805
sweepReq := SweepRequest {
1761
- SwapHash : lntypes. Hash { 1 , 1 , 1 } ,
1762
- Value : 111 ,
1806
+ SwapHash : swapHash ,
1807
+ Value : amt ,
1763
1808
Outpoint : wire.OutPoint {
1764
1809
Hash : chainhash.Hash {1 , 1 },
1765
1810
Index : 1 ,
@@ -1770,23 +1815,13 @@ func testSweepFetcher(t *testing.T, store testStore,
1770
1815
// Create a swap in the DB. It is needed to satisfy SQL constraints in
1771
1816
// case of SQL test. The data is not actually used, since we pass sweep
1772
1817
// 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 )
1784
1819
require .NoError (t , err )
1785
1820
store .AssertLoopOutStored ()
1786
1821
1787
1822
batcher := NewBatcher (lnd .WalletKit , lnd .ChainNotifier , lnd .Signer ,
1788
- testMuSig2SignSweep , nil , lnd .ChainParams , batcherStore ,
1789
- sweepFetcher )
1823
+ testMuSig2SignSweep , testVerifySchnorrSig , lnd .ChainParams ,
1824
+ batcherStore , sweepFetcher )
1790
1825
1791
1826
var wg sync.WaitGroup
1792
1827
wg .Add (1 )
@@ -1811,7 +1846,7 @@ func testSweepFetcher(t *testing.T, store testStore,
1811
1846
// batch.
1812
1847
require .Eventually (t , func () bool {
1813
1848
// Make sure that the sweep was stored
1814
- if ! batcherStore .AssertSweepStored (sweepReq . SwapHash ) {
1849
+ if ! batcherStore .AssertSweepStored (swapHash ) {
1815
1850
return false
1816
1851
}
1817
1852
@@ -1832,6 +1867,12 @@ func testSweepFetcher(t *testing.T, store testStore,
1832
1867
return batch .cfg .batchConfTarget == 123
1833
1868
}, test .Timeout , eventuallyCheckFrequency )
1834
1869
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
+
1835
1876
// Make sure we have stored the batch.
1836
1877
batches , err := batcherStore .FetchUnconfirmedSweepBatches (ctx )
1837
1878
require .NoError (t , err )
0 commit comments