mutli: create execute config constructor

pull/222/head
carla 4 years ago
parent 5b684e295e
commit 773a9cfc73
No known key found for this signature in database
GPG Key ID: 4CA7FE54A6213C91

@ -110,13 +110,14 @@ func (s *executor) run(mainCtx context.Context,
go func() { go func() {
defer s.wg.Done() defer s.wg.Done()
newSwap.execute(mainCtx, &executeConfig{ cfg := newExecuteConfig(
statusChan: statusChan, s.sweeper, statusChan,
sweeper: s.sweeper, s.executorConfig.createExpiryTimer,
blockEpochChan: queue.ChanOut(), queue.ChanOut(),
timerFactory: s.executorConfig.createExpiryTimer, s.executorConfig.loopOutMaxParts,
loopOutMaxParts: s.executorConfig.loopOutMaxParts, )
}, height)
newSwap.execute(mainCtx, cfg, height)
select { select {
case swapDoneChan <- swapID: case swapDoneChan <- swapID:

@ -34,12 +34,10 @@ func newLoopInTestContext(t *testing.T) *loopInTestContext {
return expiryChan return expiryChan
} }
cfg := executeConfig{ cfg := newExecuteConfig(
statusChan: statusChan, &sweeper, statusChan, timerFactory, blockEpochChan,
sweeper: &sweeper, testLoopOutMaxParts,
blockEpochChan: blockEpochChan, )
timerFactory: timerFactory,
}
return &loopInTestContext{ return &loopInTestContext{
t: t, t: t,
@ -47,7 +45,7 @@ func newLoopInTestContext(t *testing.T) *loopInTestContext {
server: server, server: server,
store: store, store: store,
sweeper: &sweeper, sweeper: &sweeper,
cfg: &cfg, cfg: cfg,
statusChan: statusChan, statusChan: statusChan,
blockEpochChan: blockEpochChan, blockEpochChan: blockEpochChan,
} }

@ -69,6 +69,21 @@ type executeConfig struct {
loopOutMaxParts uint32 loopOutMaxParts uint32
} }
// newExecuteConfig creates an execute config.
func newExecuteConfig(sweeper *sweep.Sweeper, statusChan chan<- SwapInfo,
timerFactory func(d time.Duration) <-chan time.Time,
blockEpochChan <-chan interface{},
loopOutMaxParts uint32) *executeConfig {
return &executeConfig{
sweeper: sweeper,
statusChan: statusChan,
blockEpochChan: blockEpochChan,
timerFactory: timerFactory,
loopOutMaxParts: loopOutMaxParts,
}
}
// newLoopOutSwap initiates a new swap with the server and returns a // newLoopOutSwap initiates a new swap with the server and returns a
// corresponding swap object. // corresponding swap object.
func newLoopOutSwap(globalCtx context.Context, cfg *swapConfig, func newLoopOutSwap(globalCtx context.Context, cfg *swapConfig,

@ -19,6 +19,8 @@ import (
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
var testLoopOutMaxParts uint32 = 5
// TestLoopOutPaymentParameters tests the first part of the loop out process up // TestLoopOutPaymentParameters tests the first part of the loop out process up
// to the point where the off-chain payments are made. // to the point where the off-chain payments are made.
func TestLoopOutPaymentParameters(t *testing.T) { func TestLoopOutPaymentParameters(t *testing.T) {
@ -48,8 +50,6 @@ func TestLoopOutPaymentParameters(t *testing.T) {
blockEpochChan := make(chan interface{}) blockEpochChan := make(chan interface{})
statusChan := make(chan SwapInfo) statusChan := make(chan SwapInfo)
const maxParts = 5
// Initiate the swap. // Initiate the swap.
req := *testRequest req := *testRequest
req.OutgoingChanSet = loopdb.ChannelSet{2, 3} req.OutgoingChanSet = loopdb.ChannelSet{2, 3}
@ -66,13 +66,12 @@ func TestLoopOutPaymentParameters(t *testing.T) {
swapCtx, cancel := context.WithCancel(context.Background()) swapCtx, cancel := context.WithCancel(context.Background())
go func() { go func() {
err := swap.execute(swapCtx, &executeConfig{ cfg := newExecuteConfig(
statusChan: statusChan, sweeper, statusChan, timerFactory, blockEpochChan,
sweeper: sweeper, testLoopOutMaxParts,
blockEpochChan: blockEpochChan, )
timerFactory: timerFactory,
loopOutMaxParts: maxParts, err := swap.execute(swapCtx, cfg, height)
}, height)
if err != nil { if err != nil {
log.Error(err) log.Error(err)
} }
@ -101,9 +100,9 @@ func TestLoopOutPaymentParameters(t *testing.T) {
} }
// Assert that it is sent as a multi-part payment. // Assert that it is sent as a multi-part payment.
if swapPayment.MaxParts != maxParts { if swapPayment.MaxParts != testLoopOutMaxParts {
t.Fatalf("Expected %v parts, but got %v", t.Fatalf("Expected %v parts, but got %v",
maxParts, swapPayment.MaxParts) testLoopOutMaxParts, swapPayment.MaxParts)
} }
// Verify the outgoing channel set restriction. // Verify the outgoing channel set restriction.
@ -164,12 +163,12 @@ func TestLateHtlcPublish(t *testing.T) {
errChan := make(chan error) errChan := make(chan error)
go func() { go func() {
err := swap.execute(context.Background(), &executeConfig{ cfg := newExecuteConfig(
statusChan: statusChan, sweeper, statusChan, timerFactory, blockEpochChan,
sweeper: sweeper, testLoopOutMaxParts,
blockEpochChan: blockEpochChan, )
timerFactory: timerFactory,
}, height) err := swap.execute(context.Background(), cfg, height)
if err != nil { if err != nil {
log.Error(err) log.Error(err)
} }
@ -255,12 +254,12 @@ func TestCustomSweepConfTarget(t *testing.T) {
errChan := make(chan error) errChan := make(chan error)
go func() { go func() {
err := swap.execute(context.Background(), &executeConfig{ cfg := newExecuteConfig(
statusChan: statusChan, sweeper, statusChan, timerFactory, blockEpochChan,
blockEpochChan: blockEpochChan, testLoopOutMaxParts,
timerFactory: timerFactory, )
sweeper: sweeper,
}, ctx.Lnd.Height) err := swap.execute(context.Background(), cfg, ctx.Lnd.Height)
if err != nil { if err != nil {
log.Error(err) log.Error(err)
} }
@ -458,12 +457,12 @@ func TestPreimagePush(t *testing.T) {
errChan := make(chan error) errChan := make(chan error)
go func() { go func() {
err := swap.execute(context.Background(), &executeConfig{ cfg := newExecuteConfig(
statusChan: statusChan, sweeper, statusChan, timerFactory, blockEpochChan,
blockEpochChan: blockEpochChan, testLoopOutMaxParts,
timerFactory: timerFactory, )
sweeper: sweeper,
}, ctx.Lnd.Height) err := swap.execute(context.Background(), cfg, ctx.Lnd.Height)
if err != nil { if err != nil {
log.Error(err) log.Error(err)
} }

Loading…
Cancel
Save