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.

53 lines
1.8 KiB

7 years ago
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. "github.com/tendermint/tendermint/types"
  4. )
  5. //------------------------------------------------------
  6. // blockchain services types
  7. // NOTE: Interfaces used by RPC must be thread safe!
  8. //------------------------------------------------------
  9. //------------------------------------------------------
  10. // blockstore
  11. // BlockStoreRPC is the block store interface used by the RPC.
  12. type BlockStoreRPC interface {
  13. Height() int64
  14. LoadBlockMeta(height int64) *types.BlockMeta
  15. LoadBlock(height int64) *types.Block
  16. LoadBlockByHash(hash []byte) *types.Block
  17. LoadBlockPart(height int64, index int) *types.Part
  18. LoadBlockCommit(height int64) *types.Commit
  19. LoadSeenCommit(height int64) *types.Commit
  20. }
  21. // BlockStore defines the BlockStore interface used by the ConsensusState.
  22. type BlockStore interface {
  23. BlockStoreRPC
  24. SaveBlock(block *types.Block, blockParts *types.PartSet, seenCommit *types.Commit)
  25. }
  26. //-----------------------------------------------------------------------------------------------------
  27. // evidence pool
  28. // EvidencePool defines the EvidencePool interface used by the ConsensusState.
  29. // Get/Set/Commit
  30. type EvidencePool interface {
  31. PendingEvidence(int64) []types.Evidence
  32. AddEvidence(types.Evidence) error
  33. Update(*types.Block, State)
  34. // IsCommitted indicates if this evidence was already marked committed in another block.
  35. IsCommitted(types.Evidence) bool
  36. }
  37. // MockEvidencePool is an empty implementation of EvidencePool, useful for testing.
  38. type MockEvidencePool struct{}
  39. func (m MockEvidencePool) PendingEvidence(int64) []types.Evidence { return nil }
  40. func (m MockEvidencePool) AddEvidence(types.Evidence) error { return nil }
  41. func (m MockEvidencePool) Update(*types.Block, State) {}
  42. func (m MockEvidencePool) IsCommitted(types.Evidence) bool { return false }