diff --git a/simapp/sim_test.go b/simapp/sim_test.go index f151124b19ba..5daa4b190234 100644 --- a/simapp/sim_test.go +++ b/simapp/sim_test.go @@ -325,6 +325,11 @@ func TestAppStateDeterminism(t *testing.T) { numTimesToRunPerSeed := 3 // This used to be set to 5, but we've temporarily reduced it to 3 for the sake of faster CI. appHashList := make([]json.RawMessage, numTimesToRunPerSeed) + // 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{}) @@ -342,7 +347,11 @@ func TestAppStateDeterminism(t *testing.T) { } 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 diff --git a/x/group/simulation/genesis.go b/x/group/simulation/genesis.go index 66b471fa5e47..7b533cf5daa3 100644 --- a/x/group/simulation/genesis.go +++ b/x/group/simulation/genesis.go @@ -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 } diff --git a/x/simulation/client/cli/flags.go b/x/simulation/client/cli/flags.go index bec5b6e8b712..43f0e4c52465 100644 --- a/x/simulation/client/cli/flags.go +++ b/x/simulation/client/cli/flags.go @@ -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 @@ -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")