Skip to content

Commit

Permalink
refactor testing pkgs to use testing.TB
Browse files Browse the repository at this point in the history
  • Loading branch information
walldiss authored and Wondertan committed Jun 14, 2024
1 parent 5401922 commit 13439cc
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
2 changes: 1 addition & 1 deletion nodebuilder/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ type store struct {
edsStore *eds.Store
}

func newStore(ctx context.Context, t require.TestingT, params *eds.Parameters, dir string) store {
func newStore(ctx context.Context, t testing.TB, params *eds.Parameters, dir string) store {
s, err := OpenStore(dir, nil)
require.NoError(t, err)
ds, err := s.Datastore()
Expand Down
9 changes: 4 additions & 5 deletions share/eds/edstest/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/celestiaorg/celestia-node/share/sharetest"
)

func RandByzantineEDS(t *testing.T, size int, options ...nmt.Option) *rsmt2d.ExtendedDataSquare {
func RandByzantineEDS(t testing.TB, 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
Expand All @@ -25,17 +25,16 @@ func RandByzantineEDS(t *testing.T, size int, options ...nmt.Option) *rsmt2d.Ext
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 {
// RandEDS generates EDS filled with the random data with the given size for original square.
func RandEDS(t testing.TB, 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,
t testing.TB,
namespace share.Namespace,
size int,
) (*rsmt2d.ExtendedDataSquare, *share.Root) {
Expand Down
8 changes: 4 additions & 4 deletions share/sharetest/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"math/rand"
"sort"
"sync"
"testing"
"time"

"github.com/stretchr/testify/require"
Expand All @@ -14,9 +15,8 @@ import (
"github.com/celestiaorg/celestia-node/share"
)

// RandShares generate 'total' amount of shares filled with random data. It uses require.TestingT
// to be able to take both a *testing.T and a *testing.B.
func RandShares(t require.TestingT, total int) []share.Share {
// RandShares generate 'total' amount of shares filled with random data.
func RandShares(t testing.TB, total int) []share.Share {
if total&(total-1) != 0 {
t.Errorf("total must be power of 2: %d", total)
t.FailNow()
Expand All @@ -38,7 +38,7 @@ func RandShares(t require.TestingT, total int) []share.Share {
}

// RandSharesWithNamespace is same the as RandShares, but sets same namespace for all shares.
func RandSharesWithNamespace(t require.TestingT, namespace share.Namespace, total int) []share.Share {
func RandSharesWithNamespace(t testing.TB, namespace share.Namespace, total int) []share.Share {
if total&(total-1) != 0 {
t.Errorf("total must be power of 2: %d", total)
t.FailNow()
Expand Down

0 comments on commit 13439cc

Please sign in to comment.