github.com/dashpay/godash@v0.0.0-20160726055534-e038a21e0e3d/wire/msgversion_test.go (about)

     1  // Copyright (c) 2013-2015 The btcsuite developers
     2  // Copyright (c) 2016 The Dash developers
     3  // Use of this source code is governed by an ISC
     4  // license that can be found in the LICENSE file.
     5  
     6  package wire_test
     7  
     8  import (
     9  	"bytes"
    10  	"io"
    11  	"net"
    12  	"reflect"
    13  	"strings"
    14  	"testing"
    15  	"time"
    16  
    17  	"github.com/dashpay/godash/wire"
    18  	"github.com/davecgh/go-spew/spew"
    19  )
    20  
    21  // TestVersion tests the MsgVersion API.
    22  func TestVersion(t *testing.T) {
    23  	pver := wire.ProtocolVersion
    24  
    25  	// Create version message data.
    26  	lastBlock := int32(234234)
    27  	tcpAddrMe := &net.TCPAddr{IP: net.ParseIP("127.0.0.1"), Port: 8333}
    28  	me, err := wire.NewNetAddress(tcpAddrMe, wire.SFNodeNetwork)
    29  	if err != nil {
    30  		t.Errorf("NewNetAddress: %v", err)
    31  	}
    32  	tcpAddrYou := &net.TCPAddr{IP: net.ParseIP("192.168.0.1"), Port: 8333}
    33  	you, err := wire.NewNetAddress(tcpAddrYou, wire.SFNodeNetwork)
    34  	if err != nil {
    35  		t.Errorf("NewNetAddress: %v", err)
    36  	}
    37  	nonce, err := wire.RandomUint64()
    38  	if err != nil {
    39  		t.Errorf("RandomUint64: error generating nonce: %v", err)
    40  	}
    41  
    42  	// Ensure we get the correct data back out.
    43  	msg := wire.NewMsgVersion(me, you, nonce, lastBlock)
    44  	if msg.ProtocolVersion != int32(pver) {
    45  		t.Errorf("NewMsgVersion: wrong protocol version - got %v, want %v",
    46  			msg.ProtocolVersion, pver)
    47  	}
    48  	if !reflect.DeepEqual(&msg.AddrMe, me) {
    49  		t.Errorf("NewMsgVersion: wrong me address - got %v, want %v",
    50  			spew.Sdump(&msg.AddrMe), spew.Sdump(me))
    51  	}
    52  	if !reflect.DeepEqual(&msg.AddrYou, you) {
    53  		t.Errorf("NewMsgVersion: wrong you address - got %v, want %v",
    54  			spew.Sdump(&msg.AddrYou), spew.Sdump(you))
    55  	}
    56  	if msg.Nonce != nonce {
    57  		t.Errorf("NewMsgVersion: wrong nonce - got %v, want %v",
    58  			msg.Nonce, nonce)
    59  	}
    60  	if msg.UserAgent != wire.DefaultUserAgent {
    61  		t.Errorf("NewMsgVersion: wrong user agent - got %v, want %v",
    62  			msg.UserAgent, wire.DefaultUserAgent)
    63  	}
    64  	if msg.LastBlock != lastBlock {
    65  		t.Errorf("NewMsgVersion: wrong last block - got %v, want %v",
    66  			msg.LastBlock, lastBlock)
    67  	}
    68  	if msg.DisableRelayTx != false {
    69  		t.Errorf("NewMsgVersion: disable relay tx is not false by "+
    70  			"default - got %v, want %v", msg.DisableRelayTx, false)
    71  	}
    72  
    73  	msg.AddUserAgent("myclient", "1.2.3", "optional", "comments")
    74  	customUserAgent := wire.DefaultUserAgent + "myclient:1.2.3(optional; comments)/"
    75  	if msg.UserAgent != customUserAgent {
    76  		t.Errorf("AddUserAgent: wrong user agent - got %s, want %s",
    77  			msg.UserAgent, customUserAgent)
    78  	}
    79  
    80  	msg.AddUserAgent("mygui", "3.4.5")
    81  	customUserAgent += "mygui:3.4.5/"
    82  	if msg.UserAgent != customUserAgent {
    83  		t.Errorf("AddUserAgent: wrong user agent - got %s, want %s",
    84  			msg.UserAgent, customUserAgent)
    85  	}
    86  
    87  	// accounting for ":", "/"
    88  	err = msg.AddUserAgent(strings.Repeat("t",
    89  		wire.MaxUserAgentLen-len(customUserAgent)-2+1), "")
    90  	if _, ok := err.(*wire.MessageError); !ok {
    91  		t.Errorf("AddUserAgent: expected error not received "+
    92  			"- got %v, want %T", err, wire.MessageError{})
    93  
    94  	}
    95  
    96  	// Version message should not have any services set by default.
    97  	if msg.Services != 0 {
    98  		t.Errorf("NewMsgVersion: wrong default services - got %v, want %v",
    99  			msg.Services, 0)
   100  
   101  	}
   102  	if msg.HasService(wire.SFNodeNetwork) {
   103  		t.Errorf("HasService: SFNodeNetwork service is set")
   104  	}
   105  
   106  	// Ensure the command is expected value.
   107  	wantCmd := "version"
   108  	if cmd := msg.Command(); cmd != wantCmd {
   109  		t.Errorf("NewMsgVersion: wrong command - got %v want %v",
   110  			cmd, wantCmd)
   111  	}
   112  
   113  	// Ensure max payload is expected value.
   114  	// Protocol version 4 bytes + services 8 bytes + timestamp 8 bytes +
   115  	// remote and local net addresses + nonce 8 bytes + length of user agent
   116  	// (varInt) + max allowed user agent length + last block 4 bytes +
   117  	// relay transactions flag 1 byte.
   118  	wantPayload := uint32(2102)
   119  	maxPayload := msg.MaxPayloadLength(pver)
   120  	if maxPayload != wantPayload {
   121  		t.Errorf("MaxPayloadLength: wrong max payload length for "+
   122  			"protocol version %d - got %v, want %v", pver,
   123  			maxPayload, wantPayload)
   124  	}
   125  
   126  	// Ensure adding the full service node flag works.
   127  	msg.AddService(wire.SFNodeNetwork)
   128  	if msg.Services != wire.SFNodeNetwork {
   129  		t.Errorf("AddService: wrong services - got %v, want %v",
   130  			msg.Services, wire.SFNodeNetwork)
   131  	}
   132  	if !msg.HasService(wire.SFNodeNetwork) {
   133  		t.Errorf("HasService: SFNodeNetwork service not set")
   134  	}
   135  
   136  	// Use a fake connection.
   137  	conn := &fakeConn{localAddr: tcpAddrMe, remoteAddr: tcpAddrYou}
   138  	msg, err = wire.NewMsgVersionFromConn(conn, nonce, lastBlock)
   139  	if err != nil {
   140  		t.Errorf("NewMsgVersionFromConn: %v", err)
   141  	}
   142  
   143  	// Ensure we get the correct connection data back out.
   144  	if !msg.AddrMe.IP.Equal(tcpAddrMe.IP) {
   145  		t.Errorf("NewMsgVersionFromConn: wrong me ip - got %v, want %v",
   146  			msg.AddrMe.IP, tcpAddrMe.IP)
   147  	}
   148  	if !msg.AddrYou.IP.Equal(tcpAddrYou.IP) {
   149  		t.Errorf("NewMsgVersionFromConn: wrong you ip - got %v, want %v",
   150  			msg.AddrYou.IP, tcpAddrYou.IP)
   151  	}
   152  
   153  	// Use a fake connection with local UDP addresses to force a failure.
   154  	conn = &fakeConn{
   155  		localAddr:  &net.UDPAddr{IP: net.ParseIP("127.0.0.1"), Port: 8333},
   156  		remoteAddr: tcpAddrYou,
   157  	}
   158  	msg, err = wire.NewMsgVersionFromConn(conn, nonce, lastBlock)
   159  	if err != wire.ErrInvalidNetAddr {
   160  		t.Errorf("NewMsgVersionFromConn: expected error not received "+
   161  			"- got %v, want %v", err, wire.ErrInvalidNetAddr)
   162  	}
   163  
   164  	// Use a fake connection with remote UDP addresses to force a failure.
   165  	conn = &fakeConn{
   166  		localAddr:  tcpAddrMe,
   167  		remoteAddr: &net.UDPAddr{IP: net.ParseIP("192.168.0.1"), Port: 8333},
   168  	}
   169  	msg, err = wire.NewMsgVersionFromConn(conn, nonce, lastBlock)
   170  	if err != wire.ErrInvalidNetAddr {
   171  		t.Errorf("NewMsgVersionFromConn: expected error not received "+
   172  			"- got %v, want %v", err, wire.ErrInvalidNetAddr)
   173  	}
   174  
   175  	return
   176  }
   177  
   178  // TestVersionWire tests the MsgVersion wire encode and decode for various
   179  // protocol versions.
   180  func TestVersionWire(t *testing.T) {
   181  	// verRelayTxFalse and verRelayTxFalseEncoded is a version message as of
   182  	// BIP0037Version with the transaction relay disabled.
   183  	baseVersionBIP0037Copy := *baseVersionBIP0037
   184  	verRelayTxFalse := &baseVersionBIP0037Copy
   185  	verRelayTxFalse.DisableRelayTx = true
   186  	verRelayTxFalseEncoded := make([]byte, len(baseVersionBIP0037Encoded))
   187  	copy(verRelayTxFalseEncoded, baseVersionBIP0037Encoded)
   188  	verRelayTxFalseEncoded[len(verRelayTxFalseEncoded)-1] = 0
   189  
   190  	tests := []struct {
   191  		in   *wire.MsgVersion // Message to encode
   192  		out  *wire.MsgVersion // Expected decoded message
   193  		buf  []byte           // Wire encoding
   194  		pver uint32           // Protocol version for wire encoding
   195  	}{
   196  		// Latest protocol version.
   197  		{
   198  			baseVersionBIP0037,
   199  			baseVersionBIP0037,
   200  			baseVersionBIP0037Encoded,
   201  			wire.ProtocolVersion,
   202  		},
   203  
   204  		// Protocol version BIP0037Version with relay transactions field
   205  		// true.
   206  		{
   207  			baseVersionBIP0037,
   208  			baseVersionBIP0037,
   209  			baseVersionBIP0037Encoded,
   210  			wire.BIP0037Version,
   211  		},
   212  
   213  		// Protocol version BIP0037Version with relay transactions field
   214  		// false.
   215  		{
   216  			verRelayTxFalse,
   217  			verRelayTxFalse,
   218  			verRelayTxFalseEncoded,
   219  			wire.BIP0037Version,
   220  		},
   221  
   222  		// Protocol version BIP0035Version.
   223  		{
   224  			baseVersion,
   225  			baseVersion,
   226  			baseVersionEncoded,
   227  			wire.BIP0035Version,
   228  		},
   229  
   230  		// Protocol version BIP0031Version.
   231  		{
   232  			baseVersion,
   233  			baseVersion,
   234  			baseVersionEncoded,
   235  			wire.BIP0031Version,
   236  		},
   237  
   238  		// Protocol version NetAddressTimeVersion.
   239  		{
   240  			baseVersion,
   241  			baseVersion,
   242  			baseVersionEncoded,
   243  			wire.NetAddressTimeVersion,
   244  		},
   245  
   246  		// Protocol version MultipleAddressVersion.
   247  		{
   248  			baseVersion,
   249  			baseVersion,
   250  			baseVersionEncoded,
   251  			wire.MultipleAddressVersion,
   252  		},
   253  	}
   254  
   255  	t.Logf("Running %d tests", len(tests))
   256  	for i, test := range tests {
   257  		// Encode the message to wire format.
   258  		var buf bytes.Buffer
   259  		err := test.in.BtcEncode(&buf, test.pver)
   260  		if err != nil {
   261  			t.Errorf("BtcEncode #%d error %v", i, err)
   262  			continue
   263  		}
   264  		if !bytes.Equal(buf.Bytes(), test.buf) {
   265  			t.Errorf("BtcEncode #%d\n got: %s want: %s", i,
   266  				spew.Sdump(buf.Bytes()), spew.Sdump(test.buf))
   267  			continue
   268  		}
   269  
   270  		// Decode the message from wire format.
   271  		var msg wire.MsgVersion
   272  		rbuf := bytes.NewBuffer(test.buf)
   273  		err = msg.BtcDecode(rbuf, test.pver)
   274  		if err != nil {
   275  			t.Errorf("BtcDecode #%d error %v", i, err)
   276  			continue
   277  		}
   278  		if !reflect.DeepEqual(&msg, test.out) {
   279  			t.Errorf("BtcDecode #%d\n got: %s want: %s", i,
   280  				spew.Sdump(msg), spew.Sdump(test.out))
   281  			continue
   282  		}
   283  	}
   284  }
   285  
   286  // TestVersionWireErrors performs negative tests against wire encode and
   287  // decode of MsgGetHeaders to confirm error paths work correctly.
   288  func TestVersionWireErrors(t *testing.T) {
   289  	// Use protocol version 60002 specifically here instead of the latest
   290  	// because the test data is using bytes encoded with that protocol
   291  	// version.
   292  	pver := uint32(60002)
   293  	wireErr := &wire.MessageError{}
   294  
   295  	// Ensure calling MsgVersion.BtcDecode with a non *bytes.Buffer returns
   296  	// error.
   297  	fr := newFixedReader(0, []byte{})
   298  	if err := baseVersion.BtcDecode(fr, pver); err == nil {
   299  		t.Errorf("Did not received error when calling " +
   300  			"MsgVersion.BtcDecode with non *bytes.Buffer")
   301  	}
   302  
   303  	// Copy the base version and change the user agent to exceed max limits.
   304  	bvc := *baseVersion
   305  	exceedUAVer := &bvc
   306  	newUA := "/" + strings.Repeat("t", wire.MaxUserAgentLen-8+1) + ":0.0.1/"
   307  	exceedUAVer.UserAgent = newUA
   308  
   309  	// Encode the new UA length as a varint.
   310  	var newUAVarIntBuf bytes.Buffer
   311  	err := wire.TstWriteVarInt(&newUAVarIntBuf, pver, uint64(len(newUA)))
   312  	if err != nil {
   313  		t.Errorf("WriteVarInt: error %v", err)
   314  	}
   315  
   316  	// Make a new buffer big enough to hold the base version plus the new
   317  	// bytes for the bigger varint to hold the new size of the user agent
   318  	// and the new user agent string.  Then stich it all together.
   319  	newLen := len(baseVersionEncoded) - len(baseVersion.UserAgent)
   320  	newLen = newLen + len(newUAVarIntBuf.Bytes()) - 1 + len(newUA)
   321  	exceedUAVerEncoded := make([]byte, newLen)
   322  	copy(exceedUAVerEncoded, baseVersionEncoded[0:80])
   323  	copy(exceedUAVerEncoded[80:], newUAVarIntBuf.Bytes())
   324  	copy(exceedUAVerEncoded[83:], []byte(newUA))
   325  	copy(exceedUAVerEncoded[83+len(newUA):], baseVersionEncoded[97:100])
   326  
   327  	tests := []struct {
   328  		in       *wire.MsgVersion // Value to encode
   329  		buf      []byte           // Wire encoding
   330  		pver     uint32           // Protocol version for wire encoding
   331  		max      int              // Max size of fixed buffer to induce errors
   332  		writeErr error            // Expected write error
   333  		readErr  error            // Expected read error
   334  	}{
   335  		// Force error in protocol version.
   336  		{baseVersion, baseVersionEncoded, pver, 0, io.ErrShortWrite, io.EOF},
   337  		// Force error in services.
   338  		{baseVersion, baseVersionEncoded, pver, 4, io.ErrShortWrite, io.EOF},
   339  		// Force error in timestamp.
   340  		{baseVersion, baseVersionEncoded, pver, 12, io.ErrShortWrite, io.EOF},
   341  		// Force error in remote address.
   342  		{baseVersion, baseVersionEncoded, pver, 20, io.ErrShortWrite, io.EOF},
   343  		// Force error in local address.
   344  		{baseVersion, baseVersionEncoded, pver, 47, io.ErrShortWrite, io.ErrUnexpectedEOF},
   345  		// Force error in nonce.
   346  		{baseVersion, baseVersionEncoded, pver, 73, io.ErrShortWrite, io.ErrUnexpectedEOF},
   347  		// Force error in user agent length.
   348  		{baseVersion, baseVersionEncoded, pver, 81, io.ErrShortWrite, io.EOF},
   349  		// Force error in user agent.
   350  		{baseVersion, baseVersionEncoded, pver, 82, io.ErrShortWrite, io.ErrUnexpectedEOF},
   351  		// Force error in last block.
   352  		{baseVersion, baseVersionEncoded, pver, 98, io.ErrShortWrite, io.ErrUnexpectedEOF},
   353  		// Force error in relay tx - no read error should happen since
   354  		// it's optional.
   355  		{
   356  			baseVersionBIP0037, baseVersionBIP0037Encoded,
   357  			wire.BIP0037Version, 101, io.ErrShortWrite, nil,
   358  		},
   359  		// Force error due to user agent too big
   360  		{exceedUAVer, exceedUAVerEncoded, pver, newLen, wireErr, wireErr},
   361  	}
   362  
   363  	t.Logf("Running %d tests", len(tests))
   364  	for i, test := range tests {
   365  		// Encode to wire format.
   366  		w := newFixedWriter(test.max)
   367  		err := test.in.BtcEncode(w, test.pver)
   368  		if reflect.TypeOf(err) != reflect.TypeOf(test.writeErr) {
   369  			t.Errorf("BtcEncode #%d wrong error got: %v, want: %v",
   370  				i, err, test.writeErr)
   371  			continue
   372  		}
   373  
   374  		// For errors which are not of type wire.MessageError, check
   375  		// them for equality.
   376  		if _, ok := err.(*wire.MessageError); !ok {
   377  			if err != test.writeErr {
   378  				t.Errorf("BtcEncode #%d wrong error got: %v, "+
   379  					"want: %v", i, err, test.writeErr)
   380  				continue
   381  			}
   382  		}
   383  
   384  		// Decode from wire format.
   385  		var msg wire.MsgVersion
   386  		buf := bytes.NewBuffer(test.buf[0:test.max])
   387  		err = msg.BtcDecode(buf, test.pver)
   388  		if reflect.TypeOf(err) != reflect.TypeOf(test.readErr) {
   389  			t.Errorf("BtcDecode #%d wrong error got: %v, want: %v",
   390  				i, err, test.readErr)
   391  			continue
   392  		}
   393  
   394  		// For errors which are not of type wire.MessageError, check
   395  		// them for equality.
   396  		if _, ok := err.(*wire.MessageError); !ok {
   397  			if err != test.readErr {
   398  				t.Errorf("BtcDecode #%d wrong error got: %v, "+
   399  					"want: %v", i, err, test.readErr)
   400  				continue
   401  			}
   402  		}
   403  	}
   404  }
   405  
   406  // TestVersionOptionalFields performs tests to ensure that an encoded version
   407  // messages that omit optional fields are handled correctly.
   408  func TestVersionOptionalFields(t *testing.T) {
   409  	// onlyRequiredVersion is a version message that only contains the
   410  	// required versions and all other values set to their default values.
   411  	onlyRequiredVersion := wire.MsgVersion{
   412  		ProtocolVersion: 60002,
   413  		Services:        wire.SFNodeNetwork,
   414  		Timestamp:       time.Unix(0x495fab29, 0), // 2009-01-03 12:15:05 -0600 CST)
   415  		AddrYou: wire.NetAddress{
   416  			Timestamp: time.Time{}, // Zero value -- no timestamp in version
   417  			Services:  wire.SFNodeNetwork,
   418  			IP:        net.ParseIP("192.168.0.1"),
   419  			Port:      8333,
   420  		},
   421  	}
   422  	onlyRequiredVersionEncoded := make([]byte, len(baseVersionEncoded)-55)
   423  	copy(onlyRequiredVersionEncoded, baseVersionEncoded)
   424  
   425  	// addrMeVersion is a version message that contains all fields through
   426  	// the AddrMe field.
   427  	addrMeVersion := onlyRequiredVersion
   428  	addrMeVersion.AddrMe = wire.NetAddress{
   429  		Timestamp: time.Time{}, // Zero value -- no timestamp in version
   430  		Services:  wire.SFNodeNetwork,
   431  		IP:        net.ParseIP("127.0.0.1"),
   432  		Port:      8333,
   433  	}
   434  	addrMeVersionEncoded := make([]byte, len(baseVersionEncoded)-29)
   435  	copy(addrMeVersionEncoded, baseVersionEncoded)
   436  
   437  	// nonceVersion is a version message that contains all fields through
   438  	// the Nonce field.
   439  	nonceVersion := addrMeVersion
   440  	nonceVersion.Nonce = 123123 // 0x1e0f3
   441  	nonceVersionEncoded := make([]byte, len(baseVersionEncoded)-21)
   442  	copy(nonceVersionEncoded, baseVersionEncoded)
   443  
   444  	// uaVersion is a version message that contains all fields through
   445  	// the UserAgent field.
   446  	uaVersion := nonceVersion
   447  	uaVersion.UserAgent = "/btcdtest:0.0.1/"
   448  	uaVersionEncoded := make([]byte, len(baseVersionEncoded)-4)
   449  	copy(uaVersionEncoded, baseVersionEncoded)
   450  
   451  	// lastBlockVersion is a version message that contains all fields
   452  	// through the LastBlock field.
   453  	lastBlockVersion := uaVersion
   454  	lastBlockVersion.LastBlock = 234234 // 0x392fa
   455  	lastBlockVersionEncoded := make([]byte, len(baseVersionEncoded))
   456  	copy(lastBlockVersionEncoded, baseVersionEncoded)
   457  
   458  	tests := []struct {
   459  		msg  *wire.MsgVersion // Expected message
   460  		buf  []byte           // Wire encoding
   461  		pver uint32           // Protocol version for wire encoding
   462  	}{
   463  		{
   464  			&onlyRequiredVersion,
   465  			onlyRequiredVersionEncoded,
   466  			wire.ProtocolVersion,
   467  		},
   468  		{
   469  			&addrMeVersion,
   470  			addrMeVersionEncoded,
   471  			wire.ProtocolVersion,
   472  		},
   473  		{
   474  			&nonceVersion,
   475  			nonceVersionEncoded,
   476  			wire.ProtocolVersion,
   477  		},
   478  		{
   479  			&uaVersion,
   480  			uaVersionEncoded,
   481  			wire.ProtocolVersion,
   482  		},
   483  		{
   484  			&lastBlockVersion,
   485  			lastBlockVersionEncoded,
   486  			wire.ProtocolVersion,
   487  		},
   488  	}
   489  
   490  	for i, test := range tests {
   491  		// Decode the message from wire format.
   492  		var msg wire.MsgVersion
   493  		rbuf := bytes.NewBuffer(test.buf)
   494  		err := msg.BtcDecode(rbuf, test.pver)
   495  		if err != nil {
   496  			t.Errorf("BtcDecode #%d error %v", i, err)
   497  			continue
   498  		}
   499  		if !reflect.DeepEqual(&msg, test.msg) {
   500  			t.Errorf("BtcDecode #%d\n got: %s want: %s", i,
   501  				spew.Sdump(msg), spew.Sdump(test.msg))
   502  			continue
   503  		}
   504  	}
   505  }
   506  
   507  // baseVersion is used in the various tests as a baseline MsgVersion.
   508  var baseVersion = &wire.MsgVersion{
   509  	ProtocolVersion: 60002,
   510  	Services:        wire.SFNodeNetwork,
   511  	Timestamp:       time.Unix(0x495fab29, 0), // 2009-01-03 12:15:05 -0600 CST)
   512  	AddrYou: wire.NetAddress{
   513  		Timestamp: time.Time{}, // Zero value -- no timestamp in version
   514  		Services:  wire.SFNodeNetwork,
   515  		IP:        net.ParseIP("192.168.0.1"),
   516  		Port:      8333,
   517  	},
   518  	AddrMe: wire.NetAddress{
   519  		Timestamp: time.Time{}, // Zero value -- no timestamp in version
   520  		Services:  wire.SFNodeNetwork,
   521  		IP:        net.ParseIP("127.0.0.1"),
   522  		Port:      8333,
   523  	},
   524  	Nonce:     123123, // 0x1e0f3
   525  	UserAgent: "/btcdtest:0.0.1/",
   526  	LastBlock: 234234, // 0x392fa
   527  }
   528  
   529  // baseVersionEncoded is the wire encoded bytes for baseVersion using protocol
   530  // version 60002 and is used in the various tests.
   531  var baseVersionEncoded = []byte{
   532  	0x62, 0xea, 0x00, 0x00, // Protocol version 60002
   533  	0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // SFNodeNetwork
   534  	0x29, 0xab, 0x5f, 0x49, 0x00, 0x00, 0x00, 0x00, // 64-bit Timestamp
   535  	// AddrYou -- No timestamp for NetAddress in version message
   536  	0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // SFNodeNetwork
   537  	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   538  	0x00, 0x00, 0xff, 0xff, 0xc0, 0xa8, 0x00, 0x01, // IP 192.168.0.1
   539  	0x20, 0x8d, // Port 8333 in big-endian
   540  	// AddrMe -- No timestamp for NetAddress in version message
   541  	0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // SFNodeNetwork
   542  	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   543  	0x00, 0x00, 0xff, 0xff, 0x7f, 0x00, 0x00, 0x01, // IP 127.0.0.1
   544  	0x20, 0x8d, // Port 8333 in big-endian
   545  	0xf3, 0xe0, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, // Nonce
   546  	0x10, // Varint for user agent length
   547  	0x2f, 0x62, 0x74, 0x63, 0x64, 0x74, 0x65, 0x73,
   548  	0x74, 0x3a, 0x30, 0x2e, 0x30, 0x2e, 0x31, 0x2f, // User agent
   549  	0xfa, 0x92, 0x03, 0x00, // Last block
   550  }
   551  
   552  // baseVersionBIP0037 is used in the various tests as a baseline MsgVersion for
   553  // BIP0037.
   554  var baseVersionBIP0037 = &wire.MsgVersion{
   555  	ProtocolVersion: 70001,
   556  	Services:        wire.SFNodeNetwork,
   557  	Timestamp:       time.Unix(0x495fab29, 0), // 2009-01-03 12:15:05 -0600 CST)
   558  	AddrYou: wire.NetAddress{
   559  		Timestamp: time.Time{}, // Zero value -- no timestamp in version
   560  		Services:  wire.SFNodeNetwork,
   561  		IP:        net.ParseIP("192.168.0.1"),
   562  		Port:      8333,
   563  	},
   564  	AddrMe: wire.NetAddress{
   565  		Timestamp: time.Time{}, // Zero value -- no timestamp in version
   566  		Services:  wire.SFNodeNetwork,
   567  		IP:        net.ParseIP("127.0.0.1"),
   568  		Port:      8333,
   569  	},
   570  	Nonce:     123123, // 0x1e0f3
   571  	UserAgent: "/btcdtest:0.0.1/",
   572  	LastBlock: 234234, // 0x392fa
   573  }
   574  
   575  // baseVersionBIP0037Encoded is the wire encoded bytes for baseVersionBIP0037
   576  // using protocol version BIP0037Version and is used in the various tests.
   577  var baseVersionBIP0037Encoded = []byte{
   578  	0x71, 0x11, 0x01, 0x00, // Protocol version 70001
   579  	0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // SFNodeNetwork
   580  	0x29, 0xab, 0x5f, 0x49, 0x00, 0x00, 0x00, 0x00, // 64-bit Timestamp
   581  	// AddrYou -- No timestamp for NetAddress in version message
   582  	0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // SFNodeNetwork
   583  	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   584  	0x00, 0x00, 0xff, 0xff, 0xc0, 0xa8, 0x00, 0x01, // IP 192.168.0.1
   585  	0x20, 0x8d, // Port 8333 in big-endian
   586  	// AddrMe -- No timestamp for NetAddress in version message
   587  	0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // SFNodeNetwork
   588  	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   589  	0x00, 0x00, 0xff, 0xff, 0x7f, 0x00, 0x00, 0x01, // IP 127.0.0.1
   590  	0x20, 0x8d, // Port 8333 in big-endian
   591  	0xf3, 0xe0, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, // Nonce
   592  	0x10, // Varint for user agent length
   593  	0x2f, 0x62, 0x74, 0x63, 0x64, 0x74, 0x65, 0x73,
   594  	0x74, 0x3a, 0x30, 0x2e, 0x30, 0x2e, 0x31, 0x2f, // User agent
   595  	0xfa, 0x92, 0x03, 0x00, // Last block
   596  	0x01, // Relay tx
   597  }