chore: Remove testify from testdata package (#14575)

This commit is contained in:
Likhita Polavarapu
2023-01-13 09:52:33 +01:00
committed by GitHub
parent 1a58bd0704
commit fae3332d62
10 changed files with 88 additions and 106 deletions
+7 -8
View File
@@ -3,10 +3,11 @@ package testdata
import (
"context"
"fmt"
"testing"
"github.com/cosmos/gogoproto/proto"
"github.com/stretchr/testify/require"
grpc "google.golang.org/grpc"
"gotest.tools/v3/assert"
"github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
@@ -65,11 +66,9 @@ func (m *TestAnyResponse) UnpackInterfaces(unpacker types.AnyUnpacker) error {
// 2. That the gas consumption of the query is the same. When
// `gasOverwrite` is set to true, we also check that this consumed
// gas value is equal to the hardcoded `gasConsumed`.
//
// TODO: replace "github.com/stretchr/testify/require" with "gotest.tools/v3"
func DeterministicIterations[request proto.Message, response proto.Message](
ctx sdk.Context,
require *require.Assertions,
t *testing.T,
req request,
grpcFn func(context.Context, request, ...grpc.CallOption) (response, error),
gasConsumed uint64,
@@ -77,7 +76,7 @@ func DeterministicIterations[request proto.Message, response proto.Message](
) {
before := ctx.GasMeter().GasConsumed()
prevRes, err := grpcFn(ctx, req)
require.NoError(err)
assert.NilError(t, err)
if gasOverwrite { // to handle regressions, i.e. check that gas consumption didn't change
gasConsumed = ctx.GasMeter().GasConsumed() - before
}
@@ -85,8 +84,8 @@ func DeterministicIterations[request proto.Message, response proto.Message](
for i := 0; i < iterCount; i++ {
before := ctx.GasMeter().GasConsumed()
res, err := grpcFn(ctx, req)
require.Equal(ctx.GasMeter().GasConsumed()-before, gasConsumed)
require.NoError(err)
require.Equal(res, prevRes)
assert.Equal(t, ctx.GasMeter().GasConsumed()-before, gasConsumed)
assert.NilError(t, err)
assert.DeepEqual(t, res, prevRes)
}
}
+4 -3
View File
@@ -2,8 +2,9 @@ package testdata
import (
"encoding/json"
"testing"
"github.com/stretchr/testify/require"
"gotest.tools/v3/assert"
"pgregory.net/rapid"
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
@@ -44,9 +45,9 @@ func KeyTestPubAddr() (cryptotypes.PrivKey, cryptotypes.PubKey, sdk.AccAddress)
}
// KeyTestPubAddr generates a new secp256r1 keypair.
func KeyTestPubAddrSecp256R1(require *require.Assertions) (cryptotypes.PrivKey, cryptotypes.PubKey, sdk.AccAddress) {
func KeyTestPubAddrSecp256R1(t *testing.T) (cryptotypes.PrivKey, cryptotypes.PubKey, sdk.AccAddress) {
key, err := secp256r1.GenPrivKey()
require.NoError(err)
assert.NilError(t, err)
pub := key.PubKey()
addr := sdk.AccAddress(pub.Address())
return key, pub, addr