CLI: Support offline fee payers (#8009)
* CLI: Support offline fee-payer * Add some knobs to test genesis/validator helpers * Add tests
This commit is contained in:
@@ -14,7 +14,7 @@ use log::*;
|
||||
use num_traits::FromPrimitive;
|
||||
use serde_json::{self, json, Value};
|
||||
use solana_budget_program::budget_instruction::{self, BudgetError};
|
||||
use solana_clap_utils::{input_parsers::*, input_validators::*};
|
||||
use solana_clap_utils::{input_parsers::*, input_validators::*, ArgConstant};
|
||||
use solana_client::{client_error::ClientError, rpc_client::RpcClient};
|
||||
#[cfg(not(test))]
|
||||
use solana_faucet::faucet::request_airdrop_transaction;
|
||||
@@ -51,6 +51,23 @@ use std::{
|
||||
|
||||
const USERDATA_CHUNK_SIZE: usize = 229; // Keep program chunks under PACKET_DATA_SIZE
|
||||
|
||||
pub const FEE_PAYER_ARG: ArgConstant<'static> = ArgConstant {
|
||||
name: "fee_payer",
|
||||
long: "fee-payer",
|
||||
help: "Specify the fee-payer account. This may be a keypair file, the ASK keyword \n\
|
||||
or the pubkey of an offline signer, provided an appropriate --signer argument \n\
|
||||
is also passed. Defaults to the client keypair.",
|
||||
};
|
||||
|
||||
pub fn fee_payer_arg<'a, 'b>() -> Arg<'a, 'b> {
|
||||
Arg::with_name(FEE_PAYER_ARG.name)
|
||||
.long(FEE_PAYER_ARG.long)
|
||||
.takes_value(true)
|
||||
.value_name("KEYPAIR or PUBKEY")
|
||||
.validator(is_pubkey_or_keypair_or_ask_keyword)
|
||||
.help(FEE_PAYER_ARG.help)
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct KeypairEq(Keypair);
|
||||
|
||||
@@ -267,6 +284,7 @@ pub enum CliCommand {
|
||||
blockhash_query: BlockhashQuery,
|
||||
nonce_account: Option<Pubkey>,
|
||||
nonce_authority: Option<SigningAuthority>,
|
||||
fee_payer: Option<SigningAuthority>,
|
||||
},
|
||||
DelegateStake {
|
||||
stake_account_pubkey: Pubkey,
|
||||
@@ -278,6 +296,7 @@ pub enum CliCommand {
|
||||
blockhash_query: BlockhashQuery,
|
||||
nonce_account: Option<Pubkey>,
|
||||
nonce_authority: Option<SigningAuthority>,
|
||||
fee_payer: Option<SigningAuthority>,
|
||||
},
|
||||
SplitStake {
|
||||
stake_account_pubkey: Pubkey,
|
||||
@@ -308,6 +327,7 @@ pub enum CliCommand {
|
||||
blockhash_query: BlockhashQuery,
|
||||
nonce_account: Option<Pubkey>,
|
||||
nonce_authority: Option<SigningAuthority>,
|
||||
fee_payer: Option<SigningAuthority>,
|
||||
},
|
||||
WithdrawStake {
|
||||
stake_account_pubkey: Pubkey,
|
||||
@@ -1402,6 +1422,7 @@ pub fn process_command(config: &CliConfig) -> ProcessResult {
|
||||
blockhash_query,
|
||||
nonce_account,
|
||||
ref nonce_authority,
|
||||
ref fee_payer,
|
||||
} => process_deactivate_stake_account(
|
||||
&rpc_client,
|
||||
config,
|
||||
@@ -1412,6 +1433,7 @@ pub fn process_command(config: &CliConfig) -> ProcessResult {
|
||||
blockhash_query,
|
||||
*nonce_account,
|
||||
nonce_authority.as_ref(),
|
||||
fee_payer.as_ref(),
|
||||
),
|
||||
CliCommand::DelegateStake {
|
||||
stake_account_pubkey,
|
||||
@@ -1423,6 +1445,7 @@ pub fn process_command(config: &CliConfig) -> ProcessResult {
|
||||
blockhash_query,
|
||||
nonce_account,
|
||||
ref nonce_authority,
|
||||
ref fee_payer,
|
||||
} => process_delegate_stake(
|
||||
&rpc_client,
|
||||
config,
|
||||
@@ -1435,6 +1458,7 @@ pub fn process_command(config: &CliConfig) -> ProcessResult {
|
||||
blockhash_query,
|
||||
*nonce_account,
|
||||
nonce_authority.as_ref(),
|
||||
fee_payer.as_ref(),
|
||||
),
|
||||
CliCommand::SplitStake {
|
||||
stake_account_pubkey,
|
||||
@@ -1483,6 +1507,7 @@ pub fn process_command(config: &CliConfig) -> ProcessResult {
|
||||
blockhash_query,
|
||||
nonce_account,
|
||||
ref nonce_authority,
|
||||
ref fee_payer,
|
||||
} => process_stake_authorize(
|
||||
&rpc_client,
|
||||
config,
|
||||
@@ -1495,6 +1520,7 @@ pub fn process_command(config: &CliConfig) -> ProcessResult {
|
||||
blockhash_query,
|
||||
*nonce_account,
|
||||
nonce_authority.as_ref(),
|
||||
fee_payer.as_ref(),
|
||||
),
|
||||
|
||||
CliCommand::WithdrawStake {
|
||||
@@ -2808,6 +2834,7 @@ mod tests {
|
||||
blockhash_query: BlockhashQuery::default(),
|
||||
nonce_account: None,
|
||||
nonce_authority: None,
|
||||
fee_payer: None,
|
||||
};
|
||||
let signature = process_command(&config);
|
||||
assert_eq!(signature.unwrap(), SIGNATURE.to_string());
|
||||
|
256
cli/src/stake.rs
256
cli/src/stake.rs
@@ -1,9 +1,9 @@
|
||||
use crate::{
|
||||
cli::{
|
||||
build_balance_message, check_account_for_fee, check_unique_pubkeys,
|
||||
build_balance_message, check_account_for_fee, check_unique_pubkeys, fee_payer_arg,
|
||||
log_instruction_custom_error, nonce_authority_arg, replace_signatures,
|
||||
required_lamports_from, return_signers, CliCommand, CliCommandInfo, CliConfig, CliError,
|
||||
ProcessResult, SigningAuthority,
|
||||
ProcessResult, SigningAuthority, FEE_PAYER_ARG,
|
||||
},
|
||||
nonce::{check_nonce_account, nonce_arg, NONCE_ARG, NONCE_AUTHORITY_ARG},
|
||||
offline::*,
|
||||
@@ -175,6 +175,7 @@ impl StakeSubCommands for App<'_, '_> {
|
||||
.offline_args()
|
||||
.arg(nonce_arg())
|
||||
.arg(nonce_authority_arg())
|
||||
.arg(fee_payer_arg())
|
||||
)
|
||||
.subcommand(
|
||||
SubCommand::with_name("stake-authorize-staker")
|
||||
@@ -201,6 +202,7 @@ impl StakeSubCommands for App<'_, '_> {
|
||||
.offline_args()
|
||||
.arg(nonce_arg())
|
||||
.arg(nonce_authority_arg())
|
||||
.arg(fee_payer_arg())
|
||||
)
|
||||
.subcommand(
|
||||
SubCommand::with_name("stake-authorize-withdrawer")
|
||||
@@ -227,6 +229,7 @@ impl StakeSubCommands for App<'_, '_> {
|
||||
.offline_args()
|
||||
.arg(nonce_arg())
|
||||
.arg(nonce_authority_arg())
|
||||
.arg(fee_payer_arg())
|
||||
)
|
||||
.subcommand(
|
||||
SubCommand::with_name("deactivate-stake")
|
||||
@@ -243,6 +246,7 @@ impl StakeSubCommands for App<'_, '_> {
|
||||
.offline_args()
|
||||
.arg(nonce_arg())
|
||||
.arg(nonce_authority_arg())
|
||||
.arg(fee_payer_arg())
|
||||
)
|
||||
.subcommand(
|
||||
SubCommand::with_name("split-stake")
|
||||
@@ -407,6 +411,8 @@ pub fn parse_stake_delegate_stake(matches: &ArgMatches<'_>) -> Result<CliCommand
|
||||
SigningAuthority::new_from_matches(&matches, STAKE_AUTHORITY_ARG.name, signers.as_deref())?;
|
||||
let nonce_authority =
|
||||
SigningAuthority::new_from_matches(&matches, NONCE_AUTHORITY_ARG.name, signers.as_deref())?;
|
||||
let fee_payer =
|
||||
SigningAuthority::new_from_matches(&matches, FEE_PAYER_ARG.name, signers.as_deref())?;
|
||||
|
||||
Ok(CliCommandInfo {
|
||||
command: CliCommand::DelegateStake {
|
||||
@@ -419,6 +425,7 @@ pub fn parse_stake_delegate_stake(matches: &ArgMatches<'_>) -> Result<CliCommand
|
||||
blockhash_query,
|
||||
nonce_account,
|
||||
nonce_authority,
|
||||
fee_payer,
|
||||
},
|
||||
require_keypair,
|
||||
})
|
||||
@@ -442,6 +449,8 @@ pub fn parse_stake_authorize(
|
||||
let nonce_account = pubkey_of(&matches, NONCE_ARG.name);
|
||||
let nonce_authority =
|
||||
SigningAuthority::new_from_matches(&matches, NONCE_AUTHORITY_ARG.name, signers.as_deref())?;
|
||||
let fee_payer =
|
||||
SigningAuthority::new_from_matches(&matches, FEE_PAYER_ARG.name, signers.as_deref())?;
|
||||
|
||||
Ok(CliCommandInfo {
|
||||
command: CliCommand::StakeAuthorize {
|
||||
@@ -454,6 +463,7 @@ pub fn parse_stake_authorize(
|
||||
blockhash_query,
|
||||
nonce_account,
|
||||
nonce_authority,
|
||||
fee_payer,
|
||||
},
|
||||
require_keypair: true,
|
||||
})
|
||||
@@ -503,6 +513,8 @@ pub fn parse_stake_deactivate_stake(matches: &ArgMatches<'_>) -> Result<CliComma
|
||||
SigningAuthority::new_from_matches(&matches, STAKE_AUTHORITY_ARG.name, signers.as_deref())?;
|
||||
let nonce_authority =
|
||||
SigningAuthority::new_from_matches(&matches, NONCE_AUTHORITY_ARG.name, signers.as_deref())?;
|
||||
let fee_payer =
|
||||
SigningAuthority::new_from_matches(&matches, FEE_PAYER_ARG.name, signers.as_deref())?;
|
||||
|
||||
Ok(CliCommandInfo {
|
||||
command: CliCommand::DeactivateStake {
|
||||
@@ -513,6 +525,7 @@ pub fn parse_stake_deactivate_stake(matches: &ArgMatches<'_>) -> Result<CliComma
|
||||
blockhash_query,
|
||||
nonce_account,
|
||||
nonce_authority,
|
||||
fee_payer,
|
||||
},
|
||||
require_keypair,
|
||||
})
|
||||
@@ -661,6 +674,7 @@ pub fn process_stake_authorize(
|
||||
blockhash_query: &BlockhashQuery,
|
||||
nonce_account: Option<Pubkey>,
|
||||
nonce_authority: Option<&SigningAuthority>,
|
||||
fee_payer: Option<&SigningAuthority>,
|
||||
) -> ProcessResult {
|
||||
check_unique_pubkeys(
|
||||
(stake_account_pubkey, "stake_account_pubkey".to_string()),
|
||||
@@ -679,11 +693,12 @@ pub fn process_stake_authorize(
|
||||
let (nonce_authority, nonce_authority_pubkey) = nonce_authority
|
||||
.map(|a| (a.keypair(), a.pubkey()))
|
||||
.unwrap_or((&config.keypair, config.keypair.pubkey()));
|
||||
let fee_payer = fee_payer.map(|f| f.keypair()).unwrap_or(&config.keypair);
|
||||
let mut tx = if let Some(nonce_account) = &nonce_account {
|
||||
Transaction::new_signed_with_nonce(
|
||||
ixs,
|
||||
Some(&config.keypair.pubkey()),
|
||||
&[&config.keypair, nonce_authority, authority],
|
||||
Some(&fee_payer.pubkey()),
|
||||
&[fee_payer, nonce_authority, authority],
|
||||
nonce_account,
|
||||
&nonce_authority.pubkey(),
|
||||
recent_blockhash,
|
||||
@@ -691,8 +706,8 @@ pub fn process_stake_authorize(
|
||||
} else {
|
||||
Transaction::new_signed_with_payer(
|
||||
ixs,
|
||||
Some(&config.keypair.pubkey()),
|
||||
&[&config.keypair, authority],
|
||||
Some(&fee_payer.pubkey()),
|
||||
&[fee_payer, authority],
|
||||
recent_blockhash,
|
||||
)
|
||||
};
|
||||
@@ -717,6 +732,7 @@ pub fn process_stake_authorize(
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn process_deactivate_stake_account(
|
||||
rpc_client: &RpcClient,
|
||||
config: &CliConfig,
|
||||
@@ -727,6 +743,7 @@ pub fn process_deactivate_stake_account(
|
||||
blockhash_query: &BlockhashQuery,
|
||||
nonce_account: Option<Pubkey>,
|
||||
nonce_authority: Option<&SigningAuthority>,
|
||||
fee_payer: Option<&SigningAuthority>,
|
||||
) -> ProcessResult {
|
||||
let (recent_blockhash, fee_calculator) =
|
||||
blockhash_query.get_blockhash_fee_calculator(rpc_client)?;
|
||||
@@ -740,11 +757,12 @@ pub fn process_deactivate_stake_account(
|
||||
let (nonce_authority, nonce_authority_pubkey) = nonce_authority
|
||||
.map(|a| (a.keypair(), a.pubkey()))
|
||||
.unwrap_or((&config.keypair, config.keypair.pubkey()));
|
||||
let fee_payer = fee_payer.map(|f| f.keypair()).unwrap_or(&config.keypair);
|
||||
let mut tx = if let Some(nonce_account) = &nonce_account {
|
||||
Transaction::new_signed_with_nonce(
|
||||
ixs,
|
||||
Some(&config.keypair.pubkey()),
|
||||
&[&config.keypair, nonce_authority, stake_authority],
|
||||
Some(&fee_payer.pubkey()),
|
||||
&[fee_payer, nonce_authority, stake_authority],
|
||||
nonce_account,
|
||||
&nonce_authority.pubkey(),
|
||||
recent_blockhash,
|
||||
@@ -752,8 +770,8 @@ pub fn process_deactivate_stake_account(
|
||||
} else {
|
||||
Transaction::new_signed_with_payer(
|
||||
ixs,
|
||||
Some(&config.keypair.pubkey()),
|
||||
&[&config.keypair, stake_authority],
|
||||
Some(&fee_payer.pubkey()),
|
||||
&[fee_payer, stake_authority],
|
||||
recent_blockhash,
|
||||
)
|
||||
};
|
||||
@@ -1090,6 +1108,7 @@ pub fn process_delegate_stake(
|
||||
blockhash_query: &BlockhashQuery,
|
||||
nonce_account: Option<Pubkey>,
|
||||
nonce_authority: Option<&SigningAuthority>,
|
||||
fee_payer: Option<&SigningAuthority>,
|
||||
) -> ProcessResult {
|
||||
check_unique_pubkeys(
|
||||
(&config.keypair.pubkey(), "cli keypair".to_string()),
|
||||
@@ -1150,11 +1169,12 @@ pub fn process_delegate_stake(
|
||||
let (nonce_authority, nonce_authority_pubkey) = nonce_authority
|
||||
.map(|a| (a.keypair(), a.pubkey()))
|
||||
.unwrap_or((&config.keypair, config.keypair.pubkey()));
|
||||
let fee_payer = fee_payer.map(|f| f.keypair()).unwrap_or(&config.keypair);
|
||||
let mut tx = if let Some(nonce_account) = &nonce_account {
|
||||
Transaction::new_signed_with_nonce(
|
||||
ixs,
|
||||
Some(&config.keypair.pubkey()),
|
||||
&[&config.keypair, nonce_authority, stake_authority],
|
||||
Some(&fee_payer.pubkey()),
|
||||
&[fee_payer, nonce_authority, stake_authority],
|
||||
nonce_account,
|
||||
&nonce_authority.pubkey(),
|
||||
recent_blockhash,
|
||||
@@ -1162,8 +1182,8 @@ pub fn process_delegate_stake(
|
||||
} else {
|
||||
Transaction::new_signed_with_payer(
|
||||
ixs,
|
||||
Some(&config.keypair.pubkey()),
|
||||
&[&config.keypair, stake_authority],
|
||||
Some(&fee_payer.pubkey()),
|
||||
&[fee_payer, stake_authority],
|
||||
recent_blockhash,
|
||||
)
|
||||
};
|
||||
@@ -1237,6 +1257,7 @@ mod tests {
|
||||
blockhash_query: BlockhashQuery::default(),
|
||||
nonce_account: None,
|
||||
nonce_authority: None,
|
||||
fee_payer: None,
|
||||
},
|
||||
require_keypair: true
|
||||
}
|
||||
@@ -1263,6 +1284,7 @@ mod tests {
|
||||
blockhash_query: BlockhashQuery::default(),
|
||||
nonce_account: None,
|
||||
nonce_authority: None,
|
||||
fee_payer: None,
|
||||
},
|
||||
require_keypair: true
|
||||
}
|
||||
@@ -1292,6 +1314,7 @@ mod tests {
|
||||
blockhash_query: BlockhashQuery::None(blockhash, FeeCalculator::default()),
|
||||
nonce_account: None,
|
||||
nonce_authority: None,
|
||||
fee_payer: None,
|
||||
},
|
||||
require_keypair: true
|
||||
}
|
||||
@@ -1323,6 +1346,7 @@ mod tests {
|
||||
blockhash_query: BlockhashQuery::FeeCalculator(blockhash),
|
||||
nonce_account: None,
|
||||
nonce_authority: None,
|
||||
fee_payer: None,
|
||||
},
|
||||
require_keypair: true
|
||||
}
|
||||
@@ -1356,6 +1380,7 @@ mod tests {
|
||||
blockhash_query: BlockhashQuery::FeeCalculator(blockhash),
|
||||
nonce_account: None,
|
||||
nonce_authority: None,
|
||||
fee_payer: None,
|
||||
},
|
||||
require_keypair: true
|
||||
}
|
||||
@@ -1382,6 +1407,7 @@ mod tests {
|
||||
blockhash_query: BlockhashQuery::FeeCalculator(blockhash),
|
||||
nonce_account: None,
|
||||
nonce_authority: None,
|
||||
fee_payer: None,
|
||||
},
|
||||
require_keypair: true
|
||||
}
|
||||
@@ -1417,6 +1443,72 @@ mod tests {
|
||||
blockhash_query: BlockhashQuery::FeeCalculator(blockhash),
|
||||
nonce_account: Some(nonce_account_pubkey),
|
||||
nonce_authority: Some(nonce_authority_keypair.into()),
|
||||
fee_payer: None,
|
||||
},
|
||||
require_keypair: true
|
||||
}
|
||||
);
|
||||
// Test Authorize Subcommand w/ fee-payer
|
||||
let (fee_payer_keypair_file, mut fee_payer_tmp_file) = make_tmp_file();
|
||||
let fee_payer_keypair = Keypair::new();
|
||||
write_keypair(&fee_payer_keypair, fee_payer_tmp_file.as_file_mut()).unwrap();
|
||||
let fee_payer_pubkey = fee_payer_keypair.pubkey();
|
||||
let fee_payer_string = fee_payer_pubkey.to_string();
|
||||
let test_authorize = test_commands.clone().get_matches_from(vec![
|
||||
"test",
|
||||
&subcommand,
|
||||
&stake_account_string,
|
||||
&stake_account_string,
|
||||
"--fee-payer",
|
||||
&fee_payer_keypair_file,
|
||||
]);
|
||||
assert_eq!(
|
||||
parse_command(&test_authorize).unwrap(),
|
||||
CliCommandInfo {
|
||||
command: CliCommand::StakeAuthorize {
|
||||
stake_account_pubkey,
|
||||
new_authorized_pubkey: stake_account_pubkey,
|
||||
stake_authorize,
|
||||
authority: None,
|
||||
sign_only: false,
|
||||
signers: None,
|
||||
blockhash_query: BlockhashQuery::All,
|
||||
nonce_account: None,
|
||||
nonce_authority: None,
|
||||
fee_payer: Some(read_keypair_file(&fee_payer_keypair_file).unwrap().into()),
|
||||
},
|
||||
require_keypair: true
|
||||
}
|
||||
);
|
||||
// Test Authorize Subcommand w/ absentee fee-payer
|
||||
let sig = fee_payer_keypair.sign_message(&[0u8]);
|
||||
let signer = format!("{}={}", fee_payer_string, sig);
|
||||
let test_authorize = test_commands.clone().get_matches_from(vec![
|
||||
"test",
|
||||
&subcommand,
|
||||
&stake_account_string,
|
||||
&stake_account_string,
|
||||
"--fee-payer",
|
||||
&fee_payer_string,
|
||||
"--blockhash",
|
||||
&blockhash_string,
|
||||
"--signer",
|
||||
&signer,
|
||||
]);
|
||||
assert_eq!(
|
||||
parse_command(&test_authorize).unwrap(),
|
||||
CliCommandInfo {
|
||||
command: CliCommand::StakeAuthorize {
|
||||
stake_account_pubkey,
|
||||
new_authorized_pubkey: stake_account_pubkey,
|
||||
stake_authorize,
|
||||
authority: None,
|
||||
sign_only: false,
|
||||
signers: Some(vec![(fee_payer_pubkey, sig)]),
|
||||
blockhash_query: BlockhashQuery::FeeCalculator(blockhash),
|
||||
nonce_account: None,
|
||||
nonce_authority: None,
|
||||
fee_payer: Some(fee_payer_pubkey.into()),
|
||||
},
|
||||
require_keypair: true
|
||||
}
|
||||
@@ -1537,6 +1629,7 @@ mod tests {
|
||||
blockhash_query: BlockhashQuery::default(),
|
||||
nonce_account: None,
|
||||
nonce_authority: None,
|
||||
fee_payer: None,
|
||||
},
|
||||
require_keypair: true
|
||||
}
|
||||
@@ -1570,6 +1663,7 @@ mod tests {
|
||||
blockhash_query: BlockhashQuery::default(),
|
||||
nonce_account: None,
|
||||
nonce_authority: None,
|
||||
fee_payer: None,
|
||||
},
|
||||
require_keypair: true
|
||||
}
|
||||
@@ -1596,6 +1690,7 @@ mod tests {
|
||||
blockhash_query: BlockhashQuery::default(),
|
||||
nonce_account: None,
|
||||
nonce_authority: None,
|
||||
fee_payer: None,
|
||||
},
|
||||
require_keypair: true
|
||||
}
|
||||
@@ -1625,6 +1720,7 @@ mod tests {
|
||||
blockhash_query: BlockhashQuery::FeeCalculator(blockhash),
|
||||
nonce_account: None,
|
||||
nonce_authority: None,
|
||||
fee_payer: None,
|
||||
},
|
||||
require_keypair: true
|
||||
}
|
||||
@@ -1652,6 +1748,7 @@ mod tests {
|
||||
blockhash_query: BlockhashQuery::None(blockhash, FeeCalculator::default()),
|
||||
nonce_account: None,
|
||||
nonce_authority: None,
|
||||
fee_payer: None,
|
||||
},
|
||||
require_keypair: true
|
||||
}
|
||||
@@ -1684,6 +1781,7 @@ mod tests {
|
||||
blockhash_query: BlockhashQuery::FeeCalculator(blockhash),
|
||||
nonce_account: None,
|
||||
nonce_authority: None,
|
||||
fee_payer: None,
|
||||
},
|
||||
require_keypair: false
|
||||
}
|
||||
@@ -1718,6 +1816,74 @@ mod tests {
|
||||
blockhash_query: BlockhashQuery::FeeCalculator(blockhash),
|
||||
nonce_account: None,
|
||||
nonce_authority: None,
|
||||
fee_payer: None,
|
||||
},
|
||||
require_keypair: false
|
||||
}
|
||||
);
|
||||
|
||||
// Test Delegate Subcommand w/ fee-payer
|
||||
let (fee_payer_keypair_file, mut fee_payer_tmp_file) = make_tmp_file();
|
||||
let fee_payer_keypair = Keypair::new();
|
||||
write_keypair(&fee_payer_keypair, fee_payer_tmp_file.as_file_mut()).unwrap();
|
||||
let fee_payer_pubkey = fee_payer_keypair.pubkey();
|
||||
let fee_payer_string = fee_payer_pubkey.to_string();
|
||||
let test_delegate_stake = test_commands.clone().get_matches_from(vec![
|
||||
"test",
|
||||
"delegate-stake",
|
||||
&stake_account_string,
|
||||
&vote_account_string,
|
||||
"--fee-payer",
|
||||
&fee_payer_keypair_file,
|
||||
]);
|
||||
assert_eq!(
|
||||
parse_command(&test_delegate_stake).unwrap(),
|
||||
CliCommandInfo {
|
||||
command: CliCommand::DelegateStake {
|
||||
stake_account_pubkey,
|
||||
vote_account_pubkey,
|
||||
stake_authority: None,
|
||||
force: false,
|
||||
sign_only: false,
|
||||
signers: None,
|
||||
blockhash_query: BlockhashQuery::All,
|
||||
nonce_account: None,
|
||||
nonce_authority: None,
|
||||
fee_payer: Some(read_keypair_file(&fee_payer_keypair_file).unwrap().into()),
|
||||
},
|
||||
require_keypair: true
|
||||
}
|
||||
);
|
||||
|
||||
// Test Delegate Subcommand w/ absentee fee-payer
|
||||
let sig = fee_payer_keypair.sign_message(&[0u8]);
|
||||
let signer = format!("{}={}", fee_payer_string, sig);
|
||||
let test_delegate_stake = test_commands.clone().get_matches_from(vec![
|
||||
"test",
|
||||
"delegate-stake",
|
||||
&stake_account_string,
|
||||
&vote_account_string,
|
||||
"--fee-payer",
|
||||
&fee_payer_string,
|
||||
"--blockhash",
|
||||
&blockhash_string,
|
||||
"--signer",
|
||||
&signer,
|
||||
]);
|
||||
assert_eq!(
|
||||
parse_command(&test_delegate_stake).unwrap(),
|
||||
CliCommandInfo {
|
||||
command: CliCommand::DelegateStake {
|
||||
stake_account_pubkey,
|
||||
vote_account_pubkey,
|
||||
stake_authority: None,
|
||||
force: false,
|
||||
sign_only: false,
|
||||
signers: Some(vec![(fee_payer_pubkey, sig)]),
|
||||
blockhash_query: BlockhashQuery::FeeCalculator(blockhash),
|
||||
nonce_account: None,
|
||||
nonce_authority: None,
|
||||
fee_payer: Some(fee_payer_pubkey.into()),
|
||||
},
|
||||
require_keypair: false
|
||||
}
|
||||
@@ -1792,6 +1958,7 @@ mod tests {
|
||||
blockhash_query: BlockhashQuery::default(),
|
||||
nonce_account: None,
|
||||
nonce_authority: None,
|
||||
fee_payer: None,
|
||||
},
|
||||
require_keypair: true
|
||||
}
|
||||
@@ -1820,6 +1987,7 @@ mod tests {
|
||||
blockhash_query: BlockhashQuery::default(),
|
||||
nonce_account: None,
|
||||
nonce_authority: None,
|
||||
fee_payer: None,
|
||||
},
|
||||
require_keypair: true
|
||||
}
|
||||
@@ -1846,6 +2014,7 @@ mod tests {
|
||||
blockhash_query: BlockhashQuery::FeeCalculator(blockhash),
|
||||
nonce_account: None,
|
||||
nonce_authority: None,
|
||||
fee_payer: None,
|
||||
},
|
||||
require_keypair: true
|
||||
}
|
||||
@@ -1870,6 +2039,7 @@ mod tests {
|
||||
blockhash_query: BlockhashQuery::None(blockhash, FeeCalculator::default()),
|
||||
nonce_account: None,
|
||||
nonce_authority: None,
|
||||
fee_payer: None,
|
||||
},
|
||||
require_keypair: true
|
||||
}
|
||||
@@ -1899,6 +2069,7 @@ mod tests {
|
||||
blockhash_query: BlockhashQuery::FeeCalculator(blockhash),
|
||||
nonce_account: None,
|
||||
nonce_authority: None,
|
||||
fee_payer: None,
|
||||
},
|
||||
require_keypair: false
|
||||
}
|
||||
@@ -1930,6 +2101,63 @@ mod tests {
|
||||
blockhash_query: BlockhashQuery::FeeCalculator(blockhash),
|
||||
nonce_account: None,
|
||||
nonce_authority: None,
|
||||
fee_payer: None,
|
||||
},
|
||||
require_keypair: false
|
||||
}
|
||||
);
|
||||
|
||||
// Test Deactivate Subcommand w/ fee-payer
|
||||
let test_deactivate_stake = test_commands.clone().get_matches_from(vec![
|
||||
"test",
|
||||
"deactivate-stake",
|
||||
&stake_account_string,
|
||||
"--fee-payer",
|
||||
&fee_payer_keypair_file,
|
||||
]);
|
||||
assert_eq!(
|
||||
parse_command(&test_deactivate_stake).unwrap(),
|
||||
CliCommandInfo {
|
||||
command: CliCommand::DeactivateStake {
|
||||
stake_account_pubkey,
|
||||
stake_authority: None,
|
||||
sign_only: false,
|
||||
signers: None,
|
||||
blockhash_query: BlockhashQuery::All,
|
||||
nonce_account: None,
|
||||
nonce_authority: None,
|
||||
fee_payer: Some(read_keypair_file(&fee_payer_keypair_file).unwrap().into()),
|
||||
},
|
||||
require_keypair: true
|
||||
}
|
||||
);
|
||||
|
||||
// Test Deactivate Subcommand w/ absentee fee-payer
|
||||
let sig = fee_payer_keypair.sign_message(&[0u8]);
|
||||
let signer = format!("{}={}", fee_payer_string, sig);
|
||||
let test_deactivate_stake = test_commands.clone().get_matches_from(vec![
|
||||
"test",
|
||||
"deactivate-stake",
|
||||
&stake_account_string,
|
||||
"--fee-payer",
|
||||
&fee_payer_string,
|
||||
"--blockhash",
|
||||
&blockhash_string,
|
||||
"--signer",
|
||||
&signer,
|
||||
]);
|
||||
assert_eq!(
|
||||
parse_command(&test_deactivate_stake).unwrap(),
|
||||
CliCommandInfo {
|
||||
command: CliCommand::DeactivateStake {
|
||||
stake_account_pubkey,
|
||||
stake_authority: None,
|
||||
sign_only: false,
|
||||
signers: Some(vec![(fee_payer_pubkey, sig)]),
|
||||
blockhash_query: BlockhashQuery::FeeCalculator(blockhash),
|
||||
nonce_account: None,
|
||||
nonce_authority: None,
|
||||
fee_payer: Some(fee_payer_pubkey.into()),
|
||||
},
|
||||
require_keypair: false
|
||||
}
|
||||
|
Reference in New Issue
Block a user