From cd3b2f537179d9b9c1bb62ba7732d028d695f94b Mon Sep 17 00:00:00 2001 From: Paul Hauner Date: Tue, 2 Oct 2018 09:47:20 +1000 Subject: [PATCH] Add test for attestation msg generation --- .../validation/message_generation.rs | 48 +++++++++++++++++-- 1 file changed, 43 insertions(+), 5 deletions(-) diff --git a/lighthouse/state/attestation_record/validation/message_generation.rs b/lighthouse/state/attestation_record/validation/message_generation.rs index 3bcc4c16a8..6299802e93 100644 --- a/lighthouse/state/attestation_record/validation/message_generation.rs +++ b/lighthouse/state/attestation_record/validation/message_generation.rs @@ -5,11 +5,12 @@ use super::utils::types::Hash256; /// Generates the message used to validate the signature provided with an AttestationRecord. /// /// Ensures that the signer of the message has a view of the chain that is compatible with ours. -pub fn generate_signed_message(slot: u64, - parent_hashes: &[Hash256], - shard_id: u16, - shard_block_hash: &Hash256, - justified_slot: u64) +pub fn generate_signed_message( + slot: u64, + parent_hashes: &[Hash256], + shard_id: u16, + shard_block_hash: &Hash256, + justified_slot: u64) -> Vec { /* @@ -30,3 +31,40 @@ pub fn generate_signed_message(slot: u64, let bytes = ssz_stream.drain(); canonical_hash(&bytes) } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_generate_signed_message() { + let slot = 93; + let parent_hashes: Vec = (0..12) + .map(|i| Hash256::from(i as u64)) + .collect(); + let shard_id = 15; + let shard_block_hash = Hash256::from("shard_block_hash".as_bytes()); + let justified_slot = 18; + + let output = generate_signed_message( + slot, + &parent_hashes, + shard_id, + &shard_block_hash, + justified_slot); + + /* + * Note: this is not some well-known test vector, it's simply the result of running + * this and printing the output. + * + * Once well-known test vectors are established, they should be placed here. + */ + let expected = vec![ + 149, 99, 94, 229, 72, 144, 233, 14, 164, 16, 143, 53, 94, 48, + 118, 179, 33, 181, 172, 215, 2, 191, 176, 18, 188, 172, 137, + 178, 236, 66, 74, 120 + ]; + + assert_eq!(output, expected); + } +}