You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
1.4 KiB

  1. package loop
  2. import (
  3. "testing"
  4. "time"
  5. "github.com/lightninglabs/loop/loopdb"
  6. "github.com/lightninglabs/loop/sweep"
  7. "github.com/lightninglabs/loop/test"
  8. )
  9. type loopInTestContext struct {
  10. t *testing.T
  11. lnd *test.LndMockServices
  12. server *serverMock
  13. store *storeMock
  14. sweeper *sweep.Sweeper
  15. cfg *executeConfig
  16. statusChan chan SwapInfo
  17. blockEpochChan chan interface{}
  18. }
  19. func newLoopInTestContext(t *testing.T) *loopInTestContext {
  20. lnd := test.NewMockLnd()
  21. server := newServerMock()
  22. store := newStoreMock(t)
  23. sweeper := sweep.Sweeper{Lnd: &lnd.LndServices}
  24. blockEpochChan := make(chan interface{})
  25. statusChan := make(chan SwapInfo)
  26. expiryChan := make(chan time.Time)
  27. timerFactory := func(expiry time.Duration) <-chan time.Time {
  28. return expiryChan
  29. }
  30. cfg := executeConfig{
  31. statusChan: statusChan,
  32. sweeper: &sweeper,
  33. blockEpochChan: blockEpochChan,
  34. timerFactory: timerFactory,
  35. }
  36. return &loopInTestContext{
  37. t: t,
  38. lnd: lnd,
  39. server: server,
  40. store: store,
  41. sweeper: &sweeper,
  42. cfg: &cfg,
  43. statusChan: statusChan,
  44. blockEpochChan: blockEpochChan,
  45. }
  46. }
  47. func (c *loopInTestContext) assertState(expectedState loopdb.SwapState) {
  48. state := <-c.statusChan
  49. if state.State != expectedState {
  50. c.t.Fatalf("expected state %v but got %v", expectedState,
  51. state.State)
  52. }
  53. }