routing: modify path finding tests to accommodate for flip in fee calc

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.
This commit is contained in:
Olaoluwa Osuntokun 2017-10-24 18:29:18 -07:00
parent a7fe7ae941
commit 57b9b78ce3
No known key found for this signature in database
GPG Key ID: 964EA263DD637C21

@ -391,19 +391,19 @@ func TestBasicGraphPathFinding(t *testing.T) {
// Additionally, we'll ensure that the amount to forward, and fees // Additionally, we'll ensure that the amount to forward, and fees
// computed for each hop are correct. // 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", 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 { if route.TotalAmount != paymentAmt+firstHopFee {
t.Fatalf("first hop forwarding amount incorrect: expected %v, got %v", t.Fatalf("first hop forwarding amount incorrect: expected %v, got %v",
paymentAmt+firstHopFee, route.TotalAmount) 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", t.Fatalf("first hop fee incorrect: expected %v, got %v",
firstHopFee, route.Hops[1].Fee) firstHopFee, 0)
} }
if route.Hops[1].AmtToForward != paymentAmt { 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 // We shouldn't pay any fee for the first, hop, but the fee for the
// second hop posted fee should be exactly: // 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 // * 200 + 4999999 * 2000 / 1000000 = 10199
if routes[0].Hops[0].Fee != 0 { if routes[0].Hops[0].Fee != 10199 {
t.Fatalf("wrong hop fee: got %v, expected %v",
routes[0].Hops[1].Fee, 0)
}
if routes[0].Hops[1].Fee != 10199 {
t.Fatalf("wrong hop fee: got %v, expected %v", t.Fatalf("wrong hop fee: got %v, expected %v",
routes[0].Hops[0].Fee, 10199) 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 // The outgoing CLTV value itself should be the current height plus 30
// to meet Carol's requirements. // to meet Carol's requirements.
if routes[0].Hops[0].OutgoingTimeLock != if routes[0].Hops[0].OutgoingTimeLock !=