Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update test setups to use testutil.MutateGenesisState #2013

Open
4 tasks
nullpointer0x00 opened this issue May 29, 2024 · 0 comments
Open
4 tasks

Update test setups to use testutil.MutateGenesisState #2013

nullpointer0x00 opened this issue May 29, 2024 · 0 comments
Labels
good first issue Good for newcomers nice-to-have Features not required in upcoming milestone
Milestone

Comments

@nullpointer0x00
Copy link
Contributor

Summary

Test setups that manually configure GenesisState should be converted to using the testutil.MutateGenesisState.

Problem Definition

Example from x/name/client/cli/cli_test.go:

	var nameData nametypes.GenesisState
	nameData.Params.AllowUnrestrictedNames = true
	nameData.Params.MaxNameLevels = 2
	nameData.Params.MaxSegmentLength = 32
	nameData.Params.MinSegmentLength = 1
	nameData.Bindings = append(nameData.Bindings, nametypes.NewNameRecord("attribute", s.accountAddr, false))
	nameData.Bindings = append(nameData.Bindings, nametypes.NewNameRecord("example.attribute", s.accountAddr, false))
	for i := 0; i < s.acc2NameCount; i++ {
		nameData.Bindings = append(nameData.Bindings, nametypes.NewNameRecord(toWritten(i), s.account2Addr, false))
	}
	nameDataBz, err := cfg.Codec.MarshalJSON(&nameData)
	s.Require().NoError(err)
	genesisState[nametypes.ModuleName] = nameDataBz

Should be converted to:

	testutil.MutateGenesisState(s.T(), &s.cfg, nametypes.ModuleName, &nametypes.GenesisState{}, func(nameData *nametypes.GenesisState) *nametypes.GenesisState {
		nameData.Params.AllowUnrestrictedNames = true
		nameData.Params.MaxNameLevels = 2
		nameData.Params.MaxSegmentLength = 32
		nameData.Params.MinSegmentLength = 1
		nameData.Bindings = append(nameData.Bindings, nametypes.NewNameRecord("attribute", s.accountAddr, false))
		nameData.Bindings = append(nameData.Bindings, nametypes.NewNameRecord("example.attribute", s.accountAddr, false))
		for i := 0; i < s.acc2NameCount; i++ {
			nameData.Bindings = append(nameData.Bindings, nametypes.NewNameRecord(toWritten(i), s.account2Addr, false))
		}
		return nameData
	})

Proposal

Converting tests to use testutil.MutateGenesisState will make them cleaner and more consistent.


For Admin Use

  • Not duplicate issue
  • Appropriate labels applied
  • Appropriate contributors tagged
  • Contributor assigned/self-assigned
@nullpointer0x00 nullpointer0x00 added good first issue Good for newcomers nice-to-have Features not required in upcoming milestone labels May 29, 2024
@SpicyLemon SpicyLemon added this to the backlog milestone Aug 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers nice-to-have Features not required in upcoming milestone
Projects
Development

No branches or pull requests

2 participants