Skip to content

Commit

Permalink
chore: self-redeem benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
sander2 committed Aug 18, 2022
1 parent eb2a715 commit 65db349
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
29 changes: 29 additions & 0 deletions crates/redeem/src/benchmarking.rs
Expand Up @@ -380,6 +380,35 @@ BtcRelay::<T>::parachain_confirmations() + 1u32.into());
set_redeem_period {
}: _(RawOrigin::Root, 1u32.into())

self_redeem {
assert_ok!(Oracle::<T>::_set_exchange_rate(get_collateral_currency_id::<T>(),
UnsignedFixedPoint::<T>::one()
));

let vault_id = get_vault_id::<T>();
let origin = vault_id.account_id.clone();
let amount = 1000;

register_public_key::<T>(vault_id.clone());

VaultRegistry::<T>::insert_vault(
&vault_id,
Vault::new(vault_id.clone())
);

mint_wrapped::<T>(&origin, amount.into());

mint_collateral::<T>(&vault_id.account_id, 100_000u32.into());
assert_ok!(VaultRegistry::<T>::try_deposit_collateral(&vault_id, &collateral(100_000)));

assert_ok!(VaultRegistry::<T>::try_increase_to_be_issued_tokens(&vault_id, &wrapped(amount)));
assert_ok!(VaultRegistry::<T>::issue_tokens(&vault_id, &wrapped(amount)));

let currency_pair = VaultCurrencyPair {
collateral: get_collateral_currency_id::<T>(),
wrapped: get_wrapped_currency_id::<T>()
};
}: _(RawOrigin::Signed(origin), currency_pair, amount.into())
}

impl_benchmark_test_suite!(
Expand Down
7 changes: 7 additions & 0 deletions crates/redeem/src/default_weights.rs
Expand Up @@ -40,6 +40,7 @@ pub trait WeightInfo {
fn cancel_redeem_reimburse() -> Weight;
fn cancel_redeem_retry() -> Weight;
fn set_redeem_period() -> Weight;
fn self_redeem() -> Weight;
}

/// Weights for redeem using the Substrate node and recommended hardware.
Expand Down Expand Up @@ -141,6 +142,9 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
(3_288_000 as Weight)
.saturating_add(T::DbWeight::get().writes(1 as Weight))
}
fn self_redeem() -> Weight {
Self::execute_redeem() // Dummy until we rerun benchmarks
}
}

// For backwards compatibility and tests
Expand Down Expand Up @@ -241,5 +245,8 @@ impl WeightInfo for () {
(3_288_000 as Weight)
.saturating_add(RocksDbWeight::get().writes(1 as Weight))
}
fn self_redeem() -> Weight {
Self::execute_redeem() // dummy until we rerun benchmarks
}
}

2 changes: 1 addition & 1 deletion crates/redeem/src/lib.rs
Expand Up @@ -342,7 +342,7 @@ pub mod pallet {
Ok(().into())
}

#[pallet::weight(<T as Config>::WeightInfo::request_redeem())]
#[pallet::weight(<T as Config>::WeightInfo::self_redeem())]
#[transactional]
pub fn self_redeem(
origin: OriginFor<T>,
Expand Down

0 comments on commit 65db349

Please sign in to comment.