From 76a7038335e9a9d515b205bf95490d4f0aea4cc2 Mon Sep 17 00:00:00 2001 From: Carl Date: Tue, 5 Mar 2019 13:23:12 -0800 Subject: [PATCH] Update test harness to set a delegate on validator vote accounts --- core/src/local_cluster.rs | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/core/src/local_cluster.rs b/core/src/local_cluster.rs index f2edf8b050..77033919f5 100644 --- a/core/src/local_cluster.rs +++ b/core/src/local_cluster.rs @@ -85,7 +85,7 @@ impl LocalCluster { Self::create_and_fund_vote_account( &mut client, - voting_keypair.pubkey(), + &voting_keypair, &validator_keypair, 1, ) @@ -148,15 +148,18 @@ impl LocalCluster { fn create_and_fund_vote_account( client: &mut ThinClient, - vote_account: Pubkey, + vote_account: &Keypair, from_account: &Arc, amount: u64, ) -> Result<()> { + let vote_account_pubkey = vote_account.pubkey(); + let delegate_id = from_account.pubkey(); // Create the vote account if necessary - if client.poll_get_balance(&vote_account).unwrap_or(0) == 0 { + if client.poll_get_balance(&vote_account_pubkey).unwrap_or(0) == 0 { + // 1) Create vote account let mut transaction = VoteTransaction::new_account( from_account, - vote_account, + vote_account_pubkey, client.get_recent_blockhash(), amount, 1, @@ -165,14 +168,26 @@ impl LocalCluster { client .retry_transfer(&from_account, &mut transaction, 5) .expect("client transfer"); - retry_get_balance(client, &vote_account, Some(amount)).expect("get balance"); + retry_get_balance(client, &vote_account_pubkey, Some(amount)).expect("get balance"); + + // 2) Set delegate for new vote account + let mut transaction = VoteTransaction::delegate_vote_account( + vote_account, + client.get_recent_blockhash(), + delegate_id, + 1, + ); + + client + .retry_transfer(&from_account, &mut transaction, 5) + .expect("client transfer"); } info!("Checking for vote account registration"); - let vote_account_user_data = client.get_account_userdata(&vote_account); + let vote_account_user_data = client.get_account_userdata(&vote_account_pubkey); if let Ok(Some(vote_account_user_data)) = vote_account_user_data { if let Ok(vote_state) = VoteState::deserialize(&vote_account_user_data) { - if vote_state.delegate_id == vote_account { + if vote_state.delegate_id == delegate_id { return Ok(()); } }