mirror of
https://github.com/lightninglabs/loop.git
synced 2026-08-13 12:33:03 +02:00
multi: inject clocks into swap lifecycle and update tests
Inject clock.Clock into swapConfig so that swap initiation times are deterministic and testable. Update all swap tests to use TestClock with a fixed time, and assert that InitiationTime matches the clock value.
This commit is contained in:
parent
66a17f47e6
commit
b702aebbf4
8 changed files with 63 additions and 19 deletions
|
|
@ -7,7 +7,6 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/btcsuite/btcd/btcec/v2"
|
||||
"github.com/btcsuite/btcd/btcutil"
|
||||
|
|
@ -264,7 +263,7 @@ func newLoopInSwap(globalCtx context.Context, cfg *swapConfig,
|
|||
|
||||
// Instantiate a struct that contains all required data to start the
|
||||
// swap.
|
||||
initiationTime := time.Now()
|
||||
initiationTime := cfg.clock.Now()
|
||||
|
||||
contract := loopdb.LoopInContract{
|
||||
HtlcConfTarget: request.HtlcConfTarget,
|
||||
|
|
@ -837,7 +836,7 @@ func (s *loopInSwap) publishOnChainHtlc(ctx context.Context) (bool, error) {
|
|||
// the fee for publishing the htlc.
|
||||
s.cost.Onchain = fee
|
||||
|
||||
s.lastUpdateTime = time.Now()
|
||||
s.lastUpdateTime = s.clock.Now()
|
||||
if err := s.persistState(ctx); err != nil {
|
||||
return false, fmt.Errorf("persist htlc tx: %v", err)
|
||||
}
|
||||
|
|
@ -1210,7 +1209,7 @@ func (s *loopInSwap) persistState(ctx context.Context) error {
|
|||
|
||||
// setState updates the swap state and last update timestamp.
|
||||
func (s *loopInSwap) setState(state loopdb.SwapState) {
|
||||
s.lastUpdateTime = time.Now()
|
||||
s.lastUpdateTime = s.clock.Now()
|
||||
s.state = state
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue