Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarify TargetProgramBuiltin code docs #403

Merged
merged 2 commits into from
Mar 22, 2024
Merged
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
25 changes: 13 additions & 12 deletions runtime/src/bank/builtins/core_bpf_migration/target_builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use {
},
};

/// Used to validate a built-in program's account before migrating to Core BPF.
/// The account details of a built-in program to be migrated to Core BPF.
#[derive(Debug)]
pub(crate) struct TargetProgramBuiltin {
pub program_address: Pubkey,
Expand All @@ -19,7 +19,8 @@ pub(crate) struct TargetProgramBuiltin {
}

impl TargetProgramBuiltin {
/// Create a new migration configuration for a built-in program.
/// Collects the details of a built-in program and verifies it is properly
/// configured
pub(crate) fn new_checked(
bank: &Bank,
program_address: &Pubkey,
Expand Down Expand Up @@ -143,12 +144,12 @@ mod tests {
let program_data_address = get_program_data_address(&program_address);

// Success
let builtin_config =
let target_builtin =
TargetProgramBuiltin::new_checked(&bank, &program_address, &migration_target).unwrap();
assert_eq!(builtin_config.program_address, program_address);
assert_eq!(builtin_config.program_account, program_account);
assert_eq!(builtin_config.program_data_address, program_data_address);
assert_eq!(builtin_config.total_data_size, program_account.data().len());
assert_eq!(target_builtin.program_address, program_address);
assert_eq!(target_builtin.program_account, program_account);
assert_eq!(target_builtin.program_data_address, program_data_address);
assert_eq!(target_builtin.total_data_size, program_account.data().len());

// Fail if the program account is not owned by the native loader
store_account(
Expand Down Expand Up @@ -210,12 +211,12 @@ mod tests {
let program_data_address = get_program_data_address(&program_address);

// Success
let builtin_config =
let target_builtin =
TargetProgramBuiltin::new_checked(&bank, &program_address, &migration_target).unwrap();
assert_eq!(builtin_config.program_address, program_address);
assert_eq!(builtin_config.program_account, program_account);
assert_eq!(builtin_config.program_data_address, program_data_address);
assert_eq!(builtin_config.total_data_size, program_account.data().len());
assert_eq!(target_builtin.program_address, program_address);
assert_eq!(target_builtin.program_account, program_account);
assert_eq!(target_builtin.program_data_address, program_data_address);
assert_eq!(target_builtin.total_data_size, program_account.data().len());

// Fail if the program data account exists
store_account(
Expand Down
Loading