From 1e6e8fd5016f152377e20793c244a05bf5c7831a Mon Sep 17 00:00:00 2001 From: Facundo Medica Date: Wed, 21 Dec 2022 10:29:35 -0300 Subject: [PATCH 1/9] merge utils_test.go and util_test.go --- baseapp/util_test.go | 166 ------------------------------------------ baseapp/utils_test.go | 154 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 154 insertions(+), 166 deletions(-) delete mode 100644 baseapp/util_test.go diff --git a/baseapp/util_test.go b/baseapp/util_test.go deleted file mode 100644 index f35a47bb264e..000000000000 --- a/baseapp/util_test.go +++ /dev/null @@ -1,166 +0,0 @@ -package baseapp_test - -import ( - "encoding/json" - "testing" - - "github.com/stretchr/testify/require" - tmtypes "github.com/tendermint/tendermint/types" - - runtimev1alpha1 "cosmossdk.io/api/cosmos/app/runtime/v1alpha1" - appv1alpha1 "cosmossdk.io/api/cosmos/app/v1alpha1" - authmodulev1 "cosmossdk.io/api/cosmos/auth/module/v1" - bankmodulev1 "cosmossdk.io/api/cosmos/bank/module/v1" - consensusmodulev1 "cosmossdk.io/api/cosmos/consensus/module/v1" - mintmodulev1 "cosmossdk.io/api/cosmos/mint/module/v1" - paramsmodulev1 "cosmossdk.io/api/cosmos/params/module/v1" - stakingmodulev1 "cosmossdk.io/api/cosmos/staking/module/v1" - txconfigv1 "cosmossdk.io/api/cosmos/tx/config/v1" - "cosmossdk.io/core/appconfig" - "cosmossdk.io/depinject" - "github.com/cosmos/cosmos-sdk/baseapp" - "github.com/cosmos/cosmos-sdk/codec" - "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" - "github.com/cosmos/cosmos-sdk/runtime" - "github.com/cosmos/cosmos-sdk/testutil/mock" - simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/mempool" - _ "github.com/cosmos/cosmos-sdk/x/auth" - _ "github.com/cosmos/cosmos-sdk/x/auth/tx/config" - 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/consensus" - _ "github.com/cosmos/cosmos-sdk/x/mint" - minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" - _ "github.com/cosmos/cosmos-sdk/x/params" - _ "github.com/cosmos/cosmos-sdk/x/staking" - stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" -) - -// GenesisStateWithSingleValidator initializes GenesisState with a single validator and genesis accounts -// that also act as delegators. -func GenesisStateWithSingleValidator(t *testing.T, codec codec.Codec, builder *runtime.AppBuilder) map[string]json.RawMessage { - t.Helper() - - privVal := mock.NewPV() - pubKey, err := privVal.GetPubKey() - require.NoError(t, err) - - // create validator set with single validator - validator := tmtypes.NewValidator(pubKey, 1) - valSet := tmtypes.NewValidatorSet([]*tmtypes.Validator{validator}) - - // generate genesis account - senderPrivKey := secp256k1.GenPrivKey() - acc := authtypes.NewBaseAccount(senderPrivKey.PubKey().Address().Bytes(), senderPrivKey.PubKey(), 0, 0) - balances := []banktypes.Balance{ - { - Address: acc.GetAddress().String(), - Coins: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100000000000000))), - }, - } - - genesisState := builder.DefaultGenesis() - // sus - genesisState, err = simtestutil.GenesisStateWithValSet(codec, genesisState, valSet, []authtypes.GenesisAccount{acc}, balances...) - require.NoError(t, err) - - return genesisState -} - -func makeTestConfig() depinject.Config { - return appconfig.Compose(&appv1alpha1.Config{ - Modules: []*appv1alpha1.ModuleConfig{ - { - Name: "runtime", - Config: appconfig.WrapAny(&runtimev1alpha1.Module{ - AppName: "BaseAppApp", - BeginBlockers: []string{ - "mint", - "staking", - "auth", - "bank", - "params", - "consensus", - }, - EndBlockers: []string{ - "staking", - "auth", - "bank", - "mint", - "params", - "consensus", - }, - OverrideStoreKeys: []*runtimev1alpha1.StoreKeyConfig{ - { - ModuleName: "auth", - KvStoreKey: "acc", - }, - }, - InitGenesis: []string{ - "auth", - "bank", - "staking", - "mint", - "params", - "consensus", - }, - }), - }, - { - Name: "auth", - Config: appconfig.WrapAny(&authmodulev1.Module{ - Bech32Prefix: "cosmos", - ModuleAccountPermissions: []*authmodulev1.ModuleAccountPermission{ - {Account: authtypes.FeeCollectorName}, - {Account: minttypes.ModuleName, Permissions: []string{authtypes.Minter}}, - {Account: stakingtypes.BondedPoolName, Permissions: []string{authtypes.Burner, stakingtypes.ModuleName}}, - {Account: stakingtypes.NotBondedPoolName, Permissions: []string{authtypes.Burner, stakingtypes.ModuleName}}, - }, - }), - }, - { - Name: "bank", - Config: appconfig.WrapAny(&bankmodulev1.Module{}), - }, - { - Name: "params", - Config: appconfig.WrapAny(¶msmodulev1.Module{}), - }, - { - Name: "staking", - Config: appconfig.WrapAny(&stakingmodulev1.Module{}), - }, - { - Name: "mint", - Config: appconfig.WrapAny(&mintmodulev1.Module{}), - }, - { - Name: "consensus", - Config: appconfig.WrapAny(&consensusmodulev1.Module{}), - }, - { - Name: "tx", - Config: appconfig.WrapAny(&txconfigv1.Config{}), - }, - }, - }) -} - -func makeMinimalConfig() depinject.Config { - var mempoolOpt runtime.BaseAppOption = baseapp.SetMempool(mempool.NewSenderNonceMempool()) - return depinject.Configs( - depinject.Supply(mempoolOpt), - appconfig.Compose(&appv1alpha1.Config{ - Modules: []*appv1alpha1.ModuleConfig{ - { - Name: "runtime", - Config: appconfig.WrapAny(&runtimev1alpha1.Module{ - AppName: "BaseAppApp", - }), - }, - }, - })) -} diff --git a/baseapp/utils_test.go b/baseapp/utils_test.go index 7d3763f1c515..b2f4b541aefe 100644 --- a/baseapp/utils_test.go +++ b/baseapp/utils_test.go @@ -14,20 +14,48 @@ import ( "testing" "unsafe" + runtimev1alpha1 "cosmossdk.io/api/cosmos/app/runtime/v1alpha1" + appv1alpha1 "cosmossdk.io/api/cosmos/app/v1alpha1" + authmodulev1 "cosmossdk.io/api/cosmos/auth/module/v1" + bankmodulev1 "cosmossdk.io/api/cosmos/bank/module/v1" + consensusmodulev1 "cosmossdk.io/api/cosmos/consensus/module/v1" + mintmodulev1 "cosmossdk.io/api/cosmos/mint/module/v1" + paramsmodulev1 "cosmossdk.io/api/cosmos/params/module/v1" + stakingmodulev1 "cosmossdk.io/api/cosmos/staking/module/v1" + txconfigv1 "cosmossdk.io/api/cosmos/tx/config/v1" + "cosmossdk.io/core/appconfig" + "cosmossdk.io/depinject" "github.com/stretchr/testify/require" "github.com/tendermint/tendermint/libs/log" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + tmtypes "github.com/tendermint/tendermint/types" dbm "github.com/tendermint/tm-db" "github.com/cosmos/cosmos-sdk/baseapp" baseapptestutil "github.com/cosmos/cosmos-sdk/baseapp/testutil" "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" + "github.com/cosmos/cosmos-sdk/runtime" storetypes "github.com/cosmos/cosmos-sdk/store/types" + "github.com/cosmos/cosmos-sdk/testutil/mock" + simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/cosmos/cosmos-sdk/types/mempool" signingtypes "github.com/cosmos/cosmos-sdk/types/tx/signing" + _ "github.com/cosmos/cosmos-sdk/x/auth" "github.com/cosmos/cosmos-sdk/x/auth/signing" + _ "github.com/cosmos/cosmos-sdk/x/auth/tx/config" + 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/consensus" + _ "github.com/cosmos/cosmos-sdk/x/mint" + minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" + _ "github.com/cosmos/cosmos-sdk/x/params" + _ "github.com/cosmos/cosmos-sdk/x/staking" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" ) var ParamStoreKey = []byte("paramstore") @@ -40,6 +68,132 @@ func defaultLogger() log.Logger { return log.NewNopLogger() } +// GenesisStateWithSingleValidator initializes GenesisState with a single validator and genesis accounts +// that also act as delegators. +func GenesisStateWithSingleValidator(t *testing.T, codec codec.Codec, builder *runtime.AppBuilder) map[string]json.RawMessage { + t.Helper() + + privVal := mock.NewPV() + pubKey, err := privVal.GetPubKey() + require.NoError(t, err) + + // create validator set with single validator + validator := tmtypes.NewValidator(pubKey, 1) + valSet := tmtypes.NewValidatorSet([]*tmtypes.Validator{validator}) + + // generate genesis account + senderPrivKey := secp256k1.GenPrivKey() + acc := authtypes.NewBaseAccount(senderPrivKey.PubKey().Address().Bytes(), senderPrivKey.PubKey(), 0, 0) + balances := []banktypes.Balance{ + { + Address: acc.GetAddress().String(), + Coins: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100000000000000))), + }, + } + + genesisState := builder.DefaultGenesis() + // sus + genesisState, err = simtestutil.GenesisStateWithValSet(codec, genesisState, valSet, []authtypes.GenesisAccount{acc}, balances...) + require.NoError(t, err) + + return genesisState +} + +func makeTestConfig() depinject.Config { + return appconfig.Compose(&appv1alpha1.Config{ + Modules: []*appv1alpha1.ModuleConfig{ + { + Name: "runtime", + Config: appconfig.WrapAny(&runtimev1alpha1.Module{ + AppName: "BaseAppApp", + BeginBlockers: []string{ + "mint", + "staking", + "auth", + "bank", + "params", + "consensus", + }, + EndBlockers: []string{ + "staking", + "auth", + "bank", + "mint", + "params", + "consensus", + }, + OverrideStoreKeys: []*runtimev1alpha1.StoreKeyConfig{ + { + ModuleName: "auth", + KvStoreKey: "acc", + }, + }, + InitGenesis: []string{ + "auth", + "bank", + "staking", + "mint", + "params", + "consensus", + }, + }), + }, + { + Name: "auth", + Config: appconfig.WrapAny(&authmodulev1.Module{ + Bech32Prefix: "cosmos", + ModuleAccountPermissions: []*authmodulev1.ModuleAccountPermission{ + {Account: authtypes.FeeCollectorName}, + {Account: minttypes.ModuleName, Permissions: []string{authtypes.Minter}}, + {Account: stakingtypes.BondedPoolName, Permissions: []string{authtypes.Burner, stakingtypes.ModuleName}}, + {Account: stakingtypes.NotBondedPoolName, Permissions: []string{authtypes.Burner, stakingtypes.ModuleName}}, + }, + }), + }, + { + Name: "bank", + Config: appconfig.WrapAny(&bankmodulev1.Module{}), + }, + { + Name: "params", + Config: appconfig.WrapAny(¶msmodulev1.Module{}), + }, + { + Name: "staking", + Config: appconfig.WrapAny(&stakingmodulev1.Module{}), + }, + { + Name: "mint", + Config: appconfig.WrapAny(&mintmodulev1.Module{}), + }, + { + Name: "consensus", + Config: appconfig.WrapAny(&consensusmodulev1.Module{}), + }, + { + Name: "tx", + Config: appconfig.WrapAny(&txconfigv1.Config{}), + }, + }, + }) +} + +func makeMinimalConfig() depinject.Config { + var mempoolOpt runtime.BaseAppOption = baseapp.SetMempool(mempool.NewSenderNonceMempool()) + return depinject.Configs( + depinject.Supply(mempoolOpt), + appconfig.Compose(&appv1alpha1.Config{ + Modules: []*appv1alpha1.ModuleConfig{ + { + Name: "runtime", + Config: appconfig.WrapAny(&runtimev1alpha1.Module{ + AppName: "BaseAppApp", + }), + }, + }, + })) +} + type MsgKeyValueImpl struct{} func (m MsgKeyValueImpl) Set(ctx context.Context, msg *baseapptestutil.MsgKeyValue) (*baseapptestutil.MsgCreateKeyValueResponse, error) { From 6999e96d23c38742ec0f63a5f840580cedf3dbff Mon Sep 17 00:00:00 2001 From: Facundo Medica Date: Wed, 21 Dec 2022 10:34:58 -0300 Subject: [PATCH 2/9] fix getState comment --- baseapp/baseapp.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/baseapp/baseapp.go b/baseapp/baseapp.go index 04c5deffb567..cf20054f477a 100644 --- a/baseapp/baseapp.go +++ b/baseapp/baseapp.go @@ -552,7 +552,8 @@ func validateBasicTxMsgs(msgs []sdk.Msg) error { } // Returns the application's deliverState if app is in runTxModeDeliver, -// otherwise it returns the application's checkstate. +// prepareProposalState if app is in runTxPrepareProposal, processProposalState +// if app is in runTxProcessProposal, and checkState otherwise. func (app *BaseApp) getState(mode runTxMode) *state { switch mode { case runTxModeDeliver: From ce138d6253817bcc5f6658157f7784b3d530403f Mon Sep 17 00:00:00 2001 From: Facundo Medica Date: Wed, 21 Dec 2022 10:35:52 -0300 Subject: [PATCH 3/9] remove parallel block execution comment. in the spec it says it will be possible in the future --- baseapp/abci.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/baseapp/abci.go b/baseapp/abci.go index 2e2363fba95e..695047bbbb39 100644 --- a/baseapp/abci.go +++ b/baseapp/abci.go @@ -263,7 +263,7 @@ func (app *BaseApp) PrepareProposal(req abci.RequestPrepareProposal) abci.Respon // that all transactions are valid. If all transactions are valid, then we inform // Tendermint that the Status is ACCEPT. However, the application is also able // to implement optimizations such as executing the entire proposed block -// immediately. It may even execute the block in parallel. +// immediately. // // Ref: https://github.com/cosmos/cosmos-sdk/blob/main/docs/architecture/adr-060-abci-1.0.md // Ref: https://github.com/tendermint/tendermint/blob/main/spec/abci/abci%2B%2B_basic_concepts.md From fd0b844f4eb6ef3356a853a0195862d9e2144da8 Mon Sep 17 00:00:00 2001 From: Facundo Medica Date: Wed, 21 Dec 2022 11:03:51 -0300 Subject: [PATCH 4/9] factorize setState functions (from Amaury's notes) --- baseapp/abci.go | 16 +++++------ baseapp/baseapp.go | 67 +++++++++++++++++----------------------------- 2 files changed, 33 insertions(+), 50 deletions(-) diff --git a/baseapp/abci.go b/baseapp/abci.go index 695047bbbb39..ec1201737961 100644 --- a/baseapp/abci.go +++ b/baseapp/abci.go @@ -52,10 +52,10 @@ func (app *BaseApp) InitChain(req abci.RequestInitChain) (res abci.ResponseInitC } // initialize states with a correct header - app.setDeliverState(initHeader) - app.setCheckState(initHeader) - app.setPrepareProposalState(initHeader) - app.setProcessProposalState(initHeader) + app.setState(runTxModeDeliver, initHeader) + app.setState(runTxModeCheck, initHeader) + app.setState(runTxPrepareProposal, initHeader) + app.setState(runTxProcessProposal, initHeader) // Store the consensus params in the BaseApp's paramstore. Note, this must be // done after the deliver state and context have been set as it's persisted @@ -162,7 +162,7 @@ func (app *BaseApp) BeginBlock(req abci.RequestBeginBlock) (res abci.ResponseBeg // already be initialized in InitChain. Otherwise app.deliverState will be // nil, since it is reset on Commit. if app.deliverState == nil { - app.setDeliverState(req.Header) + app.setState(runTxModeDeliver, req.Header) } else { // In the first block, app.deliverState.ctx will already be initialized // by InitChain. Context is now updated with Header information. @@ -392,9 +392,9 @@ func (app *BaseApp) Commit() abci.ResponseCommit { // // NOTE: This is safe because Tendermint holds a lock on the mempool for // Commit. Use the header from this latest block. - app.setCheckState(header) - app.setPrepareProposalState(header) - app.setProcessProposalState(header) + app.setState(runTxModeCheck, header) + app.setState(runTxPrepareProposal, header) + app.setState(runTxProcessProposal, header) // empty/reset the deliver state app.deliverState = nil diff --git a/baseapp/baseapp.go b/baseapp/baseapp.go index cf20054f477a..7bc837a2878a 100644 --- a/baseapp/baseapp.go +++ b/baseapp/baseapp.go @@ -350,11 +350,11 @@ func (app *BaseApp) Init() error { emptyHeader := tmproto.Header{} // needed for the export command which inits from store but never calls initchain - app.setCheckState(emptyHeader) + app.setState(runTxModeCheck, emptyHeader) // needed for ABCI Replay Blocks mode which calls Prepare/Process proposal (InitChain is not called) - app.setPrepareProposalState(emptyHeader) - app.setProcessProposalState(emptyHeader) + app.setState(runTxPrepareProposal, emptyHeader) + app.setState(runTxProcessProposal, emptyHeader) app.Seal() if app.cms == nil { @@ -402,49 +402,32 @@ func (app *BaseApp) Seal() { app.sealed = true } // IsSealed returns true if the BaseApp is sealed and false otherwise. func (app *BaseApp) IsSealed() bool { return app.sealed } -// setCheckState sets the BaseApp's checkState with a branched multi-store -// (i.e. a CacheMultiStore) and a new Context with the same multi-store branch, -// provided header, and minimum gas prices set. It is set on InitChain and reset -// on Commit. -func (app *BaseApp) setCheckState(header tmproto.Header) { +// setState sets the BaseApp's state for the corresponding mode with a branched +// multi-store (i.e. a CacheMultiStore) and a new Context with the same +// multi-store branch, and provided header. +func (app *BaseApp) setState(mode runTxMode, header tmproto.Header) { ms := app.cms.CacheMultiStore() - app.checkState = &state{ - ms: ms, - ctx: sdk.NewContext(ms, header, true, app.logger).WithMinGasPrices(app.minGasPrices), - } -} - -// setDeliverState sets the BaseApp's deliverState with a branched multi-store -// (i.e. a CacheMultiStore) and a new Context with the same multi-store branch, -// and provided header. It is set on InitChain and BeginBlock and set to nil on -// Commit. -func (app *BaseApp) setDeliverState(header tmproto.Header) { - ms := app.cms.CacheMultiStore() - app.deliverState = &state{ - ms: ms, + baseState := &state{ + ms: app.cms.CacheMultiStore(), ctx: sdk.NewContext(ms, header, false, app.logger), } -} -// setPrepareProposalState sets the BaseApp's prepareProposalState with a -// branched multi-store (i.e. a CacheMultiStore) and a new Context with the -// same multi-store branch, and provided header. It is set on InitChain and Commit. -func (app *BaseApp) setPrepareProposalState(header tmproto.Header) { - ms := app.cms.CacheMultiStore() - app.prepareProposalState = &state{ - ms: ms, - ctx: sdk.NewContext(ms, header, false, app.logger), - } -} - -// setProcessProposalState sets the BaseApp's processProposalState with a -// branched multi-store (i.e. a CacheMultiStore) and a new Context with the -// same multi-store branch, and provided header. It is set on InitChain and Commit. -func (app *BaseApp) setProcessProposalState(header tmproto.Header) { - ms := app.cms.CacheMultiStore() - app.processProposalState = &state{ - ms: ms, - ctx: sdk.NewContext(ms, header, false, app.logger), + switch mode { + case runTxModeCheck: + // Minimum gas prices are also set. It is set on InitChain and reset on Commit. + baseState.ctx = baseState.ctx.WithIsCheckTx(true).WithMinGasPrices(app.minGasPrices) + app.checkState = baseState + case runTxModeDeliver: + // It is set on InitChain and BeginBlock and set to nil on Commit. + app.deliverState = baseState + case runTxPrepareProposal: + // It is set on InitChain and Commit. + app.prepareProposalState = baseState + case runTxProcessProposal: + // It is set on InitChain and Commit. + app.processProposalState = baseState + default: + panic(fmt.Sprintf("invalid runTxMode for setState: %d", mode)) } } From 306c596c9fa086194baae5142759ec0ec95caaf3 Mon Sep 17 00:00:00 2001 From: Facundo Medica Date: Wed, 21 Dec 2022 11:16:38 -0300 Subject: [PATCH 5/9] Revert "merge utils_test.go and util_test.go" This reverts commit 1e6e8fd5016f152377e20793c244a05bf5c7831a. --- baseapp/util_test.go | 166 ++++++++++++++++++++++++++++++++++++++++++ baseapp/utils_test.go | 154 --------------------------------------- 2 files changed, 166 insertions(+), 154 deletions(-) create mode 100644 baseapp/util_test.go diff --git a/baseapp/util_test.go b/baseapp/util_test.go new file mode 100644 index 000000000000..f35a47bb264e --- /dev/null +++ b/baseapp/util_test.go @@ -0,0 +1,166 @@ +package baseapp_test + +import ( + "encoding/json" + "testing" + + "github.com/stretchr/testify/require" + tmtypes "github.com/tendermint/tendermint/types" + + runtimev1alpha1 "cosmossdk.io/api/cosmos/app/runtime/v1alpha1" + appv1alpha1 "cosmossdk.io/api/cosmos/app/v1alpha1" + authmodulev1 "cosmossdk.io/api/cosmos/auth/module/v1" + bankmodulev1 "cosmossdk.io/api/cosmos/bank/module/v1" + consensusmodulev1 "cosmossdk.io/api/cosmos/consensus/module/v1" + mintmodulev1 "cosmossdk.io/api/cosmos/mint/module/v1" + paramsmodulev1 "cosmossdk.io/api/cosmos/params/module/v1" + stakingmodulev1 "cosmossdk.io/api/cosmos/staking/module/v1" + txconfigv1 "cosmossdk.io/api/cosmos/tx/config/v1" + "cosmossdk.io/core/appconfig" + "cosmossdk.io/depinject" + "github.com/cosmos/cosmos-sdk/baseapp" + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" + "github.com/cosmos/cosmos-sdk/runtime" + "github.com/cosmos/cosmos-sdk/testutil/mock" + simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/mempool" + _ "github.com/cosmos/cosmos-sdk/x/auth" + _ "github.com/cosmos/cosmos-sdk/x/auth/tx/config" + 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/consensus" + _ "github.com/cosmos/cosmos-sdk/x/mint" + minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" + _ "github.com/cosmos/cosmos-sdk/x/params" + _ "github.com/cosmos/cosmos-sdk/x/staking" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" +) + +// GenesisStateWithSingleValidator initializes GenesisState with a single validator and genesis accounts +// that also act as delegators. +func GenesisStateWithSingleValidator(t *testing.T, codec codec.Codec, builder *runtime.AppBuilder) map[string]json.RawMessage { + t.Helper() + + privVal := mock.NewPV() + pubKey, err := privVal.GetPubKey() + require.NoError(t, err) + + // create validator set with single validator + validator := tmtypes.NewValidator(pubKey, 1) + valSet := tmtypes.NewValidatorSet([]*tmtypes.Validator{validator}) + + // generate genesis account + senderPrivKey := secp256k1.GenPrivKey() + acc := authtypes.NewBaseAccount(senderPrivKey.PubKey().Address().Bytes(), senderPrivKey.PubKey(), 0, 0) + balances := []banktypes.Balance{ + { + Address: acc.GetAddress().String(), + Coins: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100000000000000))), + }, + } + + genesisState := builder.DefaultGenesis() + // sus + genesisState, err = simtestutil.GenesisStateWithValSet(codec, genesisState, valSet, []authtypes.GenesisAccount{acc}, balances...) + require.NoError(t, err) + + return genesisState +} + +func makeTestConfig() depinject.Config { + return appconfig.Compose(&appv1alpha1.Config{ + Modules: []*appv1alpha1.ModuleConfig{ + { + Name: "runtime", + Config: appconfig.WrapAny(&runtimev1alpha1.Module{ + AppName: "BaseAppApp", + BeginBlockers: []string{ + "mint", + "staking", + "auth", + "bank", + "params", + "consensus", + }, + EndBlockers: []string{ + "staking", + "auth", + "bank", + "mint", + "params", + "consensus", + }, + OverrideStoreKeys: []*runtimev1alpha1.StoreKeyConfig{ + { + ModuleName: "auth", + KvStoreKey: "acc", + }, + }, + InitGenesis: []string{ + "auth", + "bank", + "staking", + "mint", + "params", + "consensus", + }, + }), + }, + { + Name: "auth", + Config: appconfig.WrapAny(&authmodulev1.Module{ + Bech32Prefix: "cosmos", + ModuleAccountPermissions: []*authmodulev1.ModuleAccountPermission{ + {Account: authtypes.FeeCollectorName}, + {Account: minttypes.ModuleName, Permissions: []string{authtypes.Minter}}, + {Account: stakingtypes.BondedPoolName, Permissions: []string{authtypes.Burner, stakingtypes.ModuleName}}, + {Account: stakingtypes.NotBondedPoolName, Permissions: []string{authtypes.Burner, stakingtypes.ModuleName}}, + }, + }), + }, + { + Name: "bank", + Config: appconfig.WrapAny(&bankmodulev1.Module{}), + }, + { + Name: "params", + Config: appconfig.WrapAny(¶msmodulev1.Module{}), + }, + { + Name: "staking", + Config: appconfig.WrapAny(&stakingmodulev1.Module{}), + }, + { + Name: "mint", + Config: appconfig.WrapAny(&mintmodulev1.Module{}), + }, + { + Name: "consensus", + Config: appconfig.WrapAny(&consensusmodulev1.Module{}), + }, + { + Name: "tx", + Config: appconfig.WrapAny(&txconfigv1.Config{}), + }, + }, + }) +} + +func makeMinimalConfig() depinject.Config { + var mempoolOpt runtime.BaseAppOption = baseapp.SetMempool(mempool.NewSenderNonceMempool()) + return depinject.Configs( + depinject.Supply(mempoolOpt), + appconfig.Compose(&appv1alpha1.Config{ + Modules: []*appv1alpha1.ModuleConfig{ + { + Name: "runtime", + Config: appconfig.WrapAny(&runtimev1alpha1.Module{ + AppName: "BaseAppApp", + }), + }, + }, + })) +} diff --git a/baseapp/utils_test.go b/baseapp/utils_test.go index b2f4b541aefe..7d3763f1c515 100644 --- a/baseapp/utils_test.go +++ b/baseapp/utils_test.go @@ -14,48 +14,20 @@ import ( "testing" "unsafe" - runtimev1alpha1 "cosmossdk.io/api/cosmos/app/runtime/v1alpha1" - appv1alpha1 "cosmossdk.io/api/cosmos/app/v1alpha1" - authmodulev1 "cosmossdk.io/api/cosmos/auth/module/v1" - bankmodulev1 "cosmossdk.io/api/cosmos/bank/module/v1" - consensusmodulev1 "cosmossdk.io/api/cosmos/consensus/module/v1" - mintmodulev1 "cosmossdk.io/api/cosmos/mint/module/v1" - paramsmodulev1 "cosmossdk.io/api/cosmos/params/module/v1" - stakingmodulev1 "cosmossdk.io/api/cosmos/staking/module/v1" - txconfigv1 "cosmossdk.io/api/cosmos/tx/config/v1" - "cosmossdk.io/core/appconfig" - "cosmossdk.io/depinject" "github.com/stretchr/testify/require" "github.com/tendermint/tendermint/libs/log" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" - tmtypes "github.com/tendermint/tendermint/types" dbm "github.com/tendermint/tm-db" "github.com/cosmos/cosmos-sdk/baseapp" baseapptestutil "github.com/cosmos/cosmos-sdk/baseapp/testutil" "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" - "github.com/cosmos/cosmos-sdk/runtime" storetypes "github.com/cosmos/cosmos-sdk/store/types" - "github.com/cosmos/cosmos-sdk/testutil/mock" - simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/cosmos/cosmos-sdk/types/mempool" signingtypes "github.com/cosmos/cosmos-sdk/types/tx/signing" - _ "github.com/cosmos/cosmos-sdk/x/auth" "github.com/cosmos/cosmos-sdk/x/auth/signing" - _ "github.com/cosmos/cosmos-sdk/x/auth/tx/config" - 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/consensus" - _ "github.com/cosmos/cosmos-sdk/x/mint" - minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" - _ "github.com/cosmos/cosmos-sdk/x/params" - _ "github.com/cosmos/cosmos-sdk/x/staking" - stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" ) var ParamStoreKey = []byte("paramstore") @@ -68,132 +40,6 @@ func defaultLogger() log.Logger { return log.NewNopLogger() } -// GenesisStateWithSingleValidator initializes GenesisState with a single validator and genesis accounts -// that also act as delegators. -func GenesisStateWithSingleValidator(t *testing.T, codec codec.Codec, builder *runtime.AppBuilder) map[string]json.RawMessage { - t.Helper() - - privVal := mock.NewPV() - pubKey, err := privVal.GetPubKey() - require.NoError(t, err) - - // create validator set with single validator - validator := tmtypes.NewValidator(pubKey, 1) - valSet := tmtypes.NewValidatorSet([]*tmtypes.Validator{validator}) - - // generate genesis account - senderPrivKey := secp256k1.GenPrivKey() - acc := authtypes.NewBaseAccount(senderPrivKey.PubKey().Address().Bytes(), senderPrivKey.PubKey(), 0, 0) - balances := []banktypes.Balance{ - { - Address: acc.GetAddress().String(), - Coins: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100000000000000))), - }, - } - - genesisState := builder.DefaultGenesis() - // sus - genesisState, err = simtestutil.GenesisStateWithValSet(codec, genesisState, valSet, []authtypes.GenesisAccount{acc}, balances...) - require.NoError(t, err) - - return genesisState -} - -func makeTestConfig() depinject.Config { - return appconfig.Compose(&appv1alpha1.Config{ - Modules: []*appv1alpha1.ModuleConfig{ - { - Name: "runtime", - Config: appconfig.WrapAny(&runtimev1alpha1.Module{ - AppName: "BaseAppApp", - BeginBlockers: []string{ - "mint", - "staking", - "auth", - "bank", - "params", - "consensus", - }, - EndBlockers: []string{ - "staking", - "auth", - "bank", - "mint", - "params", - "consensus", - }, - OverrideStoreKeys: []*runtimev1alpha1.StoreKeyConfig{ - { - ModuleName: "auth", - KvStoreKey: "acc", - }, - }, - InitGenesis: []string{ - "auth", - "bank", - "staking", - "mint", - "params", - "consensus", - }, - }), - }, - { - Name: "auth", - Config: appconfig.WrapAny(&authmodulev1.Module{ - Bech32Prefix: "cosmos", - ModuleAccountPermissions: []*authmodulev1.ModuleAccountPermission{ - {Account: authtypes.FeeCollectorName}, - {Account: minttypes.ModuleName, Permissions: []string{authtypes.Minter}}, - {Account: stakingtypes.BondedPoolName, Permissions: []string{authtypes.Burner, stakingtypes.ModuleName}}, - {Account: stakingtypes.NotBondedPoolName, Permissions: []string{authtypes.Burner, stakingtypes.ModuleName}}, - }, - }), - }, - { - Name: "bank", - Config: appconfig.WrapAny(&bankmodulev1.Module{}), - }, - { - Name: "params", - Config: appconfig.WrapAny(¶msmodulev1.Module{}), - }, - { - Name: "staking", - Config: appconfig.WrapAny(&stakingmodulev1.Module{}), - }, - { - Name: "mint", - Config: appconfig.WrapAny(&mintmodulev1.Module{}), - }, - { - Name: "consensus", - Config: appconfig.WrapAny(&consensusmodulev1.Module{}), - }, - { - Name: "tx", - Config: appconfig.WrapAny(&txconfigv1.Config{}), - }, - }, - }) -} - -func makeMinimalConfig() depinject.Config { - var mempoolOpt runtime.BaseAppOption = baseapp.SetMempool(mempool.NewSenderNonceMempool()) - return depinject.Configs( - depinject.Supply(mempoolOpt), - appconfig.Compose(&appv1alpha1.Config{ - Modules: []*appv1alpha1.ModuleConfig{ - { - Name: "runtime", - Config: appconfig.WrapAny(&runtimev1alpha1.Module{ - AppName: "BaseAppApp", - }), - }, - }, - })) -} - type MsgKeyValueImpl struct{} func (m MsgKeyValueImpl) Set(ctx context.Context, msg *baseapptestutil.MsgKeyValue) (*baseapptestutil.MsgCreateKeyValueResponse, error) { From afc2c51f99994e51ce28bc1cf407e83bd24224a1 Mon Sep 17 00:00:00 2001 From: Facundo Medica Date: Wed, 21 Dec 2022 11:21:12 -0300 Subject: [PATCH 6/9] Revert "Revert "merge utils_test.go and util_test.go"" This reverts commit 306c596c9fa086194baae5142759ec0ec95caaf3. --- baseapp/util_test.go | 166 ------------------------------------------ baseapp/utils_test.go | 154 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 154 insertions(+), 166 deletions(-) delete mode 100644 baseapp/util_test.go diff --git a/baseapp/util_test.go b/baseapp/util_test.go deleted file mode 100644 index f35a47bb264e..000000000000 --- a/baseapp/util_test.go +++ /dev/null @@ -1,166 +0,0 @@ -package baseapp_test - -import ( - "encoding/json" - "testing" - - "github.com/stretchr/testify/require" - tmtypes "github.com/tendermint/tendermint/types" - - runtimev1alpha1 "cosmossdk.io/api/cosmos/app/runtime/v1alpha1" - appv1alpha1 "cosmossdk.io/api/cosmos/app/v1alpha1" - authmodulev1 "cosmossdk.io/api/cosmos/auth/module/v1" - bankmodulev1 "cosmossdk.io/api/cosmos/bank/module/v1" - consensusmodulev1 "cosmossdk.io/api/cosmos/consensus/module/v1" - mintmodulev1 "cosmossdk.io/api/cosmos/mint/module/v1" - paramsmodulev1 "cosmossdk.io/api/cosmos/params/module/v1" - stakingmodulev1 "cosmossdk.io/api/cosmos/staking/module/v1" - txconfigv1 "cosmossdk.io/api/cosmos/tx/config/v1" - "cosmossdk.io/core/appconfig" - "cosmossdk.io/depinject" - "github.com/cosmos/cosmos-sdk/baseapp" - "github.com/cosmos/cosmos-sdk/codec" - "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" - "github.com/cosmos/cosmos-sdk/runtime" - "github.com/cosmos/cosmos-sdk/testutil/mock" - simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/mempool" - _ "github.com/cosmos/cosmos-sdk/x/auth" - _ "github.com/cosmos/cosmos-sdk/x/auth/tx/config" - 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/consensus" - _ "github.com/cosmos/cosmos-sdk/x/mint" - minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" - _ "github.com/cosmos/cosmos-sdk/x/params" - _ "github.com/cosmos/cosmos-sdk/x/staking" - stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" -) - -// GenesisStateWithSingleValidator initializes GenesisState with a single validator and genesis accounts -// that also act as delegators. -func GenesisStateWithSingleValidator(t *testing.T, codec codec.Codec, builder *runtime.AppBuilder) map[string]json.RawMessage { - t.Helper() - - privVal := mock.NewPV() - pubKey, err := privVal.GetPubKey() - require.NoError(t, err) - - // create validator set with single validator - validator := tmtypes.NewValidator(pubKey, 1) - valSet := tmtypes.NewValidatorSet([]*tmtypes.Validator{validator}) - - // generate genesis account - senderPrivKey := secp256k1.GenPrivKey() - acc := authtypes.NewBaseAccount(senderPrivKey.PubKey().Address().Bytes(), senderPrivKey.PubKey(), 0, 0) - balances := []banktypes.Balance{ - { - Address: acc.GetAddress().String(), - Coins: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100000000000000))), - }, - } - - genesisState := builder.DefaultGenesis() - // sus - genesisState, err = simtestutil.GenesisStateWithValSet(codec, genesisState, valSet, []authtypes.GenesisAccount{acc}, balances...) - require.NoError(t, err) - - return genesisState -} - -func makeTestConfig() depinject.Config { - return appconfig.Compose(&appv1alpha1.Config{ - Modules: []*appv1alpha1.ModuleConfig{ - { - Name: "runtime", - Config: appconfig.WrapAny(&runtimev1alpha1.Module{ - AppName: "BaseAppApp", - BeginBlockers: []string{ - "mint", - "staking", - "auth", - "bank", - "params", - "consensus", - }, - EndBlockers: []string{ - "staking", - "auth", - "bank", - "mint", - "params", - "consensus", - }, - OverrideStoreKeys: []*runtimev1alpha1.StoreKeyConfig{ - { - ModuleName: "auth", - KvStoreKey: "acc", - }, - }, - InitGenesis: []string{ - "auth", - "bank", - "staking", - "mint", - "params", - "consensus", - }, - }), - }, - { - Name: "auth", - Config: appconfig.WrapAny(&authmodulev1.Module{ - Bech32Prefix: "cosmos", - ModuleAccountPermissions: []*authmodulev1.ModuleAccountPermission{ - {Account: authtypes.FeeCollectorName}, - {Account: minttypes.ModuleName, Permissions: []string{authtypes.Minter}}, - {Account: stakingtypes.BondedPoolName, Permissions: []string{authtypes.Burner, stakingtypes.ModuleName}}, - {Account: stakingtypes.NotBondedPoolName, Permissions: []string{authtypes.Burner, stakingtypes.ModuleName}}, - }, - }), - }, - { - Name: "bank", - Config: appconfig.WrapAny(&bankmodulev1.Module{}), - }, - { - Name: "params", - Config: appconfig.WrapAny(¶msmodulev1.Module{}), - }, - { - Name: "staking", - Config: appconfig.WrapAny(&stakingmodulev1.Module{}), - }, - { - Name: "mint", - Config: appconfig.WrapAny(&mintmodulev1.Module{}), - }, - { - Name: "consensus", - Config: appconfig.WrapAny(&consensusmodulev1.Module{}), - }, - { - Name: "tx", - Config: appconfig.WrapAny(&txconfigv1.Config{}), - }, - }, - }) -} - -func makeMinimalConfig() depinject.Config { - var mempoolOpt runtime.BaseAppOption = baseapp.SetMempool(mempool.NewSenderNonceMempool()) - return depinject.Configs( - depinject.Supply(mempoolOpt), - appconfig.Compose(&appv1alpha1.Config{ - Modules: []*appv1alpha1.ModuleConfig{ - { - Name: "runtime", - Config: appconfig.WrapAny(&runtimev1alpha1.Module{ - AppName: "BaseAppApp", - }), - }, - }, - })) -} diff --git a/baseapp/utils_test.go b/baseapp/utils_test.go index 7d3763f1c515..b2f4b541aefe 100644 --- a/baseapp/utils_test.go +++ b/baseapp/utils_test.go @@ -14,20 +14,48 @@ import ( "testing" "unsafe" + runtimev1alpha1 "cosmossdk.io/api/cosmos/app/runtime/v1alpha1" + appv1alpha1 "cosmossdk.io/api/cosmos/app/v1alpha1" + authmodulev1 "cosmossdk.io/api/cosmos/auth/module/v1" + bankmodulev1 "cosmossdk.io/api/cosmos/bank/module/v1" + consensusmodulev1 "cosmossdk.io/api/cosmos/consensus/module/v1" + mintmodulev1 "cosmossdk.io/api/cosmos/mint/module/v1" + paramsmodulev1 "cosmossdk.io/api/cosmos/params/module/v1" + stakingmodulev1 "cosmossdk.io/api/cosmos/staking/module/v1" + txconfigv1 "cosmossdk.io/api/cosmos/tx/config/v1" + "cosmossdk.io/core/appconfig" + "cosmossdk.io/depinject" "github.com/stretchr/testify/require" "github.com/tendermint/tendermint/libs/log" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + tmtypes "github.com/tendermint/tendermint/types" dbm "github.com/tendermint/tm-db" "github.com/cosmos/cosmos-sdk/baseapp" baseapptestutil "github.com/cosmos/cosmos-sdk/baseapp/testutil" "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" + "github.com/cosmos/cosmos-sdk/runtime" storetypes "github.com/cosmos/cosmos-sdk/store/types" + "github.com/cosmos/cosmos-sdk/testutil/mock" + simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/cosmos/cosmos-sdk/types/mempool" signingtypes "github.com/cosmos/cosmos-sdk/types/tx/signing" + _ "github.com/cosmos/cosmos-sdk/x/auth" "github.com/cosmos/cosmos-sdk/x/auth/signing" + _ "github.com/cosmos/cosmos-sdk/x/auth/tx/config" + 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/consensus" + _ "github.com/cosmos/cosmos-sdk/x/mint" + minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" + _ "github.com/cosmos/cosmos-sdk/x/params" + _ "github.com/cosmos/cosmos-sdk/x/staking" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" ) var ParamStoreKey = []byte("paramstore") @@ -40,6 +68,132 @@ func defaultLogger() log.Logger { return log.NewNopLogger() } +// GenesisStateWithSingleValidator initializes GenesisState with a single validator and genesis accounts +// that also act as delegators. +func GenesisStateWithSingleValidator(t *testing.T, codec codec.Codec, builder *runtime.AppBuilder) map[string]json.RawMessage { + t.Helper() + + privVal := mock.NewPV() + pubKey, err := privVal.GetPubKey() + require.NoError(t, err) + + // create validator set with single validator + validator := tmtypes.NewValidator(pubKey, 1) + valSet := tmtypes.NewValidatorSet([]*tmtypes.Validator{validator}) + + // generate genesis account + senderPrivKey := secp256k1.GenPrivKey() + acc := authtypes.NewBaseAccount(senderPrivKey.PubKey().Address().Bytes(), senderPrivKey.PubKey(), 0, 0) + balances := []banktypes.Balance{ + { + Address: acc.GetAddress().String(), + Coins: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100000000000000))), + }, + } + + genesisState := builder.DefaultGenesis() + // sus + genesisState, err = simtestutil.GenesisStateWithValSet(codec, genesisState, valSet, []authtypes.GenesisAccount{acc}, balances...) + require.NoError(t, err) + + return genesisState +} + +func makeTestConfig() depinject.Config { + return appconfig.Compose(&appv1alpha1.Config{ + Modules: []*appv1alpha1.ModuleConfig{ + { + Name: "runtime", + Config: appconfig.WrapAny(&runtimev1alpha1.Module{ + AppName: "BaseAppApp", + BeginBlockers: []string{ + "mint", + "staking", + "auth", + "bank", + "params", + "consensus", + }, + EndBlockers: []string{ + "staking", + "auth", + "bank", + "mint", + "params", + "consensus", + }, + OverrideStoreKeys: []*runtimev1alpha1.StoreKeyConfig{ + { + ModuleName: "auth", + KvStoreKey: "acc", + }, + }, + InitGenesis: []string{ + "auth", + "bank", + "staking", + "mint", + "params", + "consensus", + }, + }), + }, + { + Name: "auth", + Config: appconfig.WrapAny(&authmodulev1.Module{ + Bech32Prefix: "cosmos", + ModuleAccountPermissions: []*authmodulev1.ModuleAccountPermission{ + {Account: authtypes.FeeCollectorName}, + {Account: minttypes.ModuleName, Permissions: []string{authtypes.Minter}}, + {Account: stakingtypes.BondedPoolName, Permissions: []string{authtypes.Burner, stakingtypes.ModuleName}}, + {Account: stakingtypes.NotBondedPoolName, Permissions: []string{authtypes.Burner, stakingtypes.ModuleName}}, + }, + }), + }, + { + Name: "bank", + Config: appconfig.WrapAny(&bankmodulev1.Module{}), + }, + { + Name: "params", + Config: appconfig.WrapAny(¶msmodulev1.Module{}), + }, + { + Name: "staking", + Config: appconfig.WrapAny(&stakingmodulev1.Module{}), + }, + { + Name: "mint", + Config: appconfig.WrapAny(&mintmodulev1.Module{}), + }, + { + Name: "consensus", + Config: appconfig.WrapAny(&consensusmodulev1.Module{}), + }, + { + Name: "tx", + Config: appconfig.WrapAny(&txconfigv1.Config{}), + }, + }, + }) +} + +func makeMinimalConfig() depinject.Config { + var mempoolOpt runtime.BaseAppOption = baseapp.SetMempool(mempool.NewSenderNonceMempool()) + return depinject.Configs( + depinject.Supply(mempoolOpt), + appconfig.Compose(&appv1alpha1.Config{ + Modules: []*appv1alpha1.ModuleConfig{ + { + Name: "runtime", + Config: appconfig.WrapAny(&runtimev1alpha1.Module{ + AppName: "BaseAppApp", + }), + }, + }, + })) +} + type MsgKeyValueImpl struct{} func (m MsgKeyValueImpl) Set(ctx context.Context, msg *baseapptestutil.MsgKeyValue) (*baseapptestutil.MsgCreateKeyValueResponse, error) { From ed5eb8ae2f8db0841495b8cb05647e7e974f7dbc Mon Sep 17 00:00:00 2001 From: Facundo Medica Date: Wed, 21 Dec 2022 11:21:38 -0300 Subject: [PATCH 7/9] Revert "factorize setState functions (from Amaury's notes)" This reverts commit fd0b844f4eb6ef3356a853a0195862d9e2144da8. --- baseapp/abci.go | 16 +++++------ baseapp/baseapp.go | 67 +++++++++++++++++++++++++++++----------------- 2 files changed, 50 insertions(+), 33 deletions(-) diff --git a/baseapp/abci.go b/baseapp/abci.go index ec1201737961..695047bbbb39 100644 --- a/baseapp/abci.go +++ b/baseapp/abci.go @@ -52,10 +52,10 @@ func (app *BaseApp) InitChain(req abci.RequestInitChain) (res abci.ResponseInitC } // initialize states with a correct header - app.setState(runTxModeDeliver, initHeader) - app.setState(runTxModeCheck, initHeader) - app.setState(runTxPrepareProposal, initHeader) - app.setState(runTxProcessProposal, initHeader) + app.setDeliverState(initHeader) + app.setCheckState(initHeader) + app.setPrepareProposalState(initHeader) + app.setProcessProposalState(initHeader) // Store the consensus params in the BaseApp's paramstore. Note, this must be // done after the deliver state and context have been set as it's persisted @@ -162,7 +162,7 @@ func (app *BaseApp) BeginBlock(req abci.RequestBeginBlock) (res abci.ResponseBeg // already be initialized in InitChain. Otherwise app.deliverState will be // nil, since it is reset on Commit. if app.deliverState == nil { - app.setState(runTxModeDeliver, req.Header) + app.setDeliverState(req.Header) } else { // In the first block, app.deliverState.ctx will already be initialized // by InitChain. Context is now updated with Header information. @@ -392,9 +392,9 @@ func (app *BaseApp) Commit() abci.ResponseCommit { // // NOTE: This is safe because Tendermint holds a lock on the mempool for // Commit. Use the header from this latest block. - app.setState(runTxModeCheck, header) - app.setState(runTxPrepareProposal, header) - app.setState(runTxProcessProposal, header) + app.setCheckState(header) + app.setPrepareProposalState(header) + app.setProcessProposalState(header) // empty/reset the deliver state app.deliverState = nil diff --git a/baseapp/baseapp.go b/baseapp/baseapp.go index 7bc837a2878a..cf20054f477a 100644 --- a/baseapp/baseapp.go +++ b/baseapp/baseapp.go @@ -350,11 +350,11 @@ func (app *BaseApp) Init() error { emptyHeader := tmproto.Header{} // needed for the export command which inits from store but never calls initchain - app.setState(runTxModeCheck, emptyHeader) + app.setCheckState(emptyHeader) // needed for ABCI Replay Blocks mode which calls Prepare/Process proposal (InitChain is not called) - app.setState(runTxPrepareProposal, emptyHeader) - app.setState(runTxProcessProposal, emptyHeader) + app.setPrepareProposalState(emptyHeader) + app.setProcessProposalState(emptyHeader) app.Seal() if app.cms == nil { @@ -402,32 +402,49 @@ func (app *BaseApp) Seal() { app.sealed = true } // IsSealed returns true if the BaseApp is sealed and false otherwise. func (app *BaseApp) IsSealed() bool { return app.sealed } -// setState sets the BaseApp's state for the corresponding mode with a branched -// multi-store (i.e. a CacheMultiStore) and a new Context with the same -// multi-store branch, and provided header. -func (app *BaseApp) setState(mode runTxMode, header tmproto.Header) { +// setCheckState sets the BaseApp's checkState with a branched multi-store +// (i.e. a CacheMultiStore) and a new Context with the same multi-store branch, +// provided header, and minimum gas prices set. It is set on InitChain and reset +// on Commit. +func (app *BaseApp) setCheckState(header tmproto.Header) { ms := app.cms.CacheMultiStore() - baseState := &state{ - ms: app.cms.CacheMultiStore(), + app.checkState = &state{ + ms: ms, + ctx: sdk.NewContext(ms, header, true, app.logger).WithMinGasPrices(app.minGasPrices), + } +} + +// setDeliverState sets the BaseApp's deliverState with a branched multi-store +// (i.e. a CacheMultiStore) and a new Context with the same multi-store branch, +// and provided header. It is set on InitChain and BeginBlock and set to nil on +// Commit. +func (app *BaseApp) setDeliverState(header tmproto.Header) { + ms := app.cms.CacheMultiStore() + app.deliverState = &state{ + ms: ms, ctx: sdk.NewContext(ms, header, false, app.logger), } +} - switch mode { - case runTxModeCheck: - // Minimum gas prices are also set. It is set on InitChain and reset on Commit. - baseState.ctx = baseState.ctx.WithIsCheckTx(true).WithMinGasPrices(app.minGasPrices) - app.checkState = baseState - case runTxModeDeliver: - // It is set on InitChain and BeginBlock and set to nil on Commit. - app.deliverState = baseState - case runTxPrepareProposal: - // It is set on InitChain and Commit. - app.prepareProposalState = baseState - case runTxProcessProposal: - // It is set on InitChain and Commit. - app.processProposalState = baseState - default: - panic(fmt.Sprintf("invalid runTxMode for setState: %d", mode)) +// setPrepareProposalState sets the BaseApp's prepareProposalState with a +// branched multi-store (i.e. a CacheMultiStore) and a new Context with the +// same multi-store branch, and provided header. It is set on InitChain and Commit. +func (app *BaseApp) setPrepareProposalState(header tmproto.Header) { + ms := app.cms.CacheMultiStore() + app.prepareProposalState = &state{ + ms: ms, + ctx: sdk.NewContext(ms, header, false, app.logger), + } +} + +// setProcessProposalState sets the BaseApp's processProposalState with a +// branched multi-store (i.e. a CacheMultiStore) and a new Context with the +// same multi-store branch, and provided header. It is set on InitChain and Commit. +func (app *BaseApp) setProcessProposalState(header tmproto.Header) { + ms := app.cms.CacheMultiStore() + app.processProposalState = &state{ + ms: ms, + ctx: sdk.NewContext(ms, header, false, app.logger), } } From 56e4e6a26387f4cbce0c299c7d3d61a71351b2de Mon Sep 17 00:00:00 2001 From: Facundo Medica Date: Wed, 21 Dec 2022 11:27:58 -0300 Subject: [PATCH 8/9] Revert "Revert "factorize setState functions (from Amaury's notes)"" This reverts commit ed5eb8ae2f8db0841495b8cb05647e7e974f7dbc. --- baseapp/abci.go | 16 +++++------ baseapp/baseapp.go | 67 +++++++++++++++++----------------------------- 2 files changed, 33 insertions(+), 50 deletions(-) diff --git a/baseapp/abci.go b/baseapp/abci.go index 695047bbbb39..ec1201737961 100644 --- a/baseapp/abci.go +++ b/baseapp/abci.go @@ -52,10 +52,10 @@ func (app *BaseApp) InitChain(req abci.RequestInitChain) (res abci.ResponseInitC } // initialize states with a correct header - app.setDeliverState(initHeader) - app.setCheckState(initHeader) - app.setPrepareProposalState(initHeader) - app.setProcessProposalState(initHeader) + app.setState(runTxModeDeliver, initHeader) + app.setState(runTxModeCheck, initHeader) + app.setState(runTxPrepareProposal, initHeader) + app.setState(runTxProcessProposal, initHeader) // Store the consensus params in the BaseApp's paramstore. Note, this must be // done after the deliver state and context have been set as it's persisted @@ -162,7 +162,7 @@ func (app *BaseApp) BeginBlock(req abci.RequestBeginBlock) (res abci.ResponseBeg // already be initialized in InitChain. Otherwise app.deliverState will be // nil, since it is reset on Commit. if app.deliverState == nil { - app.setDeliverState(req.Header) + app.setState(runTxModeDeliver, req.Header) } else { // In the first block, app.deliverState.ctx will already be initialized // by InitChain. Context is now updated with Header information. @@ -392,9 +392,9 @@ func (app *BaseApp) Commit() abci.ResponseCommit { // // NOTE: This is safe because Tendermint holds a lock on the mempool for // Commit. Use the header from this latest block. - app.setCheckState(header) - app.setPrepareProposalState(header) - app.setProcessProposalState(header) + app.setState(runTxModeCheck, header) + app.setState(runTxPrepareProposal, header) + app.setState(runTxProcessProposal, header) // empty/reset the deliver state app.deliverState = nil diff --git a/baseapp/baseapp.go b/baseapp/baseapp.go index cf20054f477a..7bc837a2878a 100644 --- a/baseapp/baseapp.go +++ b/baseapp/baseapp.go @@ -350,11 +350,11 @@ func (app *BaseApp) Init() error { emptyHeader := tmproto.Header{} // needed for the export command which inits from store but never calls initchain - app.setCheckState(emptyHeader) + app.setState(runTxModeCheck, emptyHeader) // needed for ABCI Replay Blocks mode which calls Prepare/Process proposal (InitChain is not called) - app.setPrepareProposalState(emptyHeader) - app.setProcessProposalState(emptyHeader) + app.setState(runTxPrepareProposal, emptyHeader) + app.setState(runTxProcessProposal, emptyHeader) app.Seal() if app.cms == nil { @@ -402,49 +402,32 @@ func (app *BaseApp) Seal() { app.sealed = true } // IsSealed returns true if the BaseApp is sealed and false otherwise. func (app *BaseApp) IsSealed() bool { return app.sealed } -// setCheckState sets the BaseApp's checkState with a branched multi-store -// (i.e. a CacheMultiStore) and a new Context with the same multi-store branch, -// provided header, and minimum gas prices set. It is set on InitChain and reset -// on Commit. -func (app *BaseApp) setCheckState(header tmproto.Header) { +// setState sets the BaseApp's state for the corresponding mode with a branched +// multi-store (i.e. a CacheMultiStore) and a new Context with the same +// multi-store branch, and provided header. +func (app *BaseApp) setState(mode runTxMode, header tmproto.Header) { ms := app.cms.CacheMultiStore() - app.checkState = &state{ - ms: ms, - ctx: sdk.NewContext(ms, header, true, app.logger).WithMinGasPrices(app.minGasPrices), - } -} - -// setDeliverState sets the BaseApp's deliverState with a branched multi-store -// (i.e. a CacheMultiStore) and a new Context with the same multi-store branch, -// and provided header. It is set on InitChain and BeginBlock and set to nil on -// Commit. -func (app *BaseApp) setDeliverState(header tmproto.Header) { - ms := app.cms.CacheMultiStore() - app.deliverState = &state{ - ms: ms, + baseState := &state{ + ms: app.cms.CacheMultiStore(), ctx: sdk.NewContext(ms, header, false, app.logger), } -} -// setPrepareProposalState sets the BaseApp's prepareProposalState with a -// branched multi-store (i.e. a CacheMultiStore) and a new Context with the -// same multi-store branch, and provided header. It is set on InitChain and Commit. -func (app *BaseApp) setPrepareProposalState(header tmproto.Header) { - ms := app.cms.CacheMultiStore() - app.prepareProposalState = &state{ - ms: ms, - ctx: sdk.NewContext(ms, header, false, app.logger), - } -} - -// setProcessProposalState sets the BaseApp's processProposalState with a -// branched multi-store (i.e. a CacheMultiStore) and a new Context with the -// same multi-store branch, and provided header. It is set on InitChain and Commit. -func (app *BaseApp) setProcessProposalState(header tmproto.Header) { - ms := app.cms.CacheMultiStore() - app.processProposalState = &state{ - ms: ms, - ctx: sdk.NewContext(ms, header, false, app.logger), + switch mode { + case runTxModeCheck: + // Minimum gas prices are also set. It is set on InitChain and reset on Commit. + baseState.ctx = baseState.ctx.WithIsCheckTx(true).WithMinGasPrices(app.minGasPrices) + app.checkState = baseState + case runTxModeDeliver: + // It is set on InitChain and BeginBlock and set to nil on Commit. + app.deliverState = baseState + case runTxPrepareProposal: + // It is set on InitChain and Commit. + app.prepareProposalState = baseState + case runTxProcessProposal: + // It is set on InitChain and Commit. + app.processProposalState = baseState + default: + panic(fmt.Sprintf("invalid runTxMode for setState: %d", mode)) } } From c2270805db801f371054931da13fc57a5ca882e0 Mon Sep 17 00:00:00 2001 From: Facundo Medica Date: Wed, 21 Dec 2022 11:37:39 -0300 Subject: [PATCH 9/9] found issue in setState --- baseapp/baseapp.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/baseapp/baseapp.go b/baseapp/baseapp.go index 7bc837a2878a..1e95dac964ee 100644 --- a/baseapp/baseapp.go +++ b/baseapp/baseapp.go @@ -408,7 +408,7 @@ func (app *BaseApp) IsSealed() bool { return app.sealed } func (app *BaseApp) setState(mode runTxMode, header tmproto.Header) { ms := app.cms.CacheMultiStore() baseState := &state{ - ms: app.cms.CacheMultiStore(), + ms: ms, ctx: sdk.NewContext(ms, header, false, app.logger), }