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.

634 lines
20 KiB

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