Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: decrease debt #1857

Merged
merged 2 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions pallets/loans/src/tests/borrow_loan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -601,9 +601,22 @@ fn increase_debt_does_not_withdraw() {
let loan_id = util::create_loan(loan);

let amount = ExternalAmount::new(QUANTITY, PRICE_VALUE);
config_mocks(amount.balance().unwrap());
MockPrices::mock_get(|id, pool_id| {
assert_eq!(*pool_id, POOL_A);
match *id {
REGISTER_PRICE_ID => Ok((PRICE_VALUE, BLOCK_TIME_MS)),
_ => Err(PRICE_ID_NO_FOUND),
}
});
MockPrices::mock_register_id(|id, pool_id| {
assert_eq!(*pool_id, POOL_A);
match *id {
REGISTER_PRICE_ID => Ok(()),
_ => Err(PRICE_ID_NO_FOUND),
}
});

assert_ok!(Loans::borrow(
assert_ok!(Loans::increase_debt(
Copy link
Contributor

@lemunozm lemunozm Jun 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, amazing test haha. I had this modified in the cashflows. This is an example of how to not test correctly 😆

RuntimeOrigin::signed(BORROWER),
POOL_A,
loan_id,
Expand Down
41 changes: 41 additions & 0 deletions pallets/loans/src/tests/repay_loan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -978,3 +978,44 @@ fn with_external_pricing() {
assert_eq!(current_price(), NOTIONAL);
});
}

#[test]
fn decrease_debt_does_not_deposit() {
new_test_ext().execute_with(|| {
MockPools::mock_deposit(|_, _, _| {
unreachable!("increase debt must not withdraw funds from the pool");
});

let loan = LoanInfo {
pricing: Pricing::External(ExternalPricing {
max_borrow_amount: ExtMaxBorrowAmount::NoLimit,
..util::base_external_pricing()
}),
..util::base_external_loan()
};

let loan_id = util::create_loan(loan);

let amount = ExternalAmount::new(QUANTITY, PRICE_VALUE);
util::borrow_loan(loan_id, PrincipalInput::External(amount.clone()));

MockPrices::mock_get(move |id, pool_id| {
assert_eq!(*pool_id, POOL_A);
match *id {
REGISTER_PRICE_ID => Ok((PRICE_VALUE, BLOCK_TIME_MS)),
_ => Err(PRICE_ID_NO_FOUND),
}
});

assert_ok!(Loans::decrease_debt(
RuntimeOrigin::signed(BORROWER),
POOL_A,
loan_id,
RepaidInput {
principal: PrincipalInput::External(amount),
interest: 0,
unscheduled: 0,
}
));
});
}
Loading