Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
julienrbrt committed Dec 6, 2024
1 parent f1f8dc2 commit 2a2fb19
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 9 deletions.
1 change: 1 addition & 0 deletions ignite/templates/message/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ func moduleSimulationModify(replacer placeholder.Replacer, opts *Options) genny.
replacer,
f.String(),
opts.MsgName,
opts.MsgSigner,
)

newFile := genny.NewFileS(path, content)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (am AppModule) RegisterStoreDecoder(_ simtypes.StoreDecoderRegistry) {}
// ProposalMsgsX returns msgs used for governance proposals for simulations.
func (am AppModule) ProposalMsgsX(weights simsx.WeightSource, reg simsx.Registry) {
reg.Add(weights.Get("msg_update_params", 100), simulation.MsgUpdateParamsFactory())
// this line is used by starport scaffolding # simapp/module/OpMsg
// this line is used by starport scaffolding # simapp/module/proposalSimulation
}

// WeightedOperations returns the all the module operations with their respective weights.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ func MsgUpdate<%= TypeName.UpperCamel %>Factory(k keeper.Keeper) simsx.SimMsgFac
for _, obj := range all<%= TypeName.UpperCamel %> {
if ok := testData.HasAccount(obj.<%= MsgSigner.UpperCamel %>); ok {
simAccount = testData.GetAccount(reporter, obj.<%= MsgSigner.UpperCamel %>)
<%= TypeName.LowerCamel %> = obj
break
}
}
Expand Down Expand Up @@ -79,6 +80,7 @@ func MsgDelete<%= TypeName.UpperCamel %>Factory(k keeper.Keeper) simsx.SimMsgFac
for _, obj := range all<%= TypeName.UpperCamel %> {
if ok := testData.HasAccount(obj.<%= MsgSigner.UpperCamel %>); ok {
simAccount = testData.GetAccount(reporter, obj.<%= MsgSigner.UpperCamel %>)
<%= TypeName.LowerCamel %> = obj
break
}
}
Expand Down
2 changes: 1 addition & 1 deletion ignite/templates/typed/list/simulation.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ func moduleSimulationModify(replacer placeholder.Replacer, opts *typed.Options)
msgField,
)
content := replacer.Replace(f.String(), typed.PlaceholderSimappGenesisState, replacementGs)

content = typed.ModuleSimulationMsgModify(
replacer,
content,
opts.TypeName,
opts.MsgSigner,
"Create", "Update", "Delete",
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ func MsgCreate<%= TypeName.UpperCamel %>Factory(k keeper.Keeper) simsx.SimMsgFac
if err == nil && found {
reporter.Skip("<%= TypeName.UpperCamel %> already exist")
return nil, nil
} else if err != nil {
reporter.Skip(err.Error())
return nil, nil
}

return []simsx.SimAccount{from}, msg
Expand Down Expand Up @@ -54,6 +57,7 @@ func MsgUpdate<%= TypeName.UpperCamel %>Factory(k keeper.Keeper) simsx.SimMsgFac
for _, obj := range all<%= TypeName.UpperCamel %> {
if ok := testData.HasAccount(obj.<%= MsgSigner.UpperCamel %>); ok {
simAccount = testData.GetAccount(reporter, obj.<%= MsgSigner.UpperCamel %>)
<%= TypeName.LowerCamel %> = obj
break
}
}
Expand Down Expand Up @@ -90,6 +94,7 @@ func MsgDelete<%= TypeName.UpperCamel %>Factory(k keeper.Keeper) simsx.SimMsgFac
for _, obj := range all<%= TypeName.UpperCamel %> {
if ok := testData.HasAccount(obj.<%= MsgSigner.UpperCamel %>); ok {
simAccount = testData.GetAccount(reporter, obj.<%= MsgSigner.UpperCamel %>)
<%= TypeName.LowerCamel %> = obj
break
}
}
Expand Down
1 change: 1 addition & 0 deletions ignite/templates/typed/map/simulation.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ func moduleSimulationModify(replacer placeholder.Replacer, opts *typed.Options)
replacer,
content,
opts.TypeName,
opts.MsgSigner,
"Create", "Update", "Delete",
)

Expand Down
6 changes: 3 additions & 3 deletions ignite/templates/typed/placeholders.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ const (
PlaceholderGenesisModuleInit = "// this line is used by starport scaffolding # genesis/module/init"
PlaceholderGenesisModuleExport = "// this line is used by starport scaffolding # genesis/module/export"

PlaceholderSimappGenesisState = "// this line is used by starport scaffolding # simapp/module/genesisState"
PlaceholderSimappOperation = "// this line is used by starport scaffolding # simapp/module/operation"
PlaceholderSimappOperationMsg = "// this line is used by starport scaffolding # simapp/module/OpMsg"
PlaceholderSimappGenesisState = "// this line is used by starport scaffolding # simapp/module/genesisState"
PlaceholderSimappOperation = "// this line is used by starport scaffolding # simapp/module/operation"
PlaceholderSimappOperationProposalSimulation = "// this line is used by starport scaffolding # simapp/module/proposalSimulation"

// Placeholders AutoCLI
PlaceholderAutoCLIQuery = "// this line is used by ignite scaffolding # autocli/query"
Expand Down
9 changes: 5 additions & 4 deletions ignite/templates/typed/simulation.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
func ModuleSimulationMsgModify(
replacer placeholder.Replacer,
content string,
typeName multiformatname.Name,
typeName, msgSigner multiformatname.Name,
msgs ...string,
) string {
if len(msgs) == 0 {
Expand All @@ -25,11 +25,12 @@ func ModuleSimulationMsgModify(
replacementOp := fmt.Sprintf(templateOp, PlaceholderSimappOperation, msg, typeName.UpperCamel, fmt.Sprintf("%s_%s", strings.ToLower(msg), typeName.Snake))
content = replacer.Replace(content, PlaceholderSimappOperation, replacementOp)

if strings.Contains(content, PlaceholderSimappOperationMsg) { // TODO: We need to check if the message has an authority or not
// add proposal simulation operations for msgs having an authority as signer.
if strings.Contains(content, PlaceholderSimappOperationProposalSimulation) && strings.EqualFold(msgSigner.Original, "authority") {
templateOpMsg := `reg.Add(weights.Get("msg_%[4]v", 100), simulation.Msg%[2]v%[3]vFactory(am.keeper))
%[1]v`
replacementOpMsg := fmt.Sprintf(templateOpMsg, PlaceholderSimappOperationMsg, msg, typeName.UpperCamel, fmt.Sprintf("%s_%s", strings.ToLower(msg), typeName.Snake))
content = replacer.Replace(content, PlaceholderSimappOperationMsg, replacementOpMsg)
replacementOpMsg := fmt.Sprintf(templateOpMsg, PlaceholderSimappOperationProposalSimulation, msg, typeName.UpperCamel, fmt.Sprintf("%s_%s", strings.ToLower(msg), typeName.Snake))
content = replacer.Replace(content, PlaceholderSimappOperationProposalSimulation, replacementOpMsg)
}
}

Expand Down
1 change: 1 addition & 0 deletions ignite/templates/typed/singleton/simulation.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ func moduleSimulationModify(replacer placeholder.Replacer, opts *typed.Options)
replacer,
f.String(),
opts.TypeName,
opts.MsgSigner,
"Create", "Update", "Delete",
)

Expand Down

0 comments on commit 2a2fb19

Please sign in to comment.