Skip to content

Commit

Permalink
add tests for checking repay events
Browse files Browse the repository at this point in the history
  • Loading branch information
lemunozm committed May 16, 2024
1 parent fe313ab commit 45b955c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 9 deletions.
2 changes: 1 addition & 1 deletion pallets/loans/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use super::{
ActivePricing, Pricing,
},
},
pallet::{ActiveLoans, CreatedLoan, Error, LastLoanId, PortfolioValuation},
pallet::{ActiveLoans, CreatedLoan, Error, Event, LastLoanId, PortfolioValuation},
types::{
policy::{WriteOffRule, WriteOffStatus, WriteOffTrigger},
valuation::{DiscountedCashFlow, ValuationMethod},
Expand Down
21 changes: 16 additions & 5 deletions pallets/loans/src/tests/repay_loan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,18 +162,29 @@ fn with_success_half_amount() {
let loan_id = util::create_loan(util::base_internal_loan());
util::borrow_loan(loan_id, PrincipalInput::Internal(COLLATERAL_VALUE / 2));

let amount = RepaidInput {
principal: PrincipalInput::Internal(COLLATERAL_VALUE / 2),
interest: 1234, /* Will not be used */
unscheduled: 0,
};

config_mocks(COLLATERAL_VALUE / 2);
assert_ok!(Loans::repay(
RuntimeOrigin::signed(BORROWER),
POOL_A,
loan_id,
RepaidInput {
principal: PrincipalInput::Internal(COLLATERAL_VALUE / 2),
interest: 0,
unscheduled: 0,
},
amount.clone()
));
assert_eq!(0, util::current_loan_debt(loan_id));

System::assert_last_event(RuntimeEvent::Loans(Event::Repaid {
pool_id: POOL_A,
loan_id: loan_id,
amount: RepaidInput {
interest: 0,
..amount
},
}));
});
}

Expand Down
17 changes: 14 additions & 3 deletions pallets/loans/src/tests/transfer_debt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ fn with_success_internals() {

let repay_amount = RepaidInput {
principal: PrincipalInput::Internal(COLLATERAL_VALUE),
interest: 0,
interest: 1234, /* Will not be used */
unscheduled: 0,
};
let borrow_amount = PrincipalInput::Internal(COLLATERAL_VALUE);
Expand All @@ -372,8 +372,8 @@ fn with_success_internals() {
POOL_A,
loan_1,
loan_2,
repay_amount,
borrow_amount,
repay_amount.clone(),
borrow_amount.clone(),
));

assert_ok!(Loans::apply_transfer_debt(
Expand All @@ -384,6 +384,17 @@ fn with_success_internals() {

assert_eq!(0, util::current_loan_debt(loan_1));
assert_eq!(COLLATERAL_VALUE, util::current_loan_debt(loan_2));

System::assert_last_event(RuntimeEvent::Loans(Event::DebtTransferred {
pool_id: POOL_A,
from_loan_id: loan_1,
to_loan_id: loan_2,
repaid_amount: RepaidInput {
interest: 0,
..repay_amount
},
borrow_amount,
}));
});
}

Expand Down

0 comments on commit 45b955c

Please sign in to comment.