now it creates the module account on InitChain

This commit is contained in:
Jonathan Gimeno 2020-03-05 11:45:51 +01:00
parent b9ab834732
commit e01c99d019
5 changed files with 45 additions and 6 deletions

View File

@ -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),

View File

@ -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.

View File

@ -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{}
}

29
x/mint/module_test.go Normal file
View File

@ -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)
}

View File

@ -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