Skip to content

Commit

Permalink
small tests refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
walldiss committed Jun 14, 2024
1 parent 4d7810d commit ce65121
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 28 deletions.
2 changes: 1 addition & 1 deletion share/new_eds/rsmt2d_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (

func TestMemFile(t *testing.T) {
odsSize := 8
newAccessor := func(eds *rsmt2d.ExtendedDataSquare) Accessor {
newAccessor := func(tb testing.TB, eds *rsmt2d.ExtendedDataSquare) Accessor {
return &Rsmt2D{ExtendedDataSquare: eds}
}
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
Expand Down
12 changes: 6 additions & 6 deletions share/new_eds/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"github.com/celestiaorg/celestia-node/share/shwap"
)

type createAccessor func(eds *rsmt2d.ExtendedDataSquare) Accessor
type createAccessor func(testing.TB, *rsmt2d.ExtendedDataSquare) Accessor

// TestSuiteAccessor runs a suite of tests for the given Accessor implementation.
func TestSuiteAccessor(
Expand Down Expand Up @@ -51,7 +51,7 @@ func testAccessorSample(
odsSize int,
) {
eds := edstest.RandEDS(t, odsSize)
fl := createAccessor(eds)
fl := createAccessor(t, eds)

dah, err := share.NewRoot(eds)
require.NoError(t, err)
Expand Down Expand Up @@ -108,7 +108,7 @@ func testAccessorRowNamespaceData(
for amount := 1; amount < sharesAmount; amount++ {
// select random amount of shares, but not less than 1
eds, dah := edstest.RandEDSWithNamespace(t, namespace, amount, odsSize)
f := createAccessor(eds)
f := createAccessor(t, eds)

var actualSharesAmount int
// loop over all rows and check that the amount of shares in the namespace is equal to the expected
Expand Down Expand Up @@ -149,7 +149,7 @@ func testAccessorRowNamespaceData(
absentNs, err := share.Namespace(maxNs).AddInt(-1)
require.NoError(t, err)

f := createAccessor(eds)
f := createAccessor(t, eds)
rowData, err := f.RowNamespaceData(ctx, absentNs, i)
require.NoError(t, err)

Expand All @@ -170,7 +170,7 @@ func testAccessorAxisHalf(
odsSize int,
) {
eds := edstest.RandEDS(t, odsSize)
fl := createAccessor(eds)
fl := createAccessor(t, eds)

t.Run("single thread", func(t *testing.T) {
for _, axisType := range []rsmt2d.Axis{rsmt2d.Col, rsmt2d.Row} {
Expand Down Expand Up @@ -224,7 +224,7 @@ func testAccessorShares(
odsSize int,
) {
eds := edstest.RandEDS(t, odsSize)
fl := createAccessor(eds)
fl := createAccessor(t, eds)

shares, err := fl.Shares(ctx)
require.NoError(t, err)
Expand Down
31 changes: 10 additions & 21 deletions store/file/ods_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//nolint:goconst
package file

import (
"context"
"strconv"
"testing"
"time"

Expand Down Expand Up @@ -62,13 +62,6 @@ func TestOdsFile(t *testing.T) {
t.Cleanup(cancel)

odsSize := 8
createOdsFile := func(eds *rsmt2d.ExtendedDataSquare) eds.Accessor {
path := t.TempDir() + "/testfile"
fl, err := CreateOdsFile(path, []byte{}, eds)
require.NoError(t, err)
return fl
}

eds.TestSuiteAccessor(ctx, t, createOdsFile, odsSize)
}

Expand All @@ -90,14 +83,9 @@ func BenchmarkAxisFromOdsFile(b *testing.B) {
b.Cleanup(cancel)

minSize, maxSize := 32, 128
dir := b.TempDir()

newFile := func(size int) eds.Accessor {
eds := edstest.RandEDS(b, size)
path := dir + "/testfile"
f, err := CreateOdsFile(path, []byte{}, eds)
require.NoError(b, err)
return f
return createOdsFile(b, eds)
}
eds.BenchGetHalfAxisFromAccessor(ctx, b, newFile, minSize, maxSize)
}
Expand All @@ -119,15 +107,16 @@ func BenchmarkShareFromOdsFile(b *testing.B) {
b.Cleanup(cancel)

minSize, maxSize := 32, 128
dir := b.TempDir()

newFile := func(size int) eds.Accessor {
eds := edstest.RandEDS(b, size)
path := dir + "/testfile"
f, err := CreateOdsFile(path, []byte{}, eds)
require.NoError(b, err)
return f
return createOdsFile(b, eds)
}

eds.BenchGetSampleFromAccessor(ctx, b, newFile, minSize, maxSize)
}

func createOdsFile(t testing.TB, eds *rsmt2d.ExtendedDataSquare) eds.Accessor {
path := t.TempDir() + "/testfile" + strconv.Itoa(rand.Intn(1000))
fl, err := CreateOdsFile(path, []byte{}, eds)
require.NoError(t, err)
return fl
}

0 comments on commit ce65121

Please sign in to comment.