test: remove api that should not be used (#15678)
This commit is contained in:
parent
5e90819765
commit
c3b1b37e49
@ -12,6 +12,7 @@ import (
|
||||
abci "github.com/cometbft/cometbft/abci/types"
|
||||
cmtproto "github.com/cometbft/cometbft/proto/tendermint/types"
|
||||
cmttime "github.com/cometbft/cometbft/types/time"
|
||||
"github.com/stretchr/testify/require"
|
||||
"gotest.tools/v3/assert"
|
||||
|
||||
storetypes "cosmossdk.io/store/types"
|
||||
@ -20,7 +21,6 @@ import (
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
|
||||
"github.com/cosmos/cosmos-sdk/runtime"
|
||||
"github.com/cosmos/cosmos-sdk/testutil"
|
||||
"github.com/cosmos/cosmos-sdk/testutil/configurator"
|
||||
"github.com/cosmos/cosmos-sdk/testutil/sims"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
@ -242,15 +242,15 @@ func TestSupply_SendCoins(t *testing.T) {
|
||||
authKeeper.SetModuleAccount(ctx, burnerAcc)
|
||||
authKeeper.SetAccount(ctx, baseAcc)
|
||||
|
||||
testutil.AssertPanics(t, func() {
|
||||
require.Panics(t, func() {
|
||||
_ = keeper.SendCoinsFromModuleToModule(ctx, "", holderAcc.GetName(), initCoins) //nolint:errcheck // no error check is needed because we are testing for a panic
|
||||
})
|
||||
|
||||
testutil.AssertPanics(t, func() {
|
||||
require.Panics(t, func() {
|
||||
_ = keeper.SendCoinsFromModuleToModule(ctx, authtypes.Burner, "", initCoins) //nolint:errcheck // no error check is needed because we are testing for a panic
|
||||
})
|
||||
|
||||
testutil.AssertPanics(t, func() {
|
||||
require.Panics(t, func() {
|
||||
_ = keeper.SendCoinsFromModuleToAccount(ctx, "", baseAcc.GetAddress(), initCoins) //nolint:errcheck // no error check is needed because we are testing for a panic
|
||||
})
|
||||
|
||||
@ -294,14 +294,14 @@ func TestSupply_MintCoins(t *testing.T) {
|
||||
assert.NilError(t, err)
|
||||
|
||||
// no module account
|
||||
testutil.AssertPanics(t, func() { keeper.MintCoins(ctx, "", initCoins) }) //nolint:errcheck // we're testing for a panic
|
||||
require.Panics(t, func() { keeper.MintCoins(ctx, "", initCoins) }) //nolint:errcheck // we're testing for a panic
|
||||
// invalid permission
|
||||
testutil.AssertPanics(t, func() { keeper.MintCoins(ctx, authtypes.Burner, initCoins) }) //nolint:errcheck // we're testing for a panic
|
||||
require.Panics(t, func() { keeper.MintCoins(ctx, authtypes.Burner, initCoins) }) //nolint:errcheck // we're testing for a panic
|
||||
|
||||
err = keeper.MintCoins(ctx, authtypes.Minter, sdk.Coins{sdk.Coin{Denom: "denom", Amount: sdk.NewInt(-10)}})
|
||||
assert.Error(t, err, fmt.Sprintf("%sdenom: invalid coins", sdk.NewInt(-10)))
|
||||
|
||||
testutil.AssertPanics(t, func() { keeper.MintCoins(ctx, randomPerm, initCoins) }) //nolint:errcheck // we're testing for a panic
|
||||
require.Panics(t, func() { keeper.MintCoins(ctx, randomPerm, initCoins) }) //nolint:errcheck // we're testing for a panic
|
||||
|
||||
err = keeper.MintCoins(ctx, authtypes.Minter, initCoins)
|
||||
assert.NilError(t, err)
|
||||
@ -323,7 +323,7 @@ func TestSupply_MintCoins(t *testing.T) {
|
||||
assert.NilError(t, err)
|
||||
assert.DeepEqual(t, initCoins, getCoinsByName(ctx, keeper, authKeeper, multiPermAcc.GetName()))
|
||||
assert.DeepEqual(t, initialSupply.Add(initCoins...), totalSupply)
|
||||
testutil.AssertPanics(t, func() { keeper.MintCoins(ctx, authtypes.Burner, initCoins) }) //nolint:errcheck // we're testing for a panic
|
||||
require.Panics(t, func() { keeper.MintCoins(ctx, authtypes.Burner, initCoins) }) //nolint:errcheck // we're testing for a panic
|
||||
}
|
||||
|
||||
func TestSupply_BurnCoins(t *testing.T) {
|
||||
@ -344,11 +344,11 @@ func TestSupply_BurnCoins(t *testing.T) {
|
||||
supplyAfterInflation, _, err := keeper.GetPaginatedTotalSupply(ctx, &query.PageRequest{})
|
||||
assert.NilError(t, err)
|
||||
// no module account
|
||||
testutil.AssertPanics(t, func() { keeper.BurnCoins(ctx, "", initCoins) }) //nolint:errcheck // we're testing for a panic
|
||||
require.Panics(t, func() { keeper.BurnCoins(ctx, "", initCoins) }) //nolint:errcheck // we're testing for a panic
|
||||
// invalid permission
|
||||
testutil.AssertPanics(t, func() { keeper.BurnCoins(ctx, authtypes.Minter, initCoins) }) //nolint:errcheck // we're testing for a panic
|
||||
require.Panics(t, func() { keeper.BurnCoins(ctx, authtypes.Minter, initCoins) }) //nolint:errcheck // we're testing for a panic
|
||||
// random permission
|
||||
testutil.AssertPanics(t, func() { keeper.BurnCoins(ctx, randomPerm, supplyAfterInflation) }) //nolint:errcheck // we're testing for a panic
|
||||
require.Panics(t, func() { keeper.BurnCoins(ctx, randomPerm, supplyAfterInflation) }) //nolint:errcheck // we're testing for a panic
|
||||
err = keeper.BurnCoins(ctx, authtypes.Burner, supplyAfterInflation)
|
||||
assert.Error(t, err, fmt.Sprintf("spendable balance %s is smaller than %s: insufficient funds", initCoins, supplyAfterInflation))
|
||||
|
||||
|
||||
@ -9,11 +9,11 @@ import (
|
||||
|
||||
"cosmossdk.io/math"
|
||||
cmtproto "github.com/cometbft/cometbft/proto/tendermint/types"
|
||||
"github.com/stretchr/testify/require"
|
||||
"gotest.tools/v3/assert"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/baseapp"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
|
||||
sdktestutil "github.com/cosmos/cosmos-sdk/testutil"
|
||||
"github.com/cosmos/cosmos-sdk/testutil/configurator"
|
||||
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
@ -297,7 +297,7 @@ func TestDeliverGenTxs(t *testing.T) {
|
||||
tc.malleate()
|
||||
|
||||
if tc.expPass {
|
||||
sdktestutil.AssertNotPanics(t, func() {
|
||||
require.NotPanics(t, func() {
|
||||
genutil.DeliverGenTxs(
|
||||
f.ctx, genTxs, f.stakingKeeper, f.baseApp.DeliverTx,
|
||||
f.encodingConfig.TxConfig,
|
||||
|
||||
@ -8,10 +8,10 @@ import (
|
||||
"cosmossdk.io/simapp"
|
||||
abci "github.com/cometbft/cometbft/abci/types"
|
||||
cmtproto "github.com/cometbft/cometbft/proto/tendermint/types"
|
||||
"github.com/stretchr/testify/require"
|
||||
"gotest.tools/v3/assert"
|
||||
|
||||
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
|
||||
sdktestutil "github.com/cosmos/cosmos-sdk/testutil"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/bank/testutil"
|
||||
"github.com/cosmos/cosmos-sdk/x/staking"
|
||||
@ -137,7 +137,7 @@ func TestInitGenesis_PoolsBalanceMismatch(t *testing.T) {
|
||||
BondDenom: "stake",
|
||||
}
|
||||
|
||||
sdktestutil.AssertPanics(t, func() {
|
||||
require.Panics(t, func() {
|
||||
// setting validator status to bonded so the balance counts towards bonded pool
|
||||
validator.Status = types.Bonded
|
||||
app.StakingKeeper.InitGenesis(ctx, &types.GenesisState{
|
||||
@ -148,7 +148,7 @@ func TestInitGenesis_PoolsBalanceMismatch(t *testing.T) {
|
||||
// "should panic because bonded pool balance is different from bonded pool coins",
|
||||
)
|
||||
|
||||
sdktestutil.AssertPanics(t, func() {
|
||||
require.Panics(t, func() {
|
||||
// setting validator status to unbonded so the balance counts towards not bonded pool
|
||||
validator.Status = types.Unbonded
|
||||
app.StakingKeeper.InitGenesis(ctx, &types.GenesisState{
|
||||
|
||||
@ -7,9 +7,9 @@ import (
|
||||
"cosmossdk.io/math"
|
||||
"cosmossdk.io/simapp"
|
||||
cmtproto "github.com/cometbft/cometbft/proto/tendermint/types"
|
||||
"github.com/stretchr/testify/require"
|
||||
"gotest.tools/v3/assert"
|
||||
|
||||
sdktestutil "github.com/cosmos/cosmos-sdk/testutil"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
banktestutil "github.com/cosmos/cosmos-sdk/x/bank/testutil"
|
||||
"github.com/cosmos/cosmos-sdk/x/staking/keeper"
|
||||
@ -382,7 +382,7 @@ func TestSlashWithRedelegation(t *testing.T) {
|
||||
_, found := app.StakingKeeper.GetValidatorByConsAddr(ctx, consAddr)
|
||||
assert.Assert(t, found)
|
||||
|
||||
sdktestutil.AssertNotPanics(t, func() {
|
||||
require.NotPanics(t, func() {
|
||||
app.StakingKeeper.Slash(ctx, consAddr, 10, 10, fraction)
|
||||
})
|
||||
burnAmount := sdk.NewDecFromInt(app.StakingKeeper.TokensFromConsensusPower(ctx, 10)).Mul(fraction).TruncateInt()
|
||||
@ -415,7 +415,7 @@ func TestSlashWithRedelegation(t *testing.T) {
|
||||
_, found = app.StakingKeeper.GetValidatorByConsAddr(ctx, consAddr)
|
||||
assert.Assert(t, found)
|
||||
|
||||
sdktestutil.AssertNotPanics(t, func() {
|
||||
require.NotPanics(t, func() {
|
||||
app.StakingKeeper.Slash(ctx, consAddr, 10, 10, math.LegacyOneDec())
|
||||
})
|
||||
burnAmount = app.StakingKeeper.TokensFromConsensusPower(ctx, 7)
|
||||
@ -451,7 +451,7 @@ func TestSlashWithRedelegation(t *testing.T) {
|
||||
_, found = app.StakingKeeper.GetValidatorByConsAddr(ctx, consAddr)
|
||||
assert.Assert(t, found)
|
||||
|
||||
sdktestutil.AssertNotPanics(t, func() {
|
||||
require.NotPanics(t, func() {
|
||||
app.StakingKeeper.Slash(ctx, consAddr, 10, 10, math.LegacyOneDec())
|
||||
})
|
||||
|
||||
@ -486,7 +486,7 @@ func TestSlashWithRedelegation(t *testing.T) {
|
||||
validator, _ = app.StakingKeeper.GetValidatorByConsAddr(ctx, consAddr)
|
||||
assert.Equal(t, validator.GetStatus(), types.Unbonding)
|
||||
|
||||
sdktestutil.AssertNotPanics(t, func() {
|
||||
require.NotPanics(t, func() {
|
||||
app.StakingKeeper.Slash(ctx, consAddr, 10, 10, math.LegacyOneDec())
|
||||
})
|
||||
|
||||
|
||||
@ -1,25 +0,0 @@
|
||||
package testutil
|
||||
|
||||
import "testing"
|
||||
|
||||
func AssertPanics(t *testing.T, f func()) {
|
||||
panicked := false
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
panicked = true
|
||||
}
|
||||
}()
|
||||
f()
|
||||
if !panicked {
|
||||
t.Errorf("should panic")
|
||||
}
|
||||
}
|
||||
|
||||
func AssertNotPanics(t *testing.T, f func()) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
t.Errorf("should not panic: %v", r)
|
||||
}
|
||||
}()
|
||||
f()
|
||||
}
|
||||
16
testutil/compare.go
Normal file
16
testutil/compare.go
Normal file
@ -0,0 +1,16 @@
|
||||
package testutil
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"github.com/stretchr/testify/require"
|
||||
"google.golang.org/protobuf/testing/protocmp"
|
||||
)
|
||||
|
||||
// RequireProtoDeepEqual fails the test t if p1 and p2 are not equivalent protobuf messages.
|
||||
// Where p1 and p2 are proto.Message or slices of proto.Message.
|
||||
func RequireProtoDeepEqual(t *testing.T, p1, p2 interface{}) {
|
||||
t.Helper()
|
||||
require.Empty(t, cmp.Diff(p1, p2, protocmp.Transform()))
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user