htlcswitch: update tests to expect new ForwardingError type

This commit is contained in:
Olaoluwa Osuntokun 2017-10-10 19:37:28 -07:00
parent 12ae63101d
commit 93c008bb46
No known key found for this signature in database
GPG Key ID: 964EA263DD637C21

@ -397,7 +397,12 @@ func TestExitNodeTimelockPayloadMismatch(t *testing.T) {
t.Fatalf("payment should have failed but didn't") t.Fatalf("payment should have failed but didn't")
} }
switch err.(type) { ferr, ok := err.(*ForwardingError)
if !ok {
t.Fatalf("expected a ForwardingError, instead got: %T", err)
}
switch ferr.FailureMessage.(type) {
case *lnwire.FailFinalIncorrectCltvExpiry: case *lnwire.FailFinalIncorrectCltvExpiry:
default: default:
t.Fatalf("incorrect error, expected incorrect cltv expiry, "+ t.Fatalf("incorrect error, expected incorrect cltv expiry, "+
@ -481,7 +486,12 @@ func TestLinkForwardTimelockPolicyMismatch(t *testing.T) {
t.Fatalf("payment should have failed but didn't") t.Fatalf("payment should have failed but didn't")
} }
switch err.(type) { ferr, ok := err.(*ForwardingError)
if !ok {
t.Fatalf("expected a ForwardingError, instead got: %T", err)
}
switch ferr.FailureMessage.(type) {
case *lnwire.FailIncorrectCltvExpiry: case *lnwire.FailIncorrectCltvExpiry:
default: default:
t.Fatalf("incorrect error, expected incorrect cltv expiry, "+ t.Fatalf("incorrect error, expected incorrect cltv expiry, "+
@ -527,8 +537,12 @@ func TestLinkForwardFeePolicyMismatch(t *testing.T) {
t.Fatalf("payment should have failed but didn't") t.Fatalf("payment should have failed but didn't")
} }
switch err.(type) { ferr, ok := err.(*ForwardingError)
// TODO(roasbeef): assert get proper fee back if !ok {
t.Fatalf("expected a ForwardingError, instead got: %T", err)
}
switch ferr.FailureMessage.(type) {
case *lnwire.FailFeeInsufficient: case *lnwire.FailFeeInsufficient:
default: default:
t.Fatalf("incorrect error, expected fee insufficient, "+ t.Fatalf("incorrect error, expected fee insufficient, "+
@ -574,7 +588,12 @@ func TestLinkForwardMinHTLCPolicyMismatch(t *testing.T) {
t.Fatalf("payment should have failed but didn't") t.Fatalf("payment should have failed but didn't")
} }
switch err.(type) { ferr, ok := err.(*ForwardingError)
if !ok {
t.Fatalf("expected a ForwardingError, instead got: %T", err)
}
switch ferr.FailureMessage.(type) {
case *lnwire.FailAmountBelowMinimum: case *lnwire.FailAmountBelowMinimum:
default: default:
t.Fatalf("incorrect error, expected amount below minimum, "+ t.Fatalf("incorrect error, expected amount below minimum, "+
@ -896,7 +915,7 @@ func TestChannelLinkMultiHopDecodeError(t *testing.T) {
// Replace decode function with another which throws an error. // Replace decode function with another which throws an error.
n.carolChannelLink.cfg.DecodeOnionObfuscator = func( n.carolChannelLink.cfg.DecodeOnionObfuscator = func(
r io.Reader) (Obfuscator, lnwire.FailCode) { r io.Reader) (ErrorEncrypter, lnwire.FailCode) {
return nil, lnwire.CodeInvalidOnionVersion return nil, lnwire.CodeInvalidOnionVersion
} }
@ -914,7 +933,13 @@ func TestChannelLinkMultiHopDecodeError(t *testing.T) {
if err == nil { if err == nil {
t.Fatal("error haven't been received") t.Fatal("error haven't been received")
} }
switch err.(type) {
ferr, ok := err.(*ForwardingError)
if !ok {
t.Fatalf("expected a ForwardingError, instead got: %T", err)
}
switch ferr.FailureMessage.(type) {
case *lnwire.FailInvalidOnionVersion: case *lnwire.FailInvalidOnionVersion:
default: default:
t.Fatalf("wrong error have been received: %v", err) t.Fatalf("wrong error have been received: %v", err)
@ -987,7 +1012,12 @@ func TestChannelLinkExpiryTooSoonExitNode(t *testing.T) {
"time lock value") "time lock value")
} }
switch err.(type) { ferr, ok := err.(*ForwardingError)
if !ok {
t.Fatalf("expected a ForwardingError, instead got: %T", err)
}
switch ferr.FailureMessage.(type) {
case *lnwire.FailFinalIncorrectCltvExpiry: case *lnwire.FailFinalIncorrectCltvExpiry:
default: default:
t.Fatalf("incorrect error, expected final time lock too "+ t.Fatalf("incorrect error, expected final time lock too "+
@ -1033,7 +1063,12 @@ func TestChannelLinkExpiryTooSoonMidNode(t *testing.T) {
"time lock value") "time lock value")
} }
switch err.(type) { ferr, ok := err.(*ForwardingError)
if !ok {
t.Fatalf("expected a ForwardingError, instead got: %T", err)
}
switch ferr.FailureMessage.(type) {
case *lnwire.FailExpiryTooSoon: case *lnwire.FailExpiryTooSoon:
default: default:
t.Fatalf("incorrect error, expected final time lock too "+ t.Fatalf("incorrect error, expected final time lock too "+
@ -1203,7 +1238,7 @@ func newSingleLinkTestHarness(chanAmt btcutil.Amount) (ChannelLink, func(), erro
Peer: &alicePeer, Peer: &alicePeer,
Switch: nil, Switch: nil,
DecodeHopIterator: decoder.DecodeHopIterator, DecodeHopIterator: decoder.DecodeHopIterator,
DecodeOnionObfuscator: func(io.Reader) (Obfuscator, lnwire.FailCode) { DecodeOnionObfuscator: func(io.Reader) (ErrorEncrypter, lnwire.FailCode) {
return obfuscator, lnwire.CodeNone return obfuscator, lnwire.CodeNone
}, },
GetLastChannelUpdate: mockGetChanUpdateMessage, GetLastChannelUpdate: mockGetChanUpdateMessage,