2021-10-05 22:24:48 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								#![allow(clippy::redundant_closure)]
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-30 09:21:32 -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,
							 | 
						
					
						
							
								
									
										
										
										
											2021-07-15 16:45:03 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    stake::StakeAuthorizationIndexed,
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-17 12:18:48 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    test_utils::{check_ready, check_recent_balance},
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-30 09:21:32 -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,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								};
							 | 
						
					
						
							
								
									
										
										
										
											2019-12-16 14:05:17 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								use solana_faucet::faucet::run_local_faucet;
							 | 
						
					
						
							
								
									
										
										
										
											2019-12-09 23:11:04 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								use solana_sdk::{
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-22 17:54:06 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    account_utils::StateMut,
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-17 12:18:48 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    commitment_config::CommitmentConfig,
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-10 13:00:15 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    nonce::State as NonceState,
							 | 
						
					
						
							
								
									
										
										
										
											2019-12-09 23:11:04 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    pubkey::Pubkey,
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    signature::{keypair_from_seed, Keypair, Signer},
							 | 
						
					
						
							
								
									
										
										
										
											2021-06-15 18:04:00 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    stake::{
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        self,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        instruction::LockupArgs,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        state::{Lockup, StakeAuthorize, StakeState},
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    },
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-02 12:28:43 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								};
							 | 
						
					
						
							
								
									
										
										
										
											2021-07-23 15:25:03 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								use solana_streamer::socket::SocketAddrSpace;
							 | 
						
					
						
							
								
									
										
										
										
											2021-10-28 18:27:07 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								use solana_test_validator::TestValidator;
							 | 
						
					
						
							
								
									
										
										
										
											2019-12-09 23:11:04 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-10 18:59:05 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								#[test]
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								fn test_stake_delegation_force() {
							 | 
						
					
						
							
								
									
										
										
										
											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-09-02 17:22:33 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let authorized_withdrawer = Keypair::new().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_no_fees(mint_pubkey, Some(faucet_addr), SocketAddrSpace::Unspecified);
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-10 18:59:05 -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-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let default_signer = Keypair::new();
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-10 18:59:05 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											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-10 18:59:05 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2021-04-15 00:25:23 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    request_and_confirm_airdrop(&rpc_client, &config, &config.signers[0].pubkey(), 100_000)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        .unwrap();
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-10 18:59:05 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    // Create vote account
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let vote_keypair = Keypair::new();
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    config.signers = vec![&default_signer, &vote_keypair];
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-10 18:59:05 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    config.command = CliCommand::CreateVoteAccount {
							 | 
						
					
						
							
								
									
										
										
										
											2020-07-13 21:27:41 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        vote_account: 1,
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-10 18:59:05 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        seed: None,
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-19 01:58:52 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        identity_account: 0,
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-10 18:59:05 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        authorized_voter: None,
							 | 
						
					
						
							
								
									
										
										
										
											2021-09-02 17:22:33 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        authorized_withdrawer,
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-10 18:59:05 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        commission: 0,
							 | 
						
					
						
							
								
									
										
										
										
											2021-04-05 13:53:50 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        memo: None,
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-10 18:59:05 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    };
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    process_command(&config).unwrap();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    // Create stake account
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let stake_keypair = Keypair::new();
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    config.signers = vec![&default_signer, &stake_keypair];
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-10 18:59:05 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    config.command = CliCommand::CreateStakeAccount {
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        stake_account: 1,
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-10 18:59:05 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        seed: None,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        staker: None,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        withdrawer: None,
							 | 
						
					
						
							
								
									
										
										
										
											2021-07-15 16:45:03 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        withdrawer_signer: None,
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-10 18:59:05 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        lockup: Lockup::default(),
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-14 12:24:14 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        amount: SpendAmount::Some(50_000),
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-12 23:00:28 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        sign_only: false,
							 | 
						
					
						
							
								
									
										
										
										
											2021-03-12 19:37:39 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        dump_transaction_message: false,
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-11 12:14:15 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        blockhash_query: BlockhashQuery::All(blockhash_query::Source::Cluster),
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-12 23:00:28 -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,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        from: 0,
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-10 18:59:05 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    };
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    process_command(&config).unwrap();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    // Delegate stake fails (vote account had never voted)
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    config.signers = vec![&default_signer];
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-10 18:59:05 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    config.command = CliCommand::DelegateStake {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        stake_account_pubkey: stake_keypair.pubkey(),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        vote_account_pubkey: vote_keypair.pubkey(),
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        stake_authority: 0,
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-10 18:59:05 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        force: false,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        sign_only: false,
							 | 
						
					
						
							
								
									
										
										
										
											2021-03-12 19:37:39 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        dump_transaction_message: false,
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-10 18:59:05 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        blockhash_query: BlockhashQuery::default(),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        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,
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-10 18:59:05 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    };
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    process_command(&config).unwrap_err();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    // But if we force it, it works anyway!
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    config.command = CliCommand::DelegateStake {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        stake_account_pubkey: stake_keypair.pubkey(),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        vote_account_pubkey: vote_keypair.pubkey(),
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        stake_authority: 0,
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-10 18:59:05 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        force: true,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        sign_only: false,
							 | 
						
					
						
							
								
									
										
										
										
											2021-03-12 19:37:39 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        dump_transaction_message: false,
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-10 18:59:05 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        blockhash_query: BlockhashQuery::default(),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        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,
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-10 18:59:05 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    };
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    process_command(&config).unwrap();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-09 15:22:48 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								#[test]
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								fn test_seed_stake_delegation_and_deactivation() {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    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_no_fees(mint_pubkey, Some(faucet_addr), SocketAddrSpace::Unspecified);
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-09 15:22:48 -08: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-01-09 15:22:48 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-21 14:55:53 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let validator_keypair = keypair_from_seed(&[0u8; 32]).unwrap();
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-17 12:18:48 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let mut config_validator = CliConfig::recent_for_tests();
							 | 
						
					
						
							
								
									
										
										
										
											2020-11-25 17:00:47 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    config_validator.json_rpc_url = test_validator.rpc_url();
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    config_validator.signers = vec![&validator_keypair];
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-09 15:22:48 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    request_and_confirm_airdrop(
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        &rpc_client,
							 | 
						
					
						
							
								
									
										
										
										
											2021-04-15 00:25:23 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        &config_validator,
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        &config_validator.signers[0].pubkey(),
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-09 15:22:48 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        100_000,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    )
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    .unwrap();
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-17 12:18:48 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    check_recent_balance(100_000, &rpc_client, &config_validator.signers[0].pubkey());
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-09 15:22:48 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-20 15:20:48 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let stake_address = Pubkey::create_with_seed(
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        &config_validator.signers[0].pubkey(),
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-09 15:22:48 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        "hi there",
							 | 
						
					
						
							
								
									
										
										
										
											2021-06-15 18:04:00 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        &stake::program::id(),
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-09 15:22:48 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    )
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    .expect("bad seed");
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    // Create stake account with a seed, uses the validator config as the base,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    //   which is nice ;)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    config_validator.command = CliCommand::CreateStakeAccount {
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        stake_account: 0,
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-09 15:22:48 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        seed: Some("hi there".to_string()),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        staker: None,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        withdrawer: None,
							 | 
						
					
						
							
								
									
										
										
										
											2021-07-15 16:45:03 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        withdrawer_signer: None,
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-09 15:22:48 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        lockup: Lockup::default(),
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-14 12:24:14 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        amount: SpendAmount::Some(50_000),
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-12 23:00:28 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        sign_only: false,
							 | 
						
					
						
							
								
									
										
										
										
											2021-03-12 19:37:39 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        dump_transaction_message: false,
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-11 12:14:15 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        blockhash_query: BlockhashQuery::All(blockhash_query::Source::Cluster),
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-12 23:00:28 -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,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        from: 0,
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-09 15:22:48 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    };
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    process_command(&config_validator).unwrap();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    // Delegate stake
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    config_validator.command = CliCommand::DelegateStake {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        stake_account_pubkey: stake_address,
							 | 
						
					
						
							
								
									
										
										
										
											2020-11-25 17:00:47 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        vote_account_pubkey: test_validator.vote_account_address(),
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        stake_authority: 0,
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-17 12:18:48 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        force: true,
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-09 15:22:48 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        sign_only: false,
							 | 
						
					
						
							
								
									
										
										
										
											2021-03-12 19:37:39 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        dump_transaction_message: false,
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-30 09:21:32 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        blockhash_query: BlockhashQuery::default(),
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-09 15:22:48 -08: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,
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-09 15:22:48 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    };
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    process_command(&config_validator).unwrap();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    // Deactivate stake
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    config_validator.command = CliCommand::DeactivateStake {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        stake_account_pubkey: stake_address,
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        stake_authority: 0,
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-09 15:22:48 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        sign_only: false,
							 | 
						
					
						
							
								
									
										
										
										
											2021-03-12 19:37:39 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        dump_transaction_message: false,
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-30 09:21:32 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        blockhash_query: BlockhashQuery::default(),
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-09 15:22:48 -08: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,
							 | 
						
					
						
							
								
									
										
										
										
											2021-04-21 11:05:05 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        seed: None,
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        fee_payer: 0,
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-09 15:22:48 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    };
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    process_command(&config_validator).unwrap();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2019-12-09 23:11:04 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								#[test]
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								fn test_stake_delegation_and_deactivation() {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    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_no_fees(mint_pubkey, Some(faucet_addr), SocketAddrSpace::Unspecified);
							 | 
						
					
						
							
								
									
										
										
										
											2019-12-09 23:11:04 -08: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-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let validator_keypair = Keypair::new();
							 | 
						
					
						
							
								
									
										
										
										
											2019-12-09 23:11:04 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-17 12:18:48 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let mut config_validator = CliConfig::recent_for_tests();
							 | 
						
					
						
							
								
									
										
										
										
											2020-11-25 17:00:47 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    config_validator.json_rpc_url = test_validator.rpc_url();
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    config_validator.signers = vec![&validator_keypair];
							 | 
						
					
						
							
								
									
										
										
										
											2019-12-09 23:11:04 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-21 14:55:53 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let stake_keypair = keypair_from_seed(&[0u8; 32]).unwrap();
							 | 
						
					
						
							
								
									
										
										
										
											2019-12-09 23:11:04 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    request_and_confirm_airdrop(
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        &rpc_client,
							 | 
						
					
						
							
								
									
										
										
										
											2021-04-15 00:25:23 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        &config_validator,
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        &config_validator.signers[0].pubkey(),
							 | 
						
					
						
							
								
									
										
										
										
											2019-12-09 23:11:04 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        100_000,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    )
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    .unwrap();
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-17 12:18:48 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    check_recent_balance(100_000, &rpc_client, &config_validator.signers[0].pubkey());
							 | 
						
					
						
							
								
									
										
										
										
											2019-12-09 23:11:04 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    // Create stake account
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    config_validator.signers.push(&stake_keypair);
							 | 
						
					
						
							
								
									
										
										
										
											2019-12-09 23:11:04 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    config_validator.command = CliCommand::CreateStakeAccount {
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        stake_account: 1,
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-09 15:22:48 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        seed: None,
							 | 
						
					
						
							
								
									
										
										
										
											2019-12-09 23:11:04 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        staker: None,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        withdrawer: None,
							 | 
						
					
						
							
								
									
										
										
										
											2021-07-15 16:45:03 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        withdrawer_signer: None,
							 | 
						
					
						
							
								
									
										
										
										
											2019-12-19 14:37:47 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        lockup: Lockup::default(),
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-14 12:24:14 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        amount: SpendAmount::Some(50_000),
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-12 23:00:28 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        sign_only: false,
							 | 
						
					
						
							
								
									
										
										
										
											2021-03-12 19:37:39 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        dump_transaction_message: false,
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-11 12:14:15 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        blockhash_query: BlockhashQuery::All(blockhash_query::Source::Cluster),
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-12 23:00:28 -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,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        from: 0,
							 | 
						
					
						
							
								
									
										
										
										
											2019-12-09 23:11:04 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    };
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    process_command(&config_validator).unwrap();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    // Delegate stake
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    config_validator.signers.pop();
							 | 
						
					
						
							
								
									
										
										
										
											2019-12-09 23:11:04 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    config_validator.command = CliCommand::DelegateStake {
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        stake_account_pubkey: stake_keypair.pubkey(),
							 | 
						
					
						
							
								
									
										
										
										
											2020-11-25 17:00:47 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        vote_account_pubkey: test_validator.vote_account_address(),
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        stake_authority: 0,
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-17 12:18:48 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        force: true,
							 | 
						
					
						
							
								
									
										
										
										
											2019-12-09 23:11:04 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        sign_only: false,
							 | 
						
					
						
							
								
									
										
										
										
											2021-03-12 19:37:39 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        dump_transaction_message: false,
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-30 09:21:32 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        blockhash_query: BlockhashQuery::default(),
							 | 
						
					
						
							
								
									
										
										
										
											2019-12-27 14:35:49 -06: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,
							 | 
						
					
						
							
								
									
										
										
										
											2019-12-09 23:11:04 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    };
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    process_command(&config_validator).unwrap();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    // Deactivate stake
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    config_validator.command = CliCommand::DeactivateStake {
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        stake_account_pubkey: stake_keypair.pubkey(),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        stake_authority: 0,
							 | 
						
					
						
							
								
									
										
										
										
											2019-12-09 23:11:04 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        sign_only: false,
							 | 
						
					
						
							
								
									
										
										
										
											2021-03-12 19:37:39 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        dump_transaction_message: false,
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-30 09:21:32 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        blockhash_query: BlockhashQuery::default(),
							 | 
						
					
						
							
								
									
										
										
										
											2019-12-27 14:35:49 -06: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,
							 | 
						
					
						
							
								
									
										
										
										
											2021-04-21 11:05:05 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        seed: None,
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        fee_payer: 0,
							 | 
						
					
						
							
								
									
										
										
										
											2019-12-09 23:11:04 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    };
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    process_command(&config_validator).unwrap();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								#[test]
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-09 15:22:48 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								fn test_offline_stake_delegation_and_deactivation() {
							 | 
						
					
						
							
								
									
										
										
										
											2019-12-09 23:11:04 -08: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_no_fees(mint_pubkey, Some(faucet_addr), SocketAddrSpace::Unspecified);
							 | 
						
					
						
							
								
									
										
										
										
											2019-12-09 23:11:04 -08: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());
							 | 
						
					
						
							
								
									
										
										
										
											2019-12-09 23:11:04 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-17 12:18:48 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let mut config_validator = CliConfig::recent_for_tests();
							 | 
						
					
						
							
								
									
										
										
										
											2020-11-25 17:00:47 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    config_validator.json_rpc_url = test_validator.rpc_url();
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let validator_keypair = Keypair::new();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    config_validator.signers = vec![&validator_keypair];
							 | 
						
					
						
							
								
									
										
										
										
											2019-12-09 23:11:04 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-17 12:18:48 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let mut config_payer = CliConfig::recent_for_tests();
							 | 
						
					
						
							
								
									
										
										
										
											2020-11-25 17:00:47 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    config_payer.json_rpc_url = test_validator.rpc_url();
							 | 
						
					
						
							
								
									
										
										
										
											2019-12-09 23:11:04 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-21 14:55:53 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let stake_keypair = keypair_from_seed(&[0u8; 32]).unwrap();
							 | 
						
					
						
							
								
									
										
										
										
											2019-12-09 23:11:04 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-17 12:18:48 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let mut config_offline = CliConfig::recent_for_tests();
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-10 18:59:05 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    config_offline.json_rpc_url = String::default();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    config_offline.command = CliCommand::ClusterVersion;
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let offline_keypair = Keypair::new();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    config_offline.signers = vec![&offline_keypair];
							 | 
						
					
						
							
								
									
										
										
										
											2021-02-13 15:07:04 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    // Verify that we cannot reach the cluster
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-10 18:59:05 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    process_command(&config_offline).unwrap_err();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2019-12-09 23:11:04 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    request_and_confirm_airdrop(
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        &rpc_client,
							 | 
						
					
						
							
								
									
										
										
										
											2021-04-15 00:25:23 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        &config_validator,
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        &config_validator.signers[0].pubkey(),
							 | 
						
					
						
							
								
									
										
										
										
											2019-12-09 23:11:04 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        100_000,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    )
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    .unwrap();
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-17 12:18:48 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    check_recent_balance(100_000, &rpc_client, &config_validator.signers[0].pubkey());
							 | 
						
					
						
							
								
									
										
										
										
											2019-12-09 23:11:04 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-10 18:59:05 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    request_and_confirm_airdrop(
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        &rpc_client,
							 | 
						
					
						
							
								
									
										
										
										
											2021-04-15 00:25:23 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        &config_offline,
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        &config_offline.signers[0].pubkey(),
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-10 18:59:05 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        100_000,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    )
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    .unwrap();
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-17 12:18:48 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    check_recent_balance(100_000, &rpc_client, &config_offline.signers[0].pubkey());
							 | 
						
					
						
							
								
									
										
										
										
											2019-12-09 23:11:04 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    // Create stake account
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    config_validator.signers.push(&stake_keypair);
							 | 
						
					
						
							
								
									
										
										
										
											2019-12-09 23:11:04 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    config_validator.command = CliCommand::CreateStakeAccount {
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        stake_account: 1,
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-09 15:22:48 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        seed: None,
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-15 17:35:43 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        staker: Some(config_offline.signers[0].pubkey()),
							 | 
						
					
						
							
								
									
										
										
										
											2019-12-09 23:11:04 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        withdrawer: None,
							 | 
						
					
						
							
								
									
										
										
										
											2021-07-15 16:45:03 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        withdrawer_signer: None,
							 | 
						
					
						
							
								
									
										
										
										
											2019-12-19 14:37:47 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        lockup: Lockup::default(),
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-14 12:24:14 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        amount: SpendAmount::Some(50_000),
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-12 23:00:28 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        sign_only: false,
							 | 
						
					
						
							
								
									
										
										
										
											2021-03-12 19:37:39 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        dump_transaction_message: false,
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-11 12:14:15 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        blockhash_query: BlockhashQuery::All(blockhash_query::Source::Cluster),
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-12 23:00:28 -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,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        from: 0,
							 | 
						
					
						
							
								
									
										
										
										
											2019-12-09 23:11:04 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    };
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    process_command(&config_validator).unwrap();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    // Delegate stake offline
							 | 
						
					
						
							
								
									
										
										
										
											2021-08-13 09:08:20 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let blockhash = rpc_client.get_latest_blockhash().unwrap();
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-10 18:59:05 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    config_offline.command = CliCommand::DelegateStake {
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        stake_account_pubkey: stake_keypair.pubkey(),
							 | 
						
					
						
							
								
									
										
										
										
											2020-11-25 17:00:47 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        vote_account_pubkey: test_validator.vote_account_address(),
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        stake_authority: 0,
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-17 12:18:48 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        force: true,
							 | 
						
					
						
							
								
									
										
										
										
											2019-12-09 23:11:04 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        sign_only: true,
							 | 
						
					
						
							
								
									
										
										
										
											2021-03-12 19:37:39 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        dump_transaction_message: false,
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-11 12:14:15 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        blockhash_query: BlockhashQuery::None(blockhash),
							 | 
						
					
						
							
								
									
										
										
										
											2019-12-27 14:35:49 -06: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,
							 | 
						
					
						
							
								
									
										
										
										
											2019-12-09 23:11:04 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    };
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-07 07:21:48 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    config_offline.output_format = OutputFormat::JsonCompact;
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-10 18:59:05 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let sig_response = process_command(&config_offline).unwrap();
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-18 21:49:38 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let sign_only = parse_sign_only_reply_string(&sig_response);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    assert!(sign_only.has_all_signers());
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let offline_presigner = sign_only
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        .presigner_of(&config_offline.signers[0].pubkey())
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        .unwrap();
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    config_payer.signers = vec![&offline_presigner];
							 | 
						
					
						
							
								
									
										
										
										
											2019-12-09 23:11:04 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    config_payer.command = CliCommand::DelegateStake {
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        stake_account_pubkey: stake_keypair.pubkey(),
							 | 
						
					
						
							
								
									
										
										
										
											2020-11-25 17:00:47 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        vote_account_pubkey: test_validator.vote_account_address(),
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        stake_authority: 0,
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-17 12:18:48 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        force: true,
							 | 
						
					
						
							
								
									
										
										
										
											2019-12-09 23:11:04 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        sign_only: false,
							 | 
						
					
						
							
								
									
										
										
										
											2021-03-12 19:37:39 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        dump_transaction_message: false,
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-11 12:14:15 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        blockhash_query: BlockhashQuery::FeeCalculator(blockhash_query::Source::Cluster, blockhash),
							 | 
						
					
						
							
								
									
										
										
										
											2019-12-27 14:35:49 -06: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,
							 | 
						
					
						
							
								
									
										
										
										
											2019-12-09 23:11:04 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    };
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    process_command(&config_payer).unwrap();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    // Deactivate stake offline
							 | 
						
					
						
							
								
									
										
										
										
											2021-08-13 09:08:20 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let blockhash = rpc_client.get_latest_blockhash().unwrap();
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-10 18:59:05 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    config_offline.command = CliCommand::DeactivateStake {
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        stake_account_pubkey: stake_keypair.pubkey(),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        stake_authority: 0,
							 | 
						
					
						
							
								
									
										
										
										
											2019-12-09 23:11:04 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        sign_only: true,
							 | 
						
					
						
							
								
									
										
										
										
											2021-03-12 19:37:39 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        dump_transaction_message: false,
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-11 12:14:15 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        blockhash_query: BlockhashQuery::None(blockhash),
							 | 
						
					
						
							
								
									
										
										
										
											2019-12-27 14:35:49 -06: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,
							 | 
						
					
						
							
								
									
										
										
										
											2021-04-21 11:05:05 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        seed: None,
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        fee_payer: 0,
							 | 
						
					
						
							
								
									
										
										
										
											2019-12-09 23:11:04 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    };
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-10 18:59:05 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let sig_response = process_command(&config_offline).unwrap();
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-18 21:49:38 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let sign_only = parse_sign_only_reply_string(&sig_response);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    assert!(sign_only.has_all_signers());
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let offline_presigner = sign_only
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        .presigner_of(&config_offline.signers[0].pubkey())
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        .unwrap();
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    config_payer.signers = vec![&offline_presigner];
							 | 
						
					
						
							
								
									
										
										
										
											2019-12-09 23:11:04 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    config_payer.command = CliCommand::DeactivateStake {
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        stake_account_pubkey: stake_keypair.pubkey(),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        stake_authority: 0,
							 | 
						
					
						
							
								
									
										
										
										
											2019-12-09 23:11:04 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        sign_only: false,
							 | 
						
					
						
							
								
									
										
										
										
											2021-03-12 19:37:39 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        dump_transaction_message: false,
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-11 12:14:15 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        blockhash_query: BlockhashQuery::FeeCalculator(blockhash_query::Source::Cluster, blockhash),
							 | 
						
					
						
							
								
									
										
										
										
											2019-12-27 14:35:49 -06: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,
							 | 
						
					
						
							
								
									
										
										
										
											2021-04-21 11:05:05 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        seed: None,
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        fee_payer: 0,
							 | 
						
					
						
							
								
									
										
										
										
											2019-12-09 23:11:04 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    };
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    process_command(&config_payer).unwrap();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							
								
									
										
										
										
											2019-12-27 14:35:49 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								#[test]
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								fn test_nonced_stake_delegation_and_deactivation() {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    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_no_fees(mint_pubkey, Some(faucet_addr), SocketAddrSpace::Unspecified);
							 | 
						
					
						
							
								
									
										
										
										
											2019-12-27 14:35:49 -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());
							 | 
						
					
						
							
								
									
										
										
										
											2019-12-27 14:35:49 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-21 14:55:53 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let config_keypair = keypair_from_seed(&[0u8; 32]).unwrap();
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-17 12:18:48 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let mut config = CliConfig::recent_for_tests();
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    config.signers = vec![&config_keypair];
							 | 
						
					
						
							
								
									
										
										
										
											2020-11-25 17:00:47 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    config.json_rpc_url = test_validator.rpc_url();
							 | 
						
					
						
							
								
									
										
										
										
											2019-12-27 14:35:49 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let minimum_nonce_balance = rpc_client
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-10 13:00:15 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        .get_minimum_balance_for_rent_exemption(NonceState::size())
							 | 
						
					
						
							
								
									
										
										
										
											2019-12-27 14:35:49 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        .unwrap();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2021-04-15 00:25:23 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    request_and_confirm_airdrop(&rpc_client, &config, &config.signers[0].pubkey(), 100_000)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        .unwrap();
							 | 
						
					
						
							
								
									
										
										
										
											2019-12-27 14:35:49 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    // Create stake account
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let stake_keypair = Keypair::new();
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    config.signers.push(&stake_keypair);
							 | 
						
					
						
							
								
									
										
										
										
											2019-12-27 14:35:49 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    config.command = CliCommand::CreateStakeAccount {
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        stake_account: 1,
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-09 15:22:48 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        seed: None,
							 | 
						
					
						
							
								
									
										
										
										
											2019-12-27 14:35:49 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        staker: None,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        withdrawer: None,
							 | 
						
					
						
							
								
									
										
										
										
											2021-07-15 16:45:03 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        withdrawer_signer: None,
							 | 
						
					
						
							
								
									
										
										
										
											2019-12-27 14:35:49 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        lockup: Lockup::default(),
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-14 12:24:14 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        amount: SpendAmount::Some(50_000),
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-12 23:00:28 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        sign_only: false,
							 | 
						
					
						
							
								
									
										
										
										
											2021-03-12 19:37:39 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        dump_transaction_message: false,
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-11 12:14:15 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        blockhash_query: BlockhashQuery::All(blockhash_query::Source::Cluster),
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-12 23:00:28 -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,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        from: 0,
							 | 
						
					
						
							
								
									
										
										
										
											2019-12-27 14:35:49 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    };
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    process_command(&config).unwrap();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    // Create nonce account
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let nonce_account = Keypair::new();
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    config.signers[1] = &nonce_account;
							 | 
						
					
						
							
								
									
										
										
										
											2019-12-27 14:35:49 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    config.command = CliCommand::CreateNonceAccount {
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        nonce_account: 1,
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-09 15:22:48 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        seed: None,
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        nonce_authority: Some(config.signers[0].pubkey()),
							 | 
						
					
						
							
								
									
										
										
										
											2021-04-05 13:53:50 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        memo: None,
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-14 12:24:14 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        amount: SpendAmount::Some(minimum_nonce_balance),
							 | 
						
					
						
							
								
									
										
										
										
											2019-12-27 14:35:49 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    };
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    process_command(&config).unwrap();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    // 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;
							 | 
						
					
						
							
								
									
										
										
										
											2019-12-27 14:35:49 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    // Delegate stake
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    config.signers = vec![&config_keypair];
							 | 
						
					
						
							
								
									
										
										
										
											2019-12-27 14:35:49 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    config.command = CliCommand::DelegateStake {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        stake_account_pubkey: stake_keypair.pubkey(),
							 | 
						
					
						
							
								
									
										
										
										
											2020-11-25 17:00:47 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        vote_account_pubkey: test_validator.vote_account_address(),
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        stake_authority: 0,
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-17 12:18:48 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        force: true,
							 | 
						
					
						
							
								
									
										
										
										
											2019-12-27 14:35:49 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        sign_only: false,
							 | 
						
					
						
							
								
									
										
										
										
											2021-03-12 19:37:39 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        dump_transaction_message: false,
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-11 12:14:15 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        blockhash_query: BlockhashQuery::FeeCalculator(
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            blockhash_query::Source::NonceAccount(nonce_account.pubkey()),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            nonce_hash,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        ),
							 | 
						
					
						
							
								
									
										
										
										
											2019-12-27 14:35:49 -06: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,
							 | 
						
					
						
							
								
									
										
										
										
											2019-12-27 14:35:49 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    };
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    process_command(&config).unwrap();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    // 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;
							 | 
						
					
						
							
								
									
										
										
										
											2019-12-27 14:35:49 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    // Deactivate stake
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    config.command = CliCommand::DeactivateStake {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        stake_account_pubkey: stake_keypair.pubkey(),
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        stake_authority: 0,
							 | 
						
					
						
							
								
									
										
										
										
											2019-12-27 14:35:49 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        sign_only: false,
							 | 
						
					
						
							
								
									
										
										
										
											2021-03-12 19:37:39 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        dump_transaction_message: false,
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-11 12:14:15 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        blockhash_query: BlockhashQuery::FeeCalculator(
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            blockhash_query::Source::NonceAccount(nonce_account.pubkey()),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            nonce_hash,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        ),
							 | 
						
					
						
							
								
									
										
										
										
											2019-12-27 14:35:49 -06: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,
							 | 
						
					
						
							
								
									
										
										
										
											2021-04-21 11:05:05 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        seed: None,
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        fee_payer: 0,
							 | 
						
					
						
							
								
									
										
										
										
											2019-12-27 14:35:49 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    };
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    process_command(&config).unwrap();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-15 14:32:06 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								#[test]
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								fn test_stake_authorize() {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    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_no_fees(mint_pubkey, Some(faucet_addr), SocketAddrSpace::Unspecified);
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-15 14:32:06 -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-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let default_signer = Keypair::new();
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-15 14:32:06 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											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-01-15 14:32:06 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2021-04-15 00:25:23 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    request_and_confirm_airdrop(&rpc_client, &config, &config.signers[0].pubkey(), 100_000)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        .unwrap();
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-15 14:32:06 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-21 14:55:53 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let offline_keypair = keypair_from_seed(&[0u8; 32]).unwrap();
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-17 12:18:48 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let mut config_offline = CliConfig::recent_for_tests();
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    config_offline.signers = vec![&offline_keypair];
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-10 18:59:05 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    config_offline.json_rpc_url = String::default();
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let offline_authority_pubkey = config_offline.signers[0].pubkey();
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-10 18:59:05 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    config_offline.command = CliCommand::ClusterVersion;
							 | 
						
					
						
							
								
									
										
										
										
											2021-02-13 15:07:04 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    // Verify that we cannot reach the cluster
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-10 18:59:05 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    process_command(&config_offline).unwrap_err();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    request_and_confirm_airdrop(
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        &rpc_client,
							 | 
						
					
						
							
								
									
										
										
										
											2021-04-15 00:25:23 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        &config_offline,
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        &config_offline.signers[0].pubkey(),
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-10 18:59:05 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        100_000,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    )
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    .unwrap();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-15 14:32:06 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    // Create stake account, identity is authority
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let stake_keypair = Keypair::new();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let stake_account_pubkey = stake_keypair.pubkey();
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    config.signers.push(&stake_keypair);
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-15 14:32:06 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    config.command = CliCommand::CreateStakeAccount {
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        stake_account: 1,
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-15 14:32:06 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        seed: None,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        staker: None,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        withdrawer: None,
							 | 
						
					
						
							
								
									
										
										
										
											2021-07-15 16:45:03 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        withdrawer_signer: None,
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-15 14:32:06 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        lockup: Lockup::default(),
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-14 12:24:14 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        amount: SpendAmount::Some(50_000),
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-12 23:00:28 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        sign_only: false,
							 | 
						
					
						
							
								
									
										
										
										
											2021-03-12 19:37:39 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        dump_transaction_message: false,
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-11 12:14:15 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        blockhash_query: BlockhashQuery::All(blockhash_query::Source::Cluster),
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-12 23:00:28 -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,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        from: 0,
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-15 14:32:06 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    };
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    process_command(&config).unwrap();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    // Assign new online stake authority
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let online_authority = Keypair::new();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let online_authority_pubkey = online_authority.pubkey();
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    config.signers.pop();
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-15 14:32:06 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    config.command = CliCommand::StakeAuthorize {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        stake_account_pubkey,
							 | 
						
					
						
							
								
									
										
										
										
											2021-07-15 16:45:03 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        new_authorizations: vec![StakeAuthorizationIndexed {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            authorization_type: StakeAuthorize::Staker,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            new_authority_pubkey: online_authority_pubkey,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            authority: 0,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            new_authority_signer: None,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        }],
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-17 10:30:56 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        sign_only: false,
							 | 
						
					
						
							
								
									
										
										
										
											2021-03-12 19:37:39 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        dump_transaction_message: false,
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-30 09:21:32 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        blockhash_query: BlockhashQuery::default(),
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-17 10:30:56 -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-01-26 09:44:44 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        custodian: None,
							 | 
						
					
						
							
								
									
										
										
										
											2021-05-17 10:54:33 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        no_wait: false,
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-15 14:32:06 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    };
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    process_command(&config).unwrap();
							 | 
						
					
						
							
								
									
										
										
										
											2021-01-19 15:33:03 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let stake_account = rpc_client.get_account(&stake_account_pubkey).unwrap();
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-15 14:32:06 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let stake_state: StakeState = stake_account.state().unwrap();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let current_authority = match stake_state {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        StakeState::Initialized(meta) => meta.authorized.staker,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        _ => panic!("Unexpected stake state!"),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    };
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    assert_eq!(current_authority, online_authority_pubkey);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-21 19:56:17 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    // Assign new online stake and withdraw authorities
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let online_authority2 = Keypair::new();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let online_authority2_pubkey = online_authority2.pubkey();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let withdraw_authority = Keypair::new();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let withdraw_authority_pubkey = withdraw_authority.pubkey();
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    config.signers.push(&online_authority);
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-15 14:32:06 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    config.command = CliCommand::StakeAuthorize {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        stake_account_pubkey,
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-21 19:56:17 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        new_authorizations: vec![
							 | 
						
					
						
							
								
									
										
										
										
											2021-07-15 16:45:03 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            StakeAuthorizationIndexed {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                authorization_type: StakeAuthorize::Staker,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                new_authority_pubkey: online_authority2_pubkey,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                authority: 1,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                new_authority_signer: None,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            },
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            StakeAuthorizationIndexed {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                authorization_type: StakeAuthorize::Withdrawer,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                new_authority_pubkey: withdraw_authority_pubkey,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                authority: 0,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                new_authority_signer: None,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            },
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-21 19:56:17 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        ],
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        sign_only: false,
							 | 
						
					
						
							
								
									
										
										
										
											2021-03-12 19:37:39 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        dump_transaction_message: false,
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-21 19:56:17 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        blockhash_query: BlockhashQuery::default(),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        nonce_account: None,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        nonce_authority: 0,
							 | 
						
					
						
							
								
									
										
										
										
											2021-04-05 13:53:50 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        memo: None,
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-21 19:56:17 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        fee_payer: 0,
							 | 
						
					
						
							
								
									
										
										
										
											2021-01-26 09:44:44 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        custodian: None,
							 | 
						
					
						
							
								
									
										
										
										
											2021-05-17 10:54:33 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        no_wait: false,
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-21 19:56:17 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    };
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    process_command(&config).unwrap();
							 | 
						
					
						
							
								
									
										
										
										
											2021-01-19 15:33:03 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let stake_account = rpc_client.get_account(&stake_account_pubkey).unwrap();
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-21 19:56:17 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let stake_state: StakeState = stake_account.state().unwrap();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let (current_staker, current_withdrawer) = match stake_state {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        StakeState::Initialized(meta) => (meta.authorized.staker, meta.authorized.withdrawer),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        _ => panic!("Unexpected stake state!"),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    };
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    assert_eq!(current_staker, online_authority2_pubkey);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    assert_eq!(current_withdrawer, withdraw_authority_pubkey);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    // Assign new offline stake authority
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    config.signers.pop();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    config.signers.push(&online_authority2);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    config.command = CliCommand::StakeAuthorize {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        stake_account_pubkey,
							 | 
						
					
						
							
								
									
										
										
										
											2021-07-15 16:45:03 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        new_authorizations: vec![StakeAuthorizationIndexed {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            authorization_type: StakeAuthorize::Staker,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            new_authority_pubkey: offline_authority_pubkey,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            authority: 1,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            new_authority_signer: None,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        }],
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-17 10:30:56 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        sign_only: false,
							 | 
						
					
						
							
								
									
										
										
										
											2021-03-12 19:37:39 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        dump_transaction_message: false,
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-30 09:21:32 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        blockhash_query: BlockhashQuery::default(),
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-17 10:30:56 -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-01-26 09:44:44 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        custodian: None,
							 | 
						
					
						
							
								
									
										
										
										
											2021-05-17 10:54:33 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        no_wait: false,
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-15 14:32:06 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    };
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    process_command(&config).unwrap();
							 | 
						
					
						
							
								
									
										
										
										
											2021-01-19 15:33:03 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let stake_account = rpc_client.get_account(&stake_account_pubkey).unwrap();
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-15 14:32:06 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let stake_state: StakeState = stake_account.state().unwrap();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let current_authority = match stake_state {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        StakeState::Initialized(meta) => meta.authorized.staker,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        _ => panic!("Unexpected stake state!"),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    };
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    assert_eq!(current_authority, offline_authority_pubkey);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-17 10:30:56 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    // Offline assignment of new nonced stake authority
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let nonced_authority = Keypair::new();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let nonced_authority_pubkey = nonced_authority.pubkey();
							 | 
						
					
						
							
								
									
										
										
										
											2021-08-13 09:08:20 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let blockhash = rpc_client.get_latest_blockhash().unwrap();
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-10 18:59:05 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    config_offline.command = CliCommand::StakeAuthorize {
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-17 10:30:56 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        stake_account_pubkey,
							 | 
						
					
						
							
								
									
										
										
										
											2021-07-15 16:45:03 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        new_authorizations: vec![StakeAuthorizationIndexed {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            authorization_type: StakeAuthorize::Staker,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            new_authority_pubkey: nonced_authority_pubkey,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            authority: 0,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            new_authority_signer: None,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        }],
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-17 10:30:56 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        sign_only: true,
							 | 
						
					
						
							
								
									
										
										
										
											2021-03-12 19:37:39 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        dump_transaction_message: false,
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-11 12:14:15 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        blockhash_query: BlockhashQuery::None(blockhash),
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-17 10:30:56 -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-01-26 09:44:44 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        custodian: None,
							 | 
						
					
						
							
								
									
										
										
										
											2021-05-17 10:54:33 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        no_wait: false,
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-17 10:30:56 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    };
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-07 07:21:48 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    config_offline.output_format = OutputFormat::JsonCompact;
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-10 18:59:05 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let sign_reply = process_command(&config_offline).unwrap();
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-18 21:49:38 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let sign_only = parse_sign_only_reply_string(&sign_reply);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    assert!(sign_only.has_all_signers());
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let offline_presigner = sign_only.presigner_of(&offline_authority_pubkey).unwrap();
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    config.signers = vec![&offline_presigner];
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-17 10:30:56 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    config.command = CliCommand::StakeAuthorize {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        stake_account_pubkey,
							 | 
						
					
						
							
								
									
										
										
										
											2021-07-15 16:45:03 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        new_authorizations: vec![StakeAuthorizationIndexed {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            authorization_type: StakeAuthorize::Staker,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            new_authority_pubkey: nonced_authority_pubkey,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            authority: 0,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            new_authority_signer: None,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        }],
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-17 10:30:56 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        sign_only: false,
							 | 
						
					
						
							
								
									
										
										
										
											2021-03-12 19:37:39 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        dump_transaction_message: false,
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-11 12:14:15 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        blockhash_query: BlockhashQuery::FeeCalculator(blockhash_query::Source::Cluster, blockhash),
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-17 10:30:56 -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-01-26 09:44:44 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        custodian: None,
							 | 
						
					
						
							
								
									
										
										
										
											2021-05-17 10:54:33 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        no_wait: false,
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-17 10:30:56 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    };
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    process_command(&config).unwrap();
							 | 
						
					
						
							
								
									
										
										
										
											2021-01-19 15:33:03 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let stake_account = rpc_client.get_account(&stake_account_pubkey).unwrap();
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-17 10:30:56 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let stake_state: StakeState = stake_account.state().unwrap();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let current_authority = match stake_state {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        StakeState::Initialized(meta) => meta.authorized.staker,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        _ => panic!("Unexpected stake state!"),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    };
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    assert_eq!(current_authority, nonced_authority_pubkey);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    // Create nonce account
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let minimum_nonce_balance = rpc_client
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-10 13:00:15 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        .get_minimum_balance_for_rent_exemption(NonceState::size())
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-17 10:30:56 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        .unwrap();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let nonce_account = Keypair::new();
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    config.signers = vec![&default_signer, &nonce_account];
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-17 10:30:56 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    config.command = CliCommand::CreateNonceAccount {
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        nonce_account: 1,
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-17 10:30:56 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        seed: None,
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        nonce_authority: Some(offline_authority_pubkey),
							 | 
						
					
						
							
								
									
										
										
										
											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-01-17 10:30:56 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    };
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    process_command(&config).unwrap();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    // 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-01-17 10:30:56 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-22 10:10:22 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    // Nonced assignment of new online stake authority
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-17 10:30:56 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let online_authority = Keypair::new();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let online_authority_pubkey = online_authority.pubkey();
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    config_offline.signers.push(&nonced_authority);
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-10 18:59:05 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    config_offline.command = CliCommand::StakeAuthorize {
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-17 10:30:56 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        stake_account_pubkey,
							 | 
						
					
						
							
								
									
										
										
										
											2021-07-15 16:45:03 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        new_authorizations: vec![StakeAuthorizationIndexed {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            authorization_type: StakeAuthorize::Staker,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            new_authority_pubkey: online_authority_pubkey,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            authority: 1,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            new_authority_signer: None,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        }],
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-17 10:30:56 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        sign_only: true,
							 | 
						
					
						
							
								
									
										
										
										
											2021-03-12 19:37:39 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        dump_transaction_message: false,
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-11 12:14:15 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        blockhash_query: BlockhashQuery::None(nonce_hash),
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-17 10:30:56 -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-01-26 09:44:44 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        custodian: None,
							 | 
						
					
						
							
								
									
										
										
										
											2021-05-17 10:54:33 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        no_wait: false,
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-17 10:30:56 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    };
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-10 18:59:05 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let sign_reply = process_command(&config_offline).unwrap();
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-18 21:49:38 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let sign_only = parse_sign_only_reply_string(&sign_reply);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    assert!(sign_only.has_all_signers());
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    assert_eq!(sign_only.blockhash, nonce_hash);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let offline_presigner = sign_only.presigner_of(&offline_authority_pubkey).unwrap();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let nonced_authority_presigner = sign_only.presigner_of(&nonced_authority_pubkey).unwrap();
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    config.signers = vec![&offline_presigner, &nonced_authority_presigner];
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-17 10:30:56 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    config.command = CliCommand::StakeAuthorize {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        stake_account_pubkey,
							 | 
						
					
						
							
								
									
										
										
										
											2021-07-15 16:45:03 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        new_authorizations: vec![StakeAuthorizationIndexed {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            authorization_type: StakeAuthorize::Staker,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            new_authority_pubkey: online_authority_pubkey,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            authority: 1,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            new_authority_signer: None,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        }],
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-17 10:30:56 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        sign_only: false,
							 | 
						
					
						
							
								
									
										
										
										
											2021-03-12 19:37:39 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        dump_transaction_message: 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-01-17 10:30:56 -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-01-26 09:44:44 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        custodian: None,
							 | 
						
					
						
							
								
									
										
										
										
											2021-05-17 10:54:33 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        no_wait: false,
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-17 10:30:56 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    };
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    process_command(&config).unwrap();
							 | 
						
					
						
							
								
									
										
										
										
											2021-01-19 15:33:03 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let stake_account = rpc_client.get_account(&stake_account_pubkey).unwrap();
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-17 10:30:56 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let stake_state: StakeState = stake_account.state().unwrap();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let current_authority = match stake_state {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        StakeState::Initialized(meta) => meta.authorized.staker,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        _ => panic!("Unexpected stake state!"),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    };
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    assert_eq!(current_authority, online_authority_pubkey);
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-10 13:00:15 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											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-01-17 10:30:56 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    assert_ne!(nonce_hash, new_nonce_hash);
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-07 09:14:27 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								#[test]
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								fn test_stake_authorize_with_fee_payer() {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    solana_logger::setup();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    const SIG_FEE: u64 = 42;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											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,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        SIG_FEE,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        Some(faucet_addr),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        SocketAddrSpace::Unspecified,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    );
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-07 09:14:27 -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-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let default_signer = Keypair::new();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let default_pubkey = default_signer.pubkey();
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-07 09:14:27 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											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 09:14:27 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-21 14:55:53 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let payer_keypair = keypair_from_seed(&[0u8; 32]).unwrap();
							 | 
						
					
						
							
								
									
										
										
										
											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.signers = vec![&payer_keypair];
							 | 
						
					
						
							
								
									
										
										
										
											2020-11-25 17:00:47 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    config_payer.json_rpc_url = test_validator.rpc_url();
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let payer_pubkey = config_payer.signers[0].pubkey();
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-07 09:14:27 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-17 12:18:48 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let mut config_offline = CliConfig::recent_for_tests();
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let offline_signer = Keypair::new();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    config_offline.signers = vec![&offline_signer];
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-18 21:49:38 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    config_offline.json_rpc_url = String::new();
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let offline_pubkey = config_offline.signers[0].pubkey();
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-07 09:14:27 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    // Verify we're offline
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    config_offline.command = CliCommand::ClusterVersion;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    process_command(&config_offline).unwrap_err();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2021-04-15 00:25:23 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    request_and_confirm_airdrop(&rpc_client, &config, &default_pubkey, 100_000).unwrap();
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-17 12:18:48 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    check_recent_balance(100_000, &rpc_client, &config.signers[0].pubkey());
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-07 09:14:27 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2021-04-15 00:25:23 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    request_and_confirm_airdrop(&rpc_client, &config_payer, &payer_pubkey, 100_000).unwrap();
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-17 12:18:48 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    check_recent_balance(100_000, &rpc_client, &payer_pubkey);
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-07 09:14:27 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2021-04-15 00:25:23 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    request_and_confirm_airdrop(&rpc_client, &config_offline, &offline_pubkey, 100_000).unwrap();
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-17 12:18:48 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    check_recent_balance(100_000, &rpc_client, &offline_pubkey);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    check_ready(&rpc_client);
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-07 09:14:27 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    // Create stake account, identity is authority
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let stake_keypair = Keypair::new();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let stake_account_pubkey = stake_keypair.pubkey();
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    config.signers.push(&stake_keypair);
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-07 09:14:27 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    config.command = CliCommand::CreateStakeAccount {
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        stake_account: 1,
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-07 09:14:27 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        seed: None,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        staker: None,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        withdrawer: None,
							 | 
						
					
						
							
								
									
										
										
										
											2021-07-15 16:45:03 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        withdrawer_signer: None,
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-07 09:14:27 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        lockup: Lockup::default(),
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-14 12:24:14 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        amount: SpendAmount::Some(50_000),
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-12 23:00:28 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        sign_only: false,
							 | 
						
					
						
							
								
									
										
										
										
											2021-03-12 19:37:39 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        dump_transaction_message: false,
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-11 12:14:15 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        blockhash_query: BlockhashQuery::All(blockhash_query::Source::Cluster),
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-12 23:00:28 -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,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        from: 0,
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-07 09:14:27 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    };
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    process_command(&config).unwrap();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    // `config` balance should be 50,000 - 1 stake account sig - 1 fee sig
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-17 12:18:48 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    check_recent_balance(50_000 - SIG_FEE - SIG_FEE, &rpc_client, &default_pubkey);
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-07 09:14:27 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    // Assign authority with separate fee payer
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    config.signers = vec![&default_signer, &payer_keypair];
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-07 09:14:27 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    config.command = CliCommand::StakeAuthorize {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        stake_account_pubkey,
							 | 
						
					
						
							
								
									
										
										
										
											2021-07-15 16:45:03 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        new_authorizations: vec![StakeAuthorizationIndexed {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            authorization_type: StakeAuthorize::Staker,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            new_authority_pubkey: offline_pubkey,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            authority: 0,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            new_authority_signer: None,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        }],
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-07 09:14:27 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        sign_only: false,
							 | 
						
					
						
							
								
									
										
										
										
											2021-03-12 19:37:39 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        dump_transaction_message: false,
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-11 12:14:15 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        blockhash_query: BlockhashQuery::All(blockhash_query::Source::Cluster),
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-07 09:14:27 -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: 1,
							 | 
						
					
						
							
								
									
										
										
										
											2021-01-26 09:44:44 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        custodian: None,
							 | 
						
					
						
							
								
									
										
										
										
											2021-05-17 10:54:33 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        no_wait: false,
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-07 09:14:27 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    };
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    process_command(&config).unwrap();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    // `config` balance has not changed, despite submitting the TX
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-17 12:18:48 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    check_recent_balance(50_000 - SIG_FEE - SIG_FEE, &rpc_client, &default_pubkey);
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-07 09:14:27 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    // `config_payer` however has paid `config`'s authority sig
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    // and `config_payer`'s fee sig
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-17 12:18:48 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    check_recent_balance(100_000 - SIG_FEE - SIG_FEE, &rpc_client, &payer_pubkey);
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-07 09:14:27 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    // Assign authority with offline fee payer
							 | 
						
					
						
							
								
									
										
										
										
											2021-08-13 09:08:20 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let blockhash = rpc_client.get_latest_blockhash().unwrap();
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-07 09:14:27 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    config_offline.command = CliCommand::StakeAuthorize {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        stake_account_pubkey,
							 | 
						
					
						
							
								
									
										
										
										
											2021-07-15 16:45:03 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        new_authorizations: vec![StakeAuthorizationIndexed {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            authorization_type: StakeAuthorize::Staker,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            new_authority_pubkey: payer_pubkey,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            authority: 0,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            new_authority_signer: None,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        }],
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-07 09:14:27 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        sign_only: true,
							 | 
						
					
						
							
								
									
										
										
										
											2021-03-12 19:37:39 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        dump_transaction_message: false,
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-11 12:14:15 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        blockhash_query: BlockhashQuery::None(blockhash),
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-07 09:14:27 -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-01-26 09:44:44 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        custodian: None,
							 | 
						
					
						
							
								
									
										
										
										
											2021-05-17 10:54:33 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        no_wait: false,
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-07 09:14:27 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    };
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-07 07:21:48 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    config_offline.output_format = OutputFormat::JsonCompact;
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-07 09:14:27 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let sign_reply = process_command(&config_offline).unwrap();
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-18 21:49:38 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let sign_only = parse_sign_only_reply_string(&sign_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 09:14:27 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    config.command = CliCommand::StakeAuthorize {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        stake_account_pubkey,
							 | 
						
					
						
							
								
									
										
										
										
											2021-07-15 16:45:03 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        new_authorizations: vec![StakeAuthorizationIndexed {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            authorization_type: StakeAuthorize::Staker,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            new_authority_pubkey: payer_pubkey,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            authority: 0,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            new_authority_signer: None,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        }],
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-07 09:14:27 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        sign_only: false,
							 | 
						
					
						
							
								
									
										
										
										
											2021-03-12 19:37:39 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        dump_transaction_message: false,
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-11 12:14:15 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        blockhash_query: BlockhashQuery::FeeCalculator(blockhash_query::Source::Cluster, blockhash),
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-07 09:14:27 -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-01-26 09:44:44 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        custodian: None,
							 | 
						
					
						
							
								
									
										
										
										
											2021-05-17 10:54:33 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        no_wait: false,
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-07 09:14:27 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    };
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    process_command(&config).unwrap();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    // `config`'s balance again has not changed
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-17 12:18:48 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    check_recent_balance(50_000 - SIG_FEE - SIG_FEE, &rpc_client, &default_pubkey);
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-07 09:14:27 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    // `config_offline` however has paid 1 sig due to being both authority
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    // and fee payer
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-17 12:18:48 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    check_recent_balance(100_000 - SIG_FEE, &rpc_client, &offline_pubkey);
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-15 14:32:06 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-11 00:23:54 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								#[test]
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								fn test_stake_split() {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    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-11 00:23:54 -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-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let default_signer = Keypair::new();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let offline_signer = Keypair::new();
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-11 00:23:54 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											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-11 00:23:54 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-17 12:18:48 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let mut config_offline = CliConfig::recent_for_tests();
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-12 16:36:29 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    config_offline.json_rpc_url = String::default();
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    config_offline.signers = vec![&offline_signer];
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let offline_pubkey = config_offline.signers[0].pubkey();
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-11 00:23:54 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    // Verify we're offline
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    config_offline.command = CliCommand::ClusterVersion;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    process_command(&config_offline).unwrap_err();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2021-04-15 00:25:23 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    request_and_confirm_airdrop(&rpc_client, &config, &config.signers[0].pubkey(), 500_000)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        .unwrap();
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-17 12:18:48 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    check_recent_balance(500_000, &rpc_client, &config.signers[0].pubkey());
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-11 00:23:54 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2021-04-15 00:25:23 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    request_and_confirm_airdrop(&rpc_client, &config_offline, &offline_pubkey, 100_000).unwrap();
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-17 12:18:48 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    check_recent_balance(100_000, &rpc_client, &offline_pubkey);
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-11 00:23:54 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    // Create stake account, identity is authority
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let minimum_stake_balance = rpc_client
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        .get_minimum_balance_for_rent_exemption(std::mem::size_of::<StakeState>())
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        .unwrap();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let stake_keypair = keypair_from_seed(&[0u8; 32]).unwrap();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let stake_account_pubkey = stake_keypair.pubkey();
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    config.signers.push(&stake_keypair);
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-11 00:23:54 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    config.command = CliCommand::CreateStakeAccount {
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        stake_account: 1,
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-11 00:23:54 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        seed: None,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        staker: Some(offline_pubkey),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        withdrawer: Some(offline_pubkey),
							 | 
						
					
						
							
								
									
										
										
										
											2021-07-15 16:45:03 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        withdrawer_signer: None,
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-11 00:23:54 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        lockup: Lockup::default(),
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-14 12:24:14 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        amount: SpendAmount::Some(10 * minimum_stake_balance),
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-12 23:00:28 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        sign_only: false,
							 | 
						
					
						
							
								
									
										
										
										
											2021-03-12 19:37:39 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        dump_transaction_message: false,
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-11 12:14:15 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        blockhash_query: BlockhashQuery::All(blockhash_query::Source::Cluster),
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-12 23:00:28 -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,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        from: 0,
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-11 00:23:54 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    };
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    process_command(&config).unwrap();
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-17 12:18:48 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    check_recent_balance(
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-11 00:23:54 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        10 * minimum_stake_balance,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        &rpc_client,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        &stake_account_pubkey,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    );
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    // Create nonce account
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let minimum_nonce_balance = rpc_client
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-10 13:00:15 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        .get_minimum_balance_for_rent_exemption(NonceState::size())
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-11 00:23:54 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        .unwrap();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let nonce_account = keypair_from_seed(&[1u8; 32]).unwrap();
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    config.signers = vec![&default_signer, &nonce_account];
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-11 00:23:54 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    config.command = CliCommand::CreateNonceAccount {
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        nonce_account: 1,
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-11 00:23:54 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        seed: None,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        nonce_authority: Some(offline_pubkey),
							 | 
						
					
						
							
								
									
										
										
										
											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-11 00:23:54 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    };
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    process_command(&config).unwrap();
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-17 12:18:48 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    check_recent_balance(minimum_nonce_balance, &rpc_client, &nonce_account.pubkey());
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-11 00:23:54 -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-11 00:23:54 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    // Nonced offline split
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let split_account = keypair_from_seed(&[2u8; 32]).unwrap();
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-17 12:18:48 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    check_recent_balance(0, &rpc_client, &split_account.pubkey());
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    config_offline.signers.push(&split_account);
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-11 00:23:54 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    config_offline.command = CliCommand::SplitStake {
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-15 17:35:43 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        stake_account_pubkey,
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        stake_authority: 0,
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-11 00:23:54 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        sign_only: true,
							 | 
						
					
						
							
								
									
										
										
										
											2021-03-12 19:37:39 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        dump_transaction_message: false,
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-11 12:14:15 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        blockhash_query: BlockhashQuery::None(nonce_hash),
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        nonce_account: Some(nonce_account.pubkey()),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        nonce_authority: 0,
							 | 
						
					
						
							
								
									
										
										
										
											2021-04-05 13:53:50 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        memo: None,
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        split_stake_account: 1,
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-11 00:23:54 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        seed: None,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        lamports: 2 * minimum_stake_balance,
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        fee_payer: 0,
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-11 00:23:54 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    };
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-07 07:21:48 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    config_offline.output_format = OutputFormat::JsonCompact;
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-11 00:23:54 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let sig_response = process_command(&config_offline).unwrap();
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-18 21:49:38 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let sign_only = parse_sign_only_reply_string(&sig_response);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    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, &split_account];
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-11 00:23:54 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    config.command = CliCommand::SplitStake {
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-15 17:35:43 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        stake_account_pubkey,
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        stake_authority: 0,
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-11 00:23:54 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        sign_only: false,
							 | 
						
					
						
							
								
									
										
										
										
											2021-03-12 19:37:39 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        dump_transaction_message: 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-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        nonce_account: Some(nonce_account.pubkey()),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        nonce_authority: 0,
							 | 
						
					
						
							
								
									
										
										
										
											2021-04-05 13:53:50 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        memo: None,
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        split_stake_account: 1,
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-11 00:23:54 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        seed: None,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        lamports: 2 * minimum_stake_balance,
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        fee_payer: 0,
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-11 00:23:54 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    };
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    process_command(&config).unwrap();
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-17 12:18:48 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    check_recent_balance(
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-11 00:23:54 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        8 * minimum_stake_balance,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        &rpc_client,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        &stake_account_pubkey,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    );
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-17 12:18:48 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    check_recent_balance(
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-11 00:23:54 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        2 * minimum_stake_balance,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        &rpc_client,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        &split_account.pubkey(),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    );
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-12 16:36:29 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								#[test]
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								fn test_stake_set_lockup() {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    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-12 16:36:29 -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-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let default_signer = Keypair::new();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let offline_signer = Keypair::new();
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-12 16:36:29 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											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-12 16:36:29 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-17 12:18:48 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let mut config_offline = CliConfig::recent_for_tests();
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-12 16:36:29 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    config_offline.json_rpc_url = String::default();
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    config_offline.signers = vec![&offline_signer];
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let offline_pubkey = config_offline.signers[0].pubkey();
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-12 16:36:29 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    // Verify we're offline
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    config_offline.command = CliCommand::ClusterVersion;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    process_command(&config_offline).unwrap_err();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2021-04-15 00:25:23 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    request_and_confirm_airdrop(&rpc_client, &config, &config.signers[0].pubkey(), 500_000)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        .unwrap();
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-17 12:18:48 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    check_recent_balance(500_000, &rpc_client, &config.signers[0].pubkey());
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-12 16:36:29 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2021-04-15 00:25:23 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    request_and_confirm_airdrop(&rpc_client, &config_offline, &offline_pubkey, 100_000).unwrap();
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-17 12:18:48 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    check_recent_balance(100_000, &rpc_client, &offline_pubkey);
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-12 16:36:29 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    // Create stake account, identity is authority
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let minimum_stake_balance = rpc_client
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        .get_minimum_balance_for_rent_exemption(std::mem::size_of::<StakeState>())
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        .unwrap();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let stake_keypair = keypair_from_seed(&[0u8; 32]).unwrap();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let stake_account_pubkey = stake_keypair.pubkey();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2020-12-13 17:26:34 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let lockup = Lockup {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        custodian: config.signers[0].pubkey(),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        ..Lockup::default()
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    };
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-12 16:36:29 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    config.signers.push(&stake_keypair);
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-12 16:36:29 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    config.command = CliCommand::CreateStakeAccount {
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        stake_account: 1,
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-12 16:36:29 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        seed: None,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        staker: Some(offline_pubkey),
							 | 
						
					
						
							
								
									
										
										
										
											2021-05-20 14:04:07 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        withdrawer: Some(config.signers[0].pubkey()),
							 | 
						
					
						
							
								
									
										
										
										
											2021-07-15 16:45:03 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        withdrawer_signer: None,
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-12 16:36:29 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        lockup,
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-14 12:24:14 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        amount: SpendAmount::Some(10 * minimum_stake_balance),
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-12 23:00:28 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        sign_only: false,
							 | 
						
					
						
							
								
									
										
										
										
											2021-03-12 19:37:39 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        dump_transaction_message: false,
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-11 12:14:15 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        blockhash_query: BlockhashQuery::All(blockhash_query::Source::Cluster),
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-12 23:00:28 -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,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        from: 0,
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-12 16:36:29 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    };
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    process_command(&config).unwrap();
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-17 12:18:48 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    check_recent_balance(
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-12 16:36:29 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        10 * minimum_stake_balance,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        &rpc_client,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        &stake_account_pubkey,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    );
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    // Online set lockup
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-02 12:28:43 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let lockup = LockupArgs {
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-15 17:35:43 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        unix_timestamp: Some(1_581_534_570),
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-02 12:28:43 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        epoch: Some(200),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        custodian: None,
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-12 16:36:29 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    };
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    config.signers.pop();
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-12 16:36:29 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    config.command = CliCommand::StakeSetLockup {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        stake_account_pubkey,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        lockup,
							 | 
						
					
						
							
								
									
										
										
										
											2021-07-15 16:45:03 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        new_custodian_signer: None,
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        custodian: 0,
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-12 16:36:29 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        sign_only: false,
							 | 
						
					
						
							
								
									
										
										
										
											2021-03-12 19:37:39 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        dump_transaction_message: false,
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-12 16:36:29 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        blockhash_query: BlockhashQuery::default(),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        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,
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-12 16:36:29 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    };
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    process_command(&config).unwrap();
							 | 
						
					
						
							
								
									
										
										
										
											2021-01-19 15:33:03 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let stake_account = rpc_client.get_account(&stake_account_pubkey).unwrap();
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-12 16:36:29 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let stake_state: StakeState = stake_account.state().unwrap();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let current_lockup = match stake_state {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        StakeState::Initialized(meta) => meta.lockup,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        _ => panic!("Unexpected stake state!"),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    };
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-02 12:28:43 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    assert_eq!(
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        current_lockup.unix_timestamp,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        lockup.unix_timestamp.unwrap()
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    );
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    assert_eq!(current_lockup.epoch, lockup.epoch.unwrap());
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    assert_eq!(current_lockup.custodian, config.signers[0].pubkey());
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-12 16:36:29 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    // Set custodian to another pubkey
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let online_custodian = Keypair::new();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let online_custodian_pubkey = online_custodian.pubkey();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-02 12:28:43 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let lockup = LockupArgs {
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-15 17:35:43 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        unix_timestamp: Some(1_581_534_571),
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-02 12:28:43 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        epoch: Some(201),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        custodian: Some(online_custodian_pubkey),
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-12 16:36:29 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    };
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    config.command = CliCommand::StakeSetLockup {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        stake_account_pubkey,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        lockup,
							 | 
						
					
						
							
								
									
										
										
										
											2021-07-15 16:45:03 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        new_custodian_signer: None,
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        custodian: 0,
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-12 16:36:29 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        sign_only: false,
							 | 
						
					
						
							
								
									
										
										
										
											2021-03-12 19:37:39 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        dump_transaction_message: false,
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-12 16:36:29 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        blockhash_query: BlockhashQuery::default(),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        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,
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-12 16:36:29 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    };
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    process_command(&config).unwrap();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-02 12:28:43 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let lockup = LockupArgs {
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-15 17:35:43 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        unix_timestamp: Some(1_581_534_572),
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-02 12:28:43 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        epoch: Some(202),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        custodian: None,
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-12 16:36:29 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    };
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    config.signers = vec![&default_signer, &online_custodian];
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-12 16:36:29 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    config.command = CliCommand::StakeSetLockup {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        stake_account_pubkey,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        lockup,
							 | 
						
					
						
							
								
									
										
										
										
											2021-07-15 16:45:03 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        new_custodian_signer: None,
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        custodian: 1,
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-12 16:36:29 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        sign_only: false,
							 | 
						
					
						
							
								
									
										
										
										
											2021-03-12 19:37:39 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        dump_transaction_message: false,
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-12 16:36:29 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        blockhash_query: BlockhashQuery::default(),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        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,
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-12 16:36:29 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    };
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    process_command(&config).unwrap();
							 | 
						
					
						
							
								
									
										
										
										
											2021-01-19 15:33:03 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let stake_account = rpc_client.get_account(&stake_account_pubkey).unwrap();
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-12 16:36:29 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let stake_state: StakeState = stake_account.state().unwrap();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let current_lockup = match stake_state {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        StakeState::Initialized(meta) => meta.lockup,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        _ => panic!("Unexpected stake state!"),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    };
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-02 12:28:43 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    assert_eq!(
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        current_lockup.unix_timestamp,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        lockup.unix_timestamp.unwrap()
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    );
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    assert_eq!(current_lockup.epoch, lockup.epoch.unwrap());
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    assert_eq!(current_lockup.custodian, online_custodian_pubkey);
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-12 16:36:29 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    // Set custodian to offline pubkey
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-02 12:28:43 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let lockup = LockupArgs {
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-15 17:35:43 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        unix_timestamp: Some(1_581_534_573),
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-02 12:28:43 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        epoch: Some(203),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        custodian: Some(offline_pubkey),
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-12 16:36:29 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    };
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    config.command = CliCommand::StakeSetLockup {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        stake_account_pubkey,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        lockup,
							 | 
						
					
						
							
								
									
										
										
										
											2021-07-15 16:45:03 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        new_custodian_signer: None,
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        custodian: 1,
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-12 16:36:29 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        sign_only: false,
							 | 
						
					
						
							
								
									
										
										
										
											2021-03-12 19:37:39 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        dump_transaction_message: false,
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-12 16:36:29 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        blockhash_query: BlockhashQuery::default(),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        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,
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-12 16:36:29 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    };
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    process_command(&config).unwrap();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    // Create nonce account
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let minimum_nonce_balance = rpc_client
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-10 13:00:15 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        .get_minimum_balance_for_rent_exemption(NonceState::size())
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-12 16:36:29 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        .unwrap();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let nonce_account = keypair_from_seed(&[1u8; 32]).unwrap();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let nonce_account_pubkey = nonce_account.pubkey();
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    config.signers = vec![&default_signer, &nonce_account];
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-12 16:36:29 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    config.command = CliCommand::CreateNonceAccount {
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        nonce_account: 1,
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-12 16:36:29 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        seed: None,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        nonce_authority: Some(offline_pubkey),
							 | 
						
					
						
							
								
									
										
										
										
											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-12 16:36:29 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    };
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    process_command(&config).unwrap();
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-17 12:18:48 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    check_recent_balance(minimum_nonce_balance, &rpc_client, &nonce_account_pubkey);
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-12 16:36:29 -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-12 16:36:29 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    // Nonced offline set lockup
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-02 12:28:43 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let lockup = LockupArgs {
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-15 17:35:43 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        unix_timestamp: Some(1_581_534_576),
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-02 12:28:43 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        epoch: Some(222),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        custodian: None,
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-12 16:36:29 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    };
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    config_offline.command = CliCommand::StakeSetLockup {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        stake_account_pubkey,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        lockup,
							 | 
						
					
						
							
								
									
										
										
										
											2021-07-15 16:45:03 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        new_custodian_signer: None,
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        custodian: 0,
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-12 16:36:29 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        sign_only: true,
							 | 
						
					
						
							
								
									
										
										
										
											2021-03-12 19:37:39 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        dump_transaction_message: false,
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-11 12:14:15 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        blockhash_query: BlockhashQuery::None(nonce_hash),
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-12 16:36:29 -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,
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-12 16:36:29 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    };
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-07 07:21:48 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    config_offline.output_format = OutputFormat::JsonCompact;
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-12 16:36:29 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let sig_response = process_command(&config_offline).unwrap();
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-18 21:49:38 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let sign_only = parse_sign_only_reply_string(&sig_response);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    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-12 16:36:29 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    config.command = CliCommand::StakeSetLockup {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        stake_account_pubkey,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        lockup,
							 | 
						
					
						
							
								
									
										
										
										
											2021-07-15 16:45:03 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        new_custodian_signer: None,
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        custodian: 0,
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-12 16:36:29 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        sign_only: false,
							 | 
						
					
						
							
								
									
										
										
										
											2021-03-12 19:37:39 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        dump_transaction_message: 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-12 16:36:29 -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,
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-12 16:36:29 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    };
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    process_command(&config).unwrap();
							 | 
						
					
						
							
								
									
										
										
										
											2021-01-19 15:33:03 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let stake_account = rpc_client.get_account(&stake_account_pubkey).unwrap();
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-12 16:36:29 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let stake_state: StakeState = stake_account.state().unwrap();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let current_lockup = match stake_state {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        StakeState::Initialized(meta) => meta.lockup,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        _ => panic!("Unexpected stake state!"),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    };
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-02 12:28:43 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    assert_eq!(
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        current_lockup.unix_timestamp,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        lockup.unix_timestamp.unwrap()
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    );
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    assert_eq!(current_lockup.epoch, lockup.epoch.unwrap());
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    assert_eq!(current_lockup.custodian, offline_pubkey);
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-12 16:36:29 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-12 23:00:28 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								#[test]
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								fn test_offline_nonced_create_stake_account_and_withdraw() {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    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_no_fees(mint_pubkey, Some(faucet_addr), SocketAddrSpace::Unspecified);
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-12 23:00:28 -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-06-17 12:18:48 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let mut config = CliConfig::recent_for_tests();
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let default_signer = keypair_from_seed(&[1u8; 32]).unwrap();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    config.signers = vec![&default_signer];
							 | 
						
					
						
							
								
									
										
										
										
											2020-11-25 17:00:47 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    config.json_rpc_url = test_validator.rpc_url();
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-12 23:00:28 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-17 12:18:48 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let mut config_offline = CliConfig::recent_for_tests();
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let offline_signer = keypair_from_seed(&[2u8; 32]).unwrap();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    config_offline.signers = vec![&offline_signer];
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let offline_pubkey = config_offline.signers[0].pubkey();
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-12 23:00:28 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    config_offline.json_rpc_url = String::default();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    config_offline.command = CliCommand::ClusterVersion;
							 | 
						
					
						
							
								
									
										
										
										
											2021-02-13 15:07:04 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    // Verify that we cannot reach the cluster
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-12 23:00:28 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    process_command(&config_offline).unwrap_err();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2021-04-15 00:25:23 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    request_and_confirm_airdrop(&rpc_client, &config, &config.signers[0].pubkey(), 200_000)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        .unwrap();
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-17 12:18:48 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    check_recent_balance(200_000, &rpc_client, &config.signers[0].pubkey());
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2021-04-15 00:25:23 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    request_and_confirm_airdrop(&rpc_client, &config_offline, &offline_pubkey, 100_000).unwrap();
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-17 12:18:48 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    check_recent_balance(100_000, &rpc_client, &offline_pubkey);
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-12 23:00:28 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    // Create nonce account
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let minimum_nonce_balance = rpc_client
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-10 13:00:15 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        .get_minimum_balance_for_rent_exemption(NonceState::size())
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-12 23:00:28 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        .unwrap();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let nonce_account = keypair_from_seed(&[3u8; 32]).unwrap();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let nonce_pubkey = nonce_account.pubkey();
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    config.signers.push(&nonce_account);
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-12 23:00:28 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    config.command = CliCommand::CreateNonceAccount {
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        nonce_account: 1,
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-12 23:00:28 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        seed: None,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        nonce_authority: Some(offline_pubkey),
							 | 
						
					
						
							
								
									
										
										
										
											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-12 23:00:28 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    };
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    process_command(&config).unwrap();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    // 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-12 23:00:28 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    // Create stake account offline
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let stake_keypair = keypair_from_seed(&[4u8; 32]).unwrap();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let stake_pubkey = stake_keypair.pubkey();
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    config_offline.signers.push(&stake_keypair);
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-12 23:00:28 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    config_offline.command = CliCommand::CreateStakeAccount {
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        stake_account: 1,
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-12 23:00:28 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        seed: None,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        staker: None,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        withdrawer: None,
							 | 
						
					
						
							
								
									
										
										
										
											2021-07-15 16:45:03 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        withdrawer_signer: None,
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-12 23:00:28 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        lockup: Lockup::default(),
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-14 12:24:14 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        amount: SpendAmount::Some(50_000),
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-12 23:00:28 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        sign_only: true,
							 | 
						
					
						
							
								
									
										
										
										
											2021-03-12 19:37:39 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        dump_transaction_message: false,
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-11 12:14:15 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        blockhash_query: BlockhashQuery::None(nonce_hash),
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-12 23:00:28 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        nonce_account: Some(nonce_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,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        from: 0,
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-12 23:00:28 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    };
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-07 07:21:48 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    config_offline.output_format = OutputFormat::JsonCompact;
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-12 23:00:28 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let sig_response = process_command(&config_offline).unwrap();
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-18 21:49:38 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let sign_only = parse_sign_only_reply_string(&sig_response);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    assert!(sign_only.has_all_signers());
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let offline_presigner = sign_only.presigner_of(&offline_pubkey).unwrap();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let stake_presigner = sign_only.presigner_of(&stake_pubkey).unwrap();
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    config.signers = vec![&offline_presigner, &stake_presigner];
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-12 23:00:28 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    config.command = CliCommand::CreateStakeAccount {
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        stake_account: 1,
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-12 23:00:28 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        seed: None,
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-21 14:55:53 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        staker: Some(offline_pubkey),
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-12 23:00:28 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        withdrawer: None,
							 | 
						
					
						
							
								
									
										
										
										
											2021-07-15 16:45:03 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        withdrawer_signer: None,
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-12 23:00:28 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        lockup: Lockup::default(),
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-14 12:24:14 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        amount: SpendAmount::Some(50_000),
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-12 23:00:28 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        sign_only: false,
							 | 
						
					
						
							
								
									
										
										
										
											2021-03-12 19:37:39 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        dump_transaction_message: false,
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-11 12:14:15 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        blockhash_query: BlockhashQuery::FeeCalculator(
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            blockhash_query::Source::NonceAccount(nonce_pubkey),
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-18 21:49:38 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            sign_only.blockhash,
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-11 12:14:15 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        ),
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-12 23:00:28 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        nonce_account: Some(nonce_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,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        from: 0,
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-12 23:00:28 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    };
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    process_command(&config).unwrap();
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-17 12:18:48 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    check_recent_balance(50_000, &rpc_client, &stake_pubkey);
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-12 23:00:28 -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-12 23:00:28 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    // Offline, nonced stake-withdraw
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let recipient = keypair_from_seed(&[5u8; 32]).unwrap();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let recipient_pubkey = recipient.pubkey();
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    config_offline.signers.pop();
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-12 23:00:28 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    config_offline.command = CliCommand::WithdrawStake {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        stake_account_pubkey: stake_pubkey,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        destination_account_pubkey: recipient_pubkey,
							 | 
						
					
						
							
								
									
										
										
										
											2021-04-26 08:33:56 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        amount: SpendAmount::Some(42),
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        withdraw_authority: 0,
							 | 
						
					
						
							
								
									
										
										
										
											2020-04-22 16:00:18 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        custodian: None,
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-12 23:00:28 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        sign_only: true,
							 | 
						
					
						
							
								
									
										
										
										
											2021-03-12 19:37:39 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        dump_transaction_message: false,
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-11 12:14:15 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        blockhash_query: BlockhashQuery::None(nonce_hash),
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-12 23:00:28 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        nonce_account: Some(nonce_pubkey),
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        nonce_authority: 0,
							 | 
						
					
						
							
								
									
										
										
										
											2021-04-05 13:53:50 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        memo: None,
							 | 
						
					
						
							
								
									
										
										
										
											2021-04-21 11:05:05 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        seed: None,
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        fee_payer: 0,
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-12 23:00:28 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    };
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let sig_response = process_command(&config_offline).unwrap();
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-18 21:49:38 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let sign_only = parse_sign_only_reply_string(&sig_response);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    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-12 23:00:28 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    config.command = CliCommand::WithdrawStake {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        stake_account_pubkey: stake_pubkey,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        destination_account_pubkey: recipient_pubkey,
							 | 
						
					
						
							
								
									
										
										
										
											2021-04-26 08:33:56 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        amount: SpendAmount::Some(42),
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        withdraw_authority: 0,
							 | 
						
					
						
							
								
									
										
										
										
											2020-04-22 16:00:18 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        custodian: None,
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-12 23:00:28 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        sign_only: false,
							 | 
						
					
						
							
								
									
										
										
										
											2021-03-12 19:37:39 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        dump_transaction_message: false,
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-11 12:14:15 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        blockhash_query: BlockhashQuery::FeeCalculator(
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            blockhash_query::Source::NonceAccount(nonce_pubkey),
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-18 21:49:38 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            sign_only.blockhash,
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-11 12:14:15 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        ),
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-12 23:00:28 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        nonce_account: Some(nonce_pubkey),
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        nonce_authority: 0,
							 | 
						
					
						
							
								
									
										
										
										
											2021-04-05 13:53:50 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        memo: None,
							 | 
						
					
						
							
								
									
										
										
										
											2021-04-21 11:05:05 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        seed: None,
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        fee_payer: 0,
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-12 23:00:28 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    };
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    process_command(&config).unwrap();
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-17 12:18:48 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    check_recent_balance(42, &rpc_client, &recipient_pubkey);
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-12 23:00:28 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-22 09:54:29 -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-22 09:54:29 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    // Create another stake account. This time with seed
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let seed = "seedy";
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    config_offline.signers = vec![&offline_signer, &stake_keypair];
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-12 23:00:28 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    config_offline.command = CliCommand::CreateStakeAccount {
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        stake_account: 1,
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-22 09:54:29 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        seed: Some(seed.to_string()),
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-12 23:00:28 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        staker: None,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        withdrawer: None,
							 | 
						
					
						
							
								
									
										
										
										
											2021-07-15 16:45:03 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        withdrawer_signer: None,
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-12 23:00:28 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        lockup: Lockup::default(),
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-14 12:24:14 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        amount: SpendAmount::Some(50_000),
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-12 23:00:28 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        sign_only: true,
							 | 
						
					
						
							
								
									
										
										
										
											2021-03-12 19:37:39 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        dump_transaction_message: false,
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-11 12:14:15 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        blockhash_query: BlockhashQuery::None(nonce_hash),
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-12 23:00:28 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        nonce_account: Some(nonce_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,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        from: 0,
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-12 23:00:28 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    };
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-22 09:54:29 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let sig_response = process_command(&config_offline).unwrap();
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-18 21:49:38 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let sign_only = parse_sign_only_reply_string(&sig_response);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let offline_presigner = sign_only.presigner_of(&offline_pubkey).unwrap();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let stake_presigner = sign_only.presigner_of(&stake_pubkey).unwrap();
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    config.signers = vec![&offline_presigner, &stake_presigner];
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-22 09:54:29 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    config.command = CliCommand::CreateStakeAccount {
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        stake_account: 1,
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-22 09:54:29 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        seed: Some(seed.to_string()),
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-15 17:35:43 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        staker: Some(offline_pubkey),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        withdrawer: Some(offline_pubkey),
							 | 
						
					
						
							
								
									
										
										
										
											2021-07-15 16:45:03 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        withdrawer_signer: None,
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-22 09:54:29 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        lockup: Lockup::default(),
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-14 12:24:14 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        amount: SpendAmount::Some(50_000),
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-22 09:54:29 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        sign_only: false,
							 | 
						
					
						
							
								
									
										
										
										
											2021-03-12 19:37:39 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        dump_transaction_message: false,
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-11 12:14:15 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        blockhash_query: BlockhashQuery::FeeCalculator(
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            blockhash_query::Source::NonceAccount(nonce_pubkey),
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-18 21:49:38 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            sign_only.blockhash,
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-11 12:14:15 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        ),
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-22 09:54:29 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        nonce_account: Some(nonce_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,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        from: 0,
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-22 09:54:29 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    };
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    process_command(&config).unwrap();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let seed_address =
							 | 
						
					
						
							
								
									
										
										
										
											2021-06-15 18:04:00 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        Pubkey::create_with_seed(&stake_pubkey, seed, &stake::program::id()).unwrap();
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-17 12:18:48 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    check_recent_balance(50_000, &rpc_client, &seed_address);
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-12 23:00:28 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							
								
									
										
										
										
											2021-07-15 16:45:03 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								#[test]
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								fn test_stake_checked_instructions() {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    solana_logger::setup();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let mint_keypair = Keypair::new();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    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-07-15 16:45:03 -06: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];
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    request_and_confirm_airdrop(&rpc_client, &config, &config.signers[0].pubkey(), 100_000)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        .unwrap();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    // Create stake account with withdrawer
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let stake_keypair = Keypair::new();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let stake_account_pubkey = stake_keypair.pubkey();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let withdrawer_keypair = Keypair::new();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let withdrawer_pubkey = withdrawer_keypair.pubkey();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    config.signers.push(&stake_keypair);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    config.command = CliCommand::CreateStakeAccount {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        stake_account: 1,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        seed: None,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        staker: None,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        withdrawer: Some(withdrawer_pubkey),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        withdrawer_signer: Some(1),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        lockup: Lockup::default(),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        amount: SpendAmount::Some(50_000),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        sign_only: false,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        dump_transaction_message: false,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        blockhash_query: BlockhashQuery::All(blockhash_query::Source::Cluster),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        nonce_account: None,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        nonce_authority: 0,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        memo: None,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        fee_payer: 0,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        from: 0,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    };
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    process_command(&config).unwrap_err(); // unsigned authority should fail
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    config.signers = vec![&default_signer, &stake_keypair, &withdrawer_keypair];
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    config.command = CliCommand::CreateStakeAccount {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        stake_account: 1,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        seed: None,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        staker: None,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        withdrawer: Some(withdrawer_pubkey),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        withdrawer_signer: Some(1),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        lockup: Lockup::default(),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        amount: SpendAmount::Some(50_000),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        sign_only: false,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        dump_transaction_message: false,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        blockhash_query: BlockhashQuery::All(blockhash_query::Source::Cluster),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        nonce_account: None,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        nonce_authority: 0,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        memo: None,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        fee_payer: 0,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        from: 0,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    };
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    process_command(&config).unwrap();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    // Re-authorize account, checking new authority
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let staker_keypair = Keypair::new();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let staker_pubkey = staker_keypair.pubkey();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    config.signers = vec![&default_signer];
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    config.command = CliCommand::StakeAuthorize {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        stake_account_pubkey,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        new_authorizations: vec![StakeAuthorizationIndexed {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            authorization_type: StakeAuthorize::Staker,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            new_authority_pubkey: staker_pubkey,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            authority: 0,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            new_authority_signer: Some(0),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        }],
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        sign_only: false,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        dump_transaction_message: false,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        blockhash_query: BlockhashQuery::default(),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        nonce_account: None,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        nonce_authority: 0,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        memo: None,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        fee_payer: 0,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        custodian: None,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        no_wait: false,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    };
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    process_command(&config).unwrap_err(); // unsigned authority should fail
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    config.signers = vec![&default_signer, &staker_keypair];
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    config.command = CliCommand::StakeAuthorize {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        stake_account_pubkey,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        new_authorizations: vec![StakeAuthorizationIndexed {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            authorization_type: StakeAuthorize::Staker,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            new_authority_pubkey: staker_pubkey,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            authority: 0,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            new_authority_signer: Some(1),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        }],
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        sign_only: false,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        dump_transaction_message: false,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        blockhash_query: BlockhashQuery::default(),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        nonce_account: None,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        nonce_authority: 0,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        memo: None,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        fee_payer: 0,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        custodian: None,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        no_wait: false,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    };
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    process_command(&config).unwrap();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let stake_account = rpc_client.get_account(&stake_account_pubkey).unwrap();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let stake_state: StakeState = stake_account.state().unwrap();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let current_authority = match stake_state {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        StakeState::Initialized(meta) => meta.authorized.staker,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        _ => panic!("Unexpected stake state!"),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    };
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    assert_eq!(current_authority, staker_pubkey);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let new_withdrawer_keypair = Keypair::new();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let new_withdrawer_pubkey = new_withdrawer_keypair.pubkey();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    config.signers = vec![&default_signer, &withdrawer_keypair];
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    config.command = CliCommand::StakeAuthorize {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        stake_account_pubkey,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        new_authorizations: vec![StakeAuthorizationIndexed {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            authorization_type: StakeAuthorize::Withdrawer,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            new_authority_pubkey: new_withdrawer_pubkey,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            authority: 1,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            new_authority_signer: Some(1),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        }],
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        sign_only: false,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        dump_transaction_message: false,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        blockhash_query: BlockhashQuery::default(),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        nonce_account: None,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        nonce_authority: 0,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        memo: None,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        fee_payer: 0,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        custodian: None,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        no_wait: false,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    };
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    process_command(&config).unwrap_err(); // unsigned authority should fail
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    config.signers = vec![
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        &default_signer,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        &withdrawer_keypair,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        &new_withdrawer_keypair,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    ];
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    config.command = CliCommand::StakeAuthorize {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        stake_account_pubkey,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        new_authorizations: vec![StakeAuthorizationIndexed {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            authorization_type: StakeAuthorize::Withdrawer,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            new_authority_pubkey: new_withdrawer_pubkey,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            authority: 1,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            new_authority_signer: Some(2),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        }],
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        sign_only: false,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        dump_transaction_message: false,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        blockhash_query: BlockhashQuery::default(),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        nonce_account: None,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        nonce_authority: 0,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        memo: None,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        fee_payer: 0,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        custodian: None,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        no_wait: false,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    };
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    process_command(&config).unwrap();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let stake_account = rpc_client.get_account(&stake_account_pubkey).unwrap();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let stake_state: StakeState = stake_account.state().unwrap();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let current_authority = match stake_state {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        StakeState::Initialized(meta) => meta.authorized.withdrawer,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        _ => panic!("Unexpected stake state!"),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    };
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    assert_eq!(current_authority, new_withdrawer_pubkey);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    // Set lockup, checking new custodian
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let custodian = Keypair::new();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let custodian_pubkey = custodian.pubkey();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let lockup = LockupArgs {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        unix_timestamp: Some(1_581_534_570),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        epoch: Some(200),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        custodian: Some(custodian_pubkey),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    };
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    config.signers = vec![&default_signer, &new_withdrawer_keypair];
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    config.command = CliCommand::StakeSetLockup {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        stake_account_pubkey,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        lockup,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        new_custodian_signer: Some(1),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        custodian: 1,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        sign_only: false,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        dump_transaction_message: false,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        blockhash_query: BlockhashQuery::default(),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        nonce_account: None,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        nonce_authority: 0,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        memo: None,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        fee_payer: 0,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    };
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    process_command(&config).unwrap_err(); // unsigned new custodian should fail
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    config.signers = vec![&default_signer, &new_withdrawer_keypair, &custodian];
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    config.command = CliCommand::StakeSetLockup {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        stake_account_pubkey,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        lockup,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        new_custodian_signer: Some(2),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        custodian: 1,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        sign_only: false,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        dump_transaction_message: false,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        blockhash_query: BlockhashQuery::default(),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        nonce_account: None,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        nonce_authority: 0,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        memo: None,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        fee_payer: 0,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    };
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    process_command(&config).unwrap();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let stake_account = rpc_client.get_account(&stake_account_pubkey).unwrap();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let stake_state: StakeState = stake_account.state().unwrap();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let current_lockup = match stake_state {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        StakeState::Initialized(meta) => meta.lockup,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        _ => panic!("Unexpected stake state!"),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    };
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    assert_eq!(
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        current_lockup.unix_timestamp,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        lockup.unix_timestamp.unwrap()
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    );
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    assert_eq!(current_lockup.epoch, lockup.epoch.unwrap());
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    assert_eq!(current_lockup.custodian, custodian_pubkey);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 |