44 "context"
55 "testing"
66
7- "github.com/lightninglabs/lndclient"
87 "github.com/lightninglabs/loop/loopdb"
98 "github.com/lightninglabs/loop/swap"
109 "github.com/lightninglabs/loop/test"
@@ -89,17 +88,11 @@ func TestLoopInSuccess(t *testing.T) {
8988 <- ctx .lnd .RegisterSpendChannel
9089
9190 // Client starts listening for swap invoice updates.
92- subscription := <- ctx .lnd .SingleInvoiceSubcribeChannel
93- if subscription .Hash != ctx .server .swapHash {
94- t .Fatal ("client subscribing to wrong invoice" )
95- }
91+ ctx .assertSubscribeInvoice (ctx .server .swapHash )
9692
9793 // Server has already paid invoice before spending the htlc. Signal
9894 // settled.
99- subscription .Update <- lndclient.InvoiceUpdate {
100- State : channeldb .ContractSettled ,
101- AmtPaid : 49000 ,
102- }
95+ ctx .updateInvoiceState (49000 , channeldb .ContractSettled )
10396
10497 // Swap is expected to move to the state InvoiceSettled
10598 ctx .assertState (loopdb .StateInvoiceSettled )
@@ -257,10 +250,7 @@ func testLoopInTimeout(t *testing.T,
257250 <- ctx .lnd .RegisterSpendChannel
258251
259252 // Client starts listening for swap invoice updates.
260- subscription := <- ctx .lnd .SingleInvoiceSubcribeChannel
261- if subscription .Hash != ctx .server .swapHash {
262- t .Fatal ("client subscribing to wrong invoice" )
263- }
253+ ctx .assertSubscribeInvoice (ctx .server .swapHash )
264254
265255 // Let htlc expire.
266256 ctx .blockEpochChan <- s .LoopInContract .CltvExpiry
@@ -294,10 +284,8 @@ func testLoopInTimeout(t *testing.T,
294284 // safely cancel the swap invoice.
295285 <- ctx .lnd .FailInvoiceChannel
296286
297- // Signal the the invoice was canceled.
298- subscription .Update <- lndclient.InvoiceUpdate {
299- State : channeldb .ContractCanceled ,
300- }
287+ // Signal that the invoice was canceled.
288+ ctx .updateInvoiceState (0 , channeldb .ContractCanceled )
301289
302290 ctx .assertState (loopdb .StateFailTimeout )
303291 state := ctx .store .assertLoopInState (loopdb .StateFailTimeout )
@@ -501,18 +489,12 @@ func testLoopInResume(t *testing.T, state loopdb.SwapState, expired bool,
501489 <- ctx .lnd .RegisterSpendChannel
502490
503491 // Client starts listening for swap invoice updates.
504- subscription := <- ctx .lnd .SingleInvoiceSubcribeChannel
505- if subscription .Hash != testPreimage .Hash () {
506- t .Fatal ("client subscribing to wrong invoice" )
507- }
492+ ctx .assertSubscribeInvoice (testPreimage .Hash ())
508493
509494 // Server has already paid invoice before spending the htlc. Signal
510495 // settled.
511- invoiceUpdate := lndclient.InvoiceUpdate {
512- State : channeldb .ContractSettled ,
513- AmtPaid : 49000 ,
514- }
515- subscription .Update <- invoiceUpdate
496+ amtPaid := btcutil .Amount (49000 )
497+ ctx .updateInvoiceState (amtPaid , channeldb .ContractSettled )
516498
517499 // Swap is expected to move to the state InvoiceSettled
518500 ctx .assertState (loopdb .StateInvoiceSettled )
@@ -537,7 +519,6 @@ func testLoopInResume(t *testing.T, state loopdb.SwapState, expired bool,
537519 // We expect our server fee to reflect as the difference between htlc
538520 // value and invoice amount paid. We use our original on-chain cost, set
539521 // earlier in the test, because we expect this value to be unchanged.
540- cost .Server = btcutil .Amount (htlcTx .TxOut [0 ].Value ) -
541- invoiceUpdate .AmtPaid
522+ cost .Server = btcutil .Amount (htlcTx .TxOut [0 ].Value ) - amtPaid
542523 require .Equal (t , cost , finalState .Cost )
543524}
0 commit comments