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.

714 lines
23 KiB

state: add more tests for block validation (#3674) * Expose priv validators for use in testing * Generalize block header validation test past height 1 * Remove ineffectual assignment * Remove redundant SaveState call * Reorder comment for clarity * Use the block executor ApplyBlock function instead of implementing a stripped-down version of it * Remove commented-out code * Remove unnecessary test The required tests already appear to be implemented (implicitly) through the TestValidateBlockHeader test. * Allow for catching of specific error types during TestValidateBlockCommit * Make return error testable * Clean up and add TestValidateBlockCommit code * Fix formatting * Extract function to create a new mock test app * Update comment for clarity * Fix comment * Add skeleton code for evidence-related test * Allow for addressing priv val by address * Generalize test beyond a single validator * Generalize TestValidateBlockEvidence past first height * Reorder code to clearly separate tests and utility code * Use a common constant for stop height for testing in state/validation_test.go * Refactor errors to resemble existing conventions * Fix formatting * Extract common helper functions Having the tests littered with helper functions makes them less easily readable imho, so I've pulled them out into a separate file. This also makes it easier to see what helper functions are available during testing, so we minimize the chance of duplication when writing new tests. * Remove unused parameter * Remove unused parameters * Add field keys * Remove unused height constant * Fix typo * Fix incorrect return error * Add field keys * Use separate package for tests This refactors all of the state package's tests into a state_test package, so as to keep any usage of the state package's internal methods explicit. Any internal methods/constants used by tests are now explicitly exported in state/export_test.go * Refactor: extract helper function to make, validate, execute and commit a block * Rename state function to makeState * Remove redundant constant for number of validators * Refactor mock evidence registration into TestMain * Remove extraneous nVals variable * Replace function-level TODOs with file-level TODO and explanation * Remove extraneous comment * Fix linting issues brought up by GolangCI (pulled in from latest merge from develop)
6 years ago
state: add more tests for block validation (#3674) * Expose priv validators for use in testing * Generalize block header validation test past height 1 * Remove ineffectual assignment * Remove redundant SaveState call * Reorder comment for clarity * Use the block executor ApplyBlock function instead of implementing a stripped-down version of it * Remove commented-out code * Remove unnecessary test The required tests already appear to be implemented (implicitly) through the TestValidateBlockHeader test. * Allow for catching of specific error types during TestValidateBlockCommit * Make return error testable * Clean up and add TestValidateBlockCommit code * Fix formatting * Extract function to create a new mock test app * Update comment for clarity * Fix comment * Add skeleton code for evidence-related test * Allow for addressing priv val by address * Generalize test beyond a single validator * Generalize TestValidateBlockEvidence past first height * Reorder code to clearly separate tests and utility code * Use a common constant for stop height for testing in state/validation_test.go * Refactor errors to resemble existing conventions * Fix formatting * Extract common helper functions Having the tests littered with helper functions makes them less easily readable imho, so I've pulled them out into a separate file. This also makes it easier to see what helper functions are available during testing, so we minimize the chance of duplication when writing new tests. * Remove unused parameter * Remove unused parameters * Add field keys * Remove unused height constant * Fix typo * Fix incorrect return error * Add field keys * Use separate package for tests This refactors all of the state package's tests into a state_test package, so as to keep any usage of the state package's internal methods explicit. Any internal methods/constants used by tests are now explicitly exported in state/export_test.go * Refactor: extract helper function to make, validate, execute and commit a block * Rename state function to makeState * Remove redundant constant for number of validators * Refactor mock evidence registration into TestMain * Remove extraneous nVals variable * Replace function-level TODOs with file-level TODO and explanation * Remove extraneous comment * Fix linting issues brought up by GolangCI (pulled in from latest merge from develop)
6 years ago
state: add more tests for block validation (#3674) * Expose priv validators for use in testing * Generalize block header validation test past height 1 * Remove ineffectual assignment * Remove redundant SaveState call * Reorder comment for clarity * Use the block executor ApplyBlock function instead of implementing a stripped-down version of it * Remove commented-out code * Remove unnecessary test The required tests already appear to be implemented (implicitly) through the TestValidateBlockHeader test. * Allow for catching of specific error types during TestValidateBlockCommit * Make return error testable * Clean up and add TestValidateBlockCommit code * Fix formatting * Extract function to create a new mock test app * Update comment for clarity * Fix comment * Add skeleton code for evidence-related test * Allow for addressing priv val by address * Generalize test beyond a single validator * Generalize TestValidateBlockEvidence past first height * Reorder code to clearly separate tests and utility code * Use a common constant for stop height for testing in state/validation_test.go * Refactor errors to resemble existing conventions * Fix formatting * Extract common helper functions Having the tests littered with helper functions makes them less easily readable imho, so I've pulled them out into a separate file. This also makes it easier to see what helper functions are available during testing, so we minimize the chance of duplication when writing new tests. * Remove unused parameter * Remove unused parameters * Add field keys * Remove unused height constant * Fix typo * Fix incorrect return error * Add field keys * Use separate package for tests This refactors all of the state package's tests into a state_test package, so as to keep any usage of the state package's internal methods explicit. Any internal methods/constants used by tests are now explicitly exported in state/export_test.go * Refactor: extract helper function to make, validate, execute and commit a block * Rename state function to makeState * Remove redundant constant for number of validators * Refactor mock evidence registration into TestMain * Remove extraneous nVals variable * Replace function-level TODOs with file-level TODO and explanation * Remove extraneous comment * Fix linting issues brought up by GolangCI (pulled in from latest merge from develop)
6 years ago
state: add more tests for block validation (#3674) * Expose priv validators for use in testing * Generalize block header validation test past height 1 * Remove ineffectual assignment * Remove redundant SaveState call * Reorder comment for clarity * Use the block executor ApplyBlock function instead of implementing a stripped-down version of it * Remove commented-out code * Remove unnecessary test The required tests already appear to be implemented (implicitly) through the TestValidateBlockHeader test. * Allow for catching of specific error types during TestValidateBlockCommit * Make return error testable * Clean up and add TestValidateBlockCommit code * Fix formatting * Extract function to create a new mock test app * Update comment for clarity * Fix comment * Add skeleton code for evidence-related test * Allow for addressing priv val by address * Generalize test beyond a single validator * Generalize TestValidateBlockEvidence past first height * Reorder code to clearly separate tests and utility code * Use a common constant for stop height for testing in state/validation_test.go * Refactor errors to resemble existing conventions * Fix formatting * Extract common helper functions Having the tests littered with helper functions makes them less easily readable imho, so I've pulled them out into a separate file. This also makes it easier to see what helper functions are available during testing, so we minimize the chance of duplication when writing new tests. * Remove unused parameter * Remove unused parameters * Add field keys * Remove unused height constant * Fix typo * Fix incorrect return error * Add field keys * Use separate package for tests This refactors all of the state package's tests into a state_test package, so as to keep any usage of the state package's internal methods explicit. Any internal methods/constants used by tests are now explicitly exported in state/export_test.go * Refactor: extract helper function to make, validate, execute and commit a block * Rename state function to makeState * Remove redundant constant for number of validators * Refactor mock evidence registration into TestMain * Remove extraneous nVals variable * Replace function-level TODOs with file-level TODO and explanation * Remove extraneous comment * Fix linting issues brought up by GolangCI (pulled in from latest merge from develop)
6 years ago
state: add more tests for block validation (#3674) * Expose priv validators for use in testing * Generalize block header validation test past height 1 * Remove ineffectual assignment * Remove redundant SaveState call * Reorder comment for clarity * Use the block executor ApplyBlock function instead of implementing a stripped-down version of it * Remove commented-out code * Remove unnecessary test The required tests already appear to be implemented (implicitly) through the TestValidateBlockHeader test. * Allow for catching of specific error types during TestValidateBlockCommit * Make return error testable * Clean up and add TestValidateBlockCommit code * Fix formatting * Extract function to create a new mock test app * Update comment for clarity * Fix comment * Add skeleton code for evidence-related test * Allow for addressing priv val by address * Generalize test beyond a single validator * Generalize TestValidateBlockEvidence past first height * Reorder code to clearly separate tests and utility code * Use a common constant for stop height for testing in state/validation_test.go * Refactor errors to resemble existing conventions * Fix formatting * Extract common helper functions Having the tests littered with helper functions makes them less easily readable imho, so I've pulled them out into a separate file. This also makes it easier to see what helper functions are available during testing, so we minimize the chance of duplication when writing new tests. * Remove unused parameter * Remove unused parameters * Add field keys * Remove unused height constant * Fix typo * Fix incorrect return error * Add field keys * Use separate package for tests This refactors all of the state package's tests into a state_test package, so as to keep any usage of the state package's internal methods explicit. Any internal methods/constants used by tests are now explicitly exported in state/export_test.go * Refactor: extract helper function to make, validate, execute and commit a block * Rename state function to makeState * Remove redundant constant for number of validators * Refactor mock evidence registration into TestMain * Remove extraneous nVals variable * Replace function-level TODOs with file-level TODO and explanation * Remove extraneous comment * Fix linting issues brought up by GolangCI (pulled in from latest merge from develop)
6 years ago
state: add more tests for block validation (#3674) * Expose priv validators for use in testing * Generalize block header validation test past height 1 * Remove ineffectual assignment * Remove redundant SaveState call * Reorder comment for clarity * Use the block executor ApplyBlock function instead of implementing a stripped-down version of it * Remove commented-out code * Remove unnecessary test The required tests already appear to be implemented (implicitly) through the TestValidateBlockHeader test. * Allow for catching of specific error types during TestValidateBlockCommit * Make return error testable * Clean up and add TestValidateBlockCommit code * Fix formatting * Extract function to create a new mock test app * Update comment for clarity * Fix comment * Add skeleton code for evidence-related test * Allow for addressing priv val by address * Generalize test beyond a single validator * Generalize TestValidateBlockEvidence past first height * Reorder code to clearly separate tests and utility code * Use a common constant for stop height for testing in state/validation_test.go * Refactor errors to resemble existing conventions * Fix formatting * Extract common helper functions Having the tests littered with helper functions makes them less easily readable imho, so I've pulled them out into a separate file. This also makes it easier to see what helper functions are available during testing, so we minimize the chance of duplication when writing new tests. * Remove unused parameter * Remove unused parameters * Add field keys * Remove unused height constant * Fix typo * Fix incorrect return error * Add field keys * Use separate package for tests This refactors all of the state package's tests into a state_test package, so as to keep any usage of the state package's internal methods explicit. Any internal methods/constants used by tests are now explicitly exported in state/export_test.go * Refactor: extract helper function to make, validate, execute and commit a block * Rename state function to makeState * Remove redundant constant for number of validators * Refactor mock evidence registration into TestMain * Remove extraneous nVals variable * Replace function-level TODOs with file-level TODO and explanation * Remove extraneous comment * Fix linting issues brought up by GolangCI (pulled in from latest merge from develop)
6 years ago
state: add more tests for block validation (#3674) * Expose priv validators for use in testing * Generalize block header validation test past height 1 * Remove ineffectual assignment * Remove redundant SaveState call * Reorder comment for clarity * Use the block executor ApplyBlock function instead of implementing a stripped-down version of it * Remove commented-out code * Remove unnecessary test The required tests already appear to be implemented (implicitly) through the TestValidateBlockHeader test. * Allow for catching of specific error types during TestValidateBlockCommit * Make return error testable * Clean up and add TestValidateBlockCommit code * Fix formatting * Extract function to create a new mock test app * Update comment for clarity * Fix comment * Add skeleton code for evidence-related test * Allow for addressing priv val by address * Generalize test beyond a single validator * Generalize TestValidateBlockEvidence past first height * Reorder code to clearly separate tests and utility code * Use a common constant for stop height for testing in state/validation_test.go * Refactor errors to resemble existing conventions * Fix formatting * Extract common helper functions Having the tests littered with helper functions makes them less easily readable imho, so I've pulled them out into a separate file. This also makes it easier to see what helper functions are available during testing, so we minimize the chance of duplication when writing new tests. * Remove unused parameter * Remove unused parameters * Add field keys * Remove unused height constant * Fix typo * Fix incorrect return error * Add field keys * Use separate package for tests This refactors all of the state package's tests into a state_test package, so as to keep any usage of the state package's internal methods explicit. Any internal methods/constants used by tests are now explicitly exported in state/export_test.go * Refactor: extract helper function to make, validate, execute and commit a block * Rename state function to makeState * Remove redundant constant for number of validators * Refactor mock evidence registration into TestMain * Remove extraneous nVals variable * Replace function-level TODOs with file-level TODO and explanation * Remove extraneous comment * Fix linting issues brought up by GolangCI (pulled in from latest merge from develop)
6 years ago
state: add more tests for block validation (#3674) * Expose priv validators for use in testing * Generalize block header validation test past height 1 * Remove ineffectual assignment * Remove redundant SaveState call * Reorder comment for clarity * Use the block executor ApplyBlock function instead of implementing a stripped-down version of it * Remove commented-out code * Remove unnecessary test The required tests already appear to be implemented (implicitly) through the TestValidateBlockHeader test. * Allow for catching of specific error types during TestValidateBlockCommit * Make return error testable * Clean up and add TestValidateBlockCommit code * Fix formatting * Extract function to create a new mock test app * Update comment for clarity * Fix comment * Add skeleton code for evidence-related test * Allow for addressing priv val by address * Generalize test beyond a single validator * Generalize TestValidateBlockEvidence past first height * Reorder code to clearly separate tests and utility code * Use a common constant for stop height for testing in state/validation_test.go * Refactor errors to resemble existing conventions * Fix formatting * Extract common helper functions Having the tests littered with helper functions makes them less easily readable imho, so I've pulled them out into a separate file. This also makes it easier to see what helper functions are available during testing, so we minimize the chance of duplication when writing new tests. * Remove unused parameter * Remove unused parameters * Add field keys * Remove unused height constant * Fix typo * Fix incorrect return error * Add field keys * Use separate package for tests This refactors all of the state package's tests into a state_test package, so as to keep any usage of the state package's internal methods explicit. Any internal methods/constants used by tests are now explicitly exported in state/export_test.go * Refactor: extract helper function to make, validate, execute and commit a block * Rename state function to makeState * Remove redundant constant for number of validators * Refactor mock evidence registration into TestMain * Remove extraneous nVals variable * Replace function-level TODOs with file-level TODO and explanation * Remove extraneous comment * Fix linting issues brought up by GolangCI (pulled in from latest merge from develop)
6 years ago
state: add more tests for block validation (#3674) * Expose priv validators for use in testing * Generalize block header validation test past height 1 * Remove ineffectual assignment * Remove redundant SaveState call * Reorder comment for clarity * Use the block executor ApplyBlock function instead of implementing a stripped-down version of it * Remove commented-out code * Remove unnecessary test The required tests already appear to be implemented (implicitly) through the TestValidateBlockHeader test. * Allow for catching of specific error types during TestValidateBlockCommit * Make return error testable * Clean up and add TestValidateBlockCommit code * Fix formatting * Extract function to create a new mock test app * Update comment for clarity * Fix comment * Add skeleton code for evidence-related test * Allow for addressing priv val by address * Generalize test beyond a single validator * Generalize TestValidateBlockEvidence past first height * Reorder code to clearly separate tests and utility code * Use a common constant for stop height for testing in state/validation_test.go * Refactor errors to resemble existing conventions * Fix formatting * Extract common helper functions Having the tests littered with helper functions makes them less easily readable imho, so I've pulled them out into a separate file. This also makes it easier to see what helper functions are available during testing, so we minimize the chance of duplication when writing new tests. * Remove unused parameter * Remove unused parameters * Add field keys * Remove unused height constant * Fix typo * Fix incorrect return error * Add field keys * Use separate package for tests This refactors all of the state package's tests into a state_test package, so as to keep any usage of the state package's internal methods explicit. Any internal methods/constants used by tests are now explicitly exported in state/export_test.go * Refactor: extract helper function to make, validate, execute and commit a block * Rename state function to makeState * Remove redundant constant for number of validators * Refactor mock evidence registration into TestMain * Remove extraneous nVals variable * Replace function-level TODOs with file-level TODO and explanation * Remove extraneous comment * Fix linting issues brought up by GolangCI (pulled in from latest merge from develop)
6 years ago
state: add more tests for block validation (#3674) * Expose priv validators for use in testing * Generalize block header validation test past height 1 * Remove ineffectual assignment * Remove redundant SaveState call * Reorder comment for clarity * Use the block executor ApplyBlock function instead of implementing a stripped-down version of it * Remove commented-out code * Remove unnecessary test The required tests already appear to be implemented (implicitly) through the TestValidateBlockHeader test. * Allow for catching of specific error types during TestValidateBlockCommit * Make return error testable * Clean up and add TestValidateBlockCommit code * Fix formatting * Extract function to create a new mock test app * Update comment for clarity * Fix comment * Add skeleton code for evidence-related test * Allow for addressing priv val by address * Generalize test beyond a single validator * Generalize TestValidateBlockEvidence past first height * Reorder code to clearly separate tests and utility code * Use a common constant for stop height for testing in state/validation_test.go * Refactor errors to resemble existing conventions * Fix formatting * Extract common helper functions Having the tests littered with helper functions makes them less easily readable imho, so I've pulled them out into a separate file. This also makes it easier to see what helper functions are available during testing, so we minimize the chance of duplication when writing new tests. * Remove unused parameter * Remove unused parameters * Add field keys * Remove unused height constant * Fix typo * Fix incorrect return error * Add field keys * Use separate package for tests This refactors all of the state package's tests into a state_test package, so as to keep any usage of the state package's internal methods explicit. Any internal methods/constants used by tests are now explicitly exported in state/export_test.go * Refactor: extract helper function to make, validate, execute and commit a block * Rename state function to makeState * Remove redundant constant for number of validators * Refactor mock evidence registration into TestMain * Remove extraneous nVals variable * Replace function-level TODOs with file-level TODO and explanation * Remove extraneous comment * Fix linting issues brought up by GolangCI (pulled in from latest merge from develop)
6 years ago
state: add more tests for block validation (#3674) * Expose priv validators for use in testing * Generalize block header validation test past height 1 * Remove ineffectual assignment * Remove redundant SaveState call * Reorder comment for clarity * Use the block executor ApplyBlock function instead of implementing a stripped-down version of it * Remove commented-out code * Remove unnecessary test The required tests already appear to be implemented (implicitly) through the TestValidateBlockHeader test. * Allow for catching of specific error types during TestValidateBlockCommit * Make return error testable * Clean up and add TestValidateBlockCommit code * Fix formatting * Extract function to create a new mock test app * Update comment for clarity * Fix comment * Add skeleton code for evidence-related test * Allow for addressing priv val by address * Generalize test beyond a single validator * Generalize TestValidateBlockEvidence past first height * Reorder code to clearly separate tests and utility code * Use a common constant for stop height for testing in state/validation_test.go * Refactor errors to resemble existing conventions * Fix formatting * Extract common helper functions Having the tests littered with helper functions makes them less easily readable imho, so I've pulled them out into a separate file. This also makes it easier to see what helper functions are available during testing, so we minimize the chance of duplication when writing new tests. * Remove unused parameter * Remove unused parameters * Add field keys * Remove unused height constant * Fix typo * Fix incorrect return error * Add field keys * Use separate package for tests This refactors all of the state package's tests into a state_test package, so as to keep any usage of the state package's internal methods explicit. Any internal methods/constants used by tests are now explicitly exported in state/export_test.go * Refactor: extract helper function to make, validate, execute and commit a block * Rename state function to makeState * Remove redundant constant for number of validators * Refactor mock evidence registration into TestMain * Remove extraneous nVals variable * Replace function-level TODOs with file-level TODO and explanation * Remove extraneous comment * Fix linting issues brought up by GolangCI (pulled in from latest merge from develop)
6 years ago
state: add more tests for block validation (#3674) * Expose priv validators for use in testing * Generalize block header validation test past height 1 * Remove ineffectual assignment * Remove redundant SaveState call * Reorder comment for clarity * Use the block executor ApplyBlock function instead of implementing a stripped-down version of it * Remove commented-out code * Remove unnecessary test The required tests already appear to be implemented (implicitly) through the TestValidateBlockHeader test. * Allow for catching of specific error types during TestValidateBlockCommit * Make return error testable * Clean up and add TestValidateBlockCommit code * Fix formatting * Extract function to create a new mock test app * Update comment for clarity * Fix comment * Add skeleton code for evidence-related test * Allow for addressing priv val by address * Generalize test beyond a single validator * Generalize TestValidateBlockEvidence past first height * Reorder code to clearly separate tests and utility code * Use a common constant for stop height for testing in state/validation_test.go * Refactor errors to resemble existing conventions * Fix formatting * Extract common helper functions Having the tests littered with helper functions makes them less easily readable imho, so I've pulled them out into a separate file. This also makes it easier to see what helper functions are available during testing, so we minimize the chance of duplication when writing new tests. * Remove unused parameter * Remove unused parameters * Add field keys * Remove unused height constant * Fix typo * Fix incorrect return error * Add field keys * Use separate package for tests This refactors all of the state package's tests into a state_test package, so as to keep any usage of the state package's internal methods explicit. Any internal methods/constants used by tests are now explicitly exported in state/export_test.go * Refactor: extract helper function to make, validate, execute and commit a block * Rename state function to makeState * Remove redundant constant for number of validators * Refactor mock evidence registration into TestMain * Remove extraneous nVals variable * Replace function-level TODOs with file-level TODO and explanation * Remove extraneous comment * Fix linting issues brought up by GolangCI (pulled in from latest merge from develop)
6 years ago
state: add more tests for block validation (#3674) * Expose priv validators for use in testing * Generalize block header validation test past height 1 * Remove ineffectual assignment * Remove redundant SaveState call * Reorder comment for clarity * Use the block executor ApplyBlock function instead of implementing a stripped-down version of it * Remove commented-out code * Remove unnecessary test The required tests already appear to be implemented (implicitly) through the TestValidateBlockHeader test. * Allow for catching of specific error types during TestValidateBlockCommit * Make return error testable * Clean up and add TestValidateBlockCommit code * Fix formatting * Extract function to create a new mock test app * Update comment for clarity * Fix comment * Add skeleton code for evidence-related test * Allow for addressing priv val by address * Generalize test beyond a single validator * Generalize TestValidateBlockEvidence past first height * Reorder code to clearly separate tests and utility code * Use a common constant for stop height for testing in state/validation_test.go * Refactor errors to resemble existing conventions * Fix formatting * Extract common helper functions Having the tests littered with helper functions makes them less easily readable imho, so I've pulled them out into a separate file. This also makes it easier to see what helper functions are available during testing, so we minimize the chance of duplication when writing new tests. * Remove unused parameter * Remove unused parameters * Add field keys * Remove unused height constant * Fix typo * Fix incorrect return error * Add field keys * Use separate package for tests This refactors all of the state package's tests into a state_test package, so as to keep any usage of the state package's internal methods explicit. Any internal methods/constants used by tests are now explicitly exported in state/export_test.go * Refactor: extract helper function to make, validate, execute and commit a block * Rename state function to makeState * Remove redundant constant for number of validators * Refactor mock evidence registration into TestMain * Remove extraneous nVals variable * Replace function-level TODOs with file-level TODO and explanation * Remove extraneous comment * Fix linting issues brought up by GolangCI (pulled in from latest merge from develop)
6 years ago
state: add more tests for block validation (#3674) * Expose priv validators for use in testing * Generalize block header validation test past height 1 * Remove ineffectual assignment * Remove redundant SaveState call * Reorder comment for clarity * Use the block executor ApplyBlock function instead of implementing a stripped-down version of it * Remove commented-out code * Remove unnecessary test The required tests already appear to be implemented (implicitly) through the TestValidateBlockHeader test. * Allow for catching of specific error types during TestValidateBlockCommit * Make return error testable * Clean up and add TestValidateBlockCommit code * Fix formatting * Extract function to create a new mock test app * Update comment for clarity * Fix comment * Add skeleton code for evidence-related test * Allow for addressing priv val by address * Generalize test beyond a single validator * Generalize TestValidateBlockEvidence past first height * Reorder code to clearly separate tests and utility code * Use a common constant for stop height for testing in state/validation_test.go * Refactor errors to resemble existing conventions * Fix formatting * Extract common helper functions Having the tests littered with helper functions makes them less easily readable imho, so I've pulled them out into a separate file. This also makes it easier to see what helper functions are available during testing, so we minimize the chance of duplication when writing new tests. * Remove unused parameter * Remove unused parameters * Add field keys * Remove unused height constant * Fix typo * Fix incorrect return error * Add field keys * Use separate package for tests This refactors all of the state package's tests into a state_test package, so as to keep any usage of the state package's internal methods explicit. Any internal methods/constants used by tests are now explicitly exported in state/export_test.go * Refactor: extract helper function to make, validate, execute and commit a block * Rename state function to makeState * Remove redundant constant for number of validators * Refactor mock evidence registration into TestMain * Remove extraneous nVals variable * Replace function-level TODOs with file-level TODO and explanation * Remove extraneous comment * Fix linting issues brought up by GolangCI (pulled in from latest merge from develop)
6 years ago
state: add more tests for block validation (#3674) * Expose priv validators for use in testing * Generalize block header validation test past height 1 * Remove ineffectual assignment * Remove redundant SaveState call * Reorder comment for clarity * Use the block executor ApplyBlock function instead of implementing a stripped-down version of it * Remove commented-out code * Remove unnecessary test The required tests already appear to be implemented (implicitly) through the TestValidateBlockHeader test. * Allow for catching of specific error types during TestValidateBlockCommit * Make return error testable * Clean up and add TestValidateBlockCommit code * Fix formatting * Extract function to create a new mock test app * Update comment for clarity * Fix comment * Add skeleton code for evidence-related test * Allow for addressing priv val by address * Generalize test beyond a single validator * Generalize TestValidateBlockEvidence past first height * Reorder code to clearly separate tests and utility code * Use a common constant for stop height for testing in state/validation_test.go * Refactor errors to resemble existing conventions * Fix formatting * Extract common helper functions Having the tests littered with helper functions makes them less easily readable imho, so I've pulled them out into a separate file. This also makes it easier to see what helper functions are available during testing, so we minimize the chance of duplication when writing new tests. * Remove unused parameter * Remove unused parameters * Add field keys * Remove unused height constant * Fix typo * Fix incorrect return error * Add field keys * Use separate package for tests This refactors all of the state package's tests into a state_test package, so as to keep any usage of the state package's internal methods explicit. Any internal methods/constants used by tests are now explicitly exported in state/export_test.go * Refactor: extract helper function to make, validate, execute and commit a block * Rename state function to makeState * Remove redundant constant for number of validators * Refactor mock evidence registration into TestMain * Remove extraneous nVals variable * Replace function-level TODOs with file-level TODO and explanation * Remove extraneous comment * Fix linting issues brought up by GolangCI (pulled in from latest merge from develop)
6 years ago
state: add more tests for block validation (#3674) * Expose priv validators for use in testing * Generalize block header validation test past height 1 * Remove ineffectual assignment * Remove redundant SaveState call * Reorder comment for clarity * Use the block executor ApplyBlock function instead of implementing a stripped-down version of it * Remove commented-out code * Remove unnecessary test The required tests already appear to be implemented (implicitly) through the TestValidateBlockHeader test. * Allow for catching of specific error types during TestValidateBlockCommit * Make return error testable * Clean up and add TestValidateBlockCommit code * Fix formatting * Extract function to create a new mock test app * Update comment for clarity * Fix comment * Add skeleton code for evidence-related test * Allow for addressing priv val by address * Generalize test beyond a single validator * Generalize TestValidateBlockEvidence past first height * Reorder code to clearly separate tests and utility code * Use a common constant for stop height for testing in state/validation_test.go * Refactor errors to resemble existing conventions * Fix formatting * Extract common helper functions Having the tests littered with helper functions makes them less easily readable imho, so I've pulled them out into a separate file. This also makes it easier to see what helper functions are available during testing, so we minimize the chance of duplication when writing new tests. * Remove unused parameter * Remove unused parameters * Add field keys * Remove unused height constant * Fix typo * Fix incorrect return error * Add field keys * Use separate package for tests This refactors all of the state package's tests into a state_test package, so as to keep any usage of the state package's internal methods explicit. Any internal methods/constants used by tests are now explicitly exported in state/export_test.go * Refactor: extract helper function to make, validate, execute and commit a block * Rename state function to makeState * Remove redundant constant for number of validators * Refactor mock evidence registration into TestMain * Remove extraneous nVals variable * Replace function-level TODOs with file-level TODO and explanation * Remove extraneous comment * Fix linting issues brought up by GolangCI (pulled in from latest merge from develop)
6 years ago
state: add more tests for block validation (#3674) * Expose priv validators for use in testing * Generalize block header validation test past height 1 * Remove ineffectual assignment * Remove redundant SaveState call * Reorder comment for clarity * Use the block executor ApplyBlock function instead of implementing a stripped-down version of it * Remove commented-out code * Remove unnecessary test The required tests already appear to be implemented (implicitly) through the TestValidateBlockHeader test. * Allow for catching of specific error types during TestValidateBlockCommit * Make return error testable * Clean up and add TestValidateBlockCommit code * Fix formatting * Extract function to create a new mock test app * Update comment for clarity * Fix comment * Add skeleton code for evidence-related test * Allow for addressing priv val by address * Generalize test beyond a single validator * Generalize TestValidateBlockEvidence past first height * Reorder code to clearly separate tests and utility code * Use a common constant for stop height for testing in state/validation_test.go * Refactor errors to resemble existing conventions * Fix formatting * Extract common helper functions Having the tests littered with helper functions makes them less easily readable imho, so I've pulled them out into a separate file. This also makes it easier to see what helper functions are available during testing, so we minimize the chance of duplication when writing new tests. * Remove unused parameter * Remove unused parameters * Add field keys * Remove unused height constant * Fix typo * Fix incorrect return error * Add field keys * Use separate package for tests This refactors all of the state package's tests into a state_test package, so as to keep any usage of the state package's internal methods explicit. Any internal methods/constants used by tests are now explicitly exported in state/export_test.go * Refactor: extract helper function to make, validate, execute and commit a block * Rename state function to makeState * Remove redundant constant for number of validators * Refactor mock evidence registration into TestMain * Remove extraneous nVals variable * Replace function-level TODOs with file-level TODO and explanation * Remove extraneous comment * Fix linting issues brought up by GolangCI (pulled in from latest merge from develop)
6 years ago
state: add more tests for block validation (#3674) * Expose priv validators for use in testing * Generalize block header validation test past height 1 * Remove ineffectual assignment * Remove redundant SaveState call * Reorder comment for clarity * Use the block executor ApplyBlock function instead of implementing a stripped-down version of it * Remove commented-out code * Remove unnecessary test The required tests already appear to be implemented (implicitly) through the TestValidateBlockHeader test. * Allow for catching of specific error types during TestValidateBlockCommit * Make return error testable * Clean up and add TestValidateBlockCommit code * Fix formatting * Extract function to create a new mock test app * Update comment for clarity * Fix comment * Add skeleton code for evidence-related test * Allow for addressing priv val by address * Generalize test beyond a single validator * Generalize TestValidateBlockEvidence past first height * Reorder code to clearly separate tests and utility code * Use a common constant for stop height for testing in state/validation_test.go * Refactor errors to resemble existing conventions * Fix formatting * Extract common helper functions Having the tests littered with helper functions makes them less easily readable imho, so I've pulled them out into a separate file. This also makes it easier to see what helper functions are available during testing, so we minimize the chance of duplication when writing new tests. * Remove unused parameter * Remove unused parameters * Add field keys * Remove unused height constant * Fix typo * Fix incorrect return error * Add field keys * Use separate package for tests This refactors all of the state package's tests into a state_test package, so as to keep any usage of the state package's internal methods explicit. Any internal methods/constants used by tests are now explicitly exported in state/export_test.go * Refactor: extract helper function to make, validate, execute and commit a block * Rename state function to makeState * Remove redundant constant for number of validators * Refactor mock evidence registration into TestMain * Remove extraneous nVals variable * Replace function-level TODOs with file-level TODO and explanation * Remove extraneous comment * Fix linting issues brought up by GolangCI (pulled in from latest merge from develop)
6 years ago
state: add more tests for block validation (#3674) * Expose priv validators for use in testing * Generalize block header validation test past height 1 * Remove ineffectual assignment * Remove redundant SaveState call * Reorder comment for clarity * Use the block executor ApplyBlock function instead of implementing a stripped-down version of it * Remove commented-out code * Remove unnecessary test The required tests already appear to be implemented (implicitly) through the TestValidateBlockHeader test. * Allow for catching of specific error types during TestValidateBlockCommit * Make return error testable * Clean up and add TestValidateBlockCommit code * Fix formatting * Extract function to create a new mock test app * Update comment for clarity * Fix comment * Add skeleton code for evidence-related test * Allow for addressing priv val by address * Generalize test beyond a single validator * Generalize TestValidateBlockEvidence past first height * Reorder code to clearly separate tests and utility code * Use a common constant for stop height for testing in state/validation_test.go * Refactor errors to resemble existing conventions * Fix formatting * Extract common helper functions Having the tests littered with helper functions makes them less easily readable imho, so I've pulled them out into a separate file. This also makes it easier to see what helper functions are available during testing, so we minimize the chance of duplication when writing new tests. * Remove unused parameter * Remove unused parameters * Add field keys * Remove unused height constant * Fix typo * Fix incorrect return error * Add field keys * Use separate package for tests This refactors all of the state package's tests into a state_test package, so as to keep any usage of the state package's internal methods explicit. Any internal methods/constants used by tests are now explicitly exported in state/export_test.go * Refactor: extract helper function to make, validate, execute and commit a block * Rename state function to makeState * Remove redundant constant for number of validators * Refactor mock evidence registration into TestMain * Remove extraneous nVals variable * Replace function-level TODOs with file-level TODO and explanation * Remove extraneous comment * Fix linting issues brought up by GolangCI (pulled in from latest merge from develop)
6 years ago
state: add more tests for block validation (#3674) * Expose priv validators for use in testing * Generalize block header validation test past height 1 * Remove ineffectual assignment * Remove redundant SaveState call * Reorder comment for clarity * Use the block executor ApplyBlock function instead of implementing a stripped-down version of it * Remove commented-out code * Remove unnecessary test The required tests already appear to be implemented (implicitly) through the TestValidateBlockHeader test. * Allow for catching of specific error types during TestValidateBlockCommit * Make return error testable * Clean up and add TestValidateBlockCommit code * Fix formatting * Extract function to create a new mock test app * Update comment for clarity * Fix comment * Add skeleton code for evidence-related test * Allow for addressing priv val by address * Generalize test beyond a single validator * Generalize TestValidateBlockEvidence past first height * Reorder code to clearly separate tests and utility code * Use a common constant for stop height for testing in state/validation_test.go * Refactor errors to resemble existing conventions * Fix formatting * Extract common helper functions Having the tests littered with helper functions makes them less easily readable imho, so I've pulled them out into a separate file. This also makes it easier to see what helper functions are available during testing, so we minimize the chance of duplication when writing new tests. * Remove unused parameter * Remove unused parameters * Add field keys * Remove unused height constant * Fix typo * Fix incorrect return error * Add field keys * Use separate package for tests This refactors all of the state package's tests into a state_test package, so as to keep any usage of the state package's internal methods explicit. Any internal methods/constants used by tests are now explicitly exported in state/export_test.go * Refactor: extract helper function to make, validate, execute and commit a block * Rename state function to makeState * Remove redundant constant for number of validators * Refactor mock evidence registration into TestMain * Remove extraneous nVals variable * Replace function-level TODOs with file-level TODO and explanation * Remove extraneous comment * Fix linting issues brought up by GolangCI (pulled in from latest merge from develop)
6 years ago
state: add more tests for block validation (#3674) * Expose priv validators for use in testing * Generalize block header validation test past height 1 * Remove ineffectual assignment * Remove redundant SaveState call * Reorder comment for clarity * Use the block executor ApplyBlock function instead of implementing a stripped-down version of it * Remove commented-out code * Remove unnecessary test The required tests already appear to be implemented (implicitly) through the TestValidateBlockHeader test. * Allow for catching of specific error types during TestValidateBlockCommit * Make return error testable * Clean up and add TestValidateBlockCommit code * Fix formatting * Extract function to create a new mock test app * Update comment for clarity * Fix comment * Add skeleton code for evidence-related test * Allow for addressing priv val by address * Generalize test beyond a single validator * Generalize TestValidateBlockEvidence past first height * Reorder code to clearly separate tests and utility code * Use a common constant for stop height for testing in state/validation_test.go * Refactor errors to resemble existing conventions * Fix formatting * Extract common helper functions Having the tests littered with helper functions makes them less easily readable imho, so I've pulled them out into a separate file. This also makes it easier to see what helper functions are available during testing, so we minimize the chance of duplication when writing new tests. * Remove unused parameter * Remove unused parameters * Add field keys * Remove unused height constant * Fix typo * Fix incorrect return error * Add field keys * Use separate package for tests This refactors all of the state package's tests into a state_test package, so as to keep any usage of the state package's internal methods explicit. Any internal methods/constants used by tests are now explicitly exported in state/export_test.go * Refactor: extract helper function to make, validate, execute and commit a block * Rename state function to makeState * Remove redundant constant for number of validators * Refactor mock evidence registration into TestMain * Remove extraneous nVals variable * Replace function-level TODOs with file-level TODO and explanation * Remove extraneous comment * Fix linting issues brought up by GolangCI (pulled in from latest merge from develop)
6 years ago
state: add more tests for block validation (#3674) * Expose priv validators for use in testing * Generalize block header validation test past height 1 * Remove ineffectual assignment * Remove redundant SaveState call * Reorder comment for clarity * Use the block executor ApplyBlock function instead of implementing a stripped-down version of it * Remove commented-out code * Remove unnecessary test The required tests already appear to be implemented (implicitly) through the TestValidateBlockHeader test. * Allow for catching of specific error types during TestValidateBlockCommit * Make return error testable * Clean up and add TestValidateBlockCommit code * Fix formatting * Extract function to create a new mock test app * Update comment for clarity * Fix comment * Add skeleton code for evidence-related test * Allow for addressing priv val by address * Generalize test beyond a single validator * Generalize TestValidateBlockEvidence past first height * Reorder code to clearly separate tests and utility code * Use a common constant for stop height for testing in state/validation_test.go * Refactor errors to resemble existing conventions * Fix formatting * Extract common helper functions Having the tests littered with helper functions makes them less easily readable imho, so I've pulled them out into a separate file. This also makes it easier to see what helper functions are available during testing, so we minimize the chance of duplication when writing new tests. * Remove unused parameter * Remove unused parameters * Add field keys * Remove unused height constant * Fix typo * Fix incorrect return error * Add field keys * Use separate package for tests This refactors all of the state package's tests into a state_test package, so as to keep any usage of the state package's internal methods explicit. Any internal methods/constants used by tests are now explicitly exported in state/export_test.go * Refactor: extract helper function to make, validate, execute and commit a block * Rename state function to makeState * Remove redundant constant for number of validators * Refactor mock evidence registration into TestMain * Remove extraneous nVals variable * Replace function-level TODOs with file-level TODO and explanation * Remove extraneous comment * Fix linting issues brought up by GolangCI (pulled in from latest merge from develop)
6 years ago
state: add more tests for block validation (#3674) * Expose priv validators for use in testing * Generalize block header validation test past height 1 * Remove ineffectual assignment * Remove redundant SaveState call * Reorder comment for clarity * Use the block executor ApplyBlock function instead of implementing a stripped-down version of it * Remove commented-out code * Remove unnecessary test The required tests already appear to be implemented (implicitly) through the TestValidateBlockHeader test. * Allow for catching of specific error types during TestValidateBlockCommit * Make return error testable * Clean up and add TestValidateBlockCommit code * Fix formatting * Extract function to create a new mock test app * Update comment for clarity * Fix comment * Add skeleton code for evidence-related test * Allow for addressing priv val by address * Generalize test beyond a single validator * Generalize TestValidateBlockEvidence past first height * Reorder code to clearly separate tests and utility code * Use a common constant for stop height for testing in state/validation_test.go * Refactor errors to resemble existing conventions * Fix formatting * Extract common helper functions Having the tests littered with helper functions makes them less easily readable imho, so I've pulled them out into a separate file. This also makes it easier to see what helper functions are available during testing, so we minimize the chance of duplication when writing new tests. * Remove unused parameter * Remove unused parameters * Add field keys * Remove unused height constant * Fix typo * Fix incorrect return error * Add field keys * Use separate package for tests This refactors all of the state package's tests into a state_test package, so as to keep any usage of the state package's internal methods explicit. Any internal methods/constants used by tests are now explicitly exported in state/export_test.go * Refactor: extract helper function to make, validate, execute and commit a block * Rename state function to makeState * Remove redundant constant for number of validators * Refactor mock evidence registration into TestMain * Remove extraneous nVals variable * Replace function-level TODOs with file-level TODO and explanation * Remove extraneous comment * Fix linting issues brought up by GolangCI (pulled in from latest merge from develop)
6 years ago
state: add more tests for block validation (#3674) * Expose priv validators for use in testing * Generalize block header validation test past height 1 * Remove ineffectual assignment * Remove redundant SaveState call * Reorder comment for clarity * Use the block executor ApplyBlock function instead of implementing a stripped-down version of it * Remove commented-out code * Remove unnecessary test The required tests already appear to be implemented (implicitly) through the TestValidateBlockHeader test. * Allow for catching of specific error types during TestValidateBlockCommit * Make return error testable * Clean up and add TestValidateBlockCommit code * Fix formatting * Extract function to create a new mock test app * Update comment for clarity * Fix comment * Add skeleton code for evidence-related test * Allow for addressing priv val by address * Generalize test beyond a single validator * Generalize TestValidateBlockEvidence past first height * Reorder code to clearly separate tests and utility code * Use a common constant for stop height for testing in state/validation_test.go * Refactor errors to resemble existing conventions * Fix formatting * Extract common helper functions Having the tests littered with helper functions makes them less easily readable imho, so I've pulled them out into a separate file. This also makes it easier to see what helper functions are available during testing, so we minimize the chance of duplication when writing new tests. * Remove unused parameter * Remove unused parameters * Add field keys * Remove unused height constant * Fix typo * Fix incorrect return error * Add field keys * Use separate package for tests This refactors all of the state package's tests into a state_test package, so as to keep any usage of the state package's internal methods explicit. Any internal methods/constants used by tests are now explicitly exported in state/export_test.go * Refactor: extract helper function to make, validate, execute and commit a block * Rename state function to makeState * Remove redundant constant for number of validators * Refactor mock evidence registration into TestMain * Remove extraneous nVals variable * Replace function-level TODOs with file-level TODO and explanation * Remove extraneous comment * Fix linting issues brought up by GolangCI (pulled in from latest merge from develop)
6 years ago
state: add more tests for block validation (#3674) * Expose priv validators for use in testing * Generalize block header validation test past height 1 * Remove ineffectual assignment * Remove redundant SaveState call * Reorder comment for clarity * Use the block executor ApplyBlock function instead of implementing a stripped-down version of it * Remove commented-out code * Remove unnecessary test The required tests already appear to be implemented (implicitly) through the TestValidateBlockHeader test. * Allow for catching of specific error types during TestValidateBlockCommit * Make return error testable * Clean up and add TestValidateBlockCommit code * Fix formatting * Extract function to create a new mock test app * Update comment for clarity * Fix comment * Add skeleton code for evidence-related test * Allow for addressing priv val by address * Generalize test beyond a single validator * Generalize TestValidateBlockEvidence past first height * Reorder code to clearly separate tests and utility code * Use a common constant for stop height for testing in state/validation_test.go * Refactor errors to resemble existing conventions * Fix formatting * Extract common helper functions Having the tests littered with helper functions makes them less easily readable imho, so I've pulled them out into a separate file. This also makes it easier to see what helper functions are available during testing, so we minimize the chance of duplication when writing new tests. * Remove unused parameter * Remove unused parameters * Add field keys * Remove unused height constant * Fix typo * Fix incorrect return error * Add field keys * Use separate package for tests This refactors all of the state package's tests into a state_test package, so as to keep any usage of the state package's internal methods explicit. Any internal methods/constants used by tests are now explicitly exported in state/export_test.go * Refactor: extract helper function to make, validate, execute and commit a block * Rename state function to makeState * Remove redundant constant for number of validators * Refactor mock evidence registration into TestMain * Remove extraneous nVals variable * Replace function-level TODOs with file-level TODO and explanation * Remove extraneous comment * Fix linting issues brought up by GolangCI (pulled in from latest merge from develop)
6 years ago
state: add more tests for block validation (#3674) * Expose priv validators for use in testing * Generalize block header validation test past height 1 * Remove ineffectual assignment * Remove redundant SaveState call * Reorder comment for clarity * Use the block executor ApplyBlock function instead of implementing a stripped-down version of it * Remove commented-out code * Remove unnecessary test The required tests already appear to be implemented (implicitly) through the TestValidateBlockHeader test. * Allow for catching of specific error types during TestValidateBlockCommit * Make return error testable * Clean up and add TestValidateBlockCommit code * Fix formatting * Extract function to create a new mock test app * Update comment for clarity * Fix comment * Add skeleton code for evidence-related test * Allow for addressing priv val by address * Generalize test beyond a single validator * Generalize TestValidateBlockEvidence past first height * Reorder code to clearly separate tests and utility code * Use a common constant for stop height for testing in state/validation_test.go * Refactor errors to resemble existing conventions * Fix formatting * Extract common helper functions Having the tests littered with helper functions makes them less easily readable imho, so I've pulled them out into a separate file. This also makes it easier to see what helper functions are available during testing, so we minimize the chance of duplication when writing new tests. * Remove unused parameter * Remove unused parameters * Add field keys * Remove unused height constant * Fix typo * Fix incorrect return error * Add field keys * Use separate package for tests This refactors all of the state package's tests into a state_test package, so as to keep any usage of the state package's internal methods explicit. Any internal methods/constants used by tests are now explicitly exported in state/export_test.go * Refactor: extract helper function to make, validate, execute and commit a block * Rename state function to makeState * Remove redundant constant for number of validators * Refactor mock evidence registration into TestMain * Remove extraneous nVals variable * Replace function-level TODOs with file-level TODO and explanation * Remove extraneous comment * Fix linting issues brought up by GolangCI (pulled in from latest merge from develop)
6 years ago
state: add more tests for block validation (#3674) * Expose priv validators for use in testing * Generalize block header validation test past height 1 * Remove ineffectual assignment * Remove redundant SaveState call * Reorder comment for clarity * Use the block executor ApplyBlock function instead of implementing a stripped-down version of it * Remove commented-out code * Remove unnecessary test The required tests already appear to be implemented (implicitly) through the TestValidateBlockHeader test. * Allow for catching of specific error types during TestValidateBlockCommit * Make return error testable * Clean up and add TestValidateBlockCommit code * Fix formatting * Extract function to create a new mock test app * Update comment for clarity * Fix comment * Add skeleton code for evidence-related test * Allow for addressing priv val by address * Generalize test beyond a single validator * Generalize TestValidateBlockEvidence past first height * Reorder code to clearly separate tests and utility code * Use a common constant for stop height for testing in state/validation_test.go * Refactor errors to resemble existing conventions * Fix formatting * Extract common helper functions Having the tests littered with helper functions makes them less easily readable imho, so I've pulled them out into a separate file. This also makes it easier to see what helper functions are available during testing, so we minimize the chance of duplication when writing new tests. * Remove unused parameter * Remove unused parameters * Add field keys * Remove unused height constant * Fix typo * Fix incorrect return error * Add field keys * Use separate package for tests This refactors all of the state package's tests into a state_test package, so as to keep any usage of the state package's internal methods explicit. Any internal methods/constants used by tests are now explicitly exported in state/export_test.go * Refactor: extract helper function to make, validate, execute and commit a block * Rename state function to makeState * Remove redundant constant for number of validators * Refactor mock evidence registration into TestMain * Remove extraneous nVals variable * Replace function-level TODOs with file-level TODO and explanation * Remove extraneous comment * Fix linting issues brought up by GolangCI (pulled in from latest merge from develop)
6 years ago
state: add more tests for block validation (#3674) * Expose priv validators for use in testing * Generalize block header validation test past height 1 * Remove ineffectual assignment * Remove redundant SaveState call * Reorder comment for clarity * Use the block executor ApplyBlock function instead of implementing a stripped-down version of it * Remove commented-out code * Remove unnecessary test The required tests already appear to be implemented (implicitly) through the TestValidateBlockHeader test. * Allow for catching of specific error types during TestValidateBlockCommit * Make return error testable * Clean up and add TestValidateBlockCommit code * Fix formatting * Extract function to create a new mock test app * Update comment for clarity * Fix comment * Add skeleton code for evidence-related test * Allow for addressing priv val by address * Generalize test beyond a single validator * Generalize TestValidateBlockEvidence past first height * Reorder code to clearly separate tests and utility code * Use a common constant for stop height for testing in state/validation_test.go * Refactor errors to resemble existing conventions * Fix formatting * Extract common helper functions Having the tests littered with helper functions makes them less easily readable imho, so I've pulled them out into a separate file. This also makes it easier to see what helper functions are available during testing, so we minimize the chance of duplication when writing new tests. * Remove unused parameter * Remove unused parameters * Add field keys * Remove unused height constant * Fix typo * Fix incorrect return error * Add field keys * Use separate package for tests This refactors all of the state package's tests into a state_test package, so as to keep any usage of the state package's internal methods explicit. Any internal methods/constants used by tests are now explicitly exported in state/export_test.go * Refactor: extract helper function to make, validate, execute and commit a block * Rename state function to makeState * Remove redundant constant for number of validators * Refactor mock evidence registration into TestMain * Remove extraneous nVals variable * Replace function-level TODOs with file-level TODO and explanation * Remove extraneous comment * Fix linting issues brought up by GolangCI (pulled in from latest merge from develop)
6 years ago
state: add more tests for block validation (#3674) * Expose priv validators for use in testing * Generalize block header validation test past height 1 * Remove ineffectual assignment * Remove redundant SaveState call * Reorder comment for clarity * Use the block executor ApplyBlock function instead of implementing a stripped-down version of it * Remove commented-out code * Remove unnecessary test The required tests already appear to be implemented (implicitly) through the TestValidateBlockHeader test. * Allow for catching of specific error types during TestValidateBlockCommit * Make return error testable * Clean up and add TestValidateBlockCommit code * Fix formatting * Extract function to create a new mock test app * Update comment for clarity * Fix comment * Add skeleton code for evidence-related test * Allow for addressing priv val by address * Generalize test beyond a single validator * Generalize TestValidateBlockEvidence past first height * Reorder code to clearly separate tests and utility code * Use a common constant for stop height for testing in state/validation_test.go * Refactor errors to resemble existing conventions * Fix formatting * Extract common helper functions Having the tests littered with helper functions makes them less easily readable imho, so I've pulled them out into a separate file. This also makes it easier to see what helper functions are available during testing, so we minimize the chance of duplication when writing new tests. * Remove unused parameter * Remove unused parameters * Add field keys * Remove unused height constant * Fix typo * Fix incorrect return error * Add field keys * Use separate package for tests This refactors all of the state package's tests into a state_test package, so as to keep any usage of the state package's internal methods explicit. Any internal methods/constants used by tests are now explicitly exported in state/export_test.go * Refactor: extract helper function to make, validate, execute and commit a block * Rename state function to makeState * Remove redundant constant for number of validators * Refactor mock evidence registration into TestMain * Remove extraneous nVals variable * Replace function-level TODOs with file-level TODO and explanation * Remove extraneous comment * Fix linting issues brought up by GolangCI (pulled in from latest merge from develop)
6 years ago
state: add more tests for block validation (#3674) * Expose priv validators for use in testing * Generalize block header validation test past height 1 * Remove ineffectual assignment * Remove redundant SaveState call * Reorder comment for clarity * Use the block executor ApplyBlock function instead of implementing a stripped-down version of it * Remove commented-out code * Remove unnecessary test The required tests already appear to be implemented (implicitly) through the TestValidateBlockHeader test. * Allow for catching of specific error types during TestValidateBlockCommit * Make return error testable * Clean up and add TestValidateBlockCommit code * Fix formatting * Extract function to create a new mock test app * Update comment for clarity * Fix comment * Add skeleton code for evidence-related test * Allow for addressing priv val by address * Generalize test beyond a single validator * Generalize TestValidateBlockEvidence past first height * Reorder code to clearly separate tests and utility code * Use a common constant for stop height for testing in state/validation_test.go * Refactor errors to resemble existing conventions * Fix formatting * Extract common helper functions Having the tests littered with helper functions makes them less easily readable imho, so I've pulled them out into a separate file. This also makes it easier to see what helper functions are available during testing, so we minimize the chance of duplication when writing new tests. * Remove unused parameter * Remove unused parameters * Add field keys * Remove unused height constant * Fix typo * Fix incorrect return error * Add field keys * Use separate package for tests This refactors all of the state package's tests into a state_test package, so as to keep any usage of the state package's internal methods explicit. Any internal methods/constants used by tests are now explicitly exported in state/export_test.go * Refactor: extract helper function to make, validate, execute and commit a block * Rename state function to makeState * Remove redundant constant for number of validators * Refactor mock evidence registration into TestMain * Remove extraneous nVals variable * Replace function-level TODOs with file-level TODO and explanation * Remove extraneous comment * Fix linting issues brought up by GolangCI (pulled in from latest merge from develop)
6 years ago
state: add more tests for block validation (#3674) * Expose priv validators for use in testing * Generalize block header validation test past height 1 * Remove ineffectual assignment * Remove redundant SaveState call * Reorder comment for clarity * Use the block executor ApplyBlock function instead of implementing a stripped-down version of it * Remove commented-out code * Remove unnecessary test The required tests already appear to be implemented (implicitly) through the TestValidateBlockHeader test. * Allow for catching of specific error types during TestValidateBlockCommit * Make return error testable * Clean up and add TestValidateBlockCommit code * Fix formatting * Extract function to create a new mock test app * Update comment for clarity * Fix comment * Add skeleton code for evidence-related test * Allow for addressing priv val by address * Generalize test beyond a single validator * Generalize TestValidateBlockEvidence past first height * Reorder code to clearly separate tests and utility code * Use a common constant for stop height for testing in state/validation_test.go * Refactor errors to resemble existing conventions * Fix formatting * Extract common helper functions Having the tests littered with helper functions makes them less easily readable imho, so I've pulled them out into a separate file. This also makes it easier to see what helper functions are available during testing, so we minimize the chance of duplication when writing new tests. * Remove unused parameter * Remove unused parameters * Add field keys * Remove unused height constant * Fix typo * Fix incorrect return error * Add field keys * Use separate package for tests This refactors all of the state package's tests into a state_test package, so as to keep any usage of the state package's internal methods explicit. Any internal methods/constants used by tests are now explicitly exported in state/export_test.go * Refactor: extract helper function to make, validate, execute and commit a block * Rename state function to makeState * Remove redundant constant for number of validators * Refactor mock evidence registration into TestMain * Remove extraneous nVals variable * Replace function-level TODOs with file-level TODO and explanation * Remove extraneous comment * Fix linting issues brought up by GolangCI (pulled in from latest merge from develop)
6 years ago
  1. package state_test
  2. import (
  3. "testing"
  4. "time"
  5. "github.com/stretchr/testify/assert"
  6. "github.com/stretchr/testify/require"
  7. "github.com/tendermint/tendermint/crypto"
  8. "github.com/tendermint/tendermint/libs/bytes"
  9. tmrand "github.com/tendermint/tendermint/libs/rand"
  10. "github.com/tendermint/tendermint/proto/tendermint/version"
  11. "github.com/tendermint/tendermint/crypto/ed25519"
  12. "github.com/tendermint/tendermint/crypto/tmhash"
  13. "github.com/tendermint/tendermint/libs/log"
  14. memmock "github.com/tendermint/tendermint/mempool/mock"
  15. protostate "github.com/tendermint/tendermint/proto/tendermint/state"
  16. tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
  17. sm "github.com/tendermint/tendermint/state"
  18. "github.com/tendermint/tendermint/state/mocks"
  19. "github.com/tendermint/tendermint/types"
  20. tmtime "github.com/tendermint/tendermint/types/time"
  21. )
  22. const validationTestsStopHeight int64 = 10
  23. var defaultTestTime = time.Date(2019, 1, 1, 0, 0, 0, 0, time.UTC)
  24. func TestValidateBlockHeader(t *testing.T) {
  25. proxyApp := newTestApp()
  26. require.NoError(t, proxyApp.Start())
  27. defer proxyApp.Stop() //nolint:errcheck // ignore for tests
  28. state, stateDB, privVals := makeState(3, 1)
  29. blockExec := sm.NewBlockExecutor(
  30. stateDB,
  31. log.TestingLogger(),
  32. proxyApp.Consensus(),
  33. memmock.Mempool{},
  34. sm.MockEvidencePool{},
  35. )
  36. lastCommit := types.NewCommit(0, 0, types.BlockID{}, nil)
  37. // some bad values
  38. wrongHash := tmhash.Sum([]byte("this hash is wrong"))
  39. wrongVersion1 := state.Version.Consensus
  40. wrongVersion1.Block += 2
  41. wrongVersion2 := state.Version.Consensus
  42. wrongVersion2.App += 2
  43. // Manipulation of any header field causes failure.
  44. testCases := []struct {
  45. name string
  46. malleateBlock func(block *types.Block)
  47. }{
  48. {"Version wrong1", func(block *types.Block) { block.Version = wrongVersion1 }},
  49. {"Version wrong2", func(block *types.Block) { block.Version = wrongVersion2 }},
  50. {"ChainID wrong", func(block *types.Block) { block.ChainID = "not-the-real-one" }},
  51. {"Height wrong", func(block *types.Block) { block.Height += 10 }},
  52. {"Time wrong", func(block *types.Block) { block.Time = block.Time.Add(-time.Second * 1) }},
  53. {"LastBlockID wrong", func(block *types.Block) { block.LastBlockID.PartSetHeader.Total += 10 }},
  54. {"LastCommitHash wrong", func(block *types.Block) { block.LastCommitHash = wrongHash }},
  55. {"DataHash wrong", func(block *types.Block) { block.DataHash = wrongHash }},
  56. {"ValidatorsHash wrong", func(block *types.Block) { block.ValidatorsHash = wrongHash }},
  57. {"NextValidatorsHash wrong", func(block *types.Block) { block.NextValidatorsHash = wrongHash }},
  58. {"ConsensusHash wrong", func(block *types.Block) { block.ConsensusHash = wrongHash }},
  59. {"AppHash wrong", func(block *types.Block) { block.AppHash = wrongHash }},
  60. {"LastResultsHash wrong", func(block *types.Block) { block.LastResultsHash = wrongHash }},
  61. {"EvidenceHash wrong", func(block *types.Block) { block.EvidenceHash = wrongHash }},
  62. {"Proposer wrong", func(block *types.Block) { block.ProposerAddress = ed25519.GenPrivKey().PubKey().Address() }},
  63. {"Proposer invalid", func(block *types.Block) { block.ProposerAddress = []byte("wrong size") }},
  64. }
  65. // Build up state for multiple heights
  66. for height := int64(1); height < validationTestsStopHeight; height++ {
  67. proposerAddr := state.Validators.GetProposer().Address
  68. /*
  69. Invalid blocks don't pass
  70. */
  71. for _, tc := range testCases {
  72. block, _ := state.MakeBlock(height, makeTxs(height), lastCommit, nil, proposerAddr)
  73. tc.malleateBlock(block)
  74. err := blockExec.ValidateBlock(state, block)
  75. require.Error(t, err, tc.name)
  76. }
  77. /*
  78. A good block passes
  79. */
  80. var err error
  81. state, _, lastCommit, err = makeAndCommitGoodBlock(state, height, lastCommit, proposerAddr, blockExec, privVals, nil)
  82. require.NoError(t, err, "height %d", height)
  83. }
  84. }
  85. func TestValidateBlockCommit(t *testing.T) {
  86. proxyApp := newTestApp()
  87. require.NoError(t, proxyApp.Start())
  88. defer proxyApp.Stop() //nolint:errcheck // ignore for tests
  89. state, stateDB, privVals := makeState(1, 1)
  90. blockExec := sm.NewBlockExecutor(
  91. stateDB,
  92. log.TestingLogger(),
  93. proxyApp.Consensus(),
  94. memmock.Mempool{},
  95. sm.MockEvidencePool{},
  96. )
  97. lastCommit := types.NewCommit(0, 0, types.BlockID{}, nil)
  98. wrongSigsCommit := types.NewCommit(1, 0, types.BlockID{}, nil)
  99. badPrivVal := types.NewMockPV()
  100. for height := int64(1); height < validationTestsStopHeight; height++ {
  101. proposerAddr := state.Validators.GetProposer().Address
  102. if height > 1 {
  103. /*
  104. #2589: ensure state.LastValidators.VerifyCommit fails here
  105. */
  106. // should be height-1 instead of height
  107. wrongHeightVote, err := types.MakeVote(
  108. height,
  109. state.LastBlockID,
  110. state.Validators,
  111. privVals[proposerAddr.String()],
  112. chainID,
  113. time.Now(),
  114. )
  115. require.NoError(t, err, "height %d", height)
  116. wrongHeightCommit := types.NewCommit(
  117. wrongHeightVote.Height,
  118. wrongHeightVote.Round,
  119. state.LastBlockID,
  120. []types.CommitSig{wrongHeightVote.CommitSig()},
  121. )
  122. block, _ := state.MakeBlock(height, makeTxs(height), wrongHeightCommit, nil, proposerAddr)
  123. err = blockExec.ValidateBlock(state, block)
  124. _, isErrInvalidCommitHeight := err.(types.ErrInvalidCommitHeight)
  125. require.True(t, isErrInvalidCommitHeight, "expected ErrInvalidCommitHeight at height %d but got: %v", height, err)
  126. /*
  127. #2589: test len(block.LastCommit.Signatures) == state.LastValidators.Size()
  128. */
  129. block, _ = state.MakeBlock(height, makeTxs(height), wrongSigsCommit, nil, proposerAddr)
  130. err = blockExec.ValidateBlock(state, block)
  131. _, isErrInvalidCommitSignatures := err.(types.ErrInvalidCommitSignatures)
  132. require.True(t, isErrInvalidCommitSignatures,
  133. "expected ErrInvalidCommitSignatures at height %d, but got: %v",
  134. height,
  135. err,
  136. )
  137. }
  138. /*
  139. A good block passes
  140. */
  141. var err error
  142. var blockID types.BlockID
  143. state, blockID, lastCommit, err = makeAndCommitGoodBlock(
  144. state,
  145. height,
  146. lastCommit,
  147. proposerAddr,
  148. blockExec,
  149. privVals,
  150. nil,
  151. )
  152. require.NoError(t, err, "height %d", height)
  153. /*
  154. wrongSigsCommit is fine except for the extra bad precommit
  155. */
  156. goodVote, err := types.MakeVote(height,
  157. blockID,
  158. state.Validators,
  159. privVals[proposerAddr.String()],
  160. chainID,
  161. time.Now(),
  162. )
  163. require.NoError(t, err, "height %d", height)
  164. bpvPubKey, err := badPrivVal.GetPubKey()
  165. require.NoError(t, err)
  166. badVote := &types.Vote{
  167. ValidatorAddress: bpvPubKey.Address(),
  168. ValidatorIndex: 0,
  169. Height: height,
  170. Round: 0,
  171. Timestamp: tmtime.Now(),
  172. Type: tmproto.PrecommitType,
  173. BlockID: blockID,
  174. }
  175. g := goodVote.ToProto()
  176. b := badVote.ToProto()
  177. err = badPrivVal.SignVote(chainID, g)
  178. require.NoError(t, err, "height %d", height)
  179. err = badPrivVal.SignVote(chainID, b)
  180. require.NoError(t, err, "height %d", height)
  181. goodVote.Signature, badVote.Signature = g.Signature, b.Signature
  182. wrongSigsCommit = types.NewCommit(goodVote.Height, goodVote.Round,
  183. blockID, []types.CommitSig{goodVote.CommitSig(), badVote.CommitSig()})
  184. }
  185. }
  186. func TestValidateBlockEvidence(t *testing.T) {
  187. proxyApp := newTestApp()
  188. require.NoError(t, proxyApp.Start())
  189. defer proxyApp.Stop() //nolint:errcheck // ignore for tests
  190. state, stateDB, privVals := makeState(4, 1)
  191. state.ConsensusParams.Evidence.MaxNum = 3
  192. blockExec := sm.NewBlockExecutor(
  193. stateDB,
  194. log.TestingLogger(),
  195. proxyApp.Consensus(),
  196. memmock.Mempool{},
  197. sm.MockEvidencePool{},
  198. )
  199. lastCommit := types.NewCommit(0, 0, types.BlockID{}, nil)
  200. for height := int64(1); height < validationTestsStopHeight; height++ {
  201. proposerAddr := state.Validators.GetProposer().Address
  202. maxNumEvidence := state.ConsensusParams.Evidence.MaxNum
  203. t.Log(maxNumEvidence)
  204. if height > 1 {
  205. /*
  206. A block with too much evidence fails
  207. */
  208. require.True(t, maxNumEvidence > 2)
  209. evidence := make([]types.Evidence, 0)
  210. // one more than the maximum allowed evidence
  211. for i := uint32(0); i <= maxNumEvidence; i++ {
  212. evidence = append(evidence, types.NewMockDuplicateVoteEvidenceWithValidator(height, time.Now(),
  213. privVals[proposerAddr.String()], chainID))
  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. _, val := state.Validators.GetByIndex(i)
  229. evidence = append(evidence, types.NewMockDuplicateVoteEvidenceWithValidator(height, time.Now(),
  230. privVals[val.Address.String()], chainID))
  231. }
  232. var err error
  233. state, _, lastCommit, err = makeAndCommitGoodBlock(
  234. state,
  235. height,
  236. lastCommit,
  237. proposerAddr,
  238. blockExec,
  239. privVals,
  240. evidence,
  241. )
  242. require.NoError(t, err, "height %d", height)
  243. }
  244. }
  245. func TestValidateFailBlockOnCommittedEvidence(t *testing.T) {
  246. var height int64 = 1
  247. state, stateDB, privVals := makeState(2, int(height))
  248. _, val := state.Validators.GetByIndex(0)
  249. _, val2 := state.Validators.GetByIndex(1)
  250. ev := types.NewMockDuplicateVoteEvidenceWithValidator(height, defaultTestTime,
  251. privVals[val.Address.String()], chainID)
  252. ev2 := types.NewMockDuplicateVoteEvidenceWithValidator(height, defaultTestTime,
  253. privVals[val2.Address.String()], chainID)
  254. evpool := &mocks.EvidencePool{}
  255. evpool.On("IsPending", ev).Return(false)
  256. evpool.On("IsPending", ev2).Return(false)
  257. evpool.On("IsCommitted", ev).Return(false)
  258. evpool.On("IsCommitted", ev2).Return(true)
  259. blockExec := sm.NewBlockExecutor(
  260. stateDB, log.TestingLogger(),
  261. nil,
  262. nil,
  263. evpool)
  264. // A block with a couple pieces of evidence passes.
  265. block := makeBlock(state, height)
  266. block.Evidence.Evidence = []types.Evidence{ev, ev2}
  267. block.EvidenceHash = block.Evidence.Hash()
  268. err := blockExec.ValidateBlock(state, block)
  269. assert.Error(t, err)
  270. assert.IsType(t, err, &types.ErrEvidenceInvalid{})
  271. }
  272. func TestValidateAlreadyPendingEvidence(t *testing.T) {
  273. var height int64 = 1
  274. state, stateDB, privVals := makeState(2, int(height))
  275. _, val := state.Validators.GetByIndex(0)
  276. _, val2 := state.Validators.GetByIndex(1)
  277. ev := types.NewMockDuplicateVoteEvidenceWithValidator(height, defaultTestTime,
  278. privVals[val.Address.String()], chainID)
  279. ev2 := types.NewMockDuplicateVoteEvidenceWithValidator(height, defaultTestTime,
  280. privVals[val2.Address.String()], chainID)
  281. evpool := &mocks.EvidencePool{}
  282. evpool.On("IsPending", ev).Return(false)
  283. evpool.On("IsPending", ev2).Return(true)
  284. evpool.On("IsCommitted", ev).Return(false)
  285. evpool.On("IsCommitted", ev2).Return(false)
  286. blockExec := sm.NewBlockExecutor(
  287. stateDB, log.TestingLogger(),
  288. nil,
  289. nil,
  290. evpool)
  291. // A block with a couple pieces of evidence passes.
  292. block := makeBlock(state, height)
  293. // add one evidence seen before and one evidence that hasn't
  294. block.Evidence.Evidence = []types.Evidence{ev, ev2}
  295. block.EvidenceHash = block.Evidence.Hash()
  296. err := blockExec.ValidateBlock(state, block)
  297. assert.NoError(t, err)
  298. }
  299. func TestValidateDuplicateEvidenceShouldFail(t *testing.T) {
  300. var height int64 = 1
  301. state, stateDB, privVals := makeState(2, int(height))
  302. _, val := state.Validators.GetByIndex(0)
  303. _, val2 := state.Validators.GetByIndex(1)
  304. ev := types.NewMockDuplicateVoteEvidenceWithValidator(height, defaultTestTime,
  305. privVals[val.Address.String()], chainID)
  306. ev2 := types.NewMockDuplicateVoteEvidenceWithValidator(height, defaultTestTime,
  307. privVals[val2.Address.String()], chainID)
  308. blockExec := sm.NewBlockExecutor(
  309. stateDB, log.TestingLogger(),
  310. nil,
  311. nil,
  312. sm.MockEvidencePool{})
  313. // A block with a couple pieces of evidence passes.
  314. block := makeBlock(state, height)
  315. block.Evidence.Evidence = []types.Evidence{ev, ev2, ev2}
  316. block.EvidenceHash = block.Evidence.Hash()
  317. err := blockExec.ValidateBlock(state, block)
  318. assert.Error(t, err)
  319. }
  320. var (
  321. blockID = types.BlockID{
  322. Hash: tmrand.Bytes(tmhash.Size),
  323. PartSetHeader: types.PartSetHeader{
  324. Total: 1,
  325. Hash: tmrand.Bytes(tmhash.Size),
  326. },
  327. }
  328. differentBlockID = types.BlockID{
  329. Hash: tmrand.Bytes(tmhash.Size),
  330. PartSetHeader: types.PartSetHeader{
  331. Total: 1,
  332. Hash: tmrand.Bytes(tmhash.Size),
  333. },
  334. }
  335. )
  336. func TestValidateUnseenAmnesiaEvidence(t *testing.T) {
  337. var height int64 = 1
  338. state, stateDB, vals := makeState(1, int(height))
  339. addr, val := state.Validators.GetByIndex(0)
  340. voteA := makeVote(height, 1, 0, addr, blockID)
  341. vA := voteA.ToProto()
  342. err := vals[val.Address.String()].SignVote(chainID, vA)
  343. voteA.Signature = vA.Signature
  344. require.NoError(t, err)
  345. voteB := makeVote(height, 2, 0, addr, differentBlockID)
  346. vB := voteB.ToProto()
  347. err = vals[val.Address.String()].SignVote(chainID, vB)
  348. voteB.Signature = vB.Signature
  349. require.NoError(t, err)
  350. pe := &types.PotentialAmnesiaEvidence{
  351. VoteA: voteA,
  352. VoteB: voteB,
  353. }
  354. ae := &types.AmnesiaEvidence{
  355. PotentialAmnesiaEvidence: pe,
  356. Polc: types.NewEmptyPOLC(),
  357. }
  358. evpool := &mocks.EvidencePool{}
  359. evpool.On("IsPending", ae).Return(false)
  360. evpool.On("IsCommitted", ae).Return(false)
  361. evpool.On("AddEvidence", ae).Return(nil)
  362. evpool.On("AddEvidence", pe).Return(nil)
  363. blockExec := sm.NewBlockExecutor(
  364. stateDB, log.TestingLogger(),
  365. nil,
  366. nil,
  367. evpool)
  368. // A block with a couple pieces of evidence passes.
  369. block := makeBlock(state, height)
  370. block.Evidence.Evidence = []types.Evidence{ae}
  371. block.EvidenceHash = block.Evidence.Hash()
  372. err = blockExec.ValidateBlock(state, block)
  373. // if we don't have this evidence and it is has an empty polc then we expect to
  374. // start our own trial period first
  375. errMsg := "Invalid evidence: amnesia evidence is new and hasn't undergone trial period yet."
  376. if assert.Error(t, err) {
  377. assert.Equal(t, errMsg, err.Error()[:len(errMsg)])
  378. }
  379. }
  380. // Amnesia Evidence can be directly approved without needing to undergo the trial period
  381. func TestValidatePrimedAmnesiaEvidence(t *testing.T) {
  382. var height int64 = 1
  383. state, stateDB, vals := makeState(1, int(height))
  384. addr, val := state.Validators.GetByIndex(0)
  385. voteA := makeVote(height, 1, 0, addr, blockID)
  386. voteA.Timestamp = time.Now().Add(1 * time.Minute)
  387. vA := voteA.ToProto()
  388. err := vals[val.Address.String()].SignVote(chainID, vA)
  389. require.NoError(t, err)
  390. voteA.Signature = vA.Signature
  391. voteB := makeVote(height, 2, 0, addr, differentBlockID)
  392. vB := voteB.ToProto()
  393. err = vals[val.Address.String()].SignVote(chainID, vB)
  394. voteB.Signature = vB.Signature
  395. require.NoError(t, err)
  396. pe := &types.PotentialAmnesiaEvidence{
  397. VoteA: voteB,
  398. VoteB: voteA,
  399. }
  400. ae := &types.AmnesiaEvidence{
  401. PotentialAmnesiaEvidence: pe,
  402. Polc: types.NewEmptyPOLC(),
  403. }
  404. evpool := &mocks.EvidencePool{}
  405. evpool.On("IsPending", ae).Return(false)
  406. evpool.On("IsCommitted", ae).Return(false)
  407. evpool.On("AddEvidence", ae).Return(nil)
  408. evpool.On("AddEvidence", pe).Return(nil)
  409. blockExec := sm.NewBlockExecutor(
  410. stateDB, log.TestingLogger(),
  411. nil,
  412. nil,
  413. evpool)
  414. // A block with a couple pieces of evidence passes.
  415. block := makeBlock(state, height)
  416. block.Evidence.Evidence = []types.Evidence{ae}
  417. block.EvidenceHash = block.Evidence.Hash()
  418. err = blockExec.ValidateBlock(state, block)
  419. // No error because this type of amnesia evidence is punishable
  420. // without the need of a trial period
  421. assert.NoError(t, err)
  422. }
  423. func TestVerifyEvidenceWrongAddress(t *testing.T) {
  424. var height int64 = 1
  425. state, stateDB, _ := makeState(1, int(height))
  426. ev := types.NewMockDuplicateVoteEvidence(height, defaultTestTime, chainID)
  427. blockExec := sm.NewBlockExecutor(
  428. stateDB, log.TestingLogger(),
  429. nil,
  430. nil,
  431. sm.MockEvidencePool{})
  432. // A block with a couple pieces of evidence passes.
  433. block := makeBlock(state, height)
  434. block.Evidence.Evidence = []types.Evidence{ev}
  435. block.EvidenceHash = block.Evidence.Hash()
  436. err := blockExec.ValidateBlock(state, block)
  437. errMsg := "Invalid evidence: address "
  438. if assert.Error(t, err) {
  439. assert.Equal(t, err.Error()[:len(errMsg)], errMsg)
  440. }
  441. }
  442. func TestVerifyEvidenceExpiredEvidence(t *testing.T) {
  443. var height int64 = 4
  444. state, stateDB, _ := makeState(1, int(height))
  445. state.ConsensusParams.Evidence.MaxAgeNumBlocks = 1
  446. ev := types.NewMockDuplicateVoteEvidence(1, defaultTestTime, chainID)
  447. err := sm.VerifyEvidence(stateDB, state, ev, nil)
  448. errMsg := "evidence from height 1 (created at: 2019-01-01 00:00:00 +0000 UTC) is too old"
  449. if assert.Error(t, err) {
  450. assert.Equal(t, err.Error()[:len(errMsg)], errMsg)
  451. }
  452. }
  453. func TestVerifyEvidenceWithAmnesiaEvidence(t *testing.T) {
  454. var height int64 = 1
  455. state, stateDB, vals := makeState(4, int(height))
  456. addr, val := state.Validators.GetByIndex(0)
  457. addr2, val2 := state.Validators.GetByIndex(1)
  458. voteA := makeVote(height, 1, 0, addr, types.BlockID{})
  459. vA := voteA.ToProto()
  460. err := vals[val.Address.String()].SignVote(chainID, vA)
  461. voteA.Signature = vA.Signature
  462. require.NoError(t, err)
  463. voteB := makeVote(height, 2, 0, addr, blockID)
  464. vB := voteB.ToProto()
  465. err = vals[val.Address.String()].SignVote(chainID, vB)
  466. voteB.Signature = vB.Signature
  467. require.NoError(t, err)
  468. voteC := makeVote(height, 2, 1, addr2, blockID)
  469. vC := voteC.ToProto()
  470. err = vals[val2.Address.String()].SignVote(chainID, vC)
  471. voteC.Signature = vC.Signature
  472. require.NoError(t, err)
  473. //var ae types.Evidence
  474. badAe := &types.AmnesiaEvidence{
  475. PotentialAmnesiaEvidence: &types.PotentialAmnesiaEvidence{
  476. VoteA: voteA,
  477. VoteB: voteB,
  478. },
  479. Polc: &types.ProofOfLockChange{
  480. Votes: []*types.Vote{voteC},
  481. PubKey: val.PubKey,
  482. },
  483. }
  484. err = sm.VerifyEvidence(stateDB, state, badAe, nil)
  485. if assert.Error(t, err) {
  486. assert.Equal(t, err.Error(), "amnesia evidence contains invalid polc, err: "+
  487. "invalid commit -- insufficient voting power: got 1000, needed more than 2667")
  488. }
  489. addr3, val3 := state.Validators.GetByIndex(2)
  490. voteD := makeVote(height, 2, 2, addr3, blockID)
  491. vD := voteD.ToProto()
  492. err = vals[val3.Address.String()].SignVote(chainID, vD)
  493. require.NoError(t, err)
  494. voteD.Signature = vD.Signature
  495. addr4, val4 := state.Validators.GetByIndex(3)
  496. voteE := makeVote(height, 2, 3, addr4, blockID)
  497. vE := voteE.ToProto()
  498. err = vals[val4.Address.String()].SignVote(chainID, vE)
  499. voteE.Signature = vE.Signature
  500. require.NoError(t, err)
  501. goodAe := &types.AmnesiaEvidence{
  502. PotentialAmnesiaEvidence: &types.PotentialAmnesiaEvidence{
  503. VoteA: voteA,
  504. VoteB: voteB,
  505. },
  506. Polc: &types.ProofOfLockChange{
  507. Votes: []*types.Vote{voteC, voteD, voteE},
  508. PubKey: val.PubKey,
  509. },
  510. }
  511. err = sm.VerifyEvidence(stateDB, state, goodAe, nil)
  512. assert.NoError(t, err)
  513. goodAe = &types.AmnesiaEvidence{
  514. PotentialAmnesiaEvidence: &types.PotentialAmnesiaEvidence{
  515. VoteA: voteA,
  516. VoteB: voteB,
  517. },
  518. Polc: types.NewEmptyPOLC(),
  519. }
  520. err = sm.VerifyEvidence(stateDB, state, goodAe, nil)
  521. assert.NoError(t, err)
  522. }
  523. func TestVerifyEvidenceWithLunaticValidatorEvidence(t *testing.T) {
  524. state, stateDB, vals := makeState(4, 4)
  525. state.ConsensusParams.Evidence.MaxAgeNumBlocks = 1
  526. addr, val := state.Validators.GetByIndex(0)
  527. h := &types.Header{
  528. Version: version.Consensus{Block: 1, App: 2},
  529. ChainID: chainID,
  530. Height: 3,
  531. Time: defaultTestTime,
  532. LastBlockID: blockID,
  533. LastCommitHash: tmhash.Sum([]byte("last_commit_hash")),
  534. DataHash: tmhash.Sum([]byte("data_hash")),
  535. ValidatorsHash: tmhash.Sum([]byte("validators_hash")),
  536. NextValidatorsHash: tmhash.Sum([]byte("next_validators_hash")),
  537. ConsensusHash: tmhash.Sum([]byte("consensus_hash")),
  538. AppHash: tmhash.Sum([]byte("app_hash")),
  539. LastResultsHash: tmhash.Sum([]byte("last_results_hash")),
  540. EvidenceHash: tmhash.Sum([]byte("evidence_hash")),
  541. ProposerAddress: crypto.AddressHash([]byte("proposer_address")),
  542. }
  543. vote := makeVote(3, 1, 0, addr, types.BlockID{
  544. Hash: h.Hash(),
  545. PartSetHeader: types.PartSetHeader{
  546. Total: 100,
  547. Hash: crypto.CRandBytes(tmhash.Size),
  548. },
  549. })
  550. v := vote.ToProto()
  551. err := vals[val.Address.String()].SignVote(chainID, v)
  552. vote.Signature = v.Signature
  553. require.NoError(t, err)
  554. ev := &types.LunaticValidatorEvidence{
  555. Header: h,
  556. Vote: vote,
  557. InvalidHeaderField: "ConsensusHash",
  558. }
  559. err = ev.ValidateBasic()
  560. require.NoError(t, err)
  561. err = sm.VerifyEvidence(stateDB, state, ev, h)
  562. if assert.Error(t, err) {
  563. assert.Equal(t, "ConsensusHash matches committed hash", err.Error())
  564. }
  565. }
  566. func TestVerifyEvidenceWithPhantomValidatorEvidence(t *testing.T) {
  567. state, stateDB, vals := makeState(4, 4)
  568. state.ConsensusParams.Evidence.MaxAgeNumBlocks = 1
  569. addr, val := state.Validators.GetByIndex(0)
  570. vote := makeVote(3, 1, 0, addr, blockID)
  571. v := vote.ToProto()
  572. err := vals[val.Address.String()].SignVote(chainID, v)
  573. vote.Signature = v.Signature
  574. require.NoError(t, err)
  575. ev := &types.PhantomValidatorEvidence{
  576. Vote: vote,
  577. LastHeightValidatorWasInSet: 1,
  578. }
  579. err = ev.ValidateBasic()
  580. require.NoError(t, err)
  581. err = sm.VerifyEvidence(stateDB, state, ev, nil)
  582. if assert.Error(t, err) {
  583. assert.Equal(t, "address 576585A00DD4D58318255611D8AAC60E8E77CB32 was a validator at height 3", err.Error())
  584. }
  585. privVal := types.NewMockPV()
  586. pubKey, _ := privVal.GetPubKey()
  587. vote2 := makeVote(3, 1, 0, pubKey.Address(), blockID)
  588. v2 := vote2.ToProto()
  589. err = privVal.SignVote(chainID, v2)
  590. vote2.Signature = v2.Signature
  591. require.NoError(t, err)
  592. ev = &types.PhantomValidatorEvidence{
  593. Vote: vote2,
  594. LastHeightValidatorWasInSet: 1,
  595. }
  596. err = ev.ValidateBasic()
  597. assert.NoError(t, err)
  598. err = sm.VerifyEvidence(stateDB, state, ev, nil)
  599. if assert.Error(t, err) {
  600. assert.Equal(t, "last time validator was in the set at height 1, min: 2", err.Error())
  601. }
  602. ev = &types.PhantomValidatorEvidence{
  603. Vote: vote2,
  604. LastHeightValidatorWasInSet: 2,
  605. }
  606. err = ev.ValidateBasic()
  607. assert.NoError(t, err)
  608. err = sm.VerifyEvidence(stateDB, state, ev, nil)
  609. errMsg := "phantom validator"
  610. if assert.Error(t, err) {
  611. assert.Equal(t, errMsg, err.Error()[:len(errMsg)])
  612. }
  613. vals2, err := sm.LoadValidators(stateDB, 2)
  614. require.NoError(t, err)
  615. vals2.Validators = append(vals2.Validators, types.NewValidator(pubKey, 1000))
  616. valKey := []byte("validatorsKey:2")
  617. protoVals, err := vals2.ToProto()
  618. require.NoError(t, err)
  619. valInfo := &protostate.ValidatorsInfo{
  620. LastHeightChanged: 2,
  621. ValidatorSet: protoVals,
  622. }
  623. bz, err := valInfo.Marshal()
  624. require.NoError(t, err)
  625. err = stateDB.Set(valKey, bz)
  626. require.NoError(t, err)
  627. ev = &types.PhantomValidatorEvidence{
  628. Vote: vote2,
  629. LastHeightValidatorWasInSet: 2,
  630. }
  631. err = ev.ValidateBasic()
  632. assert.NoError(t, err)
  633. err = sm.VerifyEvidence(stateDB, state, ev, nil)
  634. if !assert.NoError(t, err) {
  635. t.Log(err)
  636. }
  637. }
  638. func makeVote(height int64, round, index int32, addr bytes.HexBytes, blockID types.BlockID) *types.Vote {
  639. return &types.Vote{
  640. Type: tmproto.SignedMsgType(2),
  641. Height: height,
  642. Round: round,
  643. BlockID: blockID,
  644. Timestamp: time.Now(),
  645. ValidatorAddress: addr,
  646. ValidatorIndex: index,
  647. }
  648. }