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.

59 lines
1.6 KiB

  1. package lite_test
  2. import (
  3. "testing"
  4. "github.com/stretchr/testify/assert"
  5. "github.com/tendermint/tendermint/types"
  6. "github.com/tendermint/tendermint/lite"
  7. liteErr "github.com/tendermint/tendermint/lite/errors"
  8. )
  9. func TestStaticCert(t *testing.T) {
  10. // assert, require := assert.New(t), require.New(t)
  11. assert := assert.New(t)
  12. // require := require.New(t)
  13. keys := lite.GenValKeys(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 certifier based on our known set
  17. chainID := "test-static"
  18. cert := lite.NewStatic(chainID, vals)
  19. cases := []struct {
  20. keys lite.ValKeys
  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. // perfect, signed by everyone
  28. {keys, vals, 1, 0, len(keys), true, false},
  29. // skip little guy is okay
  30. {keys, vals, 2, 1, len(keys), true, false},
  31. // but not the big guy
  32. {keys, vals, 3, 0, len(keys) - 1, false, false},
  33. // even changing the power a little bit breaks the static validator
  34. // the sigs are enough, but the validator hash is unknown
  35. {keys, keys.ToValidators(20, 11), 4, 0, len(keys), false, true},
  36. }
  37. for _, tc := range cases {
  38. check := tc.keys.GenCommit(chainID, tc.height, nil, tc.vals,
  39. []byte("foo"), []byte("params"), tc.first, tc.last)
  40. err := cert.Certify(check)
  41. if tc.proper {
  42. assert.Nil(err, "%+v", err)
  43. } else {
  44. assert.NotNil(err)
  45. if tc.changed {
  46. assert.True(liteErr.IsValidatorsChangedErr(err), "%+v", err)
  47. }
  48. }
  49. }
  50. }