2016-08-08 18:42:54 +02:00
|
|
|
// Copyright (c) 2013-2016 The btcsuite developers
|
2013-05-08 21:31:00 +02:00
|
|
|
// Use of this source code is governed by an ISC
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2016-08-08 18:42:54 +02:00
|
|
|
package wire
|
2013-05-08 21:31:00 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
2013-05-11 18:06:52 +02:00
|
|
|
"io"
|
2013-05-08 21:31:00 +02:00
|
|
|
"reflect"
|
|
|
|
"testing"
|
2014-07-03 02:43:33 +02:00
|
|
|
|
|
|
|
"github.com/davecgh/go-spew/spew"
|
2013-05-08 21:31:00 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
// TestGetBlocks tests the MsgGetBlocks API.
|
|
|
|
func TestGetBlocks(t *testing.T) {
|
2016-08-08 18:42:54 +02:00
|
|
|
pver := ProtocolVersion
|
2013-05-08 21:31:00 +02:00
|
|
|
|
|
|
|
// Block 99500 hash.
|
|
|
|
hashStr := "000000000002e7ad7b9eef9479e4aabc65cb831269cc20d2632c13684406dee0"
|
2016-08-08 18:42:54 +02:00
|
|
|
locatorHash, err := NewShaHashFromStr(hashStr)
|
2013-05-08 21:31:00 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("NewShaHashFromStr: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Block 100000 hash.
|
|
|
|
hashStr = "3ba27aa200b1cecaad478d2b00432346c3f1f3986da1afd33e506"
|
2016-08-08 18:42:54 +02:00
|
|
|
hashStop, err := NewShaHashFromStr(hashStr)
|
2013-05-08 21:31:00 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("NewShaHashFromStr: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ensure we get the same data back out.
|
2016-08-08 18:42:54 +02:00
|
|
|
msg := NewMsgGetBlocks(hashStop)
|
2013-05-08 21:31:00 +02:00
|
|
|
if !msg.HashStop.IsEqual(hashStop) {
|
|
|
|
t.Errorf("NewMsgGetBlocks: wrong stop hash - got %v, want %v",
|
|
|
|
msg.HashStop, hashStop)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ensure the command is expected value.
|
|
|
|
wantCmd := "getblocks"
|
|
|
|
if cmd := msg.Command(); cmd != wantCmd {
|
|
|
|
t.Errorf("NewMsgGetBlocks: wrong command - got %v want %v",
|
|
|
|
cmd, wantCmd)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ensure max payload is expected value for latest protocol version.
|
|
|
|
// Protocol version 4 bytes + num hashes (varInt) + max block locator
|
|
|
|
// hashes + hash stop.
|
|
|
|
wantPayload := uint32(16045)
|
|
|
|
maxPayload := msg.MaxPayloadLength(pver)
|
|
|
|
if maxPayload != wantPayload {
|
|
|
|
t.Errorf("MaxPayloadLength: wrong max payload length for "+
|
|
|
|
"protocol version %d - got %v, want %v", pver,
|
|
|
|
maxPayload, wantPayload)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ensure block locator hashes are added properly.
|
|
|
|
err = msg.AddBlockLocatorHash(locatorHash)
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("AddBlockLocatorHash: %v", err)
|
|
|
|
}
|
|
|
|
if msg.BlockLocatorHashes[0] != locatorHash {
|
|
|
|
t.Errorf("AddBlockLocatorHash: wrong block locator added - "+
|
|
|
|
"got %v, want %v",
|
|
|
|
spew.Sprint(msg.BlockLocatorHashes[0]),
|
|
|
|
spew.Sprint(locatorHash))
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ensure adding more than the max allowed block locator hashes per
|
|
|
|
// message returns an error.
|
2016-08-08 18:42:54 +02:00
|
|
|
for i := 0; i < MaxBlockLocatorsPerMsg; i++ {
|
2013-05-08 21:31:00 +02:00
|
|
|
err = msg.AddBlockLocatorHash(locatorHash)
|
|
|
|
}
|
|
|
|
if err == nil {
|
|
|
|
t.Errorf("AddBlockLocatorHash: expected error on too many " +
|
|
|
|
"block locator hashes not received")
|
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// TestGetBlocksWire tests the MsgGetBlocks wire encode and decode for various
|
|
|
|
// numbers of block locator hashes and protocol versions.
|
|
|
|
func TestGetBlocksWire(t *testing.T) {
|
|
|
|
// Set protocol inside getblocks message.
|
|
|
|
pver := uint32(60002)
|
|
|
|
|
|
|
|
// Block 99499 hash.
|
|
|
|
hashStr := "2710f40c87ec93d010a6fd95f42c59a2cbacc60b18cf6b7957535"
|
2016-08-08 18:42:54 +02:00
|
|
|
hashLocator, err := NewShaHashFromStr(hashStr)
|
2013-05-08 21:31:00 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("NewShaHashFromStr: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Block 99500 hash.
|
|
|
|
hashStr = "2e7ad7b9eef9479e4aabc65cb831269cc20d2632c13684406dee0"
|
2016-08-08 18:42:54 +02:00
|
|
|
hashLocator2, err := NewShaHashFromStr(hashStr)
|
2013-05-08 21:31:00 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("NewShaHashFromStr: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Block 100000 hash.
|
|
|
|
hashStr = "3ba27aa200b1cecaad478d2b00432346c3f1f3986da1afd33e506"
|
2016-08-08 18:42:54 +02:00
|
|
|
hashStop, err := NewShaHashFromStr(hashStr)
|
2013-05-08 21:31:00 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("NewShaHashFromStr: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// MsgGetBlocks message with no block locators or stop hash.
|
2016-08-08 18:42:54 +02:00
|
|
|
noLocators := NewMsgGetBlocks(&ShaHash{})
|
2013-05-10 07:36:49 +02:00
|
|
|
noLocators.ProtocolVersion = pver
|
|
|
|
noLocatorsEncoded := []byte{
|
2013-05-08 21:31:00 +02:00
|
|
|
0x62, 0xea, 0x00, 0x00, // Protocol version 60002
|
|
|
|
0x00, // Varint for number of block locator hashes
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Hash stop
|
|
|
|
}
|
|
|
|
|
|
|
|
// MsgGetBlocks message with multiple block locators and a stop hash.
|
2016-08-08 18:42:54 +02:00
|
|
|
multiLocators := NewMsgGetBlocks(hashStop)
|
2013-05-10 07:36:49 +02:00
|
|
|
multiLocators.AddBlockLocatorHash(hashLocator2)
|
|
|
|
multiLocators.AddBlockLocatorHash(hashLocator)
|
|
|
|
multiLocators.ProtocolVersion = pver
|
|
|
|
multiLocatorsEncoded := []byte{
|
2013-05-08 21:31:00 +02:00
|
|
|
0x62, 0xea, 0x00, 0x00, // Protocol version 60002
|
|
|
|
0x02, // Varint for number of block locator hashes
|
|
|
|
0xe0, 0xde, 0x06, 0x44, 0x68, 0x13, 0x2c, 0x63,
|
|
|
|
0xd2, 0x20, 0xcc, 0x69, 0x12, 0x83, 0xcb, 0x65,
|
|
|
|
0xbc, 0xaa, 0xe4, 0x79, 0x94, 0xef, 0x9e, 0x7b,
|
|
|
|
0xad, 0xe7, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, // Block 99500 hash
|
|
|
|
0x35, 0x75, 0x95, 0xb7, 0xf6, 0x8c, 0xb1, 0x60,
|
|
|
|
0xcc, 0xba, 0x2c, 0x9a, 0xc5, 0x42, 0x5f, 0xd9,
|
|
|
|
0x6f, 0x0a, 0x01, 0x3d, 0xc9, 0x7e, 0xc8, 0x40,
|
|
|
|
0x0f, 0x71, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, // Block 99499 hash
|
|
|
|
0x06, 0xe5, 0x33, 0xfd, 0x1a, 0xda, 0x86, 0x39,
|
|
|
|
0x1f, 0x3f, 0x6c, 0x34, 0x32, 0x04, 0xb0, 0xd2,
|
|
|
|
0x78, 0xd4, 0xaa, 0xec, 0x1c, 0x0b, 0x20, 0xaa,
|
|
|
|
0x27, 0xba, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, // Hash stop
|
|
|
|
}
|
|
|
|
|
|
|
|
tests := []struct {
|
2016-08-08 18:42:54 +02:00
|
|
|
in *MsgGetBlocks // Message to encode
|
|
|
|
out *MsgGetBlocks // Expected decoded message
|
|
|
|
buf []byte // Wire encoding
|
|
|
|
pver uint32 // Protocol version for wire encoding
|
2013-05-08 21:31:00 +02:00
|
|
|
}{
|
|
|
|
// Latest protocol version with no block locators.
|
|
|
|
{
|
2013-05-10 07:36:49 +02:00
|
|
|
noLocators,
|
|
|
|
noLocators,
|
|
|
|
noLocatorsEncoded,
|
2016-08-08 18:42:54 +02:00
|
|
|
ProtocolVersion,
|
2013-05-08 21:31:00 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
// Latest protocol version with multiple block locators.
|
|
|
|
{
|
2013-05-10 07:36:49 +02:00
|
|
|
multiLocators,
|
|
|
|
multiLocators,
|
|
|
|
multiLocatorsEncoded,
|
2016-08-08 18:42:54 +02:00
|
|
|
ProtocolVersion,
|
2013-05-08 21:31:00 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
// Protocol version BIP0035Version with no block locators.
|
|
|
|
{
|
2013-05-10 07:36:49 +02:00
|
|
|
noLocators,
|
|
|
|
noLocators,
|
|
|
|
noLocatorsEncoded,
|
2016-08-08 18:42:54 +02:00
|
|
|
BIP0035Version,
|
2013-05-08 21:31:00 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
// Protocol version BIP0035Version with multiple block locators.
|
|
|
|
{
|
2013-05-10 07:36:49 +02:00
|
|
|
multiLocators,
|
|
|
|
multiLocators,
|
|
|
|
multiLocatorsEncoded,
|
2016-08-08 18:42:54 +02:00
|
|
|
BIP0035Version,
|
2013-05-08 21:31:00 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
// Protocol version BIP0031Version with no block locators.
|
|
|
|
{
|
2013-05-10 07:36:49 +02:00
|
|
|
noLocators,
|
|
|
|
noLocators,
|
|
|
|
noLocatorsEncoded,
|
2016-08-08 18:42:54 +02:00
|
|
|
BIP0031Version,
|
2013-05-08 21:31:00 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
// Protocol version BIP0031Versionwith multiple block locators.
|
|
|
|
{
|
2013-05-10 07:36:49 +02:00
|
|
|
multiLocators,
|
|
|
|
multiLocators,
|
|
|
|
multiLocatorsEncoded,
|
2016-08-08 18:42:54 +02:00
|
|
|
BIP0031Version,
|
2013-05-08 21:31:00 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
// Protocol version NetAddressTimeVersion with no block locators.
|
|
|
|
{
|
2013-05-10 07:36:49 +02:00
|
|
|
noLocators,
|
|
|
|
noLocators,
|
|
|
|
noLocatorsEncoded,
|
2016-08-08 18:42:54 +02:00
|
|
|
NetAddressTimeVersion,
|
2013-05-08 21:31:00 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
// Protocol version NetAddressTimeVersion multiple block locators.
|
|
|
|
{
|
2013-05-10 07:36:49 +02:00
|
|
|
multiLocators,
|
|
|
|
multiLocators,
|
|
|
|
multiLocatorsEncoded,
|
2016-08-08 18:42:54 +02:00
|
|
|
NetAddressTimeVersion,
|
2013-05-08 21:31:00 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
// Protocol version MultipleAddressVersion with no block locators.
|
|
|
|
{
|
2013-05-10 07:36:49 +02:00
|
|
|
noLocators,
|
|
|
|
noLocators,
|
|
|
|
noLocatorsEncoded,
|
2016-08-08 18:42:54 +02:00
|
|
|
MultipleAddressVersion,
|
2013-05-08 21:31:00 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
// Protocol version MultipleAddressVersion multiple block locators.
|
|
|
|
{
|
2013-05-10 07:36:49 +02:00
|
|
|
multiLocators,
|
|
|
|
multiLocators,
|
|
|
|
multiLocatorsEncoded,
|
2016-08-08 18:42:54 +02:00
|
|
|
MultipleAddressVersion,
|
2013-05-08 21:31:00 +02:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Logf("Running %d tests", len(tests))
|
|
|
|
for i, test := range tests {
|
|
|
|
// Encode the message to wire format.
|
|
|
|
var buf bytes.Buffer
|
|
|
|
err := test.in.BtcEncode(&buf, test.pver)
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("BtcEncode #%d error %v", i, err)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if !bytes.Equal(buf.Bytes(), test.buf) {
|
|
|
|
t.Errorf("BtcEncode #%d\n got: %s want: %s", i,
|
|
|
|
spew.Sdump(buf.Bytes()), spew.Sdump(test.buf))
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
// Decode the message from wire format.
|
2016-08-08 18:42:54 +02:00
|
|
|
var msg MsgGetBlocks
|
2014-06-05 06:39:03 +02:00
|
|
|
rbuf := bytes.NewReader(test.buf)
|
2013-05-08 21:31:00 +02:00
|
|
|
err = msg.BtcDecode(rbuf, test.pver)
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("BtcDecode #%d error %v", i, err)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if !reflect.DeepEqual(&msg, test.out) {
|
|
|
|
t.Errorf("BtcDecode #%d\n got: %s want: %s", i,
|
|
|
|
spew.Sdump(&msg), spew.Sdump(test.out))
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-05-11 18:06:52 +02:00
|
|
|
|
|
|
|
// TestGetBlocksWireErrors performs negative tests against wire encode and
|
|
|
|
// decode of MsgGetBlocks to confirm error paths work correctly.
|
|
|
|
func TestGetBlocksWireErrors(t *testing.T) {
|
|
|
|
// Set protocol inside getheaders message. Use protocol version 60002
|
|
|
|
// specifically here instead of the latest because the test data is
|
|
|
|
// using bytes encoded with that protocol version.
|
|
|
|
pver := uint32(60002)
|
2016-08-08 18:42:54 +02:00
|
|
|
wireErr := &MessageError{}
|
2013-05-11 18:06:52 +02:00
|
|
|
|
|
|
|
// Block 99499 hash.
|
|
|
|
hashStr := "2710f40c87ec93d010a6fd95f42c59a2cbacc60b18cf6b7957535"
|
2016-08-08 18:42:54 +02:00
|
|
|
hashLocator, err := NewShaHashFromStr(hashStr)
|
2013-05-11 18:06:52 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("NewShaHashFromStr: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Block 99500 hash.
|
|
|
|
hashStr = "2e7ad7b9eef9479e4aabc65cb831269cc20d2632c13684406dee0"
|
2016-08-08 18:42:54 +02:00
|
|
|
hashLocator2, err := NewShaHashFromStr(hashStr)
|
2013-05-11 18:06:52 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("NewShaHashFromStr: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Block 100000 hash.
|
|
|
|
hashStr = "3ba27aa200b1cecaad478d2b00432346c3f1f3986da1afd33e506"
|
2016-08-08 18:42:54 +02:00
|
|
|
hashStop, err := NewShaHashFromStr(hashStr)
|
2013-05-11 18:06:52 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("NewShaHashFromStr: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// MsgGetBlocks message with multiple block locators and a stop hash.
|
2016-08-08 18:42:54 +02:00
|
|
|
baseGetBlocks := NewMsgGetBlocks(hashStop)
|
2013-05-11 18:06:52 +02:00
|
|
|
baseGetBlocks.ProtocolVersion = pver
|
|
|
|
baseGetBlocks.AddBlockLocatorHash(hashLocator2)
|
|
|
|
baseGetBlocks.AddBlockLocatorHash(hashLocator)
|
|
|
|
baseGetBlocksEncoded := []byte{
|
|
|
|
0x62, 0xea, 0x00, 0x00, // Protocol version 60002
|
|
|
|
0x02, // Varint for number of block locator hashes
|
|
|
|
0xe0, 0xde, 0x06, 0x44, 0x68, 0x13, 0x2c, 0x63,
|
|
|
|
0xd2, 0x20, 0xcc, 0x69, 0x12, 0x83, 0xcb, 0x65,
|
|
|
|
0xbc, 0xaa, 0xe4, 0x79, 0x94, 0xef, 0x9e, 0x7b,
|
|
|
|
0xad, 0xe7, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, // Block 99500 hash
|
|
|
|
0x35, 0x75, 0x95, 0xb7, 0xf6, 0x8c, 0xb1, 0x60,
|
|
|
|
0xcc, 0xba, 0x2c, 0x9a, 0xc5, 0x42, 0x5f, 0xd9,
|
|
|
|
0x6f, 0x0a, 0x01, 0x3d, 0xc9, 0x7e, 0xc8, 0x40,
|
|
|
|
0x0f, 0x71, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, // Block 99499 hash
|
|
|
|
0x06, 0xe5, 0x33, 0xfd, 0x1a, 0xda, 0x86, 0x39,
|
|
|
|
0x1f, 0x3f, 0x6c, 0x34, 0x32, 0x04, 0xb0, 0xd2,
|
|
|
|
0x78, 0xd4, 0xaa, 0xec, 0x1c, 0x0b, 0x20, 0xaa,
|
|
|
|
0x27, 0xba, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, // Hash stop
|
|
|
|
}
|
|
|
|
|
|
|
|
// Message that forces an error by having more than the max allowed
|
|
|
|
// block locator hashes.
|
2016-08-08 18:42:54 +02:00
|
|
|
maxGetBlocks := NewMsgGetBlocks(hashStop)
|
|
|
|
for i := 0; i < MaxBlockLocatorsPerMsg; i++ {
|
2014-05-28 07:26:47 +02:00
|
|
|
maxGetBlocks.AddBlockLocatorHash(&mainNetGenesisHash)
|
2013-05-11 18:06:52 +02:00
|
|
|
}
|
|
|
|
maxGetBlocks.BlockLocatorHashes = append(maxGetBlocks.BlockLocatorHashes,
|
2014-05-28 07:26:47 +02:00
|
|
|
&mainNetGenesisHash)
|
2013-05-11 18:06:52 +02:00
|
|
|
maxGetBlocksEncoded := []byte{
|
|
|
|
0x62, 0xea, 0x00, 0x00, // Protocol version 60002
|
|
|
|
0xfd, 0xf5, 0x01, // Varint for number of block loc hashes (501)
|
|
|
|
}
|
|
|
|
|
|
|
|
tests := []struct {
|
2016-08-08 18:42:54 +02:00
|
|
|
in *MsgGetBlocks // Value to encode
|
|
|
|
buf []byte // Wire encoding
|
|
|
|
pver uint32 // Protocol version for wire encoding
|
|
|
|
max int // Max size of fixed buffer to induce errors
|
|
|
|
writeErr error // Expected write error
|
|
|
|
readErr error // Expected read error
|
2013-05-11 18:06:52 +02:00
|
|
|
}{
|
|
|
|
// Force error in protocol version.
|
|
|
|
{baseGetBlocks, baseGetBlocksEncoded, pver, 0, io.ErrShortWrite, io.EOF},
|
|
|
|
// Force error in block locator hash count.
|
|
|
|
{baseGetBlocks, baseGetBlocksEncoded, pver, 4, io.ErrShortWrite, io.EOF},
|
|
|
|
// Force error in block locator hashes.
|
|
|
|
{baseGetBlocks, baseGetBlocksEncoded, pver, 5, io.ErrShortWrite, io.EOF},
|
|
|
|
// Force error in stop hash.
|
|
|
|
{baseGetBlocks, baseGetBlocksEncoded, pver, 69, io.ErrShortWrite, io.EOF},
|
|
|
|
// Force error with greater than max block locator hashes.
|
2015-01-31 19:32:55 +01:00
|
|
|
{maxGetBlocks, maxGetBlocksEncoded, pver, 7, wireErr, wireErr},
|
2013-05-11 18:06:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
t.Logf("Running %d tests", len(tests))
|
|
|
|
for i, test := range tests {
|
|
|
|
// Encode to wire format.
|
|
|
|
w := newFixedWriter(test.max)
|
|
|
|
err := test.in.BtcEncode(w, test.pver)
|
|
|
|
if reflect.TypeOf(err) != reflect.TypeOf(test.writeErr) {
|
|
|
|
t.Errorf("BtcEncode #%d wrong error got: %v, want: %v",
|
|
|
|
i, err, test.writeErr)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2016-08-08 18:42:54 +02:00
|
|
|
// For errors which are not of type MessageError, check them for
|
|
|
|
// equality.
|
|
|
|
if _, ok := err.(*MessageError); !ok {
|
2013-05-11 18:06:52 +02:00
|
|
|
if err != test.writeErr {
|
|
|
|
t.Errorf("BtcEncode #%d wrong error got: %v, "+
|
|
|
|
"want: %v", i, err, test.writeErr)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Decode from wire format.
|
2016-08-08 18:42:54 +02:00
|
|
|
var msg MsgGetBlocks
|
2013-05-11 18:06:52 +02:00
|
|
|
r := newFixedReader(test.max, test.buf)
|
|
|
|
err = msg.BtcDecode(r, test.pver)
|
|
|
|
if reflect.TypeOf(err) != reflect.TypeOf(test.readErr) {
|
|
|
|
t.Errorf("BtcDecode #%d wrong error got: %v, want: %v",
|
|
|
|
i, err, test.readErr)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2016-08-08 18:42:54 +02:00
|
|
|
// For errors which are not of type MessageError, check them for
|
|
|
|
// equality.
|
|
|
|
if _, ok := err.(*MessageError); !ok {
|
2013-05-11 18:06:52 +02:00
|
|
|
if err != test.readErr {
|
2013-05-11 19:55:50 +02:00
|
|
|
t.Errorf("BtcDecode #%d wrong error got: %v, "+
|
2013-05-11 18:06:52 +02:00
|
|
|
"want: %v", i, err, test.readErr)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|