11package rsmt2d
22
33import (
4+ "bytes"
45 "crypto/rand"
56 "encoding/json"
67 "fmt"
78 "reflect"
89 "testing"
10+
11+ "github.com/stretchr/testify/assert"
12+ )
13+
14+ const SHARD_SIZE = 64
15+
16+ var (
17+ zeros = bytes .Repeat ([]byte {0 }, SHARD_SIZE )
18+ ones = bytes .Repeat ([]byte {1 }, SHARD_SIZE )
19+ twos = bytes .Repeat ([]byte {2 }, SHARD_SIZE )
20+ threes = bytes .Repeat ([]byte {3 }, SHARD_SIZE )
21+ fours = bytes .Repeat ([]byte {4 }, SHARD_SIZE )
22+ fives = bytes .Repeat ([]byte {5 }, SHARD_SIZE )
23+ eights = bytes .Repeat ([]byte {8 }, SHARD_SIZE )
24+ elevens = bytes .Repeat ([]byte {11 }, SHARD_SIZE )
25+ thirteens = bytes .Repeat ([]byte {13 }, SHARD_SIZE )
26+ fifteens = bytes .Repeat ([]byte {15 }, SHARD_SIZE )
927)
1028
1129func TestComputeExtendedDataSquare (t * testing.T ) {
12- codec := NewRSGF8Codec ()
13- result , err := ComputeExtendedDataSquare ([][]byte {
14- {1 }, {2 },
15- {3 }, {4 },
16- }, codec , NewDefaultTree )
17- if err != nil {
18- panic (err )
30+ codec := NewLeoRSCodec ()
31+
32+ type testCase struct {
33+ name string
34+ data [][]byte
35+ want [][][]byte
1936 }
20- if ! reflect .DeepEqual (result .squareRow , [][][]byte {
21- {{1 }, {2 }, {7 }, {13 }},
22- {{3 }, {4 }, {13 }, {31 }},
23- {{5 }, {14 }, {19 }, {41 }},
24- {{9 }, {26 }, {47 }, {69 }},
25- }) {
26- t .Errorf ("NewExtendedDataSquare failed for 2x2 square with chunk size 1" )
37+ testCases := []testCase {
38+ {
39+ name : "1x1" ,
40+ // NOTE: data must contain byte slices that are a multiple of 64
41+ // bytes.
42+ // See https://github.com/catid/leopard/blob/22ddc7804998d31c8f1a2617ee720e063b1fa6cd/README.md?plain=1#L27
43+ // See https://github.com/klauspost/reedsolomon/blob/fd3e6910a7e457563469172968f456ad9b7696b6/README.md?plain=1#L403
44+ data : [][]byte {ones },
45+ want : [][][]byte {
46+ {ones , ones },
47+ {ones , ones },
48+ },
49+ },
50+ {
51+ name : "2x2" ,
52+ data : [][]byte {
53+ ones , twos ,
54+ threes , fours ,
55+ },
56+ want : [][][]byte {
57+ {ones , twos , zeros , threes },
58+ {threes , fours , eights , fifteens },
59+ {twos , elevens , thirteens , fours },
60+ {zeros , thirteens , fives , eights },
61+ },
62+ },
63+ }
64+
65+ for _ , tc := range testCases {
66+ t .Run (tc .name , func (t * testing.T ) {
67+ result , err := ComputeExtendedDataSquare (tc .data , codec , NewDefaultTree )
68+ assert .NoError (t , err )
69+ assert .Equal (t , tc .want , result .squareRow )
70+ })
2771 }
2872}
2973
3074func TestMarshalJSON (t * testing.T ) {
31- codec := NewRSGF8Codec ()
75+ codec := NewLeoRSCodec ()
3276 result , err := ComputeExtendedDataSquare ([][]byte {
33- { 1 }, { 2 } ,
34- { 3 }, { 4 } ,
77+ ones , twos ,
78+ threes , fours ,
3579 }, codec , NewDefaultTree )
3680 if err != nil {
3781 panic (err )
@@ -53,10 +97,10 @@ func TestMarshalJSON(t *testing.T) {
5397}
5498
5599func TestImmutableRoots (t * testing.T ) {
56- codec := NewRSGF8Codec ()
100+ codec := NewLeoRSCodec ()
57101 result , err := ComputeExtendedDataSquare ([][]byte {
58- { 1 }, { 2 } ,
59- { 3 }, { 4 } ,
102+ ones , twos ,
103+ threes , fours ,
60104 }, codec , NewDefaultTree )
61105 if err != nil {
62106 panic (err )
@@ -76,10 +120,10 @@ func TestImmutableRoots(t *testing.T) {
76120}
77121
78122func TestEDSRowColImmutable (t * testing.T ) {
79- codec := NewRSGF8Codec ()
123+ codec := NewLeoRSCodec ()
80124 result , err := ComputeExtendedDataSquare ([][]byte {
81- { 1 }, { 2 } ,
82- { 3 }, { 4 } ,
125+ ones , twos ,
126+ threes , fours ,
83127 }, codec , NewDefaultTree )
84128 if err != nil {
85129 panic (err )
0 commit comments