Skip to content

Commit

Permalink
fix: flaky group genesis sim (#15447)
Browse files Browse the repository at this point in the history
  • Loading branch information
robert-zaremba committed Mar 20, 2023
1 parent 124aed4 commit f4a6feb
Showing 1 changed file with 18 additions and 0 deletions.
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

0 comments on commit f4a6feb

Please sign in to comment.