htlcswitch+routing: type check on ClearTextError
Update the type check used for checking local payment failures to check on the ClearTextError interface rather than on the ForwardingError type. This change prepares for splitting payment errors up into Link and Forwarding errors.
This commit is contained in:
5 files changed
+94
-62
No files matched your search
+47
-43
@@ -574,12 +574,12 @@ func TestExitNodeTimelockPayloadMismatch(t *testing.T) {
|
||||
t.Fatalf("payment should have failed but didn't")
|
||||
}
|
||||
|
||||
ferr, ok := err.(*ForwardingError)
|
||||
rtErr, ok := err.(ClearTextError)
|
||||
if !ok {
|
||||
t.Fatalf("expected a ForwardingError, instead got: %T", err)
|
||||
t.Fatalf("expected a ClearTextError, instead got: %T", err)
|
||||
}
|
||||
|
||||
switch ferr.WireMessage().(type) {
|
||||
switch rtErr.WireMessage().(type) {
|
||||
case *lnwire.FailFinalIncorrectCltvExpiry:
|
||||
default:
|
||||
t.Fatalf("incorrect error, expected incorrect cltv expiry, "+
|
||||
@@ -674,12 +674,12 @@ func TestLinkForwardTimelockPolicyMismatch(t *testing.T) {
|
||||
t.Fatalf("payment should have failed but didn't")
|
||||
}
|
||||
|
||||
ferr, ok := err.(*ForwardingError)
|
||||
rtErr, ok := err.(ClearTextError)
|
||||
if !ok {
|
||||
t.Fatalf("expected a ForwardingError, instead got: %T", err)
|
||||
t.Fatalf("expected a ClearTextError, instead got: %T", err)
|
||||
}
|
||||
|
||||
switch ferr.WireMessage().(type) {
|
||||
switch rtErr.WireMessage().(type) {
|
||||
case *lnwire.FailIncorrectCltvExpiry:
|
||||
default:
|
||||
t.Fatalf("incorrect error, expected incorrect cltv expiry, "+
|
||||
@@ -732,12 +732,12 @@ func TestLinkForwardFeePolicyMismatch(t *testing.T) {
|
||||
t.Fatalf("payment should have failed but didn't")
|
||||
}
|
||||
|
||||
ferr, ok := err.(*ForwardingError)
|
||||
rtErr, ok := err.(ClearTextError)
|
||||
if !ok {
|
||||
t.Fatalf("expected a ForwardingError, instead got: %T", err)
|
||||
t.Fatalf("expected a ClearTextError, instead got: %T", err)
|
||||
}
|
||||
|
||||
switch ferr.WireMessage().(type) {
|
||||
switch rtErr.WireMessage().(type) {
|
||||
case *lnwire.FailFeeInsufficient:
|
||||
default:
|
||||
t.Fatalf("incorrect error, expected fee insufficient, "+
|
||||
@@ -790,12 +790,12 @@ func TestLinkForwardMinHTLCPolicyMismatch(t *testing.T) {
|
||||
t.Fatalf("payment should have failed but didn't")
|
||||
}
|
||||
|
||||
ferr, ok := err.(*ForwardingError)
|
||||
rtErr, ok := err.(ClearTextError)
|
||||
if !ok {
|
||||
t.Fatalf("expected a ForwardingError, instead got: %T", err)
|
||||
t.Fatalf("expected a ClearTextError, instead got: %T", err)
|
||||
}
|
||||
|
||||
switch ferr.WireMessage().(type) {
|
||||
switch rtErr.WireMessage().(type) {
|
||||
case *lnwire.FailAmountBelowMinimum:
|
||||
default:
|
||||
t.Fatalf("incorrect error, expected amount below minimum, "+
|
||||
@@ -857,12 +857,12 @@ func TestLinkForwardMaxHTLCPolicyMismatch(t *testing.T) {
|
||||
t.Fatalf("payment should have failed but didn't")
|
||||
}
|
||||
|
||||
ferr, ok := err.(*ForwardingError)
|
||||
rtErr, ok := err.(ClearTextError)
|
||||
if !ok {
|
||||
t.Fatalf("expected a ForwardingError, instead got: %T", err)
|
||||
t.Fatalf("expected a ClearTextError, instead got: %T", err)
|
||||
}
|
||||
|
||||
switch ferr.WireMessage().(type) {
|
||||
switch rtErr.WireMessage().(type) {
|
||||
case *lnwire.FailTemporaryChannelFailure:
|
||||
default:
|
||||
t.Fatalf("incorrect error, expected temporary channel failure, "+
|
||||
@@ -964,11 +964,12 @@ func TestUpdateForwardingPolicy(t *testing.T) {
|
||||
t.Fatalf("payment should've been rejected")
|
||||
}
|
||||
|
||||
ferr, ok := err.(*ForwardingError)
|
||||
rtErr, ok := err.(ClearTextError)
|
||||
if !ok {
|
||||
t.Fatalf("expected a ForwardingError, instead got (%T): %v", err, err)
|
||||
t.Fatalf("expected a ClearTextError, instead got (%T): %v", err, err)
|
||||
}
|
||||
switch ferr.WireMessage().(type) {
|
||||
|
||||
switch rtErr.WireMessage().(type) {
|
||||
case *lnwire.FailFeeInsufficient:
|
||||
default:
|
||||
t.Fatalf("expected FailFeeInsufficient instead got: %v", err)
|
||||
@@ -1003,12 +1004,13 @@ func TestUpdateForwardingPolicy(t *testing.T) {
|
||||
t.Fatalf("payment should've been rejected")
|
||||
}
|
||||
|
||||
ferr, ok = err.(*ForwardingError)
|
||||
rtErr, ok = err.(ClearTextError)
|
||||
if !ok {
|
||||
t.Fatalf("expected a ForwardingError, instead got (%T): %v",
|
||||
t.Fatalf("expected a ClearTextError, instead got (%T): %v",
|
||||
err, err)
|
||||
}
|
||||
switch ferr.WireMessage().(type) {
|
||||
|
||||
switch rtErr.WireMessage().(type) {
|
||||
case *lnwire.FailTemporaryChannelFailure:
|
||||
default:
|
||||
t.Fatalf("expected TemporaryChannelFailure, instead got: %v",
|
||||
@@ -1249,13 +1251,14 @@ func TestChannelLinkMultiHopUnknownNextHop(t *testing.T) {
|
||||
if err == nil {
|
||||
t.Fatal("error haven't been received")
|
||||
}
|
||||
fErr, ok := err.(*ForwardingError)
|
||||
rtErr, ok := err.(ClearTextError)
|
||||
if !ok {
|
||||
t.Fatalf("expected ForwardingError")
|
||||
t.Fatalf("expected ClearTextError")
|
||||
}
|
||||
if _, ok = fErr.WireMessage().(*lnwire.FailUnknownNextPeer); !ok {
|
||||
|
||||
if _, ok = rtErr.WireMessage().(*lnwire.FailUnknownNextPeer); !ok {
|
||||
t.Fatalf("wrong error has been received: %T",
|
||||
fErr.WireMessage())
|
||||
rtErr.WireMessage())
|
||||
}
|
||||
|
||||
// Wait for Alice to receive the revocation.
|
||||
@@ -1364,12 +1367,12 @@ func TestChannelLinkMultiHopDecodeError(t *testing.T) {
|
||||
t.Fatal("error haven't been received")
|
||||
}
|
||||
|
||||
ferr, ok := err.(*ForwardingError)
|
||||
rtErr, ok := err.(ClearTextError)
|
||||
if !ok {
|
||||
t.Fatalf("expected a ForwardingError, instead got: %T", err)
|
||||
t.Fatalf("expected a ClearTextError, instead got: %T", err)
|
||||
}
|
||||
|
||||
switch ferr.WireMessage().(type) {
|
||||
switch rtErr.WireMessage().(type) {
|
||||
case *lnwire.FailInvalidOnionVersion:
|
||||
default:
|
||||
t.Fatalf("wrong error have been received: %v", err)
|
||||
@@ -1456,13 +1459,13 @@ func TestChannelLinkExpiryTooSoonExitNode(t *testing.T) {
|
||||
"time lock value")
|
||||
}
|
||||
|
||||
ferr, ok := err.(*ForwardingError)
|
||||
rtErr, ok := err.(ClearTextError)
|
||||
if !ok {
|
||||
t.Fatalf("expected a ForwardingError, instead got: %T %v",
|
||||
err, err)
|
||||
t.Fatalf("expected a ClearTextError, instead got: %T %v",
|
||||
rtErr, err)
|
||||
}
|
||||
|
||||
switch ferr.WireMessage().(type) {
|
||||
switch rtErr.WireMessage().(type) {
|
||||
case *lnwire.FailIncorrectDetails:
|
||||
default:
|
||||
t.Fatalf("expected incorrect_or_unknown_payment_details, "+
|
||||
@@ -1519,12 +1522,13 @@ func TestChannelLinkExpiryTooSoonMidNode(t *testing.T) {
|
||||
"time lock value")
|
||||
}
|
||||
|
||||
ferr, ok := err.(*ForwardingError)
|
||||
rtErr, ok := err.(ClearTextError)
|
||||
if !ok {
|
||||
t.Fatalf("expected a ForwardingError, instead got: %T: %v", err, err)
|
||||
t.Fatalf("expected a ClearTextError, instead got: %T: %v",
|
||||
rtErr, err)
|
||||
}
|
||||
|
||||
switch ferr.WireMessage().(type) {
|
||||
switch rtErr.WireMessage().(type) {
|
||||
case *lnwire.FailExpiryTooSoon:
|
||||
default:
|
||||
t.Fatalf("incorrect error, expected final time lock too "+
|
||||
@@ -5632,11 +5636,11 @@ func TestChannelLinkCanceledInvoice(t *testing.T) {
|
||||
|
||||
// Because the invoice is canceled, we expect an unknown payment hash
|
||||
// result.
|
||||
fErr, ok := err.(*ForwardingError)
|
||||
rtErr, ok := err.(ClearTextError)
|
||||
if !ok {
|
||||
t.Fatalf("expected ForwardingError, but got %v", err)
|
||||
t.Fatalf("expected ClearTextError, but got %v", err)
|
||||
}
|
||||
_, ok = fErr.WireMessage().(*lnwire.FailIncorrectDetails)
|
||||
_, ok = rtErr.WireMessage().(*lnwire.FailIncorrectDetails)
|
||||
if !ok {
|
||||
t.Fatalf("expected unknown payment hash, but got %v", err)
|
||||
}
|
||||
@@ -6213,16 +6217,16 @@ func TestChannelLinkReceiveEmptySig(t *testing.T) {
|
||||
aliceLink.Stop()
|
||||
}
|
||||
|
||||
// assertFailureCode asserts that an error is of type ForwardingError and that
|
||||
// assertFailureCode asserts that an error is of type ClearTextError and that
|
||||
// the failure code is as expected.
|
||||
func assertFailureCode(t *testing.T, err error, code lnwire.FailCode) {
|
||||
fErr, ok := err.(*ForwardingError)
|
||||
rtErr, ok := err.(ClearTextError)
|
||||
if !ok {
|
||||
t.Fatalf("expected ForwardingError but got %T", err)
|
||||
t.Fatalf("expected ClearTextError but got %T", err)
|
||||
}
|
||||
|
||||
if fErr.WireMessage().Code() != code {
|
||||
if rtErr.WireMessage().Code() != code {
|
||||
t.Fatalf("expected %v but got %v",
|
||||
code, fErr.WireMessage().Code())
|
||||
code, rtErr.WireMessage().Code())
|
||||
}
|
||||
}
|
||||
@@ -2178,11 +2178,11 @@ func TestUpdateFailMalformedHTLCErrorConversion(t *testing.T) {
|
||||
t.Fatalf("unable to send payment: %v", err)
|
||||
}
|
||||
|
||||
fwdingErr := err.(*ForwardingError)
|
||||
failureMsg := fwdingErr.WireMessage()
|
||||
routingErr := err.(ClearTextError)
|
||||
failureMsg := routingErr.WireMessage()
|
||||
if _, ok := failureMsg.(*lnwire.FailInvalidOnionKey); !ok {
|
||||
t.Fatalf("expected onion failure instead got: %v",
|
||||
fwdingErr.WireMessage())
|
||||
routingErr.WireMessage())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2441,14 +2441,18 @@ func TestInvalidFailure(t *testing.T) {
|
||||
|
||||
select {
|
||||
case result := <-resultChan:
|
||||
fErr, ok := result.Error.(*ForwardingError)
|
||||
rtErr, ok := result.Error.(ClearTextError)
|
||||
if !ok {
|
||||
t.Fatal("expected ForwardingError")
|
||||
t.Fatal("expected ClearTextError")
|
||||
}
|
||||
if fErr.FailureSourceIdx != 2 {
|
||||
source, ok := rtErr.(*ForwardingError)
|
||||
if !ok {
|
||||
t.Fatalf("expected forwarding error, got: %T", rtErr)
|
||||
}
|
||||
if source.FailureSourceIdx != 2 {
|
||||
t.Fatal("unexpected error source index")
|
||||
}
|
||||
if fErr.WireMessage() != nil {
|
||||
if rtErr.WireMessage() != nil {
|
||||
t.Fatal("expected empty failure message")
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user