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

feat: integration test helpers #15556

Merged
merged 23 commits into from
Mar 31, 2023
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
Prev Previous commit
Next Next commit
feedback
  • Loading branch information
julienrbrt committed Mar 30, 2023
commit 35deb0ce8656915ee179c513ff42b92d30b85f83
7 changes: 0 additions & 7 deletions tests/integration/slashing/integration.go

This file was deleted.

12 changes: 9 additions & 3 deletions testutil/integration/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"gotest.tools/v3/assert"

"cosmossdk.io/log"
storetypes "cosmossdk.io/store/types"
"github.com/cosmos/cosmos-sdk/runtime"
"github.com/cosmos/cosmos-sdk/testutil/integration"
Expand All @@ -21,7 +22,6 @@ import (
func TestIntegrationTestExample(t *testing.T) {
julienrbrt marked this conversation as resolved.
Show resolved Hide resolved
// in this example we are testing the integration of the following modules:
// - mint, which directly depends on auth, bank and staking

encodingCfg := moduletestutil.MakeTestEncodingConfig(auth.AppModuleBasic{}, mint.AppModuleBasic{})
keys := storetypes.NewKVStoreKeys(authtypes.StoreKey, minttypes.StoreKey)
authority := authtypes.NewModuleAddress("gov").String()
Expand All @@ -43,17 +43,20 @@ func TestIntegrationTestExample(t *testing.T) {
mintKeeper := mintkeeper.NewKeeper(encodingCfg.Codec, keys[minttypes.StoreKey], nil, accountKeeper, nil, authtypes.FeeCollectorName, authority)
mintModule := mint.NewAppModule(encodingCfg.Codec, mintKeeper, accountKeeper, nil, nil)

integrationApp := integration.NewIntegrationApp(t, keys, authModule, mintModule)
integrationApp := integration.NewIntegrationApp(t.Name(), log.NewTestLogger(t), keys, authModule, mintModule)

// register the message and query servers
authtypes.RegisterMsgServer(integrationApp.MsgServiceRouter(), authkeeper.NewMsgServerImpl(accountKeeper))
minttypes.RegisterMsgServer(integrationApp.MsgServiceRouter(), mintkeeper.NewMsgServerImpl(mintKeeper))
minttypes.RegisterQueryServer(integrationApp.QueryHelper(), mintKeeper)

params := minttypes.DefaultParams()
params.BlocksPerYear = 10000

// now we can use the application to test an mint message
julienrbrt marked this conversation as resolved.
Show resolved Hide resolved
result, err := integrationApp.RunMsg(&minttypes.MsgUpdateParams{
Authority: authority,
Params: minttypes.DefaultParams(),
Params: params,
})
assert.NilError(t, err)
assert.Assert(t, result != nil)
Expand All @@ -62,4 +65,7 @@ func TestIntegrationTestExample(t *testing.T) {
resp := minttypes.MsgUpdateParamsResponse{}
err = encodingCfg.Codec.Unmarshal(result.Value, &resp)
assert.NilError(t, err)
julienrbrt marked this conversation as resolved.
Show resolved Hide resolved

// we can also check the state of the application
assert.DeepEqual(t, mintKeeper.GetParams(integrationApp.SDKContext()), params)
julienrbrt marked this conversation as resolved.
Show resolved Hide resolved
}
18 changes: 7 additions & 11 deletions testutil/integration/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ package integration

import (
"fmt"
"testing"

"github.com/cometbft/cometbft/abci/types"
cmtproto "github.com/cometbft/cometbft/proto/tendermint/types"
"gotest.tools/v3/assert"

"cosmossdk.io/log"
storetypes "cosmossdk.io/store/types"
Expand All @@ -23,15 +21,13 @@ import (
type App struct {
julienrbrt marked this conversation as resolved.
Show resolved Hide resolved
*baseapp.BaseApp

t *testing.T
ctx sdk.Context
logger log.Logger

queryHelper *baseapp.QueryServiceTestHelper
}

func NewIntegrationApp(t *testing.T, keys map[string]*storetypes.KVStoreKey, modules ...module.AppModuleBasic) *App {
logger := log.NewTestLogger(t)
func NewIntegrationApp(name string, logger log.Logger, keys map[string]*storetypes.KVStoreKey, modules ...module.AppModuleBasic) *App {
julienrbrt marked this conversation as resolved.
Show resolved Hide resolved
db := dbm.NewMemDB()

interfaceRegistry := codectypes.NewInterfaceRegistry()
Expand All @@ -41,7 +37,7 @@ func NewIntegrationApp(t *testing.T, keys map[string]*storetypes.KVStoreKey, mod

txConfig := authtx.NewTxConfig(codec.NewProtoCodec(interfaceRegistry), authtx.DefaultSignModes)

bApp := baseapp.NewBaseApp(t.Name(), logger, db, txConfig.TxDecoder())
bApp := baseapp.NewBaseApp(fmt.Sprintf("integration-app-%s", name), logger, db, txConfig.TxDecoder())
julienrbrt marked this conversation as resolved.
Show resolved Hide resolved
bApp.MountKVStores(keys)
bApp.SetInitChainer(func(ctx sdk.Context, req types.RequestInitChain) (types.ResponseInitChain, error) {
return types.ResponseInitChain{}, nil
Expand All @@ -51,17 +47,17 @@ func NewIntegrationApp(t *testing.T, keys map[string]*storetypes.KVStoreKey, mod
router.SetInterfaceRegistry(interfaceRegistry)
bApp.SetMsgServiceRouter(router)

assert.NilError(t, bApp.LoadLatestVersion())
if err := bApp.LoadLatestVersion(); err != nil {
panic(err)
julienrbrt marked this conversation as resolved.
Show resolved Hide resolved
}

ctx := bApp.NewContext(true, cmtproto.Header{})

return &App{
BaseApp: bApp,

t: t,
logger: logger,
ctx: ctx,

logger: logger,
ctx: ctx,
queryHelper: baseapp.NewQueryServerTestHelper(ctx, interfaceRegistry),
}
}
Expand Down