2015-01-31 19:32:55 +01:00
|
|
|
// Copyright (c) 2013-2015 Conformal Systems LLC.
|
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.
|
|
|
|
|
2015-01-31 19:32:55 +01:00
|
|
|
package wire_test
|
2013-05-08 21:31:00 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"testing"
|
2014-07-03 02:43:33 +02:00
|
|
|
|
2015-01-31 19:32:55 +01:00
|
|
|
"github.com/btcsuite/btcd/wire"
|
2013-05-08 21:31:00 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestMemPool(t *testing.T) {
|
2015-01-31 19:32:55 +01:00
|
|
|
pver := wire.ProtocolVersion
|
2013-05-08 21:31:00 +02:00
|
|
|
|
|
|
|
// Ensure the command is expected value.
|
|
|
|
wantCmd := "mempool"
|
2015-01-31 19:32:55 +01:00
|
|
|
msg := wire.NewMsgMemPool()
|
2013-05-08 21:31:00 +02:00
|
|
|
if cmd := msg.Command(); cmd != wantCmd {
|
|
|
|
t.Errorf("NewMsgMemPool: wrong command - got %v want %v",
|
|
|
|
cmd, wantCmd)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ensure max payload is expected value.
|
|
|
|
wantPayload := uint32(0)
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test encode with latest protocol version.
|
|
|
|
var buf bytes.Buffer
|
|
|
|
err := msg.BtcEncode(&buf, pver)
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("encode of MsgMemPool failed %v err <%v>", msg, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Older protocol versions should fail encode since message didn't
|
|
|
|
// exist yet.
|
2015-01-31 19:32:55 +01:00
|
|
|
oldPver := wire.BIP0035Version - 1
|
2013-05-08 21:31:00 +02:00
|
|
|
err = msg.BtcEncode(&buf, oldPver)
|
|
|
|
if err == nil {
|
|
|
|
s := "encode of MsgMemPool passed for old protocol version %v err <%v>"
|
|
|
|
t.Errorf(s, msg, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test decode with latest protocol version.
|
2015-01-31 19:32:55 +01:00
|
|
|
readmsg := wire.NewMsgMemPool()
|
2013-05-08 21:31:00 +02:00
|
|
|
err = readmsg.BtcDecode(&buf, pver)
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("decode of MsgMemPool failed [%v] err <%v>", buf, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Older protocol versions should fail decode since message didn't
|
|
|
|
// exist yet.
|
|
|
|
err = readmsg.BtcDecode(&buf, oldPver)
|
|
|
|
if err == nil {
|
|
|
|
s := "decode of MsgMemPool passed for old protocol version %v err <%v>"
|
|
|
|
t.Errorf(s, msg, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|