loopd: add loop in state InvoiceSettled

This commit is contained in:
Joost Jager 2019-04-02 10:51:51 +02:00
parent a7f4feb9ea
commit b5d2fb3894
No known key found for this signature in database
GPG key ID: A61B9D4C393C59C7
7 changed files with 242 additions and 190 deletions

View file

@ -76,17 +76,6 @@ func TestLoopInSuccess(t *testing.T) {
// Client starts listening for spend of htlc.
<-ctx.lnd.RegisterSpendChannel
// Server spends htlc.
successTx := wire.MsgTx{}
successTx.AddTxIn(&wire.TxIn{
Witness: [][]byte{{}, {}, {}},
})
ctx.lnd.SpendChannel <- &chainntnfs.SpendDetail{
SpendingTx: &successTx,
SpenderInputIndex: 0,
}
// Client starts listening for swap invoice updates.
subscription := <-ctx.lnd.SingleInvoiceSubcribeChannel
if subscription.Hash != ctx.server.swapHash {
@ -100,6 +89,21 @@ func TestLoopInSuccess(t *testing.T) {
AmtPaid: 49000,
}
// Swap is expected to move to the state InvoiceSettled
ctx.assertState(loopdb.StateInvoiceSettled)
ctx.store.assertLoopInState(loopdb.StateInvoiceSettled)
// Server spends htlc.
successTx := wire.MsgTx{}
successTx.AddTxIn(&wire.TxIn{
Witness: [][]byte{{}, {}, {}},
})
ctx.lnd.SpendChannel <- &chainntnfs.SpendDetail{
SpendingTx: &successTx,
SpenderInputIndex: 0,
}
ctx.assertState(loopdb.StateSuccess)
ctx.store.assertLoopInState(loopdb.StateSuccess)
@ -162,6 +166,12 @@ func TestLoopInTimeout(t *testing.T) {
// Client starts listening for spend of htlc.
<-ctx.lnd.RegisterSpendChannel
// Client starts listening for swap invoice updates.
subscription := <-ctx.lnd.SingleInvoiceSubcribeChannel
if subscription.Hash != ctx.server.swapHash {
t.Fatal("client subscribing to wrong invoice")
}
// Let htlc expire.
ctx.blockEpochChan <- swap.LoopInContract.CltvExpiry
@ -178,12 +188,6 @@ func TestLoopInTimeout(t *testing.T) {
// safely cancel the swap invoice.
<-ctx.lnd.FailInvoiceChannel
// Client starts listening for swap invoice updates.
subscription := <-ctx.lnd.SingleInvoiceSubcribeChannel
if subscription.Hash != ctx.server.swapHash {
t.Fatal("client subscribing to wrong invoice")
}
// Signal the the invoice was canceled.
subscription.Update <- lndclient.InvoiceUpdate{
State: channeldb.ContractCanceled,
@ -340,19 +344,6 @@ func testLoopInResume(t *testing.T, state loopdb.SwapState, expired bool) {
// Client starts listening for spend of htlc.
<-ctx.lnd.RegisterSpendChannel
// Server spends htlc.
successTx := wire.MsgTx{}
successTx.AddTxIn(&wire.TxIn{
Witness: [][]byte{{}, {}, {}},
})
successTxHash := successTx.TxHash()
ctx.lnd.SpendChannel <- &chainntnfs.SpendDetail{
SpendingTx: &successTx,
SpenderTxHash: &successTxHash,
SpenderInputIndex: 0,
}
// Client starts listening for swap invoice updates.
subscription := <-ctx.lnd.SingleInvoiceSubcribeChannel
if subscription.Hash != testPreimage.Hash() {
@ -366,5 +357,22 @@ func testLoopInResume(t *testing.T, state loopdb.SwapState, expired bool) {
AmtPaid: 49000,
}
// Swap is expected to move to the state InvoiceSettled
ctx.assertState(loopdb.StateInvoiceSettled)
ctx.store.assertLoopInState(loopdb.StateInvoiceSettled)
// Server spends htlc.
successTx := wire.MsgTx{}
successTx.AddTxIn(&wire.TxIn{
Witness: [][]byte{{}, {}, {}},
})
successTxHash := successTx.TxHash()
ctx.lnd.SpendChannel <- &chainntnfs.SpendDetail{
SpendingTx: &successTx,
SpenderTxHash: &successTxHash,
SpenderInputIndex: 0,
}
ctx.assertState(loopdb.StateSuccess)
}