Skip to content

Commit

Permalink
refactor testing
Browse files Browse the repository at this point in the history
  • Loading branch information
evan-forbes authored and renaynay committed Oct 5, 2021
1 parent e59b289 commit b2e58b9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 15 deletions.
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,5 @@ require (
google.golang.org/grpc v1.40.0 // indirect
google.golang.org/protobuf v1.27.1 // indirect
)

replace github.com/ipfs/go-verifcid => github.com/lazyledger/go-verifcid v0.0.1-lazypatch
25 changes: 10 additions & 15 deletions ipld/read_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"context"
"crypto/sha256"
"fmt"
"math"
"math/rand"
"testing"
Expand Down Expand Up @@ -121,20 +122,12 @@ func TestRetrieveBlockData(t *testing.T) {
{"128x128(max)", MaxSquareSize},
}
for _, tc := range tests {
// TODO(Wondertan): remove this
if tc.squareSize > 8 {
continue
}

tc := tc
t.Run(tc.name, func(t *testing.T) {
// generate EDS
namespacedShares := RandNamespacedShares(t, tc.squareSize*tc.squareSize)
shares := namespacedShares.Raw()
extSquareSize := uint64(math.Sqrt(float64(len(namespacedShares))))
tree := wrapper.NewErasuredNamespacedMerkleTree(extSquareSize)
eds, err := rsmt2d.ComputeExtendedDataSquare(shares, rsmt2d.NewRSGF8Codec(), tree.Constructor)
require.NoError(t, err)
eds := generateRandEDS(t, tc.squareSize)
fmt.Println(eds.Width())

in, err := PutData(ctx, eds, dag)
require.NoError(t, err)
Expand All @@ -153,14 +146,16 @@ func TestRetrieveBlockData(t *testing.T) {
}
}

func generateRandEDS(t *testing.T, squareSize int) *rsmt2d.ExtendedDataSquare {
namespacedShares := RandNamespacedShares(t, squareSize*squareSize)
func generateRandEDS(t *testing.T, originalSquareWidth int) *rsmt2d.ExtendedDataSquare {
shareCount := originalSquareWidth * originalSquareWidth

// generate test data
nsshares := RandNamespacedShares(t, shareCount)

shares := namespacedShares.Raw()
shares := nsshares.Raw()

// create the nmt wrapper to generate row and col commitments
extendedSquareSize := uint64(math.Sqrt(float64(len(shares))))
tree := wrapper.NewErasuredNamespacedMerkleTree(extendedSquareSize)
tree := wrapper.NewErasuredNamespacedMerkleTree(uint64(originalSquareWidth))

// compute extended square
eds, err := rsmt2d.ComputeExtendedDataSquare(shares, rsmt2d.NewRSGF8Codec(), tree.Constructor)
Expand Down

0 comments on commit b2e58b9

Please sign in to comment.