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: unique constraint violation for group policy sim genesis #15943

Merged
Merged
Changes from 1 commit
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
19 changes: 16 additions & 3 deletions x/group/simulation/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,21 +66,34 @@ func getGroupMembers(r *rand.Rand, accounts []simtypes.Account) []*group.GroupMe
}

func getGroupPolicies(r *rand.Rand, simState *module.SimulationState) []*group.GroupPolicyInfo {
groupPolicies := make([]*group.GroupPolicyInfo, 3)
var groupPolicies []*group.GroupPolicyInfo

usedAccs := make(map[string]bool)
for i := 0; i < 3; i++ {
acc, _ := simtypes.RandomAcc(r, simState.Accounts)

if usedAccs[acc.Address.String()] {
if len(usedAccs) != len(simState.Accounts) {
// Go again if the account is used and there are more to take from
i--
}

continue
}
usedAccs[acc.Address.String()] = true

any, err := codectypes.NewAnyWithValue(group.NewThresholdDecisionPolicy("10", time.Second, 0))
if err != nil {
panic(err)
}
groupPolicies[i] = &group.GroupPolicyInfo{
groupPolicies = append(groupPolicies, &group.GroupPolicyInfo{
GroupId: uint64(i + 1),
Admin: acc.Address.String(),
Address: acc.Address.String(),
Version: 1,
DecisionPolicy: any,
Metadata: simtypes.RandStringOfLength(r, 10),
}
})
}
return groupPolicies
}
Expand Down