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

Add contract tests #20

Merged
merged 19 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
bef64ee
fix: add pattern for testing proposals
whoabuddy Jan 14, 2025
6312bed
refactor: everything neat and tidy
whoabuddy Jan 14, 2025
54c4c1d
feat: start work on generic helpers to test proposals
whoabuddy Jan 14, 2025
85cfe9d
debug: add logging because at-block get-balance returns 0
whoabuddy Jan 15, 2025
b97e299
fix: progress chain before at-block
whoabuddy Jan 15, 2025
509f7c5
fix: continue with core proposal testing
whoabuddy Jan 15, 2025
05b460f
feat: start applying core logic to action proposals
whoabuddy Jan 15, 2025
47f4a53
fix: migrate error codes to a seperate file
whoabuddy Jan 15, 2025
43b200e
refactor: Update test files to use centralized error codes from error…
whoabuddy Jan 15, 2025
500274a
refactor: Update proposal test files to use centralized error codes
whoabuddy Jan 15, 2025
8893a2b
refactor: Update test files to use centralized error codes from error…
whoabuddy Jan 15, 2025
6b97b98
refactor: Update treasury test files to use centralized error codes
whoabuddy Jan 15, 2025
da183e2
fix: match error value in base contract
whoabuddy Jan 15, 2025
9e181ef
feat: add utilities and first action proposal test
whoabuddy Jan 15, 2025
2b704e9
fix: bring proposal code in sync, use stx block for at-block
whoabuddy Jan 15, 2025
3591b07
fix: set 144 block delay on core proposals
whoabuddy Jan 15, 2025
8068375
refactor: generalize voter funding with other proposal steps
whoabuddy Jan 15, 2025
4405299
fix: use deployment plan from clarinet check
whoabuddy Jan 15, 2025
e1fac36
feat: add codecov v5 with token
whoabuddy Jan 15, 2025
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
5 changes: 2 additions & 3 deletions .github/workflows/clarinet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ jobs:
- name: "Execute unit tests"
run: npm run test:report
- name: "Upload code coverage"
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v5
with:
files: ./coverage.lcov
verbose: true
token: ${{ secrets.CODECOV_TOKEN }}
12 changes: 7 additions & 5 deletions contracts/dao/extensions/aibtc-action-proposals.clar
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@
createdAt: uint, ;; block height
caller: principal, ;; contract caller
creator: principal, ;; proposal creator (tx-sender)
startBlock: uint, ;; block height
endBlock: uint, ;; block height
startBlockStx: uint, ;; block height for at-block calls
startBlock: uint, ;; burn block height
endBlock: uint, ;; burn block height
votesFor: uint, ;; total votes for
votesAgainst: uint, ;; total votes against
liquidTokens: uint, ;; liquid tokens
Expand Down Expand Up @@ -94,6 +95,7 @@
parameters: parameters,
creator: tx-sender,
liquidTokens: liquidTokens,
startBlockStx: block-height,

Check warning on line 98 in contracts/dao/extensions/aibtc-action-proposals.clar

View check run for this annotation

Codecov / codecov/patch

contracts/dao/extensions/aibtc-action-proposals.clar#L98

Added line #L98 was not covered by tests
startBlock: burn-block-height,
endBlock: (+ burn-block-height VOTING_PERIOD)
}
Expand All @@ -105,6 +107,7 @@
createdAt: burn-block-height,
caller: contract-caller,
creator: tx-sender,
startBlockStx: block-height,

Check warning on line 110 in contracts/dao/extensions/aibtc-action-proposals.clar

View check run for this annotation

Codecov / codecov/patch

contracts/dao/extensions/aibtc-action-proposals.clar#L110

Added line #L110 was not covered by tests
startBlock: burn-block-height,
endBlock: (+ burn-block-height VOTING_PERIOD),
votesFor: u0,
Expand All @@ -122,7 +125,7 @@
(let
(
(proposalRecord (unwrap! (map-get? Proposals proposalId) ERR_PROPOSAL_NOT_FOUND))
(proposalBlock (get startBlock proposalRecord))
(proposalBlock (get startBlockStx proposalRecord))

Check warning on line 128 in contracts/dao/extensions/aibtc-action-proposals.clar

View check run for this annotation

Codecov / codecov/patch

contracts/dao/extensions/aibtc-action-proposals.clar#L128

Added line #L128 was not covered by tests
(proposalBlockHash (unwrap! (get-block-hash proposalBlock) ERR_RETRIEVING_START_BLOCK_HASH))
(senderBalance (unwrap! (at-block proposalBlockHash (contract-call? .aibtc-token get-balance tx-sender)) ERR_FETCHING_TOKEN_DATA))
)
Expand Down Expand Up @@ -201,7 +204,7 @@
(let
(
(proposalRecord (unwrap! (map-get? Proposals proposalId) ERR_PROPOSAL_NOT_FOUND))
(proposalBlockHash (unwrap! (get-block-hash (get startBlock proposalRecord)) ERR_RETRIEVING_START_BLOCK_HASH))
(proposalBlockHash (unwrap! (get-block-hash (get startBlockStx proposalRecord)) ERR_RETRIEVING_START_BLOCK_HASH))

Check warning on line 207 in contracts/dao/extensions/aibtc-action-proposals.clar

View check run for this annotation

Codecov / codecov/patch

contracts/dao/extensions/aibtc-action-proposals.clar#L207

Added line #L207 was not covered by tests
)
(at-block proposalBlockHash (contract-call? .aibtc-token get-balance who))
)
Expand Down Expand Up @@ -244,7 +247,6 @@
))
)

;; get block hash by height
(define-private (get-block-hash (blockHeight uint))
(get-block-info? id-header-hash blockHeight)
)
Expand Down
21 changes: 12 additions & 9 deletions contracts/dao/extensions/aibtc-core-proposals.clar
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
(define-constant SELF (as-contract tx-sender))
(define-constant VOTING_PERIOD u144) ;; 144 Bitcoin blocks, ~1 day
(define-constant VOTING_QUORUM u95) ;; 95% of liquid supply
(define-constant DEPLOYED_AT burn-block-height)

;; error messages
(define-constant ERR_NOT_DAO_OR_EXTENSION (err u3000))
Expand All @@ -32,6 +33,7 @@
(define-constant ERR_VOTE_TOO_SOON (err u3009))
(define-constant ERR_VOTE_TOO_LATE (err u3010))
(define-constant ERR_ALREADY_VOTED (err u3011))
(define-constant ERR_FIRST_VOTING_PERIOD (err u3012))

;; contracts used for voting calculations
(define-constant VOTING_TOKEN_DEX .aibtc-token-dex)
Expand All @@ -46,8 +48,9 @@
createdAt: uint, ;; block height
caller: principal, ;; contract caller
creator: principal, ;; proposal creator (tx-sender)
startBlock: uint, ;; block height
endBlock: uint, ;; block height
startBlockStx: uint, ;; block height for at-block calls
startBlock: uint, ;; burn block height
endBlock: uint, ;; burn block height
votesFor: uint, ;; total votes for
votesAgainst: uint, ;; total votes against
liquidTokens: uint, ;; liquid tokens
Expand Down Expand Up @@ -77,6 +80,8 @@
(proposalContract (contract-of proposal))
(liquidTokens (try! (get-liquid-supply block-height)))
)
;; at least one voting period passed
(asserts! (>= burn-block-height (+ DEPLOYED_AT VOTING_PERIOD)) ERR_FIRST_VOTING_PERIOD)
;; caller has the required balance
(asserts! (> (unwrap! (contract-call? .aibtc-token get-balance tx-sender) ERR_FETCHING_TOKEN_DATA) u0) ERR_INSUFFICIENT_BALANCE)
;; proposal was not already executed
Expand All @@ -88,6 +93,7 @@
proposal: proposalContract,
creator: tx-sender,
liquidTokens: liquidTokens,
startBlockStx: block-height,

Check warning on line 96 in contracts/dao/extensions/aibtc-core-proposals.clar

View check run for this annotation

Codecov / codecov/patch

contracts/dao/extensions/aibtc-core-proposals.clar#L96

Added line #L96 was not covered by tests
startBlock: burn-block-height,
endBlock: (+ burn-block-height VOTING_PERIOD)
}
Expand All @@ -97,6 +103,7 @@
createdAt: burn-block-height,
caller: contract-caller,
creator: tx-sender,
startBlockStx: block-height,

Check warning on line 106 in contracts/dao/extensions/aibtc-core-proposals.clar

View check run for this annotation

Codecov / codecov/patch

contracts/dao/extensions/aibtc-core-proposals.clar#L106

Added line #L106 was not covered by tests
startBlock: burn-block-height,
endBlock: (+ burn-block-height VOTING_PERIOD),
votesFor: u0,
Expand All @@ -112,10 +119,9 @@
(
(proposalContract (contract-of proposal))
(proposalRecord (unwrap! (map-get? Proposals proposalContract) ERR_PROPOSAL_NOT_FOUND))
(proposalBlock (get startBlock proposalRecord))
(proposalBlock (get startBlockStx proposalRecord))

Check warning on line 122 in contracts/dao/extensions/aibtc-core-proposals.clar

View check run for this annotation

Codecov / codecov/patch

contracts/dao/extensions/aibtc-core-proposals.clar#L122

Added line #L122 was not covered by tests
(proposalBlockHash (unwrap! (get-block-hash proposalBlock) ERR_RETRIEVING_START_BLOCK_HASH))
(senderBalanceResponse (at-block proposalBlockHash (contract-call? .aibtc-token get-balance tx-sender)))
(senderBalance (unwrap-panic senderBalanceResponse))
(senderBalance (unwrap! (at-block proposalBlockHash (contract-call? .aibtc-token get-balance tx-sender)) ERR_FETCHING_TOKEN_DATA))

Check warning on line 124 in contracts/dao/extensions/aibtc-core-proposals.clar

View check run for this annotation

Codecov / codecov/patch

contracts/dao/extensions/aibtc-core-proposals.clar#L124

Added line #L124 was not covered by tests
)
;; caller has the required balance
(asserts! (> senderBalance u0) ERR_INSUFFICIENT_BALANCE)
Expand Down Expand Up @@ -154,8 +160,6 @@
(
(proposalContract (contract-of proposal))
(proposalRecord (unwrap! (map-get? Proposals proposalContract) ERR_PROPOSAL_NOT_FOUND))
(tokenTotalSupply (unwrap! (contract-call? .aibtc-token get-total-supply) ERR_FETCHING_TOKEN_DATA))
(treasuryBalance (unwrap! (contract-call? .aibtc-token get-balance .aibtc-treasury) ERR_FETCHING_TOKEN_DATA))
;; if VOTING_QUORUM <= ((votesFor * 100) / liquidTokens)
(votePassed (<= VOTING_QUORUM (/ (* (get votesFor proposalRecord) u100) (get liquidTokens proposalRecord))))
)
Expand Down Expand Up @@ -194,7 +198,7 @@
(let
(
(proposalRecord (unwrap! (map-get? Proposals (contract-of proposal)) ERR_PROPOSAL_NOT_FOUND))
(proposalBlockHash (unwrap! (get-block-hash (get startBlock proposalRecord)) ERR_RETRIEVING_START_BLOCK_HASH))
(proposalBlockHash (unwrap! (get-block-hash (get startBlockStx proposalRecord)) ERR_RETRIEVING_START_BLOCK_HASH))

Check warning on line 201 in contracts/dao/extensions/aibtc-core-proposals.clar

View check run for this annotation

Codecov / codecov/patch

contracts/dao/extensions/aibtc-core-proposals.clar#L201

Added line #L201 was not covered by tests
)
(at-block proposalBlockHash (contract-call? .aibtc-token get-balance who))
)
Expand Down Expand Up @@ -233,7 +237,6 @@
))
)

;; get block hash by height
(define-private (get-block-hash (blockHeight uint))
(get-block-info? id-header-hash blockHeight)
)
Expand Down
2 changes: 1 addition & 1 deletion contracts/dao/extensions/aibtc-token-owner.clar
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
;; constants
;;

(define-constant ERR_UNAUTHORIZED (err u401))
(define-constant ERR_UNAUTHORIZED (err u7000))

;; public functions
;;
Expand Down
2 changes: 1 addition & 1 deletion contracts/dao/proposals/aibtc-base-disable-extension.clar
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(impl-trait .aibtcdev-dao-traits-v1.proposal)

(define-constant ERR_EXTENSION_NOT_FOUND (err u404))
(define-constant ERR_EXTENSION_NOT_FOUND (err u3003))

(define-public (execute (sender principal))
;; disables an extension in the DAO
Expand Down
2 changes: 1 addition & 1 deletion contracts/dao/proposals/aibtc-base-enable-extension.clar
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(impl-trait .aibtcdev-dao-traits-v1.proposal)

(define-constant ERR_EXTENSION_NOT_FOUND (err u404))
(define-constant ERR_EXTENSION_NOT_FOUND (err u3003))

(define-public (execute (sender principal))
;; disables an extension in the DAO
Expand Down
2 changes: 1 addition & 1 deletion contracts/dao/proposals/aibtc-base-replace-extension.clar
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(impl-trait .aibtcdev-dao-traits-v1.proposal)

(define-constant ERR_EXTENSION_NOT_FOUND (err u404))
(define-constant ERR_EXTENSION_NOT_FOUND (err u3003))

(define-public (execute (sender principal))
;; replaces an extension in the DAO
Expand Down
Loading
Loading