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.

66 lines
1.7 KiB

  1. package lite
  2. import (
  3. "testing"
  4. "github.com/stretchr/testify/assert"
  5. "github.com/tendermint/tendermint/crypto/tmhash"
  6. lerr "github.com/tendermint/tendermint/lite/errors"
  7. "github.com/tendermint/tendermint/types"
  8. )
  9. func TestBaseCert(t *testing.T) {
  10. // TODO: Requires proposer address to be set in header.
  11. t.SkipNow()
  12. assert := assert.New(t)
  13. keys := genPrivKeys(4)
  14. // 20, 30, 40, 50 - the first 3 don't have 2/3, the last 3 do!
  15. vals := keys.ToValidators(20, 10)
  16. // and a Verifier based on our known set
  17. chainID := "test-static"
  18. cert := NewBaseVerifier(chainID, 2, vals)
  19. cases := []struct {
  20. keys privKeys
  21. vals *types.ValidatorSet
  22. height int64
  23. first, last int // who actually signs
  24. proper bool // true -> expect no error
  25. changed bool // true -> expect validator change error
  26. }{
  27. // height regression
  28. {keys, vals, 1, 0, len(keys), false, false},
  29. // perfect, signed by everyone
  30. {keys, vals, 2, 0, len(keys), true, false},
  31. // skip little guy is okay
  32. {keys, vals, 3, 1, len(keys), true, false},
  33. // but not the big guy
  34. {keys, vals, 4, 0, len(keys) - 1, false, false},
  35. // Changing the power a little bit breaks the static validator.
  36. // The sigs are enough, but the validator hash is unknown.
  37. {keys, keys.ToValidators(20, 11), 5, 0, len(keys), false, true},
  38. }
  39. for _, tc := range cases {
  40. sh := tc.keys.GenSignedHeader(
  41. chainID, tc.height, nil, tc.vals, tc.vals,
  42. tmhash.Sum([]byte("foo")),
  43. tmhash.Sum([]byte("params")),
  44. tmhash.Sum([]byte("results")),
  45. tc.first, tc.last,
  46. )
  47. err := cert.Verify(sh)
  48. if tc.proper {
  49. assert.Nil(err, "%+v", err)
  50. } else {
  51. assert.NotNil(err)
  52. if tc.changed {
  53. assert.True(lerr.IsErrUnexpectedValidators(err), "%+v", err)
  54. }
  55. }
  56. }
  57. }