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.

41 lines
1.0 KiB

state: add more tests for block validation (#3674) * Expose priv validators for use in testing * Generalize block header validation test past height 1 * Remove ineffectual assignment * Remove redundant SaveState call * Reorder comment for clarity * Use the block executor ApplyBlock function instead of implementing a stripped-down version of it * Remove commented-out code * Remove unnecessary test The required tests already appear to be implemented (implicitly) through the TestValidateBlockHeader test. * Allow for catching of specific error types during TestValidateBlockCommit * Make return error testable * Clean up and add TestValidateBlockCommit code * Fix formatting * Extract function to create a new mock test app * Update comment for clarity * Fix comment * Add skeleton code for evidence-related test * Allow for addressing priv val by address * Generalize test beyond a single validator * Generalize TestValidateBlockEvidence past first height * Reorder code to clearly separate tests and utility code * Use a common constant for stop height for testing in state/validation_test.go * Refactor errors to resemble existing conventions * Fix formatting * Extract common helper functions Having the tests littered with helper functions makes them less easily readable imho, so I've pulled them out into a separate file. This also makes it easier to see what helper functions are available during testing, so we minimize the chance of duplication when writing new tests. * Remove unused parameter * Remove unused parameters * Add field keys * Remove unused height constant * Fix typo * Fix incorrect return error * Add field keys * Use separate package for tests This refactors all of the state package's tests into a state_test package, so as to keep any usage of the state package's internal methods explicit. Any internal methods/constants used by tests are now explicitly exported in state/export_test.go * Refactor: extract helper function to make, validate, execute and commit a block * Rename state function to makeState * Remove redundant constant for number of validators * Refactor mock evidence registration into TestMain * Remove extraneous nVals variable * Replace function-level TODOs with file-level TODO and explanation * Remove extraneous comment * Fix linting issues brought up by GolangCI (pulled in from latest merge from develop)
6 years ago
  1. package types
  2. import "fmt"
  3. type (
  4. // ErrInvalidCommitHeight is returned when we encounter a commit with an
  5. // unexpected height.
  6. ErrInvalidCommitHeight struct {
  7. Expected int64
  8. Actual int64
  9. }
  10. // ErrInvalidCommitPrecommits is returned when we encounter a commit where
  11. // the number of precommits doesn't match the number of validators.
  12. ErrInvalidCommitPrecommits struct {
  13. Expected int
  14. Actual int
  15. }
  16. )
  17. func NewErrInvalidCommitHeight(expected, actual int64) ErrInvalidCommitHeight {
  18. return ErrInvalidCommitHeight{
  19. Expected: expected,
  20. Actual: actual,
  21. }
  22. }
  23. func (e ErrInvalidCommitHeight) Error() string {
  24. return fmt.Sprintf("Invalid commit -- wrong height: %v vs %v", e.Expected, e.Actual)
  25. }
  26. func NewErrInvalidCommitPrecommits(expected, actual int) ErrInvalidCommitPrecommits {
  27. return ErrInvalidCommitPrecommits{
  28. Expected: expected,
  29. Actual: actual,
  30. }
  31. }
  32. func (e ErrInvalidCommitPrecommits) Error() string {
  33. return fmt.Sprintf("Invalid commit -- wrong set size: %v vs %v", e.Expected, e.Actual)
  34. }