Skip to content

Commit

Permalink
Plumb through tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jstarry committed Apr 2, 2024
1 parent 330a98b commit 16c5927
Show file tree
Hide file tree
Showing 24 changed files with 188 additions and 89 deletions.
2 changes: 2 additions & 0 deletions core/src/banking_stage/consumer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -868,6 +868,7 @@ mod tests {
nonce_account::verify_nonce_account,
poh_config::PohConfig,
pubkey::Pubkey,
reserved_account_keys::ReservedAccountKeys,
signature::Keypair,
signer::Signer,
system_instruction, system_program, system_transaction,
Expand Down Expand Up @@ -2035,6 +2036,7 @@ mod tests {
MessageHash::Compute,
Some(false),
bank.as_ref(),
&ReservedAccountKeys::empty_key_set(),
)
.unwrap();

Expand Down
1 change: 1 addition & 0 deletions core/src/banking_stage/read_write_account_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ mod tests {
MessageHash::Compute,
Some(false),
bank,
bank.get_reserved_account_keys(),
)
.unwrap()
}
Expand Down
7 changes: 7 additions & 0 deletions core/src/banking_stage/unprocessed_packet_batches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ mod tests {
solana_sdk::{
compute_budget::ComputeBudgetInstruction,
message::Message,
reserved_account_keys::ReservedAccountKeys,
signature::{Keypair, Signer},
system_instruction, system_transaction,
transaction::{SimpleAddressLoader, Transaction},
Expand Down Expand Up @@ -490,6 +491,7 @@ mod tests {
&Arc::new(FeatureSet::default()),
votes_only,
SimpleAddressLoader::Disabled,
&ReservedAccountKeys::empty_key_set(),
)
});
assert_eq!(2, txs.count());
Expand All @@ -500,6 +502,7 @@ mod tests {
&Arc::new(FeatureSet::default()),
votes_only,
SimpleAddressLoader::Disabled,
&ReservedAccountKeys::empty_key_set(),
)
});
assert_eq!(0, txs.count());
Expand All @@ -519,6 +522,7 @@ mod tests {
&Arc::new(FeatureSet::default()),
votes_only,
SimpleAddressLoader::Disabled,
&ReservedAccountKeys::empty_key_set(),
)
});
assert_eq!(3, txs.count());
Expand All @@ -529,6 +533,7 @@ mod tests {
&Arc::new(FeatureSet::default()),
votes_only,
SimpleAddressLoader::Disabled,
&ReservedAccountKeys::empty_key_set(),
)
});
assert_eq!(2, txs.count());
Expand All @@ -548,6 +553,7 @@ mod tests {
&Arc::new(FeatureSet::default()),
votes_only,
SimpleAddressLoader::Disabled,
&ReservedAccountKeys::empty_key_set(),
)
});
assert_eq!(3, txs.count());
Expand All @@ -558,6 +564,7 @@ mod tests {
&Arc::new(FeatureSet::default()),
votes_only,
SimpleAddressLoader::Disabled,
&ReservedAccountKeys::empty_key_set(),
)
});
assert_eq!(3, txs.count());
Expand Down
2 changes: 2 additions & 0 deletions cost-model/src/cost_tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ mod tests {
crate::transaction_cost::*,
solana_sdk::{
hash::Hash,
reserved_account_keys::ReservedAccountKeys,
signature::{Keypair, Signer},
system_transaction,
transaction::{
Expand Down Expand Up @@ -401,6 +402,7 @@ mod tests {
MessageHash::Compute,
Some(true),
SimpleAddressLoader::Disabled,
&ReservedAccountKeys::empty_key_set(),
)
.unwrap();

Expand Down
3 changes: 3 additions & 0 deletions cost-model/src/transaction_cost.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ mod tests {
feature_set::FeatureSet,
hash::Hash,
message::SimpleAddressLoader,
reserved_account_keys::ReservedAccountKeys,
signer::keypair::Keypair,
transaction::{MessageHash, SanitizedTransaction, VersionedTransaction},
},
Expand Down Expand Up @@ -231,6 +232,7 @@ mod tests {
MessageHash::Compute,
Some(true),
SimpleAddressLoader::Disabled,
&ReservedAccountKeys::empty_key_set(),
)
.unwrap();

Expand All @@ -240,6 +242,7 @@ mod tests {
MessageHash::Compute,
Some(false),
SimpleAddressLoader::Disabled,
&ReservedAccountKeys::empty_key_set(),
)
.unwrap();

Expand Down
3 changes: 3 additions & 0 deletions entry/benches/entry_sigverify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use {
solana_perf::test_tx::test_tx,
solana_sdk::{
hash::Hash,
reserved_account_keys::ReservedAccountKeys,
transaction::{
Result, SanitizedTransaction, SimpleAddressLoader, TransactionVerificationMode,
VersionedTransaction,
Expand Down Expand Up @@ -41,6 +42,7 @@ fn bench_gpusigverify(bencher: &mut Bencher) {
message_hash,
None,
SimpleAddressLoader::Disabled,
&ReservedAccountKeys::empty_key_set(),
)
}?;

Expand Down Expand Up @@ -84,6 +86,7 @@ fn bench_cpusigverify(bencher: &mut Bencher) {
message_hash,
None,
SimpleAddressLoader::Disabled,
&ReservedAccountKeys::empty_key_set(),
)
}?;

Expand Down
2 changes: 2 additions & 0 deletions entry/src/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -982,6 +982,7 @@ mod tests {
solana_sdk::{
hash::{hash, Hash},
pubkey::Pubkey,
reserved_account_keys::ReservedAccountKeys,
signature::{Keypair, Signer},
system_transaction,
transaction::{
Expand Down Expand Up @@ -1084,6 +1085,7 @@ mod tests {
message_hash,
None,
SimpleAddressLoader::Disabled,
&ReservedAccountKeys::empty_key_set(),
)
}?;

Expand Down
4 changes: 3 additions & 1 deletion program-runtime/src/message_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ mod tests {
native_loader::{self, create_loadable_account_for_test},
pubkey::Pubkey,
rent::Rent,
reserved_account_keys::ReservedAccountKeys,
secp256k1_instruction::new_secp256k1_instruction,
secp256k1_program, system_program,
transaction_context::TransactionContext,
Expand All @@ -179,7 +180,8 @@ mod tests {
}

fn new_sanitized_message(message: Message) -> SanitizedMessage {
SanitizedMessage::try_from_legacy_message(message).unwrap()
SanitizedMessage::try_from_legacy_message(message, &ReservedAccountKeys::empty_key_set())
.unwrap()
}

#[test]
Expand Down
19 changes: 16 additions & 3 deletions programs/sbf/tests/programs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ use {
message::Message,
pubkey::Pubkey,
rent::Rent,
reserved_account_keys::ReservedAccountKeys,
signature::{Keypair, Signer},
system_program,
transaction::{SanitizedTransaction, Transaction, TransactionError},
Expand Down Expand Up @@ -201,7 +202,11 @@ fn execute_transactions(
}
.expect("lamports_per_signature must be available");
let fee = bank.get_fee_for_message_with_lamports_per_signature(
&SanitizedMessage::try_from_legacy_message(tx.message().clone()).unwrap(),
&SanitizedMessage::try_from_legacy_message(
tx.message().clone(),
&ReservedAccountKeys::empty_key_set(),
)
.unwrap(),
lamports_per_signature,
);

Expand Down Expand Up @@ -3706,7 +3711,11 @@ fn test_program_fees() {
Some(&mint_keypair.pubkey()),
);

let sanitized_message = SanitizedMessage::try_from_legacy_message(message.clone()).unwrap();
let sanitized_message = SanitizedMessage::try_from_legacy_message(
message.clone(),
&ReservedAccountKeys::empty_key_set(),
)
.unwrap();
let expected_normal_fee = fee_structure.calculate_fee(
&sanitized_message,
congestion_multiplier,
Expand All @@ -3730,7 +3739,11 @@ fn test_program_fees() {
],
Some(&mint_keypair.pubkey()),
);
let sanitized_message = SanitizedMessage::try_from_legacy_message(message.clone()).unwrap();
let sanitized_message = SanitizedMessage::try_from_legacy_message(
message.clone(),
&ReservedAccountKeys::empty_key_set(),
)
.unwrap();
let expected_prioritized_fee = fee_structure.calculate_fee(
&sanitized_message,
congestion_multiplier,
Expand Down
16 changes: 13 additions & 3 deletions rpc/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4771,6 +4771,7 @@ pub mod tests {
Message, MessageHeader, VersionedMessage,
},
nonce::{self, state::DurableNonce},
reserved_account_keys::ReservedAccountKeys,
rpc_port,
signature::{Keypair, Signer},
slot_hashes::SlotHashes,
Expand Down Expand Up @@ -9032,8 +9033,12 @@ pub mod tests {
.to_string(),
);
assert_eq!(
sanitize_transaction(unsanitary_versioned_tx, SimpleAddressLoader::Disabled)
.unwrap_err(),
sanitize_transaction(
unsanitary_versioned_tx,
SimpleAddressLoader::Disabled,
&ReservedAccountKeys::empty_key_set()
)
.unwrap_err(),
expect58
);
}
Expand All @@ -9053,7 +9058,12 @@ pub mod tests {
};

assert_eq!(
sanitize_transaction(versioned_tx, SimpleAddressLoader::Disabled).unwrap_err(),
sanitize_transaction(
versioned_tx,
SimpleAddressLoader::Disabled,
&ReservedAccountKeys::empty_key_set()
)
.unwrap_err(),
Error::invalid_params(
"invalid transaction: Transaction version is unsupported".to_string(),
)
Expand Down
7 changes: 6 additions & 1 deletion rpc/src/transaction_status_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ pub(crate) mod tests {
nonce_info::{NonceFull, NoncePartial},
pubkey::Pubkey,
rent_debits::RentDebits,
reserved_account_keys::ReservedAccountKeys,
signature::{Keypair, Signature, Signer},
system_transaction,
transaction::{
Expand Down Expand Up @@ -335,6 +336,7 @@ pub(crate) mod tests {
MessageHash::Compute,
None,
SimpleAddressLoader::Disabled,
&ReservedAccountKeys::empty_key_set(),
)
.unwrap();

Expand Down Expand Up @@ -364,7 +366,10 @@ pub(crate) mod tests {
durable_nonce_fee: Some(DurableNonceFee::from(
&NonceFull::from_partial(
&rollback_partial,
&SanitizedMessage::Legacy(LegacyMessage::new(message)),
&SanitizedMessage::Legacy(LegacyMessage::new(
message,
&ReservedAccountKeys::empty_key_set(),
)),
&[(pubkey, nonce_account)],
&rent_debits,
)
Expand Down
2 changes: 2 additions & 0 deletions runtime-transaction/src/runtime_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ mod tests {
compute_budget::ComputeBudgetInstruction,
instruction::Instruction,
message::Message,
reserved_account_keys::ReservedAccountKeys,
signer::{keypair::Keypair, Signer},
transaction::{SimpleAddressLoader, Transaction, VersionedTransaction},
},
Expand Down Expand Up @@ -260,6 +261,7 @@ mod tests {
let dynamically_loaded_transaction = RuntimeTransaction::<SanitizedMessage>::try_from(
statically_loaded_transaction,
SimpleAddressLoader::Disabled,
&ReservedAccountKeys::empty_key_set(),
);
let dynamically_loaded_transaction =
dynamically_loaded_transaction.expect("created from statically loaded tx");
Expand Down
25 changes: 13 additions & 12 deletions sdk/benches/serialize_instructions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use {
instruction::{AccountMeta, Instruction},
message::{Message, SanitizedMessage},
pubkey::{self, Pubkey},
reserved_account_keys::ReservedAccountKeys,
sysvar::instructions::{self, construct_instructions_data},
},
test::Bencher,
Expand All @@ -29,10 +30,10 @@ fn bench_bincode_instruction_serialize(b: &mut Bencher) {
#[bench]
fn bench_construct_instructions_data(b: &mut Bencher) {
let instructions = make_instructions();
let message = SanitizedMessage::try_from_legacy_message(Message::new(
&instructions,
Some(&Pubkey::new_unique()),
))
let message = SanitizedMessage::try_from_legacy_message(
Message::new(&instructions, Some(&Pubkey::new_unique())),
&ReservedAccountKeys::empty_key_set(),
)
.unwrap();
b.iter(|| {
let instructions = message.decompile_instructions();
Expand All @@ -52,10 +53,10 @@ fn bench_bincode_instruction_deserialize(b: &mut Bencher) {
#[bench]
fn bench_manual_instruction_deserialize(b: &mut Bencher) {
let instructions = make_instructions();
let message = SanitizedMessage::try_from_legacy_message(Message::new(
&instructions,
Some(&Pubkey::new_unique()),
))
let message = SanitizedMessage::try_from_legacy_message(
Message::new(&instructions, Some(&Pubkey::new_unique())),
&ReservedAccountKeys::empty_key_set(),
)
.unwrap();
let serialized = construct_instructions_data(&message.decompile_instructions());
b.iter(|| {
Expand All @@ -69,10 +70,10 @@ fn bench_manual_instruction_deserialize(b: &mut Bencher) {
#[bench]
fn bench_manual_instruction_deserialize_single(b: &mut Bencher) {
let instructions = make_instructions();
let message = SanitizedMessage::try_from_legacy_message(Message::new(
&instructions,
Some(&Pubkey::new_unique()),
))
let message = SanitizedMessage::try_from_legacy_message(
Message::new(&instructions, Some(&Pubkey::new_unique())),
&ReservedAccountKeys::empty_key_set(),
)
.unwrap();
let serialized = construct_instructions_data(&message.decompile_instructions());
b.iter(|| {
Expand Down
16 changes: 9 additions & 7 deletions sdk/program/src/message/legacy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -770,12 +770,14 @@ mod tests {
recent_blockhash: Hash::default(),
instructions: vec![],
};
assert!(message.is_writable(0));
assert!(!message.is_writable(1));
assert!(!message.is_writable(2));
assert!(message.is_writable(3));
assert!(message.is_writable(4));
assert!(!message.is_writable(5));

let reserved_keys = HashSet::from_iter([key2, key3]);
assert!(message.is_writable(0, &reserved_keys));
assert!(!message.is_writable(1, &reserved_keys));
assert!(!message.is_writable(2, &reserved_keys));
assert!(!message.is_writable(3, &reserved_keys));
assert!(message.is_writable(4, &reserved_keys));
assert!(!message.is_writable(5, &reserved_keys));
}

#[test]
Expand Down Expand Up @@ -803,7 +805,7 @@ mod tests {
Some(&id1),
);
assert_eq!(
message.get_account_keys_by_lock_type(),
message.get_account_keys_by_lock_type(&HashSet::default()),
(vec![&id1, &id0], vec![&id3, &program_id, &id2])
);
}
Expand Down
Loading

0 comments on commit 16c5927

Please sign in to comment.