-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'daan/feat-api_fungibles_pallet' into chungquantin/feat-…
…transfer-decrease
- Loading branch information
Showing
3 changed files
with
67 additions
and
2 deletions.
There are no files selected for viewing
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 @@ | ||
//! Benchmarking setup for pallet-cards | ||
|
||
use super::{AccountIdOf, AssetIdOf, Assets, AssetsInstanceOf, BalanceOf, Call, Config, Pallet}; | ||
use frame_benchmarking::{account, v2::*}; | ||
use frame_support::{ | ||
assert_ok, | ||
traits::{ | ||
fungibles::{ | ||
approvals::{Inspect as ApprovalInspect, Mutate}, | ||
Create, Inspect, | ||
}, | ||
Currency, | ||
}, | ||
}; | ||
use frame_system::RawOrigin; | ||
use sp_runtime::traits::Zero; | ||
|
||
const SEED: u32 = 1; | ||
|
||
#[benchmarks( | ||
where | ||
<pallet_assets::Pallet<T, AssetsInstanceOf<T>> as Inspect<<T as frame_system::Config>::AccountId>>::AssetId: Zero, | ||
)] | ||
mod benchmarks { | ||
use super::*; | ||
|
||
// The worst case scenario is when the allowance is set to a value which is lower than the | ||
// current allowance. | ||
#[benchmark] | ||
fn approve() -> Result<(), BenchmarkError> { | ||
let asset = AssetIdOf::<T>::zero(); | ||
let decreased_value = <BalanceOf<T>>::from(50u32); | ||
let min_balance = <BalanceOf<T>>::from(1u32); | ||
let owner: AccountIdOf<T> = account("Alice", 0, SEED); | ||
let spender: AccountIdOf<T> = account("Bob", 0, SEED); | ||
let value = <BalanceOf<T>>::from(100u32); | ||
T::Currency::make_free_balance_be(&owner, 100u32.into()); | ||
assert_ok!(<Assets<T> as Create<AccountIdOf<T>>>::create( | ||
asset.clone().into(), | ||
owner.clone(), | ||
true, | ||
min_balance | ||
)); | ||
assert_ok!(<Assets<T> as Mutate<AccountIdOf<T>>>::approve( | ||
asset.clone(), | ||
&owner, | ||
&spender, | ||
value | ||
)); | ||
|
||
#[extrinsic_call] | ||
_(RawOrigin::Signed(owner.clone()), asset.clone(), spender.clone(), decreased_value); | ||
|
||
assert_eq!(Assets::<T>::allowance(asset, &owner, &spender), decreased_value); | ||
|
||
Ok(()) | ||
} | ||
|
||
impl_benchmark_test_suite!(Pallet, crate::mock::new_test_ext(), 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