forked from btcsuite/btcwire
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmsgmempool_test.go
65 lines (55 loc) · 1.69 KB
/
msgmempool_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Copyright (c) 2013 Conformal Systems LLC.
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.
package btcwire_test
import (
"bytes"
"github.com/conformal/btcwire"
"testing"
)
func TestMemPool(t *testing.T) {
pver := btcwire.ProtocolVersion
// Ensure the command is expected value.
wantCmd := "mempool"
msg := btcwire.NewMsgMemPool()
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.
oldPver := btcwire.BIP0035Version - 1
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.
readmsg := btcwire.NewMsgMemPool()
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
}