mirror of
https://github.com/btcsuite/btcd.git
synced 2026-08-13 12:32:51 +02:00
wire: test v2 message trailing payload rejection
This commit is contained in:
parent
03aeb81a6f
commit
42077fdb4a
1 changed files with 22 additions and 1 deletions
|
|
@ -347,7 +347,6 @@ func TestReadMessageWireErrors(t *testing.T) {
|
|||
ErrUnknownMessage,
|
||||
24,
|
||||
},
|
||||
|
||||
}
|
||||
|
||||
t.Logf("Running %d tests", len(tests))
|
||||
|
|
@ -428,6 +427,28 @@ func TestReadMessageTrailingBytes(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
// TestReadV2MessageTrailingBytes verifies that a v2 message with unconsumed
|
||||
// trailing bytes after BtcDecode is rejected with a MessageError.
|
||||
func TestReadV2MessageTrailingBytes(t *testing.T) {
|
||||
payload := []byte{
|
||||
v2Messages[CmdInv],
|
||||
0x00, // zero inventory vectors
|
||||
0xaa, // trailing data not consumed by MsgInv.BtcDecode
|
||||
}
|
||||
|
||||
_, _, err := ReadV2MessageN(
|
||||
payload, ProtocolVersion, BaseEncoding,
|
||||
)
|
||||
if err == nil {
|
||||
t.Fatal("expected error for v2 message with trailing bytes")
|
||||
}
|
||||
|
||||
var msgErr *MessageError
|
||||
if !errors.As(err, &msgErr) {
|
||||
t.Fatalf("expected MessageError, got: %T (%v)", err, err)
|
||||
}
|
||||
}
|
||||
|
||||
// TestWriteMessageWireErrors performs negative tests against wire encoding from
|
||||
// concrete messages to confirm error paths work correctly.
|
||||
func TestWriteMessageWireErrors(t *testing.T) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue