planetmint-go/x/dao/module_simulation.go
Lorenz Herzberger 7a3ccccc7a
119 create dao msg to mint plmnt on demand (#122)
* add mint address to config file
* ignite scaffold type mint-request beneficiary amount liquid-tx-hash --module dao
* add mintrequest stores
* rename mint_request.go
* add unit tests for mint request store
* ignite scaffold message mint-token mint-request:MintRequest --module dao
* add ante handler for mint address
* add msg validation for mint request
* fix staticcheck error
* ignite scaffold query get-mint-requests-by-hash hash --response mint-request:MintRequest --module dao
* add a query for mint request and additional validation for msg server
* add mock for mint unit testing
* add unit test for mint token msg server
* add unit tests for query mint requests by hash
* ignite scaffold query mint-requests-by-address address --response mint-requests:MintRequests --module dao
* implement query mint requests by address and unit tests
* add e2e test for token mint

---------

Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com>
2023-10-05 15:38:53 +02:00

89 lines
2.9 KiB
Go

package dao
import (
"math/rand"
"github.com/planetmint/planetmint-go/testutil/sample"
daosimulation "github.com/planetmint/planetmint-go/x/dao/simulation"
"github.com/planetmint/planetmint-go/x/dao/types"
"github.com/cosmos/cosmos-sdk/baseapp"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
"github.com/cosmos/cosmos-sdk/x/simulation"
)
// avoid unused import issue
var (
_ = sample.AccAddress
_ = daosimulation.FindAccount
_ = simulation.MsgEntryKind
_ = baseapp.Paramspace
_ = rand.Rand{}
)
const (
opWeightMsgMintToken = "op_weight_msg_mint_token"
// TODO: Determine the simulation weight value
defaultWeightMsgMintToken int = 100
// this line is used by starport scaffolding # simapp/module/const
)
// GenerateGenesisState creates a randomized 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()
}
daoGenesis := types.GenesisState{
Params: types.DefaultParams(),
// this line is used by starport scaffolding # simapp/module/genesisState
}
simState.GenState[types.ModuleName] = simState.Cdc.MustMarshalJSON(&daoGenesis)
}
// RegisterStoreDecoder registers a decoder.
func (am AppModule) RegisterStoreDecoder(_ sdk.StoreDecoderRegistry) {}
// ProposalContents doesn't return any content functions for governance proposals.
func (AppModule) ProposalContents(_ module.SimulationState) []simtypes.WeightedProposalMsg {
return nil
}
// WeightedOperations returns the all the gov module operations with their respective weights.
func (am AppModule) WeightedOperations(simState module.SimulationState) []simtypes.WeightedOperation {
operations := make([]simtypes.WeightedOperation, 0)
var weightMsgMintToken int
simState.AppParams.GetOrGenerate(simState.Cdc, opWeightMsgMintToken, &weightMsgMintToken, nil,
func(_ *rand.Rand) {
weightMsgMintToken = defaultWeightMsgMintToken
},
)
operations = append(operations, simulation.NewWeightedOperation(
weightMsgMintToken,
daosimulation.SimulateMsgMintToken(am.accountKeeper, am.bankKeeper, am.keeper),
))
// this line is used by starport scaffolding # simapp/module/operation
return operations
}
// ProposalMsgs returns msgs used for governance proposals for simulations.
func (am AppModule) ProposalMsgs(simState module.SimulationState) []simtypes.WeightedProposalMsg {
return []simtypes.WeightedProposalMsg{
simulation.NewWeightedProposalMsg(
opWeightMsgMintToken,
defaultWeightMsgMintToken,
func(r *rand.Rand, ctx sdk.Context, accs []simtypes.Account) sdk.Msg {
daosimulation.SimulateMsgMintToken(am.accountKeeper, am.bankKeeper, am.keeper)
return nil
},
),
// this line is used by starport scaffolding # simapp/module/OpMsg
}
}