Skip to content

Commit

Permalink
fix asset manager pallet
Browse files Browse the repository at this point in the history
  • Loading branch information
ozgunozerk committed Sep 19, 2024
1 parent 93c4286 commit 4c8c956
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 584 deletions.
75 changes: 0 additions & 75 deletions pallets/asset-manager/src/benchmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,47 +36,7 @@ benchmarks! {
assert_eq!(Pallet::<T>::asset_id_type(asset_id), Some(asset_type));
}

set_asset_units_per_second {
// We make it dependent on the number of existing assets already
let x in 5..100;
for i in 0..x {
let asset_type: T::ForeignAssetType = Location::new(
0,
X1(GeneralIndex(i as u128))
).into();
let metadata = T::AssetRegistrarMetadata::default();
let amount = 1u32.into();
Pallet::<T>::register_foreign_asset(
RawOrigin::Root.into(),
asset_type.clone(),
metadata,
amount,
true
)?;
Pallet::<T>::set_asset_units_per_second(RawOrigin::Root.into(), asset_type.clone(), 1, i)?;
}

// does not really matter what we register, as long as it is different than the previous
let asset_type = T::ForeignAssetType::default();
let metadata = T::AssetRegistrarMetadata::default();
let amount = 1u32.into();
let asset_id: T::AssetId = asset_type.clone().into();
Pallet::<T>::register_foreign_asset(
RawOrigin::Root.into(),
asset_type.clone(),
metadata,
amount,
true
)?;

}: _(RawOrigin::Root, asset_type.clone(), 1, x)
verify {
assert!(Pallet::<T>::supported_fee_payment_assets().contains(&asset_type));
assert_eq!(Pallet::<T>::asset_type_units_per_second(asset_type), Some(1));
}

change_existing_asset_type {
// We make it dependent on the number of existing assets already
let x in 5..100;
for i in 0..x {
let asset_type: T::ForeignAssetType = Location::new(0, X1(GeneralIndex(i as u128))).into();
Expand All @@ -89,7 +49,6 @@ benchmarks! {
amount,
true
)?;
Pallet::<T>::set_asset_units_per_second(RawOrigin::Root.into(), asset_type.clone(), 1, i)?;
}

let new_asset_type = T::ForeignAssetType::default();
Expand All @@ -101,40 +60,9 @@ benchmarks! {
}: _(RawOrigin::Root, asset_id_to_be_changed, new_asset_type.clone(), x)
verify {
assert_eq!(Pallet::<T>::asset_id_type(asset_id_to_be_changed), Some(new_asset_type.clone()));
assert_eq!(Pallet::<T>::asset_type_units_per_second(&new_asset_type), Some(1));
assert!(Pallet::<T>::supported_fee_payment_assets().contains(&new_asset_type));
}

remove_supported_asset {
// We make it dependent on the number of existing assets already
let x in 5..100;
for i in 0..x {
let asset_type: T::ForeignAssetType = Location::new(0, X1(GeneralIndex(i as u128))).into();
let metadata = T::AssetRegistrarMetadata::default();
let amount = 1u32.into();
Pallet::<T>::register_foreign_asset(
RawOrigin::Root.into(),
asset_type.clone(),
metadata,
amount,
true
)?;
Pallet::<T>::set_asset_units_per_second(RawOrigin::Root.into(), asset_type.clone(), 1, i)?;
}
let asset_type_to_be_removed: T::ForeignAssetType = Location::new(
0,
X1(GeneralIndex((x-1) as u128))
).into();
// We try to remove the last asset type
}: _(RawOrigin::Root, asset_type_to_be_removed.clone(), x)
verify {
assert!(!Pallet::<T>::supported_fee_payment_assets().contains(&asset_type_to_be_removed));
assert_eq!(Pallet::<T>::asset_type_units_per_second(asset_type_to_be_removed), None);
}

remove_existing_asset_type {
// We make it dependent on the number of existing assets already
// Worst case is we need to remove it from SupportedAAssetsFeePayment too
let x in 5..100;
for i in 0..x {
let asset_type: T::ForeignAssetType = Location::new(0, X1(GeneralIndex(i as u128))).into();
Expand All @@ -147,7 +75,6 @@ benchmarks! {
amount,
true
)?;
Pallet::<T>::set_asset_units_per_second(RawOrigin::Root.into(), asset_type.clone(), 1, i)?;
}

let asset_type_to_be_removed: T::ForeignAssetType = Location::new(
Expand All @@ -158,8 +85,6 @@ benchmarks! {
}: _(RawOrigin::Root, asset_id, x)
verify {
assert!(Pallet::<T>::asset_id_type(asset_id).is_none());
assert!(Pallet::<T>::asset_type_units_per_second(&asset_type_to_be_removed).is_none());
assert!(!Pallet::<T>::supported_fee_payment_assets().contains(&asset_type_to_be_removed));
}
}

Expand Down
Loading

0 comments on commit 4c8c956

Please sign in to comment.