lnwire: use require package for onion failure fuzz tests

This commit is contained in:
Matt Morehouse committed 2023-10-27 14:52:00 -05:00
1 parent a7ee45bea0
commit ed1b54ac3a
1 file changed
+26 -26
+26 -26
View File
@@ -675,19 +675,18 @@ func onionFailureHarnessCustom(t *testing.T, data []byte, code FailCode,
// decoding the message does not mutate it. // decoding the message does not mutate it.
var b bytes.Buffer var b bytes.Buffer
if err := EncodeFailureMessage(&b, msg, 0); err != nil { err = EncodeFailureMessage(&b, msg, 0)
t.Fatalf("failed to encode failure message: %v", err) require.NoError(t, err, "failed to encode failure message")
}
newMsg, err := DecodeFailureMessage(&b, 0) newMsg, err := DecodeFailureMessage(&b, 0)
if err != nil { require.NoError(t, err, "failed to decode serialized failure message")
t.Fatalf("failed to decode serialized failure message: %v", err)
}
if !eq(msg, newMsg) { require.True(
t.Fatalf("original message and deserialized message are not "+ t, eq(msg, newMsg),
"equal: %v != %v", msg, newMsg) "original message and deserialized message are not equal: "+
} "%v != %v",
msg, newMsg,
)
// Now verify that encoding/decoding full packets works as expected. // Now verify that encoding/decoding full packets works as expected.
@@ -713,19 +712,20 @@ func onionFailureHarnessCustom(t *testing.T, data []byte, code FailCode,
// We should use FailureMessageLength sized packets plus 2 bytes to // We should use FailureMessageLength sized packets plus 2 bytes to
// encode the message length and 2 bytes to encode the padding length, // encode the message length and 2 bytes to encode the padding length,
// as recommended by the spec. // as recommended by the spec.
if pktBuf.Len() != FailureMessageLength+4 { require.Equal(
t.Fatalf("wrong failure message length: %v", pktBuf.Len()) t, pktBuf.Len(), FailureMessageLength+4,
} "wrong failure message length",
)
pktMsg, err := DecodeFailure(&pktBuf, 0) pktMsg, err := DecodeFailure(&pktBuf, 0)
if err != nil { require.NoError(t, err, "failed to decode failure packet")
t.Fatalf("failed to decode failure packet: %v", err)
}
if !eq(msg, pktMsg) { require.True(
t.Fatalf("original message and decoded packet message are not "+ t, eq(msg, pktMsg),
"equal: %v != %v", msg, pktMsg) "original message and decoded packet message are not equal: "+
} "%v != %v",
msg, pktMsg,
)
} }
func onionFailureHarness(t *testing.T, data []byte, code FailCode) { func onionFailureHarness(t *testing.T, data []byte, code FailCode) {
@@ -740,14 +740,14 @@ func FuzzFailIncorrectDetails(f *testing.F) {
// slice, we need to use a custom equality function. // slice, we need to use a custom equality function.
eq := func(x, y any) bool { eq := func(x, y any) bool {
msg1, ok := x.(*FailIncorrectDetails) msg1, ok := x.(*FailIncorrectDetails)
if !ok { require.True(
t.Fatal("msg1 was not FailIncorrectDetails") t, ok, "msg1 was not FailIncorrectDetails",
} )
msg2, ok := y.(*FailIncorrectDetails) msg2, ok := y.(*FailIncorrectDetails)
if !ok { require.True(
t.Fatalf("msg2 was not FailIncorrectDetails") t, ok, "msg2 was not FailIncorrectDetails",
} )
return msg1.amount == msg2.amount && return msg1.amount == msg2.amount &&
msg1.height == msg2.height && msg1.height == msg2.height &&