Skip to content

Commit

Permalink
chore: cleanup comet dependence in tests (#18239)
Browse files Browse the repository at this point in the history
  • Loading branch information
facundomedica authored Oct 26, 2023
1 parent bb05bf0 commit ab2a725
Show file tree
Hide file tree
Showing 33 changed files with 105 additions and 386 deletions.
11 changes: 0 additions & 11 deletions baseapp/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,6 @@ func (app *BaseApp) SimDeliver(txEncoder sdk.TxEncoder, tx sdk.Tx) (sdk.GasInfo,
return gasInfo, result, err
}

func (app *BaseApp) SimTxFinalizeBlock(txEncoder sdk.TxEncoder, tx sdk.Tx) (sdk.GasInfo, *sdk.Result, error) {
// See comment for Check().
bz, err := txEncoder(tx)
if err != nil {
return sdk.GasInfo{}, nil, errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "%s", err)
}

gasInfo, result, _, err := app.runTx(execModeFinalize, bz)
return gasInfo, result, err
}

// NewContextLegacy returns a new sdk.Context with the provided header
func (app *BaseApp) NewContextLegacy(isCheckTx bool, header cmtproto.Header) sdk.Context {
if isCheckTx {
Expand Down
12 changes: 6 additions & 6 deletions tests/integration/bank/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import (
"testing"

abci "github.com/cometbft/cometbft/abci/types"
cmtproto "github.com/cometbft/cometbft/proto/tendermint/types"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"cosmossdk.io/core/header"
"cosmossdk.io/depinject"
"cosmossdk.io/log"
sdkmath "cosmossdk.io/math"
Expand Down Expand Up @@ -168,7 +168,7 @@ func TestSendNotEnoughBalance(t *testing.T) {
origSeq := res1.GetSequence()

sendMsg := types.NewMsgSend(addr1, addr2, sdk.Coins{sdk.NewInt64Coin("foocoin", 100)})
header := cmtproto.Header{Height: baseApp.LastBlockHeight() + 1}
header := header.Info{Height: baseApp.LastBlockHeight() + 1}
txConfig := moduletestutil.MakeTestTxConfig()
_, _, err = simtestutil.SignCheckDeliver(t, txConfig, baseApp, header, []sdk.Msg{sendMsg}, "", []uint64{origAccNum}, []uint64{origSeq}, false, false, priv1)
require.Error(t, err)
Expand Down Expand Up @@ -248,7 +248,7 @@ func TestMsgMultiSendWithAccounts(t *testing.T) {

for _, tc := range testCases {
t.Logf("testing %s", tc.desc)
header := cmtproto.Header{Height: baseApp.LastBlockHeight() + 1}
header := header.Info{Height: baseApp.LastBlockHeight() + 1}
txConfig := moduletestutil.MakeTestTxConfig()
_, _, err := simtestutil.SignCheckDeliver(t, txConfig, baseApp, header, tc.msgs, "", tc.accNums, tc.accSeqs, tc.expSimPass, tc.expPass, tc.privKeys...)
if tc.expPass {
Expand Down Expand Up @@ -300,7 +300,7 @@ func TestMsgMultiSendMultipleOut(t *testing.T) {
}

for _, tc := range testCases {
header := cmtproto.Header{Height: baseApp.LastBlockHeight() + 1}
header := header.Info{Height: baseApp.LastBlockHeight() + 1}
txConfig := moduletestutil.MakeTestTxConfig()
_, _, err := simtestutil.SignCheckDeliver(t, txConfig, baseApp, header, tc.msgs, "", tc.accNums, tc.accSeqs, tc.expSimPass, tc.expPass, tc.privKeys...)
require.NoError(t, err)
Expand Down Expand Up @@ -355,7 +355,7 @@ func TestMsgMultiSendDependent(t *testing.T) {
}

for _, tc := range testCases {
header := cmtproto.Header{Height: baseApp.LastBlockHeight() + 1}
header := header.Info{Height: baseApp.LastBlockHeight() + 1}
txConfig := moduletestutil.MakeTestTxConfig()
_, _, err := simtestutil.SignCheckDeliver(t, txConfig, baseApp, header, tc.msgs, "", tc.accNums, tc.accSeqs, tc.expSimPass, tc.expPass, tc.privKeys...)
require.NoError(t, err)
Expand Down Expand Up @@ -434,7 +434,7 @@ func TestMsgSetSendEnabled(t *testing.T) {

for _, tc := range testCases {
t.Run(tc.desc, func(tt *testing.T) {
header := cmtproto.Header{Height: s.App.LastBlockHeight() + 1}
header := header.Info{Height: s.App.LastBlockHeight() + 1}
txGen := moduletestutil.MakeTestTxConfig()
_, _, err = simtestutil.SignCheckDeliver(tt, txGen, s.App.BaseApp, header, tc.msgs, "", []uint64{0}, tc.accSeqs, tc.expSimPass, tc.expPass, priv1)
if len(tc.expInError) > 0 {
Expand Down
4 changes: 2 additions & 2 deletions testutil/sims/tx_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import (
"time"

types2 "github.com/cometbft/cometbft/abci/types"
"github.com/cometbft/cometbft/proto/tendermint/types"
"github.com/stretchr/testify/require"

"cosmossdk.io/core/header"
"cosmossdk.io/errors"

"github.com/cosmos/cosmos-sdk/baseapp"
Expand Down Expand Up @@ -93,7 +93,7 @@ func GenSignedMockTx(r *rand.Rand, txConfig client.TxConfig, msgs []sdk.Msg, fee
// the parameter 'expPass' against the result. A corresponding result is
// returned.
func SignCheckDeliver(
t *testing.T, txCfg client.TxConfig, app *baseapp.BaseApp, header types.Header, msgs []sdk.Msg,
t *testing.T, txCfg client.TxConfig, app *baseapp.BaseApp, header header.Info, msgs []sdk.Msg,
chainID string, accNums, accSeqs []uint64, expSimPass, expPass bool, priv ...cryptotypes.PrivKey,
) (sdk.GasInfo, *sdk.Result, error) {
t.Helper()
Expand Down
8 changes: 0 additions & 8 deletions x/auth/ante/feegrant_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,9 @@ import (
"testing"
"time"

"github.com/cometbft/cometbft/crypto"
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/require"

storetypes "cosmossdk.io/store/types"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
Expand Down Expand Up @@ -190,11 +187,6 @@ func TestDeductFeesNoDelegation(t *testing.T) {
}
}

// don't consume any gas
func SigGasNoConsumer(meter storetypes.GasMeter, sig []byte, pubkey crypto.PubKey, params authtypes.Params) error {
return nil
}

func genTxWithFeeGranter(gen client.TxConfig, msgs []sdk.Msg, feeAmt sdk.Coins, gas uint64, chainID string, accNums,
accSeqs []uint64, feeGranter sdk.AccAddress, priv ...cryptotypes.PrivKey,
) (sdk.Tx, error) {
Expand Down
6 changes: 2 additions & 4 deletions x/auth/vesting/fuzz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ import (
"testing"
"time"

cmtproto "github.com/cometbft/cometbft/proto/tendermint/types"
cmttime "github.com/cometbft/cometbft/types/time"
"github.com/golang/mock/gomock"
fuzz "github.com/google/gofuzz"

"cosmossdk.io/core/header"
"cosmossdk.io/log"
storetypes "cosmossdk.io/store/types"

Expand Down Expand Up @@ -118,8 +117,7 @@ func FuzzMsgServerCreateVestingAccount(f *testing.F) {

msgServer := NewMsgServerImpl(accountKeeper, bankKeeper)
testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test"))
ctx := testCtx.Ctx.WithBlockHeader(cmtproto.Header{Time: cmttime.Now()})

ctx := testCtx.Ctx.WithHeaderInfo(header.Info{Time: time.Now()})
_, _ = msgServer.CreateVestingAccount(ctx, va)
})
}
6 changes: 3 additions & 3 deletions x/auth/vesting/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ import (
"testing"
"time"

cmtproto "github.com/cometbft/cometbft/proto/tendermint/types"
cmttime "github.com/cometbft/cometbft/types/time"
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/suite"

"cosmossdk.io/core/header"
"cosmossdk.io/math"
storetypes "cosmossdk.io/store/types"

Expand Down Expand Up @@ -46,7 +45,8 @@ func (s *VestingTestSuite) SetupTest() {
key := storetypes.NewKVStoreKey(authtypes.StoreKey)
storeService := runtime.NewKVStoreService(key)
testCtx := testutil.DefaultContextWithDB(s.T(), key, storetypes.NewTransientStoreKey("transient_test"))
s.ctx = testCtx.Ctx.WithBlockHeader(cmtproto.Header{Time: cmttime.Now()})
s.ctx = testCtx.Ctx.WithHeaderInfo(header.Info{Time: time.Now()})

encCfg := moduletestutil.MakeTestEncodingConfig()

maccPerms := map[string][]string{}
Expand Down
43 changes: 21 additions & 22 deletions x/auth/vesting/types/vesting_account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"testing"
"time"

tmtime "github.com/cometbft/cometbft/types/time"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"

Expand Down Expand Up @@ -66,7 +65,7 @@ func (s *VestingAccountTestSuite) SetupTest() {
}

func TestGetVestedCoinsContVestingAcc(t *testing.T) {
now := tmtime.Now()
now := time.Now()
startTime := now.Add(24 * time.Hour)
endTime := startTime.Add(24 * time.Hour)

Expand Down Expand Up @@ -102,7 +101,7 @@ func TestGetVestedCoinsContVestingAcc(t *testing.T) {
}

func TestGetVestingCoinsContVestingAcc(t *testing.T) {
now := tmtime.Now()
now := time.Now()
startTime := now.Add(24 * time.Hour)
endTime := startTime.Add(24 * time.Hour)

Expand Down Expand Up @@ -134,7 +133,7 @@ func TestGetVestingCoinsContVestingAcc(t *testing.T) {
}

func TestSpendableCoinsContVestingAcc(t *testing.T) {
now := tmtime.Now()
now := time.Now()
startTime := now.Add(24 * time.Hour)
endTime := startTime.Add(24 * time.Hour)

Expand Down Expand Up @@ -166,7 +165,7 @@ func TestSpendableCoinsContVestingAcc(t *testing.T) {
}

func TestTrackDelegationContVestingAcc(t *testing.T) {
now := tmtime.Now()
now := time.Now()
endTime := now.Add(24 * time.Hour)

bacc, origCoins := initBaseAccount()
Expand Down Expand Up @@ -207,7 +206,7 @@ func TestTrackDelegationContVestingAcc(t *testing.T) {
}

func TestTrackUndelegationContVestingAcc(t *testing.T) {
now := tmtime.Now()
now := time.Now()
endTime := now.Add(24 * time.Hour)

bacc, origCoins := initBaseAccount()
Expand Down Expand Up @@ -255,7 +254,7 @@ func TestTrackUndelegationContVestingAcc(t *testing.T) {
}

func TestGetVestedCoinsDelVestingAcc(t *testing.T) {
now := tmtime.Now()
now := time.Now()
endTime := now.Add(24 * time.Hour)

bacc, origCoins := initBaseAccount()
Expand All @@ -272,7 +271,7 @@ func TestGetVestedCoinsDelVestingAcc(t *testing.T) {
}

func TestGetVestingCoinsDelVestingAcc(t *testing.T) {
now := tmtime.Now()
now := time.Now()
endTime := now.Add(24 * time.Hour)

bacc, origCoins := initBaseAccount()
Expand All @@ -289,7 +288,7 @@ func TestGetVestingCoinsDelVestingAcc(t *testing.T) {
}

func TestSpendableCoinsDelVestingAcc(t *testing.T) {
now := tmtime.Now()
now := time.Now()
endTime := now.Add(24 * time.Hour)

bacc, origCoins := initBaseAccount()
Expand Down Expand Up @@ -319,7 +318,7 @@ func TestSpendableCoinsDelVestingAcc(t *testing.T) {
}

func TestTrackDelegationDelVestingAcc(t *testing.T) {
now := tmtime.Now()
now := time.Now()
endTime := now.Add(24 * time.Hour)

bacc, origCoins := initBaseAccount()
Expand Down Expand Up @@ -357,7 +356,7 @@ func TestTrackDelegationDelVestingAcc(t *testing.T) {
}

func TestTrackUndelegationDelVestingAcc(t *testing.T) {
now := tmtime.Now()
now := time.Now()
endTime := now.Add(24 * time.Hour)

bacc, origCoins := initBaseAccount()
Expand Down Expand Up @@ -406,7 +405,7 @@ func TestTrackUndelegationDelVestingAcc(t *testing.T) {
}

func TestGetVestedCoinsPeriodicVestingAcc(t *testing.T) {
now := tmtime.Now()
now := time.Now()
endTime := now.Add(24 * time.Hour)
periods := types.Periods{
types.Period{Length: int64(12 * 60 * 60), Amount: sdk.Coins{sdk.NewInt64Coin(feeDenom, 500), sdk.NewInt64Coin(stakeDenom, 50)}},
Expand Down Expand Up @@ -451,7 +450,7 @@ func TestGetVestedCoinsPeriodicVestingAcc(t *testing.T) {
}

func TestOverflowAndNegativeVestedCoinsPeriods(t *testing.T) {
now := tmtime.Now()
now := time.Now()
tests := []struct {
name string
periods []types.Period
Expand Down Expand Up @@ -502,7 +501,7 @@ func TestOverflowAndNegativeVestedCoinsPeriods(t *testing.T) {
}

func TestGetVestingCoinsPeriodicVestingAcc(t *testing.T) {
now := tmtime.Now()
now := time.Now()
endTime := now.Add(24 * time.Hour)
periods := types.Periods{
types.Period{Length: int64(12 * 60 * 60), Amount: sdk.Coins{sdk.NewInt64Coin(feeDenom, 500), sdk.NewInt64Coin(stakeDenom, 50)}},
Expand Down Expand Up @@ -540,7 +539,7 @@ func TestGetVestingCoinsPeriodicVestingAcc(t *testing.T) {
}

func TestSpendableCoinsPeriodicVestingAcc(t *testing.T) {
now := tmtime.Now()
now := time.Now()
endTime := now.Add(24 * time.Hour)
periods := types.Periods{
types.Period{Length: int64(12 * 60 * 60), Amount: sdk.Coins{sdk.NewInt64Coin(feeDenom, 500), sdk.NewInt64Coin(stakeDenom, 50)}},
Expand Down Expand Up @@ -568,7 +567,7 @@ func TestSpendableCoinsPeriodicVestingAcc(t *testing.T) {
}

func TestTrackDelegationPeriodicVestingAcc(t *testing.T) {
now := tmtime.Now()
now := time.Now()
endTime := now.Add(24 * time.Hour)
periods := types.Periods{
types.Period{Length: int64(12 * 60 * 60), Amount: sdk.Coins{sdk.NewInt64Coin(feeDenom, 500), sdk.NewInt64Coin(stakeDenom, 50)}},
Expand Down Expand Up @@ -630,7 +629,7 @@ func TestTrackDelegationPeriodicVestingAcc(t *testing.T) {
}

func TestTrackUndelegationPeriodicVestingAcc(t *testing.T) {
now := tmtime.Now()
now := time.Now()
endTime := now.Add(24 * time.Hour)
periods := types.Periods{
types.Period{Length: int64(12 * 60 * 60), Amount: sdk.Coins{sdk.NewInt64Coin(feeDenom, 500), sdk.NewInt64Coin(stakeDenom, 50)}},
Expand Down Expand Up @@ -691,7 +690,7 @@ func TestTrackUndelegationPeriodicVestingAcc(t *testing.T) {
}

func TestGetVestedCoinsPermLockedVestingAcc(t *testing.T) {
now := tmtime.Now()
now := time.Now()
endTime := now.Add(1000 * 24 * time.Hour)

bacc, origCoins := initBaseAccount()
Expand All @@ -708,7 +707,7 @@ func TestGetVestedCoinsPermLockedVestingAcc(t *testing.T) {
}

func TestGetVestingCoinsPermLockedVestingAcc(t *testing.T) {
now := tmtime.Now()
now := time.Now()
endTime := now.Add(1000 * 24 * time.Hour)

bacc, origCoins := initBaseAccount()
Expand All @@ -725,7 +724,7 @@ func TestGetVestingCoinsPermLockedVestingAcc(t *testing.T) {
}

func TestSpendableCoinsPermLockedVestingAcc(t *testing.T) {
now := tmtime.Now()
now := time.Now()
endTime := now.Add(1000 * 24 * time.Hour)

bacc, origCoins := initBaseAccount()
Expand All @@ -750,7 +749,7 @@ func TestSpendableCoinsPermLockedVestingAcc(t *testing.T) {
}

func TestTrackDelegationPermLockedVestingAcc(t *testing.T) {
now := tmtime.Now()
now := time.Now()
endTime := now.Add(1000 * 24 * time.Hour)

bacc, origCoins := initBaseAccount()
Expand Down Expand Up @@ -780,7 +779,7 @@ func TestTrackDelegationPermLockedVestingAcc(t *testing.T) {
}

func TestTrackUndelegationPermLockedVestingAcc(t *testing.T) {
now := tmtime.Now()
now := time.Now()
endTime := now.Add(1000 * 24 * time.Hour)

bacc, origCoins := initBaseAccount()
Expand Down
5 changes: 3 additions & 2 deletions x/authz/keeper/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import (
"testing"
"time"

cmtproto "github.com/cometbft/cometbft/proto/tendermint/types"
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/suite"

"cosmossdk.io/core/header"
"cosmossdk.io/log"
sdkmath "cosmossdk.io/math"
storetypes "cosmossdk.io/store/types"
Expand Down Expand Up @@ -46,7 +46,8 @@ func (suite *GenesisTestSuite) SetupTest() {
key := storetypes.NewKVStoreKey(keeper.StoreKey)
storeService := runtime.NewKVStoreService(key)
testCtx := testutil.DefaultContextWithDB(suite.T(), key, storetypes.NewTransientStoreKey("transient_test"))
suite.ctx = testCtx.Ctx.WithBlockHeader(cmtproto.Header{Height: 1})
suite.ctx = testCtx.Ctx.WithHeaderInfo(header.Info{Height: 1})

suite.encCfg = moduletestutil.MakeTestEncodingConfig(authzmodule.AppModuleBasic{})

// gomock initializations
Expand Down
Loading

0 comments on commit ab2a725

Please sign in to comment.