Skip to content
This repository was archived by the owner on Jan 22, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 30 additions & 10 deletions genesis-programs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ impl std::fmt::Debug for Program {
}
}

// given operating_mode and epoch, return the entire set of enabled programs
// given operating_mode, return the entire set of enabled programs
fn get_programs(operating_mode: OperatingMode) -> Vec<(Program, Epoch)> {
match operating_mode {
OperatingMode::Development => vec![
Expand All @@ -82,13 +82,13 @@ fn get_programs(operating_mode: OperatingMode) -> Vec<(Program, Epoch)> {
Program::Native(solana_exchange_program!()),
]
.into_iter()
.map(|program| (program, 0))
.map(|program| (program, GENESIS_EPOCH))
.collect::<Vec<_>>(),

OperatingMode::Preview => vec![
(
Program::BuiltinLoader(solana_bpf_loader_deprecated_program!()),
0,
GENESIS_EPOCH,
),
(Program::BuiltinLoader(solana_bpf_loader_program!()), 89),
],
Expand Down Expand Up @@ -163,18 +163,33 @@ mod tests {
use super::*;
use std::collections::HashSet;

#[test]
fn test_id_uniqueness() {
let mut unique = HashSet::new();
let programs = get_programs(OperatingMode::Development);
for (program, _start_epoch) in programs {
fn do_test_uniqueness(programs: Vec<(Program, Epoch)>) {
let mut unique_ids = HashSet::new();
let mut unique_names = HashSet::new();
let mut prev_start_epoch = GENESIS_EPOCH;
for (program, next_start_epoch) in programs {
assert!(next_start_epoch >= prev_start_epoch);
match program {
Program::Native((name, id)) => assert!(unique.insert((name, id))),
Program::BuiltinLoader((name, id, _)) => assert!(unique.insert((name, id))),
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, we must require the uniqueness separately both for name and id, not for the tuple of (name, id).

Program::Native((name, id)) => {
assert!(unique_ids.insert(id));
assert!(unique_names.insert(name));
}
Program::BuiltinLoader((name, id, _)) => {
assert!(unique_ids.insert(id));
assert!(unique_names.insert(name));
}
}
prev_start_epoch = next_start_epoch;
}
}

#[test]
fn test_uniqueness() {
do_test_uniqueness(get_programs(OperatingMode::Development));
do_test_uniqueness(get_programs(OperatingMode::Preview));
do_test_uniqueness(get_programs(OperatingMode::Stable));
}

#[test]
fn test_development_inflation() {
assert_eq!(
Expand Down Expand Up @@ -214,4 +229,9 @@ mod tests {
fn test_softlaunch_programs() {
assert!(!get_programs(OperatingMode::Stable).is_empty());
}

#[test]
fn test_debug() {
assert!(!format!("{:?}", get_programs(OperatingMode::Development)).is_empty());
}
}
4 changes: 2 additions & 2 deletions runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8242,7 +8242,7 @@ mod tests {
_ka: &[KeyedAccount],
_data: &[u8],
) -> std::result::Result<(), InstructionError> {
Err(InstructionError::Custom(42))
Ok(())
}

let slot = 123;
Expand Down Expand Up @@ -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;
Expand Down
20 changes: 20 additions & 0 deletions runtime/src/builtins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
27 changes: 27 additions & 0 deletions runtime/src/message_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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());
}
}