From 7141bdac48f36710d283a0737d7f0d39cf2e8208 Mon Sep 17 00:00:00 2001 From: Jake Sylvestre Date: Sun, 6 Dec 2020 14:42:09 -0500 Subject: [PATCH] add unknown message test case --- peer/peer_test.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/peer/peer_test.go b/peer/peer_test.go index 6cc3113d1e..18a79bec7c 100644 --- a/peer/peer_test.go +++ b/peer/peer_test.go @@ -20,6 +20,33 @@ import ( "github.com/btcsuite/go-socks/socks" ) +// this allows us to test an unknown message +type UnknownMessage struct {} + +// BtcDecode decodes r using the bitcoin protocol encoding into the receiver. +// This is part of the Message interface implementation. +func (msg *UnknownMessage) BtcDecode(r io.Reader, pver uint32, enc wire.MessageEncoding) error { + return nil +} + +// BtcEncode encodes the receiver to w using the bitcoin protocol encoding. +// This is part of the Message interface implementation. +func (msg *UnknownMessage) BtcEncode(w io.Writer, pver uint32, enc wire.MessageEncoding) error { + return nil +} + +// Command returns the protocol command string for the message. This is part +// of the Message interface implementation. +func (msg *UnknownMessage) Command() string { + return "not handled" // must be less than 13 characters +} + +// MaxPayloadLength returns the maximum length the payload can be for the +// receiver. This is part of the Message interface implementation. +func (msg *UnknownMessage) MaxPayloadLength(pver uint32) uint32 { + return 0 +} + // conn mocks a network connection by implementing the net.Conn interface. It // is used to test peer connection without actually opening a network // connection. @@ -481,6 +508,11 @@ func TestPeerListeners(t *testing.T) { } } + outPeer.QueueMessage(&UnknownMessage{}, nil) + if !outPeer.Connected(){ + t.Errorf("outpeer disconnected on an unknown message") + } + tests := []struct { listener string msg wire.Message