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.

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