This repository has been archived by the owner on Oct 22, 2024. It is now read-only.
forked from paritytech/polkadot-sdk
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Benchmarks for dot-, erc20- and eth-app pallets (paritytech#317)
* Benchmarks for dot-app pallet * Benchmarks for erc20-app pallet * Benchmarks for eth-app pallet * Generate WeightInfo for dot-app, erc20-app, eth-app
- Loading branch information
Showing
31 changed files
with
596 additions
and
10 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
//! DotApp pallet benchmarking | ||
#![cfg(feature = "runtime-benchmarks")] | ||
|
||
use super::*; | ||
|
||
use frame_system::RawOrigin; | ||
use frame_support::traits::UnfilteredDispatchable; | ||
use frame_benchmarking::{account, benchmarks, whitelisted_caller, impl_benchmark_test_suite}; | ||
use sp_core::H160; | ||
use sp_runtime::traits::Zero; | ||
|
||
use crate::Module as DotApp; | ||
|
||
benchmarks! { | ||
// Benchmark `lock` extrinsic under worst case conditions: | ||
// * The amount is successfully locked | ||
// * The sender account is killed | ||
// * The channel executes incentivization logic | ||
lock { | ||
let existential_deposit = T::Currency::minimum_balance(); | ||
let caller: T::AccountId = whitelisted_caller(); | ||
let lock_account = DotApp::<T>::account_id(); | ||
let recipient = H160::zero(); | ||
|
||
let balance = existential_deposit * 10u32.into(); | ||
// The amount is chosen such that balance - amount < existential_deposit | ||
// so that the account is reaped | ||
let amount = existential_deposit * 9u32.into() + 1u32.into(); | ||
|
||
T::Currency::make_free_balance_be(&caller, balance); | ||
|
||
}: _(RawOrigin::Signed(caller.clone()), ChannelId::Incentivized, recipient, amount) | ||
verify { | ||
assert!(!balance.is_zero() && !amount.is_zero()); | ||
assert_eq!(T::Currency::free_balance(&caller), Zero::zero()); | ||
assert_eq!(T::Currency::free_balance(&lock_account), amount); | ||
} | ||
|
||
// Benchmark `lock` extrinsic for the average case: | ||
// * The amount is successfully locked | ||
// * The sender remains alive | ||
// * The channel executes incentivization logic | ||
#[extra] | ||
lock_sender_alive { | ||
let existential_deposit = T::Currency::minimum_balance(); | ||
let caller: T::AccountId = whitelisted_caller(); | ||
let lock_account = DotApp::<T>::account_id(); | ||
let recipient = H160::zero(); | ||
|
||
let balance = existential_deposit * 10u32.into(); | ||
let amount = existential_deposit * 8u32.into(); | ||
|
||
T::Currency::make_free_balance_be(&caller, balance); | ||
|
||
}: lock(RawOrigin::Signed(caller.clone()), ChannelId::Incentivized, recipient, amount) | ||
verify { | ||
assert!(!balance.is_zero() && !amount.is_zero()); | ||
assert_eq!(T::Currency::free_balance(&caller), balance - amount); | ||
assert_eq!(T::Currency::free_balance(&lock_account), amount); | ||
} | ||
|
||
// Benchmark `unlock` extrinsic under worst case conditions: | ||
// * The amount is successfully unlocked | ||
unlock { | ||
let origin = T::CallOrigin::successful_origin(); | ||
if let Ok(caller) = T::CallOrigin::try_origin(origin.clone()) { | ||
Address::put(caller); | ||
} else { | ||
return Err("Failed to extract caller address from origin"); | ||
} | ||
|
||
let existential_deposit = T::Currency::minimum_balance(); | ||
let lock_account = DotApp::<T>::account_id(); | ||
let recipient: T::AccountId = account("recipient", 0, 0); | ||
let recipient_lookup: <T::Lookup as StaticLookup>::Source = T::Lookup::unlookup(recipient.clone()); | ||
let sender = H160::zero(); | ||
|
||
let balance = existential_deposit * 10u32.into(); | ||
let amount = existential_deposit * 8u32.into(); | ||
let amount_wrapped = wrap::<T>(amount, T::Decimals::get()).unwrap(); | ||
|
||
T::Currency::make_free_balance_be(&lock_account, balance); | ||
|
||
let call = Call::<T>::unlock(sender, recipient_lookup, amount_wrapped); | ||
|
||
}: { call.dispatch_bypass_filter(origin)? } | ||
verify { | ||
assert!(!balance.is_zero() && !amount.is_zero()); | ||
assert_eq!(T::Currency::free_balance(&lock_account), balance - amount); | ||
assert_eq!(T::Currency::free_balance(&recipient), amount); | ||
} | ||
} | ||
|
||
impl_benchmark_test_suite!( | ||
DotApp, | ||
crate::mock::new_tester(), | ||
crate::mock::Test, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
//! ERC20App pallet benchmarking | ||
#![cfg(feature = "runtime-benchmarks")] | ||
|
||
use super::*; | ||
|
||
use frame_system::RawOrigin; | ||
use frame_support::traits::UnfilteredDispatchable; | ||
use frame_benchmarking::{account, benchmarks, whitelisted_caller, impl_benchmark_test_suite}; | ||
use sp_core::H160; | ||
|
||
#[allow(unused_imports)] | ||
use crate::Module as ERC20App; | ||
|
||
benchmarks! { | ||
// Benchmark `burn` extrinsic under worst case conditions: | ||
// * `burn` successfully substracts amount from caller account | ||
// * The channel executes incentivization logic | ||
burn { | ||
let caller: T::AccountId = whitelisted_caller(); | ||
let token = H160::repeat_byte(1); | ||
let recipient = H160::repeat_byte(2); | ||
let amount: U256 = 500.into(); | ||
|
||
T::Assets::deposit(AssetId::Token(token), &caller, amount)?; | ||
|
||
}: _(RawOrigin::Signed(caller.clone()), ChannelId::Incentivized, token, recipient, amount) | ||
verify { | ||
assert_eq!(T::Assets::balance(AssetId::Token(token), &caller), U256::zero()); | ||
} | ||
|
||
// Benchmark `mint` extrinsic under worst case conditions: | ||
// * `mint` successfully adds amount to recipient account | ||
mint { | ||
let origin = T::CallOrigin::successful_origin(); | ||
if let Ok(caller) = T::CallOrigin::try_origin(origin.clone()) { | ||
Address::put(caller); | ||
} else { | ||
return Err("Failed to extract caller address from origin"); | ||
} | ||
|
||
let token = H160::repeat_byte(1); | ||
let recipient: T::AccountId = account("recipient", 0, 0); | ||
let recipient_lookup: <T::Lookup as StaticLookup>::Source = T::Lookup::unlookup(recipient.clone()); | ||
let sender = H160::zero(); | ||
let amount: U256 = 500.into(); | ||
|
||
let call = Call::<T>::mint(token, sender, recipient_lookup, amount); | ||
|
||
}: { call.dispatch_bypass_filter(origin)? } | ||
verify { | ||
assert_eq!(T::Assets::balance(AssetId::Token(token), &recipient), amount); | ||
} | ||
} | ||
|
||
impl_benchmark_test_suite!( | ||
ERC20App, | ||
crate::mock::new_tester(), | ||
crate::mock::Test, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.