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

Commit 1ca8054

Browse files
authored
Governance: set voting_completed_at to actual end time (#3179)
1 parent 3afe1e6 commit 1ca8054

File tree

2 files changed

+17
-15
lines changed

2 files changed

+17
-15
lines changed

governance/program/src/state/proposal.rs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -276,18 +276,22 @@ impl ProposalV2 {
276276
Ok(())
277277
}
278278

279+
/// Vote end time determined by the configured max_voting_time period
280+
pub fn vote_end_time(&self, config: &GovernanceConfig) -> UnixTimestamp {
281+
self.voting_at
282+
.unwrap()
283+
.checked_add(config.max_voting_time as i64)
284+
.unwrap()
285+
}
286+
279287
/// Checks whether the voting time has ended for the proposal
280288
pub fn has_vote_time_ended(
281289
&self,
282290
config: &GovernanceConfig,
283291
current_unix_timestamp: UnixTimestamp,
284292
) -> bool {
285-
// Check if we passed vote_end_time determined by the configured max_voting_time period
286-
self.voting_at
287-
.unwrap()
288-
.checked_add(config.max_voting_time as i64)
289-
.unwrap()
290-
< current_unix_timestamp
293+
// Check if we passed vote_end_time
294+
self.vote_end_time(config) < current_unix_timestamp
291295
}
292296

293297
/// Checks if Proposal can be finalized
@@ -319,8 +323,7 @@ impl ProposalV2 {
319323
self.assert_can_finalize_vote(config, current_unix_timestamp)?;
320324

321325
self.state = self.resolve_final_vote_state(max_voter_weight, vote_threshold)?;
322-
// TODO: set voting_completed_at based on the time when the voting ended and not when we finalized the proposal
323-
self.voting_completed_at = Some(current_unix_timestamp);
326+
self.voting_completed_at = Some(self.vote_end_time(config));
324327

325328
// Capture vote params to correctly display historical results
326329
self.max_vote_weight = Some(max_voter_weight);
@@ -1658,7 +1661,10 @@ mod test {
16581661

16591662
// Assert
16601663
assert_eq!(proposal.state,test_case.expected_finalized_state,"CASE: {:?}",test_case);
1661-
assert_eq!(Some(current_timestamp),proposal.voting_completed_at);
1664+
assert_eq!(
1665+
Some(proposal.vote_end_time(&governance_config)),
1666+
proposal.voting_completed_at
1667+
);
16621668

16631669
match proposal.options[0].vote_result {
16641670
OptionVoteResult::Succeeded => {

governance/program/tests/process_finalize_vote.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,6 @@ async fn test_finalize_vote_to_succeeded() {
6767
)
6868
.await;
6969

70-
let clock = governance_test.bench.get_clock().await;
71-
7270
// Act
7371

7472
governance_test
@@ -84,7 +82,7 @@ async fn test_finalize_vote_to_succeeded() {
8482

8583
assert_eq!(proposal_account.state, ProposalState::Succeeded);
8684
assert_eq!(
87-
Some(clock.unix_timestamp),
85+
Some(proposal_account.vote_end_time(&governance_cookie.account.config)),
8886
proposal_account.voting_completed_at
8987
);
9088

@@ -372,8 +370,6 @@ async fn test_finalize_council_vote() {
372370
)
373371
.await;
374372

375-
let clock = governance_test.bench.get_clock().await;
376-
377373
// Act
378374

379375
governance_test
@@ -389,7 +385,7 @@ async fn test_finalize_council_vote() {
389385

390386
assert_eq!(proposal_account.state, ProposalState::Succeeded);
391387
assert_eq!(
392-
Some(clock.unix_timestamp),
388+
Some(proposal_account.vote_end_time(&governance_cookie.account.config)),
393389
proposal_account.voting_completed_at
394390
);
395391

0 commit comments

Comments
 (0)