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.

45 lines
991 B

10 years ago
  1. package state
  2. import (
  3. . "github.com/tendermint/tendermint/common"
  4. "bytes"
  5. "testing"
  6. )
  7. func randValidator() *Validator {
  8. return &Validator{
  9. Account: Account{
  10. Id: RandUInt64(),
  11. PubKey: CRandBytes(32),
  12. },
  13. BondHeight: RandUInt32(),
  14. UnbondHeight: RandUInt32(),
  15. LastCommitHeight: RandUInt32(),
  16. VotingPower: RandUInt64(),
  17. Accum: int64(RandUInt64()),
  18. }
  19. }
  20. func randValidatorSet(numValidators int) *ValidatorSet {
  21. validators := make([]*Validator, numValidators)
  22. for i := 0; i < numValidators; i++ {
  23. validators[i] = randValidator()
  24. }
  25. return NewValidatorSet(validators)
  26. }
  27. func TestCopy(t *testing.T) {
  28. vset := randValidatorSet(10)
  29. vsetHash := vset.Hash()
  30. if len(vsetHash) == 0 {
  31. t.Fatalf("ValidatorSet had unexpected zero hash")
  32. }
  33. vsetCopy := vset.Copy()
  34. vsetCopyHash := vsetCopy.Hash()
  35. if !bytes.Equal(vsetHash, vsetCopyHash) {
  36. t.Fatalf("ValidatorSet copy had wrong hash. Orig: %X, Copy: %X", vsetHash, vsetCopyHash)
  37. }
  38. }