diff --git a/htlcswitch/link_test.go b/htlcswitch/link_test.go index c07e46ab0..bcf55cb97 100644 --- a/htlcswitch/link_test.go +++ b/htlcswitch/link_test.go @@ -629,8 +629,7 @@ func TestUpdateForwardingPolicy(t *testing.T) { n.firstBobChannelLink, n.carolChannelLink) // First, send this 1 BTC payment over the three hops, the payment - // should succeed, and all balances should be updated - // accordingly. + // should succeed, and all balances should be updated accordingly. invoice, err := n.makePayment(n.aliceServer, n.carolServer, n.bobServer.PubKey(), hops, amountNoFee, htlcAmt, htlcExpiry) @@ -675,7 +674,25 @@ func TestUpdateForwardingPolicy(t *testing.T) { newPolicy.BaseFee = lnwire.NewMSatFromSatoshis(1000) n.firstBobChannelLink.UpdateForwardingPolicy(newPolicy) - // TODO(roasbeef): should send again an ensure rejected? + // Next, we'll send the payment again, using the exact same per-hop + // payload for each node. This payment should fail as it wont' factor + // in Bob's new fee policy. + _, err = n.makePayment(n.aliceServer, n.carolServer, + n.bobServer.PubKey(), hops, amountNoFee, htlcAmt, + htlcExpiry) + if err == nil { + t.Fatalf("payment should've been rejected") + } + + ferr, ok := err.(*ForwardingError) + if !ok { + t.Fatalf("expected a ForwardingError, instead got: %T", err) + } + switch ferr.FailureMessage.(type) { + case *lnwire.FailFeeInsufficient: + default: + t.Fatalf("expected FailFeeInsufficient instead got: %v", err) + } } // TestChannelLinkMultiHopInsufficientPayment checks that we receive error if diff --git a/htlcswitch/test_utils.go b/htlcswitch/test_utils.go index 99a687ddd..082565a19 100644 --- a/htlcswitch/test_utils.go +++ b/htlcswitch/test_utils.go @@ -384,14 +384,10 @@ func generateHops(payAmt lnwire.MilliSatoshi, startingHeight uint32, fee := ExpectedFee(path[i].cfg.FwrdingPolicy, prevAmount) runningAmt += fee - // If the this the first hop, then we don't need to - // apply any fee, otherwise, the amount to forward - // needs to take into account the fees. - if i == 0 { - amount = prevAmount - } else { - amount = prevAmount + fee - } + // Otherwise, for a node to forward an HTLC, then + // following inequality most hold true: + // * amt_in - fee >= amt_to_forward + amount = runningAmt - fee } hops[i] = ForwardingInfo{