-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathheader_fields_test.go
69 lines (64 loc) · 1.55 KB
/
header_fields_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
66
67
68
69
/*
Copyright (c) Facebook, Inc. and its affiliates.
This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
*/
package tacquito
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestSequenceNumber(t *testing.T) {
tests := []struct {
name string
validate func()
}{
{
name: "below lower bound",
validate: func() {
err := SequenceNumber(0).Validate(nil)
assert.Error(t, err, "sequence 0 should be invalid")
},
},
{
name: "lower bound",
validate: func() {
err := SequenceNumber(1).Validate(nil)
assert.NoError(t, err, "sequence 1 should be valid")
},
},
{
name: "upper bound",
validate: func() {
err := SequenceNumber(HeaderMaxSequence).Validate(nil)
assert.NoError(t, err, "sequence value of 2 ^ 8 - 1 should be valid")
},
},
{
name: "beyond upper bound",
validate: func() {
err := SequenceNumber(HeaderMaxSequence + 1).Validate(nil)
assert.Error(t, err, "sequence number beyond 2 ^ 8 - 1 should be invalid")
},
},
{
name: "invalid client sequence",
validate: func() {
err := ClientSequenceNumber(2).Validate(nil)
assert.Error(t, err, "even sequence number should be invalid")
},
},
{
name: "invalid exchange sequence",
validate: func() {
last := SequenceNumber(4)
current := SequenceNumber(3)
err := LastSequence(last).Validate(current)
assert.Error(t, err, "sequence numbers must be monotonic")
},
},
}
for _, test := range tests {
test.validate()
}
}