parent
935e06f8f1
commit
c3323c0c36
|
@ -7074,6 +7074,7 @@ dependencies = [
|
||||||
"log",
|
"log",
|
||||||
"rand 0.8.5",
|
"rand 0.8.5",
|
||||||
"rustc_version 0.4.0",
|
"rustc_version 0.4.0",
|
||||||
|
"solana-program",
|
||||||
"solana-program-runtime",
|
"solana-program-runtime",
|
||||||
"solana-sdk",
|
"solana-sdk",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
|
|
|
@ -22,6 +22,7 @@ name = "solana_runtime_transaction"
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
bincode = { workspace = true }
|
bincode = { workspace = true }
|
||||||
rand = { workspace = true }
|
rand = { workspace = true }
|
||||||
|
solana-program ={ workspace = true }
|
||||||
|
|
||||||
[package.metadata.docs.rs]
|
[package.metadata.docs.rs]
|
||||||
targets = ["x86_64-unknown-linux-gnu"]
|
targets = ["x86_64-unknown-linux-gnu"]
|
||||||
|
|
|
@ -106,3 +106,113 @@ impl RuntimeTransactionDynamic {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use {
|
||||||
|
super::*,
|
||||||
|
solana_program::{
|
||||||
|
system_instruction,
|
||||||
|
vote::{self, state::Vote},
|
||||||
|
},
|
||||||
|
solana_sdk::{
|
||||||
|
compute_budget::ComputeBudgetInstruction,
|
||||||
|
message::Message,
|
||||||
|
signer::{keypair::Keypair, Signer},
|
||||||
|
transaction::{Transaction, VersionedTransaction},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
fn vote_sanitized_versioned_transaction() -> SanitizedVersionedTransaction {
|
||||||
|
let bank_hash = Hash::new_unique();
|
||||||
|
let block_hash = Hash::new_unique();
|
||||||
|
let vote_keypair = Keypair::new();
|
||||||
|
let node_keypair = Keypair::new();
|
||||||
|
let auth_keypair = Keypair::new();
|
||||||
|
let votes = Vote::new(vec![1, 2, 3], bank_hash);
|
||||||
|
let vote_ix =
|
||||||
|
vote::instruction::vote(&vote_keypair.pubkey(), &auth_keypair.pubkey(), votes);
|
||||||
|
let mut vote_tx = Transaction::new_with_payer(&[vote_ix], Some(&node_keypair.pubkey()));
|
||||||
|
vote_tx.partial_sign(&[&node_keypair], block_hash);
|
||||||
|
vote_tx.partial_sign(&[&auth_keypair], block_hash);
|
||||||
|
|
||||||
|
SanitizedVersionedTransaction::try_from(VersionedTransaction::from(vote_tx)).unwrap()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn non_vote_sanitized_versioned_transaction(
|
||||||
|
compute_unit_price: u64,
|
||||||
|
) -> SanitizedVersionedTransaction {
|
||||||
|
let from_keypair = Keypair::new();
|
||||||
|
let ixs = vec![
|
||||||
|
system_instruction::transfer(
|
||||||
|
&from_keypair.pubkey(),
|
||||||
|
&solana_sdk::pubkey::new_rand(),
|
||||||
|
1,
|
||||||
|
),
|
||||||
|
ComputeBudgetInstruction::set_compute_unit_price(compute_unit_price),
|
||||||
|
];
|
||||||
|
let message = Message::new(&ixs, Some(&from_keypair.pubkey()));
|
||||||
|
let tx = Transaction::new(&[&from_keypair], message, Hash::new_unique());
|
||||||
|
SanitizedVersionedTransaction::try_from(VersionedTransaction::from(tx)).unwrap()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_transaction_meta(
|
||||||
|
svt: SanitizedVersionedTransaction,
|
||||||
|
hash: Option<Hash>,
|
||||||
|
is_simple_vote: Option<bool>,
|
||||||
|
) -> TransactionMeta {
|
||||||
|
RuntimeTransactionStatic::try_from(svt, hash, is_simple_vote)
|
||||||
|
.unwrap()
|
||||||
|
.meta
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_new_runtime_transaction_static() {
|
||||||
|
let hash = Hash::new_unique();
|
||||||
|
let compute_unit_price = 1_000;
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
TransactionMeta {
|
||||||
|
message_hash: hash,
|
||||||
|
is_simple_vote_tx: false,
|
||||||
|
},
|
||||||
|
get_transaction_meta(
|
||||||
|
non_vote_sanitized_versioned_transaction(compute_unit_price),
|
||||||
|
Some(hash),
|
||||||
|
None
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
TransactionMeta {
|
||||||
|
message_hash: hash,
|
||||||
|
is_simple_vote_tx: true,
|
||||||
|
},
|
||||||
|
get_transaction_meta(
|
||||||
|
non_vote_sanitized_versioned_transaction(compute_unit_price),
|
||||||
|
Some(hash),
|
||||||
|
Some(true), // override
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
TransactionMeta {
|
||||||
|
message_hash: hash,
|
||||||
|
is_simple_vote_tx: true,
|
||||||
|
},
|
||||||
|
get_transaction_meta(vote_sanitized_versioned_transaction(), Some(hash), None)
|
||||||
|
);
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
TransactionMeta {
|
||||||
|
message_hash: hash,
|
||||||
|
is_simple_vote_tx: false,
|
||||||
|
},
|
||||||
|
get_transaction_meta(
|
||||||
|
vote_sanitized_versioned_transaction(),
|
||||||
|
Some(hash),
|
||||||
|
Some(false), // override
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue