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

fix: flaky group genesis sim (backport #15447) #15461

Merged
merged 1 commit into from
Mar 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions x/group/simulation/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ const (
GroupVote = "group-vote"
)

func checkAccExists(acc sdk.AccAddress, g []*group.GroupMember, lastIndex int) bool {
s := acc.String()
for i := 0; i < lastIndex; i++ {
if g[i].Member.Address == s {
return true
}
}
return false
}

func getGroups(r *rand.Rand, accounts []simtypes.Account) []*group.GroupInfo {
groups := make([]*group.GroupInfo, 3)
for i := 0; i < 3; i++ {
Expand All @@ -40,6 +50,9 @@ func getGroupMembers(r *rand.Rand, accounts []simtypes.Account) []*group.GroupMe
groupMembers := make([]*group.GroupMember, 3)
for i := 0; i < 3; i++ {
acc, _ := simtypes.RandomAcc(r, accounts)
for checkAccExists(acc.Address, groupMembers, i) {
acc, _ = simtypes.RandomAcc(r, accounts)
}
groupMembers[i] = &group.GroupMember{
GroupId: uint64(i + 1),
Member: &group.Member{
Expand Down Expand Up @@ -147,6 +160,11 @@ func getVoteOption(index int) group.VoteOption {

// RandomizedGenState generates a random GenesisState for the group module.
func RandomizedGenState(simState *module.SimulationState) {
// The test requires we have at least 3 accounts.
if len(simState.Accounts) < 3 {
return
}

// groups
var groups []*group.GroupInfo
simState.AppParams.GetOrGenerate(
Expand Down