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.

56 lines
1.6 KiB

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