Skip to content

Commit

Permalink
fix: unique constraint violation for group policy sim genesis (#15943)
Browse files Browse the repository at this point in the history
(cherry picked from commit e59c4a8)

# Conflicts:
#	simapp/sim_test.go
  • Loading branch information
gjermundgaraba authored and mergify[bot] committed Apr 26, 2023
1 parent 6b30073 commit 97d6507
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 5 deletions.
29 changes: 28 additions & 1 deletion simapp/sim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,12 +330,39 @@ func TestAppStateDeterminism(t *testing.T) {
numTimesToRunPerSeed := 5
appHashList := make([]json.RawMessage, numTimesToRunPerSeed)

<<<<<<< HEAD
appOptions := make(simtestutil.AppOptionsMap, 0)
appOptions[flags.FlagHome] = DefaultNodeHome
appOptions[server.FlagInvCheckPeriod] = simcli.FlagPeriodValue
=======
// We will be overriding the random seed and just run a single simulation on the provided seed value
if config.Seed != simcli.DefaultSeedValue {
numSeeds = 1
}

appOptions := viper.New()
if FlagEnableStreamingValue {
m := make(map[string]interface{})
m["streaming.abci.keys"] = []string{"*"}
m["streaming.abci.plugin"] = "abci_v1"
m["streaming.abci.stop-node-on-err"] = true
for key, value := range m {
appOptions.SetDefault(key, value)
}
}
appOptions.SetDefault(flags.FlagHome, DefaultNodeHome)
appOptions.SetDefault(server.FlagInvCheckPeriod, simcli.FlagPeriodValue)
if simcli.FlagVerboseValue {
appOptions.SetDefault(flags.FlagLogLevel, "debug")
}
>>>>>>> e59c4a857 (fix: unique constraint violation for group policy sim genesis (#15943))

for i := 0; i < numSeeds; i++ {
config.Seed = rand.Int63()
if config.Seed == simcli.DefaultSeedValue {
config.Seed = rand.Int63()
}

fmt.Println("config.Seed: ", config.Seed)

for j := 0; j < numTimesToRunPerSeed; j++ {
var logger log.Logger
Expand Down
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
4 changes: 3 additions & 1 deletion x/simulation/client/cli/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"github.com/cosmos/cosmos-sdk/types/simulation"
)

const DefaultSeedValue = 42

// List of available flags for the simulator
var (
FlagGenesisFileValue string
Expand Down Expand Up @@ -39,7 +41,7 @@ func GetSimulatorFlags() {
flag.IntVar(&FlagExportParamsHeightValue, "ExportParamsHeight", 0, "height to which export the randomly generated params")
flag.StringVar(&FlagExportStatePathValue, "ExportStatePath", "", "custom file path to save the exported app state JSON")
flag.StringVar(&FlagExportStatsPathValue, "ExportStatsPath", "", "custom file path to save the exported simulation statistics JSON")
flag.Int64Var(&FlagSeedValue, "Seed", 42, "simulation random seed")
flag.Int64Var(&FlagSeedValue, "Seed", DefaultSeedValue, "simulation random seed")
flag.IntVar(&FlagInitialBlockHeightValue, "InitialBlockHeight", 1, "initial block to start the simulation")
flag.IntVar(&FlagNumBlocksValue, "NumBlocks", 500, "number of new blocks to simulate from the initial block height")
flag.IntVar(&FlagBlockSizeValue, "BlockSize", 200, "operations per block")
Expand Down

0 comments on commit 97d6507

Please sign in to comment.