| 448 | } |
| 449 | |
| 450 | func state(nVals int, height int64) (sm.State, dbm.DB, []types.PrivValidator) { |
| 451 | privVals := make([]types.PrivValidator, nVals) |
| 452 | vals := make([]types.GenesisValidator, nVals) |
| 453 | for i := 0; i < nVals; i++ { |
| 454 | privVal := types.NewMockPV() |
| 455 | privVals[i] = privVal |
| 456 | vals[i] = types.GenesisValidator{ |
| 457 | Address: privVal.PrivKey.PubKey().Address(), |
| 458 | PubKey: privVal.PrivKey.PubKey(), |
| 459 | Power: 1000, |
| 460 | Name: fmt.Sprintf("test%d", i), |
| 461 | } |
| 462 | } |
| 463 | s, _ := sm.MakeGenesisState(&types.GenesisDoc{ |
| 464 | ChainID: "test-chain", |
| 465 | Validators: vals, |
| 466 | AppHash: nil, |
| 467 | }) |
| 468 | |
| 469 | // save validators to db for 2 heights |
| 470 | stateDB := dbm.NewMemDB() |
| 471 | stateStore := sm.NewStore(stateDB, sm.StoreOptions{ |
| 472 | DiscardABCIResponses: false, |
| 473 | }) |
| 474 | if err := stateStore.Save(s); err != nil { |
| 475 | panic(err) |
| 476 | } |
| 477 | |
| 478 | for i := 1; i < int(height); i++ { |
| 479 | s.LastBlockHeight++ |
| 480 | s.LastValidators = s.Validators.Copy() |
| 481 | if err := stateStore.Save(s); err != nil { |
| 482 | panic(err) |
| 483 | } |
| 484 | } |
| 485 | return s, stateDB, privVals |
| 486 | } |