From fc8cbe61d5a23f82fb1bec007805b617a6d82eee Mon Sep 17 00:00:00 2001 From: Jason Schrader Date: Tue, 24 Dec 2024 14:40:28 -0700 Subject: [PATCH] fix: start cleaning up tests with latest changes --- deployments/default.simnet-plan.yaml | 43 +- .../extensions/aibtc-ext001-actions.test.ts | 25 ++ .../aibtc-ext002-bank-account.test.ts | 391 +----------------- 3 files changed, 74 insertions(+), 385 deletions(-) create mode 100644 tests/dao/extensions/aibtc-ext001-actions.test.ts diff --git a/deployments/default.simnet-plan.yaml b/deployments/default.simnet-plan.yaml index 21ce0aa..312568a 100644 --- a/deployments/default.simnet-plan.yaml +++ b/deployments/default.simnet-plan.yaml @@ -48,6 +48,9 @@ genesis: plan: batches: - id: 0 + transactions: [] + epoch: "2.0" + - id: 1 transactions: - emulated-contract-publish: contract-name: nft-trait @@ -59,8 +62,26 @@ plan: emulated-sender: SP3FBR2AGK5H9QBDH3EEN6DF8EK8JY7RX8QJ5SVTE path: "./.cache/requirements/SP3FBR2AGK5H9QBDH3EEN6DF8EK8JY7RX8QJ5SVTE.sip-010-trait-ft-standard.clar" clarity-version: 1 - epoch: "2.0" - - id: 1 + epoch: "2.1" + - id: 2 + transactions: [] + epoch: "2.1" + - id: 3 + transactions: [] + epoch: "2.1" + - id: 4 + transactions: [] + epoch: "2.1" + - id: 5 + transactions: [] + epoch: "2.1" + - id: 6 + transactions: [] + epoch: "2.1" + - id: 7 + transactions: [] + epoch: "2.1" + - id: 8 transactions: - emulated-contract-publish: contract-name: aibtcdev-dao-traits-v1 @@ -138,3 +159,21 @@ plan: path: contracts/test-proxy.clar clarity-version: 2 epoch: "2.5" + - id: 9 + transactions: [] + epoch: "2.5" + - id: 10 + transactions: [] + epoch: "2.5" + - id: 11 + transactions: [] + epoch: "2.5" + - id: 12 + transactions: [] + epoch: "2.5" + - id: 13 + transactions: [] + epoch: "2.5" + - id: 14 + transactions: [] + epoch: "2.5" diff --git a/tests/dao/extensions/aibtc-ext001-actions.test.ts b/tests/dao/extensions/aibtc-ext001-actions.test.ts new file mode 100644 index 0000000..9adff95 --- /dev/null +++ b/tests/dao/extensions/aibtc-ext001-actions.test.ts @@ -0,0 +1,25 @@ +import { Cl } from "@stacks/transactions"; +import { describe, expect, it } from "vitest"; + +const accounts = simnet.getAccounts(); +const address1 = accounts.get("wallet_1")!; +const address2 = accounts.get("wallet_2")!; +const addressDeployer = accounts.get("deployer")!; + +const contractAddress = `${addressDeployer}.aibtc-ext001-actions`; + +enum ErrCode { + ERR_UNAUTHORIZED = 1000, + ERR_NOT_DAO_OR_EXTENSION, + ERR_NOT_INITIALIZED = 1100, + ERR_ALREADY_INITIALIZED, + ERR_TREASURY_MUST_BE_CONTRACT = 1200, + ERR_TREASURY_CANNOT_BE_SELF, + ERR_TREASURY_ALREADY_SET, + ERR_TREASURY_MISMATCH, +} + +const withdrawalAmount = 10000000; // 10 STX +const withdrawalPeriod = 144; // 144 blocks + +describe("aibtc-ext001-actions", () => {}); diff --git a/tests/dao/extensions/aibtc-ext002-bank-account.test.ts b/tests/dao/extensions/aibtc-ext002-bank-account.test.ts index 02462e3..b703222 100644 --- a/tests/dao/extensions/aibtc-ext002-bank-account.test.ts +++ b/tests/dao/extensions/aibtc-ext002-bank-account.test.ts @@ -6,391 +6,16 @@ const address1 = accounts.get("wallet_1")!; const address2 = accounts.get("wallet_2")!; const addressDeployer = accounts.get("deployer")!; -const contractAddress = `${addressDeployer}.aibtcdev-bank-account`; +const contractAddress = `${addressDeployer}.aibtc-ext002-bank-account`; enum ErrCode { - ERR_INVALID = 1000, - ERR_UNAUTHORIZED = 1001, - ERR_TOO_SOON = 1002, + ERR_INVALID = 2000, + ERR_UNAUTHORIZED, + ERR_TOO_SOON, + ERR_INVALID_AMOUNT, } -const withdrawalAmount = 10000000; -const withdrawalPeriod = 144; +const withdrawalAmount = 10000000; // 10 STX +const withdrawalPeriod = 144; // 144 blocks -describe("aibtc-ext002-bank-account", () => { - describe("set-account-holder", () => { - it("succeeds when deployer sets a valid account holder", () => { - const response = simnet.callPublicFn( - contractAddress, - "set-account-holder", - [Cl.principal(address1)], - addressDeployer - ); - expect(response.result).toBeOk(Cl.bool(true)); - }); - - it("succeeds when deployer sets a valid account holder a second time", () => { - simnet.callPublicFn( - contractAddress, - "set-account-holder", - [Cl.principal(address1)], - addressDeployer - ); - const response = simnet.callPublicFn( - contractAddress, - "set-account-holder", - [Cl.principal(address2)], - addressDeployer - ); - expect(response.result).toBeOk(Cl.bool(true)); - }); - - it("fails when a non-deployer tries to set the account holder", () => { - const response = simnet.callPublicFn( - contractAddress, - "set-account-holder", - [Cl.principal(address1)], - address1 - ); - expect(response.result).toBeErr(Cl.uint(ErrCode.ERR_UNAUTHORIZED)); - }); - - it("fails if the deployer tries to set an invalid account holder", () => { - const response = simnet.callPublicFn( - contractAddress, - "set-account-holder", - [Cl.principal(contractAddress)], - addressDeployer - ); - expect(response.result).toBeErr(Cl.uint(ErrCode.ERR_INVALID)); - }); - - it("succeeds when deployer sets a contract principal as account holder", () => { - const response = simnet.callPublicFn( - contractAddress, - "set-account-holder", - [Cl.principal(`${addressDeployer}.test-proxy`)], - addressDeployer - ); - expect(response.result).toBeOk(Cl.bool(true)); - }); - }); - - describe("set-withdrawal-period", () => { - it("succeeds when deployer sets a valid period", () => { - const response = simnet.callPublicFn( - contractAddress, - "set-withdrawal-period", - [Cl.uint(200)], - addressDeployer - ); - expect(response.result).toBeOk(Cl.bool(true)); - }); - - it("fails when a non-deployer tries to set the period", () => { - const response = simnet.callPublicFn( - contractAddress, - "set-withdrawal-period", - [Cl.uint(200)], - address1 - ); - expect(response.result).toBeErr(Cl.uint(ErrCode.ERR_UNAUTHORIZED)); - }); - - it("fails when deployer sets an invalid period", () => { - const response = simnet.callPublicFn( - contractAddress, - "set-withdrawal-period", - [Cl.uint(0)], - addressDeployer - ); - expect(response.result).toBeErr(Cl.uint(ErrCode.ERR_INVALID)); - }); - }); - - describe("set-withdrawal-amount", () => { - it("succeeds when deployer sets a valid amount", () => { - const response = simnet.callPublicFn( - contractAddress, - "set-withdrawal-amount", - [Cl.uint(15000000)], - addressDeployer - ); - expect(response.result).toBeOk(Cl.bool(true)); - }); - - it("fails when a non-deployer tries to set the amount", () => { - const response = simnet.callPublicFn( - contractAddress, - "set-withdrawal-amount", - [Cl.uint(15000000)], - address1 - ); - expect(response.result).toBeErr(Cl.uint(ErrCode.ERR_UNAUTHORIZED)); - }); - - it("fails when deployer sets an invalid amount", () => { - const response = simnet.callPublicFn( - contractAddress, - "set-withdrawal-amount", - [Cl.uint(0)], - addressDeployer - ); - expect(response.result).toBeErr(Cl.uint(ErrCode.ERR_INVALID)); - }); - }); - - describe("override-last-withdrawal-block", () => { - it("succeeds when deployer sets a valid block height", () => { - const response = simnet.callPublicFn( - contractAddress, - "override-last-withdrawal-block", - [Cl.uint(500)], - addressDeployer - ); - expect(response.result).toBeOk(Cl.bool(true)); - }); - - it("fails when a non-deployer tries to set the block height", () => { - const response = simnet.callPublicFn( - contractAddress, - "override-last-withdrawal-block", - [Cl.uint(500)], - address1 - ); - expect(response.result).toBeErr(Cl.uint(ErrCode.ERR_UNAUTHORIZED)); - }); - - it("fails when deployer sets an invalid block height", () => { - const response = simnet.callPublicFn( - contractAddress, - "override-last-withdrawal-block", - [Cl.uint(0)], - addressDeployer - ); - expect(response.result).toBeErr(Cl.uint(ErrCode.ERR_INVALID)); - }); - - it("fails when deployer sets a block height less than deployed height", () => { - const response = simnet.callPublicFn( - contractAddress, - "override-last-withdrawal-block", - [Cl.uint(1)], - addressDeployer - ); - expect(response.result).toBeErr(Cl.uint(ErrCode.ERR_INVALID)); - }); - }); - - describe("deposit-stx", () => { - it("succeeds when user deposits STX into the contract", () => { - const response = simnet.callPublicFn( - contractAddress, - "deposit-stx", - [Cl.uint(10000000)], - address1 - ); - expect(response.result).toBeOk(Cl.bool(true)); - }); - }); - - describe("withdraw-stx", () => { - it("succeeds when an authorized user withdraws STX", () => { - // arrange - simnet.callPublicFn( - contractAddress, - "deposit-stx", - [Cl.uint(100000000)], - address1 - ); - simnet.callPublicFn( - contractAddress, - "set-account-holder", - [Cl.principal(address1)], - addressDeployer - ); - simnet.mineEmptyBlocks(200); - const response = simnet.callPublicFn( - contractAddress, - "withdraw-stx", - [], - address1 - ); - expect(response.result).toBeOk(Cl.bool(true)); - }); - - it("fails when a non-authorized user tries to withdraw", () => { - const response = simnet.callPublicFn( - contractAddress, - "withdraw-stx", - [], - address2 - ); - expect(response.result).toBeErr(Cl.uint(ErrCode.ERR_UNAUTHORIZED)); - }); - - it("fails when the user tries to withdraw too soon", () => { - simnet.callPublicFn( - contractAddress, - "set-account-holder", - [Cl.principal(address1)], - addressDeployer - ); - simnet.callPublicFn( - contractAddress, - "override-last-withdrawal-block", - [Cl.uint(simnet.blockHeight)], - addressDeployer - ); - const response = simnet.callPublicFn( - contractAddress, - "withdraw-stx", - [], - address1 - ); - expect(response.result).toBeErr(Cl.uint(ErrCode.ERR_TOO_SOON)); - }); - }); - - describe("get-account-balance", () => { - it("succeeds and returns the contract balance", () => { - const response = simnet.callReadOnlyFn( - contractAddress, - "get-account-balance", - [], - addressDeployer - ); - expect(response.result).toBeUint(0); - }); - - it("succeeds and returns the contract balance after deposit", () => { - simnet.callPublicFn( - contractAddress, - "deposit-stx", - [Cl.uint(100000000)], - address1 - ); - const response = simnet.callReadOnlyFn( - contractAddress, - "get-account-balance", - [], - addressDeployer - ); - expect(response.result).toBeUint(100000000); - }); - }); - - describe("get-withdrawal-period", () => { - it("succeeds and returns the withdrawal period", () => { - const response = simnet.callReadOnlyFn( - contractAddress, - "get-withdrawal-period", - [], - address1 - ); - expect(response.result).toBeUint(withdrawalPeriod); - }); - }); - - describe("get-withdrawal-amount", () => { - it("succeeds and returns the withdrawal amount", () => { - const response = simnet.callReadOnlyFn( - contractAddress, - "get-withdrawal-amount", - [], - address1 - ); - expect(response.result).toBeUint(withdrawalAmount); - }); - }); - - describe("get-last-withdrawal-block", () => { - it("succeeds and returns the last withdrawal block", () => { - const response = simnet.callReadOnlyFn( - contractAddress, - "get-last-withdrawal-block", - [], - address1 - ); - expect(response.result).toBeUint(0); - }); - }); - - describe("get-account-terms", () => { - it("succeeds and returns all account terms", () => { - // First set up some state - simnet.callPublicFn( - contractAddress, - "deposit-stx", - [Cl.uint(100000000)], - address1 - ); - simnet.callPublicFn( - contractAddress, - "set-account-holder", - [Cl.principal(address1)], - addressDeployer - ); - - const expectedResponse = { - accountBalance: Cl.uint(100000000), - accountHolder: Cl.principal(address1), - contractName: Cl.principal(contractAddress), - deployedAt: Cl.uint(0), // In test environment this is 0 - lastWithdrawalBlock: Cl.uint(0), - withdrawalAmount: Cl.uint(withdrawalAmount), - withdrawalPeriod: Cl.uint(withdrawalPeriod), - }; - - const response = simnet.callReadOnlyFn( - contractAddress, - "get-account-terms", - [], - address1 - ).result; - - expect(response).toBeTuple(expectedResponse); - }); - }); - - describe("get-all-vars", () => { - it("succeeds and returns all the variables", () => { - const expectedResponse = { - withdrawalPeriod: Cl.uint(withdrawalPeriod), - withdrawalAmount: Cl.uint(withdrawalAmount), - lastWithdrawalBlock: Cl.uint(0), - }; - - const response = simnet.callReadOnlyFn( - contractAddress, - "get-all-vars", - [], - address1 - ).result; - - expect(response).toBeTuple(expectedResponse); - }); - }); - - describe("get-standard-caller", () => { - it("succeeds and returns the caller", () => { - const response = simnet.callReadOnlyFn( - contractAddress, - "get-standard-caller", - [], - address1 - ); - expect(response.result).toBePrincipal(address1); - }); - - it("succeeds and returns the caller with a proxy", () => { - const response = simnet.callPublicFn( - "test-proxy", - "get-standard-caller", - [], - address1 - ); - expect(response.result).toBeOk(Cl.principal(addressDeployer)); - }); - }); -}); +describe("aibtc-ext002-bank-account", () => {});