Skip to content

Commit

Permalink
fix benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
lemunozm committed May 9, 2024
1 parent a864ad4 commit 39eb12d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
31 changes: 27 additions & 4 deletions pallets/loans/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use cfg_traits::{
benchmarking::FundedPoolBenchmarkHelper,
changes::ChangeGuard,
interest::{CompoundingSchedule, InterestAccrual, InterestRate},
Permissions, PoolWriteOffPolicyMutate, Seconds, TimeAsSecs, ValueProvider,
Permissions, PoolWriteOffPolicyMutate, TimeAsSecs, ValueProvider,
};
use cfg_types::{
adjustments::Adjustment,
Expand Down Expand Up @@ -46,7 +46,6 @@ use crate::{
},
};

const OFFSET: Seconds = 120;
const COLLECION_ID: u16 = 42;
const COLLATERAL_VALUE: u128 = 1_000_000;
const FUNDS: u128 = 1_000_000_000;
Expand Down Expand Up @@ -126,7 +125,7 @@ where
fn base_loan(item_id: T::ItemId) -> LoanInfo<T> {
LoanInfo {
schedule: RepaymentSchedule {
maturity: Maturity::fixed(T::Time::now() + OFFSET),
maturity: Maturity::fixed(T::Time::now() + 120),
interest_payments: InterestPayments::None,
pay_down_schedule: PayDownSchedule::None,
},
Expand Down Expand Up @@ -171,6 +170,30 @@ where
LastLoanId::<T>::get(pool_id)
}

fn create_cashflow_loan(pool_id: T::PoolId, item_id: T::ItemId) -> T::LoanId {
let borrower = account("borrower", 0, 0);

T::NonFungible::mint_into(&COLLECION_ID.into(), &item_id, &borrower).unwrap();

let maturity_offset = 40 * 365 * 24 * 3600; // 40 years

Pallet::<T>::create(
RawOrigin::Signed(borrower).into(),
pool_id,
LoanInfo {
schedule: RepaymentSchedule {
maturity: Maturity::fixed(T::Time::now() + maturity_offset),
interest_payments: InterestPayments::Monthly(1),
pay_down_schedule: PayDownSchedule::None,
},
..Self::base_loan(item_id)
},
)
.unwrap();

LastLoanId::<T>::get(pool_id)
}

fn borrow_loan(pool_id: T::PoolId, loan_id: T::LoanId) {
let borrower = account("borrower", 0, 0);
Pallet::<T>::borrow(
Expand Down Expand Up @@ -342,7 +365,7 @@ benchmarks! {

let borrower = account("borrower", 0, 0);
let pool_id = Helper::<T>::initialize_active_state(n);
let loan_id = Helper::<T>::create_loan(pool_id, u16::MAX.into());
let loan_id = Helper::<T>::create_cashflow_loan(pool_id, u16::MAX.into());

}: _(RawOrigin::Signed(borrower), pool_id, loan_id, PrincipalInput::Internal(10.into()))

Expand Down
1 change: 0 additions & 1 deletion pallets/loans/src/types/cashflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,6 @@ mod date {
pub mod tests {
use cfg_traits::interest::CompoundingSchedule;
use frame_support::{assert_err, assert_ok};
use sp_runtime::traits::One;

use super::*;

Expand Down

0 comments on commit 39eb12d

Please sign in to comment.