@@ -29,16 +29,16 @@ type testCase struct {
2929func TestSelectDeposits (t * testing.T ) {
3030 d1 , d2 , d3 , d4 := & deposit.Deposit {
3131 Value : 1_000_000 ,
32- ConfirmationHeight : 1000 ,
32+ ConfirmationHeight : 5_000 ,
3333 }, & deposit.Deposit {
3434 Value : 2_000_000 ,
35- ConfirmationHeight : 2000 ,
35+ ConfirmationHeight : 5_001 ,
3636 }, & deposit.Deposit {
3737 Value : 3_000_000 ,
38- ConfirmationHeight : 3000 ,
38+ ConfirmationHeight : 5_002 ,
3939 }, & deposit.Deposit {
4040 Value : 3_000_000 ,
41- ConfirmationHeight : 3001 ,
41+ ConfirmationHeight : 5_003 ,
4242 }
4343 d1 .Hash = chainhash.Hash {1 }
4444 d1 .Index = 0
@@ -121,6 +121,43 @@ func TestSelectDeposits(t *testing.T) {
121121 expected : []* deposit.Deposit {d3 },
122122 expectedErr : "" ,
123123 },
124+ {
125+ name : "prefilter filters deposits close to expiry" ,
126+ deposits : func () []* deposit.Deposit {
127+ // dClose expires before
128+ // htlcExpiry+DepositHtlcDelta and must be
129+ // filtered out. dOK expires exactly at the
130+ // threshold and must be eligible.
131+ dClose := & deposit.Deposit {
132+ Value : 3_000_000 ,
133+ ConfirmationHeight : 3000 ,
134+ }
135+ dClose .Hash = chainhash.Hash {5 }
136+ dClose .Index = 0
137+ dOK := & deposit.Deposit {
138+ Value : 2_000_000 ,
139+ ConfirmationHeight : 3050 ,
140+ }
141+ dOK .Hash = chainhash.Hash {6 }
142+ dOK .Index = 0
143+ return []* deposit.Deposit {dClose , dOK }
144+ }(),
145+ targetValue : 1_000_000 ,
146+ csvExpiry : 1000 ,
147+ blockHeight : 3000 ,
148+ expected : func () []* deposit.Deposit {
149+ // Only dOK should be considered.
150+ // dClose is filtered.
151+ dOK := & deposit.Deposit {
152+ Value : 2_000_000 ,
153+ ConfirmationHeight : 3050 ,
154+ }
155+ dOK .Hash = chainhash.Hash {6 }
156+ dOK .Index = 0
157+ return []* deposit.Deposit {dOK }
158+ }(),
159+ expectedErr : "" ,
160+ },
124161 }
125162
126163 for _ , tc := range testCases {
0 commit comments