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.

62 lines
2.5 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)
5 years ago
  1. package state
  2. import (
  3. abci "github.com/tendermint/tendermint/abci/types"
  4. dbm "github.com/tendermint/tendermint/libs/db"
  5. "github.com/tendermint/tendermint/types"
  6. )
  7. //
  8. // TODO: Remove dependence on all entities exported from this file.
  9. //
  10. // Every entity exported here is dependent on a private entity from the `state`
  11. // package. Currently, these functions are only made available to tests in the
  12. // `state_test` package, but we should not be relying on them for our testing.
  13. // Instead, we should be exclusively relying on exported entities for our
  14. // testing, and should be refactoring exported entities to make them more
  15. // easily testable from outside of the package.
  16. //
  17. const ValSetCheckpointInterval = valSetCheckpointInterval
  18. // UpdateState is an alias for updateState exported from execution.go,
  19. // exclusively and explicitly for testing.
  20. func UpdateState(
  21. state State,
  22. blockID types.BlockID,
  23. header *types.Header,
  24. abciResponses *ABCIResponses,
  25. validatorUpdates []*types.Validator,
  26. ) (State, error) {
  27. return updateState(state, blockID, header, abciResponses, validatorUpdates)
  28. }
  29. // ValidateValidatorUpdates is an alias for validateValidatorUpdates exported
  30. // from execution.go, exclusively and explicitly for testing.
  31. func ValidateValidatorUpdates(abciUpdates []abci.ValidatorUpdate, params types.ValidatorParams) error {
  32. return validateValidatorUpdates(abciUpdates, params)
  33. }
  34. // CalcValidatorsKey is an alias for the private calcValidatorsKey method in
  35. // store.go, exported exclusively and explicitly for testing.
  36. func CalcValidatorsKey(height int64) []byte {
  37. return calcValidatorsKey(height)
  38. }
  39. // SaveABCIResponses is an alias for the private saveABCIResponses method in
  40. // store.go, exported exclusively and explicitly for testing.
  41. func SaveABCIResponses(db dbm.DB, height int64, abciResponses *ABCIResponses) {
  42. saveABCIResponses(db, height, abciResponses)
  43. }
  44. // SaveConsensusParamsInfo is an alias for the private saveConsensusParamsInfo
  45. // method in store.go, exported exclusively and explicitly for testing.
  46. func SaveConsensusParamsInfo(db dbm.DB, nextHeight, changeHeight int64, params types.ConsensusParams) {
  47. saveConsensusParamsInfo(db, nextHeight, changeHeight, params)
  48. }
  49. // SaveValidatorsInfo is an alias for the private saveValidatorsInfo method in
  50. // store.go, exported exclusively and explicitly for testing.
  51. func SaveValidatorsInfo(db dbm.DB, height, lastHeightChanged int64, valSet *types.ValidatorSet) {
  52. saveValidatorsInfo(db, height, lastHeightChanged, valSet)
  53. }