@@ -18,6 +18,10 @@ import (
1818 "github.com/stretchr/testify/require"
1919)
2020
21+ const (
22+ testCommitSweepConfHeight = 99
23+ )
24+
2125type commitSweepResolverTestContext struct {
2226 resolver * commitSweepResolver
2327 notifier * mock.ChainNotifier
@@ -27,7 +31,8 @@ type commitSweepResolverTestContext struct {
2731}
2832
2933func newCommitSweepResolverTestContext (t * testing.T ,
30- resolution * lnwallet.CommitOutputResolution ) * commitSweepResolverTestContext {
34+ resolution * lnwallet.CommitOutputResolution ,
35+ confirmHeight uint32 ) * commitSweepResolverTestContext {
3136
3237 notifier := & mock.ChainNotifier {
3338 EpochChan : make (chan * chainntnfs.BlockEpoch ),
@@ -68,7 +73,7 @@ func newCommitSweepResolverTestContext(t *testing.T,
6873 }
6974
7075 resolver := newCommitSweepResolver (
71- * resolution , 0 , wire.OutPoint {}, cfg ,
76+ * resolution , confirmHeight , wire.OutPoint {}, cfg ,
7277 )
7378
7479 return & commitSweepResolverTestContext {
@@ -178,7 +183,9 @@ func TestCommitSweepResolverNoDelay(t *testing.T) {
178183 },
179184 }
180185
181- ctx := newCommitSweepResolverTestContext (t , & res )
186+ ctx := newCommitSweepResolverTestContext (
187+ t , & res , testCommitSweepConfHeight ,
188+ )
182189
183190 // Replace our checkpoint with one which will push reports into a
184191 // channel for us to consume. We replace this function on the resolver
@@ -197,15 +204,12 @@ func TestCommitSweepResolverNoDelay(t *testing.T) {
197204
198205 ctx .resolve ()
199206
200- spendTx := & wire.MsgTx {}
201- spendHash := spendTx .TxHash ()
202- ctx .notifier .ConfChan <- & chainntnfs.TxConfirmation {
203- Tx : spendTx ,
204- }
205-
206207 // No csv delay, so the input should be swept immediately.
207208 <- ctx .sweeper .sweptInputs
208209
210+ spendTx := & wire.MsgTx {}
211+ spendHash := spendTx .TxHash ()
212+
209213 amt := btcutil .Amount (res .SelfOutputSignDesc .Output .Value )
210214 expectedReport := & channeldb.ResolverReport {
211215 OutPoint : wire.OutPoint {},
@@ -242,7 +246,10 @@ func testCommitSweepResolverDelay(t *testing.T, sweepErr error) {
242246 SelfOutPoint : outpoint ,
243247 }
244248
245- ctx := newCommitSweepResolverTestContext (t , & res )
249+ // Use confirmHeight = 99, so maturityHeight = 99 + 3 = 102.
250+ ctx := newCommitSweepResolverTestContext (
251+ t , & res , testCommitSweepConfHeight ,
252+ )
246253
247254 // Replace our checkpoint with one which will push reports into a
248255 // channel for us to consume. We replace this function on the resolver
@@ -270,25 +277,18 @@ func testCommitSweepResolverDelay(t *testing.T, sweepErr error) {
270277 Amount : btcutil .Amount (amt ),
271278 LimboBalance : btcutil .Amount (amt ),
272279 }
273- if * report != expectedReport {
274- t .Fatalf ("unexpected resolver report. want=%v got=%v" ,
275- expectedReport , report )
276- }
280+ require .Equal (t , expectedReport , * report )
277281
278282 ctx .resolve ()
279283
280- ctx .notifier .ConfChan <- & chainntnfs.TxConfirmation {
281- BlockHeight : testInitialBlockHeight - 1 ,
282- }
283-
284- // Allow resolver to process confirmation.
284+ // Allow resolver to launch and update the report.
285285 time .Sleep (sweepProcessInterval )
286286
287287 // Expect report to be updated.
288+ // confirmHeight(99) + maturityDelay(3) = 102.
288289 report = ctx .resolver .report ()
289- if report .MaturityHeight != testInitialBlockHeight + 2 {
290- t .Fatal ("report maturity height incorrect" )
291- }
290+ expectedMaturity := testCommitSweepConfHeight + res .MaturityDelay
291+ require .Equal (t , expectedMaturity , report .MaturityHeight )
292292
293293 // Notify initial block height. Although the csv lock is still in
294294 // effect, we expect the input being sent to the sweeper before the csv
@@ -325,13 +325,10 @@ func testCommitSweepResolverDelay(t *testing.T, sweepErr error) {
325325 Outpoint : outpoint ,
326326 Type : ReportOutputUnencumbered ,
327327 Amount : btcutil .Amount (amt ),
328- MaturityHeight : testInitialBlockHeight + 2 ,
328+ MaturityHeight : testCommitSweepConfHeight + res . MaturityDelay ,
329329 RecoveredBalance : expectedRecoveredBalance ,
330330 }
331- if * report != expectedReport {
332- t .Fatalf ("unexpected resolver report. want=%v got=%v" ,
333- expectedReport , report )
334- }
331+ require .Equal (t , expectedReport , * report )
335332}
336333
337334// TestCommitSweepResolverDelay tests resolution of a direct commitment output
0 commit comments