Add tests for the Debug and activation Vecs (#11926)

* Add tests for the Debug and activation Vecs

* Rename a bit
This commit is contained in:
Ryo Onodera
2020-09-01 17:48:25 +09:00
committed by GitHub
parent 07ecb56753
commit 11ac4eb21d
4 changed files with 79 additions and 12 deletions

View File

@ -8242,7 +8242,7 @@ mod tests {
_ka: &[KeyedAccount],
_data: &[u8],
) -> std::result::Result<(), InstructionError> {
Err(InstructionError::Custom(42))
Ok(())
}
let slot = 123;
@ -8281,7 +8281,7 @@ mod tests {
_data: &[u8],
_context: &mut dyn solana_sdk::entrypoint_native::InvokeContext,
) -> std::result::Result<(), InstructionError> {
Err(InstructionError::Custom(42))
Ok(())
}
let slot = 123;

View File

@ -75,9 +75,29 @@ mod tests {
pubkey::Pubkey,
};
use std::collections::HashSet;
use std::str::FromStr;
use std::sync::Arc;
fn do_test_uniqueness(builtins: Vec<(Builtin, Epoch)>) {
let mut unique_ids = HashSet::new();
let mut unique_names = HashSet::new();
let mut prev_start_epoch = 0;
for (builtin, next_start_epoch) in builtins {
assert!(next_start_epoch >= prev_start_epoch);
assert!(unique_ids.insert(builtin.name));
assert!(unique_names.insert(builtin.id));
prev_start_epoch = next_start_epoch;
}
}
#[test]
fn test_uniqueness() {
do_test_uniqueness(get_builtins(OperatingMode::Development));
do_test_uniqueness(get_builtins(OperatingMode::Preview));
do_test_uniqueness(get_builtins(OperatingMode::Stable));
}
#[test]
fn test_get_builtins() {
let (mut genesis_config, _mint_keypair) = create_genesis_config(100_000);

View File

@ -300,6 +300,7 @@ impl std::fmt::Debug for MessageProcessor {
loaders: Vec<String>,
native_loader: &'a NativeLoader,
is_cross_program_supported: bool,
compute_budget: ComputeBudget,
}
// rustc doesn't compile due to bug without this work around
// https://github.com/rust-lang/rust/issues/50280
@ -323,6 +324,7 @@ impl std::fmt::Debug for MessageProcessor {
.collect::<Vec<_>>(),
native_loader: &self.native_loader,
is_cross_program_supported: self.is_cross_program_supported,
compute_budget: self.compute_budget,
};
write!(f, "{:?}", processor)
@ -1554,4 +1556,29 @@ mod tests {
);
}
}
#[test]
fn test_debug() {
let mut message_processor = MessageProcessor::default();
fn mock_process_instruction(
_program_id: &Pubkey,
_keyed_accounts: &[KeyedAccount],
_data: &[u8],
) -> Result<(), InstructionError> {
Ok(())
}
fn mock_ix_processor(
_pubkey: &Pubkey,
_ka: &[KeyedAccount],
_data: &[u8],
_context: &mut dyn solana_sdk::entrypoint_native::InvokeContext,
) -> std::result::Result<(), InstructionError> {
Ok(())
}
let program_id = Pubkey::new_rand();
message_processor.add_program(program_id, mock_process_instruction);
message_processor.add_loader(program_id, mock_ix_processor);
assert!(!format!("{:?}", message_processor).is_empty());
}
}