1 // Copyright (c) 2013-2016 The btcsuite developers
2 // Use of this source code is governed by an ISC
3 // license that can be found in the LICENSE file.
12 "github.com/davecgh/go-spew/spew"
15 // TestVerAck tests the MsgVerAck API.
16 func TestVerAck(t *testing.T) {
17 pver := ProtocolVersion
19 // Ensure the command is expected value.
22 if cmd := msg.Command(); cmd != wantCmd {
23 t.Errorf("NewMsgVerAck: wrong command - got %v want %v",
27 // Ensure max payload is expected value.
28 wantPayload := uint32(0)
29 maxPayload := msg.MaxPayloadLength(pver)
30 if maxPayload != wantPayload {
31 t.Errorf("MaxPayloadLength: wrong max payload length for "+
32 "protocol version %d - got %v, want %v", pver,
33 maxPayload, wantPayload)
37 // TestVerAckWire tests the MsgVerAck wire encode and decode for various
39 func TestVerAckWire(t *testing.T) {
40 msgVerAck := NewMsgVerAck()
41 msgVerAckEncoded := []byte{}
44 in *MsgVerAck // Message to encode
45 out *MsgVerAck // Expected decoded message
46 buf []byte // Wire encoding
47 pver uint32 // Protocol version for wire encoding
48 enc MessageEncoding // Message encoding format
50 // Latest protocol version.
59 // Protocol version BIP0035Version.
68 // Protocol version BIP0031Version.
77 // Protocol version NetAddressTimeVersion.
82 NetAddressTimeVersion,
86 // Protocol version MultipleAddressVersion.
91 MultipleAddressVersion,
96 t.Logf("Running %d tests", len(tests))
97 for i, test := range tests {
98 // Encode the message to wire format.
100 err := test.in.BtcEncode(&buf, test.pver, test.enc)
102 t.Errorf("BtcEncode #%d error %v", i, err)
105 if !bytes.Equal(buf.Bytes(), test.buf) {
106 t.Errorf("BtcEncode #%d\n got: %s want: %s", i,
107 spew.Sdump(buf.Bytes()), spew.Sdump(test.buf))
111 // Decode the message from wire format.
113 rbuf := bytes.NewReader(test.buf)
114 err = msg.BtcDecode(rbuf, test.pver, test.enc)
116 t.Errorf("BtcDecode #%d error %v", i, err)
119 if !reflect.DeepEqual(&msg, test.out) {
120 t.Errorf("BtcDecode #%d\n got: %s want: %s", i,
121 spew.Sdump(msg), spew.Sdump(test.out))