forked from celestiaorg/celestia-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinfo_byte_test.go
103 lines (90 loc) · 2.17 KB
/
info_byte_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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package shares
import "testing"
func TestInfoByte(t *testing.T) {
blobStart := true
notBlobStart := false
type testCase struct {
version uint8
isSequenceStart bool
}
tests := []testCase{
{0, blobStart},
{1, blobStart},
{2, blobStart},
{127, blobStart},
{0, notBlobStart},
{1, notBlobStart},
{2, notBlobStart},
{127, notBlobStart},
}
for _, test := range tests {
irb, err := NewInfoByte(test.version, test.isSequenceStart)
if err != nil {
t.Errorf("got %v want no error", err)
}
if got := irb.Version(); got != test.version {
t.Errorf("got version %v want %v", got, test.version)
}
if got := irb.IsSequenceStart(); got != test.isSequenceStart {
t.Errorf("got IsSequenceStart %v want %v", got, test.isSequenceStart)
}
}
}
func TestInfoByteErrors(t *testing.T) {
blobStart := true
notBlobStart := false
type testCase struct {
version uint8
isSequenceStart bool
}
tests := []testCase{
{128, notBlobStart},
{255, notBlobStart},
{128, blobStart},
{255, blobStart},
}
for _, test := range tests {
_, err := NewInfoByte(test.version, false)
if err == nil {
t.Errorf("got nil but want error when version > 127")
}
}
}
func FuzzNewInfoByte(f *testing.F) {
f.Fuzz(func(t *testing.T, version uint8, isSequenceStart bool) {
if version > 127 {
t.Skip()
}
_, err := NewInfoByte(version, isSequenceStart)
if err != nil {
t.Errorf("got nil but want error when version > 127")
}
})
}
func TestParseInfoByte(t *testing.T) {
type testCase struct {
b byte
wantVersion uint8
wantisSequenceStart bool
}
tests := []testCase{
{0b00000000, 0, false},
{0b00000001, 0, true},
{0b00000010, 1, false},
{0b00000011, 1, true},
{0b00000101, 2, true},
{0b11111111, 127, true},
}
for _, test := range tests {
got, err := ParseInfoByte(test.b)
if err != nil {
t.Errorf("got %v want no error", err)
}
if got.Version() != test.wantVersion {
t.Errorf("got version %v want %v", got.Version(), test.wantVersion)
}
if got.IsSequenceStart() != test.wantisSequenceStart {
t.Errorf("got IsSequenceStart %v want %v", got.IsSequenceStart(), test.wantisSequenceStart)
}
}
}