Skip to content

Commit

Permalink
add 1.14 test
Browse files Browse the repository at this point in the history
  • Loading branch information
2501babe committed Jul 16, 2024
1 parent c4c07e0 commit 13c185d
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions sdk/program/src/vote/state/vote_state_1_14_11.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,44 @@ impl From<VoteState> for VoteState1_14_11 {
}
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_vote_deserialize_1_14_11() {
// base case
let target_vote_state = VoteState1_14_11::default();
let target_vote_state_versions = VoteStateVersions::V1_14_11(Box::new(target_vote_state));
let vote_state_buf = bincode::serialize(&target_vote_state_versions).unwrap();

let mut test_vote_state = VoteState::default();
VoteState::deserialize_into(&vote_state_buf, &mut test_vote_state).unwrap();

assert_eq!(
target_vote_state_versions.convert_to_current(),
test_vote_state
);

// variant
// provide 4x the minimum struct size in bytes to ensure we typically touch every field
let struct_bytes_x4 = std::mem::size_of::<VoteState1_14_11>() * 4;
for _ in 0..1000 {
let raw_data: Vec<u8> = (0..struct_bytes_x4).map(|_| rand::random::<u8>()).collect();
let mut unstructured = Unstructured::new(&raw_data);

let arbitrary_vote_state = VoteState1_14_11::arbitrary(&mut unstructured).unwrap();
let target_vote_state_versions =
VoteStateVersions::V1_14_11(Box::new(arbitrary_vote_state));

let vote_state_buf = bincode::serialize(&target_vote_state_versions).unwrap();
let target_vote_state = target_vote_state_versions.convert_to_current();

let mut test_vote_state = VoteState::default();
VoteState::deserialize_into(&vote_state_buf, &mut test_vote_state).unwrap();

assert_eq!(target_vote_state, test_vote_state);
}
}
}

0 comments on commit 13c185d

Please sign in to comment.