diff --git a/CHANGELOG.md b/CHANGELOG.md index 13fec3c34..7bbfad80c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -81,10 +81,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * [#1728](https://github.com/NibiruChain/nibiru/pull/1728) - test(devgas-cli): CLI tests for devgas txs * [#1735](https://github.com/NibiruChain/nibiru/pull/1735) - test(sim): fix simulation tests * [#1754](https://github.com/NibiruChain/nibiru/pull/1754) - refactor(decode-base64): clean code improvements and fn docs +* [#1736](https://github.com/NibiruChain/nibiru/pull/1736) - test(sim): add sim genesis state for all cusom modules ### Dependencies + - Bump `github.com/prometheus/client_golang` from 1.17.0 to 1.18.0 ([#1750](https://github.com/NibiruChain/nibiru/pull/1750)) -- Bump `google.golang.org/protobuf` from 1.31.0 to 1.32.0 ([#1756](https://github.com/NibiruChain/nibiru/pull/1756)) +* Bump `google.golang.org/protobuf` from 1.31.0 to 1.32.0 ([#1756](https://github.com/NibiruChain/nibiru/pull/1756)) * Bump `google.golang.org/grpc` from 1.59.0 to 1.60.0 ([#1720](https://github.com/NibiruChain/nibiru/pull/1720)) * Bump `golang.org/x/crypto` from 0.15.0 to 0.17.0 ([#1724](https://github.com/NibiruChain/nibiru/pull/1724)) diff --git a/x/devgas/v1/module.go b/x/devgas/v1/module.go index a99c44316..b76044225 100644 --- a/x/devgas/v1/module.go +++ b/x/devgas/v1/module.go @@ -5,28 +5,29 @@ import ( "encoding/json" "fmt" - "github.com/grpc-ecosystem/grpc-gateway/runtime" - "github.com/spf13/cobra" - abci "github.com/cometbft/cometbft/abci/types" - sdkclient "github.com/cosmos/cosmos-sdk/client" sdkcodec "github.com/cosmos/cosmos-sdk/codec" sdkcodectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" + simtypes "github.com/cosmos/cosmos-sdk/types/simulation" authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" + "github.com/grpc-ecosystem/grpc-gateway/runtime" + "github.com/spf13/cobra" - devgascli "github.com/NibiruChain/nibiru/x/devgas/v1/client/cli" - devgasexported "github.com/NibiruChain/nibiru/x/devgas/v1/exported" - devgaskeeper "github.com/NibiruChain/nibiru/x/devgas/v1/keeper" - devgastypes "github.com/NibiruChain/nibiru/x/devgas/v1/types" + "github.com/NibiruChain/nibiru/x/devgas/v1/client/cli" + "github.com/NibiruChain/nibiru/x/devgas/v1/exported" + "github.com/NibiruChain/nibiru/x/devgas/v1/keeper" + "github.com/NibiruChain/nibiru/x/devgas/v1/simulation" + "github.com/NibiruChain/nibiru/x/devgas/v1/types" ) // type check to ensure the interface is properly implemented var ( - _ module.AppModule = AppModule{} - _ module.AppModuleBasic = AppModuleBasic{} + _ module.AppModule = AppModule{} + _ module.AppModuleBasic = AppModuleBasic{} + _ module.AppModuleSimulation = AppModule{} ) // ConsensusVersion defines the current module consensus version. @@ -37,13 +38,13 @@ type AppModuleBasic struct{} // Name returns the fees module's name. func (AppModuleBasic) Name() string { - return devgastypes.ModuleName + return types.ModuleName } // RegisterLegacyAminoCodec performs a no-op as the fees do not support Amino // encoding. func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *sdkcodec.LegacyAmino) { - devgastypes.RegisterLegacyAminoCodec(cdc) + types.RegisterLegacyAminoCodec(cdc) } // ConsensusVersion returns the consensus state-breaking version for the module. @@ -56,22 +57,22 @@ func (AppModuleBasic) ConsensusVersion() uint64 { func (AppModuleBasic) RegisterInterfaces( interfaceRegistry sdkcodectypes.InterfaceRegistry, ) { - devgastypes.RegisterInterfaces(interfaceRegistry) + types.RegisterInterfaces(interfaceRegistry) } // DefaultGenesis returns default genesis state as raw bytes for the fees // module. func (AppModuleBasic) DefaultGenesis(cdc sdkcodec.JSONCodec) json.RawMessage { - return cdc.MustMarshalJSON(devgastypes.DefaultGenesisState()) + return cdc.MustMarshalJSON(types.DefaultGenesisState()) } // ValidateGenesis performs genesis state validation for the fees module. func (b AppModuleBasic) ValidateGenesis( cdc sdkcodec.JSONCodec, _ sdkclient.TxEncodingConfig, bz json.RawMessage, ) error { - var genesisState devgastypes.GenesisState + var genesisState types.GenesisState if err := cdc.UnmarshalJSON(bz, &genesisState); err != nil { - return fmt.Errorf("failed to unmarshal %s genesis state: %w", devgastypes.ModuleName, err) + return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err) } return genesisState.Validate() @@ -82,19 +83,19 @@ func (b AppModuleBasic) ValidateGenesis( func (b AppModuleBasic) RegisterGRPCGatewayRoutes( c sdkclient.Context, serveMux *runtime.ServeMux, ) { - if err := devgastypes.RegisterQueryHandlerClient(context.Background(), serveMux, devgastypes.NewQueryClient(c)); err != nil { + if err := types.RegisterQueryHandlerClient(context.Background(), serveMux, types.NewQueryClient(c)); err != nil { panic(err) } } // GetTxCmd returns the root tx command for the fees module. func (AppModuleBasic) GetTxCmd() *cobra.Command { - return devgascli.NewTxCmd() + return cli.NewTxCmd() } // GetQueryCmd returns the fees module's root query command. func (AppModuleBasic) GetQueryCmd() *cobra.Command { - return devgascli.GetQueryCmd() + return cli.GetQueryCmd() } // ___________________________________________________________________________ @@ -102,18 +103,18 @@ func (AppModuleBasic) GetQueryCmd() *cobra.Command { // AppModule implements the AppModule interface for the fees module. type AppModule struct { AppModuleBasic - keeper devgaskeeper.Keeper + keeper keeper.Keeper ak authkeeper.AccountKeeper // legacySubspace is used solely for migration of x/params managed parameters - legacySubspace devgasexported.Subspace + legacySubspace exported.Subspace } // NewAppModule creates a new AppModule Object func NewAppModule( - k devgaskeeper.Keeper, + k keeper.Keeper, ak authkeeper.AccountKeeper, - ss devgasexported.Subspace, + ss exported.Subspace, ) AppModule { return AppModule{ AppModuleBasic: AppModuleBasic{}, @@ -125,7 +126,7 @@ func NewAppModule( // Name returns the fees module's name. func (AppModule) Name() string { - return devgastypes.ModuleName + return types.ModuleName } // RegisterInvariants registers the fees module's invariants. @@ -133,15 +134,15 @@ func (am AppModule) RegisterInvariants(_ sdk.InvariantRegistry) {} // QuerierRoute returns the module's query routing key. func (am AppModule) QuerierRoute() string { - return devgastypes.RouterKey + return types.RouterKey } // RegisterServices registers a GRPC query service to respond to the // module-specific GRPC queries. func (am AppModule) RegisterServices(cfg module.Configurator) { - devgastypes.RegisterMsgServer(cfg.MsgServer(), am.keeper) - devgastypes.RegisterQueryServer( - cfg.QueryServer(), devgaskeeper.NewQuerier(am.keeper), + types.RegisterMsgServer(cfg.MsgServer(), am.keeper) + types.RegisterQueryServer( + cfg.QueryServer(), keeper.NewQuerier(am.keeper), ) } @@ -158,7 +159,7 @@ func (am AppModule) EndBlock(_ sdk.Context, _ abci.RequestEndBlock) []abci.Valid // InitGenesis performs the fees module's genesis initialization. It returns // no validator updates. func (am AppModule) InitGenesis(ctx sdk.Context, cdc sdkcodec.JSONCodec, data json.RawMessage) []abci.ValidatorUpdate { - var genesisState devgastypes.GenesisState + var genesisState types.GenesisState cdc.MustUnmarshalJSON(data, &genesisState) InitGenesis(ctx, am.keeper, genesisState) @@ -170,3 +171,21 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc sdkcodec.JSONCodec) json. gs := ExportGenesis(ctx, am.keeper) return cdc.MustMarshalJSON(gs) } + +//---------------------------------------------------------------------------- +// AppModuleSimulation functions +//---------------------------------------------------------------------------- + +// GenerateGenesisState implements module.AppModuleSimulation. +func (AppModule) GenerateGenesisState(simState *module.SimulationState) { + simulation.RandomizedGenState(simState) +} + +// RegisterStoreDecoder implements module.AppModuleSimulation. +func (AppModule) RegisterStoreDecoder(sdk.StoreDecoderRegistry) { +} + +// WeightedOperations implements module.AppModuleSimulation. +func (AppModule) WeightedOperations(simState module.SimulationState) []simtypes.WeightedOperation { + return nil +} diff --git a/x/devgas/v1/simulation/genesis.go b/x/devgas/v1/simulation/genesis.go new file mode 100644 index 000000000..8fd31e5c9 --- /dev/null +++ b/x/devgas/v1/simulation/genesis.go @@ -0,0 +1,46 @@ +package simulation + +// DONTCOVER + +import ( + "encoding/json" + "fmt" + "math/rand" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/module" + + "github.com/NibiruChain/nibiru/x/devgas/v1/types" +) + +const ( + DeveloperFeeShare = "developer_fee_share" +) + +func GenDeveloperFeeShare(r *rand.Rand) sdk.Dec { + return sdk.NewDecWithPrec(int64(r.Intn(100)), 2) +} + +func RandomizedGenState(simState *module.SimulationState) { + var developerFeeShare sdk.Dec + simState.AppParams.GetOrGenerate( + simState.Cdc, DeveloperFeeShare, &developerFeeShare, simState.Rand, + func(r *rand.Rand) { developerFeeShare = GenDeveloperFeeShare(r) }, + ) + + devgasGenesis := types.GenesisState{ + Params: types.ModuleParams{ + EnableFeeShare: true, + DeveloperShares: developerFeeShare, + AllowedDenoms: []string{}, + }, + FeeShare: []types.FeeShare{}, + } + + bz, err := json.MarshalIndent(&devgasGenesis, "", " ") + if err != nil { + panic(err) + } + fmt.Printf("Selected randomly generated x/devgas parameters:\n%s\n", bz) + simState.GenState[types.ModuleName] = simState.Cdc.MustMarshalJSON(&devgasGenesis) +} diff --git a/x/inflation/module.go b/x/inflation/module.go index 5265af192..5ccfaa65e 100644 --- a/x/inflation/module.go +++ b/x/inflation/module.go @@ -19,6 +19,7 @@ import ( "github.com/NibiruChain/nibiru/x/inflation/client/cli" "github.com/NibiruChain/nibiru/x/inflation/keeper" + "github.com/NibiruChain/nibiru/x/inflation/simulation" "github.com/NibiruChain/nibiru/x/inflation/types" ) @@ -153,7 +154,8 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw // AppModuleSimulation functions // GenerateGenesisState creates a randomized GenState of the inflation module. -func (am AppModule) GenerateGenesisState(_ *module.SimulationState) { +func (am AppModule) GenerateGenesisState(simState *module.SimulationState) { + simulation.RandomizedGenState(simState) } // ProposalContents doesn't return any content functions for governance proposals. diff --git a/x/inflation/simulation/genesis.go b/x/inflation/simulation/genesis.go new file mode 100644 index 000000000..11f1dc874 --- /dev/null +++ b/x/inflation/simulation/genesis.go @@ -0,0 +1,47 @@ +package simulation + +// DONTCOVER + +import ( + "encoding/json" + "fmt" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/module" + + "github.com/NibiruChain/nibiru/x/inflation/types" +) + +// RandomizedGenState generates a random GenesisState for distribution +func RandomizedGenState(simState *module.SimulationState) { + inflationGenesis := types.GenesisState{ + Params: types.Params{ + InflationEnabled: true, + PolynomialFactors: []sdk.Dec{ + sdk.MustNewDecFromStr("-0.00014903"), + sdk.MustNewDecFromStr("0.07527647"), + sdk.MustNewDecFromStr("-19.11742154"), + sdk.MustNewDecFromStr("3170.0969905"), + sdk.MustNewDecFromStr("-339271.31060432"), + sdk.MustNewDecFromStr("18063678.8582418"), + }, + InflationDistribution: types.InflationDistribution{ + CommunityPool: sdk.NewDecWithPrec(35_159141, 8), // 35.159141% + StakingRewards: sdk.NewDecWithPrec(27_757217, 8), // 27.757217% + StrategicReserves: sdk.NewDecWithPrec(37_083642, 8), // 37.083642% + }, + EpochsPerPeriod: 30, + PeriodsPerYear: 12, + MaxPeriod: 8 * 12, + }, + Period: 0, + SkippedEpochs: 0, + } + + bz, err := json.MarshalIndent(&inflationGenesis, "", " ") + if err != nil { + panic(err) + } + fmt.Printf("Selected randomly generated x/inflation parameters:\n%s\n", bz) + simState.GenState[types.ModuleName] = simState.Cdc.MustMarshalJSON(&inflationGenesis) +} diff --git a/x/perp/v2/module/module.go b/x/perp/v2/module/module.go index 94027376a..c58d70c7a 100644 --- a/x/perp/v2/module/module.go +++ b/x/perp/v2/module/module.go @@ -11,18 +11,21 @@ import ( codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" + simtypes "github.com/cosmos/cosmos-sdk/types/simulation" "github.com/grpc-ecosystem/grpc-gateway/runtime" "github.com/spf13/cobra" "github.com/NibiruChain/nibiru/x/perp/v2/client/cli" "github.com/NibiruChain/nibiru/x/perp/v2/keeper" - types "github.com/NibiruChain/nibiru/x/perp/v2/types" + "github.com/NibiruChain/nibiru/x/perp/v2/simulation" + "github.com/NibiruChain/nibiru/x/perp/v2/types" ) // type check to ensure the interface is properly implemented var ( - _ module.AppModule = AppModule{} - _ module.AppModuleBasic = AppModuleBasic{} + _ module.AppModule = AppModule{} + _ module.AppModuleBasic = AppModuleBasic{} + _ module.AppModuleSimulation = AppModule{} ) // ---------------------------------------------------------------------------- @@ -167,3 +170,17 @@ func (am AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.Val EndBlocker(ctx, am.keeper) return []abci.ValidatorUpdate{} } + +// GenerateGenesisState implements module.AppModuleSimulation. +func (AppModule) GenerateGenesisState(simState *module.SimulationState) { + simulation.RandomizedGenState(simState) +} + +// RegisterStoreDecoder implements module.AppModuleSimulation. +func (AppModule) RegisterStoreDecoder(sdk.StoreDecoderRegistry) { +} + +// WeightedOperations implements module.AppModuleSimulation. +func (AppModule) WeightedOperations(simState module.SimulationState) []simtypes.WeightedOperation { + return []simtypes.WeightedOperation{} +} diff --git a/x/perp/v2/simulation/genesis.go b/x/perp/v2/simulation/genesis.go new file mode 100644 index 000000000..6f010bdef --- /dev/null +++ b/x/perp/v2/simulation/genesis.go @@ -0,0 +1,24 @@ +package simulation + +// DONTCOVER + +import ( + "encoding/json" + "fmt" + + "github.com/cosmos/cosmos-sdk/types/module" + + "github.com/NibiruChain/nibiru/x/perp/v2/types" +) + +// RandomizedGenState generates a random GenesisState for distribution +func RandomizedGenState(simState *module.SimulationState) { + perpGenesis := *types.DefaultGenesis() + + bz, err := json.MarshalIndent(&perpGenesis, "", " ") + if err != nil { + panic(err) + } + fmt.Printf("Selected randomly generated x/tokenfactory parameters:\n%s\n", bz) + simState.GenState[types.ModuleName] = simState.Cdc.MustMarshalJSON(&perpGenesis) +} diff --git a/x/spot/module.go b/x/spot/module.go index c0fc8a40f..9bd9cca72 100644 --- a/x/spot/module.go +++ b/x/spot/module.go @@ -5,25 +5,26 @@ import ( "encoding/json" "fmt" - "github.com/grpc-ecosystem/grpc-gateway/runtime" - "github.com/spf13/cobra" - abci "github.com/cometbft/cometbft/abci/types" - "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" cdctypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" + simtypes "github.com/cosmos/cosmos-sdk/types/simulation" + "github.com/grpc-ecosystem/grpc-gateway/runtime" + "github.com/spf13/cobra" "github.com/NibiruChain/nibiru/x/spot/client/cli" "github.com/NibiruChain/nibiru/x/spot/keeper" + "github.com/NibiruChain/nibiru/x/spot/simulation" "github.com/NibiruChain/nibiru/x/spot/types" ) var ( - _ module.AppModule = AppModule{} - _ module.AppModuleBasic = AppModuleBasic{} + _ module.AppModule = AppModule{} + _ module.AppModuleBasic = AppModuleBasic{} + _ module.AppModuleSimulation = AppModule{} ) // ---------------------------------------------------------------------------- @@ -155,3 +156,21 @@ func (am AppModule) BeginBlock(_ sdk.Context, _ abci.RequestBeginBlock) {} func (am AppModule) EndBlock(_ sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate { return []abci.ValidatorUpdate{} } + +// GenerateGenesisState creates a default GenState of the module +func (AppModule) GenerateGenesisState(simState *module.SimulationState) { + simulation.RandomizedGenState(simState) +} + +// ProposalContents doesn't return any content functions for governance proposals +func (AppModule) ProposalContents(_ module.SimulationState) []simtypes.WeightedProposalMsg { + return nil +} + +// RegisterStoreDecoder registers a decoder +func (am AppModule) RegisterStoreDecoder(_ sdk.StoreDecoderRegistry) {} + +// WeightedOperations returns the all the spot module operations with their respective weights. +func (am AppModule) WeightedOperations(_ module.SimulationState) []simtypes.WeightedOperation { + return simulation.WeightedOperations(am.accountKeeper, am.bankKeeper, am.keeper) +} diff --git a/x/spot/module_simulation.go b/x/spot/module_simulation.go deleted file mode 100644 index 0b3e6dfd2..000000000 --- a/x/spot/module_simulation.go +++ /dev/null @@ -1,33 +0,0 @@ -package spot - -import ( - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/module" - simtypes "github.com/cosmos/cosmos-sdk/types/simulation" - - "github.com/NibiruChain/nibiru/x/spot/simulation" - "github.com/NibiruChain/nibiru/x/spot/types" -) - -// GenerateGenesisState creates a default GenState of the module -func (AppModule) GenerateGenesisState(simState *module.SimulationState) { - accs := make([]string, len(simState.Accounts)) - for i, acc := range simState.Accounts { - accs[i] = acc.Address.String() - } - dexGenesis := types.DefaultGenesis() - simState.GenState[types.ModuleName] = simState.Cdc.MustMarshalJSON(dexGenesis) -} - -// ProposalContents doesn't return any content functions for governance proposals -func (AppModule) ProposalContents(_ module.SimulationState) []simtypes.WeightedProposalMsg { - return nil -} - -// RegisterStoreDecoder registers a decoder -func (am AppModule) RegisterStoreDecoder(_ sdk.StoreDecoderRegistry) {} - -// WeightedOperations returns the all the spot module operations with their respective weights. -func (am AppModule) WeightedOperations(_ module.SimulationState) []simtypes.WeightedOperation { - return simulation.WeightedOperations(am.accountKeeper, am.bankKeeper, am.keeper) -} diff --git a/x/spot/simulation/genesis.go b/x/spot/simulation/genesis.go new file mode 100644 index 000000000..46904391f --- /dev/null +++ b/x/spot/simulation/genesis.go @@ -0,0 +1,34 @@ +package simulation + +// DONTCOVER + +import ( + "encoding/json" + "fmt" + "math/rand" + + "github.com/cosmos/cosmos-sdk/types/module" + + "github.com/NibiruChain/nibiru/x/tokenfactory/types" +) + +const ( + DenomCreationGasConsume = "denom_creation_gas_consume" +) + +func GenDenomCreationGasConsume(r *rand.Rand) uint64 { + return uint64(r.Intn(4e6)) +} + +// RandomizedGenState generates a random GenesisState for distribution +func RandomizedGenState(simState *module.SimulationState) { + spotGenesis := types.DefaultGenesis() + + bz, err := json.MarshalIndent(&spotGenesis, "", " ") + if err != nil { + panic(err) + } + + fmt.Printf("Selected randomly generated x/spot parameters:\n%s\n", bz) + simState.GenState[types.ModuleName] = simState.Cdc.MustMarshalJSON(spotGenesis) +} diff --git a/x/sudo/simulation/genesis.go b/x/sudo/simulation/genesis.go index 89a863582..6558770e4 100644 --- a/x/sudo/simulation/genesis.go +++ b/x/sudo/simulation/genesis.go @@ -5,36 +5,18 @@ package simulation import ( "encoding/json" "fmt" - "math/rand" - "cosmossdk.io/math" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" "github.com/NibiruChain/nibiru/x/sudo/types" ) -// Simulation parameter constants -const ( - CommunityTax = "community_tax" - WithdrawEnabled = "withdraw_enabled" -) - -// GenCommunityTax randomized CommunityTax -func GenCommunityTax(r *rand.Rand) math.LegacyDec { - return sdk.NewDecWithPrec(1, 2).Add(sdk.NewDecWithPrec(int64(r.Intn(30)), 2)) -} - -// GenWithdrawEnabled returns a randomized WithdrawEnabled parameter. -func GenWithdrawEnabled(r *rand.Rand) bool { - return r.Int63n(101) <= 95 // 95% chance of withdraws being enabled -} - -// RandomizedGenState generates a random GenesisState for distribution func RandomizedGenState(simState *module.SimulationState) { + rootAddress := simState.Accounts[simState.Rand.Intn(len(simState.Accounts))].Address + genState := types.GenesisState{ Sudoers: types.Sudoers{ - Root: simState.Accounts[0].Address.String(), + Root: rootAddress.String(), Contracts: []string{}, }, } diff --git a/x/tokenfactory/module.go b/x/tokenfactory/module.go index 80b41b36c..9cc05ec99 100644 --- a/x/tokenfactory/module.go +++ b/x/tokenfactory/module.go @@ -14,27 +14,28 @@ import ( "encoding/json" "fmt" - "github.com/grpc-ecosystem/grpc-gateway/runtime" - "github.com/spf13/cobra" - abci "github.com/cometbft/cometbft/abci/types" - sdkclient "github.com/cosmos/cosmos-sdk/client" sdkcodec "github.com/cosmos/cosmos-sdk/codec" sdkcodectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" + simtypes "github.com/cosmos/cosmos-sdk/types/simulation" authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" + "github.com/grpc-ecosystem/grpc-gateway/runtime" + "github.com/spf13/cobra" - modulecli "github.com/NibiruChain/nibiru/x/tokenfactory/cli" - modulekeeper "github.com/NibiruChain/nibiru/x/tokenfactory/keeper" - moduletypes "github.com/NibiruChain/nibiru/x/tokenfactory/types" + "github.com/NibiruChain/nibiru/x/tokenfactory/cli" + "github.com/NibiruChain/nibiru/x/tokenfactory/keeper" + "github.com/NibiruChain/nibiru/x/tokenfactory/simulation" + "github.com/NibiruChain/nibiru/x/tokenfactory/types" ) // type check to ensure the interface is properly implemented var ( _ module.AppModuleBasic = AppModuleBasic{} _ module.AppModule = AppModule{} + _ module.AppModuleSimulation = AppModule{} _ module.BeginBlockAppModule = AppModule{} _ module.EndBlockAppModule = AppModule{} ) @@ -47,13 +48,13 @@ type AppModuleBasic struct{} // Name returns the fees module's name. func (AppModuleBasic) Name() string { - return moduletypes.ModuleName + return types.ModuleName } // RegisterLegacyAminoCodec performs a no-op as the fees do not support Amino // encoding. func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *sdkcodec.LegacyAmino) { - moduletypes.RegisterLegacyAminoCodec(cdc) + types.RegisterLegacyAminoCodec(cdc) } // ConsensusVersion returns the consensus state-breaking version for the module. @@ -66,22 +67,22 @@ func (AppModuleBasic) ConsensusVersion() uint64 { func (AppModuleBasic) RegisterInterfaces( interfaceRegistry sdkcodectypes.InterfaceRegistry, ) { - moduletypes.RegisterInterfaces(interfaceRegistry) + types.RegisterInterfaces(interfaceRegistry) } // DefaultGenesis returns default genesis state as raw bytes for the fees // module. func (AppModuleBasic) DefaultGenesis(cdc sdkcodec.JSONCodec) json.RawMessage { - return cdc.MustMarshalJSON(moduletypes.DefaultGenesis()) + return cdc.MustMarshalJSON(types.DefaultGenesis()) } // ValidateGenesis performs genesis state validation for the fees module. func (b AppModuleBasic) ValidateGenesis( cdc sdkcodec.JSONCodec, _ sdkclient.TxEncodingConfig, bz json.RawMessage, ) error { - var genesisState moduletypes.GenesisState + var genesisState types.GenesisState if err := cdc.UnmarshalJSON(bz, &genesisState); err != nil { - return fmt.Errorf("failed to unmarshal %s genesis state: %w", moduletypes.ModuleName, err) + return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err) } return genesisState.Validate() @@ -92,19 +93,19 @@ func (b AppModuleBasic) ValidateGenesis( func (b AppModuleBasic) RegisterGRPCGatewayRoutes( c sdkclient.Context, serveMux *runtime.ServeMux, ) { - if err := moduletypes.RegisterQueryHandlerClient(context.Background(), serveMux, moduletypes.NewQueryClient(c)); err != nil { + if err := types.RegisterQueryHandlerClient(context.Background(), serveMux, types.NewQueryClient(c)); err != nil { panic(err) } } // GetTxCmd returns the root tx command for the fees module. func (AppModuleBasic) GetTxCmd() *cobra.Command { - return modulecli.NewTxCmd() + return cli.NewTxCmd() } // GetQueryCmd returns the fees module's root query command. func (AppModuleBasic) GetQueryCmd() *cobra.Command { - return modulecli.NewQueryCmd() + return cli.NewQueryCmd() } // ___________________________________________________________________________ @@ -112,13 +113,13 @@ func (AppModuleBasic) GetQueryCmd() *cobra.Command { // AppModule implements the AppModule interface for the fees module. type AppModule struct { AppModuleBasic - keeper modulekeeper.Keeper + keeper keeper.Keeper ak authkeeper.AccountKeeper } // NewAppModule creates a new AppModule Object func NewAppModule( - k modulekeeper.Keeper, + k keeper.Keeper, ak authkeeper.AccountKeeper, ) AppModule { return AppModule{ @@ -130,7 +131,7 @@ func NewAppModule( // Name returns the fees module's name. func (AppModule) Name() string { - return moduletypes.ModuleName + return types.ModuleName } // RegisterInvariants registers the fees module's invariants. @@ -138,14 +139,14 @@ func (am AppModule) RegisterInvariants(_ sdk.InvariantRegistry) {} // QuerierRoute returns the module's query routing key. func (am AppModule) QuerierRoute() string { - return moduletypes.RouterKey + return types.RouterKey } // RegisterServices registers a GRPC query service to respond to the // module-specific GRPC queries. func (am AppModule) RegisterServices(cfg module.Configurator) { - moduletypes.RegisterMsgServer(cfg.MsgServer(), am.keeper) - moduletypes.RegisterQueryServer( + types.RegisterMsgServer(cfg.MsgServer(), am.keeper) + types.RegisterQueryServer( cfg.QueryServer(), am.keeper.Querier(), ) } @@ -163,7 +164,7 @@ func (am AppModule) EndBlock(_ sdk.Context, _ abci.RequestEndBlock) []abci.Valid // InitGenesis performs the fees module's genesis initialization. It returns // no validator updates. func (am AppModule) InitGenesis(ctx sdk.Context, cdc sdkcodec.JSONCodec, data json.RawMessage) []abci.ValidatorUpdate { - var genesisState moduletypes.GenesisState + var genesisState types.GenesisState cdc.MustUnmarshalJSON(data, &genesisState) am.keeper.InitGenesis(ctx, genesisState) @@ -175,3 +176,17 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc sdkcodec.JSONCodec) json. gs := am.keeper.ExportGenesis(ctx) return cdc.MustMarshalJSON(gs) } + +// GenerateGenesisState implements module.AppModuleSimulation. +func (AppModule) GenerateGenesisState(simState *module.SimulationState) { + simulation.RandomizedGenState(simState) +} + +// RegisterStoreDecoder implements module.AppModuleSimulation. +func (AppModule) RegisterStoreDecoder(sdk.StoreDecoderRegistry) { +} + +// WeightedOperations implements module.AppModuleSimulation. +func (AppModule) WeightedOperations(simState module.SimulationState) []simtypes.WeightedOperation { + return []simtypes.WeightedOperation{} +} diff --git a/x/tokenfactory/simulation/genesis.go b/x/tokenfactory/simulation/genesis.go new file mode 100644 index 000000000..40856bd06 --- /dev/null +++ b/x/tokenfactory/simulation/genesis.go @@ -0,0 +1,44 @@ +package simulation + +// DONTCOVER + +import ( + "encoding/json" + "fmt" + "math/rand" + + "github.com/cosmos/cosmos-sdk/types/module" + + "github.com/NibiruChain/nibiru/x/tokenfactory/types" +) + +const ( + DenomCreationGasConsume = "denom_creation_gas_consume" +) + +func GenDenomCreationGasConsume(r *rand.Rand) uint64 { + return uint64(r.Intn(4e6)) +} + +// RandomizedGenState generates a random GenesisState for distribution +func RandomizedGenState(simState *module.SimulationState) { + var denomCreationGasConsume uint64 + simState.AppParams.GetOrGenerate( + simState.Cdc, DenomCreationGasConsume, &denomCreationGasConsume, simState.Rand, + func(r *rand.Rand) { denomCreationGasConsume = GenDenomCreationGasConsume(r) }, + ) + + tokenfactoryGenesis := types.GenesisState{ + Params: types.ModuleParams{ + DenomCreationGasConsume: denomCreationGasConsume, + }, + FactoryDenoms: []types.GenesisDenom{}, + } + + bz, err := json.MarshalIndent(&tokenfactoryGenesis, "", " ") + if err != nil { + panic(err) + } + fmt.Printf("Selected randomly generated x/tokenfactory parameters:\n%s\n", bz) + simState.GenState[types.ModuleName] = simState.Cdc.MustMarshalJSON(&tokenfactoryGenesis) +}