-
Notifications
You must be signed in to change notification settings - Fork 10
/
module_simulation.go
123 lines (106 loc) · 3.57 KB
/
module_simulation.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
package claim
import (
"math/rand"
sdkmath "cosmossdk.io/math"
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"
claimsimulation "github.com/ignite/modules/x/claim/simulation"
"github.com/ignite/modules/x/claim/types"
)
const (
airdropDenom = "drop"
opWeightMsgClaim = "op_weight_msg_claim"
defaultWeightMsgClaim int = 50
// 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))
claimRecords := make([]types.ClaimRecord, len(simState.Accounts))
totalSupply := sdkmath.ZeroInt()
for i, acc := range simState.Accounts {
accs[i] = acc.Address.String()
// fill claim records from simulation accounts
accSupply := sdkmath.NewIntFromUint64(simState.Rand.Uint64() % 1000)
claimRecords[i] = types.ClaimRecord{
Claimable: accSupply,
Address: acc.Address.String(),
}
totalSupply = totalSupply.Add(accSupply)
}
// define some decimal numbers for mission weights
dec1, err := sdk.NewDecFromStr("0.4")
if err != nil {
panic(err)
}
dec2, err := sdk.NewDecFromStr("0.3")
if err != nil {
panic(err)
}
claimGenesis := types.GenesisState{
Params: types.DefaultParams(),
AirdropSupply: sdk.NewCoin(airdropDenom, totalSupply),
Missions: []types.Mission{
{
MissionID: 0,
Description: "initial claim",
Weight: dec1,
},
{
MissionID: 1,
Description: "mission 1",
Weight: dec2,
},
{
MissionID: 2,
Description: "mission 2",
Weight: dec2,
},
},
InitialClaim: types.InitialClaim{
Enabled: true,
MissionID: 0,
},
ClaimRecords: claimRecords,
// this line is used by starport scaffolding # simapp/module/genesisState
}
simState.GenState[types.ModuleName] = simState.Cdc.MustMarshalJSON(&claimGenesis)
}
// RandomizedParams creates randomized param changes for the simulator
func (am AppModule) RandomizedParams(_ *rand.Rand) []simtypes.LegacyParamChange {
return []simtypes.LegacyParamChange{}
}
// RegisterStoreDecoder registers a decoder
func (am AppModule) RegisterStoreDecoder(_ sdk.StoreDecoderRegistry) {}
// 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 weightMsgClaim int
simState.AppParams.GetOrGenerate(simState.Cdc, opWeightMsgClaim, &weightMsgClaim, nil,
func(_ *rand.Rand) {
weightMsgClaim = defaultWeightMsgClaim
},
)
operations = append(operations, simulation.NewWeightedOperation(
weightMsgClaim,
claimsimulation.SimulateMsgClaim(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(
opWeightMsgClaim,
defaultWeightMsgClaim,
func(r *rand.Rand, ctx sdk.Context, accs []simtypes.Account) sdk.Msg {
claimsimulation.SimulateMsgClaim(am.accountKeeper, am.bankKeeper, am.keeper)
return nil
},
),
// this line is used by starport scaffolding # simapp/module/OpMsg
}
}