Skip to content

Commit

Permalink
fix clippy warnings, fix minor things
Browse files Browse the repository at this point in the history
  • Loading branch information
norwnd committed Nov 28, 2023
1 parent cf33f32 commit 494e9fd
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 19 deletions.
10 changes: 6 additions & 4 deletions cli/src/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2210,6 +2210,7 @@ fn do_process_program_write_and_deploy(
}
}

#[allow(clippy::too_many_arguments)]
fn do_process_program_upgrade(
rpc_client: Arc<RpcClient>,
config: &CliConfig,
Expand Down Expand Up @@ -2319,11 +2320,9 @@ fn do_process_program_upgrade(
Some(&fee_payer_signer.pubkey()),
&blockhash,
);
let final_message = Some(final_message);

if sign_only {
let message = final_message.expect("no final message for --sign-only mode");
let mut tx = Transaction::new_unsigned(message);
let mut tx = Transaction::new_unsigned(final_message);
let signers = &[fee_payer_signer, upgrade_authority];
// Using try_partial_sign here because fee_payer_signer might not be the fee payer we
// end up using for this transaction (it might be NullSigner).
Expand All @@ -2336,6 +2335,8 @@ fn do_process_program_upgrade(
},
)
} else {
let final_message = Some(final_message);

if !skip_fee_check {
check_payer(
&rpc_client,
Expand Down Expand Up @@ -2470,14 +2471,15 @@ fn check_payer(
}
check_account_for_spend_and_fee_with_commitment(
rpc_client,
&fee_payer_pubkey,
fee_payer_pubkey,
balance_needed,
fee,
config.commitment,
)?;
Ok(())
}

#[allow(clippy::too_many_arguments)]
fn send_deploy_messages(
rpc_client: Arc<RpcClient>,
blockhash_query: &BlockhashQuery,
Expand Down
27 changes: 16 additions & 11 deletions cli/tests/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,19 @@ use {
solana_sdk::{
account_utils::StateMut,
bpf_loader_upgradeable::{self, UpgradeableLoaderState},
clock::Slot,
commitment_config::CommitmentConfig,
pubkey::Pubkey,
signature::{Keypair, NullSigner, Presigner, Signature, Signer},
},
solana_streamer::socket::SocketAddrSpace,
solana_test_validator::TestValidator,
std::{env, fs::File, io::Read, path::PathBuf, str::FromStr},
std::{
env,
fs::File,
io::Read,
path::{Path, PathBuf},
str::FromStr,
},
};

#[test]
Expand Down Expand Up @@ -2183,8 +2188,8 @@ fn test_cli_program_dump() {
}
}

fn fetch_pre_signer(cmd_output_json_str: &String, target_pub_key: &String) -> Presigner {
let json: Value = serde_json::from_str(&cmd_output_json_str).unwrap();
fn fetch_pre_signer(cmd_output_json_str: &str, target_pub_key: &str) -> Presigner {
let json: Value = serde_json::from_str(cmd_output_json_str).unwrap();
let target_pre_signer_str = json
.as_object()
.unwrap()
Expand All @@ -2197,7 +2202,7 @@ fn fetch_pre_signer(cmd_output_json_str: &String, target_pub_key: &String) -> Pr
.unwrap()
.as_str()
.unwrap();
let mut parts = target_pre_signer_str.split("=");
let mut parts = target_pre_signer_str.split('=');
assert_eq!(2, parts.clone().count());
Presigner::new(
&Pubkey::from_str(parts.next().unwrap()).unwrap(),
Expand All @@ -2207,7 +2212,7 @@ fn fetch_pre_signer(cmd_output_json_str: &String, target_pub_key: &String) -> Pr

fn create_buffer_with_offline_authority<'a>(
rpc_client: &RpcClient,
program_path: &PathBuf,
program_path: &Path,
config: &mut CliConfig<'a>,
online_signer: &'a Keypair,
offline_signer: &'a Keypair,
Expand All @@ -2226,7 +2231,7 @@ fn create_buffer_with_offline_authority<'a>(
max_len: None,
skip_fee_check: false,
});
process_command(&config).unwrap();
process_command(config).unwrap();
let buffer_account = rpc_client.get_account(&buffer_signer.pubkey()).unwrap();
if let UpgradeableLoaderState::Buffer { authority_address } = buffer_account.state().unwrap() {
assert_eq!(authority_address, Some(online_signer.pubkey()));
Expand All @@ -2242,7 +2247,7 @@ fn create_buffer_with_offline_authority<'a>(
new_buffer_authority: offline_signer.pubkey(),
});
config.output_format = OutputFormat::JsonCompact;
let response = process_command(&config);
let response = process_command(config);
let json: Value = serde_json::from_str(&response.unwrap()).unwrap();
let offline_signer_authority_str = json
.as_object()
Expand Down Expand Up @@ -2281,7 +2286,7 @@ fn create_buffer_with_offline_authority<'a>(
min_rent_balance: Some(minimum_balance_for_program),
});
config.output_format = OutputFormat::JsonCompact;
let error = process_command(&config).unwrap_err();
let error = process_command(config).unwrap_err();
assert_eq!(error.to_string(), "Deploying program failed: RPC response error -32002: Transaction simulation failed: Error processing Instruction 1: Incorrect authority provided [5 log messages]");
}

Expand All @@ -2294,7 +2299,7 @@ fn verify_deployed_program<'a>(
max_program_data_len: usize,
) {
let min_slot = rpc_client.get_slot().unwrap();
process_command(&config).unwrap();
process_command(config).unwrap();
let max_slot = rpc_client.get_slot().unwrap();

// Verify show
Expand All @@ -2307,7 +2312,7 @@ fn verify_deployed_program<'a>(
all: false,
use_lamports_unit: false,
});
let response = process_command(&config);
let response = process_command(config);
let json: Value = serde_json::from_str(&response.unwrap()).unwrap();
let address_str = json
.as_object()
Expand Down
8 changes: 4 additions & 4 deletions docs/src/cli/deploy-a-program.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ To deploy a program, use the Solana tools to interact with the on-chain loader
to:

- Initialize a program account
- Upload the program's shared object (the program binary .so) to the program account's data buffer
- Upload the program's shared object (the program binary `.so`) to the program account's data buffer
- (optional) Verify the uploaded program
- Finalize the program by marking the program account executable.

Expand All @@ -25,7 +25,7 @@ reference it to the cluster.
### Deploy a program

To deploy a program, you will need the location of the program's shared object
(the program binary .so):
(the program binary `.so`):

```bash
solana program deploy <PROGRAM_FILEPATH>
Expand Down Expand Up @@ -256,7 +256,7 @@ solana program dump <ACCOUNT_ADDRESS> <OUTPUT_FILEPATH>
```

The dumped file will be in the same as what was deployed, so in the case of a
shared object (the program binary .so), the dumped file will be a fully functional shared object. Note
shared object (the program binary `.so`), the dumped file will be a fully functional shared object. Note
that the `dump` command dumps the entire data space, which means the output file
might have trailing zeros after the shared object's data up to `max_len`.
Sometimes it is useful to dump and compare a program to ensure it matches a
Expand Down Expand Up @@ -342,7 +342,7 @@ to verify it.

After program buffer has been verified and is believed to contain the compiled result of intended source code - we are
ready to sign program deploy (to create brand-new program or upgrade existing one), fill in all required parameters
below (<WHATEVER_PARAM> values).
below (<WHATEVER_VALUE> values).

```bash
# (4) (use offline machine) get a signature for your intent to CREATE program
Expand Down

0 comments on commit 494e9fd

Please sign in to comment.