github.com/decred/dcrlnd@v0.7.6/routing/unified_policies_test.go (about) 1 package routing 2 3 import ( 4 "testing" 5 6 "github.com/decred/dcrlnd/channeldb" 7 "github.com/decred/dcrlnd/lnwire" 8 "github.com/decred/dcrlnd/routing/route" 9 ) 10 11 // TestUnifiedPolicies tests the composition of unified policies for nodes that 12 // have multiple channels between them. 13 func TestUnifiedPolicies(t *testing.T) { 14 source := route.Vertex{1} 15 toNode := route.Vertex{2} 16 fromNode := route.Vertex{3} 17 18 bandwidthHints := &mockBandwidthHints{} 19 20 u := newUnifiedPolicies(source, toNode, nil) 21 22 // Add two channels between the pair of nodes. 23 p1 := channeldb.CachedEdgePolicy{ 24 FeeProportionalMillionths: 100000, 25 FeeBaseMAtoms: 30, 26 TimeLockDelta: 60, 27 MessageFlags: lnwire.ChanUpdateOptionMaxHtlc, 28 MaxHTLC: 500, 29 MinHTLC: 100, 30 } 31 p2 := channeldb.CachedEdgePolicy{ 32 FeeProportionalMillionths: 190000, 33 FeeBaseMAtoms: 10, 34 TimeLockDelta: 40, 35 MessageFlags: lnwire.ChanUpdateOptionMaxHtlc, 36 MaxHTLC: 400, 37 MinHTLC: 100, 38 } 39 u.addPolicy(fromNode, &p1, 7) 40 u.addPolicy(fromNode, &p2, 7) 41 42 checkPolicy := func(policy *channeldb.CachedEdgePolicy, 43 feeBase lnwire.MilliAtom, feeRate lnwire.MilliAtom, 44 timeLockDelta uint16) { 45 46 t.Helper() 47 48 if policy.FeeBaseMAtoms != feeBase { 49 t.Fatalf("expected fee base %v, got %v", 50 feeBase, policy.FeeBaseMAtoms) 51 } 52 53 if policy.TimeLockDelta != timeLockDelta { 54 t.Fatalf("expected fee base %v, got %v", 55 timeLockDelta, policy.TimeLockDelta) 56 } 57 58 if policy.FeeProportionalMillionths != feeRate { 59 t.Fatalf("expected fee rate %v, got %v", 60 feeRate, policy.FeeProportionalMillionths) 61 } 62 } 63 64 policy := u.policies[fromNode].getPolicy(50, bandwidthHints) 65 if policy != nil { 66 t.Fatal("expected no policy for amt below min htlc") 67 } 68 69 policy = u.policies[fromNode].getPolicy(550, bandwidthHints) 70 if policy != nil { 71 t.Fatal("expected no policy for amt above max htlc") 72 } 73 74 // For 200 sat, p1 yields the highest fee. Use that policy to forward, 75 // because it will also match p2 in case p1 does not have enough 76 // balance. 77 policy = u.policies[fromNode].getPolicy(200, bandwidthHints) 78 checkPolicy( 79 policy, p1.FeeBaseMAtoms, p1.FeeProportionalMillionths, 80 p1.TimeLockDelta, 81 ) 82 83 // For 400 sat, p2 yields the highest fee. Use that policy to forward, 84 // because it will also match p1 in case p2 does not have enough 85 // balance. In order to match p1, it needs to have p1's time lock delta. 86 policy = u.policies[fromNode].getPolicy(400, bandwidthHints) 87 checkPolicy( 88 policy, p2.FeeBaseMAtoms, p2.FeeProportionalMillionths, 89 p1.TimeLockDelta, 90 ) 91 }