@@ -113,9 +113,25 @@ func TestLoopInSuccess(t *testing.T) {
113
113
}
114
114
}
115
115
116
- // TestLoopInTimeout tests the scenario where the server doesn't sweep the htlc
116
+ // TestLoopInTimeout tests scenarios where the server doesn't sweep the htlc
117
117
// and the client is forced to reclaim the funds using the timeout tx.
118
118
func TestLoopInTimeout (t * testing.T ) {
119
+ testAmt := int64 (testLoopInRequest .Amount )
120
+ t .Run ("internal htlc" , func (t * testing.T ) {
121
+ testLoopInTimeout (t , 0 )
122
+ })
123
+ t .Run ("external htlc" , func (t * testing.T ) {
124
+ testLoopInTimeout (t , testAmt )
125
+ })
126
+ t .Run ("external amount too high" , func (t * testing.T ) {
127
+ testLoopInTimeout (t , testAmt + 1 )
128
+ })
129
+ t .Run ("external amount too low" , func (t * testing.T ) {
130
+ testLoopInTimeout (t , testAmt - 1 )
131
+ })
132
+ }
133
+
134
+ func testLoopInTimeout (t * testing.T , externalValue int64 ) {
119
135
defer test .Guard (t )()
120
136
121
137
ctx := newLoopInTestContext (t )
@@ -128,9 +144,14 @@ func TestLoopInTimeout(t *testing.T) {
128
144
server : ctx .server ,
129
145
}
130
146
147
+ req := testLoopInRequest
148
+ if externalValue != 0 {
149
+ req .ExternalHtlc = true
150
+ }
151
+
131
152
swap , err := newLoopInSwap (
132
153
context .Background (), cfg ,
133
- height , & testLoopInRequest ,
154
+ height , & req ,
134
155
)
135
156
if err != nil {
136
157
t .Fatal (err )
@@ -152,8 +173,21 @@ func TestLoopInTimeout(t *testing.T) {
152
173
ctx .assertState (loopdb .StateHtlcPublished )
153
174
ctx .store .assertLoopInState (loopdb .StateHtlcPublished )
154
175
155
- // Expect htlc to be published.
156
- htlcTx := <- ctx .lnd .SendOutputsChannel
176
+ var htlcTx wire.MsgTx
177
+ if externalValue == 0 {
178
+ // Expect htlc to be published.
179
+ htlcTx = <- ctx .lnd .SendOutputsChannel
180
+ } else {
181
+ // Create an external htlc publish tx.
182
+ htlcTx = wire.MsgTx {
183
+ TxOut : []* wire.TxOut {
184
+ {
185
+ PkScript : swap .htlc .PkScript ,
186
+ Value : externalValue ,
187
+ },
188
+ },
189
+ }
190
+ }
157
191
158
192
// Expect register for htlc conf.
159
193
<- ctx .lnd .RegisterConfChannel
@@ -175,8 +209,15 @@ func TestLoopInTimeout(t *testing.T) {
175
209
// Let htlc expire.
176
210
ctx .blockEpochChan <- swap .LoopInContract .CltvExpiry
177
211
178
- // Expect a signing request.
179
- <- ctx .lnd .SignOutputRawChannel
212
+ // Expect a signing request for the htlc tx output value.
213
+ //
214
+ // TODO(joostjager): FIX BUG WHERE WE ALWAYS SIGN FOR THE HTLC AMOUNT.
215
+ signReq := <- ctx .lnd .SignOutputRawChannel
216
+ if signReq .SignDescriptors [0 ].Output .Value !=
217
+ int64 (testLoopInRequest .Amount ) {
218
+
219
+ t .Fatal ("invalid signing amount" )
220
+ }
180
221
181
222
// Expect timeout tx to be published.
182
223
timeoutTx := <- ctx .lnd .TxPublishChannel
0 commit comments