Skip to content

Commit

Permalink
fix: add model and tests for ccip-025
Browse files Browse the repository at this point in the history
  • Loading branch information
whoabuddy committed Oct 29, 2024
1 parent ef47991 commit 14d7669
Show file tree
Hide file tree
Showing 7 changed files with 183 additions and 125 deletions.
10 changes: 10 additions & 0 deletions Clarinet-legacy.toml
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,11 @@ path = "contracts/proposals/ccip024-miamicoin-signal-vote.clar"
clarity_version = 2
epoch = 2.4

[contracts.ccip025-extend-sunset-period-3]
path = "contracts/proposals/ccip025-extend-sunset-period-3.clar"
clarity_version = 2
epoch = 2.4

# CITYCOINS PROTOCOL TRAITS

[contracts.extension-trait]
Expand Down Expand Up @@ -565,6 +570,11 @@ path = "tests/contracts/proposals/test-ccip024-miamicoin-signal-vote-001.clar"
clarity_version = 2
epoch = 2.4

[contracts.test-ccip025-extend-sunset-period-3-001]
path = "tests/contracts/proposals/test-ccip025-extend-sunset-period-3-001.clar"
clarity_version = 2
epoch = 2.4

[repl]
costs_version = 2
parser_version = 2
Expand Down
5 changes: 5 additions & 0 deletions Clarinet.toml
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,11 @@ path = "tests/contracts/proposals/test-ccip024-miamicoin-signal-vote-001.clar"
clarity_version = 2
epoch = 2.4

[contracts.test-ccip025-extend-sunset-period-3-001]
path = "tests/contracts/proposals/test-ccip025-extend-sunset-period-3-001.clar"
clarity_version = 2
epoch = 2.5

[repl]
costs_version = 2
parser_version = 2
Expand Down
20 changes: 10 additions & 10 deletions contracts/proposals/ccip025-extend-sunset-period-3.clar
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,6 @@

(var-set voteStart block-height)

;; vote tracking
(define-data-var yesVotes uint u0)
(define-data-var yesTotal uint u0)
(define-data-var noVotes uint u0)
(define-data-var noTotal uint u0)

;; DATA MAPS

(define-map CityVotes
Expand Down Expand Up @@ -139,11 +133,17 @@
;; READ ONLY FUNCTIONS

(define-read-only (is-executable)
(begin
(let
(
(votingRecord (unwrap! (get-vote-totals) ERR_PANIC))
(miaRecord (get mia votingRecord))
(voteTotals (get totals votingRecord))
)
;; check that there is at least one vote
(asserts! (or (> (var-get yesVotes) u0) (> (var-get noVotes) u0)) ERR_VOTE_FAILED)
;; check that yes total is more than no total
(asserts! (> (var-get yesTotal) (var-get noTotal)) ERR_VOTE_FAILED)
(asserts! (or (> (get totalVotesYes voteTotals) u0) (> (get totalVotesNo voteTotals) u0)) ERR_VOTE_FAILED)
;; check that the yes total is more than no total
(asserts! (> (get totalVotesYes voteTotals) (get totalVotesNo voteTotals)) ERR_VOTE_FAILED)
;; allow execution
(ok true)
)
)
Expand Down
80 changes: 0 additions & 80 deletions models/proposals/ccip025-extend-sunset-period-3.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,83 +78,3 @@ export class CCIP025ExtendDirectExecuteSunsetPeriod {
return result;
}
}
import { Chain, Account, Tx, types, ReadOnlyFn } from "../../utils/deps.ts";
import { PROPOSALS } from "../../utils/common.ts";

enum ErrCode {
ERR_PANIC = 25000,
ERR_VOTED_ALREADY,
ERR_NOTHING_STACKED,
ERR_USER_NOT_FOUND,
ERR_PROPOSAL_NOT_ACTIVE,
ERR_PROPOSAL_STILL_ACTIVE,
ERR_NO_CITY_ID,
ERR_VOTE_FAILED,
ERR_SAVING_VOTE,
}

export class CCIP025ExtendDirectExecuteSunsetPeriod {
name = PROPOSALS.CCIP_025;
static readonly ErrCode = ErrCode;
chain: Chain;
deployer: Account;

constructor(chain: Chain, deployer: Account) {
this.chain = chain;
this.deployer = deployer;
}

// public functions

execute(sender: Account) {
return Tx.contractCall(this.name, "execute", [types.principal(sender.address)], sender.address);
}

voteOnProposal(sender: Account, vote: boolean) {
return Tx.contractCall(this.name, "vote-on-proposal", [types.bool(vote)], sender.address);
}

// read-only functions

isExecutable() {
return this.callReadOnlyFn("is-executable");
}

isVoteActive() {
return this.callReadOnlyFn("is-vote-active");
}

getProposalInfo() {
return this.callReadOnlyFn("get-proposal-info");
}

getVotePeriod() {
return this.callReadOnlyFn("get-vote-period");
}

getVoteTotalMia() {
return this.callReadOnlyFn("get-vote-total-mia");
}

getVoteTotalMiaOrDefault() {
return this.callReadOnlyFn("get-vote-total-mia-or-default");
}

getVoteTotals() {
return this.callReadOnlyFn("get-vote-totals");
}

getVoterInfo(userId: number) {
return this.callReadOnlyFn("get-voter-info", [types.uint(userId)]);
}

getMiaVote(userId: number, scaled: boolean) {
return this.callReadOnlyFn("get-mia-vote", [types.uint(userId), types.bool(scaled)]);
}

// read-only function helper
private callReadOnlyFn(method: string, args: Array<any> = [], sender: Account = this.deployer): ReadOnlyFn {
const result = this.chain.callReadOnlyFn(this.name, method, args, sender?.address);
return result;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
;; Title: Test Proposal for CCIP-025
;; Version: 1.0.0
;; Synopsis: Test proposal for CCIP-025
;; Description:
;; Sets up everything required for CCIP-025

(impl-trait .proposal-trait.proposal-trait)

(define-public (execute (sender principal))
(begin
;; Set up MIA in city registry
(try! (contract-call? .ccd004-city-registry get-or-create-city-id "mia"))

;; Set activation details for MIA
(try! (contract-call? .ccd005-city-data set-activation-details u1 u1 u1 u5 u1))

;; Set activation status for MIA
(try! (contract-call? .ccd005-city-data set-activation-status u1 true))

;; Add MIA mining treasury
(try! (contract-call? .ccd005-city-data add-treasury u1 .ccd002-treasury-mia-mining-v2 "mining"))

;; Add MIA stacking treasury
(try! (contract-call? .ccd005-city-data add-treasury u1 .ccd002-treasury-mia-stacking "stacking"))

;; Mint MIA tokens to test users
(try! (contract-call? .test-ccext-governance-token-mia mint u1000 'ST1SJ3DTE5DN7X54YDH5D64R3BCB6A2AG2ZQ8YPD5))
(try! (contract-call? .test-ccext-governance-token-mia mint u1000 'ST2CY5V39NHDPWSXMW9QDT3HC3GD6Q6XX4CFRK9AG))
(try! (contract-call? .test-ccext-governance-token-mia mint u1000 'ST2JHG361ZXG51QTKY2NQCVBPPRRE2KZB1HR05NNC))

;; Add MIA token to stacking treasury allow list
(try! (contract-call? .ccd002-treasury-mia-stacking set-allowed .test-ccext-governance-token-mia true))

(ok true)
)
)
Loading

0 comments on commit 14d7669

Please sign in to comment.