Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(testutil/integration): use only one context in integration test framework #22616

Merged
merged 7 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions client/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/testutil"
"github.com/cosmos/cosmos-sdk/runtime"
"github.com/cosmos/cosmos-sdk/testutil/integration"
"github.com/cosmos/cosmos-sdk/testutil/testdata"
"github.com/cosmos/cosmos-sdk/testutil/x/counter"
counterkeeper "github.com/cosmos/cosmos-sdk/testutil/x/counter/keeper"
Expand All @@ -38,8 +37,6 @@ func (s *IntegrationTestSuite) SetupSuite() {

logger := log.NewNopLogger()
keys := storetypes.NewKVStoreKeys(countertypes.StoreKey)
cms := integration.CreateMultiStore(keys, logger)
s.ctx = sdk.NewContext(cms, true, logger)
cfg := moduletestutil.MakeTestEncodingConfig(testutil.CodecOptions{}, counter.AppModule{})
s.cdc = cfg.Codec

Expand Down
13 changes: 3 additions & 10 deletions tests/integration/accounts/fixture_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,6 @@ func initFixture(t *testing.T, f func(ctx context.Context, msg *account_abstract
cdc := encodingCfg.Codec

logger := log.NewTestLogger(t)
cms := integration.CreateMultiStore(keys, logger)

newCtx := sdk.NewContext(cms, true, logger)

router := baseapp.NewMsgServiceRouter()
queryRouter := baseapp.NewGRPCQueryRouter()

Expand Down Expand Up @@ -169,14 +165,11 @@ func initFixture(t *testing.T, f func(ctx context.Context, msg *account_abstract
authority.String(),
)

params := banktypes.DefaultParams()
require.NoError(t, bankKeeper.SetParams(newCtx, params))

accountsModule := accounts.NewAppModule(cdc, accountsKeeper)
authModule := auth.NewAppModule(cdc, authKeeper, accountsKeeper, authsims.RandomGenesisAccounts, nil)
bankModule := bank.NewAppModule(cdc, bankKeeper, authKeeper)

integrationApp := integration.NewIntegrationApp(newCtx, logger, keys, cdc,
integrationApp := integration.NewIntegrationApp(logger, keys, cdc,
encodingCfg.InterfaceRegistry.SigningContext().AddressCodec(),
encodingCfg.InterfaceRegistry.SigningContext().ValidatorAddressCodec(),
map[string]appmodule.AppModule{
Expand All @@ -194,14 +187,14 @@ func initFixture(t *testing.T, f func(ctx context.Context, msg *account_abstract
banktypes.RegisterMsgServer(router, bankkeeper.NewMsgServerImpl(bankKeeper))

// init account
_, addr, err := accountsKeeper.Init(newCtx, "mock", []byte("system"), &gogotypes.Empty{}, nil)
_, addr, err := accountsKeeper.Init(integrationApp.Context(), "mock", []byte("system"), &gogotypes.Empty{}, nil)
require.NoError(t, err)

fixture := &fixture{
t: t,
app: integrationApp,
cdc: cdc,
ctx: newCtx,
ctx: sdk.UnwrapSDKContext(integrationApp.Context()),
authKeeper: authKeeper,
accountsKeeper: accountsKeeper,
bankKeeper: bankKeeper,
Expand Down
10 changes: 2 additions & 8 deletions tests/integration/auth/keeper/fixture_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,6 @@ func initFixture(t *testing.T, extraAccs map[string]accountstd.Interface) *fixtu
cdc := encodingCfg.Codec

logger := log.NewTestLogger(t)
cms := integration.CreateMultiStore(keys, logger)

newCtx := sdk.NewContext(cms, true, logger)

router := baseapp.NewMsgServiceRouter()
queryRouter := baseapp.NewGRPCQueryRouter()
Expand Down Expand Up @@ -109,14 +106,11 @@ func initFixture(t *testing.T, extraAccs map[string]accountstd.Interface) *fixtu
authority.String(),
)

params := banktypes.DefaultParams()
assert.NilError(t, bankKeeper.SetParams(newCtx, params))

accountsModule := accounts.NewAppModule(cdc, accountsKeeper)
authModule := auth.NewAppModule(cdc, authKeeper, accountsKeeper, authsims.RandomGenesisAccounts, nil)
bankModule := bank.NewAppModule(cdc, bankKeeper, authKeeper)

integrationApp := integration.NewIntegrationApp(newCtx, logger, keys, cdc,
integrationApp := integration.NewIntegrationApp(logger, keys, cdc,
encodingCfg.InterfaceRegistry.SigningContext().AddressCodec(),
encodingCfg.InterfaceRegistry.SigningContext().ValidatorAddressCodec(),
map[string]appmodule.AppModule{
Expand All @@ -136,7 +130,7 @@ func initFixture(t *testing.T, extraAccs map[string]accountstd.Interface) *fixtu
return &fixture{
app: integrationApp,
cdc: cdc,
ctx: newCtx,
ctx: sdk.UnwrapSDKContext(integrationApp.Context()),
accountsKeeper: accountsKeeper,
authKeeper: authKeeper,
bankKeeper: bankKeeper,
Expand Down
8 changes: 1 addition & 7 deletions tests/integration/bank/keeper/deterministic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,6 @@ func initDeterministicFixture(t *testing.T) *deterministicFixture {
cdc := encodingCfg.Codec

logger := log.NewTestLogger(t)
cms := integration.CreateMultiStore(keys, logger)

newCtx := sdk.NewContext(cms, true, logger)

authority := authtypes.NewModuleAddress("gov")

maccPerms := map[string][]string{
Expand Down Expand Up @@ -114,12 +110,10 @@ func initDeterministicFixture(t *testing.T) *deterministicFixture {
authority.String(),
)

assert.NilError(t, bankKeeper.SetParams(newCtx, banktypes.DefaultParams()))

authModule := auth.NewAppModule(cdc, accountKeeper, acctsModKeeper, authsims.RandomGenesisAccounts, nil)
bankModule := bank.NewAppModule(cdc, bankKeeper, accountKeeper)

integrationApp := integration.NewIntegrationApp(newCtx, logger, keys, cdc,
integrationApp := integration.NewIntegrationApp(logger, keys, cdc,
encodingCfg.InterfaceRegistry.SigningContext().AddressCodec(),
encodingCfg.InterfaceRegistry.SigningContext().ValidatorAddressCodec(),
map[string]appmodule.AppModule{
Expand Down
41 changes: 16 additions & 25 deletions tests/integration/distribution/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,6 @@ func initFixture(t *testing.T) *fixture {
cdc := encodingCfg.Codec

logger := log.NewTestLogger(t)
cms := integration.CreateMultiStore(keys, logger)

newCtx := sdk.NewContext(cms, true, logger)

authority := authtypes.NewModuleAddress("gov")

maccPerms := map[string][]string{
Expand Down Expand Up @@ -128,15 +124,12 @@ func initFixture(t *testing.T) *fixture {
authority.String(),
)

assert.NilError(t, bankKeeper.SetParams(newCtx, banktypes.DefaultParams()))

msgRouter := baseapp.NewMsgServiceRouter()
grpcRouter := baseapp.NewGRPCQueryRouter()
cometService := runtime.NewContextAwareCometInfoService()

consensusParamsKeeper := consensusparamkeeper.NewKeeper(cdc, runtime.NewEnvironment(runtime.NewKVStoreService(keys[consensustypes.StoreKey]), log.NewNopLogger(), runtime.EnvWithQueryRouterService(grpcRouter), runtime.EnvWithMsgRouterService(msgRouter)), authtypes.NewModuleAddress("gov").String())
stakingKeeper := stakingkeeper.NewKeeper(cdc, runtime.NewEnvironment(runtime.NewKVStoreService(keys[stakingtypes.StoreKey]), log.NewNopLogger(), runtime.EnvWithQueryRouterService(grpcRouter), runtime.EnvWithMsgRouterService(msgRouter)), accountKeeper, bankKeeper, consensusParamsKeeper, authority.String(), addresscodec.NewBech32Codec(sdk.Bech32PrefixValAddr), addresscodec.NewBech32Codec(sdk.Bech32PrefixConsAddr), cometService)
require.NoError(t, stakingKeeper.Params.Set(newCtx, stakingtypes.DefaultParams()))

poolKeeper := poolkeeper.NewKeeper(cdc, runtime.NewEnvironment(runtime.NewKVStoreService(keys[pooltypes.StoreKey]), log.NewNopLogger()), accountKeeper, bankKeeper, authority.String())

Expand All @@ -155,23 +148,7 @@ func initFixture(t *testing.T) *fixture {
valAddr := sdk.ValAddress(addr)
valConsAddr := sdk.ConsAddress(valConsPk0.Address())

// set proposer and vote infos
ctx := newCtx.WithProposer(valConsAddr).WithCometInfo(comet.Info{
LastCommit: comet.CommitInfo{
Votes: []comet.VoteInfo{
{
Validator: comet.Validator{
Address: valAddr,
Power: 100,
},
BlockIDFlag: comet.BlockIDFlagCommit,
},
},
},
ProposerAddress: valConsAddr,
})

integrationApp := integration.NewIntegrationApp(ctx, logger, keys, cdc,
integrationApp := integration.NewIntegrationApp(logger, keys, cdc,
encodingCfg.InterfaceRegistry.SigningContext().AddressCodec(),
encodingCfg.InterfaceRegistry.SigningContext().ValidatorAddressCodec(),
map[string]appmodule.AppModule{
Expand All @@ -186,7 +163,21 @@ func initFixture(t *testing.T) *fixture {
grpcRouter,
)

sdkCtx := sdk.UnwrapSDKContext(integrationApp.Context())
// set proposer and vote infos
sdkCtx := sdk.UnwrapSDKContext(integrationApp.Context()).WithProposer(valConsAddr).WithCometInfo(comet.Info{
LastCommit: comet.CommitInfo{
Votes: []comet.VoteInfo{
{
Validator: comet.Validator{
Address: valAddr,
Power: 100,
},
BlockIDFlag: comet.BlockIDFlagCommit,
},
},
},
ProposerAddress: valConsAddr,
})

// Register MsgServer and QueryServer
distrtypes.RegisterMsgServer(integrationApp.MsgServiceRouter(), distrkeeper.NewMsgServerImpl(distrKeeper))
Expand Down
8 changes: 1 addition & 7 deletions tests/integration/evidence/keeper/infraction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,6 @@ func initFixture(tb testing.TB) *fixture {
grpcQueryRouter := baseapp.NewGRPCQueryRouter()

logger := log.NewTestLogger(tb)
cms := integration.CreateMultiStore(keys, logger)

newCtx := sdk.NewContext(cms, true, logger)

authority := authtypes.NewModuleAddress("gov")

// gomock initializations
Expand Down Expand Up @@ -144,8 +140,6 @@ func initFixture(tb testing.TB) *fixture {
authority.String(),
)

assert.NilError(tb, bankKeeper.SetParams(newCtx, banktypes.DefaultParams()))

consensusParamsKeeper := consensusparamkeeper.NewKeeper(cdc, runtime.NewEnvironment(runtime.NewKVStoreService(keys[consensusparamtypes.StoreKey]), log.NewNopLogger(), runtime.EnvWithQueryRouterService(grpcQueryRouter), runtime.EnvWithMsgRouterService(msgRouter)), authtypes.NewModuleAddress("gov").String())

stakingKeeper := stakingkeeper.NewKeeper(cdc, runtime.NewEnvironment(runtime.NewKVStoreService(keys[stakingtypes.StoreKey]), log.NewNopLogger(), runtime.EnvWithQueryRouterService(grpcQueryRouter), runtime.EnvWithMsgRouterService(msgRouter)), accountKeeper, bankKeeper, consensusParamsKeeper, authority.String(), addresscodec.NewBech32Codec(sdk.Bech32PrefixValAddr), addresscodec.NewBech32Codec(sdk.Bech32PrefixConsAddr), runtime.NewContextAwareCometInfoService())
Expand All @@ -166,7 +160,7 @@ func initFixture(tb testing.TB) *fixture {
evidenceModule := evidence.NewAppModule(cdc, *evidenceKeeper, cometInfoService)
consensusModule := consensus.NewAppModule(cdc, consensusParamsKeeper)

integrationApp := integration.NewIntegrationApp(newCtx, logger, keys, cdc,
integrationApp := integration.NewIntegrationApp(logger, keys, cdc,
encodingCfg.InterfaceRegistry.SigningContext().AddressCodec(),
encodingCfg.InterfaceRegistry.SigningContext().ValidatorAddressCodec(),
map[string]appmodule.AppModule{
Expand Down
8 changes: 0 additions & 8 deletions tests/integration/example/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@ func Example() {
// replace the logger by testing values in a real test case (e.g. log.NewTestLogger(t))
logger := log.NewNopLogger()

cms := integration.CreateMultiStore(keys, logger)
newCtx := sdk.NewContext(cms, true, logger)

// gomock initializations
ctrl := gomock.NewController(&testing.T{})
acctsModKeeper := authtestutil.NewMockAccountsModKeeper(ctrl)
Expand Down Expand Up @@ -79,7 +76,6 @@ func Example() {

// create the application and register all the modules from the previous step
integrationApp := integration.NewIntegrationApp(
newCtx,
logger,
keys,
encodingCfg.Codec,
Expand Down Expand Up @@ -149,9 +145,6 @@ func Example_oneModule() {
// replace the logger by testing values in a real test case (e.g. log.NewTestLogger(t))
logger := log.NewLogger(io.Discard)

cms := integration.CreateMultiStore(keys, logger)
newCtx := sdk.NewContext(cms, true, logger)

// gomock initializations
ctrl := gomock.NewController(&testing.T{})
acctsModKeeper := authtestutil.NewMockAccountsModKeeper(ctrl)
Expand All @@ -178,7 +171,6 @@ func Example_oneModule() {

// create the application and register all the modules from the previous step
integrationApp := integration.NewIntegrationApp(
newCtx,
logger,
keys,
encodingCfg.Codec,
Expand Down
2 changes: 0 additions & 2 deletions tests/integration/gov/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ func TestLegacyGRPCQueryTally(t *testing.T) {
t.Parallel()

f := initFixture(t)

ctx, queryClient := f.ctx, f.legacyQueryClient

addrs, _ := createValidators(t, f, []int64{5, 5, 5})

var (
Expand Down
16 changes: 1 addition & 15 deletions tests/integration/gov/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"testing"

"go.uber.org/mock/gomock"
"gotest.tools/v3/assert"

"cosmossdk.io/core/appmodule"
"cosmossdk.io/log"
Expand Down Expand Up @@ -63,10 +62,6 @@ func initFixture(tb testing.TB) *fixture {
cdc := encodingCfg.Codec

logger := log.NewTestLogger(tb)
cms := integration.CreateMultiStore(keys, logger)

newCtx := sdk.NewContext(cms, true, logger)

authority := authtypes.NewModuleAddress(types.ModuleName)

maccPerms := map[string][]string{
Expand Down Expand Up @@ -111,8 +106,6 @@ func initFixture(tb testing.TB) *fixture {
authority.String(),
)

assert.NilError(tb, bankKeeper.SetParams(newCtx, banktypes.DefaultParams()))

router := baseapp.NewMsgServiceRouter()
queryRouter := baseapp.NewGRPCQueryRouter()
consensusParamsKeeper := consensusparamkeeper.NewKeeper(cdc, runtime.NewEnvironment(runtime.NewKVStoreService(keys[consensusparamtypes.StoreKey]), log.NewNopLogger(), runtime.EnvWithQueryRouterService(queryRouter), runtime.EnvWithMsgRouterService(router)), authtypes.NewModuleAddress("gov").String())
Expand All @@ -121,10 +114,6 @@ func initFixture(tb testing.TB) *fixture {

poolKeeper := poolkeeper.NewKeeper(cdc, runtime.NewEnvironment(runtime.NewKVStoreService(keys[pooltypes.StoreKey]), log.NewNopLogger()), accountKeeper, bankKeeper, authority.String())

// set default staking params
err := stakingKeeper.Params.Set(newCtx, stakingtypes.DefaultParams())
assert.NilError(tb, err)

// Create MsgServiceRouter, but don't populate it before creating the gov
// keeper.
router.SetInterfaceRegistry(cdc.InterfaceRegistry())
Expand All @@ -140,20 +129,17 @@ func initFixture(tb testing.TB) *fixture {
keeper.DefaultConfig(),
authority.String(),
)
assert.NilError(tb, govKeeper.ProposalID.Set(newCtx, 1))
govRouter := v1beta1.NewRouter()
govRouter.AddRoute(types.RouterKey, v1beta1.ProposalHandler)
govKeeper.SetLegacyRouter(govRouter)
err = govKeeper.Params.Set(newCtx, v1.DefaultParams())
assert.NilError(tb, err)

authModule := auth.NewAppModule(cdc, accountKeeper, acctsModKeeper, authsims.RandomGenesisAccounts, nil)
bankModule := bank.NewAppModule(cdc, bankKeeper, accountKeeper)
stakingModule := staking.NewAppModule(cdc, stakingKeeper)
govModule := gov.NewAppModule(cdc, govKeeper, accountKeeper, bankKeeper, poolKeeper)
consensusModule := consensus.NewAppModule(cdc, consensusParamsKeeper)

integrationApp := integration.NewIntegrationApp(newCtx, logger, keys, cdc,
integrationApp := integration.NewIntegrationApp(logger, keys, cdc,
encodingCfg.InterfaceRegistry.SigningContext().AddressCodec(),
encodingCfg.InterfaceRegistry.SigningContext().ValidatorAddressCodec(),
map[string]appmodule.AppModule{
Expand Down
8 changes: 1 addition & 7 deletions tests/integration/slashing/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,6 @@ func initFixture(tb testing.TB) *fixture {
cdc := encodingCfg.Codec

logger := log.NewTestLogger(tb)
cms := integration.CreateMultiStore(keys, logger)

newCtx := sdk.NewContext(cms, true, logger)

authority := authtypes.NewModuleAddress("gov")

maccPerms := map[string][]string{
Expand Down Expand Up @@ -115,8 +111,6 @@ func initFixture(tb testing.TB) *fixture {
authority.String(),
)

assert.NilError(tb, bankKeeper.SetParams(newCtx, banktypes.DefaultParams()))

cometInfoService := runtime.NewContextAwareCometInfoService()

consensusParamsKeeper := consensusparamkeeper.NewKeeper(cdc, runtime.NewEnvironment(runtime.NewKVStoreService(keys[consensustypes.StoreKey]), log.NewNopLogger(), runtime.EnvWithQueryRouterService(queryRouter), runtime.EnvWithMsgRouterService(msgRouter)), authtypes.NewModuleAddress("gov").String())
Expand All @@ -130,7 +124,7 @@ func initFixture(tb testing.TB) *fixture {
slashingModule := slashing.NewAppModule(cdc, slashingKeeper, accountKeeper, bankKeeper, stakingKeeper, cdc.InterfaceRegistry(), cometInfoService)
consensusModule := consensus.NewAppModule(cdc, consensusParamsKeeper)

integrationApp := integration.NewIntegrationApp(newCtx, logger, keys, cdc,
integrationApp := integration.NewIntegrationApp(logger, keys, cdc,
encodingCfg.InterfaceRegistry.SigningContext().AddressCodec(),
encodingCfg.InterfaceRegistry.SigningContext().ValidatorAddressCodec(),
map[string]appmodule.AppModule{
Expand Down
8 changes: 1 addition & 7 deletions tests/integration/staking/keeper/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,6 @@ func initFixture(tb testing.TB) *fixture {
queryRouter := baseapp.NewGRPCQueryRouter()

logger := log.NewTestLogger(tb)
cms := integration.CreateMultiStore(keys, logger)

newCtx := sdk.NewContext(cms, true, logger)

authority := authtypes.NewModuleAddress("gov")

maccPerms := map[string][]string{
Expand Down Expand Up @@ -162,8 +158,6 @@ func initFixture(tb testing.TB) *fixture {
authority.String(),
)

assert.NilError(tb, bankKeeper.SetParams(newCtx, banktypes.DefaultParams()))

consensusParamsKeeper := consensusparamkeeper.NewKeeper(cdc, runtime.NewEnvironment(runtime.NewKVStoreService(keys[consensustypes.StoreKey]), log.NewNopLogger()), authtypes.NewModuleAddress("gov").String())

stakingKeeper := stakingkeeper.NewKeeper(cdc, runtime.NewEnvironment(runtime.NewKVStoreService(keys[types.StoreKey]), log.NewNopLogger(), runtime.EnvWithQueryRouterService(queryRouter), runtime.EnvWithMsgRouterService(msgRouter)), accountKeeper, bankKeeper, consensusParamsKeeper, authority.String(), addresscodec.NewBech32Codec(sdk.Bech32PrefixValAddr), addresscodec.NewBech32Codec(sdk.Bech32PrefixConsAddr), runtime.NewContextAwareCometInfoService())
Expand All @@ -173,7 +167,7 @@ func initFixture(tb testing.TB) *fixture {
stakingModule := staking.NewAppModule(cdc, stakingKeeper)
consensusModule := consensus.NewAppModule(cdc, consensusParamsKeeper)

integrationApp := integration.NewIntegrationApp(newCtx, logger, keys, cdc,
integrationApp := integration.NewIntegrationApp(logger, keys, cdc,
encodingCfg.InterfaceRegistry.SigningContext().AddressCodec(),
encodingCfg.InterfaceRegistry.SigningContext().ValidatorAddressCodec(),
map[string]appmodule.AppModule{
Expand Down
Loading
Loading