Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
actually, don't break every call interface
Browse files Browse the repository at this point in the history
  • Loading branch information
joepetrowski committed Nov 24, 2022
1 parent bac8e73 commit e0d5929
Show file tree
Hide file tree
Showing 5 changed files with 145 additions and 118 deletions.
1 change: 1 addition & 0 deletions bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1439,6 +1439,7 @@ impl pallet_assets::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type Balance = u128;
type AssetId = u32;
type AssetIdParameter = codec::Compact<u32>;
type Currency = Balances;
type CreateOrigin = AsEnsureOriginWithArg<EnsureSigned<AccountId>>;
type ForceOrigin = EnsureRoot<AccountId>;
Expand Down
97 changes: 51 additions & 46 deletions frame/assets/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ fn create_default_asset<T: Config<I>, I: 'static>(
let root = SystemOrigin::Root.into();
assert!(Assets::<T, I>::force_create(
root,
asset_id,
asset_id.into(),
caller_lookup.clone(),
is_sufficient,
1u32.into(),
Expand All @@ -67,7 +67,7 @@ fn create_default_minted_asset<T: Config<I>, I: 'static>(
}
assert!(Assets::<T, I>::mint(
SystemOrigin::Signed(caller.clone()).into(),
asset_id,
asset_id.into(),
caller_lookup.clone(),
amount,
)
Expand All @@ -94,7 +94,7 @@ fn add_sufficients<T: Config<I>, I: 'static>(minter: T::AccountId, n: u32) {
let target_lookup = T::Lookup::unlookup(target);
assert!(Assets::<T, I>::mint(
origin.clone().into(),
asset_id,
asset_id.into(),
target_lookup,
100u32.into()
)
Expand All @@ -108,15 +108,20 @@ fn add_approvals<T: Config<I>, I: 'static>(minter: T::AccountId, n: u32) {
T::Currency::deposit_creating(&minter, T::ApprovalDeposit::get() * n.into());
let minter_lookup = T::Lookup::unlookup(minter.clone());
let origin = SystemOrigin::Signed(minter);
Assets::<T, I>::mint(origin.clone().into(), asset_id, minter_lookup, (100 * (n + 1)).into())
.unwrap();
Assets::<T, I>::mint(
origin.clone().into(),
asset_id.into(),
minter_lookup,
(100 * (n + 1)).into(),
)
.unwrap();
for i in 0..n {
let target = account("approval", i, SEED);
T::Currency::make_free_balance_be(&target, T::Currency::minimum_balance());
let target_lookup = T::Lookup::unlookup(target);
Assets::<T, I>::approve_transfer(
origin.clone().into(),
asset_id,
asset_id.into(),
target_lookup,
100u32.into(),
)
Expand All @@ -139,7 +144,7 @@ benchmarks_instance_pallet! {
let caller = T::CreateOrigin::ensure_origin(origin, &asset_id).unwrap();
let caller_lookup = T::Lookup::unlookup(caller.clone());
T::Currency::make_free_balance_be(&caller, DepositBalanceOf::<T, I>::max_value());
}: _(SystemOrigin::Signed(caller.clone()), asset_id, caller_lookup, 1u32.into())
}: _(SystemOrigin::Signed(caller.clone()), asset_id.into(), caller_lookup, 1u32.into())
verify {
assert_last_event::<T, I>(Event::Created { asset_id, creator: caller.clone(), owner: caller }.into());
}
Expand All @@ -148,7 +153,7 @@ benchmarks_instance_pallet! {
let asset_id = default_asset_id::<T, I>();
let caller: T::AccountId = whitelisted_caller();
let caller_lookup = T::Lookup::unlookup(caller.clone());
}: _(SystemOrigin::Root, asset_id, caller_lookup, true, 1u32.into())
}: _(SystemOrigin::Root, asset_id.into(), caller_lookup, true, 1u32.into())
verify {
assert_last_event::<T, I>(Event::ForceCreated { asset_id, owner: caller }.into());
}
Expand All @@ -157,9 +162,9 @@ benchmarks_instance_pallet! {
let (asset_id, caller, caller_lookup) = create_default_minted_asset::<T, I>(true, 100u32.into());
Assets::<T, I>::freeze_asset(
SystemOrigin::Signed(caller.clone()).into(),
asset_id,
asset_id.into(),
)?;
}:_(SystemOrigin::Signed(caller), asset_id)
}:_(SystemOrigin::Signed(caller), asset_id.into())
verify {
assert_last_event::<T, I>(Event::DestructionStarted { asset_id }.into());
}
Expand All @@ -170,10 +175,10 @@ benchmarks_instance_pallet! {
add_sufficients::<T, I>(caller.clone(), c);
Assets::<T, I>::freeze_asset(
SystemOrigin::Signed(caller.clone()).into(),
asset_id,
asset_id.into(),
)?;
Assets::<T,I>::start_destroy(SystemOrigin::Signed(caller.clone()).into(), asset_id)?;
}:_(SystemOrigin::Signed(caller), asset_id)
Assets::<T,I>::start_destroy(SystemOrigin::Signed(caller.clone()).into(), asset_id.into())?;
}:_(SystemOrigin::Signed(caller), asset_id.into())
verify {
assert_last_event::<T, I>(Event::AccountsDestroyed {
asset_id,
Expand All @@ -188,10 +193,10 @@ benchmarks_instance_pallet! {
add_approvals::<T, I>(caller.clone(), a);
Assets::<T, I>::freeze_asset(
SystemOrigin::Signed(caller.clone()).into(),
asset_id,
asset_id.into(),
)?;
Assets::<T,I>::start_destroy(SystemOrigin::Signed(caller.clone()).into(), asset_id)?;
}:_(SystemOrigin::Signed(caller), asset_id)
Assets::<T,I>::start_destroy(SystemOrigin::Signed(caller.clone()).into(), asset_id.into())?;
}:_(SystemOrigin::Signed(caller), asset_id.into())
verify {
assert_last_event::<T, I>(Event::ApprovalsDestroyed {
asset_id,
Expand All @@ -204,10 +209,10 @@ benchmarks_instance_pallet! {
let (asset_id, caller, caller_lookup) = create_default_asset::<T, I>(true);
Assets::<T, I>::freeze_asset(
SystemOrigin::Signed(caller.clone()).into(),
asset_id,
asset_id.into(),
)?;
Assets::<T,I>::start_destroy(SystemOrigin::Signed(caller.clone()).into(), asset_id)?;
}:_(SystemOrigin::Signed(caller), asset_id)
Assets::<T,I>::start_destroy(SystemOrigin::Signed(caller.clone()).into(), asset_id.into())?;
}:_(SystemOrigin::Signed(caller), asset_id.into())
verify {
assert_last_event::<T, I>(Event::Destroyed {
asset_id,
Expand All @@ -218,15 +223,15 @@ benchmarks_instance_pallet! {
mint {
let (asset_id, caller, caller_lookup) = create_default_asset::<T, I>(true);
let amount = T::Balance::from(100u32);
}: _(SystemOrigin::Signed(caller.clone()), asset_id, caller_lookup, amount)
}: _(SystemOrigin::Signed(caller.clone()), asset_id.into(), caller_lookup, amount)
verify {
assert_last_event::<T, I>(Event::Issued { asset_id, owner: caller, total_supply: amount }.into());
}

burn {
let amount = T::Balance::from(100u32);
let (asset_id, caller, caller_lookup) = create_default_minted_asset::<T, I>(true, amount);
}: _(SystemOrigin::Signed(caller.clone()), asset_id, caller_lookup, amount)
}: _(SystemOrigin::Signed(caller.clone()), asset_id.into(), caller_lookup, amount)
verify {
assert_last_event::<T, I>(Event::Burned { asset_id, owner: caller, balance: amount }.into());
}
Expand All @@ -236,7 +241,7 @@ benchmarks_instance_pallet! {
let (asset_id, caller, caller_lookup) = create_default_minted_asset::<T, I>(true, amount);
let target: T::AccountId = account("target", 0, SEED);
let target_lookup = T::Lookup::unlookup(target.clone());
}: _(SystemOrigin::Signed(caller.clone()), asset_id, target_lookup, amount)
}: _(SystemOrigin::Signed(caller.clone()), asset_id.into(), target_lookup, amount)
verify {
assert_last_event::<T, I>(Event::Transferred { asset_id, from: caller, to: target, amount }.into());
}
Expand All @@ -247,7 +252,7 @@ benchmarks_instance_pallet! {
let (asset_id, caller, caller_lookup) = create_default_minted_asset::<T, I>(true, mint_amount);
let target: T::AccountId = account("target", 0, SEED);
let target_lookup = T::Lookup::unlookup(target.clone());
}: _(SystemOrigin::Signed(caller.clone()), asset_id, target_lookup, amount)
}: _(SystemOrigin::Signed(caller.clone()), asset_id.into(), target_lookup, amount)
verify {
assert!(frame_system::Pallet::<T>::account_exists(&caller));
assert_last_event::<T, I>(Event::Transferred { asset_id, from: caller, to: target, amount }.into());
Expand All @@ -258,7 +263,7 @@ benchmarks_instance_pallet! {
let (asset_id, caller, caller_lookup) = create_default_minted_asset::<T, I>(true, amount);
let target: T::AccountId = account("target", 0, SEED);
let target_lookup = T::Lookup::unlookup(target.clone());
}: _(SystemOrigin::Signed(caller.clone()), asset_id, caller_lookup, target_lookup, amount)
}: _(SystemOrigin::Signed(caller.clone()), asset_id.into(), caller_lookup, target_lookup, amount)
verify {
assert_last_event::<T, I>(
Event::Transferred { asset_id, from: caller, to: target, amount }.into()
Expand All @@ -267,7 +272,7 @@ benchmarks_instance_pallet! {

freeze {
let (asset_id, caller, caller_lookup) = create_default_minted_asset::<T, I>(true, 100u32.into());
}: _(SystemOrigin::Signed(caller.clone()), asset_id, caller_lookup)
}: _(SystemOrigin::Signed(caller.clone()), asset_id.into(), caller_lookup)
verify {
assert_last_event::<T, I>(Event::Frozen { asset_id, who: caller }.into());
}
Expand All @@ -276,17 +281,17 @@ benchmarks_instance_pallet! {
let (asset_id, caller, caller_lookup) = create_default_minted_asset::<T, I>(true, 100u32.into());
Assets::<T, I>::freeze(
SystemOrigin::Signed(caller.clone()).into(),
asset_id,
asset_id.into(),
caller_lookup.clone(),
)?;
}: _(SystemOrigin::Signed(caller.clone()), asset_id, caller_lookup)
}: _(SystemOrigin::Signed(caller.clone()), asset_id.into(), caller_lookup)
verify {
assert_last_event::<T, I>(Event::Thawed { asset_id, who: caller }.into());
}

freeze_asset {
let (asset_id, caller, caller_lookup) = create_default_minted_asset::<T, I>(true, 100u32.into());
}: _(SystemOrigin::Signed(caller.clone()), asset_id)
}: _(SystemOrigin::Signed(caller.clone()), asset_id.into())
verify {
assert_last_event::<T, I>(Event::AssetFrozen { asset_id }.into());
}
Expand All @@ -295,9 +300,9 @@ benchmarks_instance_pallet! {
let (asset_id, caller, caller_lookup) = create_default_minted_asset::<T, I>(true, 100u32.into());
Assets::<T, I>::freeze_asset(
SystemOrigin::Signed(caller.clone()).into(),
asset_id,
asset_id.into(),
)?;
}: _(SystemOrigin::Signed(caller.clone()), asset_id)
}: _(SystemOrigin::Signed(caller.clone()), asset_id.into())
verify {
assert_last_event::<T, I>(Event::AssetThawed { asset_id }.into());
}
Expand All @@ -306,7 +311,7 @@ benchmarks_instance_pallet! {
let (asset_id, caller, _) = create_default_asset::<T, I>(true);
let target: T::AccountId = account("target", 0, SEED);
let target_lookup = T::Lookup::unlookup(target.clone());
}: _(SystemOrigin::Signed(caller), asset_id, target_lookup)
}: _(SystemOrigin::Signed(caller), asset_id.into(), target_lookup)
verify {
assert_last_event::<T, I>(Event::OwnerChanged { asset_id, owner: target }.into());
}
Expand All @@ -316,7 +321,7 @@ benchmarks_instance_pallet! {
let target0 = T::Lookup::unlookup(account("target", 0, SEED));
let target1 = T::Lookup::unlookup(account("target", 1, SEED));
let target2 = T::Lookup::unlookup(account("target", 2, SEED));
}: _(SystemOrigin::Signed(caller), asset_id, target0, target1, target2)
}: _(SystemOrigin::Signed(caller), asset_id.into(), target0, target1, target2)
verify {
assert_last_event::<T, I>(Event::TeamChanged {
asset_id,
Expand All @@ -336,7 +341,7 @@ benchmarks_instance_pallet! {

let (asset_id, caller, _) = create_default_asset::<T, I>(true);
T::Currency::make_free_balance_be(&caller, DepositBalanceOf::<T, I>::max_value());
}: _(SystemOrigin::Signed(caller), asset_id, name.clone(), symbol.clone(), decimals)
}: _(SystemOrigin::Signed(caller), asset_id.into(), name.clone(), symbol.clone(), decimals)
verify {
assert_last_event::<T, I>(Event::MetadataSet { asset_id, name, symbol, decimals, is_frozen: false }.into());
}
Expand All @@ -346,8 +351,8 @@ benchmarks_instance_pallet! {
T::Currency::make_free_balance_be(&caller, DepositBalanceOf::<T, I>::max_value());
let dummy = vec![0u8; T::StringLimit::get() as usize];
let origin = SystemOrigin::Signed(caller.clone()).into();
Assets::<T, I>::set_metadata(origin, asset_id, dummy.clone(), dummy, 12)?;
}: _(SystemOrigin::Signed(caller), asset_id)
Assets::<T, I>::set_metadata(origin, asset_id.into(), dummy.clone(), dummy, 12)?;
}: _(SystemOrigin::Signed(caller), asset_id.into())
verify {
assert_last_event::<T, I>(Event::MetadataCleared { asset_id }.into());
}
Expand All @@ -364,7 +369,7 @@ benchmarks_instance_pallet! {

let origin = T::ForceOrigin::successful_origin();
let call = Call::<T, I>::force_set_metadata {
id: asset_id,
id: asset_id.into(),
name: name.clone(),
symbol: symbol.clone(),
decimals,
Expand All @@ -380,10 +385,10 @@ benchmarks_instance_pallet! {
T::Currency::make_free_balance_be(&caller, DepositBalanceOf::<T, I>::max_value());
let dummy = vec![0u8; T::StringLimit::get() as usize];
let origin = SystemOrigin::Signed(caller).into();
Assets::<T, I>::set_metadata(origin, asset_id, dummy.clone(), dummy, 12)?;
Assets::<T, I>::set_metadata(origin, asset_id.into(), dummy.clone(), dummy, 12)?;

let origin = T::ForceOrigin::successful_origin();
let call = Call::<T, I>::force_clear_metadata { id: asset_id };
let call = Call::<T, I>::force_clear_metadata { id: asset_id.into() };
}: { call.dispatch_bypass_filter(origin)? }
verify {
assert_last_event::<T, I>(Event::MetadataCleared { asset_id }.into());
Expand All @@ -394,7 +399,7 @@ benchmarks_instance_pallet! {

let origin = T::ForceOrigin::successful_origin();
let call = Call::<T, I>::force_asset_status {
id: asset_id,
id: asset_id.into(),
owner: caller_lookup.clone(),
issuer: caller_lookup.clone(),
admin: caller_lookup.clone(),
Expand All @@ -415,7 +420,7 @@ benchmarks_instance_pallet! {
let delegate: T::AccountId = account("delegate", 0, SEED);
let delegate_lookup = T::Lookup::unlookup(delegate.clone());
let amount = 100u32.into();
}: _(SystemOrigin::Signed(caller.clone()), asset_id, delegate_lookup, amount)
}: _(SystemOrigin::Signed(caller.clone()), asset_id.into(), delegate_lookup, amount)
verify {
assert_last_event::<T, I>(Event::ApprovedTransfer { asset_id, source: caller, delegate, amount }.into());
}
Expand All @@ -429,11 +434,11 @@ benchmarks_instance_pallet! {
let delegate_lookup = T::Lookup::unlookup(delegate.clone());
let amount = 100u32.into();
let origin = SystemOrigin::Signed(owner.clone()).into();
Assets::<T, I>::approve_transfer(origin, asset_id, delegate_lookup, amount)?;
Assets::<T, I>::approve_transfer(origin, asset_id.into(), delegate_lookup, amount)?;

let dest: T::AccountId = account("dest", 0, SEED);
let dest_lookup = T::Lookup::unlookup(dest.clone());
}: _(SystemOrigin::Signed(delegate.clone()), asset_id, owner_lookup, dest_lookup, amount)
}: _(SystemOrigin::Signed(delegate.clone()), asset_id.into(), owner_lookup, dest_lookup, amount)
verify {
assert!(T::Currency::reserved_balance(&owner).is_zero());
assert_event::<T, I>(Event::Transferred { asset_id, from: owner, to: dest, amount }.into());
Expand All @@ -447,8 +452,8 @@ benchmarks_instance_pallet! {
let delegate_lookup = T::Lookup::unlookup(delegate.clone());
let amount = 100u32.into();
let origin = SystemOrigin::Signed(caller.clone()).into();
Assets::<T, I>::approve_transfer(origin, asset_id, delegate_lookup.clone(), amount)?;
}: _(SystemOrigin::Signed(caller.clone()), asset_id, delegate_lookup)
Assets::<T, I>::approve_transfer(origin, asset_id.into(), delegate_lookup.clone(), amount)?;
}: _(SystemOrigin::Signed(caller.clone()), asset_id.into(), delegate_lookup)
verify {
assert_last_event::<T, I>(Event::ApprovalCancelled { asset_id, owner: caller, delegate }.into());
}
Expand All @@ -461,8 +466,8 @@ benchmarks_instance_pallet! {
let delegate_lookup = T::Lookup::unlookup(delegate.clone());
let amount = 100u32.into();
let origin = SystemOrigin::Signed(caller.clone()).into();
Assets::<T, I>::approve_transfer(origin, asset_id, delegate_lookup.clone(), amount)?;
}: _(SystemOrigin::Signed(caller.clone()), asset_id, caller_lookup, delegate_lookup)
Assets::<T, I>::approve_transfer(origin, asset_id.into(), delegate_lookup.clone(), amount)?;
}: _(SystemOrigin::Signed(caller.clone()), asset_id.into(), caller_lookup, delegate_lookup)
verify {
assert_last_event::<T, I>(Event::ApprovalCancelled { asset_id, owner: caller, delegate }.into());
}
Expand Down
Loading

0 comments on commit e0d5929

Please sign in to comment.