Skip to content

Commit

Permalink
fix: make is-vote-active dependent on voteStart and voteEnd
Browse files Browse the repository at this point in the history
The logic can be simplified here since we have a set end block height for the vote, tests are updated as well.
  • Loading branch information
whoabuddy committed Aug 9, 2024
1 parent ab2ea87 commit ac0d730
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
11 changes: 5 additions & 6 deletions contracts/proposals/ccip024-miamicoin-signal-vote.clar
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
;; DATA VARS

;; vote block heights
(define-data-var voteActive bool true)
;; MAINNET: start the vote when deployed
;; (define-data-var voteStart uint block-height)
(define-data-var voteStart uint (+ block-height u12600))
Expand Down Expand Up @@ -74,9 +73,7 @@
(voterRecord (map-get? UserVotes voterId))
)
;; check if vote is active
(asserts! (var-get voteActive) ERR_PROPOSAL_NOT_ACTIVE)
;; check if voting period has ended
(asserts! (<= block-height (var-get voteEnd)) ERR_PROPOSAL_NOT_ACTIVE)
(asserts! (is-vote-active) ERR_PROPOSAL_NOT_ACTIVE)
;; check if vote record exists for user
(match voterRecord record
;; if the voterRecord exists
Expand Down Expand Up @@ -133,8 +130,10 @@
)

(define-read-only (is-vote-active)
(some (var-get voteActive))
)
(if (and (> block-height (var-get voteStart)) (<= block-height (var-get voteEnd)))
true
false
))

(define-read-only (get-proposal-info)
(some CCIP_024)
Expand Down
11 changes: 8 additions & 3 deletions tests/proposals/ccip024-miamicoin-signal-vote.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,17 @@ Clarinet.test({
const user2 = accounts.get("wallet_2")!;
const ccd007CityStacking = new CCD007CityStacking(chain, sender, "ccd007-citycoin-stacking");
const ccip024 = new CCIP024MiamiCoinSignalVote(chain, sender);
const voteLength = 2016;

// Setup
chain.mineEmptyBlockUntil(CCD007CityStacking.FIRST_STACKING_BLOCK);
constructAndPassProposal(chain, accounts, PROPOSALS.TEST_CCIP024_MIAMICOIN_SIGNAL_VOTE_001);
chain.mineBlock([ccd007CityStacking.stack(user1, mia.cityName, 500, 10), ccd007CityStacking.stack(user2, mia.cityName, 300, 10)]);
ccip024.isVoteActive().result.expectBool(false);
chain.mineEmptyBlockUntil(CCD007CityStacking.REWARD_CYCLE_LENGTH * 6 + 10);

// Vote
chain.mineBlock([ccip024.voteOnProposal(user1, true), ccip024.voteOnProposal(user2, false)]);
const voteBlock = chain.mineBlock([ccip024.voteOnProposal(user1, true), ccip024.voteOnProposal(user2, false)]);

// Assert
ccip024
Expand Down Expand Up @@ -122,10 +124,13 @@ Clarinet.test({
mia: types.uint(500),
});

ccip024.isVoteActive().result.expectSome().expectBool(true);
ccip024.isVoteActive().result.expectBool(true);

const voteInfo = ccip024.getVotePeriod().result.expectSome().expectTuple();
voteInfo.length.expectUint(2016);
voteInfo.length.expectUint(voteLength);

chain.mineEmptyBlockUntil(voteBlock.height + voteLength);
ccip024.isVoteActive().result.expectBool(false);
},
});

Expand Down

0 comments on commit ac0d730

Please sign in to comment.