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.
loop/loopin_testcontext_test.go

63 lines
1.4 KiB
Go

package loop
import (
"testing"
"time"
"github.com/lightninglabs/loop/loopdb"
"github.com/lightninglabs/loop/sweep"
"github.com/lightninglabs/loop/test"
)
type loopInTestContext struct {
t *testing.T
lnd *test.LndMockServices
server *serverMock
store *storeMock
sweeper *sweep.Sweeper
cfg *executeConfig
statusChan chan SwapInfo
blockEpochChan chan interface{}
}
func newLoopInTestContext(t *testing.T) *loopInTestContext {
lnd := test.NewMockLnd()
server := newServerMock()
store := newStoreMock(t)
sweeper := sweep.Sweeper{Lnd: &lnd.LndServices}
blockEpochChan := make(chan interface{})
statusChan := make(chan SwapInfo)
expiryChan := make(chan time.Time)
timerFactory := func(expiry time.Duration) <-chan time.Time {
return expiryChan
}
cfg := executeConfig{
statusChan: statusChan,
sweeper: &sweeper,
blockEpochChan: blockEpochChan,
timerFactory: timerFactory,
}
return &loopInTestContext{
t: t,
lnd: lnd,
server: server,
store: store,
sweeper: &sweeper,
cfg: &cfg,
statusChan: statusChan,
blockEpochChan: blockEpochChan,
}
}
func (c *loopInTestContext) assertState(expectedState loopdb.SwapState) {
state := <-c.statusChan
if state.State != expectedState {
c.t.Fatalf("expected state %v but got %v", expectedState,
state.State)
}
}