Skip to content

Commit

Permalink
Merge pull request #298 from galacticcouncil/fix/asset_registry_bench…
Browse files Browse the repository at this point in the history
…marks

fix: update asset registry benchmarks
  • Loading branch information
enthusiastmartin authored Jan 3, 2022
2 parents 39cc3e3 + 761711a commit f7bf9ad
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pallets/asset-registry/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pallet-asset-registry"
version = "1.1.2"
version = "1.1.3"
description = "Pallet for asset registry management"
authors = ["GalacticCouncil"]
edition = "2018"
Expand Down
25 changes: 11 additions & 14 deletions pallets/asset-registry/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,21 @@ benchmarks! {
register{
let name = vec![1; T::StringLimit::get() as usize];
let ed = T::Balance::from(1_000_000u32);

// This makes sure that next asset id is equal to native asset id
// In such case, one additional operation is performed to skip the id (aka worst case)
assert_eq!(crate::Pallet::<T>::next_asset_id(), T::AssetId::from(0u8));
let next_asset_id = crate::Pallet::<T>::next_asset_id();

}: _(RawOrigin::Root, name.clone(), AssetType::Token, ed)
verify {
let bname = crate::Pallet::<T>::to_bounded_name(name).unwrap();
assert_eq!(crate::Pallet::<T>::asset_ids(bname), Some(T::AssetId::from(1u8)));
if next_asset_id == T::NativeAssetId::get() {
assert_eq!(crate::Pallet::<T>::asset_ids(&bname), next_asset_id.checked_add(&T::AssetId::from(1u8)));
} else {
assert_eq!(crate::Pallet::<T>::asset_ids(&bname), Some(next_asset_id));
}
}

update{
let name = b"NAME".to_vec();
let ed = T::Balance::from(1_000_000u32);
assert_eq!(crate::Pallet::<T>::next_asset_id(), T::AssetId::from(0u8));
let _ = crate::Pallet::<T>::register(RawOrigin::Root.into(), name, AssetType::Token, ed);

let new_name= vec![1; T::StringLimit::get() as usize];
Expand All @@ -54,7 +54,7 @@ benchmarks! {
}: _(RawOrigin::Root, asset_id, new_name.clone(), AssetType::PoolShare(T::AssetId::from(10u8),T::AssetId::from(20u8)), Some(new_ed))
verify {
let bname = crate::Pallet::<T>::to_bounded_name(new_name).unwrap();
assert_eq!(crate::Pallet::<T>::asset_ids(&bname), Some(T::AssetId::from(1u8)));
assert_eq!(crate::Pallet::<T>::asset_ids(&bname), Some(asset_id));

let stored = crate::Pallet::<T>::assets(asset_id);

Expand All @@ -75,19 +75,17 @@ benchmarks! {

set_metadata{
let name = b"NAME".to_vec();
let bname = crate::Pallet::<T>::to_bounded_name(name.clone()).unwrap();
let ed = T::Balance::from(1_000_000u32);
assert_eq!(crate::Pallet::<T>::next_asset_id(), T::AssetId::from(0u8));
let _ = crate::Pallet::<T>::register(RawOrigin::Root.into(), name.clone(), AssetType::Token, ed);
let _ = crate::Pallet::<T>::register(RawOrigin::Root.into(), name, AssetType::Token, ed);

let asset_id = T::AssetId::from(1u8);
let asset_id = crate::Pallet::<T>::asset_ids(&bname).unwrap();

let max_symbol = vec![1; T::StringLimit::get() as usize];

}: _(RawOrigin::Root, asset_id, max_symbol.clone(), 10u8)
verify {
let bname = crate::Pallet::<T>::to_bounded_name(name).unwrap();
let bsymbol= crate::Pallet::<T>::to_bounded_name(max_symbol).unwrap();
assert_eq!(crate::Pallet::<T>::asset_ids(&bname), Some(T::AssetId::from(1u8)));

let stored = crate::Pallet::<T>::asset_metadata(asset_id);

Expand All @@ -107,7 +105,6 @@ benchmarks! {
set_location{
let name = b"NAME".to_vec();
let ed = T::Balance::from(1_000_000u32);
assert_eq!(crate::Pallet::<T>::next_asset_id(), T::AssetId::from(0u8));
let _ = crate::Pallet::<T>::register(RawOrigin::Root.into(), name.clone(), AssetType::Token, ed);

let asset_id = T::AssetId::from(1u8);
Expand All @@ -116,7 +113,7 @@ benchmarks! {
verify {
let bname = crate::Pallet::<T>::to_bounded_name(name).unwrap();
let bsymbol= crate::Pallet::<T>::to_bounded_name(b"SYMBOL".to_vec()).unwrap();
assert_eq!(crate::Pallet::<T>::asset_ids(&bname), Some(T::AssetId::from(1u8)));

assert_eq!(crate::Pallet::<T>::locations(asset_id), Some(Default::default()));
assert_eq!(crate::Pallet::<T>::location_assets(T::AssetNativeLocation::default()), Some(asset_id));
}
Expand Down

0 comments on commit f7bf9ad

Please sign in to comment.