| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676 |
- #![allow(clippy::arithmetic_side_effects)]
- use {
- solana_cli::{
- check_balance,
- cli::{process_command, request_and_confirm_airdrop, CliCommand, CliConfig},
- spend_utils::SpendAmount,
- test_utils::check_ready,
- },
- solana_cli_output::{parse_sign_only_reply_string, OutputFormat},
- solana_commitment_config::CommitmentConfig,
- solana_compute_budget_interface::ComputeBudgetInstruction,
- solana_faucet::faucet::run_local_faucet_with_unique_port_for_tests,
- solana_fee_structure::FeeStructure,
- solana_keypair::{keypair_from_seed, Keypair},
- solana_message::Message,
- solana_native_token::LAMPORTS_PER_SOL,
- solana_net_utils::SocketAddrSpace,
- solana_nonce::state::State as NonceState,
- solana_pubkey::Pubkey,
- solana_rpc_client::rpc_client::RpcClient,
- solana_rpc_client_nonce_utils::blockhash_query::{self, BlockhashQuery},
- solana_signer::{null_signer::NullSigner, Signer},
- solana_stake_interface as stake,
- solana_system_interface::instruction as system_instruction,
- solana_test_validator::TestValidator,
- test_case::test_case,
- };
- #[test_case(true; "Skip Preflight")]
- #[test_case(false; "Don`t skip Preflight")]
- fn test_transfer(skip_preflight: bool) {
- agave_logger::setup();
- let fee_one_sig = FeeStructure::default().get_max_fee(1, 0);
- let fee_two_sig = FeeStructure::default().get_max_fee(2, 0);
- let mint_keypair = Keypair::new();
- let mint_pubkey = mint_keypair.pubkey();
- let faucet_addr = run_local_faucet_with_unique_port_for_tests(mint_keypair);
- let test_validator = TestValidator::with_custom_fees(
- mint_pubkey,
- fee_one_sig,
- Some(faucet_addr),
- SocketAddrSpace::Unspecified,
- );
- let rpc_client =
- RpcClient::new_with_commitment(test_validator.rpc_url(), CommitmentConfig::processed());
- let default_signer = Keypair::new();
- let default_offline_signer = Keypair::new();
- let mut config = CliConfig::recent_for_tests();
- config.json_rpc_url = test_validator.rpc_url();
- config.signers = vec![&default_signer];
- config.send_transaction_config.skip_preflight = skip_preflight;
- let sender_pubkey = config.signers[0].pubkey();
- let recipient_pubkey = Pubkey::from([1u8; 32]);
- request_and_confirm_airdrop(&rpc_client, &config, &sender_pubkey, 5 * LAMPORTS_PER_SOL)
- .unwrap();
- check_balance!(5 * LAMPORTS_PER_SOL, &rpc_client, &sender_pubkey);
- check_balance!(0, &rpc_client, &recipient_pubkey);
- check_ready(&rpc_client);
- // Plain ole transfer
- config.command = CliCommand::Transfer {
- amount: SpendAmount::Some(LAMPORTS_PER_SOL),
- to: recipient_pubkey,
- from: 0,
- sign_only: false,
- dump_transaction_message: false,
- allow_unfunded_recipient: true,
- no_wait: false,
- blockhash_query: BlockhashQuery::All(blockhash_query::Source::Cluster),
- nonce_account: None,
- nonce_authority: 0,
- memo: None,
- fee_payer: 0,
- derived_address_seed: None,
- derived_address_program_id: None,
- compute_unit_price: None,
- };
- process_command(&config).unwrap();
- check_balance!(
- 4 * LAMPORTS_PER_SOL - fee_one_sig,
- &rpc_client,
- &sender_pubkey
- );
- check_balance!(LAMPORTS_PER_SOL, &rpc_client, &recipient_pubkey);
- // Plain ole transfer, failure due to InsufficientFundsForSpendAndFee
- config.command = CliCommand::Transfer {
- amount: SpendAmount::Some(4 * LAMPORTS_PER_SOL),
- to: recipient_pubkey,
- from: 0,
- sign_only: false,
- dump_transaction_message: false,
- allow_unfunded_recipient: true,
- no_wait: false,
- blockhash_query: BlockhashQuery::All(blockhash_query::Source::Cluster),
- nonce_account: None,
- nonce_authority: 0,
- memo: None,
- fee_payer: 0,
- derived_address_seed: None,
- derived_address_program_id: None,
- compute_unit_price: None,
- };
- assert!(process_command(&config).is_err());
- check_balance!(
- 4 * LAMPORTS_PER_SOL - fee_one_sig,
- &rpc_client,
- &sender_pubkey
- );
- check_balance!(LAMPORTS_PER_SOL, &rpc_client, &recipient_pubkey);
- let mut offline = CliConfig::recent_for_tests();
- offline.json_rpc_url = String::default();
- offline.signers = vec![&default_offline_signer];
- // Verify we cannot contact the cluster
- offline.command = CliCommand::ClusterVersion;
- process_command(&offline).unwrap_err();
- let offline_pubkey = offline.signers[0].pubkey();
- request_and_confirm_airdrop(&rpc_client, &offline, &offline_pubkey, LAMPORTS_PER_SOL).unwrap();
- check_balance!(LAMPORTS_PER_SOL, &rpc_client, &offline_pubkey);
- // Offline transfer
- let blockhash = rpc_client.get_latest_blockhash().unwrap();
- offline.command = CliCommand::Transfer {
- amount: SpendAmount::Some(LAMPORTS_PER_SOL / 2),
- to: recipient_pubkey,
- from: 0,
- sign_only: true,
- dump_transaction_message: false,
- allow_unfunded_recipient: true,
- no_wait: false,
- blockhash_query: BlockhashQuery::None(blockhash),
- nonce_account: None,
- nonce_authority: 0,
- memo: None,
- fee_payer: 0,
- derived_address_seed: None,
- derived_address_program_id: None,
- compute_unit_price: None,
- };
- offline.output_format = OutputFormat::JsonCompact;
- let sign_only_reply = process_command(&offline).unwrap();
- let sign_only = parse_sign_only_reply_string(&sign_only_reply);
- assert!(sign_only.has_all_signers());
- let offline_presigner = sign_only.presigner_of(&offline_pubkey).unwrap();
- config.signers = vec![&offline_presigner];
- config.command = CliCommand::Transfer {
- amount: SpendAmount::Some(LAMPORTS_PER_SOL / 2),
- to: recipient_pubkey,
- from: 0,
- sign_only: false,
- dump_transaction_message: false,
- allow_unfunded_recipient: true,
- no_wait: false,
- blockhash_query: BlockhashQuery::FeeCalculator(blockhash_query::Source::Cluster, blockhash),
- nonce_account: None,
- nonce_authority: 0,
- memo: None,
- fee_payer: 0,
- derived_address_seed: None,
- derived_address_program_id: None,
- compute_unit_price: None,
- };
- process_command(&config).unwrap();
- check_balance!(
- LAMPORTS_PER_SOL / 2 - fee_one_sig,
- &rpc_client,
- &offline_pubkey
- );
- check_balance!(1_500_000_000, &rpc_client, &recipient_pubkey);
- // Create nonce account
- let nonce_account = keypair_from_seed(&[3u8; 32]).unwrap();
- let minimum_nonce_balance = rpc_client
- .get_minimum_balance_for_rent_exemption(NonceState::size())
- .unwrap();
- config.signers = vec![&default_signer, &nonce_account];
- config.command = CliCommand::CreateNonceAccount {
- nonce_account: 1,
- seed: None,
- nonce_authority: None,
- memo: None,
- amount: SpendAmount::Some(minimum_nonce_balance),
- compute_unit_price: None,
- };
- process_command(&config).unwrap();
- check_balance!(
- 4 * LAMPORTS_PER_SOL - fee_one_sig - fee_two_sig - minimum_nonce_balance,
- &rpc_client,
- &sender_pubkey,
- );
- // Fetch nonce hash
- let nonce_hash = solana_rpc_client_nonce_utils::get_account_with_commitment(
- &rpc_client,
- &nonce_account.pubkey(),
- CommitmentConfig::processed(),
- )
- .and_then(|ref a| solana_rpc_client_nonce_utils::data_from_account(a))
- .unwrap()
- .blockhash();
- // Nonced transfer
- config.signers = vec![&default_signer];
- config.command = CliCommand::Transfer {
- amount: SpendAmount::Some(LAMPORTS_PER_SOL),
- to: recipient_pubkey,
- from: 0,
- sign_only: false,
- dump_transaction_message: false,
- allow_unfunded_recipient: true,
- no_wait: false,
- blockhash_query: BlockhashQuery::FeeCalculator(
- blockhash_query::Source::NonceAccount(nonce_account.pubkey()),
- nonce_hash,
- ),
- nonce_account: Some(nonce_account.pubkey()),
- nonce_authority: 0,
- memo: None,
- fee_payer: 0,
- derived_address_seed: None,
- derived_address_program_id: None,
- compute_unit_price: None,
- };
- process_command(&config).unwrap();
- check_balance!(
- 3 * LAMPORTS_PER_SOL - 2 * fee_one_sig - fee_two_sig - minimum_nonce_balance,
- &rpc_client,
- &sender_pubkey,
- );
- check_balance!(2_500_000_000, &rpc_client, &recipient_pubkey);
- let new_nonce_hash = solana_rpc_client_nonce_utils::get_account_with_commitment(
- &rpc_client,
- &nonce_account.pubkey(),
- CommitmentConfig::processed(),
- )
- .and_then(|ref a| solana_rpc_client_nonce_utils::data_from_account(a))
- .unwrap()
- .blockhash();
- assert_ne!(nonce_hash, new_nonce_hash);
- // Assign nonce authority to offline
- config.signers = vec![&default_signer];
- config.command = CliCommand::AuthorizeNonceAccount {
- nonce_account: nonce_account.pubkey(),
- nonce_authority: 0,
- memo: None,
- new_authority: offline_pubkey,
- compute_unit_price: None,
- };
- process_command(&config).unwrap();
- check_balance!(
- 3 * LAMPORTS_PER_SOL - 3 * fee_one_sig - fee_two_sig - minimum_nonce_balance,
- &rpc_client,
- &sender_pubkey,
- );
- // Fetch nonce hash
- let nonce_hash = solana_rpc_client_nonce_utils::get_account_with_commitment(
- &rpc_client,
- &nonce_account.pubkey(),
- CommitmentConfig::processed(),
- )
- .and_then(|ref a| solana_rpc_client_nonce_utils::data_from_account(a))
- .unwrap()
- .blockhash();
- // Offline, nonced transfer
- offline.signers = vec![&default_offline_signer];
- offline.command = CliCommand::Transfer {
- amount: SpendAmount::Some(400_000_000),
- to: recipient_pubkey,
- from: 0,
- sign_only: true,
- dump_transaction_message: false,
- allow_unfunded_recipient: true,
- no_wait: false,
- blockhash_query: BlockhashQuery::None(nonce_hash),
- nonce_account: Some(nonce_account.pubkey()),
- nonce_authority: 0,
- memo: None,
- fee_payer: 0,
- derived_address_seed: None,
- derived_address_program_id: None,
- compute_unit_price: None,
- };
- let sign_only_reply = process_command(&offline).unwrap();
- let sign_only = parse_sign_only_reply_string(&sign_only_reply);
- assert!(sign_only.has_all_signers());
- let offline_presigner = sign_only.presigner_of(&offline_pubkey).unwrap();
- config.signers = vec![&offline_presigner];
- config.command = CliCommand::Transfer {
- amount: SpendAmount::Some(400_000_000),
- to: recipient_pubkey,
- from: 0,
- sign_only: false,
- dump_transaction_message: false,
- allow_unfunded_recipient: true,
- no_wait: false,
- blockhash_query: BlockhashQuery::FeeCalculator(
- blockhash_query::Source::NonceAccount(nonce_account.pubkey()),
- sign_only.blockhash,
- ),
- nonce_account: Some(nonce_account.pubkey()),
- nonce_authority: 0,
- memo: None,
- fee_payer: 0,
- derived_address_seed: None,
- derived_address_program_id: None,
- compute_unit_price: None,
- };
- process_command(&config).unwrap();
- check_balance!(
- LAMPORTS_PER_SOL / 10 - 2 * fee_one_sig,
- &rpc_client,
- &offline_pubkey
- );
- check_balance!(2_900_000_000, &rpc_client, &recipient_pubkey);
- }
- #[test]
- fn test_transfer_multisession_signing() {
- agave_logger::setup();
- let fee_one_sig = FeeStructure::default().get_max_fee(1, 0);
- let fee_two_sig = FeeStructure::default().get_max_fee(2, 0);
- let mint_keypair = Keypair::new();
- let mint_pubkey = mint_keypair.pubkey();
- let faucet_addr = run_local_faucet_with_unique_port_for_tests(mint_keypair);
- let test_validator = TestValidator::with_custom_fees(
- mint_pubkey,
- fee_one_sig,
- Some(faucet_addr),
- SocketAddrSpace::Unspecified,
- );
- let to_pubkey = Pubkey::from([1u8; 32]);
- let offline_from_signer = keypair_from_seed(&[2u8; 32]).unwrap();
- let offline_fee_payer_signer = keypair_from_seed(&[3u8; 32]).unwrap();
- let from_null_signer = NullSigner::new(&offline_from_signer.pubkey());
- // Setup accounts
- let rpc_client =
- RpcClient::new_with_commitment(test_validator.rpc_url(), CommitmentConfig::processed());
- request_and_confirm_airdrop(
- &rpc_client,
- &CliConfig::recent_for_tests(),
- &offline_from_signer.pubkey(),
- 43 * LAMPORTS_PER_SOL,
- )
- .unwrap();
- request_and_confirm_airdrop(
- &rpc_client,
- &CliConfig::recent_for_tests(),
- &offline_fee_payer_signer.pubkey(),
- LAMPORTS_PER_SOL + 2 * fee_two_sig,
- )
- .unwrap();
- check_balance!(
- 43 * LAMPORTS_PER_SOL,
- &rpc_client,
- &offline_from_signer.pubkey(),
- );
- check_balance!(
- LAMPORTS_PER_SOL + 2 * fee_two_sig,
- &rpc_client,
- &offline_fee_payer_signer.pubkey(),
- );
- check_balance!(0, &rpc_client, &to_pubkey);
- check_ready(&rpc_client);
- let blockhash = rpc_client.get_latest_blockhash().unwrap();
- // Offline fee-payer signs first
- let mut fee_payer_config = CliConfig::recent_for_tests();
- fee_payer_config.json_rpc_url = String::default();
- fee_payer_config.signers = vec![&offline_fee_payer_signer, &from_null_signer];
- // Verify we cannot contact the cluster
- fee_payer_config.command = CliCommand::ClusterVersion;
- process_command(&fee_payer_config).unwrap_err();
- fee_payer_config.command = CliCommand::Transfer {
- amount: SpendAmount::Some(42 * LAMPORTS_PER_SOL),
- to: to_pubkey,
- from: 1,
- sign_only: true,
- dump_transaction_message: false,
- allow_unfunded_recipient: true,
- no_wait: false,
- blockhash_query: BlockhashQuery::None(blockhash),
- nonce_account: None,
- nonce_authority: 0,
- memo: None,
- fee_payer: 0,
- derived_address_seed: None,
- derived_address_program_id: None,
- compute_unit_price: None,
- };
- fee_payer_config.output_format = OutputFormat::JsonCompact;
- let sign_only_reply = process_command(&fee_payer_config).unwrap();
- let sign_only = parse_sign_only_reply_string(&sign_only_reply);
- assert!(!sign_only.has_all_signers());
- let fee_payer_presigner = sign_only
- .presigner_of(&offline_fee_payer_signer.pubkey())
- .unwrap();
- // Now the offline fund source
- let mut from_config = CliConfig::recent_for_tests();
- from_config.json_rpc_url = String::default();
- from_config.signers = vec![&fee_payer_presigner, &offline_from_signer];
- // Verify we cannot contact the cluster
- from_config.command = CliCommand::ClusterVersion;
- process_command(&from_config).unwrap_err();
- from_config.command = CliCommand::Transfer {
- amount: SpendAmount::Some(42 * LAMPORTS_PER_SOL),
- to: to_pubkey,
- from: 1,
- sign_only: true,
- dump_transaction_message: false,
- allow_unfunded_recipient: true,
- no_wait: false,
- blockhash_query: BlockhashQuery::None(blockhash),
- nonce_account: None,
- nonce_authority: 0,
- memo: None,
- fee_payer: 0,
- derived_address_seed: None,
- derived_address_program_id: None,
- compute_unit_price: None,
- };
- from_config.output_format = OutputFormat::JsonCompact;
- let sign_only_reply = process_command(&from_config).unwrap();
- let sign_only = parse_sign_only_reply_string(&sign_only_reply);
- assert!(sign_only.has_all_signers());
- let from_presigner = sign_only
- .presigner_of(&offline_from_signer.pubkey())
- .unwrap();
- // Finally submit to the cluster
- let mut config = CliConfig::recent_for_tests();
- config.json_rpc_url = test_validator.rpc_url();
- config.signers = vec![&fee_payer_presigner, &from_presigner];
- config.command = CliCommand::Transfer {
- amount: SpendAmount::Some(42 * LAMPORTS_PER_SOL),
- to: to_pubkey,
- from: 1,
- sign_only: false,
- dump_transaction_message: false,
- allow_unfunded_recipient: true,
- no_wait: false,
- blockhash_query: BlockhashQuery::FeeCalculator(blockhash_query::Source::Cluster, blockhash),
- nonce_account: None,
- nonce_authority: 0,
- memo: None,
- fee_payer: 0,
- derived_address_seed: None,
- derived_address_program_id: None,
- compute_unit_price: None,
- };
- process_command(&config).unwrap();
- check_balance!(LAMPORTS_PER_SOL, &rpc_client, &offline_from_signer.pubkey(),);
- check_balance!(
- LAMPORTS_PER_SOL + fee_two_sig,
- &rpc_client,
- &offline_fee_payer_signer.pubkey(),
- );
- check_balance!(42 * LAMPORTS_PER_SOL, &rpc_client, &to_pubkey);
- }
- #[test_case(None; "default")]
- #[test_case(Some(100_000); "with_compute_unit_price")]
- fn test_transfer_all(compute_unit_price: Option<u64>) {
- agave_logger::setup();
- let lamports_per_signature = FeeStructure::default().get_max_fee(1, 0);
- let mint_keypair = Keypair::new();
- let mint_pubkey = mint_keypair.pubkey();
- let faucet_addr = run_local_faucet_with_unique_port_for_tests(mint_keypair);
- let test_validator = TestValidator::with_custom_fees(
- mint_pubkey,
- lamports_per_signature,
- Some(faucet_addr),
- SocketAddrSpace::Unspecified,
- );
- let rpc_client =
- RpcClient::new_with_commitment(test_validator.rpc_url(), CommitmentConfig::processed());
- let default_signer = Keypair::new();
- let recipient_pubkey = Pubkey::from([1u8; 32]);
- let fee = {
- let mut instructions = vec![system_instruction::transfer(
- &default_signer.pubkey(),
- &recipient_pubkey,
- 0,
- )];
- if let Some(compute_unit_price) = compute_unit_price {
- // This is brittle and will need to be updated if the compute unit
- // limit for the system program or compute budget program are changed,
- // or if they're converted to BPF.
- // See `solana_system_program::system_processor::DEFAULT_COMPUTE_UNITS`
- // and `solana_compute_budget_program::DEFAULT_COMPUTE_UNITS`
- instructions.push(ComputeBudgetInstruction::set_compute_unit_limit(450));
- instructions.push(ComputeBudgetInstruction::set_compute_unit_price(
- compute_unit_price,
- ));
- }
- let blockhash = rpc_client.get_latest_blockhash().unwrap();
- let sample_message =
- Message::new_with_blockhash(&instructions, Some(&default_signer.pubkey()), &blockhash);
- rpc_client.get_fee_for_message(&sample_message).unwrap()
- };
- let mut config = CliConfig::recent_for_tests();
- config.json_rpc_url = test_validator.rpc_url();
- config.signers = vec![&default_signer];
- let sender_pubkey = config.signers[0].pubkey();
- request_and_confirm_airdrop(&rpc_client, &config, &sender_pubkey, 500_000).unwrap();
- check_balance!(500_000, &rpc_client, &sender_pubkey);
- check_balance!(0, &rpc_client, &recipient_pubkey);
- check_ready(&rpc_client);
- // Plain ole transfer
- config.command = CliCommand::Transfer {
- amount: SpendAmount::All,
- to: recipient_pubkey,
- from: 0,
- sign_only: false,
- dump_transaction_message: false,
- allow_unfunded_recipient: true,
- no_wait: false,
- blockhash_query: BlockhashQuery::All(blockhash_query::Source::Cluster),
- nonce_account: None,
- nonce_authority: 0,
- memo: None,
- fee_payer: 0,
- derived_address_seed: None,
- derived_address_program_id: None,
- compute_unit_price,
- };
- process_command(&config).unwrap();
- check_balance!(0, &rpc_client, &sender_pubkey);
- check_balance!(500_000 - fee, &rpc_client, &recipient_pubkey);
- }
- #[test]
- fn test_transfer_unfunded_recipient() {
- agave_logger::setup();
- let mint_keypair = Keypair::new();
- let mint_pubkey = mint_keypair.pubkey();
- let faucet_addr = run_local_faucet_with_unique_port_for_tests(mint_keypair);
- let test_validator = TestValidator::with_custom_fees(
- mint_pubkey,
- 1,
- Some(faucet_addr),
- SocketAddrSpace::Unspecified,
- );
- let rpc_client =
- RpcClient::new_with_commitment(test_validator.rpc_url(), CommitmentConfig::processed());
- let default_signer = Keypair::new();
- let mut config = CliConfig::recent_for_tests();
- config.json_rpc_url = test_validator.rpc_url();
- config.signers = vec![&default_signer];
- config.send_transaction_config.skip_preflight = false;
- let sender_pubkey = config.signers[0].pubkey();
- let recipient_pubkey = Pubkey::from([1u8; 32]);
- request_and_confirm_airdrop(&rpc_client, &config, &sender_pubkey, 50_000).unwrap();
- check_balance!(50_000, &rpc_client, &sender_pubkey);
- check_balance!(0, &rpc_client, &recipient_pubkey);
- check_ready(&rpc_client);
- // Plain ole transfer
- config.command = CliCommand::Transfer {
- amount: SpendAmount::All,
- to: recipient_pubkey,
- from: 0,
- sign_only: false,
- dump_transaction_message: false,
- allow_unfunded_recipient: false,
- no_wait: false,
- blockhash_query: BlockhashQuery::All(blockhash_query::Source::Cluster),
- nonce_account: None,
- nonce_authority: 0,
- memo: None,
- fee_payer: 0,
- derived_address_seed: None,
- derived_address_program_id: None,
- compute_unit_price: None,
- };
- // Expect failure due to unfunded recipient and the lack of the `allow_unfunded_recipient` flag
- process_command(&config).unwrap_err();
- }
- #[test]
- fn test_transfer_with_seed() {
- agave_logger::setup();
- let fee = FeeStructure::default().get_max_fee(1, 0);
- let mint_keypair = Keypair::new();
- let mint_pubkey = mint_keypair.pubkey();
- let faucet_addr = run_local_faucet_with_unique_port_for_tests(mint_keypair);
- let test_validator = TestValidator::with_custom_fees(
- mint_pubkey,
- fee,
- Some(faucet_addr),
- SocketAddrSpace::Unspecified,
- );
- let rpc_client =
- RpcClient::new_with_commitment(test_validator.rpc_url(), CommitmentConfig::processed());
- let default_signer = Keypair::new();
- let mut config = CliConfig::recent_for_tests();
- config.json_rpc_url = test_validator.rpc_url();
- config.signers = vec![&default_signer];
- let sender_pubkey = config.signers[0].pubkey();
- let recipient_pubkey = Pubkey::from([1u8; 32]);
- let derived_address_seed = "seed".to_string();
- let derived_address_program_id = stake::program::id();
- let derived_address = Pubkey::create_with_seed(
- &sender_pubkey,
- &derived_address_seed,
- &derived_address_program_id,
- )
- .unwrap();
- request_and_confirm_airdrop(&rpc_client, &config, &sender_pubkey, LAMPORTS_PER_SOL).unwrap();
- request_and_confirm_airdrop(&rpc_client, &config, &derived_address, 5 * LAMPORTS_PER_SOL)
- .unwrap();
- check_balance!(LAMPORTS_PER_SOL, &rpc_client, &sender_pubkey);
- check_balance!(5 * LAMPORTS_PER_SOL, &rpc_client, &derived_address);
- check_balance!(0, &rpc_client, &recipient_pubkey);
- check_ready(&rpc_client);
- // Transfer with seed
- config.command = CliCommand::Transfer {
- amount: SpendAmount::Some(5 * LAMPORTS_PER_SOL),
- to: recipient_pubkey,
- from: 0,
- sign_only: false,
- dump_transaction_message: false,
- allow_unfunded_recipient: true,
- no_wait: false,
- blockhash_query: BlockhashQuery::All(blockhash_query::Source::Cluster),
- nonce_account: None,
- nonce_authority: 0,
- memo: None,
- fee_payer: 0,
- derived_address_seed: Some(derived_address_seed),
- derived_address_program_id: Some(derived_address_program_id),
- compute_unit_price: None,
- };
- process_command(&config).unwrap();
- check_balance!(LAMPORTS_PER_SOL - fee, &rpc_client, &sender_pubkey);
- check_balance!(5 * LAMPORTS_PER_SOL, &rpc_client, &recipient_pubkey);
- check_balance!(0, &rpc_client, &derived_address);
- }
|