@@ -351,13 +351,16 @@ func TestRestrictedSuggestions(t *testing.T) {
351351 return testCase .loopIn , nil
352352 }
353353
354- rules := map [lnwire.ShortChannelID ]* ThresholdRule {
354+ lnd .Channels = testCase .channels
355+
356+ params := defaultParameters
357+ params .ChannelRules = map [lnwire.ShortChannelID ]* ThresholdRule {
355358 chanID1 : chanRule ,
356359 chanID2 : chanRule ,
357360 }
358361
359362 testSuggestSwaps (
360- t , cfg , lnd , testCase . channels , rules ,
363+ t , newSuggestSwapsSetup ( cfg , lnd , params ) ,
361364 testCase .expected ,
362365 )
363366 })
@@ -397,16 +400,18 @@ func TestSweepFeeLimit(t *testing.T) {
397400 loop .DefaultSweepConfTarget , testCase .feeRate ,
398401 )
399402
400- channels : = []lndclient.ChannelInfo {
403+ lnd . Channels = []lndclient.ChannelInfo {
401404 channel1 ,
402405 }
403406
404- rules := map [lnwire.ShortChannelID ]* ThresholdRule {
407+ params := defaultParameters
408+ params .ChannelRules = map [lnwire.ShortChannelID ]* ThresholdRule {
405409 chanID1 : chanRule ,
406410 }
407411
408412 testSuggestSwaps (
409- t , cfg , lnd , channels , rules , testCase .swaps ,
413+ t , newSuggestSwapsSetup (cfg , lnd , params ),
414+ testCase .swaps ,
410415 )
411416 })
412417 }
@@ -448,12 +453,15 @@ func TestSuggestSwaps(t *testing.T) {
448453 t .Run (testCase .name , func (t * testing.T ) {
449454 cfg , lnd := newTestConfig ()
450455
451- channels : = []lndclient.ChannelInfo {
456+ lnd . Channels = []lndclient.ChannelInfo {
452457 channel1 ,
453458 }
454459
460+ params := defaultParameters
461+ params .ChannelRules = testCase .rules
462+
455463 testSuggestSwaps (
456- t , cfg , lnd , channels , testCase . rules ,
464+ t , newSuggestSwapsSetup ( cfg , lnd , params ) ,
457465 testCase .swaps ,
458466 )
459467 })
@@ -513,40 +521,78 @@ func TestFeeLimits(t *testing.T) {
513521 return testCase .quote , nil
514522 }
515523
516- channels : = []lndclient.ChannelInfo {
524+ lnd . Channels = []lndclient.ChannelInfo {
517525 channel1 ,
518526 }
519- rules := map [lnwire.ShortChannelID ]* ThresholdRule {
527+
528+ params := defaultParameters
529+ params .ChannelRules = map [lnwire.ShortChannelID ]* ThresholdRule {
520530 chanID1 : chanRule ,
521531 }
522532
523533 testSuggestSwaps (
524- t , cfg , lnd , channels , rules , testCase .expected ,
534+ t , newSuggestSwapsSetup (cfg , lnd , params ),
535+ testCase .expected ,
525536 )
526537 })
527538 }
528539}
529540
530- // testSuggestSwaps tests getting swap suggestions.
531- func testSuggestSwaps (t * testing.T , cfg * Config , lnd * test.LndMockServices ,
532- channels []lndclient.ChannelInfo ,
533- rules map [lnwire.ShortChannelID ]* ThresholdRule ,
541+ // testSuggestSwapsSetup contains the elements that are used to create a
542+ // suggest swaps test.
543+ type testSuggestSwapsSetup struct {
544+ cfg * Config
545+ lnd * test.LndMockServices
546+ params Parameters
547+ }
548+
549+ // newSuggestSwapsSetup creates a suggest swaps setup struct.
550+ func newSuggestSwapsSetup (cfg * Config , lnd * test.LndMockServices ,
551+ params Parameters ) * testSuggestSwapsSetup {
552+
553+ return & testSuggestSwapsSetup {
554+ cfg : cfg ,
555+ lnd : lnd ,
556+ params : params ,
557+ }
558+ }
559+
560+ // testSuggestSwaps tests getting swap suggestions. It takes a setup struct
561+ // which contains custom setup for the test. If this struct is nil, it will
562+ // use the default parameters and setup two channels (channel1 + channel2) with
563+ // chanRule set for each.
564+ func testSuggestSwaps (t * testing.T , setup * testSuggestSwapsSetup ,
534565 expected []loop.OutRequest ) {
535566
536567 t .Parallel ()
537568
538- // Create a mock lnd with the set of channels set in our test case and
539- // update our test case lnd to use these channels.
540- lnd .Channels = channels
569+ // If our setup struct is nil, we replace it with our default test
570+ // values.
571+ if setup == nil {
572+ cfg , lnd := newTestConfig ()
573+
574+ lnd .Channels = []lndclient.ChannelInfo {
575+ channel1 , channel2 ,
576+ }
577+
578+ params := defaultParameters
579+ params .ChannelRules = map [lnwire.ShortChannelID ]* ThresholdRule {
580+ chanID1 : chanRule ,
581+ chanID2 : chanRule ,
582+ }
583+
584+ setup = & testSuggestSwapsSetup {
585+ cfg : cfg ,
586+ lnd : lnd ,
587+ params : params ,
588+ }
589+ }
541590
542591 // Create a new manager, get our current set of parameters and update
543592 // them to use the rules set by the test.
544- manager := NewManager (cfg )
545-
546- currentParams := manager .GetParameters ()
547- currentParams .ChannelRules = rules
593+ manager := NewManager (setup .cfg )
548594
549- err := manager .SetParameters (currentParams )
595+ err := manager .SetParameters (setup . params )
550596 require .NoError (t , err )
551597
552598 actual , err := manager .SuggestSwaps (context .Background ())
0 commit comments