| 
									
										
										
										
											2020-02-07 12:16:35 -07:00
										 |  |  | use solana_cli::{
 | 
					
						
							|  |  |  |     cli::{process_command, request_and_confirm_airdrop, CliCommand, CliConfig},
 | 
					
						
							| 
									
										
										
										
											2020-05-14 12:24:14 -06:00
										 |  |  |     spend_utils::SpendAmount,
 | 
					
						
							| 
									
										
										
										
											2020-06-17 12:18:48 -06:00
										 |  |  |     test_utils::{check_ready, check_recent_balance},
 | 
					
						
							| 
									
										
										
										
											2020-02-07 12:16:35 -07:00
										 |  |  | };
 | 
					
						
							| 
									
										
										
										
											2020-09-22 20:29:32 -06:00
										 |  |  | use solana_cli_output::{parse_sign_only_reply_string, OutputFormat};
 | 
					
						
							| 
									
										
										
										
											2020-09-22 16:06:14 -06:00
										 |  |  | use solana_client::{
 | 
					
						
							|  |  |  |     blockhash_query::{self, BlockhashQuery},
 | 
					
						
							|  |  |  |     nonce_utils,
 | 
					
						
							|  |  |  |     rpc_client::RpcClient,
 | 
					
						
							|  |  |  | };
 | 
					
						
							| 
									
										
										
										
											2020-11-16 23:27:36 -07:00
										 |  |  | use solana_core::test_validator::TestValidator;
 | 
					
						
							| 
									
										
										
										
											2020-02-07 12:16:35 -07:00
										 |  |  | use solana_faucet::faucet::run_local_faucet;
 | 
					
						
							|  |  |  | use solana_sdk::{
 | 
					
						
							| 
									
										
										
										
											2020-06-17 12:18:48 -06:00
										 |  |  |     commitment_config::CommitmentConfig,
 | 
					
						
							| 
									
										
										
										
											2020-03-10 13:00:15 -06:00
										 |  |  |     nonce::State as NonceState,
 | 
					
						
							| 
									
										
										
										
											2020-02-07 12:16:35 -07:00
										 |  |  |     pubkey::Pubkey,
 | 
					
						
							| 
									
										
										
										
											2020-03-18 21:49:38 -06:00
										 |  |  |     signature::{keypair_from_seed, Keypair, NullSigner, Signer},
 | 
					
						
							| 
									
										
										
										
											2021-06-15 18:04:00 +02:00
										 |  |  |     stake,
 | 
					
						
							| 
									
										
										
										
											2020-02-07 12:16:35 -07:00
										 |  |  | };
 | 
					
						
							| 
									
										
										
										
											2021-07-23 15:25:03 +00:00
										 |  |  | use solana_streamer::socket::SocketAddrSpace;
 | 
					
						
							| 
									
										
										
										
											2020-02-07 12:16:35 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | #[test]
 | 
					
						
							|  |  |  | fn test_transfer() {
 | 
					
						
							| 
									
										
										
										
											2020-11-16 23:27:36 -07:00
										 |  |  |     solana_logger::setup();
 | 
					
						
							| 
									
										
										
										
											2020-12-08 23:18:27 -08:00
										 |  |  |     let mint_keypair = Keypair::new();
 | 
					
						
							| 
									
										
										
										
											2021-04-15 00:25:23 -06:00
										 |  |  |     let mint_pubkey = mint_keypair.pubkey();
 | 
					
						
							| 
									
										
										
										
											2021-01-28 12:11:53 -08:00
										 |  |  |     let faucet_addr = run_local_faucet(mint_keypair, None);
 | 
					
						
							| 
									
										
										
										
											2021-07-23 15:25:03 +00:00
										 |  |  |     let test_validator = TestValidator::with_custom_fees(
 | 
					
						
							|  |  |  |         mint_pubkey,
 | 
					
						
							|  |  |  |         1,
 | 
					
						
							|  |  |  |         Some(faucet_addr),
 | 
					
						
							|  |  |  |         SocketAddrSpace::Unspecified,
 | 
					
						
							|  |  |  |     );
 | 
					
						
							| 
									
										
										
										
											2020-02-07 12:16:35 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-19 15:33:03 -07:00
										 |  |  |     let rpc_client =
 | 
					
						
							| 
									
										
										
										
											2021-01-26 12:23:07 -07:00
										 |  |  |         RpcClient::new_with_commitment(test_validator.rpc_url(), CommitmentConfig::processed());
 | 
					
						
							| 
									
										
										
										
											2020-02-07 12:16:35 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 |  |  |     let default_signer = Keypair::new();
 | 
					
						
							|  |  |  |     let default_offline_signer = Keypair::new();
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-17 12:18:48 -06:00
										 |  |  |     let mut config = CliConfig::recent_for_tests();
 | 
					
						
							| 
									
										
										
										
											2020-11-25 17:00:47 -08:00
										 |  |  |     config.json_rpc_url = test_validator.rpc_url();
 | 
					
						
							| 
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 |  |  |     config.signers = vec![&default_signer];
 | 
					
						
							| 
									
										
										
										
											2020-02-07 12:16:35 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 |  |  |     let sender_pubkey = config.signers[0].pubkey();
 | 
					
						
							| 
									
										
										
										
											2020-02-07 12:16:35 -07:00
										 |  |  |     let recipient_pubkey = Pubkey::new(&[1u8; 32]);
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-15 00:25:23 -06:00
										 |  |  |     request_and_confirm_airdrop(&rpc_client, &config, &sender_pubkey, 50_000).unwrap();
 | 
					
						
							| 
									
										
										
										
											2020-06-17 12:18:48 -06:00
										 |  |  |     check_recent_balance(50_000, &rpc_client, &sender_pubkey);
 | 
					
						
							|  |  |  |     check_recent_balance(0, &rpc_client, &recipient_pubkey);
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     check_ready(&rpc_client);
 | 
					
						
							| 
									
										
										
										
											2020-02-07 12:16:35 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |     // Plain ole transfer
 | 
					
						
							|  |  |  |     config.command = CliCommand::Transfer {
 | 
					
						
							| 
									
										
										
										
											2020-05-14 12:24:14 -06:00
										 |  |  |         amount: SpendAmount::Some(10),
 | 
					
						
							| 
									
										
										
										
											2020-02-07 12:16:35 -07:00
										 |  |  |         to: recipient_pubkey,
 | 
					
						
							| 
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 |  |  |         from: 0,
 | 
					
						
							| 
									
										
										
										
											2020-02-07 12:16:35 -07:00
										 |  |  |         sign_only: false,
 | 
					
						
							| 
									
										
										
										
											2021-03-12 19:37:39 -07:00
										 |  |  |         dump_transaction_message: false,
 | 
					
						
							| 
									
										
										
										
											2021-03-22 11:10:44 -07:00
										 |  |  |         allow_unfunded_recipient: true,
 | 
					
						
							| 
									
										
										
										
											2020-04-08 23:46:19 -06:00
										 |  |  |         no_wait: false,
 | 
					
						
							| 
									
										
										
										
											2020-03-11 12:14:15 -06:00
										 |  |  |         blockhash_query: BlockhashQuery::All(blockhash_query::Source::Cluster),
 | 
					
						
							| 
									
										
										
										
											2020-02-07 12:16:35 -07:00
										 |  |  |         nonce_account: None,
 | 
					
						
							| 
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 |  |  |         nonce_authority: 0,
 | 
					
						
							| 
									
										
										
										
											2021-04-05 13:53:50 -07:00
										 |  |  |         memo: None,
 | 
					
						
							| 
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 |  |  |         fee_payer: 0,
 | 
					
						
							| 
									
										
										
										
											2021-02-18 00:08:12 -07:00
										 |  |  |         derived_address_seed: None,
 | 
					
						
							|  |  |  |         derived_address_program_id: None,
 | 
					
						
							| 
									
										
										
										
											2020-02-07 12:16:35 -07:00
										 |  |  |     };
 | 
					
						
							|  |  |  |     process_command(&config).unwrap();
 | 
					
						
							| 
									
										
										
										
											2020-06-17 12:18:48 -06:00
										 |  |  |     check_recent_balance(49_989, &rpc_client, &sender_pubkey);
 | 
					
						
							|  |  |  |     check_recent_balance(10, &rpc_client, &recipient_pubkey);
 | 
					
						
							| 
									
										
										
										
											2020-02-07 12:16:35 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-14 12:24:14 -06:00
										 |  |  |     // Plain ole transfer, failure due to InsufficientFundsForSpendAndFee
 | 
					
						
							|  |  |  |     config.command = CliCommand::Transfer {
 | 
					
						
							|  |  |  |         amount: SpendAmount::Some(49_989),
 | 
					
						
							|  |  |  |         to: recipient_pubkey,
 | 
					
						
							|  |  |  |         from: 0,
 | 
					
						
							|  |  |  |         sign_only: false,
 | 
					
						
							| 
									
										
										
										
											2021-03-12 19:37:39 -07:00
										 |  |  |         dump_transaction_message: false,
 | 
					
						
							| 
									
										
										
										
											2021-03-22 11:10:44 -07:00
										 |  |  |         allow_unfunded_recipient: true,
 | 
					
						
							| 
									
										
										
										
											2020-05-14 12:24:14 -06:00
										 |  |  |         no_wait: false,
 | 
					
						
							|  |  |  |         blockhash_query: BlockhashQuery::All(blockhash_query::Source::Cluster),
 | 
					
						
							|  |  |  |         nonce_account: None,
 | 
					
						
							|  |  |  |         nonce_authority: 0,
 | 
					
						
							| 
									
										
										
										
											2021-04-05 13:53:50 -07:00
										 |  |  |         memo: None,
 | 
					
						
							| 
									
										
										
										
											2020-05-14 12:24:14 -06:00
										 |  |  |         fee_payer: 0,
 | 
					
						
							| 
									
										
										
										
											2021-02-18 00:08:12 -07:00
										 |  |  |         derived_address_seed: None,
 | 
					
						
							|  |  |  |         derived_address_program_id: None,
 | 
					
						
							| 
									
										
										
										
											2020-05-14 12:24:14 -06:00
										 |  |  |     };
 | 
					
						
							|  |  |  |     assert!(process_command(&config).is_err());
 | 
					
						
							| 
									
										
										
										
											2020-06-17 12:18:48 -06:00
										 |  |  |     check_recent_balance(49_989, &rpc_client, &sender_pubkey);
 | 
					
						
							|  |  |  |     check_recent_balance(10, &rpc_client, &recipient_pubkey);
 | 
					
						
							| 
									
										
										
										
											2020-05-14 12:24:14 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-17 12:18:48 -06:00
										 |  |  |     let mut offline = CliConfig::recent_for_tests();
 | 
					
						
							| 
									
										
										
										
											2020-02-07 12:16:35 -07:00
										 |  |  |     offline.json_rpc_url = String::default();
 | 
					
						
							| 
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 |  |  |     offline.signers = vec![&default_offline_signer];
 | 
					
						
							| 
									
										
										
										
											2020-02-07 12:16:35 -07:00
										 |  |  |     // Verify we cannot contact the cluster
 | 
					
						
							|  |  |  |     offline.command = CliCommand::ClusterVersion;
 | 
					
						
							|  |  |  |     process_command(&offline).unwrap_err();
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 |  |  |     let offline_pubkey = offline.signers[0].pubkey();
 | 
					
						
							| 
									
										
										
										
											2021-04-15 00:25:23 -06:00
										 |  |  |     request_and_confirm_airdrop(&rpc_client, &offline, &offline_pubkey, 50).unwrap();
 | 
					
						
							| 
									
										
										
										
											2020-06-17 12:18:48 -06:00
										 |  |  |     check_recent_balance(50, &rpc_client, &offline_pubkey);
 | 
					
						
							| 
									
										
										
										
											2020-02-07 12:16:35 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |     // Offline transfer
 | 
					
						
							| 
									
										
										
										
											2021-01-19 15:33:03 -07:00
										 |  |  |     let (blockhash, _) = rpc_client.get_recent_blockhash().unwrap();
 | 
					
						
							| 
									
										
										
										
											2020-02-07 12:16:35 -07:00
										 |  |  |     offline.command = CliCommand::Transfer {
 | 
					
						
							| 
									
										
										
										
											2020-05-14 12:24:14 -06:00
										 |  |  |         amount: SpendAmount::Some(10),
 | 
					
						
							| 
									
										
										
										
											2020-02-07 12:16:35 -07:00
										 |  |  |         to: recipient_pubkey,
 | 
					
						
							| 
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 |  |  |         from: 0,
 | 
					
						
							| 
									
										
										
										
											2020-02-07 12:16:35 -07:00
										 |  |  |         sign_only: true,
 | 
					
						
							| 
									
										
										
										
											2021-03-12 19:37:39 -07:00
										 |  |  |         dump_transaction_message: false,
 | 
					
						
							| 
									
										
										
										
											2021-03-22 11:10:44 -07:00
										 |  |  |         allow_unfunded_recipient: true,
 | 
					
						
							| 
									
										
										
										
											2020-04-08 23:46:19 -06:00
										 |  |  |         no_wait: false,
 | 
					
						
							| 
									
										
										
										
											2020-03-11 12:14:15 -06:00
										 |  |  |         blockhash_query: BlockhashQuery::None(blockhash),
 | 
					
						
							| 
									
										
										
										
											2020-02-07 12:16:35 -07:00
										 |  |  |         nonce_account: None,
 | 
					
						
							| 
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 |  |  |         nonce_authority: 0,
 | 
					
						
							| 
									
										
										
										
											2021-04-05 13:53:50 -07:00
										 |  |  |         memo: None,
 | 
					
						
							| 
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 |  |  |         fee_payer: 0,
 | 
					
						
							| 
									
										
										
										
											2021-02-18 00:08:12 -07:00
										 |  |  |         derived_address_seed: None,
 | 
					
						
							|  |  |  |         derived_address_program_id: None,
 | 
					
						
							| 
									
										
										
										
											2020-02-07 12:16:35 -07:00
										 |  |  |     };
 | 
					
						
							| 
									
										
										
										
											2020-05-07 07:21:48 +03:00
										 |  |  |     offline.output_format = OutputFormat::JsonCompact;
 | 
					
						
							| 
									
										
										
										
											2020-02-07 12:16:35 -07:00
										 |  |  |     let sign_only_reply = process_command(&offline).unwrap();
 | 
					
						
							| 
									
										
										
										
											2020-03-18 21:49:38 -06:00
										 |  |  |     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();
 | 
					
						
							| 
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 |  |  |     config.signers = vec![&offline_presigner];
 | 
					
						
							| 
									
										
										
										
											2020-02-07 12:16:35 -07:00
										 |  |  |     config.command = CliCommand::Transfer {
 | 
					
						
							| 
									
										
										
										
											2020-05-14 12:24:14 -06:00
										 |  |  |         amount: SpendAmount::Some(10),
 | 
					
						
							| 
									
										
										
										
											2020-02-07 12:16:35 -07:00
										 |  |  |         to: recipient_pubkey,
 | 
					
						
							| 
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 |  |  |         from: 0,
 | 
					
						
							| 
									
										
										
										
											2020-02-07 12:16:35 -07:00
										 |  |  |         sign_only: false,
 | 
					
						
							| 
									
										
										
										
											2021-03-12 19:37:39 -07:00
										 |  |  |         dump_transaction_message: false,
 | 
					
						
							| 
									
										
										
										
											2021-03-22 11:10:44 -07:00
										 |  |  |         allow_unfunded_recipient: true,
 | 
					
						
							| 
									
										
										
										
											2020-04-08 23:46:19 -06:00
										 |  |  |         no_wait: false,
 | 
					
						
							| 
									
										
										
										
											2020-03-11 12:14:15 -06:00
										 |  |  |         blockhash_query: BlockhashQuery::FeeCalculator(blockhash_query::Source::Cluster, blockhash),
 | 
					
						
							| 
									
										
										
										
											2020-02-07 12:16:35 -07:00
										 |  |  |         nonce_account: None,
 | 
					
						
							| 
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 |  |  |         nonce_authority: 0,
 | 
					
						
							| 
									
										
										
										
											2021-04-05 13:53:50 -07:00
										 |  |  |         memo: None,
 | 
					
						
							| 
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 |  |  |         fee_payer: 0,
 | 
					
						
							| 
									
										
										
										
											2021-02-18 00:08:12 -07:00
										 |  |  |         derived_address_seed: None,
 | 
					
						
							|  |  |  |         derived_address_program_id: None,
 | 
					
						
							| 
									
										
										
										
											2020-02-07 12:16:35 -07:00
										 |  |  |     };
 | 
					
						
							|  |  |  |     process_command(&config).unwrap();
 | 
					
						
							| 
									
										
										
										
											2020-06-17 12:18:48 -06:00
										 |  |  |     check_recent_balance(39, &rpc_client, &offline_pubkey);
 | 
					
						
							|  |  |  |     check_recent_balance(20, &rpc_client, &recipient_pubkey);
 | 
					
						
							| 
									
										
										
										
											2020-02-07 12:16:35 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |     // Create nonce account
 | 
					
						
							|  |  |  |     let nonce_account = keypair_from_seed(&[3u8; 32]).unwrap();
 | 
					
						
							|  |  |  |     let minimum_nonce_balance = rpc_client
 | 
					
						
							| 
									
										
										
										
											2020-03-10 13:00:15 -06:00
										 |  |  |         .get_minimum_balance_for_rent_exemption(NonceState::size())
 | 
					
						
							| 
									
										
										
										
											2020-02-07 12:16:35 -07:00
										 |  |  |         .unwrap();
 | 
					
						
							| 
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 |  |  |     config.signers = vec![&default_signer, &nonce_account];
 | 
					
						
							| 
									
										
										
										
											2020-02-07 12:16:35 -07:00
										 |  |  |     config.command = CliCommand::CreateNonceAccount {
 | 
					
						
							| 
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 |  |  |         nonce_account: 1,
 | 
					
						
							| 
									
										
										
										
											2020-02-07 12:16:35 -07:00
										 |  |  |         seed: None,
 | 
					
						
							|  |  |  |         nonce_authority: None,
 | 
					
						
							| 
									
										
										
										
											2021-04-05 13:53:50 -07:00
										 |  |  |         memo: None,
 | 
					
						
							| 
									
										
										
										
											2020-05-14 12:24:14 -06:00
										 |  |  |         amount: SpendAmount::Some(minimum_nonce_balance),
 | 
					
						
							| 
									
										
										
										
											2020-02-07 12:16:35 -07:00
										 |  |  |     };
 | 
					
						
							|  |  |  |     process_command(&config).unwrap();
 | 
					
						
							| 
									
										
										
										
											2020-06-17 12:18:48 -06:00
										 |  |  |     check_recent_balance(49_987 - minimum_nonce_balance, &rpc_client, &sender_pubkey);
 | 
					
						
							| 
									
										
										
										
											2020-02-07 12:16:35 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |     // Fetch nonce hash
 | 
					
						
							| 
									
										
										
										
											2020-09-21 13:55:44 -06:00
										 |  |  |     let nonce_hash = nonce_utils::get_account_with_commitment(
 | 
					
						
							| 
									
										
										
										
											2020-06-17 12:18:48 -06:00
										 |  |  |         &rpc_client,
 | 
					
						
							|  |  |  |         &nonce_account.pubkey(),
 | 
					
						
							| 
									
										
										
										
											2021-01-26 12:23:07 -07:00
										 |  |  |         CommitmentConfig::processed(),
 | 
					
						
							| 
									
										
										
										
											2020-06-17 12:18:48 -06:00
										 |  |  |     )
 | 
					
						
							| 
									
										
										
										
											2020-09-21 13:55:44 -06:00
										 |  |  |     .and_then(|ref a| nonce_utils::data_from_account(a))
 | 
					
						
							| 
									
										
										
										
											2020-06-17 12:18:48 -06:00
										 |  |  |     .unwrap()
 | 
					
						
							|  |  |  |     .blockhash;
 | 
					
						
							| 
									
										
										
										
											2020-02-07 12:16:35 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |     // Nonced transfer
 | 
					
						
							| 
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 |  |  |     config.signers = vec![&default_signer];
 | 
					
						
							| 
									
										
										
										
											2020-02-07 12:16:35 -07:00
										 |  |  |     config.command = CliCommand::Transfer {
 | 
					
						
							| 
									
										
										
										
											2020-05-14 12:24:14 -06:00
										 |  |  |         amount: SpendAmount::Some(10),
 | 
					
						
							| 
									
										
										
										
											2020-02-07 12:16:35 -07:00
										 |  |  |         to: recipient_pubkey,
 | 
					
						
							| 
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 |  |  |         from: 0,
 | 
					
						
							| 
									
										
										
										
											2020-02-07 12:16:35 -07:00
										 |  |  |         sign_only: false,
 | 
					
						
							| 
									
										
										
										
											2021-03-12 19:37:39 -07:00
										 |  |  |         dump_transaction_message: false,
 | 
					
						
							| 
									
										
										
										
											2021-03-22 11:10:44 -07:00
										 |  |  |         allow_unfunded_recipient: true,
 | 
					
						
							| 
									
										
										
										
											2020-04-08 23:46:19 -06:00
										 |  |  |         no_wait: false,
 | 
					
						
							| 
									
										
										
										
											2020-03-11 12:14:15 -06:00
										 |  |  |         blockhash_query: BlockhashQuery::FeeCalculator(
 | 
					
						
							|  |  |  |             blockhash_query::Source::NonceAccount(nonce_account.pubkey()),
 | 
					
						
							|  |  |  |             nonce_hash,
 | 
					
						
							|  |  |  |         ),
 | 
					
						
							| 
									
										
										
										
											2020-02-07 12:16:35 -07:00
										 |  |  |         nonce_account: Some(nonce_account.pubkey()),
 | 
					
						
							| 
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 |  |  |         nonce_authority: 0,
 | 
					
						
							| 
									
										
										
										
											2021-04-05 13:53:50 -07:00
										 |  |  |         memo: None,
 | 
					
						
							| 
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 |  |  |         fee_payer: 0,
 | 
					
						
							| 
									
										
										
										
											2021-02-18 00:08:12 -07:00
										 |  |  |         derived_address_seed: None,
 | 
					
						
							|  |  |  |         derived_address_program_id: None,
 | 
					
						
							| 
									
										
										
										
											2020-02-07 12:16:35 -07:00
										 |  |  |     };
 | 
					
						
							|  |  |  |     process_command(&config).unwrap();
 | 
					
						
							| 
									
										
										
										
											2020-06-17 12:18:48 -06:00
										 |  |  |     check_recent_balance(49_976 - minimum_nonce_balance, &rpc_client, &sender_pubkey);
 | 
					
						
							|  |  |  |     check_recent_balance(30, &rpc_client, &recipient_pubkey);
 | 
					
						
							| 
									
										
										
										
											2020-09-21 13:55:44 -06:00
										 |  |  |     let new_nonce_hash = nonce_utils::get_account_with_commitment(
 | 
					
						
							| 
									
										
										
										
											2020-06-17 12:18:48 -06:00
										 |  |  |         &rpc_client,
 | 
					
						
							|  |  |  |         &nonce_account.pubkey(),
 | 
					
						
							| 
									
										
										
										
											2021-01-26 12:23:07 -07:00
										 |  |  |         CommitmentConfig::processed(),
 | 
					
						
							| 
									
										
										
										
											2020-06-17 12:18:48 -06:00
										 |  |  |     )
 | 
					
						
							| 
									
										
										
										
											2020-09-21 13:55:44 -06:00
										 |  |  |     .and_then(|ref a| nonce_utils::data_from_account(a))
 | 
					
						
							| 
									
										
										
										
											2020-06-17 12:18:48 -06:00
										 |  |  |     .unwrap()
 | 
					
						
							|  |  |  |     .blockhash;
 | 
					
						
							| 
									
										
										
										
											2020-02-07 12:16:35 -07:00
										 |  |  |     assert_ne!(nonce_hash, new_nonce_hash);
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-10 23:34:14 -07:00
										 |  |  |     // Assign nonce authority to offline
 | 
					
						
							| 
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 |  |  |     config.signers = vec![&default_signer];
 | 
					
						
							| 
									
										
										
										
											2020-02-10 23:34:14 -07:00
										 |  |  |     config.command = CliCommand::AuthorizeNonceAccount {
 | 
					
						
							|  |  |  |         nonce_account: nonce_account.pubkey(),
 | 
					
						
							| 
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 |  |  |         nonce_authority: 0,
 | 
					
						
							| 
									
										
										
										
											2021-04-05 13:53:50 -07:00
										 |  |  |         memo: None,
 | 
					
						
							| 
									
										
										
										
											2020-02-10 23:34:14 -07:00
										 |  |  |         new_authority: offline_pubkey,
 | 
					
						
							|  |  |  |     };
 | 
					
						
							|  |  |  |     process_command(&config).unwrap();
 | 
					
						
							| 
									
										
										
										
											2020-06-17 12:18:48 -06:00
										 |  |  |     check_recent_balance(49_975 - minimum_nonce_balance, &rpc_client, &sender_pubkey);
 | 
					
						
							| 
									
										
										
										
											2020-02-10 23:34:14 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |     // Fetch nonce hash
 | 
					
						
							| 
									
										
										
										
											2020-09-21 13:55:44 -06:00
										 |  |  |     let nonce_hash = nonce_utils::get_account_with_commitment(
 | 
					
						
							| 
									
										
										
										
											2020-06-17 12:18:48 -06:00
										 |  |  |         &rpc_client,
 | 
					
						
							|  |  |  |         &nonce_account.pubkey(),
 | 
					
						
							| 
									
										
										
										
											2021-01-26 12:23:07 -07:00
										 |  |  |         CommitmentConfig::processed(),
 | 
					
						
							| 
									
										
										
										
											2020-06-17 12:18:48 -06:00
										 |  |  |     )
 | 
					
						
							| 
									
										
										
										
											2020-09-21 13:55:44 -06:00
										 |  |  |     .and_then(|ref a| nonce_utils::data_from_account(a))
 | 
					
						
							| 
									
										
										
										
											2020-06-17 12:18:48 -06:00
										 |  |  |     .unwrap()
 | 
					
						
							|  |  |  |     .blockhash;
 | 
					
						
							| 
									
										
										
										
											2020-02-10 23:34:14 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |     // Offline, nonced transfer
 | 
					
						
							| 
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 |  |  |     offline.signers = vec![&default_offline_signer];
 | 
					
						
							| 
									
										
										
										
											2020-02-10 23:34:14 -07:00
										 |  |  |     offline.command = CliCommand::Transfer {
 | 
					
						
							| 
									
										
										
										
											2020-05-14 12:24:14 -06:00
										 |  |  |         amount: SpendAmount::Some(10),
 | 
					
						
							| 
									
										
										
										
											2020-02-10 23:34:14 -07:00
										 |  |  |         to: recipient_pubkey,
 | 
					
						
							| 
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 |  |  |         from: 0,
 | 
					
						
							| 
									
										
										
										
											2020-02-10 23:34:14 -07:00
										 |  |  |         sign_only: true,
 | 
					
						
							| 
									
										
										
										
											2021-03-12 19:37:39 -07:00
										 |  |  |         dump_transaction_message: false,
 | 
					
						
							| 
									
										
										
										
											2021-03-22 11:10:44 -07:00
										 |  |  |         allow_unfunded_recipient: true,
 | 
					
						
							| 
									
										
										
										
											2020-04-08 23:46:19 -06:00
										 |  |  |         no_wait: false,
 | 
					
						
							| 
									
										
										
										
											2020-03-11 12:14:15 -06:00
										 |  |  |         blockhash_query: BlockhashQuery::None(nonce_hash),
 | 
					
						
							| 
									
										
										
										
											2020-02-10 23:34:14 -07:00
										 |  |  |         nonce_account: Some(nonce_account.pubkey()),
 | 
					
						
							| 
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 |  |  |         nonce_authority: 0,
 | 
					
						
							| 
									
										
										
										
											2021-04-05 13:53:50 -07:00
										 |  |  |         memo: None,
 | 
					
						
							| 
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 |  |  |         fee_payer: 0,
 | 
					
						
							| 
									
										
										
										
											2021-02-18 00:08:12 -07:00
										 |  |  |         derived_address_seed: None,
 | 
					
						
							|  |  |  |         derived_address_program_id: None,
 | 
					
						
							| 
									
										
										
										
											2020-02-10 23:34:14 -07:00
										 |  |  |     };
 | 
					
						
							|  |  |  |     let sign_only_reply = process_command(&offline).unwrap();
 | 
					
						
							| 
									
										
										
										
											2020-03-18 21:49:38 -06:00
										 |  |  |     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();
 | 
					
						
							| 
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 |  |  |     config.signers = vec![&offline_presigner];
 | 
					
						
							| 
									
										
										
										
											2020-02-10 23:34:14 -07:00
										 |  |  |     config.command = CliCommand::Transfer {
 | 
					
						
							| 
									
										
										
										
											2020-05-14 12:24:14 -06:00
										 |  |  |         amount: SpendAmount::Some(10),
 | 
					
						
							| 
									
										
										
										
											2020-02-10 23:34:14 -07:00
										 |  |  |         to: recipient_pubkey,
 | 
					
						
							| 
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 |  |  |         from: 0,
 | 
					
						
							| 
									
										
										
										
											2020-02-10 23:34:14 -07:00
										 |  |  |         sign_only: false,
 | 
					
						
							| 
									
										
										
										
											2021-03-12 19:37:39 -07:00
										 |  |  |         dump_transaction_message: false,
 | 
					
						
							| 
									
										
										
										
											2021-03-22 11:10:44 -07:00
										 |  |  |         allow_unfunded_recipient: true,
 | 
					
						
							| 
									
										
										
										
											2020-04-08 23:46:19 -06:00
										 |  |  |         no_wait: false,
 | 
					
						
							| 
									
										
										
										
											2020-03-11 12:14:15 -06:00
										 |  |  |         blockhash_query: BlockhashQuery::FeeCalculator(
 | 
					
						
							|  |  |  |             blockhash_query::Source::NonceAccount(nonce_account.pubkey()),
 | 
					
						
							| 
									
										
										
										
											2020-03-18 21:49:38 -06:00
										 |  |  |             sign_only.blockhash,
 | 
					
						
							| 
									
										
										
										
											2020-03-11 12:14:15 -06:00
										 |  |  |         ),
 | 
					
						
							| 
									
										
										
										
											2020-02-10 23:34:14 -07:00
										 |  |  |         nonce_account: Some(nonce_account.pubkey()),
 | 
					
						
							| 
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 |  |  |         nonce_authority: 0,
 | 
					
						
							| 
									
										
										
										
											2021-04-05 13:53:50 -07:00
										 |  |  |         memo: None,
 | 
					
						
							| 
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 |  |  |         fee_payer: 0,
 | 
					
						
							| 
									
										
										
										
											2021-02-18 00:08:12 -07:00
										 |  |  |         derived_address_seed: None,
 | 
					
						
							|  |  |  |         derived_address_program_id: None,
 | 
					
						
							| 
									
										
										
										
											2020-02-10 23:34:14 -07:00
										 |  |  |     };
 | 
					
						
							|  |  |  |     process_command(&config).unwrap();
 | 
					
						
							| 
									
										
										
										
											2020-06-17 12:18:48 -06:00
										 |  |  |     check_recent_balance(28, &rpc_client, &offline_pubkey);
 | 
					
						
							|  |  |  |     check_recent_balance(40, &rpc_client, &recipient_pubkey);
 | 
					
						
							| 
									
										
										
										
											2020-02-07 12:16:35 -07:00
										 |  |  | }
 | 
					
						
							| 
									
										
										
										
											2020-03-18 21:49:38 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | #[test]
 | 
					
						
							|  |  |  | fn test_transfer_multisession_signing() {
 | 
					
						
							| 
									
										
										
										
											2020-11-16 23:27:36 -07:00
										 |  |  |     solana_logger::setup();
 | 
					
						
							| 
									
										
										
										
											2020-12-08 23:18:27 -08:00
										 |  |  |     let mint_keypair = Keypair::new();
 | 
					
						
							| 
									
										
										
										
											2021-04-15 00:25:23 -06:00
										 |  |  |     let mint_pubkey = mint_keypair.pubkey();
 | 
					
						
							| 
									
										
										
										
											2021-01-28 12:11:53 -08:00
										 |  |  |     let faucet_addr = run_local_faucet(mint_keypair, None);
 | 
					
						
							| 
									
										
										
										
											2021-07-23 15:25:03 +00:00
										 |  |  |     let test_validator = TestValidator::with_custom_fees(
 | 
					
						
							|  |  |  |         mint_pubkey,
 | 
					
						
							|  |  |  |         1,
 | 
					
						
							|  |  |  |         Some(faucet_addr),
 | 
					
						
							|  |  |  |         SocketAddrSpace::Unspecified,
 | 
					
						
							|  |  |  |     );
 | 
					
						
							| 
									
										
										
										
											2020-03-18 21:49:38 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  |     let to_pubkey = Pubkey::new(&[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
 | 
					
						
							| 
									
										
										
										
											2021-01-19 15:33:03 -07:00
										 |  |  |     let rpc_client =
 | 
					
						
							| 
									
										
										
										
											2021-01-26 12:23:07 -07:00
										 |  |  |         RpcClient::new_with_commitment(test_validator.rpc_url(), CommitmentConfig::processed());
 | 
					
						
							| 
									
										
										
										
											2020-03-18 21:49:38 -06:00
										 |  |  |     request_and_confirm_airdrop(
 | 
					
						
							|  |  |  |         &rpc_client,
 | 
					
						
							| 
									
										
										
										
											2021-04-15 00:25:23 -06:00
										 |  |  |         &CliConfig::recent_for_tests(),
 | 
					
						
							|  |  |  |         &offline_from_signer.pubkey(),
 | 
					
						
							|  |  |  |         43,
 | 
					
						
							|  |  |  |     )
 | 
					
						
							|  |  |  |     .unwrap();
 | 
					
						
							|  |  |  |     request_and_confirm_airdrop(
 | 
					
						
							|  |  |  |         &rpc_client,
 | 
					
						
							|  |  |  |         &CliConfig::recent_for_tests(),
 | 
					
						
							| 
									
										
										
										
											2020-03-18 21:49:38 -06:00
										 |  |  |         &offline_fee_payer_signer.pubkey(),
 | 
					
						
							|  |  |  |         3,
 | 
					
						
							|  |  |  |     )
 | 
					
						
							|  |  |  |     .unwrap();
 | 
					
						
							| 
									
										
										
										
											2020-06-17 12:18:48 -06:00
										 |  |  |     check_recent_balance(43, &rpc_client, &offline_from_signer.pubkey());
 | 
					
						
							|  |  |  |     check_recent_balance(3, &rpc_client, &offline_fee_payer_signer.pubkey());
 | 
					
						
							|  |  |  |     check_recent_balance(0, &rpc_client, &to_pubkey);
 | 
					
						
							| 
									
										
										
										
											2020-03-18 21:49:38 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-17 12:18:48 -06:00
										 |  |  |     check_ready(&rpc_client);
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-19 15:33:03 -07:00
										 |  |  |     let (blockhash, _) = rpc_client.get_recent_blockhash().unwrap();
 | 
					
						
							| 
									
										
										
										
											2020-03-18 21:49:38 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  |     // Offline fee-payer signs first
 | 
					
						
							| 
									
										
										
										
											2020-06-17 12:18:48 -06:00
										 |  |  |     let mut fee_payer_config = CliConfig::recent_for_tests();
 | 
					
						
							| 
									
										
										
										
											2020-03-18 21:49:38 -06:00
										 |  |  |     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 {
 | 
					
						
							| 
									
										
										
										
											2020-05-14 12:24:14 -06:00
										 |  |  |         amount: SpendAmount::Some(42),
 | 
					
						
							| 
									
										
										
										
											2020-03-18 21:49:38 -06:00
										 |  |  |         to: to_pubkey,
 | 
					
						
							|  |  |  |         from: 1,
 | 
					
						
							|  |  |  |         sign_only: true,
 | 
					
						
							| 
									
										
										
										
											2021-03-12 19:37:39 -07:00
										 |  |  |         dump_transaction_message: false,
 | 
					
						
							| 
									
										
										
										
											2021-03-22 11:10:44 -07:00
										 |  |  |         allow_unfunded_recipient: true,
 | 
					
						
							| 
									
										
										
										
											2020-04-08 23:46:19 -06:00
										 |  |  |         no_wait: false,
 | 
					
						
							| 
									
										
										
										
											2020-03-18 21:49:38 -06:00
										 |  |  |         blockhash_query: BlockhashQuery::None(blockhash),
 | 
					
						
							|  |  |  |         nonce_account: None,
 | 
					
						
							|  |  |  |         nonce_authority: 0,
 | 
					
						
							| 
									
										
										
										
											2021-04-05 13:53:50 -07:00
										 |  |  |         memo: None,
 | 
					
						
							| 
									
										
										
										
											2020-03-18 21:49:38 -06:00
										 |  |  |         fee_payer: 0,
 | 
					
						
							| 
									
										
										
										
											2021-02-18 00:08:12 -07:00
										 |  |  |         derived_address_seed: None,
 | 
					
						
							|  |  |  |         derived_address_program_id: None,
 | 
					
						
							| 
									
										
										
										
											2020-03-18 21:49:38 -06:00
										 |  |  |     };
 | 
					
						
							| 
									
										
										
										
											2020-05-07 07:21:48 +03:00
										 |  |  |     fee_payer_config.output_format = OutputFormat::JsonCompact;
 | 
					
						
							| 
									
										
										
										
											2020-03-18 21:49:38 -06:00
										 |  |  |     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
 | 
					
						
							| 
									
										
										
										
											2020-06-17 12:18:48 -06:00
										 |  |  |     let mut from_config = CliConfig::recent_for_tests();
 | 
					
						
							| 
									
										
										
										
											2020-03-18 21:49:38 -06:00
										 |  |  |     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 {
 | 
					
						
							| 
									
										
										
										
											2020-05-14 12:24:14 -06:00
										 |  |  |         amount: SpendAmount::Some(42),
 | 
					
						
							| 
									
										
										
										
											2020-03-18 21:49:38 -06:00
										 |  |  |         to: to_pubkey,
 | 
					
						
							|  |  |  |         from: 1,
 | 
					
						
							|  |  |  |         sign_only: true,
 | 
					
						
							| 
									
										
										
										
											2021-03-12 19:37:39 -07:00
										 |  |  |         dump_transaction_message: false,
 | 
					
						
							| 
									
										
										
										
											2021-03-22 11:10:44 -07:00
										 |  |  |         allow_unfunded_recipient: true,
 | 
					
						
							| 
									
										
										
										
											2020-04-08 23:46:19 -06:00
										 |  |  |         no_wait: false,
 | 
					
						
							| 
									
										
										
										
											2020-03-18 21:49:38 -06:00
										 |  |  |         blockhash_query: BlockhashQuery::None(blockhash),
 | 
					
						
							|  |  |  |         nonce_account: None,
 | 
					
						
							|  |  |  |         nonce_authority: 0,
 | 
					
						
							| 
									
										
										
										
											2021-04-05 13:53:50 -07:00
										 |  |  |         memo: None,
 | 
					
						
							| 
									
										
										
										
											2020-03-18 21:49:38 -06:00
										 |  |  |         fee_payer: 0,
 | 
					
						
							| 
									
										
										
										
											2021-02-18 00:08:12 -07:00
										 |  |  |         derived_address_seed: None,
 | 
					
						
							|  |  |  |         derived_address_program_id: None,
 | 
					
						
							| 
									
										
										
										
											2020-03-18 21:49:38 -06:00
										 |  |  |     };
 | 
					
						
							| 
									
										
										
										
											2020-05-07 07:21:48 +03:00
										 |  |  |     from_config.output_format = OutputFormat::JsonCompact;
 | 
					
						
							| 
									
										
										
										
											2020-03-18 21:49:38 -06:00
										 |  |  |     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
 | 
					
						
							| 
									
										
										
										
											2020-06-17 12:18:48 -06:00
										 |  |  |     let mut config = CliConfig::recent_for_tests();
 | 
					
						
							| 
									
										
										
										
											2020-11-25 17:00:47 -08:00
										 |  |  |     config.json_rpc_url = test_validator.rpc_url();
 | 
					
						
							| 
									
										
										
										
											2020-03-18 21:49:38 -06:00
										 |  |  |     config.signers = vec![&fee_payer_presigner, &from_presigner];
 | 
					
						
							|  |  |  |     config.command = CliCommand::Transfer {
 | 
					
						
							| 
									
										
										
										
											2020-05-14 12:24:14 -06:00
										 |  |  |         amount: SpendAmount::Some(42),
 | 
					
						
							| 
									
										
										
										
											2020-03-18 21:49:38 -06:00
										 |  |  |         to: to_pubkey,
 | 
					
						
							|  |  |  |         from: 1,
 | 
					
						
							|  |  |  |         sign_only: false,
 | 
					
						
							| 
									
										
										
										
											2021-03-12 19:37:39 -07:00
										 |  |  |         dump_transaction_message: false,
 | 
					
						
							| 
									
										
										
										
											2021-03-22 11:10:44 -07:00
										 |  |  |         allow_unfunded_recipient: true,
 | 
					
						
							| 
									
										
										
										
											2020-04-08 23:46:19 -06:00
										 |  |  |         no_wait: false,
 | 
					
						
							| 
									
										
										
										
											2020-03-18 21:49:38 -06:00
										 |  |  |         blockhash_query: BlockhashQuery::FeeCalculator(blockhash_query::Source::Cluster, blockhash),
 | 
					
						
							|  |  |  |         nonce_account: None,
 | 
					
						
							|  |  |  |         nonce_authority: 0,
 | 
					
						
							| 
									
										
										
										
											2021-04-05 13:53:50 -07:00
										 |  |  |         memo: None,
 | 
					
						
							| 
									
										
										
										
											2020-03-18 21:49:38 -06:00
										 |  |  |         fee_payer: 0,
 | 
					
						
							| 
									
										
										
										
											2021-02-18 00:08:12 -07:00
										 |  |  |         derived_address_seed: None,
 | 
					
						
							|  |  |  |         derived_address_program_id: None,
 | 
					
						
							| 
									
										
										
										
											2020-03-18 21:49:38 -06:00
										 |  |  |     };
 | 
					
						
							|  |  |  |     process_command(&config).unwrap();
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-17 12:18:48 -06:00
										 |  |  |     check_recent_balance(1, &rpc_client, &offline_from_signer.pubkey());
 | 
					
						
							|  |  |  |     check_recent_balance(1, &rpc_client, &offline_fee_payer_signer.pubkey());
 | 
					
						
							|  |  |  |     check_recent_balance(42, &rpc_client, &to_pubkey);
 | 
					
						
							| 
									
										
										
										
											2020-03-18 21:49:38 -06:00
										 |  |  | }
 | 
					
						
							| 
									
										
										
										
											2020-05-14 12:24:14 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | #[test]
 | 
					
						
							|  |  |  | fn test_transfer_all() {
 | 
					
						
							| 
									
										
										
										
											2020-11-16 23:27:36 -07:00
										 |  |  |     solana_logger::setup();
 | 
					
						
							| 
									
										
										
										
											2020-12-08 23:18:27 -08:00
										 |  |  |     let mint_keypair = Keypair::new();
 | 
					
						
							| 
									
										
										
										
											2021-04-15 00:25:23 -06:00
										 |  |  |     let mint_pubkey = mint_keypair.pubkey();
 | 
					
						
							| 
									
										
										
										
											2021-01-28 12:11:53 -08:00
										 |  |  |     let faucet_addr = run_local_faucet(mint_keypair, None);
 | 
					
						
							| 
									
										
										
										
											2021-07-23 15:25:03 +00:00
										 |  |  |     let test_validator = TestValidator::with_custom_fees(
 | 
					
						
							|  |  |  |         mint_pubkey,
 | 
					
						
							|  |  |  |         1,
 | 
					
						
							|  |  |  |         Some(faucet_addr),
 | 
					
						
							|  |  |  |         SocketAddrSpace::Unspecified,
 | 
					
						
							|  |  |  |     );
 | 
					
						
							| 
									
										
										
										
											2020-05-14 12:24:14 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-19 15:33:03 -07:00
										 |  |  |     let rpc_client =
 | 
					
						
							| 
									
										
										
										
											2021-01-26 12:23:07 -07:00
										 |  |  |         RpcClient::new_with_commitment(test_validator.rpc_url(), CommitmentConfig::processed());
 | 
					
						
							| 
									
										
										
										
											2020-05-14 12:24:14 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  |     let default_signer = Keypair::new();
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-17 12:18:48 -06:00
										 |  |  |     let mut config = CliConfig::recent_for_tests();
 | 
					
						
							| 
									
										
										
										
											2020-11-25 17:00:47 -08:00
										 |  |  |     config.json_rpc_url = test_validator.rpc_url();
 | 
					
						
							| 
									
										
										
										
											2020-05-14 12:24:14 -06:00
										 |  |  |     config.signers = vec![&default_signer];
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     let sender_pubkey = config.signers[0].pubkey();
 | 
					
						
							|  |  |  |     let recipient_pubkey = Pubkey::new(&[1u8; 32]);
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-15 00:25:23 -06:00
										 |  |  |     request_and_confirm_airdrop(&rpc_client, &config, &sender_pubkey, 50_000).unwrap();
 | 
					
						
							| 
									
										
										
										
											2020-06-17 12:18:48 -06:00
										 |  |  |     check_recent_balance(50_000, &rpc_client, &sender_pubkey);
 | 
					
						
							|  |  |  |     check_recent_balance(0, &rpc_client, &recipient_pubkey);
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     check_ready(&rpc_client);
 | 
					
						
							| 
									
										
										
										
											2020-05-14 12:24:14 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  |     // Plain ole transfer
 | 
					
						
							|  |  |  |     config.command = CliCommand::Transfer {
 | 
					
						
							|  |  |  |         amount: SpendAmount::All,
 | 
					
						
							|  |  |  |         to: recipient_pubkey,
 | 
					
						
							|  |  |  |         from: 0,
 | 
					
						
							|  |  |  |         sign_only: false,
 | 
					
						
							| 
									
										
										
										
											2021-03-12 19:37:39 -07:00
										 |  |  |         dump_transaction_message: false,
 | 
					
						
							| 
									
										
										
										
											2021-03-22 11:10:44 -07:00
										 |  |  |         allow_unfunded_recipient: true,
 | 
					
						
							| 
									
										
										
										
											2020-05-14 12:24:14 -06:00
										 |  |  |         no_wait: false,
 | 
					
						
							|  |  |  |         blockhash_query: BlockhashQuery::All(blockhash_query::Source::Cluster),
 | 
					
						
							|  |  |  |         nonce_account: None,
 | 
					
						
							|  |  |  |         nonce_authority: 0,
 | 
					
						
							| 
									
										
										
										
											2021-04-05 13:53:50 -07:00
										 |  |  |         memo: None,
 | 
					
						
							| 
									
										
										
										
											2020-05-14 12:24:14 -06:00
										 |  |  |         fee_payer: 0,
 | 
					
						
							| 
									
										
										
										
											2021-02-18 00:08:12 -07:00
										 |  |  |         derived_address_seed: None,
 | 
					
						
							|  |  |  |         derived_address_program_id: None,
 | 
					
						
							| 
									
										
										
										
											2020-05-14 12:24:14 -06:00
										 |  |  |     };
 | 
					
						
							|  |  |  |     process_command(&config).unwrap();
 | 
					
						
							| 
									
										
										
										
											2020-06-17 12:18:48 -06:00
										 |  |  |     check_recent_balance(0, &rpc_client, &sender_pubkey);
 | 
					
						
							|  |  |  |     check_recent_balance(49_999, &rpc_client, &recipient_pubkey);
 | 
					
						
							| 
									
										
										
										
											2020-05-14 12:24:14 -06:00
										 |  |  | }
 | 
					
						
							| 
									
										
										
										
											2021-02-18 00:08:12 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-22 11:10:44 -07:00
										 |  |  | #[test]
 | 
					
						
							|  |  |  | fn test_transfer_unfunded_recipient() {
 | 
					
						
							|  |  |  |     solana_logger::setup();
 | 
					
						
							|  |  |  |     let mint_keypair = Keypair::new();
 | 
					
						
							| 
									
										
										
										
											2021-04-15 00:25:23 -06:00
										 |  |  |     let mint_pubkey = mint_keypair.pubkey();
 | 
					
						
							| 
									
										
										
										
											2021-03-22 11:10:44 -07:00
										 |  |  |     let faucet_addr = run_local_faucet(mint_keypair, None);
 | 
					
						
							| 
									
										
										
										
											2021-07-23 15:25:03 +00:00
										 |  |  |     let test_validator = TestValidator::with_custom_fees(
 | 
					
						
							|  |  |  |         mint_pubkey,
 | 
					
						
							|  |  |  |         1,
 | 
					
						
							|  |  |  |         Some(faucet_addr),
 | 
					
						
							|  |  |  |         SocketAddrSpace::Unspecified,
 | 
					
						
							|  |  |  |     );
 | 
					
						
							| 
									
										
										
										
											2021-03-22 11:10:44 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |     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::new(&[1u8; 32]);
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-15 00:25:23 -06:00
										 |  |  |     request_and_confirm_airdrop(&rpc_client, &config, &sender_pubkey, 50_000).unwrap();
 | 
					
						
							| 
									
										
										
										
											2021-03-22 11:10:44 -07:00
										 |  |  |     check_recent_balance(50_000, &rpc_client, &sender_pubkey);
 | 
					
						
							|  |  |  |     check_recent_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,
 | 
					
						
							| 
									
										
										
										
											2021-04-05 13:53:50 -07:00
										 |  |  |         memo: None,
 | 
					
						
							| 
									
										
										
										
											2021-03-22 11:10:44 -07:00
										 |  |  |         fee_payer: 0,
 | 
					
						
							|  |  |  |         derived_address_seed: None,
 | 
					
						
							|  |  |  |         derived_address_program_id: None,
 | 
					
						
							|  |  |  |     };
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // Expect failure due to unfunded recipient and the lack of the `allow_unfunded_recipient` flag
 | 
					
						
							|  |  |  |     process_command(&config).unwrap_err();
 | 
					
						
							|  |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-18 00:08:12 -07:00
										 |  |  | #[test]
 | 
					
						
							|  |  |  | fn test_transfer_with_seed() {
 | 
					
						
							|  |  |  |     solana_logger::setup();
 | 
					
						
							|  |  |  |     let mint_keypair = Keypair::new();
 | 
					
						
							| 
									
										
										
										
											2021-04-15 00:25:23 -06:00
										 |  |  |     let mint_pubkey = mint_keypair.pubkey();
 | 
					
						
							| 
									
										
										
										
											2021-02-18 00:08:12 -07:00
										 |  |  |     let faucet_addr = run_local_faucet(mint_keypair, None);
 | 
					
						
							| 
									
										
										
										
											2021-07-23 15:25:03 +00:00
										 |  |  |     let test_validator = TestValidator::with_custom_fees(
 | 
					
						
							|  |  |  |         mint_pubkey,
 | 
					
						
							|  |  |  |         1,
 | 
					
						
							|  |  |  |         Some(faucet_addr),
 | 
					
						
							|  |  |  |         SocketAddrSpace::Unspecified,
 | 
					
						
							|  |  |  |     );
 | 
					
						
							| 
									
										
										
										
											2021-02-18 00:08:12 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |     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::new(&[1u8; 32]);
 | 
					
						
							|  |  |  |     let derived_address_seed = "seed".to_string();
 | 
					
						
							| 
									
										
										
										
											2021-06-15 18:04:00 +02:00
										 |  |  |     let derived_address_program_id = stake::program::id();
 | 
					
						
							| 
									
										
										
										
											2021-02-18 00:08:12 -07:00
										 |  |  |     let derived_address = Pubkey::create_with_seed(
 | 
					
						
							|  |  |  |         &sender_pubkey,
 | 
					
						
							|  |  |  |         &derived_address_seed,
 | 
					
						
							|  |  |  |         &derived_address_program_id,
 | 
					
						
							|  |  |  |     )
 | 
					
						
							|  |  |  |     .unwrap();
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-15 00:25:23 -06:00
										 |  |  |     request_and_confirm_airdrop(&rpc_client, &config, &sender_pubkey, 1).unwrap();
 | 
					
						
							|  |  |  |     request_and_confirm_airdrop(&rpc_client, &config, &derived_address, 50_000).unwrap();
 | 
					
						
							| 
									
										
										
										
											2021-02-18 00:08:12 -07:00
										 |  |  |     check_recent_balance(1, &rpc_client, &sender_pubkey);
 | 
					
						
							|  |  |  |     check_recent_balance(50_000, &rpc_client, &derived_address);
 | 
					
						
							|  |  |  |     check_recent_balance(0, &rpc_client, &recipient_pubkey);
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     check_ready(&rpc_client);
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // Transfer with seed
 | 
					
						
							|  |  |  |     config.command = CliCommand::Transfer {
 | 
					
						
							|  |  |  |         amount: SpendAmount::Some(50_000),
 | 
					
						
							|  |  |  |         to: recipient_pubkey,
 | 
					
						
							|  |  |  |         from: 0,
 | 
					
						
							|  |  |  |         sign_only: false,
 | 
					
						
							| 
									
										
										
										
											2021-03-12 19:37:39 -07:00
										 |  |  |         dump_transaction_message: false,
 | 
					
						
							| 
									
										
										
										
											2021-03-22 11:10:44 -07:00
										 |  |  |         allow_unfunded_recipient: true,
 | 
					
						
							| 
									
										
										
										
											2021-02-18 00:08:12 -07:00
										 |  |  |         no_wait: false,
 | 
					
						
							|  |  |  |         blockhash_query: BlockhashQuery::All(blockhash_query::Source::Cluster),
 | 
					
						
							|  |  |  |         nonce_account: None,
 | 
					
						
							|  |  |  |         nonce_authority: 0,
 | 
					
						
							| 
									
										
										
										
											2021-04-05 13:53:50 -07:00
										 |  |  |         memo: None,
 | 
					
						
							| 
									
										
										
										
											2021-02-18 00:08:12 -07:00
										 |  |  |         fee_payer: 0,
 | 
					
						
							|  |  |  |         derived_address_seed: Some(derived_address_seed),
 | 
					
						
							|  |  |  |         derived_address_program_id: Some(derived_address_program_id),
 | 
					
						
							|  |  |  |     };
 | 
					
						
							|  |  |  |     process_command(&config).unwrap();
 | 
					
						
							|  |  |  |     check_recent_balance(0, &rpc_client, &sender_pubkey);
 | 
					
						
							|  |  |  |     check_recent_balance(50_000, &rpc_client, &recipient_pubkey);
 | 
					
						
							|  |  |  |     check_recent_balance(0, &rpc_client, &derived_address);
 | 
					
						
							|  |  |  | }
 |