From 494e9fd7768ea29d78b7e627f716ee99f5f4e28e Mon Sep 17 00:00:00 2001 From: norwnd Date: Wed, 1 Nov 2023 19:38:35 +0300 Subject: [PATCH] fix clippy warnings, fix minor things --- cli/src/program.rs | 10 ++++++---- cli/tests/program.rs | 27 ++++++++++++++++----------- docs/src/cli/deploy-a-program.md | 8 ++++---- 3 files changed, 26 insertions(+), 19 deletions(-) diff --git a/cli/src/program.rs b/cli/src/program.rs index b1e4d01f93d4ce..4ae2d85e9a99e2 100644 --- a/cli/src/program.rs +++ b/cli/src/program.rs @@ -2210,6 +2210,7 @@ fn do_process_program_write_and_deploy( } } +#[allow(clippy::too_many_arguments)] fn do_process_program_upgrade( rpc_client: Arc, config: &CliConfig, @@ -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). @@ -2336,6 +2335,8 @@ fn do_process_program_upgrade( }, ) } else { + let final_message = Some(final_message); + if !skip_fee_check { check_payer( &rpc_client, @@ -2470,7 +2471,7 @@ fn check_payer( } check_account_for_spend_and_fee_with_commitment( rpc_client, - &fee_payer_pubkey, + fee_payer_pubkey, balance_needed, fee, config.commitment, @@ -2478,6 +2479,7 @@ fn check_payer( Ok(()) } +#[allow(clippy::too_many_arguments)] fn send_deploy_messages( rpc_client: Arc, blockhash_query: &BlockhashQuery, diff --git a/cli/tests/program.rs b/cli/tests/program.rs index 7a8a8ba1b1e777..1a7470c2478244 100644 --- a/cli/tests/program.rs +++ b/cli/tests/program.rs @@ -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] @@ -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() @@ -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(), @@ -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, @@ -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())); @@ -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() @@ -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]"); } @@ -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 @@ -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() diff --git a/docs/src/cli/deploy-a-program.md b/docs/src/cli/deploy-a-program.md index 8ecbcc026aa6bd..f78411194d1ffc 100644 --- a/docs/src/cli/deploy-a-program.md +++ b/docs/src/cli/deploy-a-program.md @@ -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. @@ -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 @@ -256,7 +256,7 @@ solana program dump ``` 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 @@ -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 ( values). +below ( values). ```bash # (4) (use offline machine) get a signature for your intent to CREATE program