mirror of
https://github.com/lightningnetwork/lnd.git
synced 2024-11-19 09:53:54 +01:00
routing: modify TestSendToRouteStructuredError to return non-second chance error
In this commit, we modify the existing `TestSendToRouteStructuredError` test to return an error that doesn't trigger the second chance logic. Otherwise, we'll get a nil failure result from the mission control interpretation, meaning we won't exercise the full code path. Instead, we use a terminal error to ensure that the expected code path is hit. As is, this test will fail as a recent refactoring causes us to return a `channeldb.FailureReason` error, since the newly added `handleSendError` code path in the `SendToRoute` method will return the raw error, rather than the `shardError`, which is of the expected type.
This commit is contained in:
parent
9c9f821ded
commit
b24edb2833
@ -2921,45 +2921,65 @@ func TestSendToRouteStructuredError(t *testing.T) {
|
|||||||
t.Fatalf("unable to create route: %v", err)
|
t.Fatalf("unable to create route: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// We'll modify the SendToSwitch method so that it simulates a failed
|
finalHopIndex := len(hops)
|
||||||
// payment with an error originating from the first hop of the route.
|
testCases := map[int]lnwire.FailureMessage{
|
||||||
// The unsigned channel update is attached to the failure message.
|
finalHopIndex: lnwire.NewFailIncorrectDetails(payAmt, 100),
|
||||||
|
1: &lnwire.FailFeeInsufficient{
|
||||||
|
Update: lnwire.ChannelUpdate{},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for failIndex, errorType := range testCases {
|
||||||
|
failIndex := failIndex
|
||||||
|
errorType := errorType
|
||||||
|
|
||||||
|
t.Run(fmt.Sprintf("%T", errorType), func(t *testing.T) {
|
||||||
|
// We'll modify the SendToSwitch method so that it
|
||||||
|
// simulates a failed payment with an error originating
|
||||||
|
// from the final hop in the route.
|
||||||
ctx.router.cfg.Payer.(*mockPaymentAttemptDispatcherOld).setPaymentResult(
|
ctx.router.cfg.Payer.(*mockPaymentAttemptDispatcherOld).setPaymentResult(
|
||||||
func(firstHop lnwire.ShortChannelID) ([32]byte, error) {
|
func(firstHop lnwire.ShortChannelID) ([32]byte, error) {
|
||||||
return [32]byte{}, htlcswitch.NewForwardingError(
|
return [32]byte{}, htlcswitch.NewForwardingError(
|
||||||
&lnwire.FailFeeInsufficient{
|
errorType, failIndex,
|
||||||
Update: lnwire.ChannelUpdate{},
|
)
|
||||||
}, 1,
|
},
|
||||||
)
|
)
|
||||||
})
|
|
||||||
|
|
||||||
// The payment parameter is mostly redundant in SendToRoute. Can be left
|
// The payment parameter is mostly redundant in
|
||||||
// empty for this test.
|
// SendToRoute. Can be left empty for this test.
|
||||||
var payment lntypes.Hash
|
var payment lntypes.Hash
|
||||||
|
|
||||||
// Send off the payment request to the router. The specified route
|
// Send off the payment request to the router. The
|
||||||
// should be attempted and the channel update should be received by
|
// specified route should be attempted and the channel
|
||||||
// router and ignored because it is missing a valid signature.
|
// update should be received by router and ignored
|
||||||
|
// because it is missing a valid
|
||||||
|
// signature.
|
||||||
_, err = ctx.router.SendToRoute(payment, rt)
|
_, err = ctx.router.SendToRoute(payment, rt)
|
||||||
|
|
||||||
fErr, ok := err.(*htlcswitch.ForwardingError)
|
fErr, ok := err.(*htlcswitch.ForwardingError)
|
||||||
if !ok {
|
require.True(
|
||||||
t.Fatalf("expected forwarding error")
|
t, ok, "expected forwarding error, got: %T", err,
|
||||||
}
|
)
|
||||||
|
|
||||||
if _, ok := fErr.WireMessage().(*lnwire.FailFeeInsufficient); !ok {
|
require.IsType(
|
||||||
t.Fatalf("expected fee insufficient error")
|
t, errorType, fErr.WireMessage(),
|
||||||
}
|
"expected type %T got %T", errorType,
|
||||||
|
fErr.WireMessage(),
|
||||||
|
)
|
||||||
|
|
||||||
// Check that the correct values were used when initiating the payment.
|
// Check that the correct values were used when
|
||||||
|
// initiating the payment.
|
||||||
select {
|
select {
|
||||||
case initVal := <-init:
|
case initVal := <-init:
|
||||||
if initVal.c.Value != payAmt {
|
if initVal.c.Value != payAmt {
|
||||||
t.Fatalf("expected %v, got %v", payAmt, initVal.c.Value)
|
t.Fatalf("expected %v, got %v", payAmt,
|
||||||
|
initVal.c.Value)
|
||||||
}
|
}
|
||||||
case <-time.After(100 * time.Millisecond):
|
case <-time.After(100 * time.Millisecond):
|
||||||
t.Fatalf("initPayment not called")
|
t.Fatalf("initPayment not called")
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestSendToRouteMultiShardSend checks that a 3-shard payment can be executed
|
// TestSendToRouteMultiShardSend checks that a 3-shard payment can be executed
|
||||||
|
Loading…
Reference in New Issue
Block a user