Remove Default, HasCompact, and TypeInfo trait bounds on AssetId (#12740)

* Remove Default, HasCompact, and TypeInfo trait bounds on AssetId

* don't use default in benchmarking

* add helper trait

* add helper to assets tx payment test

* docs fixes

* i'm confused

* aha, cargo

* move affected dispatchable calls into new indices

* Helper -> BenchmarkHelper

* benchmark use of helper

* actually, don't break every call interface

* use into on AssetIdParameter

* Remove From from AssetIdParameter and use it in BenchmarkHelper

* include from

Co-authored-by: parity-processbot <>
This commit is contained in:
joe petrowski
2022-11-28 19:51:59 +01:00
committed by GitHub
parent 2d4126d239
commit d56214c21f
7 changed files with 256 additions and 202 deletions
@@ -16,6 +16,7 @@
use super::*;
use crate as pallet_asset_tx_payment;
use codec;
use frame_support::{
assert_ok,
dispatch::{DispatchClass, DispatchInfo, PostDispatchInfo},
@@ -152,10 +153,13 @@ impl pallet_transaction_payment::Config for Runtime {
type OperationalFeeMultiplier = ConstU8<5>;
}
type AssetId = u32;
impl pallet_assets::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type Balance = Balance;
type AssetId = u32;
type AssetId = AssetId;
type AssetIdParameter = codec::Compact<AssetId>;
type Currency = Balances;
type CreateOrigin = AsEnsureOriginWithArg<frame_system::EnsureSigned<AccountId>>;
type ForceOrigin = EnsureRoot<AccountId>;
@@ -169,6 +173,8 @@ impl pallet_assets::Config for Runtime {
type Extra = ();
type WeightInfo = ();
type RemoveItemsLimit = ConstU32<1000>;
#[cfg(feature = "runtime-benchmarks")]
type BenchmarkHelper = ();
}
pub struct HardcodedAuthor;
@@ -341,7 +347,7 @@ fn transaction_payment_in_asset_possible() {
let min_balance = 2;
assert_ok!(Assets::force_create(
RuntimeOrigin::root(),
asset_id,
asset_id.into(),
42, /* owner */
true, /* is_sufficient */
min_balance
@@ -351,7 +357,7 @@ fn transaction_payment_in_asset_possible() {
let caller = 1;
let beneficiary = <Runtime as system::Config>::Lookup::unlookup(caller);
let balance = 100;
assert_ok!(Assets::mint_into(asset_id, &beneficiary, balance));
assert_ok!(Assets::mint_into(asset_id.into(), &beneficiary, balance));
assert_eq!(Assets::balance(asset_id, caller), balance);
let weight = 5;
let len = 10;
@@ -394,7 +400,7 @@ fn transaction_payment_without_fee() {
let min_balance = 2;
assert_ok!(Assets::force_create(
RuntimeOrigin::root(),
asset_id,
asset_id.into(),
42, /* owner */
true, /* is_sufficient */
min_balance
@@ -404,7 +410,7 @@ fn transaction_payment_without_fee() {
let caller = 1;
let beneficiary = <Runtime as system::Config>::Lookup::unlookup(caller);
let balance = 100;
assert_ok!(Assets::mint_into(asset_id, &beneficiary, balance));
assert_ok!(Assets::mint_into(asset_id.into(), &beneficiary, balance));
assert_eq!(Assets::balance(asset_id, caller), balance);
let weight = 5;
let len = 10;
@@ -447,7 +453,7 @@ fn asset_transaction_payment_with_tip_and_refund() {
let min_balance = 2;
assert_ok!(Assets::force_create(
RuntimeOrigin::root(),
asset_id,
asset_id.into(),
42, /* owner */
true, /* is_sufficient */
min_balance
@@ -457,7 +463,7 @@ fn asset_transaction_payment_with_tip_and_refund() {
let caller = 2;
let beneficiary = <Runtime as system::Config>::Lookup::unlookup(caller);
let balance = 1000;
assert_ok!(Assets::mint_into(asset_id, &beneficiary, balance));
assert_ok!(Assets::mint_into(asset_id.into(), &beneficiary, balance));
assert_eq!(Assets::balance(asset_id, caller), balance);
let weight = 100;
let tip = 5;
@@ -499,7 +505,7 @@ fn payment_from_account_with_only_assets() {
let min_balance = 2;
assert_ok!(Assets::force_create(
RuntimeOrigin::root(),
asset_id,
asset_id.into(),
42, /* owner */
true, /* is_sufficient */
min_balance
@@ -509,7 +515,7 @@ fn payment_from_account_with_only_assets() {
let caller = 333;
let beneficiary = <Runtime as system::Config>::Lookup::unlookup(caller);
let balance = 100;
assert_ok!(Assets::mint_into(asset_id, &beneficiary, balance));
assert_ok!(Assets::mint_into(asset_id.into(), &beneficiary, balance));
assert_eq!(Assets::balance(asset_id, caller), balance);
// assert that native balance is not necessary
assert_eq!(Balances::free_balance(caller), 0);
@@ -558,7 +564,7 @@ fn payment_only_with_existing_sufficient_asset() {
let min_balance = 2;
assert_ok!(Assets::force_create(
RuntimeOrigin::root(),
asset_id,
asset_id.into(),
42, /* owner */
false, /* is_sufficient */
min_balance
@@ -583,7 +589,7 @@ fn converted_fee_is_never_zero_if_input_fee_is_not() {
let min_balance = 1;
assert_ok!(Assets::force_create(
RuntimeOrigin::root(),
asset_id,
asset_id.into(),
42, /* owner */
true, /* is_sufficient */
min_balance
@@ -593,7 +599,7 @@ fn converted_fee_is_never_zero_if_input_fee_is_not() {
let caller = 333;
let beneficiary = <Runtime as system::Config>::Lookup::unlookup(caller);
let balance = 100;
assert_ok!(Assets::mint_into(asset_id, &beneficiary, balance));
assert_ok!(Assets::mint_into(asset_id.into(), &beneficiary, balance));
assert_eq!(Assets::balance(asset_id, caller), balance);
let weight = 1;
let len = 1;
@@ -648,7 +654,7 @@ fn post_dispatch_fee_is_zero_if_pre_dispatch_fee_is_zero() {
let min_balance = 100;
assert_ok!(Assets::force_create(
RuntimeOrigin::root(),
asset_id,
asset_id.into(),
42, /* owner */
true, /* is_sufficient */
min_balance
@@ -658,7 +664,7 @@ fn post_dispatch_fee_is_zero_if_pre_dispatch_fee_is_zero() {
let caller = 333;
let beneficiary = <Runtime as system::Config>::Lookup::unlookup(caller);
let balance = 100;
assert_ok!(Assets::mint_into(asset_id, &beneficiary, balance));
assert_ok!(Assets::mint_into(asset_id.into(), &beneficiary, balance));
assert_eq!(Assets::balance(asset_id, caller), balance);
let weight = 1;
let len = 1;
@@ -705,7 +711,7 @@ fn post_dispatch_fee_is_zero_if_unsigned_pre_dispatch_fee_is_zero() {
let min_balance = 100;
assert_ok!(Assets::force_create(
RuntimeOrigin::root(),
asset_id,
asset_id.into(),
42, /* owner */
true, /* is_sufficient */
min_balance
@@ -715,7 +721,7 @@ fn post_dispatch_fee_is_zero_if_unsigned_pre_dispatch_fee_is_zero() {
let caller = 333;
let beneficiary = <Runtime as system::Config>::Lookup::unlookup(caller);
let balance = 100;
assert_ok!(Assets::mint_into(asset_id, &beneficiary, balance));
assert_ok!(Assets::mint_into(asset_id.into(), &beneficiary, balance));
assert_eq!(Assets::balance(asset_id, caller), balance);
let weight = 1;
let len = 1;