Skip to content
This repository was archived by the owner on Mar 11, 2025. It is now read-only.

Commit 2d24967

Browse files
committed
Test using compute unit price for offline signing
1 parent 861f918 commit 2d24967

File tree

2 files changed

+90
-72
lines changed

2 files changed

+90
-72
lines changed

token/cli/src/clap_app.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use {
1717
spl_token_2022::instruction::{AuthorityType, MAX_SIGNERS, MIN_SIGNERS},
1818
std::{fmt, str::FromStr},
1919
strum::IntoEnumIterator,
20-
strum_macros::{EnumIter, EnumString, IntoStaticStr},
20+
strum_macros::{AsRefStr, EnumIter, EnumString, IntoStaticStr},
2121
};
2222

2323
pub type Error = Box<dyn std::error::Error + Send + Sync>;
@@ -78,7 +78,7 @@ pub const COMPUTE_UNIT_LIMIT_ARG: ArgConstant<'static> = ArgConstant {
7878

7979
pub static VALID_TOKEN_PROGRAM_IDS: [Pubkey; 2] = [spl_token_2022::ID, spl_token::ID];
8080

81-
#[derive(Debug, Clone, Copy, PartialEq, EnumString, IntoStaticStr)]
81+
#[derive(AsRefStr, Debug, Clone, Copy, PartialEq, EnumString, IntoStaticStr)]
8282
#[strum(serialize_all = "kebab-case")]
8383
pub enum CommandName {
8484
CreateToken,

token/cli/tests/command.rs

Lines changed: 88 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,12 @@ use {
4848
},
4949
spl_token_group_interface::state::{TokenGroup, TokenGroupMember},
5050
spl_token_metadata_interface::state::TokenMetadata,
51-
std::{ffi::OsString, path::PathBuf, str::FromStr, sync::Arc},
51+
std::{
52+
ffi::{OsStr, OsString},
53+
path::PathBuf,
54+
str::FromStr,
55+
sync::Arc,
56+
},
5257
tempfile::NamedTempFile,
5358
};
5459

@@ -441,7 +446,7 @@ where
441446
process_command(&sub_command, matches, config, wallet_manager, bulk_signers).await
442447
}
443448

444-
async fn exec_test_cmd(config: &Config<'_>, args: &[&str]) -> CommandResult {
449+
async fn exec_test_cmd<T: AsRef<OsStr>>(config: &Config<'_>, args: &[T]) -> CommandResult {
445450
let default_decimals = format!("{}", spl_token_2022::native_mint::DECIMALS);
446451
let minimum_signers_help = minimum_signers_help_string();
447452
let multisig_member_help = multisig_member_help_string();
@@ -2974,7 +2979,11 @@ async fn multisig_transfer(test_validator: &TestValidator, payer: &Keypair) {
29742979
}
29752980
}
29762981

2977-
async fn offline_multisig_transfer_with_nonce(test_validator: &TestValidator, payer: &Keypair) {
2982+
async fn do_offline_multisig_transfer(
2983+
test_validator: &TestValidator,
2984+
payer: &Keypair,
2985+
compute_unit_price: Option<u64>,
2986+
) {
29782987
let m = 2;
29792988
let n = 3u8;
29802989

@@ -3036,40 +3045,42 @@ async fn offline_multisig_transfer_with_nonce(test_validator: &TestValidator, pa
30363045
let program_client: Arc<dyn ProgramClient<ProgramRpcClientSendTransaction>> = Arc::new(
30373046
ProgramOfflineClient::new(blockhash, ProgramRpcClientSendTransaction),
30383047
);
3048+
let mut args = vec![
3049+
"spl-token".to_string(),
3050+
CommandName::Transfer.as_ref().to_string(),
3051+
token.to_string(),
3052+
"10".to_string(),
3053+
destination.to_string(),
3054+
"--blockhash".to_string(),
3055+
blockhash.to_string(),
3056+
"--nonce".to_string(),
3057+
nonce.to_string(),
3058+
"--nonce-authority".to_string(),
3059+
payer.pubkey().to_string(),
3060+
"--sign-only".to_string(),
3061+
"--mint-decimals".to_string(),
3062+
format!("{}", TEST_DECIMALS),
3063+
"--multisig-signer".to_string(),
3064+
multisig_paths[1].path().to_str().unwrap().to_string(),
3065+
"--multisig-signer".to_string(),
3066+
multisig_members[2].to_string(),
3067+
"--from".to_string(),
3068+
source.to_string(),
3069+
"--owner".to_string(),
3070+
multisig_pubkey.to_string(),
3071+
"--fee-payer".to_string(),
3072+
payer.pubkey().to_string(),
3073+
"--program-id".to_string(),
3074+
program_id.to_string(),
3075+
];
3076+
if let Some(compute_unit_price) = compute_unit_price {
3077+
args.push("--with-compute-unit-price".to_string());
3078+
args.push(compute_unit_price.to_string());
3079+
args.push("--with-compute-unit-limit".to_string());
3080+
args.push(10_000.to_string());
3081+
}
30393082
config.program_client = program_client;
3040-
let result = exec_test_cmd(
3041-
&config,
3042-
&[
3043-
"spl-token",
3044-
CommandName::Transfer.into(),
3045-
&token.to_string(),
3046-
"10",
3047-
&destination.to_string(),
3048-
"--blockhash",
3049-
&blockhash.to_string(),
3050-
"--nonce",
3051-
&nonce.to_string(),
3052-
"--nonce-authority",
3053-
&payer.pubkey().to_string(),
3054-
"--sign-only",
3055-
"--mint-decimals",
3056-
&format!("{}", TEST_DECIMALS),
3057-
"--multisig-signer",
3058-
multisig_paths[1].path().to_str().unwrap(),
3059-
"--multisig-signer",
3060-
&multisig_members[2].to_string(),
3061-
"--from",
3062-
&source.to_string(),
3063-
"--owner",
3064-
&multisig_pubkey.to_string(),
3065-
"--fee-payer",
3066-
&payer.pubkey().to_string(),
3067-
"--program-id",
3068-
&program_id.to_string(),
3069-
],
3070-
)
3071-
.await
3072-
.unwrap();
3083+
let result = exec_test_cmd(&config, &args).await.unwrap();
30733084
// the provided signer has a signature, denoted by the pubkey followed
30743085
// by "=" and the signature
30753086
let member_prefix = format!("{}=", multisig_members[1]);
@@ -3096,40 +3107,42 @@ async fn offline_multisig_transfer_with_nonce(test_validator: &TestValidator, pa
30963107
ProgramRpcClient::new(config.rpc_client.clone(), ProgramRpcClientSendTransaction),
30973108
);
30983109
config.program_client = program_client;
3099-
exec_test_cmd(
3100-
&config,
3101-
&[
3102-
"spl-token",
3103-
CommandName::Transfer.into(),
3104-
&token.to_string(),
3105-
"10",
3106-
&destination.to_string(),
3107-
"--blockhash",
3108-
&blockhash.to_string(),
3109-
"--nonce",
3110-
&nonce.to_string(),
3111-
"--nonce-authority",
3112-
&fee_payer_keypair_file.path().to_str().unwrap(),
3113-
"--mint-decimals",
3114-
&format!("{}", TEST_DECIMALS),
3115-
"--multisig-signer",
3116-
&multisig_members[1].to_string(),
3117-
"--multisig-signer",
3118-
multisig_paths[2].path().to_str().unwrap(),
3119-
"--from",
3120-
&source.to_string(),
3121-
"--owner",
3122-
&multisig_pubkey.to_string(),
3123-
"--fee-payer",
3124-
&fee_payer_keypair_file.path().to_str().unwrap(),
3125-
"--program-id",
3126-
&program_id.to_string(),
3127-
"--signer",
3128-
signer,
3129-
],
3130-
)
3131-
.await
3132-
.unwrap();
3110+
let mut args = vec![
3111+
"spl-token".to_string(),
3112+
CommandName::Transfer.as_ref().to_string(),
3113+
token.to_string(),
3114+
"10".to_string(),
3115+
destination.to_string(),
3116+
"--blockhash".to_string(),
3117+
blockhash.to_string(),
3118+
"--nonce".to_string(),
3119+
nonce.to_string(),
3120+
"--nonce-authority".to_string(),
3121+
fee_payer_keypair_file.path().to_str().unwrap().to_string(),
3122+
"--mint-decimals".to_string(),
3123+
format!("{}", TEST_DECIMALS),
3124+
"--multisig-signer".to_string(),
3125+
multisig_members[1].to_string(),
3126+
"--multisig-signer".to_string(),
3127+
multisig_paths[2].path().to_str().unwrap().to_string(),
3128+
"--from".to_string(),
3129+
source.to_string(),
3130+
"--owner".to_string(),
3131+
multisig_pubkey.to_string(),
3132+
"--fee-payer".to_string(),
3133+
fee_payer_keypair_file.path().to_str().unwrap().to_string(),
3134+
"--program-id".to_string(),
3135+
program_id.to_string(),
3136+
"--signer".to_string(),
3137+
signer.to_string(),
3138+
];
3139+
if let Some(compute_unit_price) = compute_unit_price {
3140+
args.push("--with-compute-unit-price".to_string());
3141+
args.push(compute_unit_price.to_string());
3142+
args.push("--with-compute-unit-limit".to_string());
3143+
args.push(10_000.to_string());
3144+
}
3145+
exec_test_cmd(&config, &args).await.unwrap();
31333146

31343147
let account = config.rpc_client.get_account(&source).await.unwrap();
31353148
let token_account = StateWithExtensionsOwned::<Account>::unpack(account.data).unwrap();
@@ -3142,6 +3155,11 @@ async fn offline_multisig_transfer_with_nonce(test_validator: &TestValidator, pa
31423155
}
31433156
}
31443157

3158+
async fn offline_multisig_transfer_with_nonce(test_validator: &TestValidator, payer: &Keypair) {
3159+
do_offline_multisig_transfer(test_validator, payer, None).await;
3160+
do_offline_multisig_transfer(test_validator, payer, Some(10)).await;
3161+
}
3162+
31453163
async fn withdraw_excess_lamports_from_multisig(test_validator: &TestValidator, payer: &Keypair) {
31463164
let m = 3;
31473165
let n = 5u8;

0 commit comments

Comments
 (0)