Skip to content

Commit

Permalink
test: Add missing tests for bank account extension
Browse files Browse the repository at this point in the history
  • Loading branch information
whoabuddy committed Dec 24, 2024
1 parent cedae46 commit c54ecce
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 20 deletions.
20 changes: 0 additions & 20 deletions docs/smart-contract-test-plan.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
57 changes: 57 additions & 0 deletions tests/dao/extensions/aibtc-ext002-bank-account.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand Down Expand Up @@ -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", () => {
Expand Down Expand Up @@ -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 = {
Expand Down

0 comments on commit c54ecce

Please sign in to comment.