/
simulation.go
58 lines (50 loc) · 1.36 KB
/
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
package maptype
import (
"fmt"
"path/filepath"
"github.com/gobuffalo/genny/v2"
"github.com/ignite/cli/v29/ignite/pkg/placeholder"
"github.com/ignite/cli/v29/ignite/templates/typed"
)
func moduleSimulationModify(replacer placeholder.Replacer, opts *typed.Options) genny.RunFn {
return func(r *genny.Runner) error {
path := filepath.Join(opts.AppPath, "x", opts.ModuleName, "module/simulation.go")
f, err := r.Disk.Find(path)
if err != nil {
return err
}
// Create a list of two different indexes and fields to use as sample
sampleIndexes := make([]string, 2)
for i := 0; i < 2; i++ {
sampleIndexes[i] = fmt.Sprintf("%s: sample.AccAddress(),\n", opts.MsgSigner.UpperCamel)
for _, index := range opts.Indexes {
sampleIndexes[i] += index.GenesisArgs(i)
}
}
// simulation genesis state
templateGs := `%[2]vList: []types.%[2]v{
{
%[3]v},
{
%[4]v},
},
%[1]v`
replacementGs := fmt.Sprintf(
templateGs,
typed.PlaceholderSimappGenesisState,
opts.TypeName.UpperCamel,
sampleIndexes[0],
sampleIndexes[1],
)
content := replacer.Replace(f.String(), typed.PlaceholderSimappGenesisState, replacementGs)
content = typed.ModuleSimulationMsgModify(
replacer,
content,
opts.ModuleName,
opts.TypeName,
"Create", "Update", "Delete",
)
newFile := genny.NewFileS(path, content)
return r.File(newFile)
}
}