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