Skip to content

Commit

Permalink
#80 Added event in register_new_orderbook_with_polkadex benchmarking
Browse files Browse the repository at this point in the history
  • Loading branch information
ayushmishra2005 committed Feb 5, 2021
1 parent a9698aa commit ea756d9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
10 changes: 6 additions & 4 deletions pallets/polkadex-custom-assets/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -902,12 +902,14 @@ impl<T: Config> Module<T> {
Permissions::SystemLevel
}

pub fn get_asset_id() -> Vec<T::Hash> {
<Assets<T>>::iter().map(|(key, _value)| key).collect()
pub fn get_asset_id() -> T::Hash {
let hash_vec: Vec<T::Hash> = <Assets<T>>::iter().map(|(key, _value)| key).collect();
hash_vec[2]
}

pub fn get_account_id() -> Vec<T::AccountId> {
<Balance<T>>::iter().map(|(key1, key2, _value)| key2).collect()
pub fn get_account_id() -> T::AccountId {
let account_vec: Vec<T::AccountId>= <Balance<T>>::iter().map(|(key1, key2, _value)| key2).collect();
account_vec[0].clone()
}
}

23 changes: 19 additions & 4 deletions pallets/polkadex-engine/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use frame_benchmarking::{account, benchmarks, whitelisted_caller};
use frame_support::ensure;
use frame_system::{EventRecord, RawOrigin};
use frame_support::traits::Box;
use crate::Module as Polkadex;

use super::*;
const UNIT: u32 = 1_000_000;
Expand All @@ -13,14 +14,28 @@ fn set_up_asset_id_token<T: Config>(who: T::AccountId,
total_issuance: T::Balance,
minimum_deposit: T::Balance) -> T::Hash {
polkadex_custom_assets::Module::<T>::create_token(RawOrigin::Signed(who).into(), total_issuance, minimum_deposit);
polkadex_custom_assets::Module::<T>::get_asset_id()[2]
polkadex_custom_assets::Module::<T>::get_asset_id()
}

fn assert_last_event<T: Config>(generic_event: <T as Config>::Event) {
let events = frame_system::Module::<T>::events();
let system_event: <T as frame_system::Config>::Event = generic_event.into();
// compare to the last event record
let EventRecord { event, .. } = &events[events.len() - 1];
assert_eq!(event, &system_event);
}

benchmarks! {
register_new_orderbook_with_polkadex {
let caller: T::AccountId = polkadex_custom_assets::Module::<T>::get_account_id()[0].clone();
let asset_id = set_up_asset_id_token::<T>(caller.clone(), T::Balance::from(10*UNIT), T::Balance::from(0));
}: _(RawOrigin::Signed(caller), asset_id, T::Balance::from(UNIT))
let caller: T::AccountId = polkadex_custom_assets::Module::<T>::get_account_id();
let quote_asset_id = set_up_asset_id_token::<T>(caller.clone(), T::Balance::from(10*UNIT), T::Balance::from(0));
let native_currency = polkadex_custom_assets::PolkadexNativeAssetIdProvider::<T>::asset_id();
let trading_pair_id = Polkadex::<T>::get_pair(quote_asset_id.clone(), native_currency);

}: _(RawOrigin::Signed(caller), quote_asset_id, T::Balance::from(UNIT))
verify {
assert_last_event::<T>(Event::<T>::TradingPairCreated(trading_pair_id.0, trading_pair_id.1).into());
}

}

Expand Down

0 comments on commit ea756d9

Please sign in to comment.