You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
1.7 KiB

  1. package consensus
  2. import (
  3. "testing"
  4. "time"
  5. . "github.com/tendermint/tendermint/blocks"
  6. . "github.com/tendermint/tendermint/common"
  7. db_ "github.com/tendermint/tendermint/db"
  8. "github.com/tendermint/tendermint/mempool"
  9. "github.com/tendermint/tendermint/state"
  10. )
  11. func randAccountDetail(id uint64, status byte) (*state.AccountDetail, *state.PrivAccount) {
  12. privAccount := state.GenPrivAccount()
  13. privAccount.Id = id
  14. account := privAccount.Account
  15. return &state.AccountDetail{
  16. Account: account,
  17. Sequence: RandUInt(),
  18. Balance: RandUInt64() + 1000, // At least 1000.
  19. Status: status,
  20. }, privAccount
  21. }
  22. // The first numValidators accounts are validators.
  23. func randGenesisState(numAccounts int, numValidators int) (*state.State, []*state.PrivAccount) {
  24. db := db_.NewMemDB()
  25. accountDetails := make([]*state.AccountDetail, numAccounts)
  26. privAccounts := make([]*state.PrivAccount, numAccounts)
  27. for i := 0; i < numAccounts; i++ {
  28. if i < numValidators {
  29. accountDetails[i], privAccounts[i] =
  30. randAccountDetail(uint64(i), state.AccountStatusBonded)
  31. } else {
  32. accountDetails[i], privAccounts[i] =
  33. randAccountDetail(uint64(i), state.AccountStatusNominal)
  34. }
  35. }
  36. s0 := state.GenesisState(db, time.Now(), accountDetails)
  37. s0.Save(time.Now())
  38. return s0, privAccounts
  39. }
  40. func makeConsensusState() (*ConsensusState, []*state.PrivAccount) {
  41. state, privAccounts := randGenesisState(20, 10)
  42. blockStore := NewBlockStore(db_.NewMemDB())
  43. mempool := mempool.NewMempool(nil, state)
  44. cs := NewConsensusState(state, blockStore, mempool)
  45. return cs, privAccounts
  46. }
  47. func TestUnit(t *testing.T) {
  48. cs, privAccounts := makeConsensusState()
  49. rs := cs.GetRoundState()
  50. t.Log(rs)
  51. if false {
  52. t.Log(privAccounts)
  53. }
  54. }