Skip to content
This repository was archived by the owner on Mar 11, 2025. It is now read-only.

Commit efa8826

Browse files
committed
fix: Do not allow relinquishing votes in Finalising state
1 parent 2c38c74 commit efa8826

File tree

6 files changed

+16
-27
lines changed

6 files changed

+16
-27
lines changed

Anchor.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
anchor_version = "0.20.1"
1+
anchor_version = "0.24.2"
22
solana_version = "1.9.9"
33

44
[workspace]

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

governance/program/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "spl-governance"
3-
version = "2.2.4"
3+
version = "2.2.5"
44
description = "Solana Program Library Governance Program"
55
authors = ["Solana Maintainers <[email protected]>"]
66
repository = "https://github.com/solana-labs/solana-program-library"

governance/program/src/error.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,10 @@ pub enum GovernanceError {
393393
/// GovernanceConfig change not allowed
394394
#[error("GovernanceConfig change not allowed")]
395395
GovernanceConfigChangeNotAllowed,
396+
397+
/// Cannot Relinquish in Voting state
398+
#[error("Cannot Relinquish in Voting state")]
399+
CannotRelinquishInVotingState,
396400
}
397401

398402
impl PrintProgramError for GovernanceError {

governance/program/src/processor/process_relinquish_vote.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ pub fn process_relinquish_vote(program_id: &Pubkey, accounts: &[AccountInfo]) ->
103103
.checked_sub(1)
104104
.unwrap();
105105
} else {
106+
if proposal_data.state == ProposalState::Voting {
107+
return Err(GovernanceError::CannotRelinquishInVotingState.into());
108+
}
109+
106110
vote_record_data.is_relinquished = true;
107111
vote_record_data.serialize(&mut *vote_record_info.data.borrow_mut())?;
108112
}

governance/program/tests/process_relinquish_vote.rs

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ async fn test_relinquish_vote_with_already_relinquished_error() {
447447
}
448448

449449
#[tokio::test]
450-
async fn test_relinquish_proposal_in_voting_state_after_vote_time_ended() {
450+
async fn test_relinquish_proposal_in_voting_state_after_vote_time_ended_error() {
451451
// Arrange
452452
let mut governance_test = GovernanceProgramTest::start_new().await;
453453

@@ -481,7 +481,7 @@ async fn test_relinquish_proposal_in_voting_state_after_vote_time_ended() {
481481

482482
let clock = governance_test.bench.get_clock().await;
483483

484-
let mut vote_record_cookie = governance_test
484+
governance_test
485485
.with_cast_vote(&proposal_cookie, &token_owner_record_cookie, YesNoVote::Yes)
486486
.await
487487
.unwrap();
@@ -494,32 +494,13 @@ async fn test_relinquish_proposal_in_voting_state_after_vote_time_ended() {
494494
.await;
495495

496496
// Act
497-
governance_test
497+
let err = governance_test
498498
.relinquish_vote(&proposal_cookie, &token_owner_record_cookie)
499499
.await
500+
.err()
500501
.unwrap();
501502

502503
// Assert
503504

504-
let proposal_account = governance_test
505-
.get_proposal_account(&proposal_cookie.address)
506-
.await;
507-
508-
// Proposal should be still in voting state but the vote count should not change
509-
assert_eq!(100, proposal_account.options[0].vote_weight);
510-
assert_eq!(ProposalState::Voting, proposal_account.state);
511-
512-
let token_owner_record = governance_test
513-
.get_token_owner_record_account(&token_owner_record_cookie.address)
514-
.await;
515-
516-
assert_eq!(0, token_owner_record.unrelinquished_votes_count);
517-
assert_eq!(1, token_owner_record.total_votes_count);
518-
519-
let vote_record_account = governance_test
520-
.get_vote_record_account(&vote_record_cookie.address)
521-
.await;
522-
523-
vote_record_cookie.account.is_relinquished = true;
524-
assert_eq!(vote_record_cookie.account, vote_record_account);
505+
assert_eq!(err, GovernanceError::CannotRelinquishInVotingState.into());
525506
}

0 commit comments

Comments
 (0)