Skip to content

Commit

Permalink
Make all tests working on merge before the great merge
Browse files Browse the repository at this point in the history
  • Loading branch information
1ixi1 committed Jun 15, 2023
1 parent a2ea10c commit 374738c
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 17 deletions.
2 changes: 1 addition & 1 deletion PoolConstants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export abstract class Op {
}
static readonly pool = {
request_loan : 0x7ccd46e9,
repay_loan : 0xdfdca27b,
loan_repayment : 0xdfdca27b,
deposit : 0x47d54391,
withdraw : 0x319b0cdc, //TODO
withdrawal : 0x31777cdc, //TODO
Expand Down
8 changes: 4 additions & 4 deletions contracts/controller.func
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ int check_new_stake_msg(slice cs);
state = state::REST;
}
} elseif (equal_slice_bits(sender_address, pool)) {
if(op == pool::repay_loan) {
if(op == pool::loan_repayment) {
borrowed_amount += msg_value;
borrowing_time = now();
} elseif (op == pool::request_loan) {
Expand All @@ -135,7 +135,7 @@ int check_new_stake_msg(slice cs);
if(balance >= MIN_TONS_FOR_STORAGE + borrowed_amount) {
send_msg(pool,
borrowed_amount, ;; TODO add fee???
begin_cell().store_body_header(pool::repay_loan, query_id).end_cell(),
begin_cell().store_body_header(pool::loan_repayment, query_id).end_cell(),
msgflag::BOUNCEABLE,
sendmode::PAY_FEES_SEPARETELY); ;; remaining inbound message amount, fee deducted from
borrowed_amount = 0;
Expand Down Expand Up @@ -203,7 +203,7 @@ int check_new_stake_msg(slice cs);
available_funds = min( available_funds, borrowed_amount);
send_msg(pool,
available_funds,
begin_cell().store_body_header(pool::repay_loan, query_id).end_cell(),
begin_cell().store_body_header(pool::loan_repayment, query_id).end_cell(),
msgflag::BOUNCEABLE,
sendmode::PAY_FEES_SEPARETELY); ;; remaining inbound message amount, fee deducted from
borrowed_amount -= available_funds;
Expand Down Expand Up @@ -391,7 +391,7 @@ int check_new_stake_msg(slice cs);
if(balance >= MIN_TONS_FOR_STORAGE + borrowed_amount) {
send_msg(pool,
borrowed_amount, ;; TODO add fee???
begin_cell().store_body_header(pool::repay_loan, query_id).end_cell(),
begin_cell().store_body_header(pool::loan_repayment, query_id).end_cell(),
msgflag::BOUNCEABLE,
sendmode::PAY_FEES_SEPARETELY); ;; remaining inbound message amount, fee deducted from
borrowed_amount = 0;
Expand Down
2 changes: 1 addition & 1 deletion contracts/op-codes.func
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const int controller::send_request_loan = 0x452f7112;

{- ======== Validator Pool OPCODES ========== -}
const int pool::request_loan = 0x7ccd46e9;
const int pool::repay_loan = 0xdfdca27b;
const int pool::loan_repayment = 0xdfdca27b;
const int pool::deposit = 0x47d54391;
const int pool::withdraw = 0x319b0cdc; ;;TODO
const int pool::withdrawal = 0x31777cdc; ;;TODO
Expand Down
4 changes: 2 additions & 2 deletions contracts/pool.func
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ int current_round_index();
} else {
assert_not_halted!();
update_round();
;; it is ok, controller knew how to process repay_loan/request_loan bounces
;; it is ok, controller knew how to process loan_repayment/request_loan bounces
{- ========== Pool operations ========== -}
if (op == pool::request_loan) {

Expand Down Expand Up @@ -260,7 +260,7 @@ int current_round_index();
.store_uint(max_interest, 16),
msgflag::NON_BOUNCEABLE, sendmode::PAY_FEES_SEPARETELY);

} elseif (op == pool::repay_loan) {
} elseif (op == pool::loan_repayment) {
;; we expect loans from previous round only
;; note, close_loan finalize round if last loan is closed
(int closed, int last_one) = prev_round_borrowers~close_loan(sender_address, msg_value);
Expand Down
1 change: 1 addition & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { Config } from 'jest';
const config: Config = {
preset: 'ts-jest',
testEnvironment: 'node',
testTimeout: 150000
};

export default config;
8 changes: 4 additions & 4 deletions tests/Controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -861,7 +861,7 @@ describe('Cotroller mock', () => {
expect(res.transactions).toHaveTransaction({
from: controller.address,
to: poolAddress,
op: Op.pool.repay_loan,
op: Op.pool.loan_repayment,
value: dataBefore.borrowedAmount /*- fwdFees.fees - fwdFees.remaining*/
});
expect(res.transactions).toHaveTransaction({
Expand Down Expand Up @@ -894,7 +894,7 @@ describe('Cotroller mock', () => {
expect(res.transactions).toHaveTransaction({
from: controller.address,
to: poolAddress,
op: Op.pool.repay_loan,
op: Op.pool.loan_repayment,
value: dataBefore.borrowedAmount
});

Expand All @@ -920,7 +920,7 @@ describe('Cotroller mock', () => {
expect(res.transactions).toHaveTransaction({
from: controller.address,
to: poolAddress,
op: Op.pool.repay_loan,
op: Op.pool.loan_repayment,
value: dataBefore.borrowedAmount
});
// No reward message
Expand Down Expand Up @@ -1425,7 +1425,7 @@ describe('Cotroller mock', () => {

expect(repayMsg.info.dest).toEqualAddress(poolAddress);
expect(repayMsg.info.value.coins).toEqual(stateBefore.borrowedAmount);
expect(repayMsg.body.beginParse().preloadUint(32)).toEqual(Op.pool.repay_loan);
expect(repayMsg.body.beginParse().preloadUint(32)).toEqual(Op.pool.loan_repayment);

// Should revert to rest state
const dataAfter = await controller.getControllerData();
Expand Down
2 changes: 0 additions & 2 deletions tests/ControllerPool.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ describe('Controller & Pool', () => {
let poolConfig: PoolConfig;
let controllerConfig: ControllerConfig;

jest.setTimeout(60000);

const readState = async (addr: Address) => {
const cSmc = await blockchain.getContract(addr);
let state = -1; // no account
Expand Down
2 changes: 1 addition & 1 deletion tests/Smoke.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ describe('Pool', () => {
//await blockchain.setVerbosityForAddress(pool.address, {blockchainLogs:true, vmLogs: 'vm_logs'});
const secondDeposit = await pool.sendDeposit(deployer.getSender(), toNano('1000000'));

const controllerDeployResult = await controller.sendLoanRequest(deployer.getSender(), toNano('1000'), toNano('10000'), 1000n);
const controllerDeployResult = await controller.sendRequestLoan(deployer.getSender(), toNano('1000'), toNano('10000'), 1000);
expect(controllerDeployResult.transactions).toHaveTransaction({
from: deployer.address,
to: controller.address,
Expand Down
3 changes: 1 addition & 2 deletions wrappers/ValidatorUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,8 +315,7 @@ export const calcMaxPunishment = (stake: bigint, config: Cell | ConfigDict) => {
fine = fine * medium_flat_mult; fine >>= 8;
fine_part = fine_part * rec.medium_proportional_mult; fine_part >>= 8;
*/

fine = fine + (stake * fine_part / BigInt(1 << 32));
fine = fine + (stake * fine_part / (1n << 32n));
// console.log(stake);
if(fine > stake)
return stake;
Expand Down

0 comments on commit 374738c

Please sign in to comment.