Skip to content

Commit

Permalink
interest rate in get method. interest rate check test
Browse files Browse the repository at this point in the history
  • Loading branch information
1ixi1 committed Jun 10, 2023
1 parent 34ecb08 commit 3e2713a
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ node_modules
temp
build
yarn.lock
vim.session
4 changes: 2 additions & 2 deletions contracts/pool.func
Original file line number Diff line number Diff line change
Expand Up @@ -602,9 +602,9 @@ slice get_current_round_withdrawal_minter() method_id {
return withdrawal_payout;
}

(int, int, int, int, slice) get_finance_data() method_id {
(int, int, int, int, slice, int) get_finance_data() method_id {
load_data();
return (total_balance, supply, requested_for_deposit, requested_for_withdrawal, jetton_minter);
return (total_balance, supply, requested_for_deposit, requested_for_withdrawal, jetton_minter, interest_rate);
}

(slice) _get_controller_address(int controller_id, slice validator) inline {
Expand Down
2 changes: 1 addition & 1 deletion tests/ControllerPool.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ are both starting as a message from controller to pool.
Pool should accept it only from controllers that were minted by this pool
with exact approver. Tests are need to cover

Selected interest rate should be greater or eqal to pool's interest
Selected interest rate should be greater or equal to pool's interest

Then pool should correctly add the loan to it's list.

Expand Down
35 changes: 35 additions & 0 deletions tests/ControllerPool.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const errors = {
TOO_EARLY_LOAN_REQUEST: 0xfa02,
TOO_LATE_LOAN_REQUEST: 0xfa03,
TOO_HIGH_LOAN_REQUEST_AMOUNT: 0xfa04,
INTEREST_TOO_LOW: 0xf100
};


Expand Down Expand Up @@ -216,5 +217,39 @@ describe('Controller & Pool', () => {
expect(requestLoanResult.vmLogs).toContain("terminating vm with exit code " + errors.WRONG_SENDER);
expect(bounced.body.beginParse().loadUint(32)).toEqual(0xFFFFFFFF);
});

it('should not accept loan from another approver\'s controller', async () => {
let anotherPoolConfig = {...poolConfig};
const approver = await blockchain.treasury('approver');
anotherPoolConfig.approver = approver.address;
const anotherPool = blockchain.openContract(Pool.createFromConfig(anotherPoolConfig, pool_code));
let anotherControllerConfig = {...controllerConfig};
anotherControllerConfig.pool = anotherPool.address;
const anotherController = blockchain.openContract(Controller.createFromConfig(anotherControllerConfig, controller_code));

const poolSmc = await blockchain.getContract(pool.address);
const requestLoanResult = poolSmc.receiveMessage(internal({
from: anotherController.address,
to: pool.address,
value: toNano('0.5'),
body: loanRequestBodyToPool
}));
expect(requestLoanResult.vmLogs).toContain(
"terminating vm with exit code " + errors.WRONG_SENDER);
});

it('should not accept loan with low interest rate', async () => {
const { interestRate } = await pool.getFinanceData();
const requestLoanResult1 = await controller.sendLoanRequest(deployer.getSender(), toNano('100000'), toNano('320000'), interestRate - 1);
expect(requestLoanResult1.transactions).toHaveTransaction({
from: controller.address,
to: pool.address,
success: false,
exitCode: errors.INTEREST_TOO_LOW,
});
const requestLoanResult2 = await controller.sendLoanRequest(deployer.getSender(), toNano('100000'), toNano('320000'), interestRate);
expect(requestLoanResult2.transactions).toHaveTransaction({ to: pool.address, success: true });
});

});
});
4 changes: 3 additions & 1 deletion wrappers/Pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ export class Pool implements Contract {
let supply = res.stack.readBigNumber();
let requestedForDeposit = res.stack.readBigNumber();
let requestedForWithdrawal = res.stack.readBigNumber();
return {totalBalance, supply, requestedForDeposit, requestedForWithdrawal};
res.stack.readCell();
let interestRate = res.stack.readNumber();
return {totalBalance, supply, requestedForDeposit, requestedForWithdrawal, interestRate};
}
}

0 comments on commit 3e2713a

Please sign in to comment.