From 1de08c478051506121a95f114cab811a8fdeece3 Mon Sep 17 00:00:00 2001 From: Joost Jager Date: Sat, 10 Aug 2019 12:46:36 +0200 Subject: [PATCH] lnwire/test: fix TestFailIncorrectDetailsOptionalAmount This test relied on specific internals of the failure encode function. Changes to failure message pointer receiver everywhere subtly broke this test. --- lnwire/onion_error_test.go | 36 +++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/lnwire/onion_error_test.go b/lnwire/onion_error_test.go index 21fe3fcd4..a29d3ee24 100644 --- a/lnwire/onion_error_test.go +++ b/lnwire/onion_error_test.go @@ -4,6 +4,7 @@ import ( "bufio" "bytes" "encoding/binary" + "io" "reflect" "testing" @@ -174,10 +175,7 @@ func TestWriteOnionErrorChanUpdate(t *testing.T) { func TestFailIncorrectDetailsOptionalAmount(t *testing.T) { t.Parallel() - // Creation an error that is a non-pointer will allow us to skip the - // type assertion for the Serializable interface. As a result, the - // amount body won't be written. - onionError := &FailIncorrectDetails{} + onionError := &mockFailIncorrectDetailsNoAmt{} var b bytes.Buffer if err := EncodeFailure(&b, onionError, 0); err != nil { @@ -189,8 +187,32 @@ func TestFailIncorrectDetailsOptionalAmount(t *testing.T) { t.Fatalf("unable to decode error: %v", err) } - if !reflect.DeepEqual(onionError, onionError2) { - t.Fatalf("expected %v, got %v", spew.Sdump(onionError), - spew.Sdump(onionError2)) + invalidDetailsErr, ok := onionError2.(*FailIncorrectDetails) + if !ok { + t.Fatalf("expected FailIncorrectDetails, but got %T", + onionError2) + } + + if invalidDetailsErr.amount != 0 { + t.Fatalf("expected amount to be zero") } } + +type mockFailIncorrectDetailsNoAmt struct { +} + +func (f *mockFailIncorrectDetailsNoAmt) Code() FailCode { + return CodeIncorrectOrUnknownPaymentDetails +} + +func (f *mockFailIncorrectDetailsNoAmt) Error() string { + return "" +} + +func (f *mockFailIncorrectDetailsNoAmt) Decode(r io.Reader, pver uint32) error { + return nil +} + +func (f *mockFailIncorrectDetailsNoAmt) Encode(w io.Writer, pver uint32) error { + return nil +}