mirror of https://github.com/lightninglabs/loop
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
102 lines
2.1 KiB
Go
102 lines
2.1 KiB
Go
6 years ago
|
package loop
|
||
6 years ago
|
|
||
|
import (
|
||
|
"context"
|
||
|
"errors"
|
||
|
"testing"
|
||
|
"time"
|
||
|
|
||
6 years ago
|
"github.com/lightninglabs/loop/lndclient"
|
||
6 years ago
|
"github.com/lightninglabs/loop/loopdb"
|
||
6 years ago
|
"github.com/lightninglabs/loop/sweep"
|
||
|
"github.com/lightninglabs/loop/test"
|
||
6 years ago
|
)
|
||
|
|
||
|
// TestLateHtlcPublish tests that the client is not revealing the preimage if
|
||
|
// there are not enough blocks left.
|
||
|
func TestLateHtlcPublish(t *testing.T) {
|
||
|
defer test.Guard(t)()
|
||
|
|
||
|
lnd := test.NewMockLnd()
|
||
|
|
||
|
ctx := test.NewContext(t, lnd)
|
||
|
|
||
|
server := newServerMock()
|
||
|
|
||
|
store := newStoreMock(t)
|
||
|
|
||
|
expiryChan := make(chan time.Time)
|
||
|
timerFactory := func(expiry time.Duration) <-chan time.Time {
|
||
|
return expiryChan
|
||
|
}
|
||
|
|
||
|
height := int32(600)
|
||
|
|
||
|
cfg := &swapConfig{
|
||
|
lnd: &lnd.LndServices,
|
||
|
store: store,
|
||
|
server: server,
|
||
|
}
|
||
|
|
||
6 years ago
|
swap, err := newLoopOutSwap(
|
||
6 years ago
|
context.Background(), cfg, height, testRequest,
|
||
|
)
|
||
|
if err != nil {
|
||
|
t.Fatal(err)
|
||
|
}
|
||
|
|
||
|
sweeper := &sweep.Sweeper{Lnd: &lnd.LndServices}
|
||
|
|
||
|
blockEpochChan := make(chan interface{})
|
||
|
statusChan := make(chan SwapInfo)
|
||
|
|
||
|
errChan := make(chan error)
|
||
|
go func() {
|
||
|
err := swap.execute(context.Background(), &executeConfig{
|
||
|
statusChan: statusChan,
|
||
|
sweeper: sweeper,
|
||
|
blockEpochChan: blockEpochChan,
|
||
|
timerFactory: timerFactory,
|
||
|
}, height)
|
||
|
if err != nil {
|
||
|
logger.Error(err)
|
||
|
}
|
||
|
errChan <- err
|
||
|
}()
|
||
|
|
||
6 years ago
|
store.assertLoopOutStored()
|
||
6 years ago
|
|
||
|
state := <-statusChan
|
||
6 years ago
|
if state.State != loopdb.StateInitiated {
|
||
6 years ago
|
t.Fatal("unexpected state")
|
||
|
}
|
||
|
|
||
|
signalSwapPaymentResult := ctx.AssertPaid(swapInvoiceDesc)
|
||
|
signalPrepaymentResult := ctx.AssertPaid(prepayInvoiceDesc)
|
||
|
|
||
|
// Expect client to register for conf
|
||
|
ctx.AssertRegisterConf()
|
||
|
|
||
|
// // Wait too long before publishing htlc.
|
||
|
blockEpochChan <- int32(swap.CltvExpiry - 10)
|
||
|
|
||
|
signalSwapPaymentResult(
|
||
|
errors.New(lndclient.PaymentResultUnknownPaymentHash),
|
||
|
)
|
||
|
signalPrepaymentResult(
|
||
|
errors.New(lndclient.PaymentResultUnknownPaymentHash),
|
||
|
)
|
||
|
|
||
6 years ago
|
store.assertStoreFinished(loopdb.StateFailTimeout)
|
||
6 years ago
|
|
||
|
status := <-statusChan
|
||
6 years ago
|
if status.State != loopdb.StateFailTimeout {
|
||
6 years ago
|
t.Fatal("unexpected state")
|
||
|
}
|
||
|
|
||
|
err = <-errChan
|
||
|
if err != nil {
|
||
|
t.Fatal(err)
|
||
|
}
|
||
|
}
|