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.

641 lines
20 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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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_test
  2. import (
  3. "fmt"
  4. "testing"
  5. "time"
  6. "github.com/stretchr/testify/assert"
  7. "github.com/stretchr/testify/mock"
  8. "github.com/stretchr/testify/require"
  9. "github.com/tendermint/tendermint/crypto"
  10. "github.com/tendermint/tendermint/libs/bytes"
  11. "github.com/tendermint/tendermint/proto/tendermint/version"
  12. "github.com/tendermint/tendermint/crypto/ed25519"
  13. "github.com/tendermint/tendermint/crypto/tmhash"
  14. "github.com/tendermint/tendermint/libs/log"
  15. memmock "github.com/tendermint/tendermint/mempool/mock"
  16. protostate "github.com/tendermint/tendermint/proto/tendermint/state"
  17. tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
  18. sm "github.com/tendermint/tendermint/state"
  19. "github.com/tendermint/tendermint/state/mocks"
  20. "github.com/tendermint/tendermint/types"
  21. tmtime "github.com/tendermint/tendermint/types/time"
  22. )
  23. const validationTestsStopHeight int64 = 10
  24. var defaultTestTime = time.Date(2019, 1, 1, 0, 0, 0, 0, time.UTC)
  25. func TestValidateBlockHeader(t *testing.T) {
  26. proxyApp := newTestApp()
  27. require.NoError(t, proxyApp.Start())
  28. defer proxyApp.Stop()
  29. state, stateDB, privVals := makeState(3, 1)
  30. blockExec := sm.NewBlockExecutor(
  31. stateDB,
  32. log.TestingLogger(),
  33. proxyApp.Consensus(),
  34. memmock.Mempool{},
  35. sm.MockEvidencePool{},
  36. )
  37. lastCommit := types.NewCommit(0, 0, types.BlockID{}, nil)
  38. // some bad values
  39. wrongHash := tmhash.Sum([]byte("this hash is wrong"))
  40. wrongVersion1 := state.Version.Consensus
  41. wrongVersion1.Block += 2
  42. wrongVersion2 := state.Version.Consensus
  43. wrongVersion2.App += 2
  44. // Manipulation of any header field causes failure.
  45. testCases := []struct {
  46. name string
  47. malleateBlock func(block *types.Block)
  48. }{
  49. {"Version wrong1", func(block *types.Block) { block.Version = wrongVersion1 }},
  50. {"Version wrong2", func(block *types.Block) { block.Version = wrongVersion2 }},
  51. {"ChainID wrong", func(block *types.Block) { block.ChainID = "not-the-real-one" }},
  52. {"Height wrong", func(block *types.Block) { block.Height += 10 }},
  53. {"Time wrong", func(block *types.Block) { block.Time = block.Time.Add(-time.Second * 1) }},
  54. {"LastBlockID wrong", func(block *types.Block) { block.LastBlockID.PartSetHeader.Total += 10 }},
  55. {"LastCommitHash wrong", func(block *types.Block) { block.LastCommitHash = wrongHash }},
  56. {"DataHash wrong", func(block *types.Block) { block.DataHash = wrongHash }},
  57. {"ValidatorsHash wrong", func(block *types.Block) { block.ValidatorsHash = wrongHash }},
  58. {"NextValidatorsHash wrong", func(block *types.Block) { block.NextValidatorsHash = wrongHash }},
  59. {"ConsensusHash wrong", func(block *types.Block) { block.ConsensusHash = wrongHash }},
  60. {"AppHash wrong", func(block *types.Block) { block.AppHash = wrongHash }},
  61. {"LastResultsHash wrong", func(block *types.Block) { block.LastResultsHash = wrongHash }},
  62. {"EvidenceHash wrong", func(block *types.Block) { block.EvidenceHash = wrongHash }},
  63. {"Proposer wrong", func(block *types.Block) { block.ProposerAddress = ed25519.GenPrivKey().PubKey().Address() }},
  64. {"Proposer invalid", func(block *types.Block) { block.ProposerAddress = []byte("wrong size") }},
  65. }
  66. // Build up state for multiple heights
  67. for height := int64(1); height < validationTestsStopHeight; height++ {
  68. proposerAddr := state.Validators.GetProposer().Address
  69. /*
  70. Invalid blocks don't pass
  71. */
  72. for _, tc := range testCases {
  73. block, _ := state.MakeBlock(height, makeTxs(height), lastCommit, nil, proposerAddr)
  74. tc.malleateBlock(block)
  75. err := blockExec.ValidateBlock(state, block)
  76. require.Error(t, err, tc.name)
  77. }
  78. /*
  79. A good block passes
  80. */
  81. var err error
  82. state, _, lastCommit, err = makeAndCommitGoodBlock(state, height, lastCommit, proposerAddr, blockExec, privVals, nil)
  83. require.NoError(t, err, "height %d", height)
  84. }
  85. }
  86. func TestValidateBlockCommit(t *testing.T) {
  87. proxyApp := newTestApp()
  88. require.NoError(t, proxyApp.Start())
  89. defer proxyApp.Stop()
  90. state, stateDB, privVals := makeState(1, 1)
  91. blockExec := sm.NewBlockExecutor(
  92. stateDB,
  93. log.TestingLogger(),
  94. proxyApp.Consensus(),
  95. memmock.Mempool{},
  96. sm.MockEvidencePool{},
  97. )
  98. lastCommit := types.NewCommit(0, 0, types.BlockID{}, nil)
  99. wrongSigsCommit := types.NewCommit(1, 0, types.BlockID{}, nil)
  100. badPrivVal := types.NewMockPV()
  101. for height := int64(1); height < validationTestsStopHeight; height++ {
  102. proposerAddr := state.Validators.GetProposer().Address
  103. if height > 1 {
  104. /*
  105. #2589: ensure state.LastValidators.VerifyCommit fails here
  106. */
  107. // should be height-1 instead of height
  108. wrongHeightVote, err := types.MakeVote(
  109. height,
  110. state.LastBlockID,
  111. state.Validators,
  112. privVals[proposerAddr.String()],
  113. chainID,
  114. time.Now(),
  115. )
  116. require.NoError(t, err, "height %d", height)
  117. wrongHeightCommit := types.NewCommit(
  118. wrongHeightVote.Height,
  119. wrongHeightVote.Round,
  120. state.LastBlockID,
  121. []types.CommitSig{wrongHeightVote.CommitSig()},
  122. )
  123. block, _ := state.MakeBlock(height, makeTxs(height), wrongHeightCommit, nil, proposerAddr)
  124. err = blockExec.ValidateBlock(state, block)
  125. _, isErrInvalidCommitHeight := err.(types.ErrInvalidCommitHeight)
  126. require.True(t, isErrInvalidCommitHeight, "expected ErrInvalidCommitHeight at height %d but got: %v", height, err)
  127. /*
  128. #2589: test len(block.LastCommit.Signatures) == state.LastValidators.Size()
  129. */
  130. block, _ = state.MakeBlock(height, makeTxs(height), wrongSigsCommit, nil, proposerAddr)
  131. err = blockExec.ValidateBlock(state, block)
  132. _, isErrInvalidCommitSignatures := err.(types.ErrInvalidCommitSignatures)
  133. require.True(t, isErrInvalidCommitSignatures,
  134. "expected ErrInvalidCommitSignatures at height %d, but got: %v",
  135. height,
  136. err,
  137. )
  138. }
  139. /*
  140. A good block passes
  141. */
  142. var err error
  143. var blockID types.BlockID
  144. state, blockID, lastCommit, err = makeAndCommitGoodBlock(
  145. state,
  146. height,
  147. lastCommit,
  148. proposerAddr,
  149. blockExec,
  150. privVals,
  151. nil,
  152. )
  153. require.NoError(t, err, "height %d", height)
  154. /*
  155. wrongSigsCommit is fine except for the extra bad precommit
  156. */
  157. goodVote, err := types.MakeVote(height,
  158. blockID,
  159. state.Validators,
  160. privVals[proposerAddr.String()],
  161. chainID,
  162. time.Now(),
  163. )
  164. require.NoError(t, err, "height %d", height)
  165. bpvPubKey, err := badPrivVal.GetPubKey()
  166. require.NoError(t, err)
  167. badVote := &types.Vote{
  168. ValidatorAddress: bpvPubKey.Address(),
  169. ValidatorIndex: 0,
  170. Height: height,
  171. Round: 0,
  172. Timestamp: tmtime.Now(),
  173. Type: tmproto.PrecommitType,
  174. BlockID: blockID,
  175. }
  176. g := goodVote.ToProto()
  177. b := badVote.ToProto()
  178. err = badPrivVal.SignVote(chainID, g)
  179. require.NoError(t, err, "height %d", height)
  180. err = badPrivVal.SignVote(chainID, b)
  181. require.NoError(t, err, "height %d", height)
  182. goodVote.Signature, badVote.Signature = g.Signature, b.Signature
  183. wrongSigsCommit = types.NewCommit(goodVote.Height, goodVote.Round,
  184. blockID, []types.CommitSig{goodVote.CommitSig(), badVote.CommitSig()})
  185. }
  186. }
  187. func TestValidateBlockEvidence(t *testing.T) {
  188. proxyApp := newTestApp()
  189. require.NoError(t, proxyApp.Start())
  190. defer proxyApp.Stop()
  191. state, stateDB, privVals := makeState(4, 1)
  192. state.ConsensusParams.Evidence.MaxNum = 3
  193. blockExec := sm.NewBlockExecutor(
  194. stateDB,
  195. log.TestingLogger(),
  196. proxyApp.Consensus(),
  197. memmock.Mempool{},
  198. sm.MockEvidencePool{},
  199. )
  200. lastCommit := types.NewCommit(0, 0, types.BlockID{}, nil)
  201. for height := int64(1); height < validationTestsStopHeight; height++ {
  202. proposerAddr := state.Validators.GetProposer().Address
  203. maxNumEvidence := state.ConsensusParams.Evidence.MaxNum
  204. t.Log(maxNumEvidence)
  205. if height > 1 {
  206. /*
  207. A block with too much evidence fails
  208. */
  209. require.True(t, maxNumEvidence > 2)
  210. evidence := make([]types.Evidence, 0)
  211. // one more than the maximum allowed evidence
  212. for i := uint32(0); i <= maxNumEvidence; i++ {
  213. evidence = append(evidence, types.NewMockEvidence(height, time.Now(), proposerAddr))
  214. }
  215. block, _ := state.MakeBlock(height, makeTxs(height), lastCommit, evidence, proposerAddr)
  216. err := blockExec.ValidateBlock(state, block)
  217. _, ok := err.(*types.ErrEvidenceOverflow)
  218. require.True(t, ok, "expected error to be of type ErrEvidenceOverflow at height %d", height)
  219. }
  220. /*
  221. A good block with several pieces of good evidence passes
  222. */
  223. require.True(t, maxNumEvidence > 2)
  224. evidence := make([]types.Evidence, 0)
  225. // precisely the amount of allowed evidence
  226. for i := int32(0); uint32(i) < maxNumEvidence; i++ {
  227. // make different evidence for each validator
  228. addr, _ := state.Validators.GetByIndex(i)
  229. evidence = append(evidence, types.NewMockEvidence(height, time.Now(), addr))
  230. }
  231. var err error
  232. state, _, lastCommit, err = makeAndCommitGoodBlock(
  233. state,
  234. height,
  235. lastCommit,
  236. proposerAddr,
  237. blockExec,
  238. privVals,
  239. evidence,
  240. )
  241. require.NoError(t, err, "height %d", height)
  242. }
  243. }
  244. func TestValidateFailBlockOnCommittedEvidence(t *testing.T) {
  245. var height int64 = 1
  246. state, stateDB, _ := makeState(2, int(height))
  247. addr, _ := state.Validators.GetByIndex(0)
  248. addr2, _ := state.Validators.GetByIndex(1)
  249. ev := types.NewMockEvidence(height, defaultTestTime, addr)
  250. ev2 := types.NewMockEvidence(height, defaultTestTime, addr2)
  251. evpool := &mocks.EvidencePool{}
  252. evpool.On("IsPending", mock.AnythingOfType("types.MockEvidence")).Return(false)
  253. evpool.On("IsCommitted", ev).Return(false)
  254. evpool.On("IsCommitted", ev2).Return(true)
  255. blockExec := sm.NewBlockExecutor(
  256. stateDB, log.TestingLogger(),
  257. nil,
  258. nil,
  259. evpool)
  260. // A block with a couple pieces of evidence passes.
  261. block := makeBlock(state, height)
  262. block.Evidence.Evidence = []types.Evidence{ev, ev2}
  263. block.EvidenceHash = block.Evidence.Hash()
  264. err := blockExec.ValidateBlock(state, block)
  265. assert.Error(t, err)
  266. assert.IsType(t, err, &types.ErrEvidenceInvalid{})
  267. }
  268. func TestValidateAlreadyPendingEvidence(t *testing.T) {
  269. var height int64 = 1
  270. state, stateDB, _ := makeState(2, int(height))
  271. addr, _ := state.Validators.GetByIndex(0)
  272. addr2, _ := state.Validators.GetByIndex(1)
  273. ev := types.NewMockEvidence(height, defaultTestTime, addr)
  274. ev2 := types.NewMockEvidence(height, defaultTestTime, addr2)
  275. evpool := &mocks.EvidencePool{}
  276. evpool.On("IsPending", ev).Return(false)
  277. evpool.On("IsPending", ev2).Return(true)
  278. evpool.On("IsCommitted", mock.AnythingOfType("types.MockEvidence")).Return(false)
  279. blockExec := sm.NewBlockExecutor(
  280. stateDB, log.TestingLogger(),
  281. nil,
  282. nil,
  283. evpool)
  284. // A block with a couple pieces of evidence passes.
  285. block := makeBlock(state, height)
  286. // add one evidence seen before and one evidence that hasn't
  287. block.Evidence.Evidence = []types.Evidence{ev, ev2}
  288. block.EvidenceHash = block.Evidence.Hash()
  289. err := blockExec.ValidateBlock(state, block)
  290. assert.NoError(t, err)
  291. }
  292. func TestValidateDuplicateEvidenceShouldFail(t *testing.T) {
  293. var height int64 = 1
  294. state, stateDB, _ := makeState(1, int(height))
  295. addr, _ := state.Validators.GetByIndex(0)
  296. addr2, _ := state.Validators.GetByIndex(1)
  297. ev := types.NewMockEvidence(height, defaultTestTime, addr)
  298. ev2 := types.NewMockEvidence(height, defaultTestTime, addr2)
  299. blockExec := sm.NewBlockExecutor(
  300. stateDB, log.TestingLogger(),
  301. nil,
  302. nil,
  303. sm.MockEvidencePool{})
  304. // A block with a couple pieces of evidence passes.
  305. block := makeBlock(state, height)
  306. block.Evidence.Evidence = []types.Evidence{ev, ev2, ev2}
  307. block.EvidenceHash = block.Evidence.Hash()
  308. err := blockExec.ValidateBlock(state, block)
  309. assert.Error(t, err)
  310. }
  311. var blockID = types.BlockID{
  312. Hash: []byte("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"),
  313. PartSetHeader: types.PartSetHeader{
  314. Total: 1,
  315. Hash: []byte("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"),
  316. },
  317. }
  318. func TestValidateAmnesiaEvidence(t *testing.T) {
  319. var height int64 = 1
  320. state, stateDB, vals := makeState(1, int(height))
  321. addr, val := state.Validators.GetByIndex(0)
  322. voteA := makeVote(height, 1, 0, addr, blockID)
  323. vA := voteA.ToProto()
  324. err := vals[val.Address.String()].SignVote(chainID, vA)
  325. voteA.Signature = vA.Signature
  326. require.NoError(t, err)
  327. voteB := makeVote(height, 2, 0, addr, types.BlockID{})
  328. vB := voteB.ToProto()
  329. err = vals[val.Address.String()].SignVote(chainID, vB)
  330. voteB.Signature = vB.Signature
  331. require.NoError(t, err)
  332. ae := types.AmnesiaEvidence{
  333. PotentialAmnesiaEvidence: types.PotentialAmnesiaEvidence{
  334. VoteA: voteA,
  335. VoteB: voteB,
  336. },
  337. Polc: types.EmptyPOLC(),
  338. }
  339. evpool := &mocks.EvidencePool{}
  340. evpool.On("IsPending", ae).Return(false)
  341. evpool.On("IsCommitted", ae).Return(false)
  342. evpool.On("AddEvidence", ae).Return(fmt.Errorf("test error"))
  343. blockExec := sm.NewBlockExecutor(
  344. stateDB, log.TestingLogger(),
  345. nil,
  346. nil,
  347. evpool)
  348. // A block with a couple pieces of evidence passes.
  349. block := makeBlock(state, height)
  350. block.Evidence.Evidence = []types.Evidence{ae}
  351. block.EvidenceHash = block.Evidence.Hash()
  352. err = blockExec.ValidateBlock(state, block)
  353. errMsg := "Invalid evidence: unknown amnesia evidence, trying to add to evidence pool, err: test error"
  354. if assert.Error(t, err) {
  355. assert.Equal(t, err.Error()[:len(errMsg)], errMsg)
  356. }
  357. }
  358. func TestVerifyEvidenceWrongAddress(t *testing.T) {
  359. var height int64 = 1
  360. state, stateDB, _ := makeState(1, int(height))
  361. randomAddr := []byte("wrong address")
  362. ev := types.NewMockEvidence(height, defaultTestTime, randomAddr)
  363. blockExec := sm.NewBlockExecutor(
  364. stateDB, log.TestingLogger(),
  365. nil,
  366. nil,
  367. sm.MockEvidencePool{})
  368. // A block with a couple pieces of evidence passes.
  369. block := makeBlock(state, height)
  370. block.Evidence.Evidence = []types.Evidence{ev}
  371. block.EvidenceHash = block.Evidence.Hash()
  372. err := blockExec.ValidateBlock(state, block)
  373. errMsg := "Invalid evidence: address 77726F6E672061646472657373 was not a validator at height 1"
  374. if assert.Error(t, err) {
  375. assert.Equal(t, err.Error()[:len(errMsg)], errMsg)
  376. }
  377. }
  378. func TestVerifyEvidenceExpiredEvidence(t *testing.T) {
  379. var height int64 = 4
  380. state, stateDB, _ := makeState(1, int(height))
  381. state.ConsensusParams.Evidence.MaxAgeNumBlocks = 1
  382. addr, _ := state.Validators.GetByIndex(0)
  383. ev := types.NewMockEvidence(1, defaultTestTime, addr)
  384. err := sm.VerifyEvidence(stateDB, state, ev, nil)
  385. errMsg := "evidence from height 1 (created at: 2019-01-01 00:00:00 +0000 UTC) is too old"
  386. if assert.Error(t, err) {
  387. assert.Equal(t, err.Error()[:len(errMsg)], errMsg)
  388. }
  389. }
  390. func TestVerifyEvidenceWithAmnesiaEvidence(t *testing.T) {
  391. var height int64 = 1
  392. state, stateDB, vals := makeState(4, int(height))
  393. addr, val := state.Validators.GetByIndex(0)
  394. addr2, val2 := state.Validators.GetByIndex(1)
  395. voteA := makeVote(height, 1, 0, addr, types.BlockID{})
  396. vA := voteA.ToProto()
  397. err := vals[val.Address.String()].SignVote(chainID, vA)
  398. voteA.Signature = vA.Signature
  399. require.NoError(t, err)
  400. voteB := makeVote(height, 2, 0, addr, blockID)
  401. vB := voteB.ToProto()
  402. err = vals[val.Address.String()].SignVote(chainID, vB)
  403. voteB.Signature = vB.Signature
  404. require.NoError(t, err)
  405. voteC := makeVote(height, 2, 1, addr2, blockID)
  406. vC := voteC.ToProto()
  407. err = vals[val2.Address.String()].SignVote(chainID, vC)
  408. voteC.Signature = vC.Signature
  409. require.NoError(t, err)
  410. //var ae types.Evidence
  411. badAe := types.AmnesiaEvidence{
  412. PotentialAmnesiaEvidence: types.PotentialAmnesiaEvidence{
  413. VoteA: voteA,
  414. VoteB: voteB,
  415. },
  416. Polc: types.ProofOfLockChange{
  417. Votes: []types.Vote{*voteC},
  418. PubKey: val.PubKey,
  419. },
  420. }
  421. err = sm.VerifyEvidence(stateDB, state, badAe, nil)
  422. if assert.Error(t, err) {
  423. assert.Equal(t, err.Error(), "amnesia evidence contains invalid polc, err: "+
  424. "invalid commit -- insufficient voting power: got 1000, needed more than 2667")
  425. }
  426. addr3, val3 := state.Validators.GetByIndex(2)
  427. voteD := makeVote(height, 2, 2, addr3, blockID)
  428. vD := voteD.ToProto()
  429. err = vals[val3.Address.String()].SignVote(chainID, vD)
  430. require.NoError(t, err)
  431. voteD.Signature = vD.Signature
  432. addr4, val4 := state.Validators.GetByIndex(3)
  433. voteE := makeVote(height, 2, 3, addr4, blockID)
  434. vE := voteE.ToProto()
  435. err = vals[val4.Address.String()].SignVote(chainID, vE)
  436. voteE.Signature = vE.Signature
  437. require.NoError(t, err)
  438. goodAe := types.AmnesiaEvidence{
  439. PotentialAmnesiaEvidence: types.PotentialAmnesiaEvidence{
  440. VoteA: voteA,
  441. VoteB: voteB,
  442. },
  443. Polc: types.ProofOfLockChange{
  444. Votes: []types.Vote{*voteC, *voteD, *voteE},
  445. PubKey: val.PubKey,
  446. },
  447. }
  448. err = sm.VerifyEvidence(stateDB, state, goodAe, nil)
  449. assert.NoError(t, err)
  450. goodAe = types.AmnesiaEvidence{
  451. PotentialAmnesiaEvidence: types.PotentialAmnesiaEvidence{
  452. VoteA: voteA,
  453. VoteB: voteB,
  454. },
  455. Polc: types.EmptyPOLC(),
  456. }
  457. err = sm.VerifyEvidence(stateDB, state, goodAe, nil)
  458. assert.NoError(t, err)
  459. }
  460. func TestVerifyEvidenceWithLunaticValidatorEvidence(t *testing.T) {
  461. state, stateDB, vals := makeState(4, 4)
  462. state.ConsensusParams.Evidence.MaxAgeNumBlocks = 1
  463. addr, val := state.Validators.GetByIndex(0)
  464. h := &types.Header{
  465. Version: version.Consensus{Block: 1, App: 2},
  466. ChainID: chainID,
  467. Height: 3,
  468. Time: defaultTestTime,
  469. LastBlockID: blockID,
  470. LastCommitHash: tmhash.Sum([]byte("last_commit_hash")),
  471. DataHash: tmhash.Sum([]byte("data_hash")),
  472. ValidatorsHash: tmhash.Sum([]byte("validators_hash")),
  473. NextValidatorsHash: tmhash.Sum([]byte("next_validators_hash")),
  474. ConsensusHash: tmhash.Sum([]byte("consensus_hash")),
  475. AppHash: tmhash.Sum([]byte("app_hash")),
  476. LastResultsHash: tmhash.Sum([]byte("last_results_hash")),
  477. EvidenceHash: tmhash.Sum([]byte("evidence_hash")),
  478. ProposerAddress: crypto.AddressHash([]byte("proposer_address")),
  479. }
  480. vote := makeVote(3, 1, 0, addr, blockID)
  481. v := vote.ToProto()
  482. err := vals[val.Address.String()].SignVote(chainID, v)
  483. vote.Signature = v.Signature
  484. require.NoError(t, err)
  485. ev := types.LunaticValidatorEvidence{
  486. Header: h,
  487. Vote: vote,
  488. InvalidHeaderField: "ConsensusHash",
  489. }
  490. err = ev.ValidateBasic()
  491. require.NoError(t, err)
  492. err = sm.VerifyEvidence(stateDB, state, ev, h)
  493. if assert.Error(t, err) {
  494. assert.Equal(t, "ConsensusHash matches committed hash", err.Error())
  495. }
  496. }
  497. func TestVerifyEvidenceWithPhantomValidatorEvidence(t *testing.T) {
  498. state, stateDB, vals := makeState(4, 4)
  499. state.ConsensusParams.Evidence.MaxAgeNumBlocks = 1
  500. addr, val := state.Validators.GetByIndex(0)
  501. vote := makeVote(3, 1, 0, addr, blockID)
  502. v := vote.ToProto()
  503. err := vals[val.Address.String()].SignVote(chainID, v)
  504. vote.Signature = v.Signature
  505. require.NoError(t, err)
  506. ev := types.PhantomValidatorEvidence{
  507. Vote: vote,
  508. LastHeightValidatorWasInSet: 1,
  509. }
  510. err = ev.ValidateBasic()
  511. require.NoError(t, err)
  512. err = sm.VerifyEvidence(stateDB, state, ev, nil)
  513. if assert.Error(t, err) {
  514. assert.Equal(t, "address 576585A00DD4D58318255611D8AAC60E8E77CB32 was a validator at height 3", err.Error())
  515. }
  516. privVal := types.NewMockPV()
  517. pubKey, _ := privVal.GetPubKey()
  518. vote2 := makeVote(3, 1, 0, pubKey.Address(), blockID)
  519. v2 := vote2.ToProto()
  520. err = privVal.SignVote(chainID, v2)
  521. vote2.Signature = v2.Signature
  522. require.NoError(t, err)
  523. ev = types.PhantomValidatorEvidence{
  524. Vote: vote2,
  525. LastHeightValidatorWasInSet: 1,
  526. }
  527. err = ev.ValidateBasic()
  528. assert.NoError(t, err)
  529. err = sm.VerifyEvidence(stateDB, state, ev, nil)
  530. if assert.Error(t, err) {
  531. assert.Equal(t, "last time validator was in the set at height 1, min: 2", err.Error())
  532. }
  533. ev = types.PhantomValidatorEvidence{
  534. Vote: vote2,
  535. LastHeightValidatorWasInSet: 2,
  536. }
  537. err = ev.ValidateBasic()
  538. assert.NoError(t, err)
  539. err = sm.VerifyEvidence(stateDB, state, ev, nil)
  540. errMsg := "phantom validator"
  541. if assert.Error(t, err) {
  542. assert.Equal(t, errMsg, err.Error()[:len(errMsg)])
  543. }
  544. vals2, err := sm.LoadValidators(stateDB, 2)
  545. require.NoError(t, err)
  546. vals2.Validators = append(vals2.Validators, types.NewValidator(pubKey, 1000))
  547. valKey := []byte("validatorsKey:2")
  548. protoVals, err := vals2.ToProto()
  549. require.NoError(t, err)
  550. valInfo := &protostate.ValidatorsInfo{
  551. LastHeightChanged: 2,
  552. ValidatorSet: protoVals,
  553. }
  554. bz, err := valInfo.Marshal()
  555. require.NoError(t, err)
  556. stateDB.Set(valKey, bz)
  557. ev = types.PhantomValidatorEvidence{
  558. Vote: vote2,
  559. LastHeightValidatorWasInSet: 2,
  560. }
  561. err = ev.ValidateBasic()
  562. assert.NoError(t, err)
  563. err = sm.VerifyEvidence(stateDB, state, ev, nil)
  564. if !assert.NoError(t, err) {
  565. t.Log(err)
  566. }
  567. }
  568. func makeVote(height int64, round, index int32, addr bytes.HexBytes, blockID types.BlockID) *types.Vote {
  569. return &types.Vote{
  570. Type: tmproto.SignedMsgType(2),
  571. Height: height,
  572. Round: round,
  573. BlockID: blockID,
  574. Timestamp: time.Now(),
  575. ValidatorAddress: addr,
  576. ValidatorIndex: index,
  577. }
  578. }