diff --git a/ignite/templates/module/create/files/base/x/{{moduleName}}/types/genesis_test.go.plush b/ignite/templates/module/create/files/base/x/{{moduleName}}/types/genesis_test.go.plush index 8a53260a3e..5a6d2911c4 100644 --- a/ignite/templates/module/create/files/base/x/{{moduleName}}/types/genesis_test.go.plush +++ b/ignite/templates/module/create/files/base/x/{{moduleName}}/types/genesis_test.go.plush @@ -22,7 +22,6 @@ func TestGenesisState_Validate(t *testing.T) { desc: "valid genesis state", genState: &types.GenesisState{ <%= if (isIBC) { %>PortId: types.PortID,<% } %> - // this line is used by starport scaffolding # types/genesis/validField }, valid: true, }, diff --git a/ignite/templates/module/placeholders.go b/ignite/templates/module/placeholders.go index a3399ba53a..be6ffd3ad6 100644 --- a/ignite/templates/module/placeholders.go +++ b/ignite/templates/module/placeholders.go @@ -16,8 +16,7 @@ const ( PlaceholderIBCNewModule = "// this line is used by starport scaffolding # ibc/app/module" // Genesis test - PlaceholderTypesGenesisTestcase = "// this line is used by starport scaffolding # types/genesis/testcase" - PlaceholderTypesGenesisValidField = "// this line is used by starport scaffolding # types/genesis/validField" - PlaceholderGenesisTestState = "// this line is used by starport scaffolding # genesis/test/state" - PlaceholderGenesisTestAssert = "// this line is used by starport scaffolding # genesis/test/assert" + PlaceholderTypesGenesisTestcase = "// this line is used by starport scaffolding # types/genesis/testcase" + PlaceholderGenesisTestState = "// this line is used by starport scaffolding # genesis/test/state" + PlaceholderGenesisTestAssert = "// this line is used by starport scaffolding # genesis/test/assert" ) diff --git a/ignite/templates/typed/list/genesis.go b/ignite/templates/typed/list/genesis.go index 5542adcc80..c00e02d635 100644 --- a/ignite/templates/typed/list/genesis.go +++ b/ignite/templates/typed/list/genesis.go @@ -225,22 +225,26 @@ func genesisTypesTestsModify(replacer placeholder.Replacer, opts *typed.Options) return err } - templateValid := `%[2]vList: []types.%[2]v{ - { - Id: 0, - }, - { - Id: 1, - }, -}, -%[2]vCount: 2, -%[1]v` - replacementValid := fmt.Sprintf( - templateValid, - module.PlaceholderTypesGenesisValidField, - opts.TypeName.UpperCamel, + // add parameter to the struct into the new method. + content, err := xast.ModifyFunction( + f.String(), + "TestGenesisState_Validate", + xast.AppendInsideFuncStruct( + "GenesisState", + fmt.Sprintf("%[1]vList", opts.TypeName.UpperCamel), + fmt.Sprintf("[]types.%[1]v{{ Id: 0 }, { Id: 1 }}", opts.TypeName.UpperCamel), + -1, + ), + xast.AppendInsideFuncStruct( + "GenesisState", + fmt.Sprintf("%[1]vCount", opts.TypeName.UpperCamel), + "2", + -1, + ), ) - content := replacer.Replace(f.String(), module.PlaceholderTypesGenesisValidField, replacementValid) + if err != nil { + return err + } templateTests := `{ desc: "duplicated %[2]v", diff --git a/ignite/templates/typed/map/map.go b/ignite/templates/typed/map/map.go index 3c57de4a1a..59d2a56641 100644 --- a/ignite/templates/typed/map/map.go +++ b/ignite/templates/typed/map/map.go @@ -499,21 +499,25 @@ func genesisTypesTestsModify(replacer placeholder.Replacer, opts *typed.Options) sampleIndexes[i] = opts.Index.GenesisArgs(i) } - templateValid := `%[2]vList: []types.%[2]v{ - { - %[3]v}, - { - %[4]v}, -}, -%[1]v` - replacementValid := fmt.Sprintf( - templateValid, - module.PlaceholderTypesGenesisValidField, - opts.TypeName.UpperCamel, - sampleIndexes[0], - sampleIndexes[1], + // add parameter to the struct into the new method. + content, err := xast.ModifyFunction( + f.String(), + "TestGenesisState_Validate", + xast.AppendInsideFuncStruct( + "GenesisState", + fmt.Sprintf("%[1]vList", opts.TypeName.UpperCamel), + fmt.Sprintf( + "[]types.%[1]v{{ %[2]v }, { %[3]v }}", + opts.TypeName.UpperCamel, + sampleIndexes[0], + sampleIndexes[1], + ), + -1, + ), ) - content := replacer.Replace(f.String(), module.PlaceholderTypesGenesisValidField, replacementValid) + if err != nil { + return err + } templateDuplicated := `{ desc: "duplicated %[2]v", diff --git a/ignite/templates/typed/singleton/singleton.go b/ignite/templates/typed/singleton/singleton.go index 28d280ec02..9a1e08c643 100644 --- a/ignite/templates/typed/singleton/singleton.go +++ b/ignite/templates/typed/singleton/singleton.go @@ -62,7 +62,7 @@ func NewGenerator(replacer placeholder.Replacer, opts *typed.Options) (*genny.Ge g.RunFn(genesisTypesModify(opts)) g.RunFn(genesisModuleModify(replacer, opts)) g.RunFn(genesisTestsModify(replacer, opts)) - g.RunFn(genesisTypesTestsModify(replacer, opts)) + g.RunFn(genesisTypesTestsModify(opts)) // Modifications for new messages if !opts.NoMessage { @@ -332,7 +332,7 @@ func genesisTestsModify(replacer placeholder.Replacer, opts *typed.Options) genn } } -func genesisTypesTestsModify(replacer placeholder.Replacer, opts *typed.Options) genny.RunFn { +func genesisTypesTestsModify(opts *typed.Options) genny.RunFn { return func(r *genny.Runner) error { path := filepath.Join(opts.AppPath, "x", opts.ModuleName, "types/genesis_test.go") f, err := r.Disk.Find(path) @@ -350,16 +350,20 @@ func genesisTypesTestsModify(replacer placeholder.Replacer, opts *typed.Options) sampleFields += field.GenesisArgs(int(n.Int64()) + 1) } - templateValid := `%[2]v: &types.%[2]v{ - %[3]v}, -%[1]v` - replacementValid := fmt.Sprintf( - templateValid, - module.PlaceholderTypesGenesisValidField, - opts.TypeName.UpperCamel, - sampleFields, + // add parameter to the struct into the new method. + content, err := xast.ModifyFunction( + f.String(), + "TestGenesisState_Validate", + xast.AppendInsideFuncStruct( + "GenesisState", + opts.TypeName.UpperCamel, + fmt.Sprintf("&types.%[1]v{ %[2]v }", opts.TypeName.UpperCamel, sampleFields), + -1, + ), ) - content := replacer.Replace(f.String(), module.PlaceholderTypesGenesisValidField, replacementValid) + if err != nil { + return err + } newFile := genny.NewFileS(path, content) return r.File(newFile)