@@ -142,8 +142,31 @@ func checkPkgFilterEncodeDecode(t *testing.T, i uint16, f *channeldb.PkgFilter)
142142
143143var (
144144 chanID = lnwire .NewChanIDFromOutPoint (wire.OutPoint {})
145+ )
146+
147+ func testSettleFails () []channeldb.LogUpdate {
148+ return []channeldb.LogUpdate {
149+ {
150+ LogIndex : 2 ,
151+ UpdateMsg : & lnwire.UpdateFulfillHTLC {
152+ ChanID : chanID ,
153+ ID : 0 ,
154+ PaymentPreimage : [32 ]byte {0 },
155+ },
156+ },
157+ {
158+ LogIndex : 3 ,
159+ UpdateMsg : & lnwire.UpdateFailHTLC {
160+ ChanID : chanID ,
161+ ID : 1 ,
162+ Reason : []byte {},
163+ },
164+ },
165+ }
166+ }
145167
146- adds = []channeldb.LogUpdate {
168+ func testAdds () []channeldb.LogUpdate {
169+ return []channeldb.LogUpdate {
147170 {
148171 LogIndex : 0 ,
149172 UpdateMsg : & lnwire.UpdateAddHTLC {
@@ -165,26 +188,7 @@ var (
165188 },
166189 },
167190 }
168-
169- settleFails = []channeldb.LogUpdate {
170- {
171- LogIndex : 2 ,
172- UpdateMsg : & lnwire.UpdateFulfillHTLC {
173- ChanID : chanID ,
174- ID : 0 ,
175- PaymentPreimage : [32 ]byte {0 },
176- },
177- },
178- {
179- LogIndex : 3 ,
180- UpdateMsg : & lnwire.UpdateFailHTLC {
181- ChanID : chanID ,
182- ID : 1 ,
183- Reason : []byte {},
184- },
185- },
186- }
187- )
191+ }
188192
189193// TestPackagerEmptyFwdPkg checks that the state transitions exhibited by a
190194// forwarding package that contains no adds, fails or settles. We expect that
@@ -273,6 +277,8 @@ func TestPackagerOnlyAdds(t *testing.T) {
273277 t .Fatalf ("no forwarding packages should exist, found %d" , len (fwdPkgs ))
274278 }
275279
280+ adds := testAdds ()
281+
276282 // Next, create and write a new forwarding package that only has add
277283 // htlcs.
278284 fwdPkg := channeldb .NewFwdPkg (shortChanID , 0 , adds , nil )
@@ -377,6 +383,7 @@ func TestPackagerOnlySettleFails(t *testing.T) {
377383
378384 // Next, create and write a new forwarding package that only has add
379385 // htlcs.
386+ settleFails := testSettleFails ()
380387 fwdPkg := channeldb .NewFwdPkg (shortChanID , 0 , nil , settleFails )
381388
382389 nSettleFails := len (settleFails )
@@ -479,8 +486,11 @@ func TestPackagerAddsThenSettleFails(t *testing.T) {
479486 t .Fatalf ("no forwarding packages should exist, found %d" , len (fwdPkgs ))
480487 }
481488
489+ adds := testAdds ()
490+
482491 // Next, create and write a new forwarding package that only has add
483492 // htlcs.
493+ settleFails := testSettleFails ()
484494 fwdPkg := channeldb .NewFwdPkg (shortChanID , 0 , adds , settleFails )
485495
486496 nAdds := len (adds )
@@ -612,8 +622,11 @@ func TestPackagerSettleFailsThenAdds(t *testing.T) {
612622 t .Fatalf ("no forwarding packages should exist, found %d" , len (fwdPkgs ))
613623 }
614624
625+ adds := testAdds ()
626+
615627 // Next, create and write a new forwarding package that has both add
616628 // and settle/fail htlcs.
629+ settleFails := testSettleFails ()
617630 fwdPkg := channeldb .NewFwdPkg (shortChanID , 0 , adds , settleFails )
618631
619632 nAdds := len (adds )
0 commit comments