diff --git a/x/mock/simulation/event_stats.go b/x/mock/simulation/event_stats.go index 5276c533b..f54eef4cc 100644 --- a/x/mock/simulation/event_stats.go +++ b/x/mock/simulation/event_stats.go @@ -10,12 +10,9 @@ type eventStats map[string]uint func newEventStats() eventStats { events := make(map[string]uint) return events - event := func(what string) { - events[what]++ - } } -func (es *eventStats) tally(eventDesc string) { +func (es eventStats) tally(eventDesc string) { es[eventDesc]++ } diff --git a/x/mock/simulation/mock_tendermint.go b/x/mock/simulation/mock_tendermint.go index a98e89614..2ddac2e79 100644 --- a/x/mock/simulation/mock_tendermint.go +++ b/x/mock/simulation/mock_tendermint.go @@ -20,9 +20,10 @@ type mockValidator struct { type mockValidators map[string]mockValidator // get mockValidators from abci validators -func newMockValidators(abciVals abci.ValidatorUpdate) mockValidators { +func newMockValidators(r *rand.Rand, abciVals []abci.ValidatorUpdate, + params Params) mockValidators { - validators = make(mockValidators) + validators := make(mockValidators) for _, validator := range abciVals { str := fmt.Sprintf("%v", validator.PubKey) liveliness := GetMemberOfInitialState(r, @@ -39,9 +40,9 @@ func newMockValidators(abciVals abci.ValidatorUpdate) mockValidators { // TODO describe usage func (vals mockValidators) getKeys() []string { - keys := make([]string, len(validators)) + keys := make([]string, len(vals)) i := 0 - for key := range validators { + for key := range vals { keys[i] = key i++ } @@ -52,13 +53,13 @@ func (vals mockValidators) getKeys() []string { //_________________________________________________________________________________ // randomProposer picks a random proposer from the current validator set -func randomProposer(r *rand.Rand, validators map[string]mockValidator) cmn.HexBytes { - keys := validators.getKeys() +func (vals mockValidators) randomProposer(r *rand.Rand) cmn.HexBytes { + keys := vals.getKeys() if len(keys) == 0 { return nil } key := keys[r.Intn(len(keys))] - proposer := validators[key].val + proposer := vals[key].val pk, err := tmtypes.PB2TM.PubKey(proposer.PubKey) if err != nil { panic(err) diff --git a/x/mock/simulation/operation.go b/x/mock/simulation/operation.go index 7710cf5c9..00237e03e 100644 --- a/x/mock/simulation/operation.go +++ b/x/mock/simulation/operation.go @@ -86,17 +86,17 @@ type WeightedOperation struct { // WeightedOperations is the group of all weighted operations to simulate. type WeightedOperations []WeightedOperation -func (w WeightedOperations) totalWeight() int { +func (ops WeightedOperations) totalWeight() int { totalOpWeight := 0 - for i := 0; i < len(w); i++ { - totalOpWeight += w[i].Weight + for _, op := range ops { + totalOpWeight += op.Weight } return totalOpWeight } type selectOpFn func(r *rand.Rand) Operation -func (w WeightedOperations) getSelectOpFn() selectOpFn { +func (ops WeightedOperations) getSelectOpFn() selectOpFn { totalOpWeight := ops.totalWeight() return func(r *rand.Rand) Operation { x := r.Intn(totalOpWeight) diff --git a/x/mock/simulation/simulate.go b/x/mock/simulation/simulate.go index e6749f4e1..ac0e5d3f7 100644 --- a/x/mock/simulation/simulate.go +++ b/x/mock/simulation/simulate.go @@ -43,7 +43,7 @@ func initChain(r *rand.Rand, params Params, accounts []Account, AppStateBytes: appStateFn(r, accounts), } res := app.InitChain(req) - validators = newMockValidators(res.Validators) + validators := newMockValidators(r, res.Validators, params) for i := 0; i < len(setups); i++ { setups[i](r, accounts) @@ -76,16 +76,16 @@ func SimulateFromSeed(tb testing.TB, app *baseapp.BaseApp, timeDiff := maxTimePerBlock - minTimePerBlock accs := RandomAccounts(r, params.NumKeys) eventStats := newEventStats() - validators := initChain(r, params, accs, setups, app, appStateFn) // Second variable to keep pending validator set (delayed one block since // TM 0.24) Initially this is the same as the initial validator set - nextValidators := validators() + validators := initChain(r, params, accs, setups, app, appStateFn) + nextValidators := validators header := abci.Header{ Height: 1, Time: timestamp, - ProposerAddress: randomProposer(r, validators), + ProposerAddress: validators.randomProposer(r), } opCount := 0 @@ -186,7 +186,7 @@ func SimulateFromSeed(tb testing.TB, app *baseapp.BaseApp, time.Duration(minTimePerBlock) * time.Second) header.Time = header.Time.Add( time.Duration(int64(r.Intn(int(timeDiff)))) * time.Second) - header.ProposerAddress = randomProposer(r, validators) + header.ProposerAddress = validators.randomProposer(r) logWriter("EndBlock") if testingMode {