From 57b9b78ce3f5e72a1d20826c3e84627d257cf840 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Tue, 24 Oct 2017 18:29:18 -0700 Subject: [PATCH] routing: modify path finding tests to accommodate for flip in fee calc MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before this commit, we would expect that structurally we don’t pay any fee for the first hop, but do for the final hop. After the latest commit, this is now flipped as when we say fee, we mean the fee that we need to pay to transit a link. For the final hop, there’s no additional distance to be traveled, so the fee is nothing. --- routing/pathfind_test.go | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/routing/pathfind_test.go b/routing/pathfind_test.go index cab890eb..d37fc52d 100644 --- a/routing/pathfind_test.go +++ b/routing/pathfind_test.go @@ -391,19 +391,19 @@ func TestBasicGraphPathFinding(t *testing.T) { // Additionally, we'll ensure that the amount to forward, and fees // computed for each hop are correct. - if route.Hops[0].Fee != 0 { + firstHopFee := computeFee(paymentAmt, route.Hops[1].Channel) + if route.Hops[0].Fee != firstHopFee { t.Fatalf("first hop fee incorrect: expected %v, got %v", - 0, route.Hops[1].Fee) + firstHopFee, route.Hops[0].Fee) } - firstHopFee := computeFee(paymentAmt, route.Hops[1].Channel) if route.TotalAmount != paymentAmt+firstHopFee { t.Fatalf("first hop forwarding amount incorrect: expected %v, got %v", paymentAmt+firstHopFee, route.TotalAmount) } - if route.Hops[1].Fee != firstHopFee { + if route.Hops[1].Fee != 0 { t.Fatalf("first hop fee incorrect: expected %v, got %v", - firstHopFee, route.Hops[1].Fee) + firstHopFee, 0) } if route.Hops[1].AmtToForward != paymentAmt { @@ -773,17 +773,23 @@ func TestPathFindSpecExample(t *testing.T) { // We shouldn't pay any fee for the first, hop, but the fee for the // second hop posted fee should be exactly: + + // The fee that we pay for the second hop will be "applied to the first + // hop, so we should get a fee of exactly: // // * 200 + 4999999 * 2000 / 1000000 = 10199 - if routes[0].Hops[0].Fee != 0 { - t.Fatalf("wrong hop fee: got %v, expected %v", - routes[0].Hops[1].Fee, 0) - } - if routes[0].Hops[1].Fee != 10199 { + if routes[0].Hops[0].Fee != 10199 { t.Fatalf("wrong hop fee: got %v, expected %v", routes[0].Hops[0].Fee, 10199) } + // While for the final hop, as there's no additional hop afterwards, we + // pay no fee. + if routes[0].Hops[1].Fee != 0 { + t.Fatalf("wrong hop fee: got %v, expected %v", + routes[0].Hops[0].Fee, 0) + } + // The outgoing CLTV value itself should be the current height plus 30 // to meet Carol's requirements. if routes[0].Hops[0].OutgoingTimeLock !=