@@ -113,9 +113,25 @@ func TestLoopInSuccess(t *testing.T) {
113113 }
114114}
115115
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
117117// and the client is forced to reclaim the funds using the timeout tx.
118118func 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 ) {
119135 defer test .Guard (t )()
120136
121137 ctx := newLoopInTestContext (t )
@@ -128,9 +144,14 @@ func TestLoopInTimeout(t *testing.T) {
128144 server : ctx .server ,
129145 }
130146
147+ req := testLoopInRequest
148+ if externalValue != 0 {
149+ req .ExternalHtlc = true
150+ }
151+
131152 swap , err := newLoopInSwap (
132153 context .Background (), cfg ,
133- height , & testLoopInRequest ,
154+ height , & req ,
134155 )
135156 if err != nil {
136157 t .Fatal (err )
@@ -152,8 +173,21 @@ func TestLoopInTimeout(t *testing.T) {
152173 ctx .assertState (loopdb .StateHtlcPublished )
153174 ctx .store .assertLoopInState (loopdb .StateHtlcPublished )
154175
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+ }
157191
158192 // Expect register for htlc conf.
159193 <- ctx .lnd .RegisterConfChannel
@@ -175,6 +209,13 @@ func TestLoopInTimeout(t *testing.T) {
175209 // Let htlc expire.
176210 ctx .blockEpochChan <- swap .LoopInContract .CltvExpiry
177211
212+ // Expect a signing request for the htlc tx output value.
213+ signReq := <- ctx .lnd .SignOutputRawChannel
214+ if signReq .SignDescriptors [0 ].Output .Value != htlcTx .TxOut [0 ].Value {
215+
216+ t .Fatal ("invalid signing amount" )
217+ }
218+
178219 // Expect timeout tx to be published.
179220 timeoutTx := <- ctx .lnd .TxPublishChannel
180221
0 commit comments