Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v1.17: initialize with new VoteState for tests (backport of #33518) #33531

Merged
merged 1 commit into from
Oct 4, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions programs/vote/src/vote_state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1095,16 +1095,14 @@ pub fn do_process_vote_state_update(
// a. In many tests.
// b. In the genesis tool that initializes a cluster to create the bootstrap validator.
// c. In the ledger tool when creating bootstrap vote accounts.
// In all cases, initializing with the 1_14_11 version of VoteState is safest, as this version will in-place upgrade
// the first time it is altered by a vote transaction.
pub fn create_account_with_authorized(
node_pubkey: &Pubkey,
authorized_voter: &Pubkey,
authorized_withdrawer: &Pubkey,
commission: u8,
lamports: u64,
) -> AccountSharedData {
let mut vote_account = AccountSharedData::new(lamports, VoteState1_14_11::size_of(), &id());
let mut vote_account = AccountSharedData::new(lamports, VoteState::size_of(), &id());

let vote_state = VoteState::new(
&VoteInit {
Expand All @@ -1116,8 +1114,11 @@ pub fn create_account_with_authorized(
&Clock::default(),
);

let version1_14_11 = VoteStateVersions::V1_14_11(Box::new(VoteState1_14_11::from(vote_state)));
VoteState::serialize(&version1_14_11, vote_account.data_as_mut_slice()).unwrap();
VoteState::serialize(
&VoteStateVersions::Current(Box::new(vote_state)),
vote_account.data_as_mut_slice(),
)
.unwrap();

vote_account
}
Expand Down