compiling

This commit is contained in:
rigelrozanski 2018-11-08 01:57:37 -05:00
parent 5f289e5fdd
commit a9ef83bc4a
4 changed files with 18 additions and 20 deletions

View File

@ -10,12 +10,9 @@ type eventStats map[string]uint
func newEventStats() eventStats { func newEventStats() eventStats {
events := make(map[string]uint) events := make(map[string]uint)
return events return events
event := func(what string) {
events[what]++
}
} }
func (es *eventStats) tally(eventDesc string) { func (es eventStats) tally(eventDesc string) {
es[eventDesc]++ es[eventDesc]++
} }

View File

@ -20,9 +20,10 @@ type mockValidator struct {
type mockValidators map[string]mockValidator type mockValidators map[string]mockValidator
// get mockValidators from abci validators // 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 { for _, validator := range abciVals {
str := fmt.Sprintf("%v", validator.PubKey) str := fmt.Sprintf("%v", validator.PubKey)
liveliness := GetMemberOfInitialState(r, liveliness := GetMemberOfInitialState(r,
@ -39,9 +40,9 @@ func newMockValidators(abciVals abci.ValidatorUpdate) mockValidators {
// TODO describe usage // TODO describe usage
func (vals mockValidators) getKeys() []string { func (vals mockValidators) getKeys() []string {
keys := make([]string, len(validators)) keys := make([]string, len(vals))
i := 0 i := 0
for key := range validators { for key := range vals {
keys[i] = key keys[i] = key
i++ i++
} }
@ -52,13 +53,13 @@ func (vals mockValidators) getKeys() []string {
//_________________________________________________________________________________ //_________________________________________________________________________________
// randomProposer picks a random proposer from the current validator set // randomProposer picks a random proposer from the current validator set
func randomProposer(r *rand.Rand, validators map[string]mockValidator) cmn.HexBytes { func (vals mockValidators) randomProposer(r *rand.Rand) cmn.HexBytes {
keys := validators.getKeys() keys := vals.getKeys()
if len(keys) == 0 { if len(keys) == 0 {
return nil return nil
} }
key := keys[r.Intn(len(keys))] key := keys[r.Intn(len(keys))]
proposer := validators[key].val proposer := vals[key].val
pk, err := tmtypes.PB2TM.PubKey(proposer.PubKey) pk, err := tmtypes.PB2TM.PubKey(proposer.PubKey)
if err != nil { if err != nil {
panic(err) panic(err)

View File

@ -86,17 +86,17 @@ type WeightedOperation struct {
// WeightedOperations is the group of all weighted operations to simulate. // WeightedOperations is the group of all weighted operations to simulate.
type WeightedOperations []WeightedOperation type WeightedOperations []WeightedOperation
func (w WeightedOperations) totalWeight() int { func (ops WeightedOperations) totalWeight() int {
totalOpWeight := 0 totalOpWeight := 0
for i := 0; i < len(w); i++ { for _, op := range ops {
totalOpWeight += w[i].Weight totalOpWeight += op.Weight
} }
return totalOpWeight return totalOpWeight
} }
type selectOpFn func(r *rand.Rand) Operation type selectOpFn func(r *rand.Rand) Operation
func (w WeightedOperations) getSelectOpFn() selectOpFn { func (ops WeightedOperations) getSelectOpFn() selectOpFn {
totalOpWeight := ops.totalWeight() totalOpWeight := ops.totalWeight()
return func(r *rand.Rand) Operation { return func(r *rand.Rand) Operation {
x := r.Intn(totalOpWeight) x := r.Intn(totalOpWeight)

View File

@ -43,7 +43,7 @@ func initChain(r *rand.Rand, params Params, accounts []Account,
AppStateBytes: appStateFn(r, accounts), AppStateBytes: appStateFn(r, accounts),
} }
res := app.InitChain(req) res := app.InitChain(req)
validators = newMockValidators(res.Validators) validators := newMockValidators(r, res.Validators, params)
for i := 0; i < len(setups); i++ { for i := 0; i < len(setups); i++ {
setups[i](r, accounts) setups[i](r, accounts)
@ -76,16 +76,16 @@ func SimulateFromSeed(tb testing.TB, app *baseapp.BaseApp,
timeDiff := maxTimePerBlock - minTimePerBlock timeDiff := maxTimePerBlock - minTimePerBlock
accs := RandomAccounts(r, params.NumKeys) accs := RandomAccounts(r, params.NumKeys)
eventStats := newEventStats() eventStats := newEventStats()
validators := initChain(r, params, accs, setups, app, appStateFn)
// Second variable to keep pending validator set (delayed one block since // Second variable to keep pending validator set (delayed one block since
// TM 0.24) Initially this is the same as the initial validator set // 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{ header := abci.Header{
Height: 1, Height: 1,
Time: timestamp, Time: timestamp,
ProposerAddress: randomProposer(r, validators), ProposerAddress: validators.randomProposer(r),
} }
opCount := 0 opCount := 0
@ -186,7 +186,7 @@ func SimulateFromSeed(tb testing.TB, app *baseapp.BaseApp,
time.Duration(minTimePerBlock) * time.Second) time.Duration(minTimePerBlock) * time.Second)
header.Time = header.Time.Add( header.Time = header.Time.Add(
time.Duration(int64(r.Intn(int(timeDiff)))) * time.Second) time.Duration(int64(r.Intn(int(timeDiff)))) * time.Second)
header.ProposerAddress = randomProposer(r, validators) header.ProposerAddress = validators.randomProposer(r)
logWriter("EndBlock") logWriter("EndBlock")
if testingMode { if testingMode {