From eb00fb22b9bf8615d07113f3c3464239c7765db0 Mon Sep 17 00:00:00 2001 From: Aaron Feickert <66188213+AaronFeickert@users.noreply.github.com> Date: Fri, 18 Oct 2024 01:07:06 -0500 Subject: [PATCH] test: add DammSum known-answer test (#6638) Description --- Adds a known-answer test for the DammSum checksum implementation. Motivation and Context --- The DammSum checksum implementation already had extensive randomized testing, but did not have any known-answer tests. This PR adds one. How Has This Been Tested? --- The new test passes! What process can a PR reviewer use to test or verify this change? --- Ensure the test passes. If you're feeling bored, examine the checksum algorithm to convince yourself of the validity of the test. Breaking Changes --- - [x] None - [ ] Requires data directory on base node to be deleted - [ ] Requires hard fork - [ ] Other - Please specify --- base_layer/common_types/src/dammsum.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/base_layer/common_types/src/dammsum.rs b/base_layer/common_types/src/dammsum.rs index b862cda995..f5c680f513 100644 --- a/base_layer/common_types/src/dammsum.rs +++ b/base_layer/common_types/src/dammsum.rs @@ -224,4 +224,12 @@ mod test { assert_eq!(validate_checksum(&data_), Err(ChecksumError::InvalidChecksum)); } } + + #[test] + fn known_checksum() { + const SIZE: usize = 33; + + // We know what the checksum for all-zero data must be + assert_eq!(compute_checksum(&[0u8; SIZE]), 0u8); + } }