118
cli/src/cli.rs
118
cli/src/cli.rs
@ -2,7 +2,7 @@ use crate::{
|
||||
cluster_query::*,
|
||||
display::{println_name_value, println_signers},
|
||||
nonce::{self, *},
|
||||
offline::*,
|
||||
offline::{blockhash_query::BlockhashQuery, *},
|
||||
stake::*,
|
||||
storage::*,
|
||||
validator_info::*,
|
||||
@ -990,7 +990,7 @@ pub fn check_unique_pubkeys(
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_blockhash_fee_calculator(
|
||||
pub fn get_blockhash_and_fee_calculator(
|
||||
rpc_client: &RpcClient,
|
||||
sign_only: bool,
|
||||
blockhash: Option<Hash>,
|
||||
@ -1283,7 +1283,8 @@ fn process_pay(
|
||||
(to, "to".to_string()),
|
||||
)?;
|
||||
|
||||
let (blockhash, fee_calculator) = blockhash_query.get_blockhash_fee_calculator(rpc_client)?;
|
||||
let (blockhash, fee_calculator) =
|
||||
blockhash_query.get_blockhash_and_fee_calculator(rpc_client)?;
|
||||
|
||||
let cancelable = if cancelable {
|
||||
Some(config.signers[0].pubkey())
|
||||
@ -1471,7 +1472,7 @@ fn process_transfer(
|
||||
)?;
|
||||
|
||||
let (recent_blockhash, fee_calculator) =
|
||||
blockhash_query.get_blockhash_fee_calculator(rpc_client)?;
|
||||
blockhash_query.get_blockhash_and_fee_calculator(rpc_client)?;
|
||||
let ixs = vec![system_instruction::transfer(&from.pubkey(), to, lamports)];
|
||||
|
||||
let nonce_authority = config.signers[nonce_authority];
|
||||
@ -2485,20 +2486,13 @@ pub fn app<'ab, 'v>(name: &str, about: &'ab str, version: &'v str) -> App<'ab, '
|
||||
mod tests {
|
||||
use super::*;
|
||||
use serde_json::Value;
|
||||
use solana_client::{
|
||||
mock_rpc_client_request::SIGNATURE,
|
||||
rpc_request::RpcRequest,
|
||||
rpc_response::{Response, RpcAccount, RpcResponseContext},
|
||||
};
|
||||
use solana_client::mock_rpc_client_request::SIGNATURE;
|
||||
use solana_sdk::{
|
||||
account::Account,
|
||||
nonce,
|
||||
pubkey::Pubkey,
|
||||
signature::{keypair_from_seed, read_keypair_file, write_keypair_file, Presigner},
|
||||
system_program,
|
||||
transaction::TransactionError,
|
||||
};
|
||||
use std::{collections::HashMap, path::PathBuf};
|
||||
use std::path::PathBuf;
|
||||
|
||||
fn make_tmp_path(name: &str) -> String {
|
||||
let out_dir = std::env::var("FARF_DIR").unwrap_or_else(|_| "farf".to_string());
|
||||
@ -2855,7 +2849,7 @@ mod tests {
|
||||
command: CliCommand::Pay(PayCommand {
|
||||
lamports: 50_000_000_000,
|
||||
to: pubkey,
|
||||
blockhash_query: BlockhashQuery::None(blockhash, FeeCalculator::default()),
|
||||
blockhash_query: BlockhashQuery::None(blockhash),
|
||||
sign_only: true,
|
||||
..PayCommand::default()
|
||||
}),
|
||||
@ -2878,7 +2872,10 @@ mod tests {
|
||||
command: CliCommand::Pay(PayCommand {
|
||||
lamports: 50_000_000_000,
|
||||
to: pubkey,
|
||||
blockhash_query: BlockhashQuery::FeeCalculator(blockhash),
|
||||
blockhash_query: BlockhashQuery::FeeCalculator(
|
||||
blockhash_query::Source::Cluster,
|
||||
blockhash
|
||||
),
|
||||
..PayCommand::default()
|
||||
}),
|
||||
signers: vec![read_keypair_file(&keypair_file).unwrap().into()],
|
||||
@ -2904,7 +2901,10 @@ mod tests {
|
||||
command: CliCommand::Pay(PayCommand {
|
||||
lamports: 50_000_000_000,
|
||||
to: pubkey,
|
||||
blockhash_query: BlockhashQuery::FeeCalculator(blockhash),
|
||||
blockhash_query: BlockhashQuery::FeeCalculator(
|
||||
blockhash_query::Source::NonceAccount(pubkey),
|
||||
blockhash
|
||||
),
|
||||
nonce_account: Some(pubkey),
|
||||
..PayCommand::default()
|
||||
}),
|
||||
@ -2934,7 +2934,10 @@ mod tests {
|
||||
command: CliCommand::Pay(PayCommand {
|
||||
lamports: 50_000_000_000,
|
||||
to: pubkey,
|
||||
blockhash_query: BlockhashQuery::FeeCalculator(blockhash),
|
||||
blockhash_query: BlockhashQuery::FeeCalculator(
|
||||
blockhash_query::Source::NonceAccount(pubkey),
|
||||
blockhash
|
||||
),
|
||||
nonce_account: Some(pubkey),
|
||||
nonce_authority: 0,
|
||||
..PayCommand::default()
|
||||
@ -2969,7 +2972,10 @@ mod tests {
|
||||
command: CliCommand::Pay(PayCommand {
|
||||
lamports: 50_000_000_000,
|
||||
to: pubkey,
|
||||
blockhash_query: BlockhashQuery::FeeCalculator(blockhash),
|
||||
blockhash_query: BlockhashQuery::FeeCalculator(
|
||||
blockhash_query::Source::NonceAccount(pubkey),
|
||||
blockhash
|
||||
),
|
||||
nonce_account: Some(pubkey),
|
||||
nonce_authority: 0,
|
||||
..PayCommand::default()
|
||||
@ -3151,7 +3157,7 @@ mod tests {
|
||||
},
|
||||
lamports: 1234,
|
||||
sign_only: false,
|
||||
blockhash_query: BlockhashQuery::All,
|
||||
blockhash_query: BlockhashQuery::All(blockhash_query::Source::Cluster),
|
||||
nonce_account: None,
|
||||
nonce_authority: 0,
|
||||
fee_payer: 0,
|
||||
@ -3169,7 +3175,7 @@ mod tests {
|
||||
lamports: 100,
|
||||
withdraw_authority: 0,
|
||||
sign_only: false,
|
||||
blockhash_query: BlockhashQuery::All,
|
||||
blockhash_query: BlockhashQuery::All(blockhash_query::Source::Cluster),
|
||||
nonce_account: None,
|
||||
nonce_authority: 0,
|
||||
fee_payer: 0,
|
||||
@ -3269,64 +3275,6 @@ mod tests {
|
||||
SIGNATURE.to_string()
|
||||
);
|
||||
|
||||
// Nonced pay
|
||||
let blockhash = Hash::default();
|
||||
let data =
|
||||
nonce::state::Versions::new_current(nonce::State::Initialized(nonce::state::Data {
|
||||
authority: config.signers[0].pubkey(),
|
||||
blockhash,
|
||||
fee_calculator: FeeCalculator::default(),
|
||||
}));
|
||||
let nonce_response = json!(Response {
|
||||
context: RpcResponseContext { slot: 1 },
|
||||
value: json!(RpcAccount::encode(
|
||||
Account::new_data(1, &data, &system_program::ID,).unwrap()
|
||||
)),
|
||||
});
|
||||
let mut mocks = HashMap::new();
|
||||
mocks.insert(RpcRequest::GetAccountInfo, nonce_response);
|
||||
config.rpc_client = Some(RpcClient::new_mock_with_mocks("".to_string(), mocks));
|
||||
config.command = CliCommand::Pay(PayCommand {
|
||||
lamports: 10,
|
||||
to: bob_pubkey,
|
||||
nonce_account: Some(bob_pubkey),
|
||||
blockhash_query: BlockhashQuery::FeeCalculator(blockhash),
|
||||
..PayCommand::default()
|
||||
});
|
||||
let signature = process_command(&config);
|
||||
assert_eq!(signature.unwrap(), SIGNATURE.to_string());
|
||||
|
||||
// Nonced pay w/ non-payer authority
|
||||
let bob_keypair = Keypair::new();
|
||||
let bob_pubkey = bob_keypair.pubkey();
|
||||
let blockhash = Hash::default();
|
||||
let data =
|
||||
nonce::state::Versions::new_current(nonce::State::Initialized(nonce::state::Data {
|
||||
authority: bob_pubkey,
|
||||
blockhash,
|
||||
fee_calculator: FeeCalculator::default(),
|
||||
}));
|
||||
let nonce_authority_response = json!(Response {
|
||||
context: RpcResponseContext { slot: 1 },
|
||||
value: json!(RpcAccount::encode(
|
||||
Account::new_data(1, &data, &system_program::ID,).unwrap()
|
||||
)),
|
||||
});
|
||||
let mut mocks = HashMap::new();
|
||||
mocks.insert(RpcRequest::GetAccountInfo, nonce_authority_response);
|
||||
config.rpc_client = Some(RpcClient::new_mock_with_mocks("".to_string(), mocks));
|
||||
config.command = CliCommand::Pay(PayCommand {
|
||||
lamports: 10,
|
||||
to: bob_pubkey,
|
||||
blockhash_query: BlockhashQuery::FeeCalculator(blockhash),
|
||||
nonce_account: Some(bob_pubkey),
|
||||
nonce_authority: 1,
|
||||
..PayCommand::default()
|
||||
});
|
||||
config.signers = vec![&keypair, &bob_keypair];
|
||||
let signature = process_command(&config);
|
||||
assert_eq!(signature.unwrap(), SIGNATURE.to_string());
|
||||
|
||||
let process_id = Pubkey::new_rand();
|
||||
config.command = CliCommand::TimeElapsed(bob_pubkey, process_id, dt);
|
||||
config.signers = vec![&keypair];
|
||||
@ -3528,7 +3476,7 @@ mod tests {
|
||||
to: to_pubkey,
|
||||
from: 0,
|
||||
sign_only: false,
|
||||
blockhash_query: BlockhashQuery::All,
|
||||
blockhash_query: BlockhashQuery::All(blockhash_query::Source::Cluster),
|
||||
nonce_account: None,
|
||||
nonce_authority: 0,
|
||||
fee_payer: 0,
|
||||
@ -3557,7 +3505,7 @@ mod tests {
|
||||
to: to_pubkey,
|
||||
from: 0,
|
||||
sign_only: true,
|
||||
blockhash_query: BlockhashQuery::None(blockhash, FeeCalculator::default()),
|
||||
blockhash_query: BlockhashQuery::None(blockhash),
|
||||
nonce_account: None,
|
||||
nonce_authority: 0,
|
||||
fee_payer: 0,
|
||||
@ -3591,7 +3539,10 @@ mod tests {
|
||||
to: to_pubkey,
|
||||
from: 0,
|
||||
sign_only: false,
|
||||
blockhash_query: BlockhashQuery::FeeCalculator(blockhash),
|
||||
blockhash_query: BlockhashQuery::FeeCalculator(
|
||||
blockhash_query::Source::Cluster,
|
||||
blockhash
|
||||
),
|
||||
nonce_account: None,
|
||||
nonce_authority: 0,
|
||||
fee_payer: 0,
|
||||
@ -3626,7 +3577,10 @@ mod tests {
|
||||
to: to_pubkey,
|
||||
from: 0,
|
||||
sign_only: false,
|
||||
blockhash_query: BlockhashQuery::FeeCalculator(blockhash),
|
||||
blockhash_query: BlockhashQuery::FeeCalculator(
|
||||
blockhash_query::Source::NonceAccount(nonce_address),
|
||||
blockhash
|
||||
),
|
||||
nonce_account: Some(nonce_address.into()),
|
||||
nonce_authority: 1,
|
||||
fee_payer: 0,
|
||||
|
Reference in New Issue
Block a user