From e01c99d0199f950fc33ee6c7454cc5d5563ff0f2 Mon Sep 17 00:00:00 2001 From: Jonathan Gimeno Date: Thu, 5 Mar 2020 11:45:51 +0100 Subject: [PATCH 1/9] now it creates the module account on InitChain --- simapp/app.go | 4 ++-- x/mint/genesis.go | 5 ++++- x/mint/module.go | 12 +++++++++--- x/mint/module_test.go | 29 +++++++++++++++++++++++++++++ x/mint/types/expected_keepers.go | 1 + 5 files changed, 45 insertions(+), 6 deletions(-) create mode 100644 x/mint/module_test.go diff --git a/simapp/app.go b/simapp/app.go index 5408bcfe9..56aaae8d8 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -226,7 +226,7 @@ func NewSimApp( crisis.NewAppModule(&app.CrisisKeeper), supply.NewAppModule(app.SupplyKeeper, app.BankKeeper, app.AccountKeeper), gov.NewAppModule(app.GovKeeper, app.AccountKeeper, app.BankKeeper, app.SupplyKeeper), - mint.NewAppModule(app.MintKeeper), + mint.NewAppModule(app.MintKeeper, app.SupplyKeeper), slashing.NewAppModule(app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper), distr.NewAppModule(app.DistrKeeper, app.AccountKeeper, app.BankKeeper, app.SupplyKeeper, app.StakingKeeper), staking.NewAppModule(app.StakingKeeper, app.AccountKeeper, app.BankKeeper, app.SupplyKeeper), @@ -260,7 +260,7 @@ func NewSimApp( bank.NewAppModule(app.BankKeeper, app.AccountKeeper), supply.NewAppModule(app.SupplyKeeper, app.BankKeeper, app.AccountKeeper), gov.NewAppModule(app.GovKeeper, app.AccountKeeper, app.BankKeeper, app.SupplyKeeper), - mint.NewAppModule(app.MintKeeper), + mint.NewAppModule(app.MintKeeper, app.SupplyKeeper), staking.NewAppModule(app.StakingKeeper, app.AccountKeeper, app.BankKeeper, app.SupplyKeeper), distr.NewAppModule(app.DistrKeeper, app.AccountKeeper, app.BankKeeper, app.SupplyKeeper, app.StakingKeeper), slashing.NewAppModule(app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper), diff --git a/x/mint/genesis.go b/x/mint/genesis.go index 331852b43..44e0a5ee1 100644 --- a/x/mint/genesis.go +++ b/x/mint/genesis.go @@ -2,12 +2,15 @@ package mint import ( sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/mint/types" ) // InitGenesis new mint genesis -func InitGenesis(ctx sdk.Context, keeper Keeper, data GenesisState) { +func InitGenesis(ctx sdk.Context, keeper Keeper, supplyKeeper types.SupplyKeeper, data GenesisState) { keeper.SetMinter(ctx, data.Minter) keeper.SetParams(ctx, data.Params) + + supplyKeeper.GetModuleAccount(ctx, ModuleName) } // ExportGenesis returns a GenesisState for a given context and keeper. diff --git a/x/mint/module.go b/x/mint/module.go index 53bd8fff1..88c03dfea 100644 --- a/x/mint/module.go +++ b/x/mint/module.go @@ -5,6 +5,8 @@ import ( "fmt" "math/rand" + "github.com/cosmos/cosmos-sdk/x/mint/types" + "github.com/gorilla/mux" "github.com/spf13/cobra" @@ -74,14 +76,16 @@ func (AppModuleBasic) GetQueryCmd(cdc *codec.Codec) *cobra.Command { type AppModule struct { AppModuleBasic - keeper Keeper + keeper Keeper + supplyKeeper types.SupplyKeeper } // NewAppModule creates a new AppModule object -func NewAppModule(keeper Keeper) AppModule { +func NewAppModule(keeper Keeper, supplyKeeper types.SupplyKeeper) AppModule { return AppModule{ AppModuleBasic: AppModuleBasic{}, keeper: keeper, + supplyKeeper: supplyKeeper, } } @@ -114,7 +118,9 @@ func (am AppModule) NewQuerierHandler() sdk.Querier { func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONMarshaler, data json.RawMessage) []abci.ValidatorUpdate { var genesisState GenesisState cdc.MustUnmarshalJSON(data, &genesisState) - InitGenesis(ctx, am.keeper, genesisState) + + InitGenesis(ctx, am.keeper, am.supplyKeeper, genesisState) + return []abci.ValidatorUpdate{} } diff --git a/x/mint/module_test.go b/x/mint/module_test.go new file mode 100644 index 000000000..448d2f6b0 --- /dev/null +++ b/x/mint/module_test.go @@ -0,0 +1,29 @@ +package mint_test + +import ( + "testing" + + "github.com/cosmos/cosmos-sdk/x/mint" + "github.com/cosmos/cosmos-sdk/x/supply" + "github.com/stretchr/testify/assert" + + "github.com/tendermint/tendermint/abci/types" + + "github.com/cosmos/cosmos-sdk/simapp" +) + +func TestItCreatesModuleAccountOnInitBlock(t *testing.T) { + app := simapp.Setup(false) + ctx := app.BaseApp.NewContext(false, types.Header{}) + + app.InitChain( + types.RequestInitChain{ + AppStateBytes: []byte("{}"), + ChainId: "test-chain-id", + }, + ) + + acc := app.AccountKeeper.GetAccount(ctx, supply.NewModuleAddress(mint.ModuleName)) + + assert.NotNil(t, acc) +} diff --git a/x/mint/types/expected_keepers.go b/x/mint/types/expected_keepers.go index ea2061916..104a28602 100644 --- a/x/mint/types/expected_keepers.go +++ b/x/mint/types/expected_keepers.go @@ -17,6 +17,7 @@ type SupplyKeeper interface { // TODO remove with genesis 2-phases refactor https://github.com/cosmos/cosmos-sdk/issues/2862 SetModuleAccount(sdk.Context, exported.ModuleAccountI) + GetModuleAccount(ctx sdk.Context, moduleName string) exported.ModuleAccountI SendCoinsFromModuleToAccount(ctx sdk.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error SendCoinsFromModuleToModule(ctx sdk.Context, senderModule, recipientModule string, amt sdk.Coins) error From 29abc244eb9a8c7407871b0b5481fda8c7f7464f Mon Sep 17 00:00:00 2001 From: Jonathan Gimeno Date: Thu, 5 Mar 2020 11:56:39 +0100 Subject: [PATCH 2/9] make private methods that does not need to be exported --- x/mint/abci.go | 2 +- x/mint/genesis.go | 8 ++++---- x/mint/module.go | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/x/mint/abci.go b/x/mint/abci.go index 21595b466..6d77dcc02 100644 --- a/x/mint/abci.go +++ b/x/mint/abci.go @@ -6,7 +6,7 @@ import ( ) // BeginBlocker mints new tokens for the previous block. -func BeginBlocker(ctx sdk.Context, k Keeper) { +func beginBlocker(ctx sdk.Context, k Keeper) { // fetch stored minter & params minter := k.GetMinter(ctx) params := k.GetParams(ctx) diff --git a/x/mint/genesis.go b/x/mint/genesis.go index 44e0a5ee1..fb07680d3 100644 --- a/x/mint/genesis.go +++ b/x/mint/genesis.go @@ -5,16 +5,16 @@ import ( "github.com/cosmos/cosmos-sdk/x/mint/types" ) -// InitGenesis new mint genesis -func InitGenesis(ctx sdk.Context, keeper Keeper, supplyKeeper types.SupplyKeeper, data GenesisState) { +// initGenesis new mint genesis +func initGenesis(ctx sdk.Context, keeper Keeper, supplyKeeper types.SupplyKeeper, data GenesisState) { keeper.SetMinter(ctx, data.Minter) keeper.SetParams(ctx, data.Params) supplyKeeper.GetModuleAccount(ctx, ModuleName) } -// ExportGenesis returns a GenesisState for a given context and keeper. -func ExportGenesis(ctx sdk.Context, keeper Keeper) GenesisState { +// exportGenesis returns a GenesisState for a given context and keeper. +func exportGenesis(ctx sdk.Context, keeper Keeper) GenesisState { minter := keeper.GetMinter(ctx) params := keeper.GetParams(ctx) return NewGenesisState(minter, params) diff --git a/x/mint/module.go b/x/mint/module.go index 88c03dfea..8e9ca590c 100644 --- a/x/mint/module.go +++ b/x/mint/module.go @@ -119,7 +119,7 @@ func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONMarshaler, data j var genesisState GenesisState cdc.MustUnmarshalJSON(data, &genesisState) - InitGenesis(ctx, am.keeper, am.supplyKeeper, genesisState) + initGenesis(ctx, am.keeper, am.supplyKeeper, genesisState) return []abci.ValidatorUpdate{} } @@ -127,13 +127,13 @@ func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONMarshaler, data j // ExportGenesis returns the exported genesis state as raw bytes for the mint // module. func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONMarshaler) json.RawMessage { - gs := ExportGenesis(ctx, am.keeper) + gs := exportGenesis(ctx, am.keeper) return cdc.MustMarshalJSON(gs) } // BeginBlock returns the begin blocker for the mint module. func (am AppModule) BeginBlock(ctx sdk.Context, _ abci.RequestBeginBlock) { - BeginBlocker(ctx, am.keeper) + beginBlocker(ctx, am.keeper) } // EndBlock returns the end blocker for the mint module. It returns no validator From 626cc1973d7f4a0f92c737d173c087c73044c165 Mon Sep 17 00:00:00 2001 From: Jonathan Gimeno Date: Thu, 5 Mar 2020 12:17:18 +0100 Subject: [PATCH 3/9] update changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 19934bee5..856528154 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -62,6 +62,8 @@ and provided directly the IAVL store. * (types) [\#5533](https://github.com/cosmos/cosmos-sdk/pull/5533) Refactored `AppModuleBasic` and `AppModuleGenesis` to now accept a `codec.JSONMarshaler` for modular serialization of genesis state. * (crypto/keys) [\#5735](https://github.com/cosmos/cosmos-sdk/pull/5735) Keyring's Update() function is now no-op. +* (x/mint) [\#5569](https://github.com/cosmos/cosmos-sdk/issues/5569) `AppModule` now requires SupplyKeeper in its constructor to create +module account on `InitGenesis`. ### Features From ccb0062560e737bec3c1d83b45726ea0c688c88f Mon Sep 17 00:00:00 2001 From: Jonathan Gimeno Date: Thu, 5 Mar 2020 12:18:04 +0100 Subject: [PATCH 4/9] update changelog --- x/mint/abci.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/mint/abci.go b/x/mint/abci.go index 6d77dcc02..c87f8ef2d 100644 --- a/x/mint/abci.go +++ b/x/mint/abci.go @@ -5,7 +5,7 @@ import ( "github.com/cosmos/cosmos-sdk/x/mint/types" ) -// BeginBlocker mints new tokens for the previous block. +// beginBlocker mints new tokens for the previous block. func beginBlocker(ctx sdk.Context, k Keeper) { // fetch stored minter & params minter := k.GetMinter(ctx) From 643b10982620cb7ce0151d6297f3b7d72da11219 Mon Sep 17 00:00:00 2001 From: Jonathan Gimeno Date: Thu, 5 Mar 2020 16:15:53 +0100 Subject: [PATCH 5/9] change assert by require --- x/mint/module_test.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/x/mint/module_test.go b/x/mint/module_test.go index 448d2f6b0..8b283b032 100644 --- a/x/mint/module_test.go +++ b/x/mint/module_test.go @@ -3,13 +3,13 @@ package mint_test import ( "testing" - "github.com/cosmos/cosmos-sdk/x/mint" - "github.com/cosmos/cosmos-sdk/x/supply" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/tendermint/tendermint/abci/types" "github.com/cosmos/cosmos-sdk/simapp" + "github.com/cosmos/cosmos-sdk/x/mint" + "github.com/cosmos/cosmos-sdk/x/supply" ) func TestItCreatesModuleAccountOnInitBlock(t *testing.T) { @@ -24,6 +24,5 @@ func TestItCreatesModuleAccountOnInitBlock(t *testing.T) { ) acc := app.AccountKeeper.GetAccount(ctx, supply.NewModuleAddress(mint.ModuleName)) - - assert.NotNil(t, acc) + require.NotNil(t, acc) } From 60031bbc9b9738b6a4fdb69e67a3c44ac123cc01 Mon Sep 17 00:00:00 2001 From: Jonathan Gimeno Date: Thu, 5 Mar 2020 16:19:36 +0100 Subject: [PATCH 6/9] re-public methods --- x/mint/abci.go | 4 ++-- x/mint/genesis.go | 8 ++++---- x/mint/module.go | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/x/mint/abci.go b/x/mint/abci.go index c87f8ef2d..21595b466 100644 --- a/x/mint/abci.go +++ b/x/mint/abci.go @@ -5,8 +5,8 @@ import ( "github.com/cosmos/cosmos-sdk/x/mint/types" ) -// beginBlocker mints new tokens for the previous block. -func beginBlocker(ctx sdk.Context, k Keeper) { +// BeginBlocker mints new tokens for the previous block. +func BeginBlocker(ctx sdk.Context, k Keeper) { // fetch stored minter & params minter := k.GetMinter(ctx) params := k.GetParams(ctx) diff --git a/x/mint/genesis.go b/x/mint/genesis.go index fb07680d3..44e0a5ee1 100644 --- a/x/mint/genesis.go +++ b/x/mint/genesis.go @@ -5,16 +5,16 @@ import ( "github.com/cosmos/cosmos-sdk/x/mint/types" ) -// initGenesis new mint genesis -func initGenesis(ctx sdk.Context, keeper Keeper, supplyKeeper types.SupplyKeeper, data GenesisState) { +// InitGenesis new mint genesis +func InitGenesis(ctx sdk.Context, keeper Keeper, supplyKeeper types.SupplyKeeper, data GenesisState) { keeper.SetMinter(ctx, data.Minter) keeper.SetParams(ctx, data.Params) supplyKeeper.GetModuleAccount(ctx, ModuleName) } -// exportGenesis returns a GenesisState for a given context and keeper. -func exportGenesis(ctx sdk.Context, keeper Keeper) GenesisState { +// ExportGenesis returns a GenesisState for a given context and keeper. +func ExportGenesis(ctx sdk.Context, keeper Keeper) GenesisState { minter := keeper.GetMinter(ctx) params := keeper.GetParams(ctx) return NewGenesisState(minter, params) diff --git a/x/mint/module.go b/x/mint/module.go index 8e9ca590c..88c03dfea 100644 --- a/x/mint/module.go +++ b/x/mint/module.go @@ -119,7 +119,7 @@ func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONMarshaler, data j var genesisState GenesisState cdc.MustUnmarshalJSON(data, &genesisState) - initGenesis(ctx, am.keeper, am.supplyKeeper, genesisState) + InitGenesis(ctx, am.keeper, am.supplyKeeper, genesisState) return []abci.ValidatorUpdate{} } @@ -127,13 +127,13 @@ func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONMarshaler, data j // ExportGenesis returns the exported genesis state as raw bytes for the mint // module. func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONMarshaler) json.RawMessage { - gs := exportGenesis(ctx, am.keeper) + gs := ExportGenesis(ctx, am.keeper) return cdc.MustMarshalJSON(gs) } // BeginBlock returns the begin blocker for the mint module. func (am AppModule) BeginBlock(ctx sdk.Context, _ abci.RequestBeginBlock) { - beginBlocker(ctx, am.keeper) + BeginBlocker(ctx, am.keeper) } // EndBlock returns the end blocker for the mint module. It returns no validator From ba099998f6e564f38a0b0018e48f7e7cab6bfc06 Mon Sep 17 00:00:00 2001 From: Jonathan Gimeno Date: Thu, 5 Mar 2020 16:36:36 +0100 Subject: [PATCH 7/9] Clarify what happens with GetModuleAccount method. --- x/supply/keeper/account.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/x/supply/keeper/account.go b/x/supply/keeper/account.go index 685308cf6..fdf8f9aff 100644 --- a/x/supply/keeper/account.go +++ b/x/supply/keeper/account.go @@ -49,7 +49,8 @@ func (k Keeper) GetModuleAccountAndPermissions(ctx sdk.Context, moduleName strin return maccI, perms } -// GetModuleAccount gets the module account from the auth account store +// GetModuleAccount gets the module account from the auth account store, if the account does not +// exist in the AccountKeeper, then it is created. func (k Keeper) GetModuleAccount(ctx sdk.Context, moduleName string) exported.ModuleAccountI { acc, _ := k.GetModuleAccountAndPermissions(ctx, moduleName) return acc From e45be08eb1a6e834c73728f40940777323bb195a Mon Sep 17 00:00:00 2001 From: Jonathan Gimeno Date: Thu, 5 Mar 2020 22:11:05 +0100 Subject: [PATCH 8/9] create module account on init for FeeCollectorName and tests for other module accounts --- CHANGELOG.md | 6 ++++-- simapp/app.go | 4 ++-- x/auth/genesis.go | 5 ++++- x/auth/module.go | 6 ++++-- x/auth/module_test.go | 27 +++++++++++++++++++++++++++ x/distribution/module_test.go | 27 +++++++++++++++++++++++++++ x/gov/module_test.go | 29 +++++++++++++++++++++++++++++ x/staking/module_test.go | 31 +++++++++++++++++++++++++++++++ 8 files changed, 128 insertions(+), 7 deletions(-) create mode 100644 x/auth/module_test.go create mode 100644 x/distribution/module_test.go create mode 100644 x/gov/module_test.go create mode 100644 x/staking/module_test.go diff --git a/CHANGELOG.md b/CHANGELOG.md index 856528154..aaf108ce6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -62,8 +62,6 @@ and provided directly the IAVL store. * (types) [\#5533](https://github.com/cosmos/cosmos-sdk/pull/5533) Refactored `AppModuleBasic` and `AppModuleGenesis` to now accept a `codec.JSONMarshaler` for modular serialization of genesis state. * (crypto/keys) [\#5735](https://github.com/cosmos/cosmos-sdk/pull/5735) Keyring's Update() function is now no-op. -* (x/mint) [\#5569](https://github.com/cosmos/cosmos-sdk/issues/5569) `AppModule` now requires SupplyKeeper in its constructor to create -module account on `InitGenesis`. ### Features @@ -77,6 +75,10 @@ resulted in a panic when the tx execution mode was `CheckTx`. * (x/distribution) [\#5620](https://github.com/cosmos/cosmos-sdk/pull/5620) Fix nil pointer deref in distribution tax/rewward validation helpers. * (genesis) [\#5086](https://github.com/cosmos/cosmos-sdk/issues/5086) Ensure `gentxs` are always an empty array instead of `nil` * (types) [\#5741](https://github.com/cosmos/cosmos-sdk/issues/5741) Prevent ChainAnteDecorators() from panicking when empty AnteDecorator slice is supplied. +* (x/mint) [\#5569](https://github.com/cosmos/cosmos-sdk/issues/5569) Create Mint Module account on InitGenesis. `AppModule` now requires SupplyKeeper in its constructor to create +module account on `InitGenesis`. +* (x/auth) [\#5569](https://github.com/cosmos/cosmos-sdk/issues/5569) Create FeeCollectorName Module account on InitGenesis. `AppModule` now requires SupplyKeeper in its constructor to create +module account on `InitGenesis`. ### State Machine Breaking diff --git a/simapp/app.go b/simapp/app.go index 56aaae8d8..f7d9f30d7 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -221,7 +221,7 @@ func NewSimApp( // must be passed by reference here. app.mm = module.NewManager( genutil.NewAppModule(app.AccountKeeper, app.StakingKeeper, app.BaseApp.DeliverTx), - auth.NewAppModule(app.AccountKeeper), + auth.NewAppModule(app.AccountKeeper, app.SupplyKeeper), bank.NewAppModule(app.BankKeeper, app.AccountKeeper), crisis.NewAppModule(&app.CrisisKeeper), supply.NewAppModule(app.SupplyKeeper, app.BankKeeper, app.AccountKeeper), @@ -256,7 +256,7 @@ func NewSimApp( // NOTE: this is not required apps that don't use the simulator for fuzz testing // transactions app.sm = module.NewSimulationManager( - auth.NewAppModule(app.AccountKeeper), + auth.NewAppModule(app.AccountKeeper, app.SupplyKeeper), bank.NewAppModule(app.BankKeeper, app.AccountKeeper), supply.NewAppModule(app.SupplyKeeper, app.BankKeeper, app.AccountKeeper), gov.NewAppModule(app.GovKeeper, app.AccountKeeper, app.BankKeeper, app.SupplyKeeper), diff --git a/x/auth/genesis.go b/x/auth/genesis.go index 22db3557d..420bdba09 100644 --- a/x/auth/genesis.go +++ b/x/auth/genesis.go @@ -3,13 +3,14 @@ package auth import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth/exported" + "github.com/cosmos/cosmos-sdk/x/auth/types" ) // InitGenesis - Init store state from genesis data // // CONTRACT: old coins from the FeeCollectionKeeper need to be transferred through // a genesis port script to the new fee collector account -func InitGenesis(ctx sdk.Context, ak AccountKeeper, data GenesisState) { +func InitGenesis(ctx sdk.Context, ak AccountKeeper, sk types.SupplyKeeper, data GenesisState) { ak.SetParams(ctx, data.Params) data.Accounts = SanitizeGenesisAccounts(data.Accounts) @@ -17,6 +18,8 @@ func InitGenesis(ctx sdk.Context, ak AccountKeeper, data GenesisState) { acc := ak.NewAccount(ctx, a) ak.SetAccount(ctx, acc) } + + sk.GetModuleAccount(ctx, FeeCollectorName) } // ExportGenesis returns a GenesisState for a given context and keeper diff --git a/x/auth/module.go b/x/auth/module.go index c5adc5811..910a54a2b 100644 --- a/x/auth/module.go +++ b/x/auth/module.go @@ -77,13 +77,15 @@ type AppModule struct { AppModuleBasic accountKeeper AccountKeeper + supplyKeeper types.SupplyKeeper } // NewAppModule creates a new AppModule object -func NewAppModule(accountKeeper AccountKeeper) AppModule { +func NewAppModule(accountKeeper AccountKeeper, supplyKeeper types.SupplyKeeper) AppModule { return AppModule{ AppModuleBasic: AppModuleBasic{}, accountKeeper: accountKeeper, + supplyKeeper: supplyKeeper, } } @@ -116,7 +118,7 @@ func (am AppModule) NewQuerierHandler() sdk.Querier { func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONMarshaler, data json.RawMessage) []abci.ValidatorUpdate { var genesisState GenesisState cdc.MustUnmarshalJSON(data, &genesisState) - InitGenesis(ctx, am.accountKeeper, genesisState) + InitGenesis(ctx, am.accountKeeper, am.supplyKeeper, genesisState) return []abci.ValidatorUpdate{} } diff --git a/x/auth/module_test.go b/x/auth/module_test.go new file mode 100644 index 000000000..b49c407b9 --- /dev/null +++ b/x/auth/module_test.go @@ -0,0 +1,27 @@ +package auth_test + +import ( + "testing" + + "github.com/stretchr/testify/require" + "github.com/tendermint/tendermint/abci/types" + + "github.com/cosmos/cosmos-sdk/simapp" + "github.com/cosmos/cosmos-sdk/x/auth" + "github.com/cosmos/cosmos-sdk/x/supply" +) + +func TestItCreatesModuleAccountOnInitBlock(t *testing.T) { + app := simapp.Setup(false) + ctx := app.BaseApp.NewContext(false, types.Header{}) + + app.InitChain( + types.RequestInitChain{ + AppStateBytes: []byte("{}"), + ChainId: "test-chain-id", + }, + ) + + acc := app.AccountKeeper.GetAccount(ctx, supply.NewModuleAddress(auth.FeeCollectorName)) + require.NotNil(t, acc) +} diff --git a/x/distribution/module_test.go b/x/distribution/module_test.go new file mode 100644 index 000000000..83bf1b0ef --- /dev/null +++ b/x/distribution/module_test.go @@ -0,0 +1,27 @@ +package distribution_test + +import ( + "testing" + + "github.com/cosmos/cosmos-sdk/x/distribution" + + "github.com/cosmos/cosmos-sdk/simapp" + "github.com/cosmos/cosmos-sdk/x/supply" + "github.com/stretchr/testify/require" + "github.com/tendermint/tendermint/abci/types" +) + +func TestItCreatesModuleAccountOnInitBlock(t *testing.T) { + app := simapp.Setup(false) + ctx := app.BaseApp.NewContext(false, types.Header{}) + + app.InitChain( + types.RequestInitChain{ + AppStateBytes: []byte("{}"), + ChainId: "test-chain-id", + }, + ) + + acc := app.AccountKeeper.GetAccount(ctx, supply.NewModuleAddress(distribution.ModuleName)) + require.NotNil(t, acc) +} diff --git a/x/gov/module_test.go b/x/gov/module_test.go new file mode 100644 index 000000000..59794489f --- /dev/null +++ b/x/gov/module_test.go @@ -0,0 +1,29 @@ +package gov_test + +import ( + "testing" + + "github.com/cosmos/cosmos-sdk/x/gov" + + "github.com/stretchr/testify/require" + + "github.com/tendermint/tendermint/abci/types" + + "github.com/cosmos/cosmos-sdk/simapp" + "github.com/cosmos/cosmos-sdk/x/supply" +) + +func TestItCreatesModuleAccountOnInitBlock(t *testing.T) { + app := simapp.Setup(false) + ctx := app.BaseApp.NewContext(false, types.Header{}) + + app.InitChain( + types.RequestInitChain{ + AppStateBytes: []byte("{}"), + ChainId: "test-chain-id", + }, + ) + + acc := app.AccountKeeper.GetAccount(ctx, supply.NewModuleAddress(gov.ModuleName)) + require.NotNil(t, acc) +} diff --git a/x/staking/module_test.go b/x/staking/module_test.go new file mode 100644 index 000000000..512d96e5a --- /dev/null +++ b/x/staking/module_test.go @@ -0,0 +1,31 @@ +package staking_test + +import ( + "testing" + + "github.com/cosmos/cosmos-sdk/x/staking" + + "github.com/stretchr/testify/require" + "github.com/tendermint/tendermint/abci/types" + + "github.com/cosmos/cosmos-sdk/simapp" + "github.com/cosmos/cosmos-sdk/x/supply" +) + +func TestItCreatesModuleAccountOnInitBlock(t *testing.T) { + app := simapp.Setup(false) + ctx := app.BaseApp.NewContext(false, types.Header{}) + + app.InitChain( + types.RequestInitChain{ + AppStateBytes: []byte("{}"), + ChainId: "test-chain-id", + }, + ) + + acc := app.AccountKeeper.GetAccount(ctx, supply.NewModuleAddress(staking.BondedPoolName)) + require.NotNil(t, acc) + + acc = app.AccountKeeper.GetAccount(ctx, supply.NewModuleAddress(staking.NotBondedPoolName)) + require.NotNil(t, acc) +} From 2d5711ff14dd840dacadcc4b79ea8f9b4ef312c7 Mon Sep 17 00:00:00 2001 From: Aleksandr Bezobchuk Date: Thu, 5 Mar 2020 23:31:30 -0500 Subject: [PATCH 9/9] Edit changelog entry --- CHANGELOG.md | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index aaf108ce6..403d420ce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -75,10 +75,7 @@ resulted in a panic when the tx execution mode was `CheckTx`. * (x/distribution) [\#5620](https://github.com/cosmos/cosmos-sdk/pull/5620) Fix nil pointer deref in distribution tax/rewward validation helpers. * (genesis) [\#5086](https://github.com/cosmos/cosmos-sdk/issues/5086) Ensure `gentxs` are always an empty array instead of `nil` * (types) [\#5741](https://github.com/cosmos/cosmos-sdk/issues/5741) Prevent ChainAnteDecorators() from panicking when empty AnteDecorator slice is supplied. -* (x/mint) [\#5569](https://github.com/cosmos/cosmos-sdk/issues/5569) Create Mint Module account on InitGenesis. `AppModule` now requires SupplyKeeper in its constructor to create -module account on `InitGenesis`. -* (x/auth) [\#5569](https://github.com/cosmos/cosmos-sdk/issues/5569) Create FeeCollectorName Module account on InitGenesis. `AppModule` now requires SupplyKeeper in its constructor to create -module account on `InitGenesis`. +* (modules) [\#5569](https://github.com/cosmos/cosmos-sdk/issues/5569) `InitGenesis`, for the relevant modules, now ensures module accounts exist. ### State Machine Breaking