diff --git a/pallets/loans/src/benchmarking.rs b/pallets/loans/src/benchmarking.rs index 39c72e1e4f..e8832538fa 100644 --- a/pallets/loans/src/benchmarking.rs +++ b/pallets/loans/src/benchmarking.rs @@ -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, @@ -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; @@ -126,7 +125,7 @@ where fn base_loan(item_id: T::ItemId) -> LoanInfo { 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, }, @@ -171,6 +170,30 @@ where LastLoanId::::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::::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::::get(pool_id) + } + fn borrow_loan(pool_id: T::PoolId, loan_id: T::LoanId) { let borrower = account("borrower", 0, 0); Pallet::::borrow( @@ -342,7 +365,7 @@ benchmarks! { let borrower = account("borrower", 0, 0); let pool_id = Helper::::initialize_active_state(n); - let loan_id = Helper::::create_loan(pool_id, u16::MAX.into()); + let loan_id = Helper::::create_cashflow_loan(pool_id, u16::MAX.into()); }: _(RawOrigin::Signed(borrower), pool_id, loan_id, PrincipalInput::Internal(10.into())) diff --git a/pallets/loans/src/types/cashflow.rs b/pallets/loans/src/types/cashflow.rs index 3fbcabcce4..cc7e7ccf5a 100644 --- a/pallets/loans/src/types/cashflow.rs +++ b/pallets/loans/src/types/cashflow.rs @@ -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::*;