From bef64eeb0cafe175c0b35f3b3de12c3710d9c667 Mon Sep 17 00:00:00 2001 From: Jason Schrader Date: Tue, 14 Jan 2025 14:32:34 -0700 Subject: [PATCH 01/19] fix: add pattern for testing proposals They all really need the same test to start: execute fails when called directly. Importing error codes to avoid setting them again, so far since each proposal is keyed to one contract doesn't look like an issue. --- .../dao/extensions/aibtc-bank-account.test.ts | 2 +- .../aibtc-bank-account-deposit-stx.test.ts | 22 ++++++++++++++++--- ...ank-account-initialize-new-account.test.ts | 21 +++++++++++++++--- ...unt-override-last-withdrawal-block.test.ts | 21 +++++++++++++++--- ...tc-bank-account-set-account-holder.test.ts | 21 +++++++++++++++--- ...bank-account-set-withdrawal-amount.test.ts | 21 +++++++++++++++--- ...bank-account-set-withdrawal-period.test.ts | 21 +++++++++++++++--- .../aibtc-bank-account-withdraw-stx.test.ts | 21 +++++++++++++++--- 8 files changed, 128 insertions(+), 22 deletions(-) diff --git a/tests/dao/extensions/aibtc-bank-account.test.ts b/tests/dao/extensions/aibtc-bank-account.test.ts index b7f6c13..4acb3ab 100644 --- a/tests/dao/extensions/aibtc-bank-account.test.ts +++ b/tests/dao/extensions/aibtc-bank-account.test.ts @@ -8,7 +8,7 @@ const deployer = accounts.get("deployer")!; const contractAddress = `${deployer}.aibtc-bank-account`; -enum ErrCode { +export enum ErrCode { ERR_INVALID = 2000, ERR_UNAUTHORIZED, ERR_TOO_SOON, diff --git a/tests/dao/proposals/aibtc-bank-account-deposit-stx.test.ts b/tests/dao/proposals/aibtc-bank-account-deposit-stx.test.ts index 8f5ff5c..b7a4cae 100644 --- a/tests/dao/proposals/aibtc-bank-account-deposit-stx.test.ts +++ b/tests/dao/proposals/aibtc-bank-account-deposit-stx.test.ts @@ -1,7 +1,23 @@ +import { Cl } from "@stacks/transactions"; import { describe, expect, it } from "vitest"; -describe("aibtc-bank-account-deposit-stx", () => { - it("should have tests written", () => { - expect(true).toBe(true); +const accounts = simnet.getAccounts(); +const deployer = accounts.get("deployer")!; +const contractName = "aibtc-bank-account-deposit-stx"; +const contractAddress = `${deployer}.${contractName}`; + +// normally would succeed (anyone can call) +// fails because contract has no funds to deposit +const expectedErr = Cl.uint(4); + +describe(contractName, () => { + it("execute() fails if called directly", () => { + const receipt = simnet.callPublicFn( + contractAddress, + "execute", + [Cl.principal(deployer)], + deployer + ); + expect(receipt.result).toBeErr(expectedErr); }); }); diff --git a/tests/dao/proposals/aibtc-bank-account-initialize-new-account.test.ts b/tests/dao/proposals/aibtc-bank-account-initialize-new-account.test.ts index 45a2e81..b784447 100644 --- a/tests/dao/proposals/aibtc-bank-account-initialize-new-account.test.ts +++ b/tests/dao/proposals/aibtc-bank-account-initialize-new-account.test.ts @@ -1,7 +1,22 @@ +import { Cl } from "@stacks/transactions"; import { describe, expect, it } from "vitest"; +import { ErrCode } from "../extensions/aibtc-bank-account.test"; -describe("aibtc-bank-account-initialize-new", () => { - it("should have tests written", () => { - expect(true).toBe(true); +const accounts = simnet.getAccounts(); +const deployer = accounts.get("deployer")!; +const contractName = "aibtc-bank-account-initialize-new-account"; +const contractAddress = `${deployer}.${contractName}`; + +const expectedErr = Cl.uint(ErrCode.ERR_UNAUTHORIZED); + +describe(contractName, () => { + it("execute() fails if called directly", () => { + const receipt = simnet.callPublicFn( + contractAddress, + "execute", + [Cl.principal(deployer)], + deployer + ); + expect(receipt.result).toBeErr(expectedErr); }); }); diff --git a/tests/dao/proposals/aibtc-bank-account-override-last-withdrawal-block.test.ts b/tests/dao/proposals/aibtc-bank-account-override-last-withdrawal-block.test.ts index c56ca07..8f4ea40 100644 --- a/tests/dao/proposals/aibtc-bank-account-override-last-withdrawal-block.test.ts +++ b/tests/dao/proposals/aibtc-bank-account-override-last-withdrawal-block.test.ts @@ -1,7 +1,22 @@ +import { Cl } from "@stacks/transactions"; import { describe, expect, it } from "vitest"; +import { ErrCode } from "../extensions/aibtc-bank-account.test"; -describe("aibtc-bank-account-override-last-withdrawal-block", () => { - it("should have tests written", () => { - expect(true).toBe(true); +const accounts = simnet.getAccounts(); +const deployer = accounts.get("deployer")!; +const contractName = "aibtc-bank-account-override-last-withdrawal-block"; +const contractAddress = `${deployer}.${contractName}`; + +const expectedErr = Cl.uint(ErrCode.ERR_UNAUTHORIZED); + +describe(contractName, () => { + it("execute() fails if called directly", () => { + const receipt = simnet.callPublicFn( + contractAddress, + "execute", + [Cl.principal(deployer)], + deployer + ); + expect(receipt.result).toBeErr(expectedErr); }); }); diff --git a/tests/dao/proposals/aibtc-bank-account-set-account-holder.test.ts b/tests/dao/proposals/aibtc-bank-account-set-account-holder.test.ts index e3bb295..43544b7 100644 --- a/tests/dao/proposals/aibtc-bank-account-set-account-holder.test.ts +++ b/tests/dao/proposals/aibtc-bank-account-set-account-holder.test.ts @@ -1,7 +1,22 @@ +import { Cl } from "@stacks/transactions"; import { describe, expect, it } from "vitest"; +import { ErrCode } from "../extensions/aibtc-bank-account.test"; -describe("aibtc-bank-account-set-account-holder", () => { - it("should have tests written", () => { - expect(true).toBe(true); +const accounts = simnet.getAccounts(); +const deployer = accounts.get("deployer")!; +const contractName = "aibtc-bank-account-set-account-holder"; +const contractAddress = `${deployer}.${contractName}`; + +const expectedErr = Cl.uint(ErrCode.ERR_UNAUTHORIZED); + +describe(contractName, () => { + it("execute() fails if called directly", () => { + const receipt = simnet.callPublicFn( + contractAddress, + "execute", + [Cl.principal(deployer)], + deployer + ); + expect(receipt.result).toBeErr(expectedErr); }); }); diff --git a/tests/dao/proposals/aibtc-bank-account-set-withdrawal-amount.test.ts b/tests/dao/proposals/aibtc-bank-account-set-withdrawal-amount.test.ts index bfe55d3..6634213 100644 --- a/tests/dao/proposals/aibtc-bank-account-set-withdrawal-amount.test.ts +++ b/tests/dao/proposals/aibtc-bank-account-set-withdrawal-amount.test.ts @@ -1,7 +1,22 @@ +import { Cl } from "@stacks/transactions"; import { describe, expect, it } from "vitest"; +import { ErrCode } from "../extensions/aibtc-bank-account.test"; -describe("aibtc-bank-account-set-withdrawal-amount", () => { - it("should have tests written", () => { - expect(true).toBe(true); +const accounts = simnet.getAccounts(); +const deployer = accounts.get("deployer")!; +const contractName = "aibtc-bank-account-set-withdrawal-amount"; +const contractAddress = `${deployer}.${contractName}`; + +const expectedErr = Cl.uint(ErrCode.ERR_UNAUTHORIZED); + +describe(contractName, () => { + it("execute() fails if called directly", () => { + const receipt = simnet.callPublicFn( + contractAddress, + "execute", + [Cl.principal(deployer)], + deployer + ); + expect(receipt.result).toBeErr(expectedErr); }); }); diff --git a/tests/dao/proposals/aibtc-bank-account-set-withdrawal-period.test.ts b/tests/dao/proposals/aibtc-bank-account-set-withdrawal-period.test.ts index d465e95..927880b 100644 --- a/tests/dao/proposals/aibtc-bank-account-set-withdrawal-period.test.ts +++ b/tests/dao/proposals/aibtc-bank-account-set-withdrawal-period.test.ts @@ -1,7 +1,22 @@ +import { Cl } from "@stacks/transactions"; import { describe, expect, it } from "vitest"; +import { ErrCode } from "../extensions/aibtc-bank-account.test"; -describe("aibtc-bank-account-set-withdrawal-period", () => { - it("should have tests written", () => { - expect(true).toBe(true); +const accounts = simnet.getAccounts(); +const deployer = accounts.get("deployer")!; +const contractName = "aibtc-bank-account-set-withdrawal-period"; +const contractAddress = `${deployer}.${contractName}`; + +const expectedErr = Cl.uint(ErrCode.ERR_UNAUTHORIZED); + +describe(contractName, () => { + it("execute() fails if called directly", () => { + const receipt = simnet.callPublicFn( + contractAddress, + "execute", + [Cl.principal(deployer)], + deployer + ); + expect(receipt.result).toBeErr(expectedErr); }); }); diff --git a/tests/dao/proposals/aibtc-bank-account-withdraw-stx.test.ts b/tests/dao/proposals/aibtc-bank-account-withdraw-stx.test.ts index 30346a3..68908be 100644 --- a/tests/dao/proposals/aibtc-bank-account-withdraw-stx.test.ts +++ b/tests/dao/proposals/aibtc-bank-account-withdraw-stx.test.ts @@ -1,7 +1,22 @@ +import { Cl } from "@stacks/transactions"; import { describe, expect, it } from "vitest"; +import { ErrCode } from "../extensions/aibtc-bank-account.test"; -describe("aibtc-bank-account-withdraw-stx", () => { - it("should have tests written", () => { - expect(true).toBe(true); +const accounts = simnet.getAccounts(); +const deployer = accounts.get("deployer")!; +const contractName = "aibtc-bank-account-withdraw-stx"; +const contractAddress = `${deployer}.${contractName}`; + +const expectedErr = Cl.uint(ErrCode.ERR_UNAUTHORIZED); + +describe(contractName, () => { + it("execute() fails if called directly", () => { + const receipt = simnet.callPublicFn( + contractAddress, + "execute", + [Cl.principal(deployer)], + deployer + ); + expect(receipt.result).toBeErr(expectedErr); }); }); From 6312bed29aded95118fa0a363cafe095f799927f Mon Sep 17 00:00:00 2001 From: Jason Schrader Date: Tue, 14 Jan 2025 15:15:59 -0700 Subject: [PATCH 02/19] refactor: everything neat and tidy --- .../dao/extensions/aibtc-token-owner.clar | 2 +- tests/dao/aibtcdev-base-dao.test.ts | 15 +++++++------ .../actions/aibtc-action-add-resource.test.ts | 5 +++-- .../actions/aibtc-action-allow-asset.test.ts | 5 +++-- .../actions/aibtc-action-send-message.test.ts | 5 +++-- .../aibtc-action-set-account-holder.test.ts | 5 +++-- ...aibtc-action-set-withdrawal-amount.test.ts | 5 +++-- ...aibtc-action-set-withdrawal-period.test.ts | 5 +++-- ...btc-action-toggle-resource-by-name.test.ts | 5 +++-- .../extensions/aibtc-action-proposals.test.ts | 5 +++-- .../dao/extensions/aibtc-bank-account.test.ts | 5 +++-- .../extensions/aibtc-core-proposals.test.ts | 5 +++-- .../aibtc-onchain-messaging.test.ts | 5 +++-- .../aibtc-payments-invoices.test.ts | 7 +++--- .../dao/extensions/aibtc-token-owner.test.ts | 9 ++++++-- tests/dao/extensions/aibtc-treasury.test.ts | 7 +++--- .../aibtc-bank-account-deposit-stx.test.ts | 2 +- ...ank-account-initialize-new-account.test.ts | 2 +- ...unt-override-last-withdrawal-block.test.ts | 2 +- ...tc-bank-account-set-account-holder.test.ts | 2 +- ...bank-account-set-withdrawal-amount.test.ts | 2 +- ...bank-account-set-withdrawal-period.test.ts | 2 +- .../aibtc-bank-account-withdraw-stx.test.ts | 2 +- .../aibtc-base-add-new-extension.test.ts | 21 +++++++++++++++--- ...ibtc-base-bootstrap-initialization.test.ts | 18 ++++++++++++--- .../aibtc-base-disable-extension.test.ts | 22 ++++++++++++++++--- .../aibtc-base-enable-extension.test.ts | 22 ++++++++++++++++--- .../aibtc-base-replace-extension.test.ts | 22 ++++++++++++++++--- .../aibtc-onchain-messaging-send.test.ts | 21 +++++++++++++++--- ...btc-payments-invoices-add-resource.test.ts | 21 +++++++++++++++--- ...oices-pay-invoice-by-resource-name.test.ts | 21 +++++++++++++++--- ...ibtc-payments-invoices-pay-invoice.test.ts | 21 +++++++++++++++--- ...ments-invoices-set-payment-address.test.ts | 21 +++++++++++++++--- ...s-invoices-toggle-resource-by-name.test.ts | 21 +++++++++++++++--- ...-payments-invoices-toggle-resource.test.ts | 21 +++++++++++++++--- .../aibtc-token-owner-set-token-uri.test.ts | 21 +++++++++++++++--- ...btc-token-owner-transfer-ownership.test.ts | 21 +++++++++++++++--- .../aibtc-treasury-allow-asset.test.ts | 21 +++++++++++++++--- .../aibtc-treasury-delegate-stx.test.ts | 21 +++++++++++++++--- .../aibtc-treasury-deposit-ft.test.ts | 21 +++++++++++++++--- .../aibtc-treasury-deposit-nft.test.ts | 21 +++++++++++++++--- .../aibtc-treasury-deposit-stx.test.ts | 19 +++++++++++++--- .../aibtc-treasury-freeze-asset.test.ts | 21 +++++++++++++++--- .../aibtc-treasury-revoke-delegation.test.ts | 21 +++++++++++++++--- .../aibtc-treasury-withdraw-ft.test.ts | 21 +++++++++++++++--- .../aibtc-treasury-withdraw-nft.test.ts | 21 +++++++++++++++--- .../aibtc-treasury-withdraw-stx.test.ts | 21 +++++++++++++++--- 47 files changed, 494 insertions(+), 117 deletions(-) diff --git a/contracts/dao/extensions/aibtc-token-owner.clar b/contracts/dao/extensions/aibtc-token-owner.clar index a18fb6c..702c54b 100644 --- a/contracts/dao/extensions/aibtc-token-owner.clar +++ b/contracts/dao/extensions/aibtc-token-owner.clar @@ -10,7 +10,7 @@ ;; constants ;; -(define-constant ERR_UNAUTHORIZED (err u401)) +(define-constant ERR_UNAUTHORIZED (err u7000)) ;; public functions ;; diff --git a/tests/dao/aibtcdev-base-dao.test.ts b/tests/dao/aibtcdev-base-dao.test.ts index ae95145..1f949d9 100644 --- a/tests/dao/aibtcdev-base-dao.test.ts +++ b/tests/dao/aibtcdev-base-dao.test.ts @@ -6,16 +6,17 @@ const address1 = accounts.get("wallet_1")!; const address2 = accounts.get("wallet_2")!; const deployer = accounts.get("deployer")!; -const contractAddress = `${deployer}.aibtcdev-base-dao`; +const contractName = "aibtcdev-base-dao"; +const contractAddress = `${deployer}.${contractName}`; -enum ErrCode { - ERR_UNAUTHORIZED = 1000, - ERR_NOT_DAO_OR_EXTENSION = 1001, - ERR_ALREADY_EXECUTED = 1002, - ERR_INVALID_EXTENSION = 1003, +export enum ErrCode { + ERR_UNAUTHORIZED = 900, + ERR_ALREADY_EXECUTED, + ERR_INVALID_EXTENSION, + ERR_NO_EMPTY_LISTS, } -describe("aibtcdev-base-dao", () => { +describe(`base dao: ${contractName}`, () => { it("should have tests written", () => { expect(true).toBe(true); }); diff --git a/tests/dao/extensions/actions/aibtc-action-add-resource.test.ts b/tests/dao/extensions/actions/aibtc-action-add-resource.test.ts index 00f1846..d508e73 100644 --- a/tests/dao/extensions/actions/aibtc-action-add-resource.test.ts +++ b/tests/dao/extensions/actions/aibtc-action-add-resource.test.ts @@ -4,9 +4,10 @@ import { describe, expect, it } from "vitest"; const accounts = simnet.getAccounts(); const deployer = accounts.get("deployer")!; -const contractAddress = `${deployer}.aibtc-action-add-resource`; +const contractName = "aibtc-action-add-resource"; +const contractAddress = `${deployer}.${contractName}`; -describe("aibtc-action-add-resource", () => { +describe(`action extension: ${contractName}`, () => { it("callback() should respond with (ok true)", () => { const callback = simnet.callPublicFn( contractAddress, diff --git a/tests/dao/extensions/actions/aibtc-action-allow-asset.test.ts b/tests/dao/extensions/actions/aibtc-action-allow-asset.test.ts index 1519f01..57a9550 100644 --- a/tests/dao/extensions/actions/aibtc-action-allow-asset.test.ts +++ b/tests/dao/extensions/actions/aibtc-action-allow-asset.test.ts @@ -4,9 +4,10 @@ import { describe, expect, it } from "vitest"; const accounts = simnet.getAccounts(); const deployer = accounts.get("deployer")!; -const contractAddress = `${deployer}.aibtc-action-add-resource`; +const contractName = "aibtc-action-allow-asset"; +const contractAddress = `${deployer}.${contractName}`; -describe("aibtc-action-allow-asset", () => { +describe(`action extension: ${contractName}`, () => { it("callback() should respond with (ok true)", () => { const callback = simnet.callPublicFn( contractAddress, diff --git a/tests/dao/extensions/actions/aibtc-action-send-message.test.ts b/tests/dao/extensions/actions/aibtc-action-send-message.test.ts index c3b416f..1178c17 100644 --- a/tests/dao/extensions/actions/aibtc-action-send-message.test.ts +++ b/tests/dao/extensions/actions/aibtc-action-send-message.test.ts @@ -4,9 +4,10 @@ import { describe, expect, it } from "vitest"; const accounts = simnet.getAccounts(); const deployer = accounts.get("deployer")!; -const contractAddress = `${deployer}.aibtc-action-add-resource`; +const contractName = "aibtc-action-send-message"; +const contractAddress = `${deployer}.${contractName}`; -describe("aibtc-action-send-message", () => { +describe(`action extension: ${contractName}`, () => { it("callback() should respond with (ok true)", () => { const callback = simnet.callPublicFn( contractAddress, diff --git a/tests/dao/extensions/actions/aibtc-action-set-account-holder.test.ts b/tests/dao/extensions/actions/aibtc-action-set-account-holder.test.ts index 53faf99..0a8636e 100644 --- a/tests/dao/extensions/actions/aibtc-action-set-account-holder.test.ts +++ b/tests/dao/extensions/actions/aibtc-action-set-account-holder.test.ts @@ -4,9 +4,10 @@ import { describe, expect, it } from "vitest"; const accounts = simnet.getAccounts(); const deployer = accounts.get("deployer")!; -const contractAddress = `${deployer}.aibtc-action-add-resource`; +const contractName = "aibtc-action-set-account-holder"; +const contractAddress = `${deployer}.${contractName}`; -describe("aibtc-action-set-account-holder", () => { +describe(`action extension: ${contractName}`, () => { it("callback() should respond with (ok true)", () => { const callback = simnet.callPublicFn( contractAddress, diff --git a/tests/dao/extensions/actions/aibtc-action-set-withdrawal-amount.test.ts b/tests/dao/extensions/actions/aibtc-action-set-withdrawal-amount.test.ts index b659104..182f90a 100644 --- a/tests/dao/extensions/actions/aibtc-action-set-withdrawal-amount.test.ts +++ b/tests/dao/extensions/actions/aibtc-action-set-withdrawal-amount.test.ts @@ -4,9 +4,10 @@ import { describe, expect, it } from "vitest"; const accounts = simnet.getAccounts(); const deployer = accounts.get("deployer")!; -const contractAddress = `${deployer}.aibtc-action-add-resource`; +const contractName = "aibtc-action-set-withdrawal-amount"; +const contractAddress = `${deployer}.${contractName}`; -describe("aibtc-action-set-withdrawal-amount", () => { +describe(`action extension: ${contractName}`, () => { it("callback() should respond with (ok true)", () => { const callback = simnet.callPublicFn( contractAddress, diff --git a/tests/dao/extensions/actions/aibtc-action-set-withdrawal-period.test.ts b/tests/dao/extensions/actions/aibtc-action-set-withdrawal-period.test.ts index bf0c8df..1c2b699 100644 --- a/tests/dao/extensions/actions/aibtc-action-set-withdrawal-period.test.ts +++ b/tests/dao/extensions/actions/aibtc-action-set-withdrawal-period.test.ts @@ -4,9 +4,10 @@ import { describe, expect, it } from "vitest"; const accounts = simnet.getAccounts(); const deployer = accounts.get("deployer")!; -const contractAddress = `${deployer}.aibtc-action-add-resource`; +const contractName = "aibtc-action-set-withdrawal-period"; +const contractAddress = `${deployer}.${contractName}`; -describe("aibtc-action-set-withdrawal-period", () => { +describe(`action extension: ${contractName}`, () => { it("callback() should respond with (ok true)", () => { const callback = simnet.callPublicFn( contractAddress, diff --git a/tests/dao/extensions/actions/aibtc-action-toggle-resource-by-name.test.ts b/tests/dao/extensions/actions/aibtc-action-toggle-resource-by-name.test.ts index 48b4ac5..5f9ec21 100644 --- a/tests/dao/extensions/actions/aibtc-action-toggle-resource-by-name.test.ts +++ b/tests/dao/extensions/actions/aibtc-action-toggle-resource-by-name.test.ts @@ -4,9 +4,10 @@ import { describe, expect, it } from "vitest"; const accounts = simnet.getAccounts(); const deployer = accounts.get("deployer")!; -const contractAddress = `${deployer}.aibtc-action-add-resource`; +const contractName = "aibtc-action-toggle-resource-by-name"; +const contractAddress = `${deployer}.${contractName}`; -describe("aibtc-action-toggle-resource-by-name", () => { +describe(`action extension: ${contractName}`, () => { it("callback() should respond with (ok true)", () => { const callback = simnet.callPublicFn( contractAddress, diff --git a/tests/dao/extensions/aibtc-action-proposals.test.ts b/tests/dao/extensions/aibtc-action-proposals.test.ts index 15f156d..9816200 100644 --- a/tests/dao/extensions/aibtc-action-proposals.test.ts +++ b/tests/dao/extensions/aibtc-action-proposals.test.ts @@ -6,7 +6,8 @@ const address1 = accounts.get("wallet_1")!; const address2 = accounts.get("wallet_2")!; const deployer = accounts.get("deployer")!; -const contractAddress = `${deployer}.aibtc-action-proposals`; +const contractName = "aibtc-action-proposals"; +const contractAddress = `${deployer}.${contractName}`; export enum ErrCode { ERR_NOT_DAO_OR_EXTENSION = 1000, @@ -26,7 +27,7 @@ export enum ErrCode { const votingPeriod = 144; // 24 hours in BTC blocks const votingQuorum = 66; // 66% quorum -describe("aibtc-action-proposals", () => { +describe(`extension: ${contractName}`, () => { it("callback() should respond with (ok true)", () => { const callback = simnet.callPublicFn( contractAddress, diff --git a/tests/dao/extensions/aibtc-bank-account.test.ts b/tests/dao/extensions/aibtc-bank-account.test.ts index 4acb3ab..ae1d936 100644 --- a/tests/dao/extensions/aibtc-bank-account.test.ts +++ b/tests/dao/extensions/aibtc-bank-account.test.ts @@ -6,7 +6,8 @@ const address1 = accounts.get("wallet_1")!; const address2 = accounts.get("wallet_2")!; const deployer = accounts.get("deployer")!; -const contractAddress = `${deployer}.aibtc-bank-account`; +const contractName = "aibtc-bank-account"; +const contractAddress = `${deployer}.${contractName}`; export enum ErrCode { ERR_INVALID = 2000, @@ -18,7 +19,7 @@ export enum ErrCode { const withdrawalAmount = 10000000; // 10 STX const withdrawalPeriod = 144; // 144 blocks -describe("aibtc-bank-account", () => { +describe(`extension: ${contractName}`, () => { it("callback() should respond with (ok true)", () => { const callback = simnet.callPublicFn( contractAddress, diff --git a/tests/dao/extensions/aibtc-core-proposals.test.ts b/tests/dao/extensions/aibtc-core-proposals.test.ts index a106c08..50ba758 100644 --- a/tests/dao/extensions/aibtc-core-proposals.test.ts +++ b/tests/dao/extensions/aibtc-core-proposals.test.ts @@ -4,7 +4,8 @@ import { describe, expect, it } from "vitest"; const accounts = simnet.getAccounts(); const deployer = accounts.get("deployer")!; -const contractAddress = `${deployer}.aibtc-core-proposals`; +const contractName = "aibtc-core-proposals"; +const contractAddress = `${deployer}.${contractName}`; export enum ErrCode { ERR_NOT_DAO_OR_EXTENSION = 3000, @@ -24,7 +25,7 @@ export enum ErrCode { const votingPeriod = 144; // 24 hours in BTC blocks const votingQuorum = 95; // 95% quorum -describe("aibtc-core-proposals", () => { +describe(`extension: ${contractName}`, () => { it("callback() should respond with (ok true)", () => { const callback = simnet.callPublicFn( contractAddress, diff --git a/tests/dao/extensions/aibtc-onchain-messaging.test.ts b/tests/dao/extensions/aibtc-onchain-messaging.test.ts index 7157651..0e667f8 100644 --- a/tests/dao/extensions/aibtc-onchain-messaging.test.ts +++ b/tests/dao/extensions/aibtc-onchain-messaging.test.ts @@ -6,14 +6,15 @@ const address1 = accounts.get("wallet_1")!; const address2 = accounts.get("wallet_2")!; const deployer = accounts.get("deployer")!; -const contractAddress = `${deployer}.aibtc-onchain-messaging`; +const contractName = "aibtc-onchain-messaging"; +const contractAddress = `${deployer}.${contractName}`; export enum ErrCode { INPUT_ERROR = 4000, ERR_UNAUTHORIZED, } -describe("aibtc-onchain-messaging", () => { +describe(`extension: ${contractName}`, () => { it("callback() should respond with (ok true)", () => { const callback = simnet.callPublicFn( contractAddress, diff --git a/tests/dao/extensions/aibtc-payments-invoices.test.ts b/tests/dao/extensions/aibtc-payments-invoices.test.ts index 6c4d047..50ae70a 100644 --- a/tests/dao/extensions/aibtc-payments-invoices.test.ts +++ b/tests/dao/extensions/aibtc-payments-invoices.test.ts @@ -6,9 +6,10 @@ const address1 = accounts.get("wallet_1")!; const address2 = accounts.get("wallet_2")!; const deployer = accounts.get("deployer")!; -const contractAddress = `${deployer}.aibtc-payments-invoices`; +const contractName = "aibtc-payments-invoices"; +const contractAddress = `${deployer}.${contractName}`; -enum ErrCode { +export enum ErrCode { ERR_UNAUTHORIZED = 5000, ERR_INVALID_PARAMS, ERR_NAME_ALREADY_USED, @@ -25,7 +26,7 @@ enum ErrCode { ERR_RECENT_PAYMENT_NOT_FOUND, } -describe("aibtc-payments-invoices", () => { +describe(`extension: ${contractName}`, () => { it("callback() should respond with (ok true)", () => { const callback = simnet.callPublicFn( contractAddress, diff --git a/tests/dao/extensions/aibtc-token-owner.test.ts b/tests/dao/extensions/aibtc-token-owner.test.ts index 3cab3dd..1e101a8 100644 --- a/tests/dao/extensions/aibtc-token-owner.test.ts +++ b/tests/dao/extensions/aibtc-token-owner.test.ts @@ -4,9 +4,14 @@ import { describe, expect, it } from "vitest"; const accounts = simnet.getAccounts(); const deployer = accounts.get("deployer")!; -const contractAddress = `${deployer}.aibtc-token-owner`; +const contractName = "aibtc-token-owner"; +const contractAddress = `${deployer}.${contractName}`; -describe("aibtc-token-owner", () => { +export enum ErrCode { + ERR_UNAUTHORIZED = 7000, +} + +describe(`extension: ${contractName}`, () => { it("callback() should respond with (ok true)", () => { const callback = simnet.callPublicFn( contractAddress, diff --git a/tests/dao/extensions/aibtc-treasury.test.ts b/tests/dao/extensions/aibtc-treasury.test.ts index 67f5ef1..ff40c10 100644 --- a/tests/dao/extensions/aibtc-treasury.test.ts +++ b/tests/dao/extensions/aibtc-treasury.test.ts @@ -6,14 +6,15 @@ const address1 = accounts.get("wallet_1")!; const address2 = accounts.get("wallet_2")!; const deployer = accounts.get("deployer")!; -const contractAddress = `${deployer}.aibtc-treasury`; +const contractName = "aibtc-treasury"; +const contractAddress = `${deployer}.${contractName}`; -enum ErrCode { +export enum ErrCode { ERR_UNAUTHORIZED = 6000, ERR_UNKNOWN_ASSSET = 6001, } -describe("aibtc-treasury", () => { +describe(`extension: ${contractName}`, () => { it("callback() should respond with (ok true)", () => { const callback = simnet.callPublicFn( contractAddress, diff --git a/tests/dao/proposals/aibtc-bank-account-deposit-stx.test.ts b/tests/dao/proposals/aibtc-bank-account-deposit-stx.test.ts index b7a4cae..f49315e 100644 --- a/tests/dao/proposals/aibtc-bank-account-deposit-stx.test.ts +++ b/tests/dao/proposals/aibtc-bank-account-deposit-stx.test.ts @@ -10,7 +10,7 @@ const contractAddress = `${deployer}.${contractName}`; // fails because contract has no funds to deposit const expectedErr = Cl.uint(4); -describe(contractName, () => { +describe(`core proposal: ${contractName}`, () => { it("execute() fails if called directly", () => { const receipt = simnet.callPublicFn( contractAddress, diff --git a/tests/dao/proposals/aibtc-bank-account-initialize-new-account.test.ts b/tests/dao/proposals/aibtc-bank-account-initialize-new-account.test.ts index b784447..f43c5da 100644 --- a/tests/dao/proposals/aibtc-bank-account-initialize-new-account.test.ts +++ b/tests/dao/proposals/aibtc-bank-account-initialize-new-account.test.ts @@ -9,7 +9,7 @@ const contractAddress = `${deployer}.${contractName}`; const expectedErr = Cl.uint(ErrCode.ERR_UNAUTHORIZED); -describe(contractName, () => { +describe(`core proposal: ${contractName}`, () => { it("execute() fails if called directly", () => { const receipt = simnet.callPublicFn( contractAddress, diff --git a/tests/dao/proposals/aibtc-bank-account-override-last-withdrawal-block.test.ts b/tests/dao/proposals/aibtc-bank-account-override-last-withdrawal-block.test.ts index 8f4ea40..e2f2828 100644 --- a/tests/dao/proposals/aibtc-bank-account-override-last-withdrawal-block.test.ts +++ b/tests/dao/proposals/aibtc-bank-account-override-last-withdrawal-block.test.ts @@ -9,7 +9,7 @@ const contractAddress = `${deployer}.${contractName}`; const expectedErr = Cl.uint(ErrCode.ERR_UNAUTHORIZED); -describe(contractName, () => { +describe(`core proposal: ${contractName}`, () => { it("execute() fails if called directly", () => { const receipt = simnet.callPublicFn( contractAddress, diff --git a/tests/dao/proposals/aibtc-bank-account-set-account-holder.test.ts b/tests/dao/proposals/aibtc-bank-account-set-account-holder.test.ts index 43544b7..7970c37 100644 --- a/tests/dao/proposals/aibtc-bank-account-set-account-holder.test.ts +++ b/tests/dao/proposals/aibtc-bank-account-set-account-holder.test.ts @@ -9,7 +9,7 @@ const contractAddress = `${deployer}.${contractName}`; const expectedErr = Cl.uint(ErrCode.ERR_UNAUTHORIZED); -describe(contractName, () => { +describe(`core proposal: ${contractName}`, () => { it("execute() fails if called directly", () => { const receipt = simnet.callPublicFn( contractAddress, diff --git a/tests/dao/proposals/aibtc-bank-account-set-withdrawal-amount.test.ts b/tests/dao/proposals/aibtc-bank-account-set-withdrawal-amount.test.ts index 6634213..e418269 100644 --- a/tests/dao/proposals/aibtc-bank-account-set-withdrawal-amount.test.ts +++ b/tests/dao/proposals/aibtc-bank-account-set-withdrawal-amount.test.ts @@ -9,7 +9,7 @@ const contractAddress = `${deployer}.${contractName}`; const expectedErr = Cl.uint(ErrCode.ERR_UNAUTHORIZED); -describe(contractName, () => { +describe(`core proposal: ${contractName}`, () => { it("execute() fails if called directly", () => { const receipt = simnet.callPublicFn( contractAddress, diff --git a/tests/dao/proposals/aibtc-bank-account-set-withdrawal-period.test.ts b/tests/dao/proposals/aibtc-bank-account-set-withdrawal-period.test.ts index 927880b..d591149 100644 --- a/tests/dao/proposals/aibtc-bank-account-set-withdrawal-period.test.ts +++ b/tests/dao/proposals/aibtc-bank-account-set-withdrawal-period.test.ts @@ -9,7 +9,7 @@ const contractAddress = `${deployer}.${contractName}`; const expectedErr = Cl.uint(ErrCode.ERR_UNAUTHORIZED); -describe(contractName, () => { +describe(`core proposal: ${contractName}`, () => { it("execute() fails if called directly", () => { const receipt = simnet.callPublicFn( contractAddress, diff --git a/tests/dao/proposals/aibtc-bank-account-withdraw-stx.test.ts b/tests/dao/proposals/aibtc-bank-account-withdraw-stx.test.ts index 68908be..47fa97f 100644 --- a/tests/dao/proposals/aibtc-bank-account-withdraw-stx.test.ts +++ b/tests/dao/proposals/aibtc-bank-account-withdraw-stx.test.ts @@ -9,7 +9,7 @@ const contractAddress = `${deployer}.${contractName}`; const expectedErr = Cl.uint(ErrCode.ERR_UNAUTHORIZED); -describe(contractName, () => { +describe(`core proposal: ${contractName}`, () => { it("execute() fails if called directly", () => { const receipt = simnet.callPublicFn( contractAddress, diff --git a/tests/dao/proposals/aibtc-base-add-new-extension.test.ts b/tests/dao/proposals/aibtc-base-add-new-extension.test.ts index 7f13dfd..98f6678 100644 --- a/tests/dao/proposals/aibtc-base-add-new-extension.test.ts +++ b/tests/dao/proposals/aibtc-base-add-new-extension.test.ts @@ -1,7 +1,22 @@ +import { Cl } from "@stacks/transactions"; import { describe, expect, it } from "vitest"; +import { ErrCode } from "../aibtcdev-base-dao.test"; -describe("aibtc-base-add-new-extension", () => { - it("should have tests written", () => { - expect(true).toBe(true); +const accounts = simnet.getAccounts(); +const deployer = accounts.get("deployer")!; +const contractName = "aibtc-base-add-new-extension"; +const contractAddress = `${deployer}.${contractName}`; + +const expectedErr = Cl.uint(ErrCode.ERR_UNAUTHORIZED); + +describe(`core proposal: ${contractName}`, () => { + it("execute() fails if called directly", () => { + const receipt = simnet.callPublicFn( + contractAddress, + "execute", + [Cl.principal(deployer)], + deployer + ); + expect(receipt.result).toBeErr(expectedErr); }); }); diff --git a/tests/dao/proposals/aibtc-base-bootstrap-initialization.test.ts b/tests/dao/proposals/aibtc-base-bootstrap-initialization.test.ts index 6423498..f47795b 100644 --- a/tests/dao/proposals/aibtc-base-bootstrap-initialization.test.ts +++ b/tests/dao/proposals/aibtc-base-bootstrap-initialization.test.ts @@ -1,18 +1,30 @@ import { Cl } from "@stacks/transactions"; import { describe, expect, it } from "vitest"; +import { ErrCode } from "../aibtcdev-base-dao.test"; const accounts = simnet.getAccounts(); const address1 = accounts.get("wallet_1")!; const address2 = accounts.get("wallet_2")!; const deployer = accounts.get("deployer")!; -const contractAddress = `${deployer}.aibtc-base-bootstrap-initialization`; +const contractName = "aibtc-base-bootstrap-initialization"; +const contractAddress = `${deployer}.${contractName}`; + +const expectedErr = Cl.uint(ErrCode.ERR_UNAUTHORIZED); const daoManifest = "This is where the DAO can put it's mission, purpose, and goals."; -describe("aibtc-base-bootstrap-proposal", () => { - // Manifest Tests +describe(`core proposal: ${contractName}`, () => { + it("execute() fails if called directly", () => { + const receipt = simnet.callPublicFn( + contractAddress, + "execute", + [Cl.principal(deployer)], + deployer + ); + expect(receipt.result).toBeErr(expectedErr); + }); it("get-dao-manifest() returns DAO_MANIFEST as string", () => { const receipt = simnet.callReadOnlyFn( contractAddress, diff --git a/tests/dao/proposals/aibtc-base-disable-extension.test.ts b/tests/dao/proposals/aibtc-base-disable-extension.test.ts index 8483c8b..3781f61 100644 --- a/tests/dao/proposals/aibtc-base-disable-extension.test.ts +++ b/tests/dao/proposals/aibtc-base-disable-extension.test.ts @@ -1,7 +1,23 @@ +import { Cl } from "@stacks/transactions"; import { describe, expect, it } from "vitest"; +import { ErrCode } from "../aibtcdev-base-dao.test"; -describe("aibtc-base-disable-extension", () => { - it("should have tests written", () => { - expect(true).toBe(true); +const accounts = simnet.getAccounts(); +const deployer = accounts.get("deployer")!; +const contractName = "aibtc-base-disable-extension"; +const contractAddress = `${deployer}.${contractName}`; + +// custom error because proposal is not found / setup yet +const expectedErr = Cl.uint(404); + +describe(`core proposal: ${contractName}`, () => { + it("execute() fails if called directly", () => { + const receipt = simnet.callPublicFn( + contractAddress, + "execute", + [Cl.principal(deployer)], + deployer + ); + expect(receipt.result).toBeErr(expectedErr); }); }); diff --git a/tests/dao/proposals/aibtc-base-enable-extension.test.ts b/tests/dao/proposals/aibtc-base-enable-extension.test.ts index e0a57c8..1726eb5 100644 --- a/tests/dao/proposals/aibtc-base-enable-extension.test.ts +++ b/tests/dao/proposals/aibtc-base-enable-extension.test.ts @@ -1,7 +1,23 @@ +import { Cl } from "@stacks/transactions"; import { describe, expect, it } from "vitest"; +import { ErrCode } from "../aibtcdev-base-dao.test"; -describe("aibtc-base-enable-extension", () => { - it("should have tests written", () => { - expect(true).toBe(true); +const accounts = simnet.getAccounts(); +const deployer = accounts.get("deployer")!; +const contractName = "aibtc-base-enable-extension"; +const contractAddress = `${deployer}.${contractName}`; + +// custom error because proposal is not found / setup yet +const expectedErr = Cl.uint(404); + +describe(`core proposal: ${contractName}`, () => { + it("execute() fails if called directly", () => { + const receipt = simnet.callPublicFn( + contractAddress, + "execute", + [Cl.principal(deployer)], + deployer + ); + expect(receipt.result).toBeErr(expectedErr); }); }); diff --git a/tests/dao/proposals/aibtc-base-replace-extension.test.ts b/tests/dao/proposals/aibtc-base-replace-extension.test.ts index 9f946aa..a4f561a 100644 --- a/tests/dao/proposals/aibtc-base-replace-extension.test.ts +++ b/tests/dao/proposals/aibtc-base-replace-extension.test.ts @@ -1,7 +1,23 @@ +import { Cl } from "@stacks/transactions"; import { describe, expect, it } from "vitest"; +import { ErrCode } from "../aibtcdev-base-dao.test"; -describe("aibtc-base-replace-extension", () => { - it("should have tests written", () => { - expect(true).toBe(true); +const accounts = simnet.getAccounts(); +const deployer = accounts.get("deployer")!; +const contractName = "aibtc-base-replace-extension"; +const contractAddress = `${deployer}.${contractName}`; + +// custom error because proposal is not found / setup yet +const expectedErr = Cl.uint(404); + +describe(`core proposal: ${contractName}`, () => { + it("execute() fails if called directly before dao is initialized", () => { + const receipt = simnet.callPublicFn( + contractAddress, + "execute", + [Cl.principal(deployer)], + deployer + ); + expect(receipt.result).toBeErr(expectedErr); }); }); diff --git a/tests/dao/proposals/aibtc-onchain-messaging-send.test.ts b/tests/dao/proposals/aibtc-onchain-messaging-send.test.ts index 0f7ae9b..a584594 100644 --- a/tests/dao/proposals/aibtc-onchain-messaging-send.test.ts +++ b/tests/dao/proposals/aibtc-onchain-messaging-send.test.ts @@ -1,7 +1,22 @@ +import { Cl } from "@stacks/transactions"; import { describe, expect, it } from "vitest"; +import { ErrCode } from "../extensions/aibtc-onchain-messaging.test"; -describe("aibtc-onchain-messaging-send", () => { - it("should have tests written", () => { - expect(true).toBe(true); +const accounts = simnet.getAccounts(); +const deployer = accounts.get("deployer")!; +const contractName = "aibtc-onchain-messaging-send"; +const contractAddress = `${deployer}.${contractName}`; + +const expectedErr = Cl.uint(ErrCode.ERR_UNAUTHORIZED); + +describe(`core proposal: ${contractName}`, () => { + it("execute() fails if called directly", () => { + const receipt = simnet.callPublicFn( + contractAddress, + "execute", + [Cl.principal(deployer)], + deployer + ); + expect(receipt.result).toBeErr(expectedErr); }); }); diff --git a/tests/dao/proposals/aibtc-payments-invoices-add-resource.test.ts b/tests/dao/proposals/aibtc-payments-invoices-add-resource.test.ts index 6c25ec1..0f669b7 100644 --- a/tests/dao/proposals/aibtc-payments-invoices-add-resource.test.ts +++ b/tests/dao/proposals/aibtc-payments-invoices-add-resource.test.ts @@ -1,7 +1,22 @@ +import { Cl } from "@stacks/transactions"; import { describe, expect, it } from "vitest"; +import { ErrCode } from "../extensions/aibtc-payments-invoices.test"; -describe("aibtc-payments-invoices-add-resource", () => { - it("should have tests written", () => { - expect(true).toBe(true); +const accounts = simnet.getAccounts(); +const deployer = accounts.get("deployer")!; +const contractName = "aibtc-payments-invoices-add-resource"; +const contractAddress = `${deployer}.${contractName}`; + +const expectedErr = Cl.uint(ErrCode.ERR_UNAUTHORIZED); + +describe(`core proposal: ${contractName}`, () => { + it("execute() fails if called directly", () => { + const receipt = simnet.callPublicFn( + contractAddress, + "execute", + [Cl.principal(deployer)], + deployer + ); + expect(receipt.result).toBeErr(expectedErr); }); }); diff --git a/tests/dao/proposals/aibtc-payments-invoices-pay-invoice-by-resource-name.test.ts b/tests/dao/proposals/aibtc-payments-invoices-pay-invoice-by-resource-name.test.ts index 304694c..032e384 100644 --- a/tests/dao/proposals/aibtc-payments-invoices-pay-invoice-by-resource-name.test.ts +++ b/tests/dao/proposals/aibtc-payments-invoices-pay-invoice-by-resource-name.test.ts @@ -1,7 +1,22 @@ +import { Cl } from "@stacks/transactions"; import { describe, expect, it } from "vitest"; +import { ErrCode } from "../extensions/aibtc-payments-invoices.test"; -describe("aibtc-payments-invoices-pay-invoice-by-resource-name", () => { - it("should have tests written", () => { - expect(true).toBe(true); +const accounts = simnet.getAccounts(); +const deployer = accounts.get("deployer")!; +const contractName = "aibtc-payments-invoices-pay-invoice-by-resource-name"; +const contractAddress = `${deployer}.${contractName}`; + +const expectedErr = Cl.uint(ErrCode.ERR_RESOURCE_NOT_FOUND); + +describe(`core proposal: ${contractName}`, () => { + it("execute() fails if called directly", () => { + const receipt = simnet.callPublicFn( + contractAddress, + "execute", + [Cl.principal(deployer)], + deployer + ); + expect(receipt.result).toBeErr(expectedErr); }); }); diff --git a/tests/dao/proposals/aibtc-payments-invoices-pay-invoice.test.ts b/tests/dao/proposals/aibtc-payments-invoices-pay-invoice.test.ts index 19ee4f1..deb9075 100644 --- a/tests/dao/proposals/aibtc-payments-invoices-pay-invoice.test.ts +++ b/tests/dao/proposals/aibtc-payments-invoices-pay-invoice.test.ts @@ -1,7 +1,22 @@ +import { Cl } from "@stacks/transactions"; import { describe, expect, it } from "vitest"; +import { ErrCode } from "../extensions/aibtc-payments-invoices.test"; -describe("aibtc-payments-invoices-pay-invoice", () => { - it("should have tests written", () => { - expect(true).toBe(true); +const accounts = simnet.getAccounts(); +const deployer = accounts.get("deployer")!; +const contractName = "aibtc-payments-invoices-pay-invoice"; +const contractAddress = `${deployer}.${contractName}`; + +const expectedErr = Cl.uint(ErrCode.ERR_RESOURCE_NOT_FOUND); + +describe(`core proposal: ${contractName}`, () => { + it("execute() fails if called directly", () => { + const receipt = simnet.callPublicFn( + contractAddress, + "execute", + [Cl.principal(deployer)], + deployer + ); + expect(receipt.result).toBeErr(expectedErr); }); }); diff --git a/tests/dao/proposals/aibtc-payments-invoices-set-payment-address.test.ts b/tests/dao/proposals/aibtc-payments-invoices-set-payment-address.test.ts index dfdaa10..facaddb 100644 --- a/tests/dao/proposals/aibtc-payments-invoices-set-payment-address.test.ts +++ b/tests/dao/proposals/aibtc-payments-invoices-set-payment-address.test.ts @@ -1,7 +1,22 @@ +import { Cl } from "@stacks/transactions"; import { describe, expect, it } from "vitest"; +import { ErrCode } from "../extensions/aibtc-payments-invoices.test"; -describe("aibtc-payments-invoices-set-payment-address", () => { - it("should have tests written", () => { - expect(true).toBe(true); +const accounts = simnet.getAccounts(); +const deployer = accounts.get("deployer")!; +const contractName = "aibtc-payments-invoices-set-payment-address"; +const contractAddress = `${deployer}.${contractName}`; + +const expectedErr = Cl.uint(ErrCode.ERR_UNAUTHORIZED); + +describe(`core proposal: ${contractName}`, () => { + it("execute() fails if called directly", () => { + const receipt = simnet.callPublicFn( + contractAddress, + "execute", + [Cl.principal(deployer)], + deployer + ); + expect(receipt.result).toBeErr(expectedErr); }); }); diff --git a/tests/dao/proposals/aibtc-payments-invoices-toggle-resource-by-name.test.ts b/tests/dao/proposals/aibtc-payments-invoices-toggle-resource-by-name.test.ts index c59f3da..52bdbcd 100644 --- a/tests/dao/proposals/aibtc-payments-invoices-toggle-resource-by-name.test.ts +++ b/tests/dao/proposals/aibtc-payments-invoices-toggle-resource-by-name.test.ts @@ -1,7 +1,22 @@ +import { Cl } from "@stacks/transactions"; import { describe, expect, it } from "vitest"; +import { ErrCode } from "../extensions/aibtc-payments-invoices.test"; -describe("aibtc-payments-invoices-toggle-resource-by-name", () => { - it("should have tests written", () => { - expect(true).toBe(true); +const accounts = simnet.getAccounts(); +const deployer = accounts.get("deployer")!; +const contractName = "aibtc-payments-invoices-toggle-resource-by-name"; +const contractAddress = `${deployer}.${contractName}`; + +const expectedErr = Cl.uint(ErrCode.ERR_RESOURCE_NOT_FOUND); + +describe(`core proposal: ${contractName}`, () => { + it("execute() fails if called directly", () => { + const receipt = simnet.callPublicFn( + contractAddress, + "execute", + [Cl.principal(deployer)], + deployer + ); + expect(receipt.result).toBeErr(expectedErr); }); }); diff --git a/tests/dao/proposals/aibtc-payments-invoices-toggle-resource.test.ts b/tests/dao/proposals/aibtc-payments-invoices-toggle-resource.test.ts index f0b5786..825899b 100644 --- a/tests/dao/proposals/aibtc-payments-invoices-toggle-resource.test.ts +++ b/tests/dao/proposals/aibtc-payments-invoices-toggle-resource.test.ts @@ -1,7 +1,22 @@ +import { Cl } from "@stacks/transactions"; import { describe, expect, it } from "vitest"; +import { ErrCode } from "../extensions/aibtc-payments-invoices.test"; -describe("aibtc-payments-invoices-toggle-resource", () => { - it("should have tests written", () => { - expect(true).toBe(true); +const accounts = simnet.getAccounts(); +const deployer = accounts.get("deployer")!; +const contractName = "aibtc-payments-invoices-toggle-resource"; +const contractAddress = `${deployer}.${contractName}`; + +const expectedErr = Cl.uint(ErrCode.ERR_RESOURCE_NOT_FOUND); + +describe(`core proposal: ${contractName}`, () => { + it("execute() fails if called directly", () => { + const receipt = simnet.callPublicFn( + contractAddress, + "execute", + [Cl.principal(deployer)], + deployer + ); + expect(receipt.result).toBeErr(expectedErr); }); }); diff --git a/tests/dao/proposals/aibtc-token-owner-set-token-uri.test.ts b/tests/dao/proposals/aibtc-token-owner-set-token-uri.test.ts index 41e6818..69fa763 100644 --- a/tests/dao/proposals/aibtc-token-owner-set-token-uri.test.ts +++ b/tests/dao/proposals/aibtc-token-owner-set-token-uri.test.ts @@ -1,7 +1,22 @@ +import { Cl } from "@stacks/transactions"; import { describe, expect, it } from "vitest"; +import { ErrCode } from "../extensions/aibtc-token-owner.test"; -describe("aibtc-token-owner-set-token-uri", () => { - it("should have tests written", () => { - expect(true).toBe(true); +const accounts = simnet.getAccounts(); +const deployer = accounts.get("deployer")!; +const contractName = "aibtc-token-owner-set-token-uri"; +const contractAddress = `${deployer}.${contractName}`; + +const expectedErr = Cl.uint(ErrCode.ERR_UNAUTHORIZED); + +describe(`core proposal: ${contractName}`, () => { + it("execute() fails if called directly", () => { + const receipt = simnet.callPublicFn( + contractAddress, + "execute", + [Cl.principal(deployer)], + deployer + ); + expect(receipt.result).toBeErr(expectedErr); }); }); diff --git a/tests/dao/proposals/aibtc-token-owner-transfer-ownership.test.ts b/tests/dao/proposals/aibtc-token-owner-transfer-ownership.test.ts index 22af3ff..47593a2 100644 --- a/tests/dao/proposals/aibtc-token-owner-transfer-ownership.test.ts +++ b/tests/dao/proposals/aibtc-token-owner-transfer-ownership.test.ts @@ -1,7 +1,22 @@ +import { Cl } from "@stacks/transactions"; import { describe, expect, it } from "vitest"; +import { ErrCode } from "../extensions/aibtc-token-owner.test"; -describe("aibtc-token-owner-transfer-ownership", () => { - it("should have tests written", () => { - expect(true).toBe(true); +const accounts = simnet.getAccounts(); +const deployer = accounts.get("deployer")!; +const contractName = "aibtc-token-owner-transfer-ownership"; +const contractAddress = `${deployer}.${contractName}`; + +const expectedErr = Cl.uint(ErrCode.ERR_UNAUTHORIZED); + +describe(`core proposal: ${contractName}`, () => { + it("execute() fails if called directly", () => { + const receipt = simnet.callPublicFn( + contractAddress, + "execute", + [Cl.principal(deployer)], + deployer + ); + expect(receipt.result).toBeErr(expectedErr); }); }); diff --git a/tests/dao/proposals/aibtc-treasury-allow-asset.test.ts b/tests/dao/proposals/aibtc-treasury-allow-asset.test.ts index 89ec4cb..4c8b0af 100644 --- a/tests/dao/proposals/aibtc-treasury-allow-asset.test.ts +++ b/tests/dao/proposals/aibtc-treasury-allow-asset.test.ts @@ -1,7 +1,22 @@ +import { Cl } from "@stacks/transactions"; import { describe, expect, it } from "vitest"; +import { ErrCode } from "../extensions/aibtc-treasury.test"; -describe("aibtc-treasury-allow-asset", () => { - it("should have tests written", () => { - expect(true).toBe(true); +const accounts = simnet.getAccounts(); +const deployer = accounts.get("deployer")!; +const contractName = "aibtc-treasury-allow-asset"; +const contractAddress = `${deployer}.${contractName}`; + +const expectedErr = Cl.uint(ErrCode.ERR_UNAUTHORIZED); + +describe(`core proposal: ${contractName}`, () => { + it("execute() fails if called directly", () => { + const receipt = simnet.callPublicFn( + contractAddress, + "execute", + [Cl.principal(deployer)], + deployer + ); + expect(receipt.result).toBeErr(expectedErr); }); }); diff --git a/tests/dao/proposals/aibtc-treasury-delegate-stx.test.ts b/tests/dao/proposals/aibtc-treasury-delegate-stx.test.ts index 26c9a16..4ffa033 100644 --- a/tests/dao/proposals/aibtc-treasury-delegate-stx.test.ts +++ b/tests/dao/proposals/aibtc-treasury-delegate-stx.test.ts @@ -1,7 +1,22 @@ +import { Cl } from "@stacks/transactions"; import { describe, expect, it } from "vitest"; +import { ErrCode } from "../extensions/aibtc-treasury.test"; -describe("aibtc-treasury-delegate-stx", () => { - it("should have tests written", () => { - expect(true).toBe(true); +const accounts = simnet.getAccounts(); +const deployer = accounts.get("deployer")!; +const contractName = "aibtc-treasury-delegate-stx"; +const contractAddress = `${deployer}.${contractName}`; + +const expectedErr = Cl.uint(ErrCode.ERR_UNAUTHORIZED); + +describe(`core proposal: ${contractName}`, () => { + it("execute() fails if called directly", () => { + const receipt = simnet.callPublicFn( + contractAddress, + "execute", + [Cl.principal(deployer)], + deployer + ); + expect(receipt.result).toBeErr(expectedErr); }); }); diff --git a/tests/dao/proposals/aibtc-treasury-deposit-ft.test.ts b/tests/dao/proposals/aibtc-treasury-deposit-ft.test.ts index d856a72..4b79c90 100644 --- a/tests/dao/proposals/aibtc-treasury-deposit-ft.test.ts +++ b/tests/dao/proposals/aibtc-treasury-deposit-ft.test.ts @@ -1,7 +1,22 @@ +import { Cl } from "@stacks/transactions"; import { describe, expect, it } from "vitest"; +import { ErrCode } from "../extensions/aibtc-treasury.test"; -describe("aibtc-treasury-deposit-ft", () => { - it("should have tests written", () => { - expect(true).toBe(true); +const accounts = simnet.getAccounts(); +const deployer = accounts.get("deployer")!; +const contractName = "aibtc-treasury-deposit-ft"; +const contractAddress = `${deployer}.${contractName}`; + +const expectedErr = Cl.uint(ErrCode.ERR_UNKNOWN_ASSSET); + +describe(`core proposal: ${contractName}`, () => { + it("execute() fails if called directly", () => { + const receipt = simnet.callPublicFn( + contractAddress, + "execute", + [Cl.principal(deployer)], + deployer + ); + expect(receipt.result).toBeErr(expectedErr); }); }); diff --git a/tests/dao/proposals/aibtc-treasury-deposit-nft.test.ts b/tests/dao/proposals/aibtc-treasury-deposit-nft.test.ts index 7c50a64..41d1725 100644 --- a/tests/dao/proposals/aibtc-treasury-deposit-nft.test.ts +++ b/tests/dao/proposals/aibtc-treasury-deposit-nft.test.ts @@ -1,7 +1,22 @@ +import { Cl } from "@stacks/transactions"; import { describe, expect, it } from "vitest"; +import { ErrCode } from "../extensions/aibtc-treasury.test"; -describe("aibtc-treasury-deposit-nft", () => { - it("should have tests written", () => { - expect(true).toBe(true); +const accounts = simnet.getAccounts(); +const deployer = accounts.get("deployer")!; +const contractName = "aibtc-treasury-deposit-nft"; +const contractAddress = `${deployer}.${contractName}`; + +const expectedErr = Cl.uint(ErrCode.ERR_UNKNOWN_ASSSET); + +describe(`core proposal: ${contractName}`, () => { + it("execute() fails if called directly", () => { + const receipt = simnet.callPublicFn( + contractAddress, + "execute", + [Cl.principal(deployer)], + deployer + ); + expect(receipt.result).toBeErr(expectedErr); }); }); diff --git a/tests/dao/proposals/aibtc-treasury-deposit-stx.test.ts b/tests/dao/proposals/aibtc-treasury-deposit-stx.test.ts index 98bf26d..605101b 100644 --- a/tests/dao/proposals/aibtc-treasury-deposit-stx.test.ts +++ b/tests/dao/proposals/aibtc-treasury-deposit-stx.test.ts @@ -1,7 +1,20 @@ +import { Cl } from "@stacks/transactions"; import { describe, expect, it } from "vitest"; +import { ErrCode } from "../extensions/aibtc-treasury.test"; -describe("aibtc-treasury-deposit-stx", () => { - it("should have tests written", () => { - expect(true).toBe(true); +const accounts = simnet.getAccounts(); +const deployer = accounts.get("deployer")!; +const contractName = "aibtc-treasury-deposit-stx"; +const contractAddress = `${deployer}.${contractName}`; + +describe(`core proposal: ${contractName}`, () => { + it("execute() succeeds if called directly (open to anyone)", () => { + const receipt = simnet.callPublicFn( + contractAddress, + "execute", + [Cl.principal(deployer)], + deployer + ); + expect(receipt.result).toBeOk(Cl.bool(true)); }); }); diff --git a/tests/dao/proposals/aibtc-treasury-freeze-asset.test.ts b/tests/dao/proposals/aibtc-treasury-freeze-asset.test.ts index 71e0773..0a4b85b 100644 --- a/tests/dao/proposals/aibtc-treasury-freeze-asset.test.ts +++ b/tests/dao/proposals/aibtc-treasury-freeze-asset.test.ts @@ -1,7 +1,22 @@ +import { Cl } from "@stacks/transactions"; import { describe, expect, it } from "vitest"; +import { ErrCode } from "../extensions/aibtc-treasury.test"; -describe("aibtc-treasury-freeze-asset", () => { - it("should have tests written", () => { - expect(true).toBe(true); +const accounts = simnet.getAccounts(); +const deployer = accounts.get("deployer")!; +const contractName = "aibtc-treasury-freeze-asset"; +const contractAddress = `${deployer}.${contractName}`; + +const expectedErr = Cl.uint(ErrCode.ERR_UNAUTHORIZED); + +describe(`core proposal: ${contractName}`, () => { + it("execute() fails if called directly", () => { + const receipt = simnet.callPublicFn( + contractAddress, + "execute", + [Cl.principal(deployer)], + deployer + ); + expect(receipt.result).toBeErr(expectedErr); }); }); diff --git a/tests/dao/proposals/aibtc-treasury-revoke-delegation.test.ts b/tests/dao/proposals/aibtc-treasury-revoke-delegation.test.ts index 1f1fabb..9f024ce 100644 --- a/tests/dao/proposals/aibtc-treasury-revoke-delegation.test.ts +++ b/tests/dao/proposals/aibtc-treasury-revoke-delegation.test.ts @@ -1,7 +1,22 @@ +import { Cl } from "@stacks/transactions"; import { describe, expect, it } from "vitest"; +import { ErrCode } from "../extensions/aibtc-treasury.test"; -describe("aibtc-treasury-revoke-delegation", () => { - it("should have tests written", () => { - expect(true).toBe(true); +const accounts = simnet.getAccounts(); +const deployer = accounts.get("deployer")!; +const contractName = "aibtc-treasury-revoke-delegation"; +const contractAddress = `${deployer}.${contractName}`; + +const expectedErr = Cl.uint(ErrCode.ERR_UNAUTHORIZED); + +describe(`core proposal: ${contractName}`, () => { + it("execute() fails if called directly", () => { + const receipt = simnet.callPublicFn( + contractAddress, + "execute", + [Cl.principal(deployer)], + deployer + ); + expect(receipt.result).toBeErr(expectedErr); }); }); diff --git a/tests/dao/proposals/aibtc-treasury-withdraw-ft.test.ts b/tests/dao/proposals/aibtc-treasury-withdraw-ft.test.ts index 49fa8a9..6e9596f 100644 --- a/tests/dao/proposals/aibtc-treasury-withdraw-ft.test.ts +++ b/tests/dao/proposals/aibtc-treasury-withdraw-ft.test.ts @@ -1,7 +1,22 @@ +import { Cl } from "@stacks/transactions"; import { describe, expect, it } from "vitest"; +import { ErrCode } from "../extensions/aibtc-treasury.test"; -describe("aibtc-treasury-withdraw-ft", () => { - it("should have tests written", () => { - expect(true).toBe(true); +const accounts = simnet.getAccounts(); +const deployer = accounts.get("deployer")!; +const contractName = "aibtc-treasury-withdraw-ft"; +const contractAddress = `${deployer}.${contractName}`; + +const expectedErr = Cl.uint(ErrCode.ERR_UNAUTHORIZED); + +describe(`core proposal: ${contractName}`, () => { + it("execute() fails if called directly", () => { + const receipt = simnet.callPublicFn( + contractAddress, + "execute", + [Cl.principal(deployer)], + deployer + ); + expect(receipt.result).toBeErr(expectedErr); }); }); diff --git a/tests/dao/proposals/aibtc-treasury-withdraw-nft.test.ts b/tests/dao/proposals/aibtc-treasury-withdraw-nft.test.ts index af5a2ed..06900d3 100644 --- a/tests/dao/proposals/aibtc-treasury-withdraw-nft.test.ts +++ b/tests/dao/proposals/aibtc-treasury-withdraw-nft.test.ts @@ -1,7 +1,22 @@ +import { Cl } from "@stacks/transactions"; import { describe, expect, it } from "vitest"; +import { ErrCode } from "../extensions/aibtc-treasury.test"; -describe("aibtc-treasury-withdraw-nft", () => { - it("should have tests written", () => { - expect(true).toBe(true); +const accounts = simnet.getAccounts(); +const deployer = accounts.get("deployer")!; +const contractName = "aibtc-treasury-withdraw-nft"; +const contractAddress = `${deployer}.${contractName}`; + +const expectedErr = Cl.uint(ErrCode.ERR_UNAUTHORIZED); + +describe(`core proposal: ${contractName}`, () => { + it("execute() fails if called directly", () => { + const receipt = simnet.callPublicFn( + contractAddress, + "execute", + [Cl.principal(deployer)], + deployer + ); + expect(receipt.result).toBeErr(expectedErr); }); }); diff --git a/tests/dao/proposals/aibtc-treasury-withdraw-stx.test.ts b/tests/dao/proposals/aibtc-treasury-withdraw-stx.test.ts index 8656231..6991473 100644 --- a/tests/dao/proposals/aibtc-treasury-withdraw-stx.test.ts +++ b/tests/dao/proposals/aibtc-treasury-withdraw-stx.test.ts @@ -1,7 +1,22 @@ +import { Cl } from "@stacks/transactions"; import { describe, expect, it } from "vitest"; +import { ErrCode } from "../extensions/aibtc-treasury.test"; -describe("aibtc-treasury-withdraw-stx", () => { - it("should have tests written", () => { - expect(true).toBe(true); +const accounts = simnet.getAccounts(); +const deployer = accounts.get("deployer")!; +const contractName = "aibtc-treasury-withdraw-stx"; +const contractAddress = `${deployer}.${contractName}`; + +const expectedErr = Cl.uint(ErrCode.ERR_UNAUTHORIZED); + +describe(`core proposal: ${contractName}`, () => { + it("execute() fails if called directly", () => { + const receipt = simnet.callPublicFn( + contractAddress, + "execute", + [Cl.principal(deployer)], + deployer + ); + expect(receipt.result).toBeErr(expectedErr); }); }); From 54c4c1dbe08cdbba9d719c1ca0b3917d5da2b91c Mon Sep 17 00:00:00 2001 From: Jason Schrader Date: Tue, 14 Jan 2025 16:48:05 -0700 Subject: [PATCH 03/19] feat: start work on generic helpers to test proposals One challenge with this structure if we have to instantiate the dao before running every test. These helper methods should allow us to meet all the criteria to pass proposals and test their result, and we can verify other values along the way. --- .../aibtc-onchain-messaging.test.ts | 77 ++++++++- tests/test-utilities.ts | 150 ++++++++++++++++++ 2 files changed, 225 insertions(+), 2 deletions(-) diff --git a/tests/dao/extensions/aibtc-onchain-messaging.test.ts b/tests/dao/extensions/aibtc-onchain-messaging.test.ts index 0e667f8..291ed93 100644 --- a/tests/dao/extensions/aibtc-onchain-messaging.test.ts +++ b/tests/dao/extensions/aibtc-onchain-messaging.test.ts @@ -1,9 +1,13 @@ -import { Cl } from "@stacks/transactions"; +import { Cl, cvToValue } from "@stacks/transactions"; import { describe, expect, it } from "vitest"; +import { + constructDao, + getDaoTokens, + passCoreProposal, +} from "../../test-utilities"; const accounts = simnet.getAccounts(); const address1 = accounts.get("wallet_1")!; -const address2 = accounts.get("wallet_2")!; const deployer = accounts.get("deployer")!; const contractName = "aibtc-onchain-messaging"; @@ -24,6 +28,75 @@ describe(`extension: ${contractName}`, () => { ); expect(callback.result).toBeOk(Cl.bool(true)); }); + + it("send() succeeds if called by any user with isFromDao false", () => { + const message = "test"; + const receipt = simnet.callPublicFn( + contractAddress, + "send", + [Cl.stringAscii(message), Cl.bool(false)], + address1 + ); + expect(receipt.result).toBeOk(Cl.bool(true)); + }); + + it("send() fails if called by any user with isFromDao true", () => { + const message = "test"; + const receipt = simnet.callPublicFn( + contractAddress, + "send", + [Cl.stringAscii(message), Cl.bool(true)], + address1 + ); + expect(receipt.result).toBeErr(Cl.uint(ErrCode.ERR_UNAUTHORIZED)); + }); + + it("send() succeeds if called by a DAO proposal with isFromDao true", () => { + const proposalContractName = "aibtc-onchain-messaging-send"; + const proposalContractAddress = `${deployer}.${proposalContractName}`; + const message = "test"; + + // fund account that sends proposal + const getDaoTokensReceipt = getDaoTokens(deployer, deployer); + + console.log("getDaoTokensReceipt"); + console.log(getDaoTokensReceipt); + + // construct DAO + const constructReceipt = constructDao(deployer); + + console.log("constructReceipt"); + console.log(constructReceipt); + + // pass proposal + const proposalReceipt = passCoreProposal(proposalContractAddress, deployer); + + console.log("proposalReceipt"); + console.log(proposalReceipt); + + const votingPowerReceipt = simnet.callReadOnlyFn( + `${deployer}.aibtc-core-proposals`, + "get-voting-power", + [Cl.principal(deployer), Cl.principal(proposalContractAddress)], + deployer + ); + + console.log("votingPowerReceipt"); + console.log(cvToValue(votingPowerReceipt.result)); + + const addressBalanceReceipt = simnet.callReadOnlyFn( + `${deployer}.aibtc-token`, + "get-balance", + [Cl.principal(deployer)], + deployer + ); + + console.log("addressBalanceReceipt"); + console.log(cvToValue(addressBalanceReceipt.result)); + + expect(proposalReceipt.result).toBeOk(Cl.bool(true)); + }); + /* // Message Tests describe("send()", () => { diff --git a/tests/test-utilities.ts b/tests/test-utilities.ts index e69de29..9f0b004 100644 --- a/tests/test-utilities.ts +++ b/tests/test-utilities.ts @@ -0,0 +1,150 @@ +import { Cl, cvToValue } from "@stacks/transactions"; + +export const actionProposalsContractName = "aibtc-action-proposals"; +export const coreProposalsContractName = "aibtc-core-proposals"; + +export function getDaoTokens(deployer: string, address: string) { + const tokenContractName = "aibtc-token"; + const tokenContractAddress = `${deployer}.${tokenContractName}`; + const tokenDexContractName = "aibtc-token-dex"; + const tokenDexContractAddress = `${deployer}.${tokenDexContractName}`; + const tokenTreasuryContractName = "aibtc-treasury"; + const treasuryContractAddress = `${deployer}.${tokenTreasuryContractName}`; + + const getTotalSupplyReceipt = simnet.callReadOnlyFn( + tokenContractAddress, + "get-total-supply", + [], + deployer + ); + const totalSupply = cvToValue(getTotalSupplyReceipt.result); + + const getTreasuryBalanceReceipt = simnet.callReadOnlyFn( + tokenContractAddress, + "get-balance", + [Cl.principal(treasuryContractAddress)], + deployer + ); + const treasuryBalance = cvToValue(getTreasuryBalanceReceipt.result); + + const getTokenDexBalanceReceipt = simnet.callReadOnlyFn( + tokenContractAddress, + "get-balance", + [Cl.principal(tokenDexContractAddress)], + deployer + ); + const tokenDexBalance = cvToValue(getTokenDexBalanceReceipt.result); + + const liquidTokenSupply = + parseInt(totalSupply.value) - + parseInt(treasuryBalance.value) - + parseInt(tokenDexBalance.value); + + console.log("BEFORE BUY"); + console.log("totalSupply", totalSupply); + console.log("treasuryBalance", treasuryBalance); + console.log("tokenDexBalance", tokenDexBalance); + console.log("liquidTokenSupply", liquidTokenSupply); + + const getDaoTokensReceipt = simnet.callPublicFn( + tokenDexContractAddress, + "buy", + [Cl.principal(tokenContractAddress), Cl.uint(1000000000)], // 1000 STX buy test + address + ); + + const getTreasuryBalanceReceipt2 = simnet.callReadOnlyFn( + tokenContractAddress, + "get-balance", + [Cl.principal(treasuryContractAddress)], + deployer + ); + + const getTokenDexBalanceReceipt2 = simnet.callReadOnlyFn( + tokenContractAddress, + "get-balance", + [Cl.principal(tokenDexContractAddress)], + deployer + ); + + const getTotalSupplyReceipt2 = simnet.callReadOnlyFn( + tokenContractAddress, + "get-total-supply", + [], + deployer + ); + + const addressBalanceReceipt = simnet.callReadOnlyFn( + tokenContractAddress, + "get-balance", + [Cl.principal(address)], + deployer + ); + + const totalSupply2 = cvToValue(getTotalSupplyReceipt2.result); + const treasuryBalance2 = cvToValue(getTreasuryBalanceReceipt2.result); + const tokenDexBalance2 = cvToValue(getTokenDexBalanceReceipt2.result); + + const liquidTokenSupply2 = + parseInt(totalSupply2.value) - + parseInt(treasuryBalance2.value) - + parseInt(tokenDexBalance2.value); + + console.log("AFTER BUY"); + console.log("totalSupply2", totalSupply2); + console.log("treasuryBalance2", treasuryBalance2); + console.log("tokenDexBalance2", tokenDexBalance2); + console.log("liquidTokenSupply2", liquidTokenSupply2); + + const addressBalance = cvToValue(addressBalanceReceipt.result); + const addressVotingPower = + parseInt(addressBalance.value) / parseInt(totalSupply2.value); + + console.log("ADDRESS INFO"); + console.log("addressBalance", addressBalance); + console.log("addressBalance voting power", addressVotingPower); + + return getDaoTokensReceipt; +} + +export function constructDao(deployer: string) { + const baseDaoContractName = "aibtcdev-base-dao"; + const baseDaoContractAddress = `${deployer}.${baseDaoContractName}`; + const bootstrapContractName = "aibtc-base-bootstrap-initialization"; + const bootstrapContractAddress = `${deployer}.${bootstrapContractName}`; + + const constructDaoReceipt = simnet.callPublicFn( + baseDaoContractAddress, + "construct", + [Cl.principal(bootstrapContractAddress)], + deployer + ); + + return constructDaoReceipt; +} + +export function passCoreProposal( + proposalContractAddress: string, + deployer: string +) { + // create-proposal + const createProposalReceipt = simnet.callPublicFn( + `${deployer}.${coreProposalsContractName}`, + "create-proposal", + [Cl.principal(proposalContractAddress)], + deployer + ); + // temporary + return createProposalReceipt; + // vote-on-proposal + // conclude-proposal +} + +export function passActionProposal( + proposalContractAddress: string, + sender: string +) { + // propose-action + // vote-on-proposal + // conclude-propsal +} From 85cfe9de944196063f63781ec3be3ab26e3aeb07 Mon Sep 17 00:00:00 2001 From: Jason Schrader Date: Tue, 14 Jan 2025 17:18:27 -0700 Subject: [PATCH 04/19] debug: add logging because at-block get-balance returns 0 --- .../dao/extensions/aibtc-core-proposals.clar | 10 +- .../aibtc-onchain-messaging.test.ts | 24 ++++- tests/test-utilities.ts | 99 ++++++++++++++----- 3 files changed, 103 insertions(+), 30 deletions(-) diff --git a/contracts/dao/extensions/aibtc-core-proposals.clar b/contracts/dao/extensions/aibtc-core-proposals.clar index 6418b48..9183c2e 100644 --- a/contracts/dao/extensions/aibtc-core-proposals.clar +++ b/contracts/dao/extensions/aibtc-core-proposals.clar @@ -46,8 +46,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 @@ -97,6 +98,7 @@ createdAt: burn-block-height, caller: contract-caller, creator: tx-sender, + startBlockStx: block-height, startBlock: burn-block-height, endBlock: (+ burn-block-height VOTING_PERIOD), votesFor: u0, @@ -112,7 +114,7 @@ ( (proposalContract (contract-of proposal)) (proposalRecord (unwrap! (map-get? Proposals proposalContract) ERR_PROPOSAL_NOT_FOUND)) - (proposalBlock (get startBlock proposalRecord)) + (proposalBlock (get startBlockStx proposalRecord)) (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)) @@ -194,7 +196,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)) ) (at-block proposalBlockHash (contract-call? .aibtc-token get-balance who)) ) diff --git a/tests/dao/extensions/aibtc-onchain-messaging.test.ts b/tests/dao/extensions/aibtc-onchain-messaging.test.ts index 291ed93..39764b3 100644 --- a/tests/dao/extensions/aibtc-onchain-messaging.test.ts +++ b/tests/dao/extensions/aibtc-onchain-messaging.test.ts @@ -74,6 +74,18 @@ describe(`extension: ${contractName}`, () => { console.log("proposalReceipt"); console.log(proposalReceipt); + const proposalDetails = simnet.callReadOnlyFn( + `${deployer}.aibtc-core-proposals`, + "get-proposal", + [Cl.principal(proposalContractAddress)], + deployer + ); + + console.log("proposalDetails"); + console.log(cvToValue(proposalDetails.result)); + + simnet.mineEmptyBlocks(100); + const votingPowerReceipt = simnet.callReadOnlyFn( `${deployer}.aibtc-core-proposals`, "get-voting-power", @@ -94,7 +106,17 @@ describe(`extension: ${contractName}`, () => { console.log("addressBalanceReceipt"); console.log(cvToValue(addressBalanceReceipt.result)); - expect(proposalReceipt.result).toBeOk(Cl.bool(true)); + const voteReceipt = simnet.callPublicFn( + `${deployer}.aibtc-core-proposals`, + "vote-on-proposal", + [Cl.principal(proposalContractAddress), Cl.bool(true)], + deployer + ); + + console.log("voteReceipt"); + console.log(voteReceipt); + + expect(voteReceipt.result).toBeOk(Cl.bool(true)); }); /* diff --git a/tests/test-utilities.ts b/tests/test-utilities.ts index 9f0b004..8c362ed 100644 --- a/tests/test-utilities.ts +++ b/tests/test-utilities.ts @@ -3,6 +3,12 @@ import { Cl, cvToValue } from "@stacks/transactions"; export const actionProposalsContractName = "aibtc-action-proposals"; export const coreProposalsContractName = "aibtc-core-proposals"; +function getPercentageOfSupply(amount: number, totalSupply: number) { + const rawPercentage = (amount / totalSupply) * 100; + const percentage = rawPercentage.toFixed(2); + return `${percentage}% supply`; +} + export function getDaoTokens(deployer: string, address: string) { const tokenContractName = "aibtc-token"; const tokenContractAddress = `${deployer}.${tokenContractName}`; @@ -17,7 +23,7 @@ export function getDaoTokens(deployer: string, address: string) { [], deployer ); - const totalSupply = cvToValue(getTotalSupplyReceipt.result); + const totalSupply = parseInt(cvToValue(getTotalSupplyReceipt.result).value); const getTreasuryBalanceReceipt = simnet.callReadOnlyFn( tokenContractAddress, @@ -25,7 +31,9 @@ export function getDaoTokens(deployer: string, address: string) { [Cl.principal(treasuryContractAddress)], deployer ); - const treasuryBalance = cvToValue(getTreasuryBalanceReceipt.result); + const treasuryBalance = parseInt( + cvToValue(getTreasuryBalanceReceipt.result).value + ); const getTokenDexBalanceReceipt = simnet.callReadOnlyFn( tokenContractAddress, @@ -33,18 +41,30 @@ export function getDaoTokens(deployer: string, address: string) { [Cl.principal(tokenDexContractAddress)], deployer ); - const tokenDexBalance = cvToValue(getTokenDexBalanceReceipt.result); + const tokenDexBalance = parseInt( + cvToValue(getTokenDexBalanceReceipt.result).value + ); - const liquidTokenSupply = - parseInt(totalSupply.value) - - parseInt(treasuryBalance.value) - - parseInt(tokenDexBalance.value); + const liquidTokenSupply = totalSupply - treasuryBalance - tokenDexBalance; console.log("BEFORE BUY"); + console.log("========================="); console.log("totalSupply", totalSupply); - console.log("treasuryBalance", treasuryBalance); - console.log("tokenDexBalance", tokenDexBalance); - console.log("liquidTokenSupply", liquidTokenSupply); + console.log( + "treasuryBalance", + treasuryBalance, + getPercentageOfSupply(treasuryBalance, totalSupply) + ); + console.log( + "tokenDexBalance", + tokenDexBalance, + getPercentageOfSupply(tokenDexBalance, totalSupply) + ); + console.log( + "liquidTokenSupply", + liquidTokenSupply, + getPercentageOfSupply(liquidTokenSupply, totalSupply) + ); const getDaoTokensReceipt = simnet.callPublicFn( tokenDexContractAddress, @@ -81,28 +101,57 @@ export function getDaoTokens(deployer: string, address: string) { deployer ); - const totalSupply2 = cvToValue(getTotalSupplyReceipt2.result); - const treasuryBalance2 = cvToValue(getTreasuryBalanceReceipt2.result); - const tokenDexBalance2 = cvToValue(getTokenDexBalanceReceipt2.result); + const totalSupply2 = parseInt(cvToValue(getTotalSupplyReceipt2.result).value); + const treasuryBalance2 = parseInt( + cvToValue(getTreasuryBalanceReceipt2.result).value + ); + const tokenDexBalance2 = parseInt( + cvToValue(getTokenDexBalanceReceipt2.result).value + ); - const liquidTokenSupply2 = - parseInt(totalSupply2.value) - - parseInt(treasuryBalance2.value) - - parseInt(tokenDexBalance2.value); + const liquidTokenSupply2 = totalSupply2 - treasuryBalance2 - tokenDexBalance2; console.log("AFTER BUY"); + console.log("========================="); console.log("totalSupply2", totalSupply2); - console.log("treasuryBalance2", treasuryBalance2); - console.log("tokenDexBalance2", tokenDexBalance2); - console.log("liquidTokenSupply2", liquidTokenSupply2); + console.log( + "treasuryBalance2", + treasuryBalance2, + getPercentageOfSupply(treasuryBalance2, totalSupply2) + ); + console.log( + "tokenDexBalance2", + tokenDexBalance2, + getPercentageOfSupply(tokenDexBalance2, totalSupply2) + ); + console.log( + "liquidTokenSupply2", + liquidTokenSupply2, + getPercentageOfSupply(liquidTokenSupply2, totalSupply2) + ); - const addressBalance = cvToValue(addressBalanceReceipt.result); - const addressVotingPower = - parseInt(addressBalance.value) / parseInt(totalSupply2.value); + const addressBalance = parseInt( + cvToValue(addressBalanceReceipt.result).value + ); + const addressVotingPower = addressBalance / liquidTokenSupply2; console.log("ADDRESS INFO"); - console.log("addressBalance", addressBalance); - console.log("addressBalance voting power", addressVotingPower); + console.log("========================="); + console.log( + "addressBalance", + addressBalance, + getPercentageOfSupply(addressBalance, totalSupply2) + ); + console.log( + "addressBalance voting power calculated", + addressVotingPower, + getPercentageOfSupply(addressBalance, liquidTokenSupply2) + ); + + /* + ;; if VOTING_QUORUM <= ((votesFor * 100) / liquidTokens) + (votePassed (<= VOTING_QUORUM (/ (* (get votesFor proposalRecord) u100) (get liquidTokens proposalRecord)))) + */ return getDaoTokensReceipt; } From b97e29919ce3625b151a3867d9b27647f68542ec Mon Sep 17 00:00:00 2001 From: Jason Schrader Date: Tue, 14 Jan 2025 18:10:55 -0700 Subject: [PATCH 05/19] fix: progress chain before at-block Haven't narrowed down the exact bug but can continue making the generalized proposal functions now that flow is confirmed. --- .../aibtc-onchain-messaging.test.ts | 37 +++++++++++-------- tests/test-utilities.ts | 15 +++++--- 2 files changed, 32 insertions(+), 20 deletions(-) diff --git a/tests/dao/extensions/aibtc-onchain-messaging.test.ts b/tests/dao/extensions/aibtc-onchain-messaging.test.ts index 39764b3..1cb6497 100644 --- a/tests/dao/extensions/aibtc-onchain-messaging.test.ts +++ b/tests/dao/extensions/aibtc-onchain-messaging.test.ts @@ -7,8 +7,9 @@ import { } from "../../test-utilities"; const accounts = simnet.getAccounts(); -const address1 = accounts.get("wallet_1")!; const deployer = accounts.get("deployer")!; +const address1 = accounts.get("wallet_1")!; +const address2 = accounts.get("wallet_2")!; const contractName = "aibtc-onchain-messaging"; const contractAddress = `${deployer}.${contractName}`; @@ -57,20 +58,31 @@ describe(`extension: ${contractName}`, () => { const message = "test"; // fund account that sends proposal - const getDaoTokensReceipt = getDaoTokens(deployer, deployer); - - console.log("getDaoTokensReceipt"); - console.log(getDaoTokensReceipt); + const getDaoTokensReceipts = [ + getDaoTokens(deployer, deployer, 1000000000), // 1000 STX + getDaoTokens(deployer, address1, 500000000), // 500 STX + getDaoTokens(deployer, address2, 250000000), // 250 STX + ]; + + console.log("==========================="); + console.log("getDaoTokensReceipts"); + for (const receipt of getDaoTokensReceipts) { + console.log(receipt); + } // construct DAO const constructReceipt = constructDao(deployer); + console.log("==========================="); console.log("constructReceipt"); console.log(constructReceipt); + simnet.mineEmptyBlocks(10); + // pass proposal const proposalReceipt = passCoreProposal(proposalContractAddress, deployer); + console.log("==========================="); console.log("proposalReceipt"); console.log(proposalReceipt); @@ -81,8 +93,9 @@ describe(`extension: ${contractName}`, () => { deployer ); + console.log("==========================="); console.log("proposalDetails"); - console.log(cvToValue(proposalDetails.result)); + console.log(cvToValue(proposalDetails.result).value); simnet.mineEmptyBlocks(100); @@ -93,6 +106,7 @@ describe(`extension: ${contractName}`, () => { deployer ); + console.log("==========================="); console.log("votingPowerReceipt"); console.log(cvToValue(votingPowerReceipt.result)); @@ -103,6 +117,7 @@ describe(`extension: ${contractName}`, () => { deployer ); + console.log("==========================="); console.log("addressBalanceReceipt"); console.log(cvToValue(addressBalanceReceipt.result)); @@ -113,18 +128,10 @@ describe(`extension: ${contractName}`, () => { deployer ); + console.log("==========================="); console.log("voteReceipt"); console.log(voteReceipt); expect(voteReceipt.result).toBeOk(Cl.bool(true)); }); - - /* - // Message Tests - describe("send()", () => { - it("succeeds if called by any user with isFromDao false"); - it("fails if called by any user with isFromDao true"); - it("succeeds if called by a DAO proposal with isFromDao true"); - }); - */ }); diff --git a/tests/test-utilities.ts b/tests/test-utilities.ts index 8c362ed..938e084 100644 --- a/tests/test-utilities.ts +++ b/tests/test-utilities.ts @@ -9,7 +9,11 @@ function getPercentageOfSupply(amount: number, totalSupply: number) { return `${percentage}% supply`; } -export function getDaoTokens(deployer: string, address: string) { +export function getDaoTokens( + deployer: string, + address: string, + stxAmount: number +) { const tokenContractName = "aibtc-token"; const tokenContractAddress = `${deployer}.${tokenContractName}`; const tokenDexContractName = "aibtc-token-dex"; @@ -47,8 +51,8 @@ export function getDaoTokens(deployer: string, address: string) { const liquidTokenSupply = totalSupply - treasuryBalance - tokenDexBalance; - console.log("BEFORE BUY"); console.log("========================="); + console.log("BEFORE BUY"); console.log("totalSupply", totalSupply); console.log( "treasuryBalance", @@ -69,7 +73,7 @@ export function getDaoTokens(deployer: string, address: string) { const getDaoTokensReceipt = simnet.callPublicFn( tokenDexContractAddress, "buy", - [Cl.principal(tokenContractAddress), Cl.uint(1000000000)], // 1000 STX buy test + [Cl.principal(tokenContractAddress), Cl.uint(stxAmount)], // 1000 STX buy test address ); @@ -111,8 +115,8 @@ export function getDaoTokens(deployer: string, address: string) { const liquidTokenSupply2 = totalSupply2 - treasuryBalance2 - tokenDexBalance2; - console.log("AFTER BUY"); console.log("========================="); + console.log("AFTER BUY"); console.log("totalSupply2", totalSupply2); console.log( "treasuryBalance2", @@ -135,8 +139,8 @@ export function getDaoTokens(deployer: string, address: string) { ); const addressVotingPower = addressBalance / liquidTokenSupply2; - console.log("ADDRESS INFO"); console.log("========================="); + console.log("ADDRESS INFO"); console.log( "addressBalance", addressBalance, @@ -175,6 +179,7 @@ export function constructDao(deployer: string) { export function passCoreProposal( proposalContractAddress: string, deployer: string + // voters: string[] ) { // create-proposal const createProposalReceipt = simnet.callPublicFn( From 509f7c5d61030de52122963cf858ae7b6ec6f636 Mon Sep 17 00:00:00 2001 From: Jason Schrader Date: Tue, 14 Jan 2025 18:36:23 -0700 Subject: [PATCH 06/19] fix: continue with core proposal testing --- .../aibtc-onchain-messaging.test.ts | 96 +++++----- tests/test-utilities.ts | 165 +++--------------- 2 files changed, 75 insertions(+), 186 deletions(-) diff --git a/tests/dao/extensions/aibtc-onchain-messaging.test.ts b/tests/dao/extensions/aibtc-onchain-messaging.test.ts index 1cb6497..8409b0f 100644 --- a/tests/dao/extensions/aibtc-onchain-messaging.test.ts +++ b/tests/dao/extensions/aibtc-onchain-messaging.test.ts @@ -55,7 +55,6 @@ describe(`extension: ${contractName}`, () => { it("send() succeeds if called by a DAO proposal with isFromDao true", () => { const proposalContractName = "aibtc-onchain-messaging-send"; const proposalContractAddress = `${deployer}.${proposalContractName}`; - const message = "test"; // fund account that sends proposal const getDaoTokensReceipts = [ @@ -63,28 +62,62 @@ describe(`extension: ${contractName}`, () => { getDaoTokens(deployer, address1, 500000000), // 500 STX getDaoTokens(deployer, address2, 250000000), // 250 STX ]; - - console.log("==========================="); - console.log("getDaoTokensReceipts"); - for (const receipt of getDaoTokensReceipts) { - console.log(receipt); + const getAddressBalances = [ + simnet.callReadOnlyFn( + `${deployer}.aibtc-token`, + "get-balance", + [Cl.principal(deployer)], + deployer + ), + simnet.callReadOnlyFn( + `${deployer}.aibtc-token`, + "get-balance", + [Cl.principal(address1)], + deployer + ), + simnet.callReadOnlyFn( + `${deployer}.aibtc-token`, + "get-balance", + [Cl.principal(address2)], + deployer + ), + ]; + for (let i = 0; i < getDaoTokensReceipts.length; i++) { + const expectedBalance = parseInt( + cvToValue(getAddressBalances[i].result).value + ); + console.log(`expectedBalance: ${expectedBalance}`); + expect(getDaoTokensReceipts[i].result).toBeOk(Cl.uint(expectedBalance)); } // construct DAO const constructReceipt = constructDao(deployer); + expect(constructReceipt.result).toBeOk(Cl.bool(true)); - console.log("==========================="); - console.log("constructReceipt"); - console.log(constructReceipt); - + // progres the chain for at-block calls simnet.mineEmptyBlocks(10); // pass proposal - const proposalReceipt = passCoreProposal(proposalContractAddress, deployer); + const concludeProposalReceipt = passCoreProposal( + proposalContractAddress, + deployer, + [deployer, address1, address2] + ); console.log("==========================="); - console.log("proposalReceipt"); - console.log(proposalReceipt); + console.log("concludeProposalReceipt"); + console.log(concludeProposalReceipt); + for (const event of concludeProposalReceipt.events) { + const eventValue = cvToValue(event.data.value!); + // if event value is an object stringify it + console.log( + `- event: ${ + typeof eventValue === "object" + ? JSON.stringify(eventValue) + : eventValue + }` + ); + } const proposalDetails = simnet.callReadOnlyFn( `${deployer}.aibtc-core-proposals`, @@ -97,41 +130,6 @@ describe(`extension: ${contractName}`, () => { console.log("proposalDetails"); console.log(cvToValue(proposalDetails.result).value); - simnet.mineEmptyBlocks(100); - - const votingPowerReceipt = simnet.callReadOnlyFn( - `${deployer}.aibtc-core-proposals`, - "get-voting-power", - [Cl.principal(deployer), Cl.principal(proposalContractAddress)], - deployer - ); - - console.log("==========================="); - console.log("votingPowerReceipt"); - console.log(cvToValue(votingPowerReceipt.result)); - - const addressBalanceReceipt = simnet.callReadOnlyFn( - `${deployer}.aibtc-token`, - "get-balance", - [Cl.principal(deployer)], - deployer - ); - - console.log("==========================="); - console.log("addressBalanceReceipt"); - console.log(cvToValue(addressBalanceReceipt.result)); - - const voteReceipt = simnet.callPublicFn( - `${deployer}.aibtc-core-proposals`, - "vote-on-proposal", - [Cl.principal(proposalContractAddress), Cl.bool(true)], - deployer - ); - - console.log("==========================="); - console.log("voteReceipt"); - console.log(voteReceipt); - - expect(voteReceipt.result).toBeOk(Cl.bool(true)); + expect(concludeProposalReceipt.result).toBeOk(Cl.bool(true)); }); }); diff --git a/tests/test-utilities.ts b/tests/test-utilities.ts index 938e084..8174f61 100644 --- a/tests/test-utilities.ts +++ b/tests/test-utilities.ts @@ -1,12 +1,14 @@ -import { Cl, cvToValue } from "@stacks/transactions"; +import { Cl } from "@stacks/transactions"; +import { expect } from "vitest"; export const actionProposalsContractName = "aibtc-action-proposals"; export const coreProposalsContractName = "aibtc-core-proposals"; +const votingPeriod = 144; // 24 hours function getPercentageOfSupply(amount: number, totalSupply: number) { const rawPercentage = (amount / totalSupply) * 100; const percentage = rawPercentage.toFixed(2); - return `${percentage}% supply`; + return percentage; } export function getDaoTokens( @@ -18,57 +20,6 @@ export function getDaoTokens( const tokenContractAddress = `${deployer}.${tokenContractName}`; const tokenDexContractName = "aibtc-token-dex"; const tokenDexContractAddress = `${deployer}.${tokenDexContractName}`; - const tokenTreasuryContractName = "aibtc-treasury"; - const treasuryContractAddress = `${deployer}.${tokenTreasuryContractName}`; - - const getTotalSupplyReceipt = simnet.callReadOnlyFn( - tokenContractAddress, - "get-total-supply", - [], - deployer - ); - const totalSupply = parseInt(cvToValue(getTotalSupplyReceipt.result).value); - - const getTreasuryBalanceReceipt = simnet.callReadOnlyFn( - tokenContractAddress, - "get-balance", - [Cl.principal(treasuryContractAddress)], - deployer - ); - const treasuryBalance = parseInt( - cvToValue(getTreasuryBalanceReceipt.result).value - ); - - const getTokenDexBalanceReceipt = simnet.callReadOnlyFn( - tokenContractAddress, - "get-balance", - [Cl.principal(tokenDexContractAddress)], - deployer - ); - const tokenDexBalance = parseInt( - cvToValue(getTokenDexBalanceReceipt.result).value - ); - - const liquidTokenSupply = totalSupply - treasuryBalance - tokenDexBalance; - - console.log("========================="); - console.log("BEFORE BUY"); - console.log("totalSupply", totalSupply); - console.log( - "treasuryBalance", - treasuryBalance, - getPercentageOfSupply(treasuryBalance, totalSupply) - ); - console.log( - "tokenDexBalance", - tokenDexBalance, - getPercentageOfSupply(tokenDexBalance, totalSupply) - ); - console.log( - "liquidTokenSupply", - liquidTokenSupply, - getPercentageOfSupply(liquidTokenSupply, totalSupply) - ); const getDaoTokensReceipt = simnet.callPublicFn( tokenDexContractAddress, @@ -77,86 +28,6 @@ export function getDaoTokens( address ); - const getTreasuryBalanceReceipt2 = simnet.callReadOnlyFn( - tokenContractAddress, - "get-balance", - [Cl.principal(treasuryContractAddress)], - deployer - ); - - const getTokenDexBalanceReceipt2 = simnet.callReadOnlyFn( - tokenContractAddress, - "get-balance", - [Cl.principal(tokenDexContractAddress)], - deployer - ); - - const getTotalSupplyReceipt2 = simnet.callReadOnlyFn( - tokenContractAddress, - "get-total-supply", - [], - deployer - ); - - const addressBalanceReceipt = simnet.callReadOnlyFn( - tokenContractAddress, - "get-balance", - [Cl.principal(address)], - deployer - ); - - const totalSupply2 = parseInt(cvToValue(getTotalSupplyReceipt2.result).value); - const treasuryBalance2 = parseInt( - cvToValue(getTreasuryBalanceReceipt2.result).value - ); - const tokenDexBalance2 = parseInt( - cvToValue(getTokenDexBalanceReceipt2.result).value - ); - - const liquidTokenSupply2 = totalSupply2 - treasuryBalance2 - tokenDexBalance2; - - console.log("========================="); - console.log("AFTER BUY"); - console.log("totalSupply2", totalSupply2); - console.log( - "treasuryBalance2", - treasuryBalance2, - getPercentageOfSupply(treasuryBalance2, totalSupply2) - ); - console.log( - "tokenDexBalance2", - tokenDexBalance2, - getPercentageOfSupply(tokenDexBalance2, totalSupply2) - ); - console.log( - "liquidTokenSupply2", - liquidTokenSupply2, - getPercentageOfSupply(liquidTokenSupply2, totalSupply2) - ); - - const addressBalance = parseInt( - cvToValue(addressBalanceReceipt.result).value - ); - const addressVotingPower = addressBalance / liquidTokenSupply2; - - console.log("========================="); - console.log("ADDRESS INFO"); - console.log( - "addressBalance", - addressBalance, - getPercentageOfSupply(addressBalance, totalSupply2) - ); - console.log( - "addressBalance voting power calculated", - addressVotingPower, - getPercentageOfSupply(addressBalance, liquidTokenSupply2) - ); - - /* - ;; if VOTING_QUORUM <= ((votesFor * 100) / liquidTokens) - (votePassed (<= VOTING_QUORUM (/ (* (get votesFor proposalRecord) u100) (get liquidTokens proposalRecord)))) - */ - return getDaoTokensReceipt; } @@ -178,8 +49,8 @@ export function constructDao(deployer: string) { export function passCoreProposal( proposalContractAddress: string, - deployer: string - // voters: string[] + deployer: string, + voters: string[] ) { // create-proposal const createProposalReceipt = simnet.callPublicFn( @@ -188,10 +59,30 @@ export function passCoreProposal( [Cl.principal(proposalContractAddress)], deployer ); - // temporary - return createProposalReceipt; + expect(createProposalReceipt.result).toBeOk(Cl.bool(true)); // vote-on-proposal + for (const voter of voters) { + const voteReceipt = simnet.callPublicFn( + `${deployer}.${coreProposalsContractName}`, + "vote-on-proposal", + [Cl.principal(proposalContractAddress), Cl.bool(true)], + voter + ); + console.log(`voteReceipt: ${voter}`); + console.log(voteReceipt.result); + expect(voteReceipt.result).toBeOk(Cl.bool(true)); + } + // progress past the end block + simnet.mineEmptyBlocks(votingPeriod); // conclude-proposal + const concludeProposalReceipt = simnet.callPublicFn( + `${deployer}.${coreProposalsContractName}`, + "conclude-proposal", + [Cl.principal(proposalContractAddress)], + deployer + ); + // return final receipt for processing + return concludeProposalReceipt; } export function passActionProposal( From 05b460f479a1ce4b8548929fa7d44cd20200b05a Mon Sep 17 00:00:00 2001 From: Jason Schrader Date: Tue, 14 Jan 2025 22:04:22 -0700 Subject: [PATCH 07/19] feat: start applying core logic to action proposals --- .../actions/aibtc-action-send-message.test.ts | 99 ++++++++++++++++++- .../aibtc-onchain-messaging.test.ts | 4 +- tests/test-utilities.ts | 32 +++++- 3 files changed, 128 insertions(+), 7 deletions(-) diff --git a/tests/dao/extensions/actions/aibtc-action-send-message.test.ts b/tests/dao/extensions/actions/aibtc-action-send-message.test.ts index 1178c17..a34ba25 100644 --- a/tests/dao/extensions/actions/aibtc-action-send-message.test.ts +++ b/tests/dao/extensions/actions/aibtc-action-send-message.test.ts @@ -1,8 +1,16 @@ -import { Cl } from "@stacks/transactions"; +import { Cl, cvToValue } from "@stacks/transactions"; import { describe, expect, it } from "vitest"; +import { + actionProposalsContractName, + constructDao, + getDaoTokens, + passActionProposal, +} from "../../../test-utilities"; const accounts = simnet.getAccounts(); const deployer = accounts.get("deployer")!; +const address1 = accounts.get("address1")!; +const address2 = accounts.get("address2")!; const contractName = "aibtc-action-send-message"; const contractAddress = `${deployer}.${contractName}`; @@ -17,4 +25,93 @@ describe(`action extension: ${contractName}`, () => { ); expect(callback.result).toBeOk(Cl.bool(true)); }); + + it("run() fails if called directly", () => { + const receipt = simnet.callPublicFn( + contractAddress, + "run", + [Cl.principal(deployer)], + deployer + ); + expect(receipt.result).toBeErr(Cl.uint(0)); + }); + + it("run() succeeds if called as a DAO action proposal", () => { + // fund accounts for creating and voting on proposals + const getDaoTokensReceipts = [ + getDaoTokens(deployer, deployer, 1000000000), // 1000 STX + getDaoTokens(deployer, address1, 500000000), // 500 STX + getDaoTokens(deployer, address2, 250000000), // 250 STX + ]; + const getAddressBalances = [ + simnet.callReadOnlyFn( + `${deployer}.aibtc-token`, + "get-balance", + [Cl.principal(deployer)], + deployer + ), + simnet.callReadOnlyFn( + `${deployer}.aibtc-token`, + "get-balance", + [Cl.principal(address1)], + deployer + ), + simnet.callReadOnlyFn( + `${deployer}.aibtc-token`, + "get-balance", + [Cl.principal(address2)], + deployer + ), + ]; + for (let i = 0; i < getDaoTokensReceipts.length; i++) { + const expectedBalance = parseInt( + cvToValue(getAddressBalances[i].result).value + ); + console.log(`expectedBalance: ${expectedBalance}`); + expect(getDaoTokensReceipts[i].result).toBeOk(Cl.uint(expectedBalance)); + } + + // construct DAO + const constructReceipt = constructDao(deployer); + expect(constructReceipt.result).toBeOk(Cl.bool(true)); + + // progress the chain for at-block calls + simnet.mineEmptyBlocks(10); + + // pass action proposal + const concludeProposalReceipt = passActionProposal( + contractAddress, + deployer, + deployer, + [deployer, address1, address2] + ); + + console.log("==========================="); + console.log("concludeProposalReceipt"); + console.log(concludeProposalReceipt); + for (const event of concludeProposalReceipt.events) { + const eventValue = cvToValue(event.data.value!); + // if event value is an object stringify it + console.log( + `- event: ${ + typeof eventValue === "object" + ? JSON.stringify(eventValue) + : eventValue + }` + ); + } + + const proposalDetails = simnet.callReadOnlyFn( + `${deployer}.aibtc-action-proposals`, + "get-proposal", + [Cl.uint(1)], + deployer + ); + + console.log("==========================="); + console.log("proposalDetails"); + console.log(cvToValue(proposalDetails.result).value); + + expect(concludeProposalReceipt.result).toBeOk(Cl.bool(true)); + }); }); diff --git a/tests/dao/extensions/aibtc-onchain-messaging.test.ts b/tests/dao/extensions/aibtc-onchain-messaging.test.ts index 8409b0f..3a1d03c 100644 --- a/tests/dao/extensions/aibtc-onchain-messaging.test.ts +++ b/tests/dao/extensions/aibtc-onchain-messaging.test.ts @@ -56,7 +56,7 @@ describe(`extension: ${contractName}`, () => { const proposalContractName = "aibtc-onchain-messaging-send"; const proposalContractAddress = `${deployer}.${proposalContractName}`; - // fund account that sends proposal + // fund accounts for creating and voting on proposals const getDaoTokensReceipts = [ getDaoTokens(deployer, deployer, 1000000000), // 1000 STX getDaoTokens(deployer, address1, 500000000), // 500 STX @@ -94,7 +94,7 @@ describe(`extension: ${contractName}`, () => { const constructReceipt = constructDao(deployer); expect(constructReceipt.result).toBeOk(Cl.bool(true)); - // progres the chain for at-block calls + // progress the chain for at-block calls simnet.mineEmptyBlocks(10); // pass proposal diff --git a/tests/test-utilities.ts b/tests/test-utilities.ts index 8174f61..636e176 100644 --- a/tests/test-utilities.ts +++ b/tests/test-utilities.ts @@ -68,8 +68,6 @@ export function passCoreProposal( [Cl.principal(proposalContractAddress), Cl.bool(true)], voter ); - console.log(`voteReceipt: ${voter}`); - console.log(voteReceipt.result); expect(voteReceipt.result).toBeOk(Cl.bool(true)); } // progress past the end block @@ -87,9 +85,35 @@ export function passCoreProposal( export function passActionProposal( proposalContractAddress: string, - sender: string + deployer: string, + sender: string, + voters: string[] ) { // propose-action + const proposeActionReceipt = simnet.callPublicFn( + `${deployer}.${actionProposalsContractName}`, + "propose-action", + [Cl.principal(proposalContractAddress)], + sender + ); + expect(proposeActionReceipt.result).toBeOk(Cl.bool(true)); // vote-on-proposal - // conclude-propsal + for (const voter of voters) { + const voteReceipt = simnet.callPublicFn( + `${deployer}.${actionProposalsContractName}`, + "vote-on-proposal", + [Cl.principal(proposalContractAddress), Cl.bool(true)], + voter + ); + expect(voteReceipt.result).toBeOk(Cl.bool(true)); + } + // conclude-proposal + const concludeProposalReceipt = simnet.callPublicFn( + `${deployer}.${actionProposalsContractName}`, + "conclude-proposal", + [Cl.principal(proposalContractAddress)], + deployer + ); + // return final receipt for processing + return concludeProposalReceipt; } From 47f4a53a9ba53fd82888f8827dcf55b0c9664c40 Mon Sep 17 00:00:00 2001 From: Jason Schrader Date: Tue, 14 Jan 2025 22:15:14 -0700 Subject: [PATCH 08/19] fix: migrate error codes to a seperate file Importing between test files is a no no --- tests/dao/aibtcdev-base-dao.test.ts | 8 +- .../extensions/aibtc-action-proposals.test.ts | 18 +---- .../dao/extensions/aibtc-bank-account.test.ts | 8 +- .../extensions/aibtc-core-proposals.test.ts | 16 +--- .../aibtc-onchain-messaging.test.ts | 6 +- .../aibtc-payments-invoices.test.ts | 18 +---- .../dao/extensions/aibtc-token-owner.test.ts | 5 +- tests/dao/extensions/aibtc-treasury.test.ts | 6 +- ...ank-account-initialize-new-account.test.ts | 4 +- ...unt-override-last-withdrawal-block.test.ts | 4 +- .../aibtc-base-add-new-extension.test.ts | 4 +- ...ibtc-base-bootstrap-initialization.test.ts | 4 +- .../aibtc-onchain-messaging-send.test.ts | 4 +- ...btc-payments-invoices-add-resource.test.ts | 4 +- ...oices-pay-invoice-by-resource-name.test.ts | 4 +- .../aibtc-token-owner-set-token-uri.test.ts | 4 +- ...btc-token-owner-transfer-ownership.test.ts | 4 +- .../aibtc-treasury-allow-asset.test.ts | 4 +- .../aibtc-treasury-delegate-stx.test.ts | 4 +- tests/error-codes.ts | 74 +++++++++++++++++++ 20 files changed, 113 insertions(+), 90 deletions(-) create mode 100644 tests/error-codes.ts diff --git a/tests/dao/aibtcdev-base-dao.test.ts b/tests/dao/aibtcdev-base-dao.test.ts index 1f949d9..d9863f2 100644 --- a/tests/dao/aibtcdev-base-dao.test.ts +++ b/tests/dao/aibtcdev-base-dao.test.ts @@ -1,5 +1,6 @@ import { Cl } from "@stacks/transactions"; import { describe, expect, it } from "vitest"; +import { BaseDaoErrCode } from "../error-codes"; const accounts = simnet.getAccounts(); const address1 = accounts.get("wallet_1")!; @@ -9,12 +10,7 @@ const deployer = accounts.get("deployer")!; const contractName = "aibtcdev-base-dao"; const contractAddress = `${deployer}.${contractName}`; -export enum ErrCode { - ERR_UNAUTHORIZED = 900, - ERR_ALREADY_EXECUTED, - ERR_INVALID_EXTENSION, - ERR_NO_EMPTY_LISTS, -} +const ErrCode = BaseDaoErrCode; describe(`base dao: ${contractName}`, () => { it("should have tests written", () => { diff --git a/tests/dao/extensions/aibtc-action-proposals.test.ts b/tests/dao/extensions/aibtc-action-proposals.test.ts index 9816200..a6a3c45 100644 --- a/tests/dao/extensions/aibtc-action-proposals.test.ts +++ b/tests/dao/extensions/aibtc-action-proposals.test.ts @@ -1,5 +1,6 @@ import { Cl } from "@stacks/transactions"; import { describe, expect, it } from "vitest"; +import { ActionProposalsErrCode } from "../../error-codes"; const accounts = simnet.getAccounts(); const address1 = accounts.get("wallet_1")!; @@ -9,24 +10,11 @@ const deployer = accounts.get("deployer")!; const contractName = "aibtc-action-proposals"; const contractAddress = `${deployer}.${contractName}`; -export enum ErrCode { - ERR_NOT_DAO_OR_EXTENSION = 1000, - ERR_INSUFFICIENT_BALANCE, - ERR_FETCHING_TOKEN_DATA, - ERR_PROPOSAL_NOT_FOUND, - ERR_PROPOSAL_STILL_ACTIVE, - ERR_SAVING_PROPOSAL, - ERR_PROPOSAL_ALREADY_CONCLUDED, - ERR_RETRIEVING_START_BLOCK_HASH, - ERR_VOTE_TOO_SOON, - ERR_VOTE_TOO_LATE, - ERR_ALREADY_VOTED, - ERR_INVALID_ACTION, -} - const votingPeriod = 144; // 24 hours in BTC blocks const votingQuorum = 66; // 66% quorum +const ErrCode = ActionProposalsErrCode; + describe(`extension: ${contractName}`, () => { it("callback() should respond with (ok true)", () => { const callback = simnet.callPublicFn( diff --git a/tests/dao/extensions/aibtc-bank-account.test.ts b/tests/dao/extensions/aibtc-bank-account.test.ts index ae1d936..87f585f 100644 --- a/tests/dao/extensions/aibtc-bank-account.test.ts +++ b/tests/dao/extensions/aibtc-bank-account.test.ts @@ -1,5 +1,6 @@ import { Cl } from "@stacks/transactions"; import { describe, expect, it } from "vitest"; +import { BankAccountErrCode } from "../../error-codes"; const accounts = simnet.getAccounts(); const address1 = accounts.get("wallet_1")!; @@ -9,12 +10,7 @@ const deployer = accounts.get("deployer")!; const contractName = "aibtc-bank-account"; const contractAddress = `${deployer}.${contractName}`; -export enum ErrCode { - ERR_INVALID = 2000, - ERR_UNAUTHORIZED, - ERR_TOO_SOON, - ERR_INVALID_AMOUNT, -} +const ErrCode = BankAccountErrCode; const withdrawalAmount = 10000000; // 10 STX const withdrawalPeriod = 144; // 144 blocks diff --git a/tests/dao/extensions/aibtc-core-proposals.test.ts b/tests/dao/extensions/aibtc-core-proposals.test.ts index 50ba758..491fadf 100644 --- a/tests/dao/extensions/aibtc-core-proposals.test.ts +++ b/tests/dao/extensions/aibtc-core-proposals.test.ts @@ -1,5 +1,6 @@ import { Cl } from "@stacks/transactions"; import { describe, expect, it } from "vitest"; +import { CoreProposalErrCode } from "../../error-codes"; const accounts = simnet.getAccounts(); const deployer = accounts.get("deployer")!; @@ -7,20 +8,7 @@ const deployer = accounts.get("deployer")!; const contractName = "aibtc-core-proposals"; const contractAddress = `${deployer}.${contractName}`; -export enum ErrCode { - ERR_NOT_DAO_OR_EXTENSION = 3000, - ERR_FETCHING_TOKEN_DATA, - ERR_INSUFFICIENT_BALANCE, - ERR_PROPOSAL_NOT_FOUND, - ERR_PROPOSAL_ALREADY_EXECUTED, - ERR_PROPOSAL_STILL_ACTIVE, - ERR_SAVING_PROPOSAL, - ERR_PROPOSAL_ALREADY_CONCLUDED, - ERR_RETRIEVING_START_BLOCK_HASH, - ERR_VOTE_TOO_SOON, - ERR_VOTE_TOO_LATE, - ERR_ALREADY_VOTED, -} +const ErrCode = CoreProposalErrCode; const votingPeriod = 144; // 24 hours in BTC blocks const votingQuorum = 95; // 95% quorum diff --git a/tests/dao/extensions/aibtc-onchain-messaging.test.ts b/tests/dao/extensions/aibtc-onchain-messaging.test.ts index 3a1d03c..8616ace 100644 --- a/tests/dao/extensions/aibtc-onchain-messaging.test.ts +++ b/tests/dao/extensions/aibtc-onchain-messaging.test.ts @@ -5,6 +5,7 @@ import { getDaoTokens, passCoreProposal, } from "../../test-utilities"; +import { OnchainMessagingErrCode } from "../../error-codes"; const accounts = simnet.getAccounts(); const deployer = accounts.get("deployer")!; @@ -14,10 +15,7 @@ const address2 = accounts.get("wallet_2")!; const contractName = "aibtc-onchain-messaging"; const contractAddress = `${deployer}.${contractName}`; -export enum ErrCode { - INPUT_ERROR = 4000, - ERR_UNAUTHORIZED, -} +const ErrCode = OnchainMessagingErrCode; describe(`extension: ${contractName}`, () => { it("callback() should respond with (ok true)", () => { diff --git a/tests/dao/extensions/aibtc-payments-invoices.test.ts b/tests/dao/extensions/aibtc-payments-invoices.test.ts index 50ae70a..01be3c5 100644 --- a/tests/dao/extensions/aibtc-payments-invoices.test.ts +++ b/tests/dao/extensions/aibtc-payments-invoices.test.ts @@ -1,5 +1,6 @@ import { Cl } from "@stacks/transactions"; import { describe, expect, it } from "vitest"; +import { PaymentsInvoicesErrCode } from "../../error-codes"; const accounts = simnet.getAccounts(); const address1 = accounts.get("wallet_1")!; @@ -9,22 +10,7 @@ const deployer = accounts.get("deployer")!; const contractName = "aibtc-payments-invoices"; const contractAddress = `${deployer}.${contractName}`; -export enum ErrCode { - ERR_UNAUTHORIZED = 5000, - ERR_INVALID_PARAMS, - ERR_NAME_ALREADY_USED, - ERR_SAVING_RESOURCE_DATA, - ERR_DELETING_RESOURCE_DATA, - ERR_RESOURCE_NOT_FOUND, - ERR_RESOURCE_DISABLED, - ERR_USER_ALREADY_EXISTS, - ERR_SAVING_USER_DATA, - ERR_USER_NOT_FOUND, - ERR_INVOICE_ALREADY_PAID, - ERR_SAVING_INVOICE_DATA, - ERR_INVOICE_NOT_FOUND, - ERR_RECENT_PAYMENT_NOT_FOUND, -} +const ErrCode = PaymentsInvoicesErrCode; describe(`extension: ${contractName}`, () => { it("callback() should respond with (ok true)", () => { diff --git a/tests/dao/extensions/aibtc-token-owner.test.ts b/tests/dao/extensions/aibtc-token-owner.test.ts index 1e101a8..2494c95 100644 --- a/tests/dao/extensions/aibtc-token-owner.test.ts +++ b/tests/dao/extensions/aibtc-token-owner.test.ts @@ -1,5 +1,6 @@ import { Cl } from "@stacks/transactions"; import { describe, expect, it } from "vitest"; +import { TokenOwnerErrCode } from "../../error-codes"; const accounts = simnet.getAccounts(); const deployer = accounts.get("deployer")!; @@ -7,9 +8,7 @@ const deployer = accounts.get("deployer")!; const contractName = "aibtc-token-owner"; const contractAddress = `${deployer}.${contractName}`; -export enum ErrCode { - ERR_UNAUTHORIZED = 7000, -} +const ErrCode = TokenOwnerErrCode; describe(`extension: ${contractName}`, () => { it("callback() should respond with (ok true)", () => { diff --git a/tests/dao/extensions/aibtc-treasury.test.ts b/tests/dao/extensions/aibtc-treasury.test.ts index ff40c10..cffe617 100644 --- a/tests/dao/extensions/aibtc-treasury.test.ts +++ b/tests/dao/extensions/aibtc-treasury.test.ts @@ -1,5 +1,6 @@ import { Cl } from "@stacks/transactions"; import { describe, expect, it } from "vitest"; +import { TreasuryErrCode } from "../../error-codes"; const accounts = simnet.getAccounts(); const address1 = accounts.get("wallet_1")!; @@ -9,10 +10,7 @@ const deployer = accounts.get("deployer")!; const contractName = "aibtc-treasury"; const contractAddress = `${deployer}.${contractName}`; -export enum ErrCode { - ERR_UNAUTHORIZED = 6000, - ERR_UNKNOWN_ASSSET = 6001, -} +const ErrCode = TreasuryErrCode; describe(`extension: ${contractName}`, () => { it("callback() should respond with (ok true)", () => { diff --git a/tests/dao/proposals/aibtc-bank-account-initialize-new-account.test.ts b/tests/dao/proposals/aibtc-bank-account-initialize-new-account.test.ts index f43c5da..c2976bc 100644 --- a/tests/dao/proposals/aibtc-bank-account-initialize-new-account.test.ts +++ b/tests/dao/proposals/aibtc-bank-account-initialize-new-account.test.ts @@ -1,13 +1,13 @@ import { Cl } from "@stacks/transactions"; import { describe, expect, it } from "vitest"; -import { ErrCode } from "../extensions/aibtc-bank-account.test"; +import { BankAccountErrCode } from "../../error-codes"; const accounts = simnet.getAccounts(); const deployer = accounts.get("deployer")!; const contractName = "aibtc-bank-account-initialize-new-account"; const contractAddress = `${deployer}.${contractName}`; -const expectedErr = Cl.uint(ErrCode.ERR_UNAUTHORIZED); +const expectedErr = Cl.uint(BankAccountErrCode.ERR_UNAUTHORIZED); describe(`core proposal: ${contractName}`, () => { it("execute() fails if called directly", () => { diff --git a/tests/dao/proposals/aibtc-bank-account-override-last-withdrawal-block.test.ts b/tests/dao/proposals/aibtc-bank-account-override-last-withdrawal-block.test.ts index e2f2828..5d82e48 100644 --- a/tests/dao/proposals/aibtc-bank-account-override-last-withdrawal-block.test.ts +++ b/tests/dao/proposals/aibtc-bank-account-override-last-withdrawal-block.test.ts @@ -1,13 +1,13 @@ import { Cl } from "@stacks/transactions"; import { describe, expect, it } from "vitest"; -import { ErrCode } from "../extensions/aibtc-bank-account.test"; +import { BankAccountErrCode } from "../../error-codes"; const accounts = simnet.getAccounts(); const deployer = accounts.get("deployer")!; const contractName = "aibtc-bank-account-override-last-withdrawal-block"; const contractAddress = `${deployer}.${contractName}`; -const expectedErr = Cl.uint(ErrCode.ERR_UNAUTHORIZED); +const expectedErr = Cl.uint(BankAccountErrCode.ERR_UNAUTHORIZED); describe(`core proposal: ${contractName}`, () => { it("execute() fails if called directly", () => { diff --git a/tests/dao/proposals/aibtc-base-add-new-extension.test.ts b/tests/dao/proposals/aibtc-base-add-new-extension.test.ts index 98f6678..73db0a4 100644 --- a/tests/dao/proposals/aibtc-base-add-new-extension.test.ts +++ b/tests/dao/proposals/aibtc-base-add-new-extension.test.ts @@ -1,13 +1,13 @@ import { Cl } from "@stacks/transactions"; import { describe, expect, it } from "vitest"; -import { ErrCode } from "../aibtcdev-base-dao.test"; +import { BaseDaoErrCode } from "../../error-codes"; const accounts = simnet.getAccounts(); const deployer = accounts.get("deployer")!; const contractName = "aibtc-base-add-new-extension"; const contractAddress = `${deployer}.${contractName}`; -const expectedErr = Cl.uint(ErrCode.ERR_UNAUTHORIZED); +const expectedErr = Cl.uint(BaseDaoErrCode.ERR_UNAUTHORIZED); describe(`core proposal: ${contractName}`, () => { it("execute() fails if called directly", () => { diff --git a/tests/dao/proposals/aibtc-base-bootstrap-initialization.test.ts b/tests/dao/proposals/aibtc-base-bootstrap-initialization.test.ts index f47795b..72ca347 100644 --- a/tests/dao/proposals/aibtc-base-bootstrap-initialization.test.ts +++ b/tests/dao/proposals/aibtc-base-bootstrap-initialization.test.ts @@ -1,6 +1,6 @@ import { Cl } from "@stacks/transactions"; import { describe, expect, it } from "vitest"; -import { ErrCode } from "../aibtcdev-base-dao.test"; +import { BaseDaoErrCode } from "../../error-codes"; const accounts = simnet.getAccounts(); const address1 = accounts.get("wallet_1")!; @@ -10,7 +10,7 @@ const deployer = accounts.get("deployer")!; const contractName = "aibtc-base-bootstrap-initialization"; const contractAddress = `${deployer}.${contractName}`; -const expectedErr = Cl.uint(ErrCode.ERR_UNAUTHORIZED); +const expectedErr = Cl.uint(BaseDaoErrCode.ERR_UNAUTHORIZED); const daoManifest = "This is where the DAO can put it's mission, purpose, and goals."; diff --git a/tests/dao/proposals/aibtc-onchain-messaging-send.test.ts b/tests/dao/proposals/aibtc-onchain-messaging-send.test.ts index a584594..f3bcff9 100644 --- a/tests/dao/proposals/aibtc-onchain-messaging-send.test.ts +++ b/tests/dao/proposals/aibtc-onchain-messaging-send.test.ts @@ -1,13 +1,13 @@ import { Cl } from "@stacks/transactions"; import { describe, expect, it } from "vitest"; -import { ErrCode } from "../extensions/aibtc-onchain-messaging.test"; +import { OnchainMessagingErrCode } from "../../error-codes"; const accounts = simnet.getAccounts(); const deployer = accounts.get("deployer")!; const contractName = "aibtc-onchain-messaging-send"; const contractAddress = `${deployer}.${contractName}`; -const expectedErr = Cl.uint(ErrCode.ERR_UNAUTHORIZED); +const expectedErr = Cl.uint(OnchainMessagingErrCode.ERR_UNAUTHORIZED); describe(`core proposal: ${contractName}`, () => { it("execute() fails if called directly", () => { diff --git a/tests/dao/proposals/aibtc-payments-invoices-add-resource.test.ts b/tests/dao/proposals/aibtc-payments-invoices-add-resource.test.ts index 0f669b7..5d33e9b 100644 --- a/tests/dao/proposals/aibtc-payments-invoices-add-resource.test.ts +++ b/tests/dao/proposals/aibtc-payments-invoices-add-resource.test.ts @@ -1,13 +1,13 @@ import { Cl } from "@stacks/transactions"; import { describe, expect, it } from "vitest"; -import { ErrCode } from "../extensions/aibtc-payments-invoices.test"; +import { PaymentsInvoicesErrCode } from "../../error-codes"; const accounts = simnet.getAccounts(); const deployer = accounts.get("deployer")!; const contractName = "aibtc-payments-invoices-add-resource"; const contractAddress = `${deployer}.${contractName}`; -const expectedErr = Cl.uint(ErrCode.ERR_UNAUTHORIZED); +const expectedErr = Cl.uint(PaymentsInvoicesErrCode.ERR_UNAUTHORIZED); describe(`core proposal: ${contractName}`, () => { it("execute() fails if called directly", () => { diff --git a/tests/dao/proposals/aibtc-payments-invoices-pay-invoice-by-resource-name.test.ts b/tests/dao/proposals/aibtc-payments-invoices-pay-invoice-by-resource-name.test.ts index 032e384..f367aa9 100644 --- a/tests/dao/proposals/aibtc-payments-invoices-pay-invoice-by-resource-name.test.ts +++ b/tests/dao/proposals/aibtc-payments-invoices-pay-invoice-by-resource-name.test.ts @@ -1,13 +1,13 @@ import { Cl } from "@stacks/transactions"; import { describe, expect, it } from "vitest"; -import { ErrCode } from "../extensions/aibtc-payments-invoices.test"; +import { PaymentsInvoicesErrCode } from "../../error-codes"; const accounts = simnet.getAccounts(); const deployer = accounts.get("deployer")!; const contractName = "aibtc-payments-invoices-pay-invoice-by-resource-name"; const contractAddress = `${deployer}.${contractName}`; -const expectedErr = Cl.uint(ErrCode.ERR_RESOURCE_NOT_FOUND); +const expectedErr = Cl.uint(PaymentsInvoicesErrCode.ERR_RESOURCE_NOT_FOUND); describe(`core proposal: ${contractName}`, () => { it("execute() fails if called directly", () => { diff --git a/tests/dao/proposals/aibtc-token-owner-set-token-uri.test.ts b/tests/dao/proposals/aibtc-token-owner-set-token-uri.test.ts index 69fa763..744173b 100644 --- a/tests/dao/proposals/aibtc-token-owner-set-token-uri.test.ts +++ b/tests/dao/proposals/aibtc-token-owner-set-token-uri.test.ts @@ -1,13 +1,13 @@ import { Cl } from "@stacks/transactions"; import { describe, expect, it } from "vitest"; -import { ErrCode } from "../extensions/aibtc-token-owner.test"; +import { TokenOwnerErrCode } from "../../error-codes"; const accounts = simnet.getAccounts(); const deployer = accounts.get("deployer")!; const contractName = "aibtc-token-owner-set-token-uri"; const contractAddress = `${deployer}.${contractName}`; -const expectedErr = Cl.uint(ErrCode.ERR_UNAUTHORIZED); +const expectedErr = Cl.uint(TokenOwnerErrCode.ERR_UNAUTHORIZED); describe(`core proposal: ${contractName}`, () => { it("execute() fails if called directly", () => { diff --git a/tests/dao/proposals/aibtc-token-owner-transfer-ownership.test.ts b/tests/dao/proposals/aibtc-token-owner-transfer-ownership.test.ts index 47593a2..dadf6df 100644 --- a/tests/dao/proposals/aibtc-token-owner-transfer-ownership.test.ts +++ b/tests/dao/proposals/aibtc-token-owner-transfer-ownership.test.ts @@ -1,13 +1,13 @@ import { Cl } from "@stacks/transactions"; import { describe, expect, it } from "vitest"; -import { ErrCode } from "../extensions/aibtc-token-owner.test"; +import { TokenOwnerErrCode } from "../../error-codes"; const accounts = simnet.getAccounts(); const deployer = accounts.get("deployer")!; const contractName = "aibtc-token-owner-transfer-ownership"; const contractAddress = `${deployer}.${contractName}`; -const expectedErr = Cl.uint(ErrCode.ERR_UNAUTHORIZED); +const expectedErr = Cl.uint(TokenOwnerErrCode.ERR_UNAUTHORIZED); describe(`core proposal: ${contractName}`, () => { it("execute() fails if called directly", () => { diff --git a/tests/dao/proposals/aibtc-treasury-allow-asset.test.ts b/tests/dao/proposals/aibtc-treasury-allow-asset.test.ts index 4c8b0af..b48669c 100644 --- a/tests/dao/proposals/aibtc-treasury-allow-asset.test.ts +++ b/tests/dao/proposals/aibtc-treasury-allow-asset.test.ts @@ -1,13 +1,13 @@ import { Cl } from "@stacks/transactions"; import { describe, expect, it } from "vitest"; -import { ErrCode } from "../extensions/aibtc-treasury.test"; +import { TreasuryErrCode } from "../../error-codes"; const accounts = simnet.getAccounts(); const deployer = accounts.get("deployer")!; const contractName = "aibtc-treasury-allow-asset"; const contractAddress = `${deployer}.${contractName}`; -const expectedErr = Cl.uint(ErrCode.ERR_UNAUTHORIZED); +const expectedErr = Cl.uint(TreasuryErrCode.ERR_UNAUTHORIZED); describe(`core proposal: ${contractName}`, () => { it("execute() fails if called directly", () => { diff --git a/tests/dao/proposals/aibtc-treasury-delegate-stx.test.ts b/tests/dao/proposals/aibtc-treasury-delegate-stx.test.ts index 4ffa033..41e8628 100644 --- a/tests/dao/proposals/aibtc-treasury-delegate-stx.test.ts +++ b/tests/dao/proposals/aibtc-treasury-delegate-stx.test.ts @@ -1,13 +1,13 @@ import { Cl } from "@stacks/transactions"; import { describe, expect, it } from "vitest"; -import { ErrCode } from "../extensions/aibtc-treasury.test"; +import { TreasuryErrCode } from "../../error-codes"; const accounts = simnet.getAccounts(); const deployer = accounts.get("deployer")!; const contractName = "aibtc-treasury-delegate-stx"; const contractAddress = `${deployer}.${contractName}`; -const expectedErr = Cl.uint(ErrCode.ERR_UNAUTHORIZED); +const expectedErr = Cl.uint(TreasuryErrCode.ERR_UNAUTHORIZED); describe(`core proposal: ${contractName}`, () => { it("execute() fails if called directly", () => { diff --git a/tests/error-codes.ts b/tests/error-codes.ts new file mode 100644 index 0000000..c9abad9 --- /dev/null +++ b/tests/error-codes.ts @@ -0,0 +1,74 @@ +export enum BaseDaoErrCode { + ERR_UNAUTHORIZED = 900, + ERR_ALREADY_EXECUTED, + ERR_INVALID_EXTENSION, + ERR_NO_EMPTY_LISTS, +} + +export enum ActionProposalsErrCode { + ERR_NOT_DAO_OR_EXTENSION = 1000, + ERR_INSUFFICIENT_BALANCE, + ERR_FETCHING_TOKEN_DATA, + ERR_PROPOSAL_NOT_FOUND, + ERR_PROPOSAL_STILL_ACTIVE, + ERR_SAVING_PROPOSAL, + ERR_PROPOSAL_ALREADY_CONCLUDED, + ERR_RETRIEVING_START_BLOCK_HASH, + ERR_VOTE_TOO_SOON, + ERR_VOTE_TOO_LATE, + ERR_ALREADY_VOTED, + ERR_INVALID_ACTION, +} + +export enum BankAccountErrCode { + ERR_INVALID = 2000, + ERR_UNAUTHORIZED, + ERR_TOO_SOON, + ERR_INVALID_AMOUNT, +} + +export enum CoreProposalErrCode { + ERR_NOT_DAO_OR_EXTENSION = 3000, + ERR_FETCHING_TOKEN_DATA, + ERR_INSUFFICIENT_BALANCE, + ERR_PROPOSAL_NOT_FOUND, + ERR_PROPOSAL_ALREADY_EXECUTED, + ERR_PROPOSAL_STILL_ACTIVE, + ERR_SAVING_PROPOSAL, + ERR_PROPOSAL_ALREADY_CONCLUDED, + ERR_RETRIEVING_START_BLOCK_HASH, + ERR_VOTE_TOO_SOON, + ERR_VOTE_TOO_LATE, + ERR_ALREADY_VOTED, +} + +export enum OnchainMessagingErrCode { + INPUT_ERROR = 4000, + ERR_UNAUTHORIZED, +} + +export enum PaymentsInvoicesErrCode { + ERR_UNAUTHORIZED = 5000, + ERR_INVALID_PARAMS, + ERR_NAME_ALREADY_USED, + ERR_SAVING_RESOURCE_DATA, + ERR_DELETING_RESOURCE_DATA, + ERR_RESOURCE_NOT_FOUND, + ERR_RESOURCE_DISABLED, + ERR_USER_ALREADY_EXISTS, + ERR_SAVING_USER_DATA, + ERR_USER_NOT_FOUND, + ERR_INVOICE_ALREADY_PAID, + ERR_SAVING_INVOICE_DATA, + ERR_INVOICE_NOT_FOUND, + ERR_RECENT_PAYMENT_NOT_FOUND, +} + +export enum TreasuryErrCode { + ERR_UNAUTHORIZED = 6000, + ERR_UNKNOWN_ASSSET, +} + +export enum TokenOwnerErrCode { + ERR_UNAUTHORIZED = 7000, +} From 43b200e2ade2a736f5fd0b69032bf8c0f3442212 Mon Sep 17 00:00:00 2001 From: "Jason Schrader (aider)" Date: Tue, 14 Jan 2025 22:16:51 -0700 Subject: [PATCH 09/19] refactor: Update test files to use centralized error codes from error-codes --- .../proposals/aibtc-bank-account-set-account-holder.test.ts | 4 ++-- .../aibtc-bank-account-set-withdrawal-amount.test.ts | 4 ++-- .../aibtc-bank-account-set-withdrawal-period.test.ts | 4 ++-- tests/dao/proposals/aibtc-bank-account-withdraw-stx.test.ts | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/dao/proposals/aibtc-bank-account-set-account-holder.test.ts b/tests/dao/proposals/aibtc-bank-account-set-account-holder.test.ts index 7970c37..f08cc53 100644 --- a/tests/dao/proposals/aibtc-bank-account-set-account-holder.test.ts +++ b/tests/dao/proposals/aibtc-bank-account-set-account-holder.test.ts @@ -1,13 +1,13 @@ import { Cl } from "@stacks/transactions"; import { describe, expect, it } from "vitest"; -import { ErrCode } from "../extensions/aibtc-bank-account.test"; +import { BankAccountErrCode } from "../../error-codes"; const accounts = simnet.getAccounts(); const deployer = accounts.get("deployer")!; const contractName = "aibtc-bank-account-set-account-holder"; const contractAddress = `${deployer}.${contractName}`; -const expectedErr = Cl.uint(ErrCode.ERR_UNAUTHORIZED); +const expectedErr = Cl.uint(BankAccountErrCode.ERR_UNAUTHORIZED); describe(`core proposal: ${contractName}`, () => { it("execute() fails if called directly", () => { diff --git a/tests/dao/proposals/aibtc-bank-account-set-withdrawal-amount.test.ts b/tests/dao/proposals/aibtc-bank-account-set-withdrawal-amount.test.ts index e418269..9780b31 100644 --- a/tests/dao/proposals/aibtc-bank-account-set-withdrawal-amount.test.ts +++ b/tests/dao/proposals/aibtc-bank-account-set-withdrawal-amount.test.ts @@ -1,13 +1,13 @@ import { Cl } from "@stacks/transactions"; import { describe, expect, it } from "vitest"; -import { ErrCode } from "../extensions/aibtc-bank-account.test"; +import { BankAccountErrCode } from "../../error-codes"; const accounts = simnet.getAccounts(); const deployer = accounts.get("deployer")!; const contractName = "aibtc-bank-account-set-withdrawal-amount"; const contractAddress = `${deployer}.${contractName}`; -const expectedErr = Cl.uint(ErrCode.ERR_UNAUTHORIZED); +const expectedErr = Cl.uint(BankAccountErrCode.ERR_UNAUTHORIZED); describe(`core proposal: ${contractName}`, () => { it("execute() fails if called directly", () => { diff --git a/tests/dao/proposals/aibtc-bank-account-set-withdrawal-period.test.ts b/tests/dao/proposals/aibtc-bank-account-set-withdrawal-period.test.ts index d591149..f81e7cb 100644 --- a/tests/dao/proposals/aibtc-bank-account-set-withdrawal-period.test.ts +++ b/tests/dao/proposals/aibtc-bank-account-set-withdrawal-period.test.ts @@ -1,13 +1,13 @@ import { Cl } from "@stacks/transactions"; import { describe, expect, it } from "vitest"; -import { ErrCode } from "../extensions/aibtc-bank-account.test"; +import { BankAccountErrCode } from "../../error-codes"; const accounts = simnet.getAccounts(); const deployer = accounts.get("deployer")!; const contractName = "aibtc-bank-account-set-withdrawal-period"; const contractAddress = `${deployer}.${contractName}`; -const expectedErr = Cl.uint(ErrCode.ERR_UNAUTHORIZED); +const expectedErr = Cl.uint(BankAccountErrCode.ERR_UNAUTHORIZED); describe(`core proposal: ${contractName}`, () => { it("execute() fails if called directly", () => { diff --git a/tests/dao/proposals/aibtc-bank-account-withdraw-stx.test.ts b/tests/dao/proposals/aibtc-bank-account-withdraw-stx.test.ts index 47fa97f..04914d1 100644 --- a/tests/dao/proposals/aibtc-bank-account-withdraw-stx.test.ts +++ b/tests/dao/proposals/aibtc-bank-account-withdraw-stx.test.ts @@ -1,13 +1,13 @@ import { Cl } from "@stacks/transactions"; import { describe, expect, it } from "vitest"; -import { ErrCode } from "../extensions/aibtc-bank-account.test"; +import { BankAccountErrCode } from "../../error-codes"; const accounts = simnet.getAccounts(); const deployer = accounts.get("deployer")!; const contractName = "aibtc-bank-account-withdraw-stx"; const contractAddress = `${deployer}.${contractName}`; -const expectedErr = Cl.uint(ErrCode.ERR_UNAUTHORIZED); +const expectedErr = Cl.uint(BankAccountErrCode.ERR_UNAUTHORIZED); describe(`core proposal: ${contractName}`, () => { it("execute() fails if called directly", () => { From 500274a0e72301e525fcdb67855247467fbb3cda Mon Sep 17 00:00:00 2001 From: "Jason Schrader (aider)" Date: Tue, 14 Jan 2025 22:17:36 -0700 Subject: [PATCH 10/19] refactor: Update proposal test files to use centralized error codes --- tests/dao/proposals/aibtc-base-disable-extension.test.ts | 4 ++-- tests/dao/proposals/aibtc-base-enable-extension.test.ts | 4 ++-- tests/dao/proposals/aibtc-base-replace-extension.test.ts | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/dao/proposals/aibtc-base-disable-extension.test.ts b/tests/dao/proposals/aibtc-base-disable-extension.test.ts index 3781f61..9860870 100644 --- a/tests/dao/proposals/aibtc-base-disable-extension.test.ts +++ b/tests/dao/proposals/aibtc-base-disable-extension.test.ts @@ -1,6 +1,6 @@ import { Cl } from "@stacks/transactions"; import { describe, expect, it } from "vitest"; -import { ErrCode } from "../aibtcdev-base-dao.test"; +import { CoreProposalErrCode } from "../../error-codes"; const accounts = simnet.getAccounts(); const deployer = accounts.get("deployer")!; @@ -8,7 +8,7 @@ const contractName = "aibtc-base-disable-extension"; const contractAddress = `${deployer}.${contractName}`; // custom error because proposal is not found / setup yet -const expectedErr = Cl.uint(404); +const expectedErr = Cl.uint(CoreProposalErrCode.ERR_PROPOSAL_NOT_FOUND); describe(`core proposal: ${contractName}`, () => { it("execute() fails if called directly", () => { diff --git a/tests/dao/proposals/aibtc-base-enable-extension.test.ts b/tests/dao/proposals/aibtc-base-enable-extension.test.ts index 1726eb5..6c1e135 100644 --- a/tests/dao/proposals/aibtc-base-enable-extension.test.ts +++ b/tests/dao/proposals/aibtc-base-enable-extension.test.ts @@ -1,6 +1,6 @@ import { Cl } from "@stacks/transactions"; import { describe, expect, it } from "vitest"; -import { ErrCode } from "../aibtcdev-base-dao.test"; +import { CoreProposalErrCode } from "../../error-codes"; const accounts = simnet.getAccounts(); const deployer = accounts.get("deployer")!; @@ -8,7 +8,7 @@ const contractName = "aibtc-base-enable-extension"; const contractAddress = `${deployer}.${contractName}`; // custom error because proposal is not found / setup yet -const expectedErr = Cl.uint(404); +const expectedErr = Cl.uint(CoreProposalErrCode.ERR_PROPOSAL_NOT_FOUND); describe(`core proposal: ${contractName}`, () => { it("execute() fails if called directly", () => { diff --git a/tests/dao/proposals/aibtc-base-replace-extension.test.ts b/tests/dao/proposals/aibtc-base-replace-extension.test.ts index a4f561a..3845212 100644 --- a/tests/dao/proposals/aibtc-base-replace-extension.test.ts +++ b/tests/dao/proposals/aibtc-base-replace-extension.test.ts @@ -1,6 +1,6 @@ import { Cl } from "@stacks/transactions"; import { describe, expect, it } from "vitest"; -import { ErrCode } from "../aibtcdev-base-dao.test"; +import { CoreProposalErrCode } from "../../error-codes"; const accounts = simnet.getAccounts(); const deployer = accounts.get("deployer")!; @@ -8,7 +8,7 @@ const contractName = "aibtc-base-replace-extension"; const contractAddress = `${deployer}.${contractName}`; // custom error because proposal is not found / setup yet -const expectedErr = Cl.uint(404); +const expectedErr = Cl.uint(CoreProposalErrCode.ERR_PROPOSAL_NOT_FOUND); describe(`core proposal: ${contractName}`, () => { it("execute() fails if called directly before dao is initialized", () => { From 8893a2b64e6e76c349c02a96406226d013b3aabe Mon Sep 17 00:00:00 2001 From: "Jason Schrader (aider)" Date: Tue, 14 Jan 2025 22:18:24 -0700 Subject: [PATCH 11/19] refactor: Update test files to use centralized error codes from error-codes --- .../dao/proposals/aibtc-payments-invoices-pay-invoice.test.ts | 4 ++-- .../aibtc-payments-invoices-set-payment-address.test.ts | 4 ++-- .../aibtc-payments-invoices-toggle-resource-by-name.test.ts | 4 ++-- .../proposals/aibtc-payments-invoices-toggle-resource.test.ts | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/dao/proposals/aibtc-payments-invoices-pay-invoice.test.ts b/tests/dao/proposals/aibtc-payments-invoices-pay-invoice.test.ts index deb9075..4d8acbb 100644 --- a/tests/dao/proposals/aibtc-payments-invoices-pay-invoice.test.ts +++ b/tests/dao/proposals/aibtc-payments-invoices-pay-invoice.test.ts @@ -1,13 +1,13 @@ import { Cl } from "@stacks/transactions"; import { describe, expect, it } from "vitest"; -import { ErrCode } from "../extensions/aibtc-payments-invoices.test"; +import { PaymentsInvoicesErrCode } from "../../error-codes"; const accounts = simnet.getAccounts(); const deployer = accounts.get("deployer")!; const contractName = "aibtc-payments-invoices-pay-invoice"; const contractAddress = `${deployer}.${contractName}`; -const expectedErr = Cl.uint(ErrCode.ERR_RESOURCE_NOT_FOUND); +const expectedErr = Cl.uint(PaymentsInvoicesErrCode.ERR_RESOURCE_NOT_FOUND); describe(`core proposal: ${contractName}`, () => { it("execute() fails if called directly", () => { diff --git a/tests/dao/proposals/aibtc-payments-invoices-set-payment-address.test.ts b/tests/dao/proposals/aibtc-payments-invoices-set-payment-address.test.ts index facaddb..80ff62d 100644 --- a/tests/dao/proposals/aibtc-payments-invoices-set-payment-address.test.ts +++ b/tests/dao/proposals/aibtc-payments-invoices-set-payment-address.test.ts @@ -1,13 +1,13 @@ import { Cl } from "@stacks/transactions"; import { describe, expect, it } from "vitest"; -import { ErrCode } from "../extensions/aibtc-payments-invoices.test"; +import { PaymentsInvoicesErrCode } from "../../error-codes"; const accounts = simnet.getAccounts(); const deployer = accounts.get("deployer")!; const contractName = "aibtc-payments-invoices-set-payment-address"; const contractAddress = `${deployer}.${contractName}`; -const expectedErr = Cl.uint(ErrCode.ERR_UNAUTHORIZED); +const expectedErr = Cl.uint(PaymentsInvoicesErrCode.ERR_UNAUTHORIZED); describe(`core proposal: ${contractName}`, () => { it("execute() fails if called directly", () => { diff --git a/tests/dao/proposals/aibtc-payments-invoices-toggle-resource-by-name.test.ts b/tests/dao/proposals/aibtc-payments-invoices-toggle-resource-by-name.test.ts index 52bdbcd..a284151 100644 --- a/tests/dao/proposals/aibtc-payments-invoices-toggle-resource-by-name.test.ts +++ b/tests/dao/proposals/aibtc-payments-invoices-toggle-resource-by-name.test.ts @@ -1,13 +1,13 @@ import { Cl } from "@stacks/transactions"; import { describe, expect, it } from "vitest"; -import { ErrCode } from "../extensions/aibtc-payments-invoices.test"; +import { PaymentsInvoicesErrCode } from "../../error-codes"; const accounts = simnet.getAccounts(); const deployer = accounts.get("deployer")!; const contractName = "aibtc-payments-invoices-toggle-resource-by-name"; const contractAddress = `${deployer}.${contractName}`; -const expectedErr = Cl.uint(ErrCode.ERR_RESOURCE_NOT_FOUND); +const expectedErr = Cl.uint(PaymentsInvoicesErrCode.ERR_RESOURCE_NOT_FOUND); describe(`core proposal: ${contractName}`, () => { it("execute() fails if called directly", () => { diff --git a/tests/dao/proposals/aibtc-payments-invoices-toggle-resource.test.ts b/tests/dao/proposals/aibtc-payments-invoices-toggle-resource.test.ts index 825899b..f87b7a5 100644 --- a/tests/dao/proposals/aibtc-payments-invoices-toggle-resource.test.ts +++ b/tests/dao/proposals/aibtc-payments-invoices-toggle-resource.test.ts @@ -1,13 +1,13 @@ import { Cl } from "@stacks/transactions"; import { describe, expect, it } from "vitest"; -import { ErrCode } from "../extensions/aibtc-payments-invoices.test"; +import { PaymentsInvoicesErrCode } from "../../error-codes"; const accounts = simnet.getAccounts(); const deployer = accounts.get("deployer")!; const contractName = "aibtc-payments-invoices-toggle-resource"; const contractAddress = `${deployer}.${contractName}`; -const expectedErr = Cl.uint(ErrCode.ERR_RESOURCE_NOT_FOUND); +const expectedErr = Cl.uint(PaymentsInvoicesErrCode.ERR_RESOURCE_NOT_FOUND); describe(`core proposal: ${contractName}`, () => { it("execute() fails if called directly", () => { From 6b97b986a1b899a49192d2b685cd77d763f42cd9 Mon Sep 17 00:00:00 2001 From: "Jason Schrader (aider)" Date: Tue, 14 Jan 2025 22:19:10 -0700 Subject: [PATCH 12/19] refactor: Update treasury test files to use centralized error codes --- tests/dao/proposals/aibtc-treasury-deposit-ft.test.ts | 4 ++-- tests/dao/proposals/aibtc-treasury-deposit-nft.test.ts | 4 ++-- tests/dao/proposals/aibtc-treasury-freeze-asset.test.ts | 4 ++-- tests/dao/proposals/aibtc-treasury-revoke-delegation.test.ts | 4 ++-- tests/dao/proposals/aibtc-treasury-withdraw-ft.test.ts | 4 ++-- tests/dao/proposals/aibtc-treasury-withdraw-nft.test.ts | 4 ++-- tests/dao/proposals/aibtc-treasury-withdraw-stx.test.ts | 4 ++-- 7 files changed, 14 insertions(+), 14 deletions(-) diff --git a/tests/dao/proposals/aibtc-treasury-deposit-ft.test.ts b/tests/dao/proposals/aibtc-treasury-deposit-ft.test.ts index 4b79c90..acacfa1 100644 --- a/tests/dao/proposals/aibtc-treasury-deposit-ft.test.ts +++ b/tests/dao/proposals/aibtc-treasury-deposit-ft.test.ts @@ -1,13 +1,13 @@ import { Cl } from "@stacks/transactions"; import { describe, expect, it } from "vitest"; -import { ErrCode } from "../extensions/aibtc-treasury.test"; +import { TreasuryErrCode } from "../../error-codes"; const accounts = simnet.getAccounts(); const deployer = accounts.get("deployer")!; const contractName = "aibtc-treasury-deposit-ft"; const contractAddress = `${deployer}.${contractName}`; -const expectedErr = Cl.uint(ErrCode.ERR_UNKNOWN_ASSSET); +const expectedErr = Cl.uint(TreasuryErrCode.ERR_UNKNOWN_ASSSET); describe(`core proposal: ${contractName}`, () => { it("execute() fails if called directly", () => { diff --git a/tests/dao/proposals/aibtc-treasury-deposit-nft.test.ts b/tests/dao/proposals/aibtc-treasury-deposit-nft.test.ts index 41d1725..89479fe 100644 --- a/tests/dao/proposals/aibtc-treasury-deposit-nft.test.ts +++ b/tests/dao/proposals/aibtc-treasury-deposit-nft.test.ts @@ -1,13 +1,13 @@ import { Cl } from "@stacks/transactions"; import { describe, expect, it } from "vitest"; -import { ErrCode } from "../extensions/aibtc-treasury.test"; +import { TreasuryErrCode } from "../../error-codes"; const accounts = simnet.getAccounts(); const deployer = accounts.get("deployer")!; const contractName = "aibtc-treasury-deposit-nft"; const contractAddress = `${deployer}.${contractName}`; -const expectedErr = Cl.uint(ErrCode.ERR_UNKNOWN_ASSSET); +const expectedErr = Cl.uint(TreasuryErrCode.ERR_UNKNOWN_ASSSET); describe(`core proposal: ${contractName}`, () => { it("execute() fails if called directly", () => { diff --git a/tests/dao/proposals/aibtc-treasury-freeze-asset.test.ts b/tests/dao/proposals/aibtc-treasury-freeze-asset.test.ts index 0a4b85b..d75a246 100644 --- a/tests/dao/proposals/aibtc-treasury-freeze-asset.test.ts +++ b/tests/dao/proposals/aibtc-treasury-freeze-asset.test.ts @@ -1,13 +1,13 @@ import { Cl } from "@stacks/transactions"; import { describe, expect, it } from "vitest"; -import { ErrCode } from "../extensions/aibtc-treasury.test"; +import { TreasuryErrCode } from "../../error-codes"; const accounts = simnet.getAccounts(); const deployer = accounts.get("deployer")!; const contractName = "aibtc-treasury-freeze-asset"; const contractAddress = `${deployer}.${contractName}`; -const expectedErr = Cl.uint(ErrCode.ERR_UNAUTHORIZED); +const expectedErr = Cl.uint(TreasuryErrCode.ERR_UNAUTHORIZED); describe(`core proposal: ${contractName}`, () => { it("execute() fails if called directly", () => { diff --git a/tests/dao/proposals/aibtc-treasury-revoke-delegation.test.ts b/tests/dao/proposals/aibtc-treasury-revoke-delegation.test.ts index 9f024ce..f6ec4db 100644 --- a/tests/dao/proposals/aibtc-treasury-revoke-delegation.test.ts +++ b/tests/dao/proposals/aibtc-treasury-revoke-delegation.test.ts @@ -1,13 +1,13 @@ import { Cl } from "@stacks/transactions"; import { describe, expect, it } from "vitest"; -import { ErrCode } from "../extensions/aibtc-treasury.test"; +import { TreasuryErrCode } from "../../error-codes"; const accounts = simnet.getAccounts(); const deployer = accounts.get("deployer")!; const contractName = "aibtc-treasury-revoke-delegation"; const contractAddress = `${deployer}.${contractName}`; -const expectedErr = Cl.uint(ErrCode.ERR_UNAUTHORIZED); +const expectedErr = Cl.uint(TreasuryErrCode.ERR_UNAUTHORIZED); describe(`core proposal: ${contractName}`, () => { it("execute() fails if called directly", () => { diff --git a/tests/dao/proposals/aibtc-treasury-withdraw-ft.test.ts b/tests/dao/proposals/aibtc-treasury-withdraw-ft.test.ts index 6e9596f..e455e93 100644 --- a/tests/dao/proposals/aibtc-treasury-withdraw-ft.test.ts +++ b/tests/dao/proposals/aibtc-treasury-withdraw-ft.test.ts @@ -1,13 +1,13 @@ import { Cl } from "@stacks/transactions"; import { describe, expect, it } from "vitest"; -import { ErrCode } from "../extensions/aibtc-treasury.test"; +import { TreasuryErrCode } from "../../error-codes"; const accounts = simnet.getAccounts(); const deployer = accounts.get("deployer")!; const contractName = "aibtc-treasury-withdraw-ft"; const contractAddress = `${deployer}.${contractName}`; -const expectedErr = Cl.uint(ErrCode.ERR_UNAUTHORIZED); +const expectedErr = Cl.uint(TreasuryErrCode.ERR_UNAUTHORIZED); describe(`core proposal: ${contractName}`, () => { it("execute() fails if called directly", () => { diff --git a/tests/dao/proposals/aibtc-treasury-withdraw-nft.test.ts b/tests/dao/proposals/aibtc-treasury-withdraw-nft.test.ts index 06900d3..4ed1db1 100644 --- a/tests/dao/proposals/aibtc-treasury-withdraw-nft.test.ts +++ b/tests/dao/proposals/aibtc-treasury-withdraw-nft.test.ts @@ -1,13 +1,13 @@ import { Cl } from "@stacks/transactions"; import { describe, expect, it } from "vitest"; -import { ErrCode } from "../extensions/aibtc-treasury.test"; +import { TreasuryErrCode } from "../../error-codes"; const accounts = simnet.getAccounts(); const deployer = accounts.get("deployer")!; const contractName = "aibtc-treasury-withdraw-nft"; const contractAddress = `${deployer}.${contractName}`; -const expectedErr = Cl.uint(ErrCode.ERR_UNAUTHORIZED); +const expectedErr = Cl.uint(TreasuryErrCode.ERR_UNAUTHORIZED); describe(`core proposal: ${contractName}`, () => { it("execute() fails if called directly", () => { diff --git a/tests/dao/proposals/aibtc-treasury-withdraw-stx.test.ts b/tests/dao/proposals/aibtc-treasury-withdraw-stx.test.ts index 6991473..500e626 100644 --- a/tests/dao/proposals/aibtc-treasury-withdraw-stx.test.ts +++ b/tests/dao/proposals/aibtc-treasury-withdraw-stx.test.ts @@ -1,13 +1,13 @@ import { Cl } from "@stacks/transactions"; import { describe, expect, it } from "vitest"; -import { ErrCode } from "../extensions/aibtc-treasury.test"; +import { TreasuryErrCode } from "../../error-codes"; const accounts = simnet.getAccounts(); const deployer = accounts.get("deployer")!; const contractName = "aibtc-treasury-withdraw-stx"; const contractAddress = `${deployer}.${contractName}`; -const expectedErr = Cl.uint(ErrCode.ERR_UNAUTHORIZED); +const expectedErr = Cl.uint(TreasuryErrCode.ERR_UNAUTHORIZED); describe(`core proposal: ${contractName}`, () => { it("execute() fails if called directly", () => { From da183e2e14563d444509126010007efdf789478a Mon Sep 17 00:00:00 2001 From: Jason Schrader Date: Tue, 14 Jan 2025 22:25:55 -0700 Subject: [PATCH 13/19] fix: match error value in base contract That way we can use same enum, same outcome --- contracts/dao/proposals/aibtc-base-disable-extension.clar | 2 +- contracts/dao/proposals/aibtc-base-enable-extension.clar | 2 +- contracts/dao/proposals/aibtc-base-replace-extension.clar | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/contracts/dao/proposals/aibtc-base-disable-extension.clar b/contracts/dao/proposals/aibtc-base-disable-extension.clar index 6a9cb26..48f3a09 100644 --- a/contracts/dao/proposals/aibtc-base-disable-extension.clar +++ b/contracts/dao/proposals/aibtc-base-disable-extension.clar @@ -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 diff --git a/contracts/dao/proposals/aibtc-base-enable-extension.clar b/contracts/dao/proposals/aibtc-base-enable-extension.clar index 5d51848..895fd94 100644 --- a/contracts/dao/proposals/aibtc-base-enable-extension.clar +++ b/contracts/dao/proposals/aibtc-base-enable-extension.clar @@ -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 diff --git a/contracts/dao/proposals/aibtc-base-replace-extension.clar b/contracts/dao/proposals/aibtc-base-replace-extension.clar index 14c0c36..a52a151 100644 --- a/contracts/dao/proposals/aibtc-base-replace-extension.clar +++ b/contracts/dao/proposals/aibtc-base-replace-extension.clar @@ -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 From 9e181ef6ee4e4f24430fff0449138ce418b07784 Mon Sep 17 00:00:00 2001 From: Jason Schrader Date: Tue, 14 Jan 2025 23:19:01 -0700 Subject: [PATCH 14/19] feat: add utilities and first action proposal test --- .../actions/aibtc-action-send-message.test.ts | 26 ++++++++++++------- .../aibtc-onchain-messaging.test.ts | 11 +++++--- tests/error-codes.ts | 5 ++++ tests/test-utilities.ts | 18 +++++++++---- 4 files changed, 41 insertions(+), 19 deletions(-) diff --git a/tests/dao/extensions/actions/aibtc-action-send-message.test.ts b/tests/dao/extensions/actions/aibtc-action-send-message.test.ts index a34ba25..e4919af 100644 --- a/tests/dao/extensions/actions/aibtc-action-send-message.test.ts +++ b/tests/dao/extensions/actions/aibtc-action-send-message.test.ts @@ -1,16 +1,16 @@ import { Cl, cvToValue } from "@stacks/transactions"; import { describe, expect, it } from "vitest"; import { - actionProposalsContractName, constructDao, getDaoTokens, passActionProposal, } from "../../../test-utilities"; +import { ActionErrCode } from "../../../error-codes"; const accounts = simnet.getAccounts(); const deployer = accounts.get("deployer")!; -const address1 = accounts.get("address1")!; -const address2 = accounts.get("address2")!; +const address1 = accounts.get("wallet_1")!; +const address2 = accounts.get("wallet_2")!; const contractName = "aibtc-action-send-message"; const contractAddress = `${deployer}.${contractName}`; @@ -27,21 +27,23 @@ describe(`action extension: ${contractName}`, () => { }); it("run() fails if called directly", () => { + const message = "hello world"; const receipt = simnet.callPublicFn( contractAddress, "run", - [Cl.principal(deployer)], + [Cl.buffer(Cl.serialize(Cl.stringAscii(message)))], deployer ); - expect(receipt.result).toBeErr(Cl.uint(0)); + expect(receipt.result).toBeErr(Cl.uint(ActionErrCode.ERR_UNAUTHORIZED)); }); it("run() succeeds if called as a DAO action proposal", () => { + const message = "hello world"; // fund accounts for creating and voting on proposals const getDaoTokensReceipts = [ - getDaoTokens(deployer, deployer, 1000000000), // 1000 STX - getDaoTokens(deployer, address1, 500000000), // 500 STX - getDaoTokens(deployer, address2, 250000000), // 250 STX + getDaoTokens(deployer, deployer, 100000000), // 100 STX + getDaoTokens(deployer, address1, 50000000), // 50 STX + getDaoTokens(deployer, address2, 25000000), // 25 STX ]; const getAddressBalances = [ simnet.callReadOnlyFn( @@ -67,7 +69,7 @@ describe(`action extension: ${contractName}`, () => { const expectedBalance = parseInt( cvToValue(getAddressBalances[i].result).value ); - console.log(`expectedBalance: ${expectedBalance}`); + // console.log(`expectedBalance: ${expectedBalance}`); expect(getDaoTokensReceipts[i].result).toBeOk(Cl.uint(expectedBalance)); } @@ -81,19 +83,22 @@ describe(`action extension: ${contractName}`, () => { // pass action proposal const concludeProposalReceipt = passActionProposal( contractAddress, + Cl.stringAscii(message), deployer, deployer, [deployer, address1, address2] ); + /* console.log("==========================="); console.log("concludeProposalReceipt"); console.log(concludeProposalReceipt); + console.log("events:"); for (const event of concludeProposalReceipt.events) { const eventValue = cvToValue(event.data.value!); // if event value is an object stringify it console.log( - `- event: ${ + `${ typeof eventValue === "object" ? JSON.stringify(eventValue) : eventValue @@ -111,6 +116,7 @@ describe(`action extension: ${contractName}`, () => { console.log("==========================="); console.log("proposalDetails"); console.log(cvToValue(proposalDetails.result).value); + */ expect(concludeProposalReceipt.result).toBeOk(Cl.bool(true)); }); diff --git a/tests/dao/extensions/aibtc-onchain-messaging.test.ts b/tests/dao/extensions/aibtc-onchain-messaging.test.ts index 8616ace..3df7c57 100644 --- a/tests/dao/extensions/aibtc-onchain-messaging.test.ts +++ b/tests/dao/extensions/aibtc-onchain-messaging.test.ts @@ -56,9 +56,9 @@ describe(`extension: ${contractName}`, () => { // fund accounts for creating and voting on proposals const getDaoTokensReceipts = [ - getDaoTokens(deployer, deployer, 1000000000), // 1000 STX - getDaoTokens(deployer, address1, 500000000), // 500 STX - getDaoTokens(deployer, address2, 250000000), // 250 STX + getDaoTokens(deployer, deployer, 100000000), // 100 STX + getDaoTokens(deployer, address1, 50000000), // 50 STX + getDaoTokens(deployer, address2, 25000000), // 25 STX ]; const getAddressBalances = [ simnet.callReadOnlyFn( @@ -84,7 +84,7 @@ describe(`extension: ${contractName}`, () => { const expectedBalance = parseInt( cvToValue(getAddressBalances[i].result).value ); - console.log(`expectedBalance: ${expectedBalance}`); + // console.log(`expectedBalance: ${expectedBalance}`); expect(getDaoTokensReceipts[i].result).toBeOk(Cl.uint(expectedBalance)); } @@ -102,6 +102,7 @@ describe(`extension: ${contractName}`, () => { [deployer, address1, address2] ); + /* console.log("==========================="); console.log("concludeProposalReceipt"); console.log(concludeProposalReceipt); @@ -117,6 +118,7 @@ describe(`extension: ${contractName}`, () => { ); } + const proposalDetails = simnet.callReadOnlyFn( `${deployer}.aibtc-core-proposals`, "get-proposal", @@ -127,6 +129,7 @@ describe(`extension: ${contractName}`, () => { console.log("==========================="); console.log("proposalDetails"); console.log(cvToValue(proposalDetails.result).value); + */ expect(concludeProposalReceipt.result).toBeOk(Cl.bool(true)); }); diff --git a/tests/error-codes.ts b/tests/error-codes.ts index c9abad9..e6a8bb5 100644 --- a/tests/error-codes.ts +++ b/tests/error-codes.ts @@ -20,6 +20,11 @@ export enum ActionProposalsErrCode { ERR_INVALID_ACTION, } +export enum ActionErrCode { + ERR_UNAUTHORIZED = 10001, + ERR_INVALID_PARAMS, +} + export enum BankAccountErrCode { ERR_INVALID = 2000, ERR_UNAUTHORIZED, diff --git a/tests/test-utilities.ts b/tests/test-utilities.ts index 636e176..be45c68 100644 --- a/tests/test-utilities.ts +++ b/tests/test-utilities.ts @@ -1,4 +1,4 @@ -import { Cl } from "@stacks/transactions"; +import { Cl, ClarityValue } from "@stacks/transactions"; import { expect } from "vitest"; export const actionProposalsContractName = "aibtc-action-proposals"; @@ -24,7 +24,7 @@ export function getDaoTokens( const getDaoTokensReceipt = simnet.callPublicFn( tokenDexContractAddress, "buy", - [Cl.principal(tokenContractAddress), Cl.uint(stxAmount)], // 1000 STX buy test + [Cl.principal(tokenContractAddress), Cl.uint(stxAmount)], address ); @@ -85,15 +85,21 @@ export function passCoreProposal( export function passActionProposal( proposalContractAddress: string, + proposalParams: ClarityValue, deployer: string, sender: string, voters: string[] ) { + // TODO: hardcoded + const proposalId = 1; // propose-action const proposeActionReceipt = simnet.callPublicFn( `${deployer}.${actionProposalsContractName}`, "propose-action", - [Cl.principal(proposalContractAddress)], + [ + Cl.principal(proposalContractAddress), + Cl.buffer(Cl.serialize(proposalParams)), + ], sender ); expect(proposeActionReceipt.result).toBeOk(Cl.bool(true)); @@ -102,16 +108,18 @@ export function passActionProposal( const voteReceipt = simnet.callPublicFn( `${deployer}.${actionProposalsContractName}`, "vote-on-proposal", - [Cl.principal(proposalContractAddress), Cl.bool(true)], + [Cl.uint(proposalId), Cl.bool(true)], voter ); expect(voteReceipt.result).toBeOk(Cl.bool(true)); } + // progress past the end block + simnet.mineEmptyBlocks(votingPeriod); // conclude-proposal const concludeProposalReceipt = simnet.callPublicFn( `${deployer}.${actionProposalsContractName}`, "conclude-proposal", - [Cl.principal(proposalContractAddress)], + [Cl.uint(proposalId), Cl.principal(proposalContractAddress)], deployer ); // return final receipt for processing From 2b704e94a632c818a4e8fc8fb769f0bb502d1d8c Mon Sep 17 00:00:00 2001 From: Jason Schrader Date: Tue, 14 Jan 2025 23:49:48 -0700 Subject: [PATCH 15/19] fix: bring proposal code in sync, use stx block for at-block Merges some other minor changes, one test passing each should be ready to translate to the templates for testnet. --- contracts/dao/extensions/aibtc-action-proposals.clar | 12 +++++++----- contracts/dao/extensions/aibtc-core-proposals.clar | 7 ++----- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/contracts/dao/extensions/aibtc-action-proposals.clar b/contracts/dao/extensions/aibtc-action-proposals.clar index f3c8d31..58fbfee 100644 --- a/contracts/dao/extensions/aibtc-action-proposals.clar +++ b/contracts/dao/extensions/aibtc-action-proposals.clar @@ -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 @@ -94,6 +95,7 @@ parameters: parameters, creator: tx-sender, liquidTokens: liquidTokens, + startBlockStx: block-height, startBlock: burn-block-height, endBlock: (+ burn-block-height VOTING_PERIOD) } @@ -105,6 +107,7 @@ createdAt: burn-block-height, caller: contract-caller, creator: tx-sender, + startBlockStx: block-height, startBlock: burn-block-height, endBlock: (+ burn-block-height VOTING_PERIOD), votesFor: u0, @@ -122,7 +125,7 @@ (let ( (proposalRecord (unwrap! (map-get? Proposals proposalId) ERR_PROPOSAL_NOT_FOUND)) - (proposalBlock (get startBlock proposalRecord)) + (proposalBlock (get startBlockStx proposalRecord)) (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)) ) @@ -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)) ) (at-block proposalBlockHash (contract-call? .aibtc-token get-balance who)) ) @@ -244,7 +247,6 @@ )) ) -;; get block hash by height (define-private (get-block-hash (blockHeight uint)) (get-block-info? id-header-hash blockHeight) ) diff --git a/contracts/dao/extensions/aibtc-core-proposals.clar b/contracts/dao/extensions/aibtc-core-proposals.clar index 9183c2e..aca2253 100644 --- a/contracts/dao/extensions/aibtc-core-proposals.clar +++ b/contracts/dao/extensions/aibtc-core-proposals.clar @@ -89,6 +89,7 @@ proposal: proposalContract, creator: tx-sender, liquidTokens: liquidTokens, + startBlockStx: block-height, startBlock: burn-block-height, endBlock: (+ burn-block-height VOTING_PERIOD) } @@ -116,8 +117,7 @@ (proposalRecord (unwrap! (map-get? Proposals proposalContract) ERR_PROPOSAL_NOT_FOUND)) (proposalBlock (get startBlockStx proposalRecord)) (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)) ) ;; caller has the required balance (asserts! (> senderBalance u0) ERR_INSUFFICIENT_BALANCE) @@ -156,8 +156,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)))) ) @@ -235,7 +233,6 @@ )) ) -;; get block hash by height (define-private (get-block-hash (blockHeight uint)) (get-block-info? id-header-hash blockHeight) ) From 3591b07caeead1a776925e8a2117cf6cdf0077ec Mon Sep 17 00:00:00 2001 From: Jason Schrader Date: Tue, 14 Jan 2025 23:55:38 -0700 Subject: [PATCH 16/19] fix: set 144 block delay on core proposals give a little time for liquidity --- contracts/dao/extensions/aibtc-core-proposals.clar | 4 ++++ tests/dao/extensions/aibtc-onchain-messaging.test.ts | 4 +++- tests/error-codes.ts | 1 + 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/contracts/dao/extensions/aibtc-core-proposals.clar b/contracts/dao/extensions/aibtc-core-proposals.clar index aca2253..7967007 100644 --- a/contracts/dao/extensions/aibtc-core-proposals.clar +++ b/contracts/dao/extensions/aibtc-core-proposals.clar @@ -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)) @@ -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) @@ -78,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 diff --git a/tests/dao/extensions/aibtc-onchain-messaging.test.ts b/tests/dao/extensions/aibtc-onchain-messaging.test.ts index 3df7c57..45040f8 100644 --- a/tests/dao/extensions/aibtc-onchain-messaging.test.ts +++ b/tests/dao/extensions/aibtc-onchain-messaging.test.ts @@ -55,6 +55,7 @@ describe(`extension: ${contractName}`, () => { const proposalContractAddress = `${deployer}.${proposalContractName}`; // fund accounts for creating and voting on proposals + // TODO: consolidate as fundVoters() const getDaoTokensReceipts = [ getDaoTokens(deployer, deployer, 100000000), // 100 STX getDaoTokens(deployer, address1, 50000000), // 50 STX @@ -93,7 +94,8 @@ describe(`extension: ${contractName}`, () => { expect(constructReceipt.result).toBeOk(Cl.bool(true)); // progress the chain for at-block calls - simnet.mineEmptyBlocks(10); + // and to pass first core proposal voting period + simnet.mineEmptyBlocks(144); // pass proposal const concludeProposalReceipt = passCoreProposal( diff --git a/tests/error-codes.ts b/tests/error-codes.ts index e6a8bb5..9dd7006 100644 --- a/tests/error-codes.ts +++ b/tests/error-codes.ts @@ -45,6 +45,7 @@ export enum CoreProposalErrCode { ERR_VOTE_TOO_SOON, ERR_VOTE_TOO_LATE, ERR_ALREADY_VOTED, + ERR_FIRST_VOTING_PERIOD, } export enum OnchainMessagingErrCode { From 806837549e891b770e6dc5cdda45fd7d7a3f2dbc Mon Sep 17 00:00:00 2001 From: Jason Schrader Date: Wed, 15 Jan 2025 00:03:14 -0700 Subject: [PATCH 17/19] refactor: generalize voter funding with other proposal steps --- .../actions/aibtc-action-send-message.test.ts | 34 ++---------------- .../aibtc-onchain-messaging.test.ts | 35 ++----------------- tests/test-utilities.ts | 17 ++++++++- 3 files changed, 20 insertions(+), 66 deletions(-) diff --git a/tests/dao/extensions/actions/aibtc-action-send-message.test.ts b/tests/dao/extensions/actions/aibtc-action-send-message.test.ts index e4919af..920c501 100644 --- a/tests/dao/extensions/actions/aibtc-action-send-message.test.ts +++ b/tests/dao/extensions/actions/aibtc-action-send-message.test.ts @@ -2,6 +2,7 @@ import { Cl, cvToValue } from "@stacks/transactions"; import { describe, expect, it } from "vitest"; import { constructDao, + fundVoters, getDaoTokens, passActionProposal, } from "../../../test-utilities"; @@ -40,38 +41,7 @@ describe(`action extension: ${contractName}`, () => { it("run() succeeds if called as a DAO action proposal", () => { const message = "hello world"; // fund accounts for creating and voting on proposals - const getDaoTokensReceipts = [ - getDaoTokens(deployer, deployer, 100000000), // 100 STX - getDaoTokens(deployer, address1, 50000000), // 50 STX - getDaoTokens(deployer, address2, 25000000), // 25 STX - ]; - const getAddressBalances = [ - simnet.callReadOnlyFn( - `${deployer}.aibtc-token`, - "get-balance", - [Cl.principal(deployer)], - deployer - ), - simnet.callReadOnlyFn( - `${deployer}.aibtc-token`, - "get-balance", - [Cl.principal(address1)], - deployer - ), - simnet.callReadOnlyFn( - `${deployer}.aibtc-token`, - "get-balance", - [Cl.principal(address2)], - deployer - ), - ]; - for (let i = 0; i < getDaoTokensReceipts.length; i++) { - const expectedBalance = parseInt( - cvToValue(getAddressBalances[i].result).value - ); - // console.log(`expectedBalance: ${expectedBalance}`); - expect(getDaoTokensReceipts[i].result).toBeOk(Cl.uint(expectedBalance)); - } + fundVoters(deployer, [deployer, address1, address2]); // construct DAO const constructReceipt = constructDao(deployer); diff --git a/tests/dao/extensions/aibtc-onchain-messaging.test.ts b/tests/dao/extensions/aibtc-onchain-messaging.test.ts index 45040f8..2d6c38f 100644 --- a/tests/dao/extensions/aibtc-onchain-messaging.test.ts +++ b/tests/dao/extensions/aibtc-onchain-messaging.test.ts @@ -2,6 +2,7 @@ import { Cl, cvToValue } from "@stacks/transactions"; import { describe, expect, it } from "vitest"; import { constructDao, + fundVoters, getDaoTokens, passCoreProposal, } from "../../test-utilities"; @@ -55,39 +56,7 @@ describe(`extension: ${contractName}`, () => { const proposalContractAddress = `${deployer}.${proposalContractName}`; // fund accounts for creating and voting on proposals - // TODO: consolidate as fundVoters() - const getDaoTokensReceipts = [ - getDaoTokens(deployer, deployer, 100000000), // 100 STX - getDaoTokens(deployer, address1, 50000000), // 50 STX - getDaoTokens(deployer, address2, 25000000), // 25 STX - ]; - const getAddressBalances = [ - simnet.callReadOnlyFn( - `${deployer}.aibtc-token`, - "get-balance", - [Cl.principal(deployer)], - deployer - ), - simnet.callReadOnlyFn( - `${deployer}.aibtc-token`, - "get-balance", - [Cl.principal(address1)], - deployer - ), - simnet.callReadOnlyFn( - `${deployer}.aibtc-token`, - "get-balance", - [Cl.principal(address2)], - deployer - ), - ]; - for (let i = 0; i < getDaoTokensReceipts.length; i++) { - const expectedBalance = parseInt( - cvToValue(getAddressBalances[i].result).value - ); - // console.log(`expectedBalance: ${expectedBalance}`); - expect(getDaoTokensReceipts[i].result).toBeOk(Cl.uint(expectedBalance)); - } + fundVoters(deployer, [deployer, address1, address2]); // construct DAO const constructReceipt = constructDao(deployer); diff --git a/tests/test-utilities.ts b/tests/test-utilities.ts index be45c68..8a9e5b6 100644 --- a/tests/test-utilities.ts +++ b/tests/test-utilities.ts @@ -1,4 +1,4 @@ -import { Cl, ClarityValue } from "@stacks/transactions"; +import { Cl, ClarityValue, cvToValue } from "@stacks/transactions"; import { expect } from "vitest"; export const actionProposalsContractName = "aibtc-action-proposals"; @@ -11,6 +11,21 @@ function getPercentageOfSupply(amount: number, totalSupply: number) { return percentage; } +export function fundVoters(deployer: string, voters: string[]) { + for (const voter of voters) { + const stxAmount = Math.floor(Math.random() * 500000000) + 1000000; + const getDaoTokensReceipt = getDaoTokens(deployer, voter, stxAmount); + const getAddressBalanceResult = simnet.callReadOnlyFn( + `${deployer}.aibtc-token`, + "get-balance", + [Cl.principal(voter)], + deployer + ).result; + const expectedBalance = parseInt(cvToValue(getAddressBalanceResult).value); + expect(getDaoTokensReceipt.result).toBeOk(Cl.uint(expectedBalance)); + } +} + export function getDaoTokens( deployer: string, address: string, From 4405299e3482ad84ed01e10aac882c4322085d24 Mon Sep 17 00:00:00 2001 From: Jason Schrader Date: Wed, 15 Jan 2025 00:09:55 -0700 Subject: [PATCH 18/19] fix: use deployment plan from clarinet check --- deployments/default.simnet-plan.yaml | 384 --------------------------- 1 file changed, 384 deletions(-) delete mode 100644 deployments/default.simnet-plan.yaml diff --git a/deployments/default.simnet-plan.yaml b/deployments/default.simnet-plan.yaml deleted file mode 100644 index 0306fd5..0000000 --- a/deployments/default.simnet-plan.yaml +++ /dev/null @@ -1,384 +0,0 @@ ---- -id: 0 -name: "Simulated deployment, used as a default for `clarinet console`, `clarinet test` and `clarinet check`" -network: simnet -genesis: - wallets: - - name: deployer - address: ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM - balance: "100000000000000" - - name: faucet - address: STNHKEPYEPJ8ET55ZZ0M5A34J0R3N5FM2CMMMAZ6 - balance: "100000000000000" - - name: wallet_1 - address: ST1SJ3DTE5DN7X54YDH5D64R3BCB6A2AG2ZQ8YPD5 - balance: "100000000000000" - - name: wallet_2 - address: ST2CY5V39NHDPWSXMW9QDT3HC3GD6Q6XX4CFRK9AG - balance: "100000000000000" - - name: wallet_3 - address: ST2JHG361ZXG51QTKY2NQCVBPPRRE2KZB1HR05NNC - balance: "100000000000000" - - name: wallet_4 - address: ST2NEB84ASENDXKYGJPQW86YXQCEFEX2ZQPG87ND - balance: "100000000000000" - - name: wallet_5 - address: ST2REHHS5J3CERCRBEPMGH7921Q6PYKAADT7JP2VB - balance: "100000000000000" - - name: wallet_6 - address: ST3AM1A56AK2C1XAFJ4115ZSV26EB49BVQ10MGCS0 - balance: "100000000000000" - - name: wallet_7 - address: ST3PF13W7Z0RRM42A8VZRVFQ75SV1K26RXEP8YGKJ - balance: "100000000000000" - - name: wallet_8 - address: ST3NBRSFKX28FQ2ZJ1MAKX58HKHSDGNV5N7R21XCP - balance: "100000000000000" - contracts: - - costs - - pox - - pox-2 - - pox-3 - - pox-4 - - lockup - - costs-2 - - costs-3 - - cost-voting - - bns -plan: - batches: - - id: 0 - transactions: - - emulated-contract-publish: - contract-name: nft-trait - emulated-sender: SP2PABAF9FTAJYNFZH93XENAJ8FVY99RRM50D2JG9 - path: "./.cache/requirements/SP2PABAF9FTAJYNFZH93XENAJ8FVY99RRM50D2JG9.nft-trait.clar" - clarity-version: 1 - - emulated-contract-publish: - contract-name: sip-010-trait-ft-standard - emulated-sender: SP3FBR2AGK5H9QBDH3EEN6DF8EK8JY7RX8QJ5SVTE - path: "./.cache/requirements/SP3FBR2AGK5H9QBDH3EEN6DF8EK8JY7RX8QJ5SVTE.sip-010-trait-ft-standard.clar" - clarity-version: 1 - epoch: "2.1" - - id: 1 - transactions: - - emulated-contract-publish: - contract-name: sip-010-trait-ft-standard - emulated-sender: ST3VXT52QEQPZ5246A16RFNMR1PRJ96JK6YYX37N8 - path: "./.cache/requirements/ST3VXT52QEQPZ5246A16RFNMR1PRJ96JK6YYX37N8.sip-010-trait-ft-standard.clar" - clarity-version: 2 - - emulated-contract-publish: - contract-name: token-stx-v-1-2 - emulated-sender: ST295MNE41DC74QYCPRS8N37YYMC06N6Q3VQDZ6G1 - path: "./.cache/requirements/ST295MNE41DC74QYCPRS8N37YYMC06N6Q3VQDZ6G1.token-stx-v-1-2.clar" - clarity-version: 2 - - emulated-contract-publish: - contract-name: xyk-pool-trait-v-1-2 - emulated-sender: ST3VXT52QEQPZ5246A16RFNMR1PRJ96JK6YYX37N8 - path: "./.cache/requirements/ST3VXT52QEQPZ5246A16RFNMR1PRJ96JK6YYX37N8.xyk-pool-trait-v-1-2.clar" - clarity-version: 2 - - emulated-contract-publish: - contract-name: xyk-core-v-1-2 - emulated-sender: ST295MNE41DC74QYCPRS8N37YYMC06N6Q3VQDZ6G1 - path: "./.cache/requirements/ST295MNE41DC74QYCPRS8N37YYMC06N6Q3VQDZ6G1.xyk-core-v-1-2.clar" - clarity-version: 2 - epoch: "2.5" - - id: 2 - transactions: - - emulated-contract-publish: - contract-name: aibtcdev-dao-traits-v1 - emulated-sender: ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM - path: contracts/dao/traits/aibtcdev-dao-traits-v1.clar - clarity-version: 2 - - emulated-contract-publish: - contract-name: aibtcdev-dao-v1 - emulated-sender: ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM - path: contracts/dao/traits/aibtcdev-dao-v1.clar - clarity-version: 2 - - emulated-contract-publish: - contract-name: aibtcdev-base-dao - emulated-sender: ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM - path: contracts/dao/aibtcdev-base-dao.clar - clarity-version: 2 - - emulated-contract-publish: - contract-name: aibtc-payments-invoices - emulated-sender: ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM - path: contracts/dao/extensions/aibtc-payments-invoices.clar - clarity-version: 2 - - emulated-contract-publish: - contract-name: aibtc-action-add-resource - emulated-sender: ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM - path: contracts/dao/extensions/actions/aibtc-action-add-resource.clar - clarity-version: 2 - - emulated-contract-publish: - contract-name: aibtc-treasury - emulated-sender: ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM - path: contracts/dao/extensions/aibtc-treasury.clar - clarity-version: 2 - - emulated-contract-publish: - contract-name: aibtc-action-allow-asset - emulated-sender: ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM - path: contracts/dao/extensions/actions/aibtc-action-allow-asset.clar - clarity-version: 2 - - emulated-contract-publish: - contract-name: aibtc-token - emulated-sender: ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM - path: contracts/dao/extensions/aibtc-token.clar - clarity-version: 2 - - emulated-contract-publish: - contract-name: aibtc-action-proposals - emulated-sender: ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM - path: contracts/dao/extensions/aibtc-action-proposals.clar - clarity-version: 2 - - emulated-contract-publish: - contract-name: aibtc-onchain-messaging - emulated-sender: ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM - path: contracts/dao/extensions/aibtc-onchain-messaging.clar - clarity-version: 2 - - emulated-contract-publish: - contract-name: aibtc-action-send-message - emulated-sender: ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM - path: contracts/dao/extensions/actions/aibtc-action-send-message.clar - clarity-version: 2 - - emulated-contract-publish: - contract-name: aibtc-bank-account - emulated-sender: ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM - path: contracts/dao/extensions/aibtc-bank-account.clar - clarity-version: 2 - - emulated-contract-publish: - contract-name: aibtc-action-set-account-holder - emulated-sender: ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM - path: contracts/dao/extensions/actions/aibtc-action-set-account-holder.clar - clarity-version: 2 - - emulated-contract-publish: - contract-name: aibtc-action-set-withdrawal-amount - emulated-sender: ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM - path: contracts/dao/extensions/actions/aibtc-action-set-withdrawal-amount.clar - clarity-version: 2 - - emulated-contract-publish: - contract-name: aibtc-action-set-withdrawal-period - emulated-sender: ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM - path: contracts/dao/extensions/actions/aibtc-action-set-withdrawal-period.clar - clarity-version: 2 - - emulated-contract-publish: - contract-name: aibtc-action-toggle-resource-by-name - emulated-sender: ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM - path: contracts/dao/extensions/actions/aibtc-action-toggle-resource-by-name.clar - clarity-version: 2 - - emulated-contract-publish: - contract-name: aibtc-bank-account-deposit-stx - emulated-sender: ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM - path: contracts/dao/proposals/aibtc-bank-account-deposit-stx.clar - clarity-version: 2 - - emulated-contract-publish: - contract-name: aibtc-bank-account-initialize-new-account - emulated-sender: ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM - path: contracts/dao/proposals/aibtc-bank-account-initialize-new-account.clar - clarity-version: 2 - - emulated-contract-publish: - contract-name: aibtc-bank-account-override-last-withdrawal-block - emulated-sender: ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM - path: contracts/dao/proposals/aibtc-bank-account-override-last-withdrawal-block.clar - clarity-version: 2 - - emulated-contract-publish: - contract-name: aibtc-bank-account-set-account-holder - emulated-sender: ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM - path: contracts/dao/proposals/aibtc-bank-account-set-account-holder.clar - clarity-version: 2 - - emulated-contract-publish: - contract-name: aibtc-bank-account-set-withdrawal-amount - emulated-sender: ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM - path: contracts/dao/proposals/aibtc-bank-account-set-withdrawal-amount.clar - clarity-version: 2 - - emulated-contract-publish: - contract-name: aibtc-bank-account-set-withdrawal-period - emulated-sender: ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM - path: contracts/dao/proposals/aibtc-bank-account-set-withdrawal-period.clar - clarity-version: 2 - - emulated-contract-publish: - contract-name: aibtc-bank-account-withdraw-stx - emulated-sender: ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM - path: contracts/dao/proposals/aibtc-bank-account-withdraw-stx.clar - clarity-version: 2 - - emulated-contract-publish: - contract-name: aibtc-base-add-new-extension - emulated-sender: ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM - path: contracts/dao/proposals/aibtc-base-add-new-extension.clar - clarity-version: 2 - - emulated-contract-publish: - contract-name: aibtc-base-bootstrap-initialization - emulated-sender: ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM - path: contracts/dao/proposals/aibtc-base-bootstrap-initialization.clar - clarity-version: 2 - epoch: "3.0" - - id: 3 - transactions: - - emulated-contract-publish: - contract-name: aibtc-base-disable-extension - emulated-sender: ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM - path: contracts/dao/proposals/aibtc-base-disable-extension.clar - clarity-version: 2 - - emulated-contract-publish: - contract-name: aibtc-base-enable-extension - emulated-sender: ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM - path: contracts/dao/proposals/aibtc-base-enable-extension.clar - clarity-version: 2 - - emulated-contract-publish: - contract-name: aibtc-base-replace-extension - emulated-sender: ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM - path: contracts/dao/proposals/aibtc-base-replace-extension.clar - clarity-version: 2 - - emulated-contract-publish: - contract-name: aibtc-bitflow-pool - emulated-sender: ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM - path: contracts/dao/extensions/aibtc-bitflow-pool.clar - clarity-version: 2 - - emulated-contract-publish: - contract-name: aibtc-core-proposals - emulated-sender: ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM - path: contracts/dao/extensions/aibtc-core-proposals.clar - clarity-version: 2 - - emulated-contract-publish: - contract-name: aibtc-onchain-messaging-send - emulated-sender: ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM - path: contracts/dao/proposals/aibtc-onchain-messaging-send.clar - clarity-version: 2 - - emulated-contract-publish: - contract-name: aibtc-payments-invoices-add-resource - emulated-sender: ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM - path: contracts/dao/proposals/aibtc-payments-invoices-add-resource.clar - clarity-version: 2 - - emulated-contract-publish: - contract-name: aibtc-payments-invoices-pay-invoice - emulated-sender: ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM - path: contracts/dao/proposals/aibtc-payments-invoices-pay-invoice.clar - clarity-version: 2 - - emulated-contract-publish: - contract-name: aibtc-payments-invoices-pay-invoice-by-resource-name - emulated-sender: ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM - path: contracts/dao/proposals/aibtc-payments-invoices-pay-invoice-by-resource-name.clar - clarity-version: 2 - - emulated-contract-publish: - contract-name: aibtc-payments-invoices-set-payment-address - emulated-sender: ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM - path: contracts/dao/proposals/aibtc-payments-invoices-set-payment-address.clar - clarity-version: 2 - - emulated-contract-publish: - contract-name: aibtc-payments-invoices-toggle-resource - emulated-sender: ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM - path: contracts/dao/proposals/aibtc-payments-invoices-toggle-resource.clar - clarity-version: 2 - - emulated-contract-publish: - contract-name: aibtc-payments-invoices-toggle-resource-by-name - emulated-sender: ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM - path: contracts/dao/proposals/aibtc-payments-invoices-toggle-resource-by-name.clar - clarity-version: 2 - - emulated-contract-publish: - contract-name: aibtc-token-dex - emulated-sender: ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM - path: contracts/dao/extensions/aibtc-token-dex.clar - clarity-version: 2 - - emulated-contract-publish: - contract-name: aibtc-token-owner - emulated-sender: ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM - path: contracts/dao/extensions/aibtc-token-owner.clar - clarity-version: 2 - - emulated-contract-publish: - contract-name: aibtc-token-owner-set-token-uri - emulated-sender: ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM - path: contracts/dao/proposals/aibtc-token-owner-set-token-uri.clar - clarity-version: 2 - - emulated-contract-publish: - contract-name: aibtc-token-owner-transfer-ownership - emulated-sender: ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM - path: contracts/dao/proposals/aibtc-token-owner-transfer-ownership.clar - clarity-version: 2 - - emulated-contract-publish: - contract-name: aibtc-treasury-allow-asset - emulated-sender: ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM - path: contracts/dao/proposals/aibtc-treasury-allow-asset.clar - clarity-version: 2 - - emulated-contract-publish: - contract-name: aibtc-treasury-delegate-stx - emulated-sender: ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM - path: contracts/dao/proposals/aibtc-treasury-delegate-stx.clar - clarity-version: 2 - - emulated-contract-publish: - contract-name: aibtc-treasury-deposit-ft - emulated-sender: ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM - path: contracts/dao/proposals/aibtc-treasury-deposit-ft.clar - clarity-version: 2 - - emulated-contract-publish: - contract-name: aibtcdev-airdrop-1 - emulated-sender: ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM - path: contracts/aibtcdev-airdrop-1.clar - clarity-version: 2 - - emulated-contract-publish: - contract-name: aibtc-treasury-deposit-nft - emulated-sender: ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM - path: contracts/dao/proposals/aibtc-treasury-deposit-nft.clar - clarity-version: 2 - - emulated-contract-publish: - contract-name: aibtc-treasury-deposit-stx - emulated-sender: ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM - path: contracts/dao/proposals/aibtc-treasury-deposit-stx.clar - clarity-version: 2 - - emulated-contract-publish: - contract-name: aibtc-treasury-freeze-asset - emulated-sender: ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM - path: contracts/dao/proposals/aibtc-treasury-freeze-asset.clar - clarity-version: 2 - - emulated-contract-publish: - contract-name: aibtc-treasury-revoke-delegation - emulated-sender: ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM - path: contracts/dao/proposals/aibtc-treasury-revoke-delegation.clar - clarity-version: 2 - - emulated-contract-publish: - contract-name: aibtc-treasury-withdraw-ft - emulated-sender: ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM - path: contracts/dao/proposals/aibtc-treasury-withdraw-ft.clar - clarity-version: 2 - epoch: "3.0" - - id: 4 - transactions: - - emulated-contract-publish: - contract-name: aibtc-treasury-withdraw-nft - emulated-sender: ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM - path: contracts/dao/proposals/aibtc-treasury-withdraw-nft.clar - clarity-version: 2 - - emulated-contract-publish: - contract-name: aibtc-treasury-withdraw-stx - emulated-sender: ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM - path: contracts/dao/proposals/aibtc-treasury-withdraw-stx.clar - clarity-version: 2 - - emulated-contract-publish: - contract-name: aibtcdev-airdrop-2 - emulated-sender: ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM - path: contracts/aibtcdev-airdrop-2.clar - clarity-version: 2 - - emulated-contract-publish: - contract-name: proxy - emulated-sender: ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM - path: contracts/test/proxy.clar - clarity-version: 2 - - emulated-contract-publish: - contract-name: test-proxy - emulated-sender: ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM - path: contracts/test/proxy.clar - clarity-version: 2 - - emulated-contract-publish: - contract-name: test-token - emulated-sender: ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM - path: contracts/test/sip010-token.clar - clarity-version: 2 - - emulated-contract-publish: - contract-name: test-treasury - emulated-sender: ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM - path: contracts/test/aibtc-treasury.clar - clarity-version: 2 - - emulated-contract-publish: - contract-name: external-proxy - emulated-sender: ST1SJ3DTE5DN7X54YDH5D64R3BCB6A2AG2ZQ8YPD5 - path: contracts/test/proxy.clar - clarity-version: 2 - epoch: "3.0" From e1fac3604e76b3c69f09b8a27792cf87783e531e Mon Sep 17 00:00:00 2001 From: Jason Schrader Date: Wed, 15 Jan 2025 00:17:27 -0700 Subject: [PATCH 19/19] feat: add codecov v5 with token --- .github/workflows/clarinet.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/clarinet.yml b/.github/workflows/clarinet.yml index c46eecd..56999c4 100644 --- a/.github/workflows/clarinet.yml +++ b/.github/workflows/clarinet.yml @@ -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 }}