diff --git a/loopout_test.go b/loopout_test.go index 7827b4f..3138b1a 100644 --- a/loopout_test.go +++ b/loopout_test.go @@ -297,7 +297,7 @@ func testCustomSweepConfTarget(t *testing.T) { errChan := make(chan error, 2) - batcherStore := sweepbatcher.NewStoreMock(cfg.store) + batcherStore := sweepbatcher.NewStoreMock() batcher := sweepbatcher.NewBatcher( lnd.WalletKit, lnd.ChainNotifier, lnd.Signer, @@ -530,7 +530,7 @@ func testPreimagePush(t *testing.T) { errChan := make(chan error, 2) - batcherStore := sweepbatcher.NewStoreMock(cfg.store) + batcherStore := sweepbatcher.NewStoreMock() batcher := sweepbatcher.NewBatcher( lnd.WalletKit, lnd.ChainNotifier, lnd.Signer, @@ -951,7 +951,7 @@ func TestLoopOutMuSig2Sweep(t *testing.T) { errChan := make(chan error, 2) - batcherStore := sweepbatcher.NewStoreMock(cfg.store) + batcherStore := sweepbatcher.NewStoreMock() batcher := sweepbatcher.NewBatcher( lnd.WalletKit, lnd.ChainNotifier, lnd.Signer, diff --git a/sweepbatcher/store_mock.go b/sweepbatcher/store_mock.go index 96d5dcf..57cdd34 100644 --- a/sweepbatcher/store_mock.go +++ b/sweepbatcher/store_mock.go @@ -3,7 +3,6 @@ package sweepbatcher import ( "context" "errors" - "fmt" "sort" "github.com/btcsuite/btcd/btcutil" @@ -12,17 +11,15 @@ import ( // StoreMock implements a mock client swap store. type StoreMock struct { - batches map[int32]dbBatch - sweeps map[lntypes.Hash]dbSweep - swapStore LoopOutFetcher + batches map[int32]dbBatch + sweeps map[lntypes.Hash]dbSweep } // NewStoreMock instantiates a new mock store. -func NewStoreMock(swapStore LoopOutFetcher) *StoreMock { +func NewStoreMock() *StoreMock { return &StoreMock{ - batches: make(map[int32]dbBatch), - sweeps: make(map[lntypes.Hash]dbSweep), - swapStore: swapStore, + batches: make(map[int32]dbBatch), + sweeps: make(map[lntypes.Hash]dbSweep), } } @@ -93,21 +90,9 @@ func (s *StoreMock) FetchBatchSweeps(ctx context.Context, result := []*dbSweep{} for _, sweep := range s.sweeps { sweep := sweep - if sweep.BatchID != id { - continue + if sweep.BatchID == id { + result = append(result, &sweep) } - - // Load swap from loopdb. - swap, err := s.swapStore.FetchLoopOutSwap( - ctx, sweep.SwapHash, - ) - if err != nil { - return nil, fmt.Errorf("failed to fetch swap "+ - "for SwapHash=%v", sweep.SwapHash) - } - sweep.LoopOut = swap - - result = append(result, &sweep) } sort.Slice(result, func(i, j int) bool { diff --git a/sweepbatcher/sweep_batcher_test.go b/sweepbatcher/sweep_batcher_test.go index 4b73cfa..4afb726 100644 --- a/sweepbatcher/sweep_batcher_test.go +++ b/sweepbatcher/sweep_batcher_test.go @@ -64,7 +64,7 @@ func TestSweepBatcherBatchCreation(t *testing.T) { store := loopdb.NewStoreMock(t) - batcherStore := NewStoreMock(store) + batcherStore := NewStoreMock() batcher := NewBatcher(lnd.WalletKit, lnd.ChainNotifier, lnd.Signer, testMuSig2SignSweep, nil, lnd.ChainParams, batcherStore, store) @@ -218,7 +218,7 @@ func TestSweepBatcherSimpleLifecycle(t *testing.T) { store := loopdb.NewStoreMock(t) - batcherStore := NewStoreMock(store) + batcherStore := NewStoreMock() batcher := NewBatcher(lnd.WalletKit, lnd.ChainNotifier, lnd.Signer, testMuSig2SignSweep, nil, lnd.ChainParams, batcherStore, store) @@ -355,7 +355,7 @@ func TestSweepBatcherSweepReentry(t *testing.T) { store := loopdb.NewStoreMock(t) - batcherStore := NewStoreMock(store) + batcherStore := NewStoreMock() batcher := NewBatcher(lnd.WalletKit, lnd.ChainNotifier, lnd.Signer, testMuSig2SignSweep, nil, lnd.ChainParams, batcherStore, store) @@ -562,7 +562,7 @@ func TestSweepBatcherNonWalletAddr(t *testing.T) { store := loopdb.NewStoreMock(t) - batcherStore := NewStoreMock(store) + batcherStore := NewStoreMock() batcher := NewBatcher(lnd.WalletKit, lnd.ChainNotifier, lnd.Signer, testMuSig2SignSweep, nil, lnd.ChainParams, batcherStore, store) @@ -727,7 +727,7 @@ func TestSweepBatcherComposite(t *testing.T) { store := loopdb.NewStoreMock(t) - batcherStore := NewStoreMock(store) + batcherStore := NewStoreMock() batcher := NewBatcher(lnd.WalletKit, lnd.ChainNotifier, lnd.Signer, testMuSig2SignSweep, nil, lnd.ChainParams, batcherStore, store) @@ -1044,7 +1044,7 @@ func TestRestoringEmptyBatch(t *testing.T) { store := loopdb.NewStoreMock(t) - batcherStore := NewStoreMock(store) + batcherStore := NewStoreMock() _, err := batcherStore.InsertSweepBatch(ctx, &dbBatch{}) require.NoError(t, err) @@ -1158,7 +1158,7 @@ func TestHandleSweepTwice(t *testing.T) { store := newLoopStoreMock() - batcherStore := NewStoreMock(store) + batcherStore := NewStoreMock() batcher := NewBatcher(lnd.WalletKit, lnd.ChainNotifier, lnd.Signer, testMuSig2SignSweep, nil, lnd.ChainParams, batcherStore, store) @@ -1314,7 +1314,7 @@ func TestRestoringPreservesConfTarget(t *testing.T) { store := loopdb.NewStoreMock(t) - batcherStore := NewStoreMock(store) + batcherStore := NewStoreMock() batcher := NewBatcher(lnd.WalletKit, lnd.ChainNotifier, lnd.Signer, testMuSig2SignSweep, nil, lnd.ChainParams, batcherStore, store) diff --git a/testcontext_test.go b/testcontext_test.go index 9f8f120..423eb31 100644 --- a/testcontext_test.go +++ b/testcontext_test.go @@ -77,7 +77,7 @@ func newSwapClient(config *clientConfig) *Client { lndServices := config.LndServices - batcherStore := sweepbatcher.NewStoreMock(config.Store) + batcherStore := sweepbatcher.NewStoreMock() batcher := sweepbatcher.NewBatcher( config.LndServices.WalletKit, config.LndServices.ChainNotifier,