-
Notifications
You must be signed in to change notification settings - Fork 923
/
testing.go
48 lines (41 loc) · 1.69 KB
/
testing.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
package edstest
import (
"testing"
"github.com/stretchr/testify/require"
"github.com/celestiaorg/celestia-app/pkg/wrapper"
"github.com/celestiaorg/nmt"
"github.com/celestiaorg/rsmt2d"
"github.com/celestiaorg/celestia-node/share"
"github.com/celestiaorg/celestia-node/share/sharetest"
)
func RandByzantineEDS(t *testing.T, size int, options ...nmt.Option) *rsmt2d.ExtendedDataSquare {
eds := RandEDS(t, size)
shares := eds.Flattened()
copy(share.GetData(shares[0]), share.GetData(shares[1])) // corrupting eds
eds, err := rsmt2d.ImportExtendedDataSquare(shares,
share.DefaultRSMT2DCodec(),
wrapper.NewConstructor(uint64(size),
options...))
require.NoError(t, err, "failure to recompute the extended data square")
return eds
}
// RandEDS generates EDS filled with the random data with the given size for original square. It
// uses require.TestingT to be able to take both a *testing.T and a *testing.B.
func RandEDS(t require.TestingT, size int) *rsmt2d.ExtendedDataSquare {
shares := sharetest.RandShares(t, size*size)
eds, err := rsmt2d.ComputeExtendedDataSquare(shares, share.DefaultRSMT2DCodec(), wrapper.NewConstructor(uint64(size)))
require.NoError(t, err, "failure to recompute the extended data square")
return eds
}
func RandEDSWithNamespace(
t require.TestingT,
namespace share.Namespace,
size int,
) (*rsmt2d.ExtendedDataSquare, *share.Root) {
shares := sharetest.RandSharesWithNamespace(t, namespace, size*size)
eds, err := rsmt2d.ComputeExtendedDataSquare(shares, share.DefaultRSMT2DCodec(), wrapper.NewConstructor(uint64(size)))
require.NoError(t, err, "failure to recompute the extended data square")
dah, err := share.NewRoot(eds)
require.NoError(t, err)
return eds, dah
}