diff --git a/CHANGELOG.md b/CHANGELOG.md index 856528154a..aaf108ce66 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 56aaae8d84..f7d9f30d7f 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 22db3557d7..420bdba09d 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 c5adc58113..910a54a2b9 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 0000000000..b49c407b9c --- /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 0000000000..83bf1b0ef6 --- /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 0000000000..59794489fc --- /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 0000000000..512d96e5a1 --- /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) +}