Skip to content
This repository has been archived by the owner on Jan 22, 2025. It is now read-only.

Commit

Permalink
test-validator: use ADDRESS from account flag
Browse files Browse the repository at this point in the history
  • Loading branch information
skrrb authored and mvines committed Jul 14, 2022
1 parent 27cee7a commit 4f71ae6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
7 changes: 5 additions & 2 deletions test-validator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ use {

#[derive(Clone)]
pub struct AccountInfo<'a> {
pub address: Pubkey,
pub address: Option<Pubkey>,
pub filename: &'a str,
}

Expand Down Expand Up @@ -319,7 +319,10 @@ impl TestValidatorGenesis {
}
Ok(deserialized) => deserialized,
};
let address = Pubkey::from_str(account_info.keyed_account.pubkey.as_str()).unwrap();

let address = account.address.unwrap_or_else(|| {
Pubkey::from_str(account_info.keyed_account.pubkey.as_str()).unwrap()
});
let account = account_info
.keyed_account
.account
Expand Down
14 changes: 10 additions & 4 deletions validator/src/bin/solana-test-validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,12 @@ fn main() {
.value_name("ADDRESS FILENAME.JSON")
.takes_value(true)
.number_of_values(2)
.allow_hyphen_values(true)
.multiple(true)
.help(
"Load an account from the provided JSON file (see `solana account --help` on how to dump \
an account to file). Files are searched for relatively to CWD and tests/fixtures. \
If ADDRESS is omitted via the `-` placeholder, the one in the file will be used. \
If the ledger already exists then this parameter is silently ignored",
),
)
Expand Down Expand Up @@ -549,10 +551,14 @@ fn main() {
for address_filename in values.chunks(2) {
match address_filename {
[address, filename] => {
let address = address.parse::<Pubkey>().unwrap_or_else(|err| {
println!("Error: invalid address {}: {}", address, err);
exit(1);
});
let address = if *address == "-" {
None
} else {
Some(address.parse::<Pubkey>().unwrap_or_else(|err| {
println!("Error: invalid address {}: {}", address, err);
exit(1);
}))
};

accounts_to_load.push(AccountInfo { address, filename });
}
Expand Down

0 comments on commit 4f71ae6

Please sign in to comment.