Skip to content

Commit c54ecce

Browse files
committed
test: Add missing tests for bank account extension
1 parent cedae46 commit c54ecce

File tree

2 files changed

+57
-20
lines changed

2 files changed

+57
-20
lines changed

docs/smart-contract-test-plan.md

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -57,26 +57,6 @@ set-voting-token() fails if token is not initialized
5757
set-voting-token() fails if token mismatches
5858
set-voting-token() succeeds and sets new token
5959

60-
### aibtc-ext002-bank-account
61-
62-
set-account-holder() fails if caller is not DAO or extension
63-
set-account-holder() succeeds and sets the account holder to a standard principal
64-
set-account-holder() succeeds and sets the account holder to a contract principal
65-
66-
set-withdrawal-period() fails if caller is not DAO or extension
67-
set-withdrawal-period() fails if value is set to 0
68-
set-withdrawal-period() succeeds and sets the withdrawal period
69-
70-
set-withdrawal-amount() fails if caller is not DAO or extension
71-
set-withdrawal-amount() fails if value is set to 0
72-
set-withdrawal-amount() succeeds and sets the withdrawal amount
73-
74-
override-last-withdrawal-block() fails if caller is not DAO or extension
75-
override-last-withdrawal-block() fails if value is set to 0
76-
override-last-withdrawal-block() fails if value is set less than deployed height
77-
override-last-withdrawal-block() succeeds and sets the withdrawal block
78-
79-
get-account-terms() succeeds and returns expected values
8060

8161
### aibtc-ext003-direct-execute
8262

tests/dao/extensions/aibtc-ext002-bank-account.test.ts

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,16 @@ describe("aibtc-ext002-bank-account", () => {
6464
);
6565
expect(response.result).toBeErr(Cl.uint(ErrCode.ERR_INVALID));
6666
});
67+
68+
it("succeeds when deployer sets a contract principal as account holder", () => {
69+
const response = simnet.callPublicFn(
70+
contractAddress,
71+
"set-account-holder",
72+
[Cl.principal(`${addressDeployer}.test-proxy`)],
73+
addressDeployer
74+
);
75+
expect(response.result).toBeOk(Cl.bool(true));
76+
});
6777
});
6878

6979
describe("set-withdrawal-period", () => {
@@ -160,6 +170,16 @@ describe("aibtc-ext002-bank-account", () => {
160170
);
161171
expect(response.result).toBeErr(Cl.uint(ErrCode.ERR_INVALID));
162172
});
173+
174+
it("fails when deployer sets a block height less than deployed height", () => {
175+
const response = simnet.callPublicFn(
176+
contractAddress,
177+
"override-last-withdrawal-block",
178+
[Cl.uint(1)],
179+
addressDeployer
180+
);
181+
expect(response.result).toBeErr(Cl.uint(ErrCode.ERR_INVALID));
182+
});
163183
});
164184

165185
describe("deposit-stx", () => {
@@ -296,6 +316,43 @@ describe("aibtc-ext002-bank-account", () => {
296316
});
297317
});
298318

319+
describe("get-account-terms", () => {
320+
it("succeeds and returns all account terms", () => {
321+
// First set up some state
322+
simnet.callPublicFn(
323+
contractAddress,
324+
"deposit-stx",
325+
[Cl.uint(100000000)],
326+
address1
327+
);
328+
simnet.callPublicFn(
329+
contractAddress,
330+
"set-account-holder",
331+
[Cl.principal(address1)],
332+
addressDeployer
333+
);
334+
335+
const expectedResponse = {
336+
accountBalance: Cl.uint(100000000),
337+
accountHolder: Cl.principal(address1),
338+
contractName: Cl.principal(contractAddress),
339+
deployedAt: Cl.uint(0), // In test environment this is 0
340+
lastWithdrawalBlock: Cl.uint(0),
341+
withdrawalAmount: Cl.uint(withdrawalAmount),
342+
withdrawalPeriod: Cl.uint(withdrawalPeriod),
343+
};
344+
345+
const response = simnet.callReadOnlyFn(
346+
contractAddress,
347+
"get-account-terms",
348+
[],
349+
address1
350+
).result;
351+
352+
expect(response).toBeTuple(expectedResponse);
353+
});
354+
});
355+
299356
describe("get-all-vars", () => {
300357
it("succeeds and returns all the variables", () => {
301358
const expectedResponse = {

0 commit comments

Comments
 (0)