refactor: remove simapp from client/server tests (#12676)

This commit is contained in:
Matt Kocubinski 2022-07-21 15:01:23 -05:00 committed by GitHub
parent 71dc827c72
commit 5e1ff06821
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 399 additions and 170 deletions

View File

@ -2,7 +2,6 @@ package client_test
import (
"bytes"
"context"
"encoding/json"
"os"
"strings"
@ -17,9 +16,8 @@ import (
"github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/crypto/hd"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
"github.com/cosmos/cosmos-sdk/simapp"
"github.com/cosmos/cosmos-sdk/testutil/network"
"github.com/cosmos/cosmos-sdk/testutil/testdata"
"github.com/cosmos/cosmos-sdk/types/module/testutil"
)
func TestMain(m *testing.M) {
@ -145,22 +143,8 @@ x: "10"
`, buf.String())
}
func TestCLIQueryConn(t *testing.T) {
cfg := network.DefaultConfig(simapp.NewTestNetworkFixture)
cfg.NumValidators = 1
n, err := network.New(t, t.TempDir(), cfg)
require.NoError(t, err)
defer n.Cleanup()
testClient := testdata.NewQueryClient(n.Validators[0].ClientCtx)
res, err := testClient.Echo(context.Background(), &testdata.EchoRequest{Message: "hello"})
require.NoError(t, err)
require.Equal(t, "hello", res.Message)
}
func TestGetFromFields(t *testing.T) {
cfg := network.DefaultConfig(simapp.NewTestNetworkFixture)
cfg := testutil.MakeTestEncodingConfig()
path := hd.CreateHDPath(118, 0, 0).String()
testCases := []struct {

View File

@ -1,83 +1,131 @@
//go:build norace
// +build norace
package client_test
import (
"context"
"fmt"
"testing"
"github.com/stretchr/testify/suite"
abci "github.com/tendermint/tendermint/abci/types"
tmjson "github.com/tendermint/tendermint/libs/json"
"github.com/tendermint/tendermint/libs/log"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
dbm "github.com/tendermint/tm-db"
"google.golang.org/grpc"
"google.golang.org/grpc/metadata"
"github.com/cosmos/cosmos-sdk/simapp"
"github.com/cosmos/cosmos-sdk/testutil/network"
"cosmossdk.io/depinject"
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
"github.com/cosmos/cosmos-sdk/runtime"
"github.com/cosmos/cosmos-sdk/testutil/sims"
"github.com/cosmos/cosmos-sdk/testutil/testdata"
sdk "github.com/cosmos/cosmos-sdk/types"
grpctypes "github.com/cosmos/cosmos-sdk/types/grpc"
"github.com/cosmos/cosmos-sdk/x/auth/testutil"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
"github.com/cosmos/cosmos-sdk/x/bank/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
)
type IntegrationTestSuite struct {
suite.Suite
network *network.Network
ctx sdk.Context
genesisAccount *authtypes.BaseAccount
bankClient types.QueryClient
testClient testdata.QueryClient
genesisAccountBalance int64
}
func (s *IntegrationTestSuite) SetupSuite() {
s.T().Log("setting up integration test suite")
var (
interfaceRegistry codectypes.InterfaceRegistry
bankKeeper bankkeeper.BaseKeeper
appBuilder *runtime.AppBuilder
cdc codec.Codec
)
var err error
s.network, err = network.New(s.T(), s.T().TempDir(), network.DefaultConfig(simapp.NewTestNetworkFixture))
s.Require().NoError(err)
// TODO duplicated from testutils/sims/app_helpers.go
// need more composable startup options for simapp, this test needed a handle to the closed over genesis account
// to query balances
err := depinject.Inject(testutil.AppConfig, &interfaceRegistry, &bankKeeper, &appBuilder, &cdc)
s.NoError(err)
_, err = s.network.WaitForHeight(2)
s.Require().NoError(err)
app := appBuilder.Build(log.NewNopLogger(), dbm.NewMemDB(), nil)
err = app.Load(true)
s.NoError(err)
valSet, err := sims.CreateRandomValidatorSet()
s.NoError(err)
// generate genesis account
s.genesisAccountBalance = 100000000000000
senderPrivKey := secp256k1.GenPrivKey()
acc := authtypes.NewBaseAccount(senderPrivKey.PubKey().Address().Bytes(), senderPrivKey.PubKey(), 0, 0)
balance := banktypes.Balance{
Address: acc.GetAddress().String(),
Coins: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(s.genesisAccountBalance))),
}
genesisState, err := sims.GenesisStateWithValSet(cdc, appBuilder.DefaultGenesis(), valSet, []authtypes.GenesisAccount{acc}, balance)
s.NoError(err)
stateBytes, err := tmjson.MarshalIndent(genesisState, "", " ")
s.NoError(err)
// init chain will set the validator set and initialize the genesis accounts
app.InitChain(
abci.RequestInitChain{
Validators: []abci.ValidatorUpdate{},
ConsensusParams: sims.DefaultConsensusParams,
AppStateBytes: stateBytes,
},
)
app.Commit()
app.BeginBlock(abci.RequestBeginBlock{Header: tmproto.Header{
Height: app.LastBlockHeight() + 1,
AppHash: app.LastCommitID().Hash,
ValidatorsHash: valSet.Hash(),
NextValidatorsHash: valSet.Hash(),
}})
// end of app init
s.ctx = app.BaseApp.NewContext(false, tmproto.Header{})
queryHelper := baseapp.NewQueryServerTestHelper(s.ctx, interfaceRegistry)
types.RegisterQueryServer(queryHelper, bankKeeper)
testdata.RegisterQueryServer(queryHelper, testdata.QueryImpl{})
s.bankClient = types.NewQueryClient(queryHelper)
s.testClient = testdata.NewQueryClient(queryHelper)
s.genesisAccount = acc
}
func (s *IntegrationTestSuite) TearDownSuite() {
s.T().Log("tearing down integration test suite")
s.network.Cleanup()
}
func (s *IntegrationTestSuite) TestGRPCQuery() {
val0 := s.network.Validators[0]
denom := sdk.DefaultBondDenom
// gRPC query to test service should work
testClient := testdata.NewQueryClient(val0.ClientCtx)
testRes, err := testClient.Echo(context.Background(), &testdata.EchoRequest{Message: "hello"})
testRes, err := s.testClient.Echo(context.Background(), &testdata.EchoRequest{Message: "hello"})
s.Require().NoError(err)
s.Require().Equal("hello", testRes.Message)
// gRPC query to bank service should work
denom := fmt.Sprintf("%stoken", val0.Moniker)
bankClient := banktypes.NewQueryClient(val0.ClientCtx)
var header metadata.MD
bankRes, err := bankClient.Balance(
res, err := s.bankClient.Balance(
context.Background(),
&banktypes.QueryBalanceRequest{Address: val0.Address.String(), Denom: denom},
&banktypes.QueryBalanceRequest{Address: s.genesisAccount.GetAddress().String(), Denom: denom},
grpc.Header(&header), // Also fetch grpc header
)
s.Require().NoError(err)
s.Require().Equal(
sdk.NewCoin(denom, s.network.Config.AccountTokens),
*bankRes.GetBalance(),
)
blockHeight := header.Get(grpctypes.GRPCBlockHeightHeader)
s.Require().NotEmpty(blockHeight[0]) // Should contain the block height
// Request metadata should work
val0.ClientCtx = val0.ClientCtx.WithHeight(1) // We set clientCtx to height 1
bankClient = banktypes.NewQueryClient(val0.ClientCtx)
bankRes, err = bankClient.Balance(
context.Background(),
&banktypes.QueryBalanceRequest{Address: val0.Address.String(), Denom: denom},
grpc.Header(&header),
)
blockHeight = header.Get(grpctypes.GRPCBlockHeightHeader)
s.Require().Equal([]string{"1"}, blockHeight)
bal := res.GetBalance()
s.Equal(sdk.NewCoin(denom, sdk.NewInt(s.genesisAccountBalance)), *bal)
}
func TestIntegrationTestSuite(t *testing.T) {

View File

@ -1,63 +0,0 @@
//go:build norace
// +build norace
package client_test
import (
"fmt"
abci "github.com/tendermint/tendermint/abci/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
)
func (s *IntegrationTestSuite) TestQueryABCIHeight() {
testCases := []struct {
name string
reqHeight int64
ctxHeight int64
expHeight int64
}{
{
name: "non zero request height",
reqHeight: 3,
ctxHeight: 1, // query at height 1 or 2 would cause an error
expHeight: 3,
},
{
name: "empty request height - use context height",
reqHeight: 0,
ctxHeight: 3,
expHeight: 3,
},
{
name: "empty request height and context height - use latest height",
reqHeight: 0,
ctxHeight: 0,
expHeight: 4,
},
}
for _, tc := range testCases {
s.Run(tc.name, func() {
s.network.WaitForHeight(tc.expHeight)
val := s.network.Validators[0]
clientCtx := val.ClientCtx
clientCtx = clientCtx.WithHeight(tc.ctxHeight)
req := abci.RequestQuery{
Path: fmt.Sprintf("store/%s/key", banktypes.StoreKey),
Height: tc.reqHeight,
Data: banktypes.CreateAccountBalancesPrefix(val.Address),
Prove: true,
}
res, err := clientCtx.QueryABCI(req)
s.Require().NoError(err)
s.Require().Equal(tc.expHeight, res.Height)
})
}
}

View File

@ -1,15 +1,24 @@
//go:build norace
// +build norace
package rpc_test
import (
"context"
"fmt"
"testing"
"github.com/stretchr/testify/suite"
abci "github.com/tendermint/tendermint/abci/types"
"google.golang.org/grpc"
"google.golang.org/grpc/metadata"
"github.com/cosmos/cosmos-sdk/client/rpc"
"github.com/cosmos/cosmos-sdk/simapp"
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
"github.com/cosmos/cosmos-sdk/testutil/network"
"github.com/cosmos/cosmos-sdk/testutil/testdata"
grpctypes "github.com/cosmos/cosmos-sdk/types/grpc"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
)
type IntegrationTestSuite struct {
@ -21,8 +30,11 @@ type IntegrationTestSuite struct {
func (s *IntegrationTestSuite) SetupSuite() {
s.T().Log("setting up integration test suite")
var err error
s.network, err = network.New(s.T(), s.T().TempDir(), network.DefaultConfig(simapp.NewTestNetworkFixture))
cfg, err := network.DefaultConfigWithAppConfig(network.MinimumAppConfig())
s.NoError(err)
s.network, err = network.New(s.T(), s.T().TempDir(), cfg)
s.Require().NoError(err)
s.Require().NoError(s.network.WaitForNextBlock())
@ -44,6 +56,70 @@ func (s *IntegrationTestSuite) TestStatusCommand() {
s.Require().Contains(out.String(), fmt.Sprintf("\"moniker\":\"%s\"", val0.Moniker))
}
func (s *IntegrationTestSuite) TestCLIQueryConn() {
var header metadata.MD
testClient := testdata.NewQueryClient(s.network.Validators[0].ClientCtx)
res, err := testClient.Echo(context.Background(), &testdata.EchoRequest{Message: "hello"}, grpc.Header(&header))
s.NoError(err)
blockHeight := header.Get(grpctypes.GRPCBlockHeightHeader)
s.Require().Equal([]string{"1"}, blockHeight)
s.Equal("hello", res.Message)
}
func (s *IntegrationTestSuite) TestQueryABCIHeight() {
testCases := []struct {
name string
reqHeight int64
ctxHeight int64
expHeight int64
}{
{
name: "non zero request height",
reqHeight: 3,
ctxHeight: 1, // query at height 1 or 2 would cause an error
expHeight: 3,
},
{
name: "empty request height - use context height",
reqHeight: 0,
ctxHeight: 3,
expHeight: 3,
},
{
name: "empty request height and context height - use latest height",
reqHeight: 0,
ctxHeight: 0,
expHeight: 4,
},
}
for _, tc := range testCases {
s.Run(tc.name, func() {
s.network.WaitForHeight(tc.expHeight)
val := s.network.Validators[0]
clientCtx := val.ClientCtx
clientCtx = clientCtx.WithHeight(tc.ctxHeight)
req := abci.RequestQuery{
Path: fmt.Sprintf("store/%s/key", banktypes.StoreKey),
Height: tc.reqHeight,
Data: banktypes.CreateAccountBalancesPrefix(val.Address),
Prove: true,
}
res, err := clientCtx.QueryABCI(req)
s.Require().NoError(err)
s.Require().Equal(tc.expHeight, res.Height)
})
}
}
func TestIntegrationTestSuite(t *testing.T) {
suite.Run(t, new(IntegrationTestSuite))
}

View File

@ -21,9 +21,14 @@ import (
"github.com/cosmos/cosmos-sdk/client/grpc/tmservice"
"github.com/cosmos/cosmos-sdk/codec"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
"github.com/cosmos/cosmos-sdk/simapp"
"github.com/cosmos/cosmos-sdk/testutil/network"
_ "github.com/cosmos/cosmos-sdk/x/auth"
_ "github.com/cosmos/cosmos-sdk/x/auth/tx/module"
_ "github.com/cosmos/cosmos-sdk/x/bank"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
_ "github.com/cosmos/cosmos-sdk/x/genutil"
_ "github.com/cosmos/cosmos-sdk/x/params"
_ "github.com/cosmos/cosmos-sdk/x/staking"
)
// https://github.com/improbable-eng/grpc-web/blob/master/go/grpcweb/wrapper_test.go used as a reference
@ -42,11 +47,12 @@ type GRPCWebTestSuite struct {
func (s *GRPCWebTestSuite) SetupSuite() {
s.T().Log("setting up integration test suite")
cfg := network.DefaultConfig(simapp.NewTestNetworkFixture)
cfg, err := network.DefaultConfigWithAppConfig(network.MinimumAppConfig())
s.NoError(err)
cfg.NumValidators = 1
s.cfg = cfg
var err error
s.network, err = network.New(s.T(), s.T().TempDir(), s.cfg)
s.Require().NoError(err)

View File

@ -9,13 +9,13 @@ import (
"testing"
"time"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/jhump/protoreflect/grpcreflect"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
"github.com/cosmos/cosmos-sdk/codec"
"google.golang.org/grpc"
"google.golang.org/grpc/metadata"
rpb "google.golang.org/grpc/reflection/grpc_reflection_v1alpha"
@ -24,7 +24,6 @@ import (
reflectionv1 "github.com/cosmos/cosmos-sdk/client/grpc/reflection"
clienttx "github.com/cosmos/cosmos-sdk/client/tx"
reflectionv2 "github.com/cosmos/cosmos-sdk/server/grpc/reflection/v2alpha1"
"github.com/cosmos/cosmos-sdk/simapp"
"github.com/cosmos/cosmos-sdk/testutil/network"
"github.com/cosmos/cosmos-sdk/testutil/testdata"
sdk "github.com/cosmos/cosmos-sdk/types"
@ -40,19 +39,19 @@ import (
type IntegrationTestSuite struct {
suite.Suite
app *simapp.SimApp
cfg network.Config
network *network.Network
conn *grpc.ClientConn
}
func (s *IntegrationTestSuite) SetupSuite() {
var err error
s.T().Log("setting up integration test suite")
s.app = simapp.Setup(s.T(), false)
s.cfg = network.DefaultConfig(simapp.NewTestNetworkFixture)
s.cfg, err = network.DefaultConfigWithAppConfig(network.MinimumAppConfig())
s.NoError(err)
s.cfg.NumValidators = 1
var err error
s.network, err = network.New(s.T(), s.T().TempDir(), s.cfg)
s.Require().NoError(err)
@ -63,7 +62,7 @@ func (s *IntegrationTestSuite) SetupSuite() {
s.conn, err = grpc.Dial(
val0.AppConfig.GRPC.Address,
grpc.WithInsecure(), // Or else we get "no transport security set"
grpc.WithDefaultCallOptions(grpc.ForceCodec(codec.NewProtoCodec(s.app.InterfaceRegistry()).GRPCCodec())),
grpc.WithDefaultCallOptions(grpc.ForceCodec(codec.NewProtoCodec(s.cfg.InterfaceRegistry).GRPCCodec())),
)
s.Require().NoError(err)
}
@ -226,7 +225,7 @@ func (s *IntegrationTestSuite) TestGRPCServerInvalidHeaderHeights() {
// TestGRPCUnpacker - tests the grpc endpoint for Validator and using the interface registry unpack and extract the
// ConsAddr. (ref: https://github.com/cosmos/cosmos-sdk/issues/8045)
func (s *IntegrationTestSuite) TestGRPCUnpacker() {
ir := s.app.InterfaceRegistry()
ir := s.cfg.InterfaceRegistry
queryClient := stakingtypes.NewQueryClient(s.conn)
validator, err := queryClient.Validator(context.Background(),
&stakingtypes.QueryValidatorRequest{ValidatorAddr: s.network.Validators[0].ValAddress.String()})

View File

@ -19,8 +19,9 @@ import (
"github.com/cosmos/cosmos-sdk/server"
"github.com/cosmos/cosmos-sdk/server/config"
servertypes "github.com/cosmos/cosmos-sdk/server/types"
"github.com/cosmos/cosmos-sdk/simapp"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/types/module/testutil"
genutilcli "github.com/cosmos/cosmos-sdk/x/genutil/client/cli"
)
@ -413,14 +414,14 @@ func TestEmptyMinGasPrices(t *testing.T) {
tempDir := t.TempDir()
err := os.Mkdir(filepath.Join(tempDir, "config"), os.ModePerm)
require.NoError(t, err)
encCfg := simapp.MakeTestEncodingConfig()
encCfg := testutil.MakeTestEncodingConfig()
// Run InitCmd to create necessary config files.
clientCtx := client.Context{}.WithHomeDir(tempDir).WithCodec(encCfg.Codec)
serverCtx := server.NewDefaultContext()
ctx := context.WithValue(context.Background(), server.ServerContextKey, serverCtx)
ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx)
cmd := genutilcli.InitCmd(simapp.ModuleBasics, tempDir)
cmd := genutilcli.InitCmd(module.NewBasicManager(), tempDir)
cmd.SetArgs([]string{"appnode-test"})
err = cmd.ExecuteContext(ctx)
require.NoError(t, err)

View File

@ -1,3 +1,6 @@
//go:build norace
// +build norace
package tmservice_test
import (
@ -10,12 +13,13 @@ import (
"github.com/cosmos/cosmos-sdk/client/grpc/tmservice"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
"github.com/cosmos/cosmos-sdk/simapp"
"github.com/cosmos/cosmos-sdk/testutil/configurator"
"github.com/cosmos/cosmos-sdk/testutil/network"
"github.com/cosmos/cosmos-sdk/testutil/rest"
"github.com/cosmos/cosmos-sdk/types"
qtypes "github.com/cosmos/cosmos-sdk/types/query"
"github.com/cosmos/cosmos-sdk/version"
_ "github.com/cosmos/cosmos-sdk/x/gov"
)
type IntegrationTestSuite struct {
@ -27,7 +31,7 @@ type IntegrationTestSuite struct {
}
func TestIntegrationTestSuite(t *testing.T) {
t.Skip() // to be re-enabled in https://github.com/cosmos/cosmos-sdk/pull/12482/
//t.Skip() // to be re-enabled in https://github.com/cosmos/cosmos-sdk/pull/12482/
suite.Run(t, new(IntegrationTestSuite))
}
@ -35,12 +39,21 @@ func TestIntegrationTestSuite(t *testing.T) {
func (s *IntegrationTestSuite) SetupSuite() {
s.T().Log("setting up integration test suite")
cfg := network.DefaultConfig(simapp.NewTestNetworkFixture)
appConfig := configurator.NewAppConfig(
configurator.AuthModule(),
configurator.ParamsModule(),
configurator.BankModule(),
configurator.GenutilModule(),
configurator.StakingModule(),
configurator.GovModule(),
configurator.TxModule())
cfg, err := network.DefaultConfigWithAppConfig(appConfig)
s.NoError(err)
cfg.NumValidators = 1
s.cfg = cfg
var err error
s.network, err = network.New(s.T(), s.T().TempDir(), s.cfg)
s.Require().NoError(err)

View File

@ -5,32 +5,91 @@ import (
appv1alpha1 "cosmossdk.io/api/cosmos/app/v1alpha1"
authmodulev1 "cosmossdk.io/api/cosmos/auth/module/v1"
bankmodulev1 "cosmossdk.io/api/cosmos/bank/module/v1"
distrmodulev1 "cosmossdk.io/api/cosmos/distribution/module/v1"
feegrantmodulev1 "cosmossdk.io/api/cosmos/feegrant/module/v1"
genutilmodulev1 "cosmossdk.io/api/cosmos/genutil/module/v1"
govmodulev1 "cosmossdk.io/api/cosmos/gov/module/v1"
paramsmodulev1 "cosmossdk.io/api/cosmos/params/module/v1"
stakingmodulev1 "cosmossdk.io/api/cosmos/staking/module/v1"
txmodulev1 "cosmossdk.io/api/cosmos/tx/module/v1"
vestingmodulev1 "cosmossdk.io/api/cosmos/vesting/module/v1"
"cosmossdk.io/core/appconfig"
"cosmossdk.io/depinject"
)
var beginBlockOrder = []string{
"upgrade",
"capability",
"mint",
"distribution",
"slashing",
"evidence",
"staking",
"auth",
"bank",
"gov",
"crisis",
"genutil",
"authz",
"feegrant",
"nft",
"group",
"params",
"vesting",
}
var endBlockersOrder = []string{
"crisis",
"gov",
"staking",
"capability",
"auth",
"bank",
"distribution",
"slashing",
"mint",
"genutil",
"evidence",
"authz",
"feegrant",
"nft",
"group",
"params",
"upgrade",
"vesting",
}
type ModuleOption func(options map[string]*appv1alpha1.ModuleConfig)
var initGenesisOrder = []string{
"capability",
"auth",
"bank",
"distribution",
"staking",
"slashing",
"gov",
"mint",
"crisis",
"genutil",
"evidence",
"authz",
"feegrant",
"nft",
"group",
"params",
"upgrade",
"vesting",
}
type appConfig struct {
moduleConfigs map[string]*appv1alpha1.ModuleConfig
setInitGenesis bool
}
type ModuleOption func(config *appConfig)
func BankModule() ModuleOption {
return func(options map[string]*appv1alpha1.ModuleConfig) {
options["bank"] = &appv1alpha1.ModuleConfig{
return func(config *appConfig) {
config.moduleConfigs["bank"] = &appv1alpha1.ModuleConfig{
Name: "bank",
Config: appconfig.WrapAny(&bankmodulev1.Module{}),
}
@ -38,16 +97,18 @@ func BankModule() ModuleOption {
}
func AuthModule() ModuleOption {
return func(options map[string]*appv1alpha1.ModuleConfig) {
options["auth"] = &appv1alpha1.ModuleConfig{
return func(config *appConfig) {
config.moduleConfigs["auth"] = &appv1alpha1.ModuleConfig{
Name: "auth",
Config: appconfig.WrapAny(&authmodulev1.Module{
Bech32Prefix: "cosmos",
ModuleAccountPermissions: []*authmodulev1.ModuleAccountPermission{
{Account: "fee_collector"},
{Account: "distribution"},
{Account: "mint", Permissions: []string{"minter"}},
{Account: "bonded_tokens_pool", Permissions: []string{"burner", "staking"}},
{Account: "not_bonded_tokens_pool", Permissions: []string{"burner", "staking"}},
{Account: "gov", Permissions: []string{"burner"}},
},
}),
}
@ -55,53 +116,135 @@ func AuthModule() ModuleOption {
}
func ParamsModule() ModuleOption {
return func(options map[string]*appv1alpha1.ModuleConfig) {
options["params"] = &appv1alpha1.ModuleConfig{
return func(config *appConfig) {
config.moduleConfigs["params"] = &appv1alpha1.ModuleConfig{
Name: "params",
Config: appconfig.WrapAny(&paramsmodulev1.Module{}),
}
}
}
func TxModule() ModuleOption {
return func(config *appConfig) {
config.moduleConfigs["tx"] = &appv1alpha1.ModuleConfig{
Name: "tx",
Config: appconfig.WrapAny(&txmodulev1.Module{}),
}
}
}
func StakingModule() ModuleOption {
return func(config *appConfig) {
config.moduleConfigs["staking"] = &appv1alpha1.ModuleConfig{
Name: "staking",
Config: appconfig.WrapAny(&stakingmodulev1.Module{}),
}
}
}
func GenutilModule() ModuleOption {
return func(config *appConfig) {
config.moduleConfigs["genutil"] = &appv1alpha1.ModuleConfig{
Name: "genutil",
Config: appconfig.WrapAny(&genutilmodulev1.Module{}),
}
}
}
func DistributionModule() ModuleOption {
return func(config *appConfig) {
config.moduleConfigs["distribution"] = &appv1alpha1.ModuleConfig{
Name: "distribution",
Config: appconfig.WrapAny(&distrmodulev1.Module{}),
}
}
}
func FeegrantModule() ModuleOption {
return func(config *appConfig) {
config.moduleConfigs["feegrant"] = &appv1alpha1.ModuleConfig{
Name: "feegrant",
Config: appconfig.WrapAny(&feegrantmodulev1.Module{}),
}
}
}
func VestingModule() ModuleOption {
return func(config *appConfig) {
config.moduleConfigs["vesting"] = &appv1alpha1.ModuleConfig{
Name: "vesting",
Config: appconfig.WrapAny(&vestingmodulev1.Module{}),
}
}
}
func GovModule() ModuleOption {
return func(config *appConfig) {
config.moduleConfigs["gov"] = &appv1alpha1.ModuleConfig{
Name: "gov",
Config: appconfig.WrapAny(&govmodulev1.Module{}),
}
}
}
func OmitInitGenesis() ModuleOption {
return func(config *appConfig) {
config.setInitGenesis = false
}
}
func NewAppConfig(opts ...ModuleOption) depinject.Config {
options := make(map[string]*appv1alpha1.ModuleConfig)
cfg := &appConfig{
moduleConfigs: make(map[string]*appv1alpha1.ModuleConfig),
setInitGenesis: true,
}
for _, opt := range opts {
opt(options)
opt(cfg)
}
beginBlockers := make([]string, 0)
endBlockers := make([]string, 0)
initGenesis := make([]string, 0)
overrides := make([]*runtimev1alpha1.StoreKeyConfig, 0)
for _, s := range beginBlockOrder {
if _, ok := options[s]; ok {
if _, ok := cfg.moduleConfigs[s]; ok {
beginBlockers = append(beginBlockers, s)
}
}
for _, s := range endBlockersOrder {
if _, ok := options[s]; ok {
if _, ok := cfg.moduleConfigs[s]; ok {
endBlockers = append(endBlockers, s)
}
}
if _, ok := options["auth"]; ok {
for _, s := range initGenesisOrder {
if _, ok := cfg.moduleConfigs[s]; ok {
initGenesis = append(initGenesis, s)
}
}
if _, ok := cfg.moduleConfigs["auth"]; ok {
overrides = append(overrides, &runtimev1alpha1.StoreKeyConfig{ModuleName: "auth", KvStoreKey: "acc"})
}
modules := []*appv1alpha1.ModuleConfig{
{
Name: "runtime",
Config: appconfig.WrapAny(&runtimev1alpha1.Module{
AppName: "TestApp",
BeginBlockers: beginBlockers,
EndBlockers: endBlockers,
OverrideStoreKeys: overrides,
}),
},
runtimeConfig := &runtimev1alpha1.Module{
AppName: "TestApp",
BeginBlockers: beginBlockers,
EndBlockers: endBlockers,
OverrideStoreKeys: overrides,
}
if cfg.setInitGenesis {
runtimeConfig.InitGenesis = initGenesis
}
for _, m := range options {
modules := []*appv1alpha1.ModuleConfig{{
Name: "runtime",
Config: appconfig.WrapAny(runtimeConfig),
}}
for _, m := range cfg.moduleConfigs {
modules = append(modules, m)
}

View File

@ -25,6 +25,8 @@ import (
"google.golang.org/grpc"
"cosmossdk.io/math"
"github.com/cosmos/cosmos-sdk/testutil/configurator"
"github.com/cosmos/cosmos-sdk/testutil/testdata"
moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil"
"cosmossdk.io/depinject"
@ -44,9 +46,14 @@ import (
servertypes "github.com/cosmos/cosmos-sdk/server/types"
"github.com/cosmos/cosmos-sdk/testutil"
sdk "github.com/cosmos/cosmos-sdk/types"
_ "github.com/cosmos/cosmos-sdk/x/auth"
_ "github.com/cosmos/cosmos-sdk/x/auth/tx/module"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
_ "github.com/cosmos/cosmos-sdk/x/bank"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
"github.com/cosmos/cosmos-sdk/x/genutil"
_ "github.com/cosmos/cosmos-sdk/x/params"
_ "github.com/cosmos/cosmos-sdk/x/staking"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
)
@ -124,6 +131,17 @@ func DefaultConfig(factory TestFixtureFactory) Config {
}
}
// MinimumAppConfig defines the minimum of modules required for a call to New to succeed
func MinimumAppConfig() depinject.Config {
return configurator.NewAppConfig(
configurator.AuthModule(),
configurator.ParamsModule(),
configurator.BankModule(),
configurator.GenutilModule(),
configurator.StakingModule(),
configurator.TxModule())
}
func DefaultConfigWithAppConfig(appConfig depinject.Config) (Config, error) {
var (
appBuilder *runtime.AppBuilder
@ -165,6 +183,8 @@ func DefaultConfigWithAppConfig(appConfig depinject.Config) (Config, error) {
baseapp.SetMinGasPrices(val.GetAppConfig().MinGasPrices),
)
testdata.RegisterQueryServer(app.GRPCQueryRouter(), testdata.QueryImpl{})
if err := app.Load(true); err != nil {
panic(err)
}

View File

@ -53,8 +53,8 @@ var DefaultConsensusParams = &tmproto.ConsensusParams{
},
}
// createDefaultRandomValidatorSet creates a validator set with one random validator
func createDefaultRandomValidatorSet() (*tmtypes.ValidatorSet, error) {
// CreateRandomValidatorSet creates a validator set with one random validator
func CreateRandomValidatorSet() (*tmtypes.ValidatorSet, error) {
privVal := mock.NewPV()
pubKey, err := privVal.GetPubKey(context.TODO())
if err != nil {
@ -70,19 +70,19 @@ func createDefaultRandomValidatorSet() (*tmtypes.ValidatorSet, error) {
// Setup initializes a new runtime.App and can inject values into extraOutputs.
// It uses SetupWithConfiguration under the hood.
func Setup(appConfig depinject.Config, extraOutputs ...interface{}) (*runtime.App, error) {
return SetupWithConfiguration(appConfig, createDefaultRandomValidatorSet, nil, false, extraOutputs...)
return SetupWithConfiguration(appConfig, CreateRandomValidatorSet, nil, false, extraOutputs...)
}
// SetupAtGenesis initializes a new runtime.App at genesis and can inject values into extraOutputs.
// It uses SetupWithConfiguration under the hood.
func SetupAtGenesis(appConfig depinject.Config, extraOutputs ...interface{}) (*runtime.App, error) {
return SetupWithConfiguration(appConfig, createDefaultRandomValidatorSet, nil, true, extraOutputs...)
return SetupWithConfiguration(appConfig, CreateRandomValidatorSet, nil, true, extraOutputs...)
}
// SetupWithBaseAppOption initializes a new runtime.App and can inject values into extraOutputs.
// With specific baseApp options. It uses SetupWithConfiguration under the hood.
func SetupWithBaseAppOption(appConfig depinject.Config, baseAppOption runtime.BaseAppOption, extraOutputs ...interface{}) (*runtime.App, error) {
return SetupWithConfiguration(appConfig, createDefaultRandomValidatorSet, baseAppOption, false, extraOutputs...)
return SetupWithConfiguration(appConfig, CreateRandomValidatorSet, baseAppOption, false, extraOutputs...)
}
// SetupWithConfiguration initializes a new runtime.App. A Nop logger is set in runtime.App.

View File

@ -65,7 +65,9 @@ func (s *paginationTestSuite) SetupTest() {
configurator.NewAppConfig(
configurator.AuthModule(),
configurator.BankModule(),
configurator.ParamsModule()),
configurator.ParamsModule(),
configurator.OmitInitGenesis(),
),
&bankKeeper, &accountKeeper, &reg, &cdc)
s.NoError(err)