fix char_to_vote_type (was always returning PreVote ...)
See:
@@ -20,12 +20,9 @@ fn vote_type_to_char(vt: VoteType) -> char {
}
fn char_to_vote_type(data: char) -> Result<VoteType, DecodeError> {
- let pre_vote = 0x01 as char;
- let pre_commit = 0x02 as char;
-
match data {
- pre_vote => Ok(VoteType::PreVote),
- pre_commit => Ok(VoteType::PreCommit),
+ '\u{1}' => Ok(VoteType::PreVote),
+ '\u{2}' => Ok(VoteType::PreCommit),
_ => Err(DecodeError::new("Invalid vote type"))
}
}
@@ -226,8 +223,8 @@ mod tests {
let data = vec![0x58, 0x6c, 0x1d, 0x3a, 0x33, 0xb, 0xa, 0x14, 0xa3, 0xb2, 0xcc, 0xdd, 0x71, 0x86, 0xf1, 0x68, 0x5f, 0x21, 0xf2, 0x48, 0x2a, 0xf4, 0xfb, 0x34, 0x46, 0xa8, 0x4b, 0x35, 0x10, 0xaa, 0xf7, 0x6, 0x19, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x30, 0x39, 0x20, 0x4, 0x2b, 0x9, 0x0, 0x0, 0x0, 0x0, 0x5a, 0x40, 0x69, 0xb1, 0x15, 0xd, 0xf2, 0x8e, 0x80, 0x4, 0x30, 0x1, 0x3b, 0xa, 0x4, 0x68, 0x61, 0x73, 0x68, 0x13, 0x8, 0x80, 0x89, 0x7a, 0x12, 0xa, 0x70, 0x61, 0x72, 0x74, 0x73, 0x5f, 0x68, 0x61, 0x73, 0x68, 0x4, 0x4, 0x4, 0x4];
match Vote::deserialize(&data) {
- Err(err) => assert!(false, err.description().to_string()),
- Ok(have) => assert_eq!(have, want)
+ Ok(have) => assert_eq!(have, want),
+ Err(err) => assert!(false, err.description().to_string())
}
}
//ToDo Serialization with Signature
