Skip to content

Commit

Permalink
remove genesis state for test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
Pantani committed Dec 5, 2024
1 parent a544d51 commit 6179d70
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down
7 changes: 3 additions & 4 deletions ignite/templates/module/placeholders.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
34 changes: 19 additions & 15 deletions ignite/templates/typed/list/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
32 changes: 18 additions & 14 deletions ignite/templates/typed/map/map.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
26 changes: 15 additions & 11 deletions ignite/templates/typed/singleton/singleton.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit 6179d70

Please sign in to comment.