-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmsg_proto_conf_test.go
More file actions
85 lines (64 loc) · 2.4 KB
/
msg_proto_conf_test.go
File metadata and controls
85 lines (64 loc) · 2.4 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package wire
import (
"bufio"
"bytes"
"encoding/hex"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestMsgProtoconf(t *testing.T) {
t.Run("default payload length", func(t *testing.T) {
msg := NewMsgProtoconf(0, true)
assert.Equal(t, "protoconf", msg.Command())
assert.Equal(t, uint64(2), msg.NumberOfFields)
assert.Equal(t, uint64(1024*1024), msg.MaxPayloadLength(ProtocolVersion))
assert.Equal(t, uint32(2*1024*1024), msg.MaxRecvPayloadLength)
assert.Len(t, msg.StreamPolicies, 2)
assert.Equal(t, BlockPriorityStreamPolicy, msg.StreamPolicies[0])
assert.Equal(t, DefaultStreamPolicy, msg.StreamPolicies[1])
})
t.Run("custom payload length", func(t *testing.T) {
customLength := uint32(5 * 1024 * 1024) // 5MB
msg := NewMsgProtoconf(customLength, true)
assert.Equal(t, customLength, msg.MaxRecvPayloadLength)
assert.Len(t, msg.StreamPolicies, 2)
})
t.Run("without block priority", func(t *testing.T) {
msg := NewMsgProtoconf(0, false)
assert.Len(t, msg.StreamPolicies, 1)
assert.Equal(t, DefaultStreamPolicy, msg.StreamPolicies[0])
})
t.Run("encoding and decoding without block priority", func(t *testing.T) {
msg := NewMsgProtoconf(0, false)
var b bytes.Buffer
bw := bufio.NewWriter(&b)
err := msg.BsvEncode(bw, ProtocolVersion, BaseEncoding)
require.NoError(t, err)
err = bw.Flush()
require.NoError(t, err)
assert.Equal(t, "02000020000744656661756c74", hex.EncodeToString(b.Bytes()))
msg2 := &MsgProtoconf{}
r := bytes.NewReader(b.Bytes())
err = msg2.Bsvdecode(r, ProtocolVersion, BaseEncoding)
require.NoError(t, err)
assert.Equal(t, msg.MaxRecvPayloadLength, msg2.MaxRecvPayloadLength)
assert.Equal(t, msg.StreamPolicies, msg2.StreamPolicies)
})
t.Run("encoding and decoding with block priority", func(t *testing.T) {
msg := NewMsgProtoconf(0, true)
var b bytes.Buffer
bw := bufio.NewWriter(&b)
err := msg.BsvEncode(bw, ProtocolVersion, BaseEncoding)
require.NoError(t, err)
err = bw.Flush()
require.NoError(t, err)
assert.Equal(t, "020000200015426c6f636b5072696f726974792c44656661756c74", hex.EncodeToString(b.Bytes()))
msg2 := &MsgProtoconf{}
r := bytes.NewReader(b.Bytes())
err = msg2.Bsvdecode(r, ProtocolVersion, BaseEncoding)
require.NoError(t, err)
assert.Equal(t, msg.MaxRecvPayloadLength, msg2.MaxRecvPayloadLength)
assert.Equal(t, msg.StreamPolicies, msg2.StreamPolicies)
})
}