From 41554f433b6a2e3840ae49c4d56accd89d0a1653 Mon Sep 17 00:00:00 2001 From: Greg Fitzgerald Date: Tue, 12 Feb 2019 20:30:29 -0700 Subject: [PATCH] Fix VoteTransaction::get_votes() --- sdk/src/vote_transaction.rs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/sdk/src/vote_transaction.rs b/sdk/src/vote_transaction.rs index 420743daed..f2435c515f 100644 --- a/sdk/src/vote_transaction.rs +++ b/sdk/src/vote_transaction.rs @@ -60,7 +60,7 @@ impl VoteTransaction { for i in 0..tx.instructions.len() { let tx_program_id = tx.program_id(i); if vote_program::check_id(&tx_program_id) { - if let Ok(Some(VoteInstruction::Vote(vote))) = deserialize(&tx.userdata(i)) { + if let Ok(VoteInstruction::Vote(vote)) = deserialize(&tx.userdata(i)) { votes.push((tx.account_keys[0], vote, tx.last_id)) } } @@ -68,3 +68,20 @@ impl VoteTransaction { votes } } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_get_votes() { + let keypair = Keypair::new(); + let tick_height = 1; + let last_id = Hash::default(); + let transaction = VoteTransaction::new_vote(&keypair, tick_height, last_id, 0); + assert_eq!( + VoteTransaction::get_votes(&transaction), + vec![(keypair.pubkey(), Vote::new(tick_height), last_id)] + ); + } +}