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.

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