forked from celestiaorg/celestia-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpadding_test.go
86 lines (74 loc) · 2 KB
/
padding_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
package shares
import (
"bytes"
"testing"
"github.com/celestiaorg/celestia-app/pkg/appconsts"
appns "github.com/celestiaorg/celestia-app/pkg/namespace"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
var ns1 = appns.MustNewV0(bytes.Repeat([]byte{1}, appns.NamespaceVersionZeroIDSize))
var nsOnePadding, _ = zeroPadIfNecessary(
append(
ns1.Bytes(),
[]byte{
1, // info byte
0, 0, 0, 0, // sequence len
}...,
), appconsts.ShareSize)
var reservedPadding, _ = zeroPadIfNecessary(
append(
appns.PrimaryReservedPaddingNamespace.Bytes(),
[]byte{
1, // info byte
0, 0, 0, 0, // sequence len
}...,
), appconsts.ShareSize)
var tailPadding, _ = zeroPadIfNecessary(
append(
appns.TailPaddingNamespace.Bytes(),
[]byte{
1, // info byte
0, 0, 0, 0, // sequence len
}...,
), appconsts.ShareSize)
func TestNamespacePaddingShare(t *testing.T) {
got, err := NamespacePaddingShare(ns1, appconsts.ShareVersionZero)
assert.NoError(t, err)
assert.Equal(t, nsOnePadding, got.ToBytes())
}
func TestNamespacePaddingShares(t *testing.T) {
shares, err := NamespacePaddingShares(ns1, appconsts.ShareVersionZero, 2)
assert.NoError(t, err)
for _, share := range shares {
assert.Equal(t, nsOnePadding, share.ToBytes())
}
}
func TestReservedPaddingShare(t *testing.T) {
require.NotPanics(t, func() {
got := ReservedPaddingShare()
assert.Equal(t, reservedPadding, got.ToBytes())
})
}
func TestReservedPaddingShares(t *testing.T) {
require.NotPanics(t, func() {
shares := ReservedPaddingShares(2)
for _, share := range shares {
assert.Equal(t, reservedPadding, share.ToBytes())
}
})
}
func TestTailPaddingShare(t *testing.T) {
require.NotPanics(t, func() {
got := TailPaddingShare()
assert.Equal(t, tailPadding, got.ToBytes())
})
}
func TestTailPaddingShares(t *testing.T) {
require.NotPanics(t, func() {
shares := TailPaddingShares(2)
for _, share := range shares {
assert.Equal(t, tailPadding, share.ToBytes())
}
})
}