Skip to content

Commit

Permalink
activate more benchmark items
Browse files Browse the repository at this point in the history
  • Loading branch information
GopherJ committed Sep 25, 2021
1 parent afdd5d7 commit 2e0b87f
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 19 deletions.
54 changes: 36 additions & 18 deletions pallets/loans/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ benchmarks! {
mint {
let caller: T::AccountId = whitelisted_caller();
transfer_initial_balance::<T>(caller.clone());
assert_ok!(Loans::<T>::add_market(SystemOrigin::Root.into(), DOT.into(), PENDING_MARKET_MOCK));
assert_ok!(Loans::<T>::active_market(SystemOrigin::Root.into(), DOT.into()));
let amount: u32 = 100_000;
}: _(SystemOrigin::Signed(caller.clone()), DOT.into(), amount.into())
verify {
Expand All @@ -133,6 +135,8 @@ benchmarks! {
transfer_initial_balance::<T>(caller.clone());
let deposit_amount: u32 = 200_000_000;
let borrowed_amount: u32 = 100_000_000;
assert_ok!(Loans::<T>::add_market(SystemOrigin::Root.into(), DOT.into(), PENDING_MARKET_MOCK));
assert_ok!(Loans::<T>::active_market(SystemOrigin::Root.into(), DOT.into()));
assert_ok!(Loans::<T>::mint(SystemOrigin::Signed(caller.clone()).into(), DOT.into(), deposit_amount.into()));
assert_ok!(Loans::<T>::collateral_asset(SystemOrigin::Signed(caller.clone()).into(), DOT.into(), true));
}: _(SystemOrigin::Signed(caller.clone()), DOT.into(), borrowed_amount.into())
Expand All @@ -145,6 +149,8 @@ benchmarks! {
transfer_initial_balance::<T>(caller.clone());
let deposit_amount: u32 = 100_000_000;
let redeem_amount: u32 = 100_000;
assert_ok!(Loans::<T>::add_market(SystemOrigin::Root.into(), DOT.into(), PENDING_MARKET_MOCK));
assert_ok!(Loans::<T>::active_market(SystemOrigin::Root.into(), DOT.into()));
assert_ok!(Loans::<T>::mint(SystemOrigin::Signed(caller.clone()).into(), DOT.into(), deposit_amount.into()));
}: _(SystemOrigin::Signed(caller.clone()), DOT.into(), redeem_amount.into())
verify {
Expand All @@ -155,6 +161,8 @@ benchmarks! {
let caller: T::AccountId = whitelisted_caller();
transfer_initial_balance::<T>(caller.clone());
let deposit_amount: u32 = 100_000_000;
assert_ok!(Loans::<T>::add_market(SystemOrigin::Root.into(), DOT.into(), PENDING_MARKET_MOCK));
assert_ok!(Loans::<T>::active_market(SystemOrigin::Root.into(), DOT.into()));
assert_ok!(Loans::<T>::mint(SystemOrigin::Signed(caller.clone()).into(), DOT.into(), deposit_amount.into()));
}: _(SystemOrigin::Signed(caller.clone()), DOT.into())
verify {
Expand All @@ -167,6 +175,8 @@ benchmarks! {
let deposit_amount: u32 = 200_000_000;
let borrowed_amount: u32 = 100_000_000;
let repay_amount: u32 = 100;
assert_ok!(Loans::<T>::add_market(SystemOrigin::Root.into(), DOT.into(), PENDING_MARKET_MOCK));
assert_ok!(Loans::<T>::active_market(SystemOrigin::Root.into(), DOT.into()));
assert_ok!(Loans::<T>::mint(SystemOrigin::Signed(caller.clone()).into(), DOT.into(), deposit_amount.into()));
assert_ok!(Loans::<T>::collateral_asset(SystemOrigin::Signed(caller.clone()).into(), DOT.into(), true));
assert_ok!(Loans::<T>::borrow(SystemOrigin::Signed(caller.clone()).into(), DOT.into(), borrowed_amount.into()));
Expand All @@ -180,6 +190,8 @@ benchmarks! {
transfer_initial_balance::<T>(caller.clone());
let deposit_amount: u32 = 200_000_000;
let borrowed_amount: u32 = 100_000_000;
assert_ok!(Loans::<T>::add_market(SystemOrigin::Root.into(), DOT.into(), PENDING_MARKET_MOCK));
assert_ok!(Loans::<T>::active_market(SystemOrigin::Root.into(), DOT.into()));
assert_ok!(Loans::<T>::mint(SystemOrigin::Signed(caller.clone()).into(), DOT.into(), deposit_amount.into()));
assert_ok!(Loans::<T>::collateral_asset(SystemOrigin::Signed(caller.clone()).into(), DOT.into(), true));
assert_ok!(Loans::<T>::borrow(SystemOrigin::Signed(caller.clone()).into(), DOT.into(), borrowed_amount.into()));
Expand All @@ -192,36 +204,40 @@ benchmarks! {
let caller: T::AccountId = whitelisted_caller();
transfer_initial_balance::<T>(caller.clone());
let deposit_amount: u32 = 200_000_000;
assert_ok!(Loans::<T>::add_market(SystemOrigin::Root.into(), DOT.into(), PENDING_MARKET_MOCK));
assert_ok!(Loans::<T>::active_market(SystemOrigin::Root.into(), DOT.into()));
assert_ok!(Loans::<T>::mint(SystemOrigin::Signed(caller.clone()).into(), DOT.into(), deposit_amount.into()));
}: _(SystemOrigin::Signed(caller.clone()), DOT.into(), true)
verify {
assert_last_event::<T>(Event::<T>::CollateralAssetAdded(caller, DOT.into()).into());
}

liquidate_borrow {
let alice: T::AccountId = account("Sample", 100, SEED);
let bob: T::AccountId = account("Sample", 101, SEED);
transfer_initial_balance::<T>(alice.clone());
transfer_initial_balance::<T>(bob.clone());
let deposit_amount: u32 = 200_000_000;
let borrowed_amount: u32 = 200_000_000;
let liquidate_amount: u32 = 100_000_000;
let incentive_amount: u32 = 110_000_000;
assert_ok!(Loans::<T>::mint(SystemOrigin::Signed(bob.clone()).into(), KSM.into(), deposit_amount.into()));
assert_ok!(Loans::<T>::mint(SystemOrigin::Signed(alice.clone()).into(), DOT.into(), deposit_amount.into()));
assert_ok!(Loans::<T>::collateral_asset(SystemOrigin::Signed(alice.clone()).into(), DOT.into(), true));
// assert_ok!(Loans::<T>::borrow(SystemOrigin::Signed(alice.clone()).into(), KSM.into(), borrowed_amount.into()));
set_account_borrows::<T>(alice.clone(), KSM.into(), borrowed_amount.into());
}: _(SystemOrigin::Signed(bob.clone()), alice.clone(), KSM.into(), liquidate_amount.into(), DOT.into())
verify {
assert_last_event::<T>(Event::<T>::LiquidatedBorrow(bob.clone(), alice.clone(), KSM.into(), DOT.into(), liquidate_amount.into(), incentive_amount.into()).into());
}
// liquidate_borrow {
// let alice: T::AccountId = account("Sample", 100, SEED);
// let bob: T::AccountId = account("Sample", 101, SEED);
// transfer_initial_balance::<T>(alice.clone());
// transfer_initial_balance::<T>(bob.clone());
// let deposit_amount: u32 = 200_000_000;
// let borrowed_amount: u32 = 200_000_000;
// let liquidate_amount: u32 = 100_000_000;
// let incentive_amount: u32 = 110_000_000;
// assert_ok!(Loans::<T>::mint(SystemOrigin::Signed(bob.clone()).into(), KSM.into(), deposit_amount.into()));
// assert_ok!(Loans::<T>::mint(SystemOrigin::Signed(alice.clone()).into(), DOT.into(), deposit_amount.into()));
// assert_ok!(Loans::<T>::collateral_asset(SystemOrigin::Signed(alice.clone()).into(), DOT.into(), true));
// // assert_ok!(Loans::<T>::borrow(SystemOrigin::Signed(alice.clone()).into(), KSM.into(), borrowed_amount.into()));
// set_account_borrows::<T>(alice.clone(), KSM.into(), borrowed_amount.into());
// }: _(SystemOrigin::Signed(bob.clone()), alice.clone(), KSM.into(), liquidate_amount.into(), DOT.into())
// verify {
// assert_last_event::<T>(Event::<T>::LiquidatedBorrow(bob.clone(), alice.clone(), KSM.into(), DOT.into(), liquidate_amount.into(), incentive_amount.into()).into());
// }

add_reserves {
let caller: T::AccountId = whitelisted_caller();
let payer = T::Lookup::unlookup(caller.clone());
transfer_initial_balance::<T>(caller.clone());
let amount: u32 = 2000;
assert_ok!(Loans::<T>::add_market(SystemOrigin::Root.into(), DOT.into(), PENDING_MARKET_MOCK));
assert_ok!(Loans::<T>::active_market(SystemOrigin::Root.into(), DOT.into()));
}: _(SystemOrigin::Root, payer, DOT.into(), amount.into())
verify {
assert_last_event::<T>(Event::<T>::ReservesAdded(caller, DOT.into(), amount.into(), amount.into()).into());
Expand All @@ -233,6 +249,8 @@ benchmarks! {
transfer_initial_balance::<T>(caller.clone());
let add_amount: u32 = 2000;
let reduce_amount: u32 = 1000;
assert_ok!(Loans::<T>::add_market(SystemOrigin::Root.into(), DOT.into(), PENDING_MARKET_MOCK));
assert_ok!(Loans::<T>::active_market(SystemOrigin::Root.into(), DOT.into()));
assert_ok!(Loans::<T>::add_reserves(SystemOrigin::Root.into(), payer.clone(), DOT.into(), add_amount.into()));
}: _(SystemOrigin::Root, payer, DOT.into(), reduce_amount.into())
verify {
Expand Down
2 changes: 1 addition & 1 deletion pallets/loans/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,7 @@ pub mod pallet {
TotalReserves::<T>::insert(asset_id, total_reserves_new);

Self::deposit_event(Event::<T>::ReservesAdded(
Self::account_id(),
payer,
asset_id,
add_amount,
total_reserves_new,
Expand Down

0 comments on commit 2e0b87f

Please sign in to comment.