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.

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