cli: enforce rent-exemption balance for stake, vote and program accounts in cli (#6118)

* require minimum balance for stake, vote and program accounts
This commit is contained in:
Parth
2019-10-01 01:14:49 +05:30
committed by GitHub
parent 4fbe36d9c6
commit 2c8c2029d8
8 changed files with 43 additions and 53 deletions

View File

@@ -26,8 +26,6 @@ pub fn parse_vote_create_account(
let authorized_voter = pubkey_of(matches, "authorized_voter").unwrap_or(vote_account_pubkey);
let authorized_withdrawer = pubkey_of(matches, "authorized_withdrawer").unwrap_or(*pubkey);
let lamports = amount_of(matches, "amount", "unit").expect("Invalid amount");
Ok(WalletCommand::CreateVoteAccount(
vote_account_pubkey,
VoteInit {
@@ -36,7 +34,6 @@ pub fn parse_vote_create_account(
authorized_withdrawer,
commission,
},
lamports,
))
}
@@ -70,7 +67,6 @@ pub fn process_create_vote_account(
config: &WalletConfig,
vote_account_pubkey: &Pubkey,
vote_init: &VoteInit,
lamports: u64,
) -> ProcessResult {
check_unique_pubkeys(
(vote_account_pubkey, "vote_account_pubkey".to_string()),
@@ -80,11 +76,13 @@ pub fn process_create_vote_account(
(&config.keypair.pubkey(), "wallet keypair".to_string()),
(vote_account_pubkey, "vote_account_pubkey".to_string()),
)?;
let required_balance =
rpc_client.get_minimum_balance_for_rent_exemption(VoteState::size_of())?;
let ixs = vote_instruction::create_account(
&config.keypair.pubkey(),
vote_account_pubkey,
vote_init,
lamports,
required_balance,
);
let (recent_blockhash, fee_calculator) = rpc_client.get_recent_blockhash()?;
let mut tx = Transaction::new_signed_instructions(&[&config.keypair], ixs, recent_blockhash);
@@ -303,10 +301,8 @@ mod tests {
"create-vote-account",
&pubkey_string,
&node_pubkey_string,
"50",
"--commission",
"10",
"lamports",
]);
assert_eq!(
parse_command(&pubkey, &test_create_vote_account).unwrap(),
@@ -317,8 +313,7 @@ mod tests {
authorized_voter: pubkey,
authorized_withdrawer: pubkey,
commission: 10
},
50
}
)
);
let test_create_vote_account2 = test_commands.clone().get_matches_from(vec![
@@ -326,7 +321,6 @@ mod tests {
"create-vote-account",
&pubkey_string,
&node_pubkey_string,
"50",
]);
assert_eq!(
parse_command(&pubkey, &test_create_vote_account2).unwrap(),
@@ -337,8 +331,7 @@ mod tests {
authorized_voter: pubkey,
authorized_withdrawer: pubkey,
commission: 0
},
858993459200
}
)
);
// test init with an authed voter
@@ -348,8 +341,6 @@ mod tests {
"create-vote-account",
&pubkey_string,
&node_pubkey_string,
"50",
"SOL",
"--authorized-voter",
&authed.to_string(),
]);
@@ -362,8 +353,7 @@ mod tests {
authorized_voter: authed,
authorized_withdrawer: pubkey,
commission: 0
},
858993459200
}
)
);
// test init with an authed withdrawer
@@ -372,7 +362,6 @@ mod tests {
"create-vote-account",
&pubkey_string,
&node_pubkey_string,
"0.5",
"--authorized-withdrawer",
&authed.to_string(),
]);
@@ -385,8 +374,7 @@ mod tests {
authorized_voter: pubkey,
authorized_withdrawer: authed,
commission: 0
},
8589934592
}
)
);