diff --git a/docs/smart-contract-test-plan.md b/docs/smart-contract-test-plan.md index 6528306e..ec5cbad4 100644 --- a/docs/smart-contract-test-plan.md +++ b/docs/smart-contract-test-plan.md @@ -57,26 +57,6 @@ set-voting-token() fails if token is not initialized set-voting-token() fails if token mismatches set-voting-token() succeeds and sets new token -### aibtc-ext002-bank-account - -set-account-holder() fails if caller is not DAO or extension -set-account-holder() succeeds and sets the account holder to a standard principal -set-account-holder() succeeds and sets the account holder to a contract principal - -set-withdrawal-period() fails if caller is not DAO or extension -set-withdrawal-period() fails if value is set to 0 -set-withdrawal-period() succeeds and sets the withdrawal period - -set-withdrawal-amount() fails if caller is not DAO or extension -set-withdrawal-amount() fails if value is set to 0 -set-withdrawal-amount() succeeds and sets the withdrawal amount - -override-last-withdrawal-block() fails if caller is not DAO or extension -override-last-withdrawal-block() fails if value is set to 0 -override-last-withdrawal-block() fails if value is set less than deployed height -override-last-withdrawal-block() succeeds and sets the withdrawal block - -get-account-terms() succeeds and returns expected values ### aibtc-ext003-direct-execute diff --git a/tests/dao/extensions/aibtc-ext002-bank-account.test.ts b/tests/dao/extensions/aibtc-ext002-bank-account.test.ts index 1bf2e121..02462e3a 100644 --- a/tests/dao/extensions/aibtc-ext002-bank-account.test.ts +++ b/tests/dao/extensions/aibtc-ext002-bank-account.test.ts @@ -64,6 +64,16 @@ describe("aibtc-ext002-bank-account", () => { ); 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", () => { @@ -160,6 +170,16 @@ describe("aibtc-ext002-bank-account", () => { ); 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", () => { @@ -296,6 +316,43 @@ describe("aibtc-ext002-bank-account", () => { }); }); + 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 = {