From 617aaf79996ac5874543cce02a4ab6b4fad250fb Mon Sep 17 00:00:00 2001 From: Andrew Fitzgerald Date: Thu, 7 Nov 2024 14:34:55 -0600 Subject: [PATCH] transition tests --- .../runtime_transaction/transaction_view.rs | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/runtime-transaction/src/runtime_transaction/transaction_view.rs b/runtime-transaction/src/runtime_transaction/transaction_view.rs index 8c4ae4a781ba29..dfeb54037018fc 100644 --- a/runtime-transaction/src/runtime_transaction/transaction_view.rs +++ b/runtime-transaction/src/runtime_transaction/transaction_view.rs @@ -90,3 +90,61 @@ impl RuntimeTransaction> { Ok(()) } } + +#[cfg(test)] +mod tests { + use { + crate::{runtime_transaction::RuntimeTransaction, transaction_meta::StaticMeta}, + agave_transaction_view::{ + resolved_transaction_view::ResolvedTransactionView, + transaction_view::SanitizedTransactionView, + }, + solana_pubkey::Pubkey, + solana_sdk::{ + hash::Hash, + reserved_account_keys::ReservedAccountKeys, + signature::Keypair, + system_transaction, + transaction::{MessageHash, VersionedTransaction}, + }, + }; + + #[test] + fn test_advancing_transaction_type() { + // Create serialized simple transfer. + let serialized_transaction = { + let transaction = VersionedTransaction::from(system_transaction::transfer( + &Keypair::new(), + &Pubkey::new_unique(), + 1, + Hash::new_unique(), + )); + bincode::serialize(&transaction).unwrap() + }; + + let hash = Hash::new_unique(); + let transaction = + SanitizedTransactionView::try_new_sanitized(&serialized_transaction[..]).unwrap(); + let static_runtime_transaction = + RuntimeTransaction::>::try_from( + transaction, + MessageHash::Precomputed(hash), + None, + ) + .unwrap(); + + assert_eq!(hash, *static_runtime_transaction.message_hash()); + assert!(!static_runtime_transaction.is_simple_vote_transaction()); + + let dynamic_runtime_transaction = + RuntimeTransaction::>::try_from( + static_runtime_transaction, + None, + &ReservedAccountKeys::empty_key_set(), + ) + .unwrap(); + + assert_eq!(hash, *dynamic_runtime_transaction.message_hash()); + assert!(!dynamic_runtime_transaction.is_simple_vote_transaction()); + } +}