2020-03-19 10:36:53 -06: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-03-19 10:36:53 -06: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;
							 | 
						
					
						
							
								
									
										
										
										
											2019-12-16 14:05:17 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								use solana_faucet::faucet::run_local_faucet;
							 | 
						
					
						
							
								
									
										
										
										
											2019-12-10 00:24:44 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								use solana_sdk::{
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-17 12:18:48 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    commitment_config::CommitmentConfig,
							 | 
						
					
						
							
								
									
										
										
										
											2019-12-10 00:24:44 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    hash::Hash,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    pubkey::Pubkey,
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    signature::{keypair_from_seed, Keypair, Signer},
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-09 15:22:48 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    system_program,
							 | 
						
					
						
							
								
									
										
										
										
											2019-12-10 00:24:44 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								};
							 | 
						
					
						
							
								
									
										
										
										
											2021-07-23 15:25:03 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								use solana_streamer::socket::SocketAddrSpace;
							 | 
						
					
						
							
								
									
										
										
										
											2019-12-10 00:24:44 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								#[test]
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								fn test_nonce() {
							 | 
						
					
						
							
								
									
										
										
										
											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();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let faucet_addr = run_local_faucet(mint_keypair, None);
							 | 
						
					
						
							
								
									
										
										
										
											2021-07-23 15:25:03 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let test_validator =
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        TestValidator::with_no_fees(mint_pubkey, Some(faucet_addr), SocketAddrSpace::Unspecified);
							 | 
						
					
						
							
								
									
										
										
										
											2021-04-15 00:25:23 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    full_battery_tests(test_validator, None, false);
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-09 15:22:48 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								#[test]
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								fn test_nonce_with_seed() {
							 | 
						
					
						
							
								
									
										
										
										
											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();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let faucet_addr = run_local_faucet(mint_keypair, None);
							 | 
						
					
						
							
								
									
										
										
										
											2021-07-23 15:25:03 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let test_validator =
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        TestValidator::with_no_fees(mint_pubkey, Some(faucet_addr), SocketAddrSpace::Unspecified);
							 | 
						
					
						
							
								
									
										
										
										
											2021-04-15 00:25:23 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    full_battery_tests(test_validator, Some(String::from("seed")), false);
							 | 
						
					
						
							
								
									
										
										
										
											2019-12-17 09:34:21 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								#[test]
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								fn test_nonce_with_authority() {
							 | 
						
					
						
							
								
									
										
										
										
											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();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let faucet_addr = run_local_faucet(mint_keypair, None);
							 | 
						
					
						
							
								
									
										
										
										
											2021-07-23 15:25:03 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let test_validator =
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        TestValidator::with_no_fees(mint_pubkey, Some(faucet_addr), SocketAddrSpace::Unspecified);
							 | 
						
					
						
							
								
									
										
										
										
											2021-04-15 00:25:23 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    full_battery_tests(test_validator, None, true);
							 | 
						
					
						
							
								
									
										
										
										
											2019-12-17 09:34:21 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								fn full_battery_tests(
							 | 
						
					
						
							
								
									
										
										
										
											2020-11-25 17:00:47 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    test_validator: TestValidator,
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-09 15:22:48 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    seed: Option<String>,
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    use_nonce_authority: bool,
							 | 
						
					
						
							
								
									
										
										
										
											2019-12-17 09:34:21 -05: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-11-25 17:00:47 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let json_rpc_url = test_validator.rpc_url();
							 | 
						
					
						
							
								
									
										
										
										
											2020-04-09 18:05:56 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-17 12:18:48 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let mut config_payer = CliConfig::recent_for_tests();
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    config_payer.json_rpc_url = json_rpc_url.clone();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let payer = Keypair::new();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    config_payer.signers = vec![&payer];
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2019-12-10 00:24:44 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    request_and_confirm_airdrop(
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        &rpc_client,
							 | 
						
					
						
							
								
									
										
										
										
											2021-04-15 00:25:23 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        &config_payer,
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        &config_payer.signers[0].pubkey(),
							 | 
						
					
						
							
								
									
										
										
										
											2019-12-10 00:24:44 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        2000,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    )
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    .unwrap();
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-17 12:18:48 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    check_recent_balance(2000, &rpc_client, &config_payer.signers[0].pubkey());
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-17 12:18:48 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let mut config_nonce = CliConfig::recent_for_tests();
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    config_nonce.json_rpc_url = json_rpc_url;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let nonce_keypair = keypair_from_seed(&[0u8; 32]).unwrap();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    config_nonce.signers = vec![&nonce_keypair];
							 | 
						
					
						
							
								
									
										
										
										
											2019-12-10 00:24:44 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-09 15:22:48 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let nonce_account = if let Some(seed) = seed.as_ref() {
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-20 15:20:48 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        Pubkey::create_with_seed(
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            &config_nonce.signers[0].pubkey(),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            seed,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            &system_program::id(),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        )
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        .unwrap()
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    } else {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        nonce_keypair.pubkey()
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    };
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let nonce_authority = Keypair::new();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let optional_authority = if use_nonce_authority {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        Some(nonce_authority.pubkey())
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-09 15:22:48 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else {
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        None
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-09 15:22:48 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    };
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2019-12-10 00:24:44 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    // Create nonce account
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    config_payer.signers.push(&nonce_keypair);
							 | 
						
					
						
							
								
									
										
										
										
											2019-12-10 00:24:44 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    config_payer.command = CliCommand::CreateNonceAccount {
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        nonce_account: 1,
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-09 15:22:48 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        seed,
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        nonce_authority: optional_authority,
							 | 
						
					
						
							
								
									
										
										
										
											2021-04-05 13:53:50 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        memo: None,
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-14 12:24:14 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        amount: SpendAmount::Some(1000),
							 | 
						
					
						
							
								
									
										
										
										
											2019-12-10 00:24:44 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    };
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-09 15:22:48 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2019-12-10 00:24:44 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    process_command(&config_payer).unwrap();
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-17 12:18:48 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    check_recent_balance(1000, &rpc_client, &config_payer.signers[0].pubkey());
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    check_recent_balance(1000, &rpc_client, &nonce_account);
							 | 
						
					
						
							
								
									
										
										
										
											2019-12-10 00:24:44 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    // Get nonce
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    config_payer.signers.pop();
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-09 15:22:48 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    config_payer.command = CliCommand::GetNonce(nonce_account);
							 | 
						
					
						
							
								
									
										
										
										
											2019-12-10 00:24:44 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let first_nonce_string = process_command(&config_payer).unwrap();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let first_nonce = first_nonce_string.parse::<Hash>().unwrap();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    // Get nonce
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-09 15:22:48 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    config_payer.command = CliCommand::GetNonce(nonce_account);
							 | 
						
					
						
							
								
									
										
										
										
											2019-12-10 00:24:44 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let second_nonce_string = process_command(&config_payer).unwrap();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let second_nonce = second_nonce_string.parse::<Hash>().unwrap();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    assert_eq!(first_nonce, second_nonce);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let mut authorized_signers: Vec<&dyn Signer> = vec![&payer];
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let index = if use_nonce_authority {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        authorized_signers.push(&nonce_authority);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        1
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    } else {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        0
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    };
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2019-12-10 00:24:44 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    // New nonce
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    config_payer.signers = authorized_signers.clone();
							 | 
						
					
						
							
								
									
										
										
										
											2019-12-17 09:34:21 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    config_payer.command = CliCommand::NewNonce {
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-09 15:22:48 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        nonce_account,
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        nonce_authority: index,
							 | 
						
					
						
							
								
									
										
										
										
											2021-04-05 13:53:50 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        memo: None,
							 | 
						
					
						
							
								
									
										
										
										
											2019-12-17 09:34:21 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    };
							 | 
						
					
						
							
								
									
										
										
										
											2019-12-10 00:24:44 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    process_command(&config_payer).unwrap();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    // Get nonce
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    config_payer.signers = vec![&payer];
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-09 15:22:48 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    config_payer.command = CliCommand::GetNonce(nonce_account);
							 | 
						
					
						
							
								
									
										
										
										
											2019-12-10 00:24:44 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let third_nonce_string = process_command(&config_payer).unwrap();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let third_nonce = third_nonce_string.parse::<Hash>().unwrap();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    assert_ne!(first_nonce, third_nonce);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    // Withdraw from nonce account
							 | 
						
					
						
							
								
									
										
										
										
											2020-10-19 12:12:08 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let payee_pubkey = solana_sdk::pubkey::new_rand();
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    config_payer.signers = authorized_signers;
							 | 
						
					
						
							
								
									
										
										
										
											2019-12-10 00:24:44 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    config_payer.command = CliCommand::WithdrawFromNonceAccount {
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-09 15:22:48 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        nonce_account,
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        nonce_authority: index,
							 | 
						
					
						
							
								
									
										
										
										
											2021-04-05 13:53:50 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        memo: None,
							 | 
						
					
						
							
								
									
										
										
										
											2019-12-10 00:24:44 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        destination_account_pubkey: payee_pubkey,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        lamports: 100,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    };
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    process_command(&config_payer).unwrap();
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-17 12:18:48 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    check_recent_balance(1000, &rpc_client, &config_payer.signers[0].pubkey());
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    check_recent_balance(900, &rpc_client, &nonce_account);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    check_recent_balance(100, &rpc_client, &payee_pubkey);
							 | 
						
					
						
							
								
									
										
										
										
											2019-12-10 00:24:44 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    // Show nonce account
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    config_payer.command = CliCommand::ShowNonceAccount {
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-09 15:22:48 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        nonce_account_pubkey: nonce_account,
							 | 
						
					
						
							
								
									
										
										
										
											2019-12-10 00:24:44 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        use_lamports_unit: true,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    };
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    process_command(&config_payer).unwrap();
							 | 
						
					
						
							
								
									
										
										
										
											2019-12-19 19:13:01 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    // Set new authority
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let new_authority = Keypair::new();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    config_payer.command = CliCommand::AuthorizeNonceAccount {
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-09 15:22:48 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        nonce_account,
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        nonce_authority: index,
							 | 
						
					
						
							
								
									
										
										
										
											2021-04-05 13:53:50 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        memo: None,
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        new_authority: new_authority.pubkey(),
							 | 
						
					
						
							
								
									
										
										
										
											2019-12-19 19:13:01 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    };
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    process_command(&config_payer).unwrap();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    // Old authority fails now
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    config_payer.command = CliCommand::NewNonce {
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-09 15:22:48 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        nonce_account,
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        nonce_authority: index,
							 | 
						
					
						
							
								
									
										
										
										
											2021-04-05 13:53:50 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        memo: None,
							 | 
						
					
						
							
								
									
										
										
										
											2019-12-19 19:13:01 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    };
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    process_command(&config_payer).unwrap_err();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    // New authority can advance nonce
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    config_payer.signers = vec![&payer, &new_authority];
							 | 
						
					
						
							
								
									
										
										
										
											2019-12-19 19:13:01 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    config_payer.command = CliCommand::NewNonce {
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-09 15:22:48 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        nonce_account,
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        nonce_authority: 1,
							 | 
						
					
						
							
								
									
										
										
										
											2021-04-05 13:53:50 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        memo: None,
							 | 
						
					
						
							
								
									
										
										
										
											2019-12-19 19:13:01 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    };
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    process_command(&config_payer).unwrap();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    // New authority can withdraw from nonce account
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    config_payer.command = CliCommand::WithdrawFromNonceAccount {
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-09 15:22:48 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        nonce_account,
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        nonce_authority: 1,
							 | 
						
					
						
							
								
									
										
										
										
											2021-04-05 13:53:50 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        memo: None,
							 | 
						
					
						
							
								
									
										
										
										
											2019-12-19 19:13:01 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        destination_account_pubkey: payee_pubkey,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        lamports: 100,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    };
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    process_command(&config_payer).unwrap();
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-17 12:18:48 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    check_recent_balance(1000, &rpc_client, &config_payer.signers[0].pubkey());
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    check_recent_balance(800, &rpc_client, &nonce_account);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    check_recent_balance(200, &rpc_client, &payee_pubkey);
							 | 
						
					
						
							
								
									
										
										
										
											2019-12-10 00:24:44 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-19 10:36:53 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								#[test]
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								fn test_create_account_with_seed() {
							 | 
						
					
						
							
								
									
										
										
										
											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-19 10:36:53 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let offline_nonce_authority_signer = keypair_from_seed(&[1u8; 32]).unwrap();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let online_nonce_creator_signer = keypair_from_seed(&[2u8; 32]).unwrap();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let to_address = Pubkey::new(&[3u8; 32]);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    // 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-19 10:36:53 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    request_and_confirm_airdrop(
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        &rpc_client,
							 | 
						
					
						
							
								
									
										
										
										
											2021-04-15 00:25:23 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        &CliConfig::recent_for_tests(),
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-19 10:36:53 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        &offline_nonce_authority_signer.pubkey(),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        42,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    )
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    .unwrap();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    request_and_confirm_airdrop(
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        &rpc_client,
							 | 
						
					
						
							
								
									
										
										
										
											2021-04-15 00:25:23 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        &CliConfig::recent_for_tests(),
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-19 10:36:53 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        &online_nonce_creator_signer.pubkey(),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        4242,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    )
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    .unwrap();
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-17 12:18:48 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    check_recent_balance(42, &rpc_client, &offline_nonce_authority_signer.pubkey());
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    check_recent_balance(4242, &rpc_client, &online_nonce_creator_signer.pubkey());
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    check_recent_balance(0, &rpc_client, &to_address);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    check_ready(&rpc_client);
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-19 10:36:53 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    // Create nonce account
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let creator_pubkey = online_nonce_creator_signer.pubkey();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let authority_pubkey = offline_nonce_authority_signer.pubkey();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let seed = authority_pubkey.to_string()[0..32].to_string();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let nonce_address =
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-20 15:20:48 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        Pubkey::create_with_seed(&creator_pubkey, &seed, &system_program::id()).unwrap();
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-17 12:18:48 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    check_recent_balance(0, &rpc_client, &nonce_address);
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-19 10:36:53 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-17 12:18:48 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let mut creator_config = CliConfig::recent_for_tests();
							 | 
						
					
						
							
								
									
										
										
										
											2020-11-25 17:00:47 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    creator_config.json_rpc_url = test_validator.rpc_url();
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-19 10:36:53 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    creator_config.signers = vec![&online_nonce_creator_signer];
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    creator_config.command = CliCommand::CreateNonceAccount {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        nonce_account: 0,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        seed: Some(seed),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        nonce_authority: Some(authority_pubkey),
							 | 
						
					
						
							
								
									
										
										
										
											2021-04-05 13:53:50 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        memo: None,
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-14 12:24:14 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        amount: SpendAmount::Some(241),
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-19 10:36:53 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    };
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    process_command(&creator_config).unwrap();
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-17 12:18:48 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    check_recent_balance(241, &rpc_client, &nonce_address);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    check_recent_balance(42, &rpc_client, &offline_nonce_authority_signer.pubkey());
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    check_recent_balance(4000, &rpc_client, &online_nonce_creator_signer.pubkey());
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    check_recent_balance(0, &rpc_client, &to_address);
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-19 10:36:53 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    // Fetch nonce hash
							 | 
						
					
						
							
								
									
										
										
										
											2020-09-21 13:55:44 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let nonce_hash = nonce_utils::get_account_with_commitment(
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        &rpc_client,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        &nonce_address,
							 | 
						
					
						
							
								
									
										
										
										
											2021-01-26 12:23:07 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        CommitmentConfig::processed(),
							 | 
						
					
						
							
								
									
										
										
										
											2020-09-21 13:55:44 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    )
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    .and_then(|ref a| nonce_utils::data_from_account(a))
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    .unwrap()
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    .blockhash;
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-19 10:36:53 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    // Test by creating transfer TX with nonce, fully offline
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-17 12:18:48 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let mut authority_config = CliConfig::recent_for_tests();
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-19 10:36:53 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    authority_config.json_rpc_url = String::default();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    authority_config.signers = vec![&offline_nonce_authority_signer];
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    // Verify we cannot contact the cluster
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    authority_config.command = CliCommand::ClusterVersion;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    process_command(&authority_config).unwrap_err();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    authority_config.command = CliCommand::Transfer {
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-14 12:24:14 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        amount: SpendAmount::Some(10),
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-19 10:36:53 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        to: to_address,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        from: 0,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        sign_only: true,
							 | 
						
					
						
							
								
									
										
										
										
											2021-03-12 19:37:39 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        dump_transaction_message: true,
							 | 
						
					
						
							
								
									
										
										
										
											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-19 10:36:53 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        blockhash_query: BlockhashQuery::None(nonce_hash),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        nonce_account: Some(nonce_address),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        nonce_authority: 0,
							 | 
						
					
						
							
								
									
										
										
										
											2021-04-05 13:53:50 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        memo: None,
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-19 10:36:53 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        fee_payer: 0,
							 | 
						
					
						
							
								
									
										
										
										
											2021-02-18 00:08:12 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        derived_address_seed: None,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        derived_address_program_id: None,
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-19 10:36:53 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    };
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-07 07:21:48 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    authority_config.output_format = OutputFormat::JsonCompact;
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-19 10:36:53 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let sign_only_reply = process_command(&authority_config).unwrap();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let sign_only = parse_sign_only_reply_string(&sign_only_reply);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let authority_presigner = sign_only.presigner_of(&authority_pubkey).unwrap();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    assert_eq!(sign_only.blockhash, nonce_hash);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    // And submit it
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-17 12:18:48 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let mut submit_config = CliConfig::recent_for_tests();
							 | 
						
					
						
							
								
									
										
										
										
											2020-11-25 17:00:47 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    submit_config.json_rpc_url = test_validator.rpc_url();
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-19 10:36:53 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    submit_config.signers = vec![&authority_presigner];
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    submit_config.command = CliCommand::Transfer {
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-14 12:24:14 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        amount: SpendAmount::Some(10),
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-19 10:36:53 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        to: to_address,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        from: 0,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        sign_only: false,
							 | 
						
					
						
							
								
									
										
										
										
											2021-03-12 19:37:39 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        dump_transaction_message: true,
							 | 
						
					
						
							
								
									
										
										
										
											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-19 10:36:53 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        blockhash_query: BlockhashQuery::FeeCalculator(
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            blockhash_query::Source::NonceAccount(nonce_address),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            sign_only.blockhash,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        ),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        nonce_account: Some(nonce_address),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        nonce_authority: 0,
							 | 
						
					
						
							
								
									
										
										
										
											2021-04-05 13:53:50 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        memo: None,
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-19 10:36:53 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        fee_payer: 0,
							 | 
						
					
						
							
								
									
										
										
										
											2021-02-18 00:08:12 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        derived_address_seed: None,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        derived_address_program_id: None,
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-19 10:36:53 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    };
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    process_command(&submit_config).unwrap();
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-17 12:18:48 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    check_recent_balance(241, &rpc_client, &nonce_address);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    check_recent_balance(31, &rpc_client, &offline_nonce_authority_signer.pubkey());
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    check_recent_balance(4000, &rpc_client, &online_nonce_creator_signer.pubkey());
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    check_recent_balance(10, &rpc_client, &to_address);
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-19 10:36:53 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								}
							 |