Clean up sanitized tx creation for tests (#21006)
This commit is contained in:
@ -163,16 +163,11 @@ mod tests {
|
||||
hash::Hash, message::Message, pubkey::Pubkey, signature::Keypair, signer::Signer,
|
||||
transaction::Transaction,
|
||||
};
|
||||
use std::convert::TryInto;
|
||||
|
||||
fn sanitize_tx(tx: Transaction) -> SanitizedTransaction {
|
||||
tx.try_into().unwrap()
|
||||
}
|
||||
|
||||
macro_rules! test {
|
||||
( $instructions: expr, $expected_error: expr, $expected_budget: expr ) => {
|
||||
let payer_keypair = Keypair::new();
|
||||
let tx = sanitize_tx(Transaction::new(
|
||||
let tx = SanitizedTransaction::from_transaction_for_tests(Transaction::new(
|
||||
&[&payer_keypair],
|
||||
Message::new($instructions, Some(&payer_keypair.pubkey())),
|
||||
Hash::default(),
|
||||
|
@ -14,7 +14,6 @@ use {
|
||||
transaction::{Result, Transaction, TransactionError, VersionedTransaction},
|
||||
},
|
||||
solana_program::{system_instruction::SystemInstruction, system_program},
|
||||
std::convert::TryFrom,
|
||||
std::sync::Arc,
|
||||
};
|
||||
|
||||
@ -35,23 +34,6 @@ pub struct TransactionAccountLocks<'a> {
|
||||
pub writable: Vec<&'a Pubkey>,
|
||||
}
|
||||
|
||||
impl TryFrom<Transaction> for SanitizedTransaction {
|
||||
type Error = TransactionError;
|
||||
fn try_from(tx: Transaction) -> Result<Self> {
|
||||
tx.sanitize()?;
|
||||
|
||||
if tx.message.has_duplicates() {
|
||||
return Err(TransactionError::AccountLoadedTwice);
|
||||
}
|
||||
|
||||
Ok(Self {
|
||||
message_hash: tx.message.hash(),
|
||||
message: SanitizedMessage::Legacy(tx.message),
|
||||
signatures: tx.signatures,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl SanitizedTransaction {
|
||||
/// Create a sanitized transaction from an unsanitized transaction.
|
||||
/// If the input transaction uses address maps, attempt to map the
|
||||
@ -83,6 +65,21 @@ impl SanitizedTransaction {
|
||||
})
|
||||
}
|
||||
|
||||
/// Create a sanitized transaction from a legacy transaction. Used for tests only.
|
||||
pub fn from_transaction_for_tests(tx: Transaction) -> Self {
|
||||
tx.sanitize().unwrap();
|
||||
|
||||
if tx.message.has_duplicates() {
|
||||
Result::<Self>::Err(TransactionError::AccountLoadedTwice).unwrap();
|
||||
}
|
||||
|
||||
Self {
|
||||
message_hash: tx.message.hash(),
|
||||
message: SanitizedMessage::Legacy(tx.message),
|
||||
signatures: tx.signatures,
|
||||
}
|
||||
}
|
||||
|
||||
/// Return the first signature for this transaction.
|
||||
///
|
||||
/// Notes:
|
||||
|
Reference in New Issue
Block a user