github.com/dashpay/godash@v0.0.0-20160726055534-e038a21e0e3d/wire/msgmempool_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  	"testing"
    11  
    12  	"github.com/dashpay/godash/wire"
    13  )
    14  
    15  func TestMemPool(t *testing.T) {
    16  	pver := wire.ProtocolVersion
    17  
    18  	// Ensure the command is expected value.
    19  	wantCmd := "mempool"
    20  	msg := wire.NewMsgMemPool()
    21  	if cmd := msg.Command(); cmd != wantCmd {
    22  		t.Errorf("NewMsgMemPool: wrong command - got %v want %v",
    23  			cmd, wantCmd)
    24  	}
    25  
    26  	// Ensure max payload is expected value.
    27  	wantPayload := uint32(0)
    28  	maxPayload := msg.MaxPayloadLength(pver)
    29  	if maxPayload != wantPayload {
    30  		t.Errorf("MaxPayloadLength: wrong max payload length for "+
    31  			"protocol version %d - got %v, want %v", pver,
    32  			maxPayload, wantPayload)
    33  	}
    34  
    35  	// Test encode with latest protocol version.
    36  	var buf bytes.Buffer
    37  	err := msg.BtcEncode(&buf, pver)
    38  	if err != nil {
    39  		t.Errorf("encode of MsgMemPool failed %v err <%v>", msg, err)
    40  	}
    41  
    42  	// Older protocol versions should fail encode since message didn't
    43  	// exist yet.
    44  	oldPver := wire.BIP0035Version - 1
    45  	err = msg.BtcEncode(&buf, oldPver)
    46  	if err == nil {
    47  		s := "encode of MsgMemPool passed for old protocol version %v err <%v>"
    48  		t.Errorf(s, msg, err)
    49  	}
    50  
    51  	// Test decode with latest protocol version.
    52  	readmsg := wire.NewMsgMemPool()
    53  	err = readmsg.BtcDecode(&buf, pver)
    54  	if err != nil {
    55  		t.Errorf("decode of MsgMemPool failed [%v] err <%v>", buf, err)
    56  	}
    57  
    58  	// Older protocol versions should fail decode since message didn't
    59  	// exist yet.
    60  	err = readmsg.BtcDecode(&buf, oldPver)
    61  	if err == nil {
    62  		s := "decode of MsgMemPool passed for old protocol version %v err <%v>"
    63  		t.Errorf(s, msg, err)
    64  	}
    65  
    66  	return
    67  }