Skip to content

Commit

Permalink
Plumb --upgradeable-program for solana-test-validator
Browse files Browse the repository at this point in the history
  • Loading branch information
CriesofCarrots committed Feb 20, 2023
1 parent 44746e9 commit a88c550
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
51 changes: 51 additions & 0 deletions validator/src/bin/solana-test-validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,56 @@ fn main() {
}
}

let mut upgradeable_programs_to_load = vec![];
if let Some(values) = matches.values_of("upgradeable_program") {
let values: Vec<&str> = values.collect::<Vec<_>>();
for address_program_upgrade_authority in values.chunks(3) {
match address_program_upgrade_authority {
[address, program, upgrade_authority] => {
let address = address
.parse::<Pubkey>()
.or_else(|_| read_keypair_file(address).map(|keypair| keypair.pubkey()))
.unwrap_or_else(|err| {
println!("Error: invalid address {address}: {err}");
exit(1);
});
let upgrade_authority_address = if *upgrade_authority == "none" {
Pubkey::default()
} else {
upgrade_authority
.parse::<Pubkey>()
.or_else(|_| {
read_keypair_file(upgrade_authority).map(|keypair| keypair.pubkey())
})
.unwrap_or_else(|err| {
println!(
"Error: invalid upgrade_authority {upgrade_authority}: {err}"
);
exit(1);
})
};

let program_path = PathBuf::from(program);
if !program_path.exists() {
println!(
"Error: program file does not exist: {}",
program_path.display()
);
exit(1);
}

upgradeable_programs_to_load.push(UpgradeableProgramInfo {
program_id: address,
loader: solana_sdk::bpf_loader_upgradeable::id(),
upgrade_authority: upgrade_authority_address,
program_path,
});
}
_ => unreachable!(),
}
}
}

let mut accounts_to_load = vec![];
if let Some(values) = matches.values_of("account") {
let values: Vec<&str> = values.collect::<Vec<_>>();
Expand Down Expand Up @@ -409,6 +459,7 @@ fn main() {
.bpf_jit(!matches.is_present("no_bpf_jit"))
.rpc_port(rpc_port)
.add_programs_with_path(&programs_to_load)
.add_upgradeable_programs_with_path(&upgradeable_programs_to_load)
.add_accounts_from_json_files(&accounts_to_load)
.unwrap_or_else(|e| {
println!("Error: add_accounts_from_json_files failed: {e}");
Expand Down
13 changes: 13 additions & 0 deletions validator/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2021,6 +2021,19 @@ pub fn test_app<'a>(version: &'a str, default_args: &'a DefaultTestArgs) -> App<
First argument can be a pubkey string or path to a keypair",
),
)
.arg(
Arg::with_name("upgradeable_program")
.long("upgradeable-program")
.value_names(&["ADDRESS_OR_KEYPAIR", "SBF_PROGRAM.SO", "UPGRADE_AUTHORITY"])
.takes_value(true)
.number_of_values(3)
.multiple(true)
.help(
"Add an upgradeable SBF program to the genesis configuration. \
If the ledger already exists then this parameter is silently ignored. \
First argument can be a pubkey string or path to a keypair",
),
)
.arg(
Arg::with_name("account")
.long("account")
Expand Down

0 comments on commit a88c550

Please sign in to comment.