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.

42 lines
966 B

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