mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-09 20:11:09 +00:00
Assets: Remove zombies, introduce approvals (#8220)
* Initial work * Tests for frame system * Self-sufficient account ref-counting * Fixes * Benchmarks building. * Update frame/system/src/lib.rs Co-authored-by: Jaco Greeff <jacogr@gmail.com> * Fixes * Fixes * Fixes * Fixes * Fixes * Fixes * Test approvals * Fixes * Report assets pallet tests * Tests for approvals & force_cancel_approval * Use structs rather than tuples for approval data * Add force_asset_status, force_set_metadata * Add clear_metadata. * approval benchmarks * force_asset_status benchmarks * final benchmarks * cargo run --release --features=runtime-benchmarks --manifest-path=bin/node/cli/Cargo.toml -- benchmark --chain=dev --steps=50 --repeat=20 --pallet=pallet_assets --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./frame/assets/src/weights.rs --template=./.maintain/frame-weight-template.hbs * Update frame/system/src/lib.rs Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com> * Update frame/system/src/lib.rs Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com> * Update frame/system/src/lib.rs Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com> * Docs for new approval dispatches. * Docs for pallet. * Remove accidental code. * cargo run --release --features=runtime-benchmarks --manifest-path=bin/node/cli/Cargo.toml -- benchmark --chain=dev --steps=50 --repeat=20 --pallet=pallet_assets --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./frame/assets/src/weights.rs --template=./.maintain/frame-weight-template.hbs * cargo run --release --features=runtime-benchmarks --manifest-path=bin/node/cli/Cargo.toml -- benchmark --chain=dev --steps=50 --repeat=20 --pallet=pallet_assets --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./frame/assets/src/weights.rs --template=./.maintain/frame-weight-template.hbs * Fixes * Update frame/assets/src/lib.rs Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com> * Grumbles. * Transfer zero works, use DispatchResult * fix test * Remove force_destroy * Remove TODO * cargo run --release --features=runtime-benchmarks --manifest-path=bin/node/cli/Cargo.toml -- benchmark --chain=dev --steps=50 --repeat=20 --pallet=pallet_assets --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./frame/assets/src/weights.rs --template=./.maintain/frame-weight-template.hbs * transfer_keep_alive * Fixes * Fixes * Fixes * cargo run --release --features=runtime-benchmarks --manifest-path=bin/node/cli/Cargo.toml -- benchmark --chain=dev --steps=50 --repeat=20 --pallet=pallet_assets --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./frame/assets/src/weights.rs --template=./.maintain/frame-weight-template.hbs Co-authored-by: Jaco Greeff <jacogr@gmail.com> Co-authored-by: Parity Benchmarking Bot <admin@parity.io> Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com> Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
This commit is contained in:
@@ -1013,9 +1013,9 @@ parameter_types! {
|
||||
impl pallet_lottery::Config for Runtime {
|
||||
type ModuleId = LotteryModuleId;
|
||||
type Call = Call;
|
||||
type Event = Event;
|
||||
type Currency = Balances;
|
||||
type Randomness = RandomnessCollectiveFlip;
|
||||
type Event = Event;
|
||||
type ManagerOrigin = EnsureRoot<AccountId>;
|
||||
type MaxCalls = MaxCalls;
|
||||
type ValidateCall = Lottery;
|
||||
@@ -1024,8 +1024,8 @@ impl pallet_lottery::Config for Runtime {
|
||||
}
|
||||
|
||||
parameter_types! {
|
||||
pub const AssetDepositBase: Balance = 100 * DOLLARS;
|
||||
pub const AssetDepositPerZombie: Balance = 1 * DOLLARS;
|
||||
pub const AssetDeposit: Balance = 100 * DOLLARS;
|
||||
pub const ApprovalDeposit: Balance = 1 * DOLLARS;
|
||||
pub const StringLimit: u32 = 50;
|
||||
pub const MetadataDepositBase: Balance = 10 * DOLLARS;
|
||||
pub const MetadataDepositPerByte: Balance = 1 * DOLLARS;
|
||||
@@ -1037,11 +1037,11 @@ impl pallet_assets::Config for Runtime {
|
||||
type AssetId = u32;
|
||||
type Currency = Balances;
|
||||
type ForceOrigin = EnsureRoot<AccountId>;
|
||||
type AssetDepositBase = AssetDepositBase;
|
||||
type AssetDepositPerZombie = AssetDepositPerZombie;
|
||||
type StringLimit = StringLimit;
|
||||
type AssetDeposit = AssetDeposit;
|
||||
type MetadataDepositBase = MetadataDepositBase;
|
||||
type MetadataDepositPerByte = MetadataDepositPerByte;
|
||||
type ApprovalDeposit = ApprovalDeposit;
|
||||
type StringLimit = StringLimit;
|
||||
type WeightInfo = pallet_assets::weights::SubstrateWeight<Runtime>;
|
||||
}
|
||||
|
||||
|
||||
@@ -17,17 +17,23 @@
|
||||
|
||||
//! Assets pallet benchmarking.
|
||||
|
||||
#![cfg(feature = "runtime-benchmarks")]
|
||||
|
||||
use sp_std::prelude::*;
|
||||
use super::*;
|
||||
use sp_runtime::traits::Bounded;
|
||||
use frame_system::RawOrigin as SystemOrigin;
|
||||
use frame_benchmarking::{benchmarks, account, whitelisted_caller, impl_benchmark_test_suite};
|
||||
use frame_benchmarking::{
|
||||
benchmarks, account, whitelisted_caller, whitelist_account, impl_benchmark_test_suite
|
||||
};
|
||||
use frame_support::traits::Get;
|
||||
use frame_support::{traits::EnsureOrigin, dispatch::UnfilteredDispatchable};
|
||||
|
||||
use crate::Module as Assets;
|
||||
|
||||
const SEED: u32 = 0;
|
||||
|
||||
fn create_default_asset<T: Config>(max_zombies: u32)
|
||||
fn create_default_asset<T: Config>(is_sufficient: bool)
|
||||
-> (T::AccountId, <T::Lookup as StaticLookup>::Source)
|
||||
{
|
||||
let caller: T::AccountId = whitelisted_caller();
|
||||
@@ -37,16 +43,19 @@ fn create_default_asset<T: Config>(max_zombies: u32)
|
||||
root,
|
||||
Default::default(),
|
||||
caller_lookup.clone(),
|
||||
max_zombies,
|
||||
is_sufficient,
|
||||
1u32.into(),
|
||||
).is_ok());
|
||||
(caller, caller_lookup)
|
||||
}
|
||||
|
||||
fn create_default_minted_asset<T: Config>(max_zombies: u32, amount: T::Balance)
|
||||
fn create_default_minted_asset<T: Config>(is_sufficient: bool, amount: T::Balance)
|
||||
-> (T::AccountId, <T::Lookup as StaticLookup>::Source)
|
||||
{
|
||||
let (caller, caller_lookup) = create_default_asset::<T>(max_zombies);
|
||||
let (caller, caller_lookup) = create_default_asset::<T>(is_sufficient);
|
||||
if !is_sufficient {
|
||||
T::Currency::make_free_balance_be(&caller, T::Currency::minimum_balance());
|
||||
}
|
||||
assert!(Assets::<T>::mint(
|
||||
SystemOrigin::Signed(caller.clone()).into(),
|
||||
Default::default(),
|
||||
@@ -56,13 +65,58 @@ fn create_default_minted_asset<T: Config>(max_zombies: u32, amount: T::Balance)
|
||||
(caller, caller_lookup)
|
||||
}
|
||||
|
||||
fn add_zombies<T: Config>(minter: T::AccountId, n: u32) {
|
||||
fn swap_is_sufficient<T: Config>(s: &mut bool) {
|
||||
Asset::<T>::mutate(&T::AssetId::default(), |maybe_a|
|
||||
if let Some(ref mut a) = maybe_a { sp_std::mem::swap(s, &mut a.is_sufficient) }
|
||||
);
|
||||
}
|
||||
|
||||
fn add_consumers<T: Config>(minter: T::AccountId, n: u32) {
|
||||
let origin = SystemOrigin::Signed(minter);
|
||||
let mut s = false;
|
||||
swap_is_sufficient::<T>(&mut s);
|
||||
for i in 0..n {
|
||||
let target = account("zombie", i, SEED);
|
||||
let target = account("consumer", i, SEED);
|
||||
T::Currency::make_free_balance_be(&target, T::Currency::minimum_balance());
|
||||
let target_lookup = T::Lookup::unlookup(target);
|
||||
assert!(Assets::<T>::mint(origin.clone().into(), Default::default(), target_lookup, 100u32.into()).is_ok());
|
||||
}
|
||||
swap_is_sufficient::<T>(&mut s);
|
||||
}
|
||||
|
||||
fn add_sufficients<T: Config>(minter: T::AccountId, n: u32) {
|
||||
let origin = SystemOrigin::Signed(minter);
|
||||
let mut s = true;
|
||||
swap_is_sufficient::<T>(&mut s);
|
||||
for i in 0..n {
|
||||
let target = account("sufficient", i, SEED);
|
||||
let target_lookup = T::Lookup::unlookup(target);
|
||||
assert!(Assets::<T>::mint(origin.clone().into(), Default::default(), target_lookup, 100u32.into()).is_ok());
|
||||
}
|
||||
swap_is_sufficient::<T>(&mut s);
|
||||
}
|
||||
|
||||
fn add_approvals<T: Config>(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>::mint(
|
||||
origin.clone().into(),
|
||||
Default::default(),
|
||||
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>::approve_transfer(
|
||||
origin.clone().into(),
|
||||
Default::default(),
|
||||
target_lookup,
|
||||
100u32.into(),
|
||||
).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
fn assert_last_event<T: Config>(generic_event: <T as Config>::Event) {
|
||||
@@ -77,8 +131,8 @@ benchmarks! {
|
||||
create {
|
||||
let caller: T::AccountId = whitelisted_caller();
|
||||
let caller_lookup = T::Lookup::unlookup(caller.clone());
|
||||
T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value());
|
||||
}: _(SystemOrigin::Signed(caller.clone()), Default::default(), caller_lookup, 1, 1u32.into())
|
||||
T::Currency::make_free_balance_be(&caller, DepositBalanceOf::<T>::max_value());
|
||||
}: _(SystemOrigin::Signed(caller.clone()), Default::default(), caller_lookup, 1u32.into())
|
||||
verify {
|
||||
assert_last_event::<T>(Event::Created(Default::default(), caller.clone(), caller).into());
|
||||
}
|
||||
@@ -86,31 +140,27 @@ benchmarks! {
|
||||
force_create {
|
||||
let caller: T::AccountId = whitelisted_caller();
|
||||
let caller_lookup = T::Lookup::unlookup(caller.clone());
|
||||
}: _(SystemOrigin::Root, Default::default(), caller_lookup, 1, 1u32.into())
|
||||
}: _(SystemOrigin::Root, Default::default(), caller_lookup, true, 1u32.into())
|
||||
verify {
|
||||
assert_last_event::<T>(Event::ForceCreated(Default::default(), caller).into());
|
||||
}
|
||||
|
||||
destroy {
|
||||
let z in 0 .. 10_000;
|
||||
let (caller, _) = create_default_asset::<T>(10_000);
|
||||
add_zombies::<T>(caller.clone(), z);
|
||||
}: _(SystemOrigin::Signed(caller), Default::default(), 10_000)
|
||||
verify {
|
||||
assert_last_event::<T>(Event::Destroyed(Default::default()).into());
|
||||
}
|
||||
|
||||
force_destroy {
|
||||
let z in 0 .. 10_000;
|
||||
let (caller, _) = create_default_asset::<T>(10_000);
|
||||
add_zombies::<T>(caller.clone(), z);
|
||||
}: _(SystemOrigin::Root, Default::default(), 10_000)
|
||||
let c in 0 .. 5_000;
|
||||
let s in 0 .. 5_000;
|
||||
let a in 0 .. 5_00;
|
||||
let (caller, _) = create_default_asset::<T>(true);
|
||||
add_consumers::<T>(caller.clone(), c);
|
||||
add_sufficients::<T>(caller.clone(), s);
|
||||
add_approvals::<T>(caller.clone(), a);
|
||||
let witness = Asset::<T>::get(T::AssetId::default()).unwrap().destroy_witness();
|
||||
}: _(SystemOrigin::Signed(caller), Default::default(), witness)
|
||||
verify {
|
||||
assert_last_event::<T>(Event::Destroyed(Default::default()).into());
|
||||
}
|
||||
|
||||
mint {
|
||||
let (caller, caller_lookup) = create_default_asset::<T>(10);
|
||||
let (caller, caller_lookup) = create_default_asset::<T>(true);
|
||||
let amount = T::Balance::from(100u32);
|
||||
}: _(SystemOrigin::Signed(caller.clone()), Default::default(), caller_lookup, amount)
|
||||
verify {
|
||||
@@ -119,7 +169,7 @@ benchmarks! {
|
||||
|
||||
burn {
|
||||
let amount = T::Balance::from(100u32);
|
||||
let (caller, caller_lookup) = create_default_minted_asset::<T>(10, amount);
|
||||
let (caller, caller_lookup) = create_default_minted_asset::<T>(true, amount);
|
||||
}: _(SystemOrigin::Signed(caller.clone()), Default::default(), caller_lookup, amount)
|
||||
verify {
|
||||
assert_last_event::<T>(Event::Burned(Default::default(), caller, amount).into());
|
||||
@@ -127,7 +177,7 @@ benchmarks! {
|
||||
|
||||
transfer {
|
||||
let amount = T::Balance::from(100u32);
|
||||
let (caller, caller_lookup) = create_default_minted_asset::<T>(10, amount);
|
||||
let (caller, caller_lookup) = create_default_minted_asset::<T>(true, amount);
|
||||
let target: T::AccountId = account("target", 0, SEED);
|
||||
let target_lookup = T::Lookup::unlookup(target.clone());
|
||||
}: _(SystemOrigin::Signed(caller.clone()), Default::default(), target_lookup, amount)
|
||||
@@ -135,27 +185,39 @@ benchmarks! {
|
||||
assert_last_event::<T>(Event::Transferred(Default::default(), caller, target, amount).into());
|
||||
}
|
||||
|
||||
transfer_keep_alive {
|
||||
let mint_amount = T::Balance::from(200u32);
|
||||
let amount = T::Balance::from(100u32);
|
||||
let (caller, caller_lookup) = create_default_minted_asset::<T>(true, mint_amount);
|
||||
let target: T::AccountId = account("target", 0, SEED);
|
||||
let target_lookup = T::Lookup::unlookup(target.clone());
|
||||
}: _(SystemOrigin::Signed(caller.clone()), Default::default(), target_lookup, amount)
|
||||
verify {
|
||||
assert!(frame_system::Module::<T>::account_exists(&caller));
|
||||
assert_last_event::<T>(Event::Transferred(Default::default(), caller, target, amount).into());
|
||||
}
|
||||
|
||||
force_transfer {
|
||||
let amount = T::Balance::from(100u32);
|
||||
let (caller, caller_lookup) = create_default_minted_asset::<T>(10, amount);
|
||||
let (caller, caller_lookup) = create_default_minted_asset::<T>(true, amount);
|
||||
let target: T::AccountId = account("target", 0, SEED);
|
||||
let target_lookup = T::Lookup::unlookup(target.clone());
|
||||
}: _(SystemOrigin::Signed(caller.clone()), Default::default(), caller_lookup, target_lookup, amount)
|
||||
verify {
|
||||
assert_last_event::<T>(
|
||||
Event::ForceTransferred(Default::default(), caller, target, amount).into()
|
||||
Event::Transferred(Default::default(), caller, target, amount).into()
|
||||
);
|
||||
}
|
||||
|
||||
freeze {
|
||||
let (caller, caller_lookup) = create_default_minted_asset::<T>(10, 100u32.into());
|
||||
let (caller, caller_lookup) = create_default_minted_asset::<T>(true, 100u32.into());
|
||||
}: _(SystemOrigin::Signed(caller.clone()), Default::default(), caller_lookup)
|
||||
verify {
|
||||
assert_last_event::<T>(Event::Frozen(Default::default(), caller).into());
|
||||
}
|
||||
|
||||
thaw {
|
||||
let (caller, caller_lookup) = create_default_minted_asset::<T>(10, 100u32.into());
|
||||
let (caller, caller_lookup) = create_default_minted_asset::<T>(true, 100u32.into());
|
||||
Assets::<T>::freeze(
|
||||
SystemOrigin::Signed(caller.clone()).into(),
|
||||
Default::default(),
|
||||
@@ -167,14 +229,14 @@ benchmarks! {
|
||||
}
|
||||
|
||||
freeze_asset {
|
||||
let (caller, caller_lookup) = create_default_minted_asset::<T>(10, 100u32.into());
|
||||
let (caller, caller_lookup) = create_default_minted_asset::<T>(true, 100u32.into());
|
||||
}: _(SystemOrigin::Signed(caller.clone()), Default::default())
|
||||
verify {
|
||||
assert_last_event::<T>(Event::AssetFrozen(Default::default()).into());
|
||||
}
|
||||
|
||||
thaw_asset {
|
||||
let (caller, caller_lookup) = create_default_minted_asset::<T>(10, 100u32.into());
|
||||
let (caller, caller_lookup) = create_default_minted_asset::<T>(true, 100u32.into());
|
||||
Assets::<T>::freeze_asset(
|
||||
SystemOrigin::Signed(caller.clone()).into(),
|
||||
Default::default(),
|
||||
@@ -185,7 +247,7 @@ benchmarks! {
|
||||
}
|
||||
|
||||
transfer_ownership {
|
||||
let (caller, _) = create_default_asset::<T>(10);
|
||||
let (caller, _) = create_default_asset::<T>(true);
|
||||
let target: T::AccountId = account("target", 0, SEED);
|
||||
let target_lookup = T::Lookup::unlookup(target.clone());
|
||||
}: _(SystemOrigin::Signed(caller), Default::default(), target_lookup)
|
||||
@@ -194,7 +256,7 @@ benchmarks! {
|
||||
}
|
||||
|
||||
set_team {
|
||||
let (caller, _) = create_default_asset::<T>(10);
|
||||
let (caller, _) = create_default_asset::<T>(true);
|
||||
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));
|
||||
@@ -208,15 +270,6 @@ benchmarks! {
|
||||
).into());
|
||||
}
|
||||
|
||||
set_max_zombies {
|
||||
let (caller, _) = create_default_asset::<T>(10);
|
||||
let max_zombies: u32 = 100;
|
||||
T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value());
|
||||
}: _(SystemOrigin::Signed(caller), Default::default(), max_zombies)
|
||||
verify {
|
||||
assert_last_event::<T>(Event::MaxZombiesChanged(Default::default(), max_zombies).into());
|
||||
}
|
||||
|
||||
set_metadata {
|
||||
let n in 0 .. T::StringLimit::get();
|
||||
let s in 0 .. T::StringLimit::get();
|
||||
@@ -225,12 +278,143 @@ benchmarks! {
|
||||
let symbol = vec![0u8; s as usize];
|
||||
let decimals = 12;
|
||||
|
||||
let (caller, _) = create_default_asset::<T>(10);
|
||||
T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value());
|
||||
let (caller, _) = create_default_asset::<T>(true);
|
||||
T::Currency::make_free_balance_be(&caller, DepositBalanceOf::<T>::max_value());
|
||||
}: _(SystemOrigin::Signed(caller), Default::default(), name.clone(), symbol.clone(), decimals)
|
||||
verify {
|
||||
assert_last_event::<T>(Event::MetadataSet(Default::default(), name, symbol, decimals).into());
|
||||
let id = Default::default();
|
||||
assert_last_event::<T>(Event::MetadataSet(id, name, symbol, decimals, false).into());
|
||||
}
|
||||
|
||||
clear_metadata {
|
||||
let (caller, _) = create_default_asset::<T>(true);
|
||||
T::Currency::make_free_balance_be(&caller, DepositBalanceOf::<T>::max_value());
|
||||
let dummy = vec![0u8; T::StringLimit::get() as usize];
|
||||
let origin = SystemOrigin::Signed(caller.clone()).into();
|
||||
Assets::<T>::set_metadata(origin, Default::default(), dummy.clone(), dummy, 12)?;
|
||||
}: _(SystemOrigin::Signed(caller), Default::default())
|
||||
verify {
|
||||
assert_last_event::<T>(Event::MetadataCleared(Default::default()).into());
|
||||
}
|
||||
|
||||
force_set_metadata {
|
||||
let n in 0 .. T::StringLimit::get();
|
||||
let s in 0 .. T::StringLimit::get();
|
||||
|
||||
let name = vec![0u8; n as usize];
|
||||
let symbol = vec![0u8; s as usize];
|
||||
let decimals = 12;
|
||||
|
||||
create_default_asset::<T>(true);
|
||||
|
||||
let origin = T::ForceOrigin::successful_origin();
|
||||
let call = Call::<T>::force_set_metadata(
|
||||
Default::default(),
|
||||
name.clone(),
|
||||
symbol.clone(),
|
||||
decimals,
|
||||
false,
|
||||
);
|
||||
}: { call.dispatch_bypass_filter(origin)? }
|
||||
verify {
|
||||
let id = Default::default();
|
||||
assert_last_event::<T>(Event::MetadataSet(id, name, symbol, decimals, false).into());
|
||||
}
|
||||
|
||||
force_clear_metadata {
|
||||
let (caller, _) = create_default_asset::<T>(true);
|
||||
T::Currency::make_free_balance_be(&caller, DepositBalanceOf::<T>::max_value());
|
||||
let dummy = vec![0u8; T::StringLimit::get() as usize];
|
||||
let origin = SystemOrigin::Signed(caller.clone()).into();
|
||||
Assets::<T>::set_metadata(origin, Default::default(), dummy.clone(), dummy, 12)?;
|
||||
|
||||
let origin = T::ForceOrigin::successful_origin();
|
||||
let call = Call::<T>::force_clear_metadata(Default::default());
|
||||
}: { call.dispatch_bypass_filter(origin)? }
|
||||
verify {
|
||||
assert_last_event::<T>(Event::MetadataCleared(Default::default()).into());
|
||||
}
|
||||
|
||||
force_asset_status {
|
||||
let (caller, caller_lookup) = create_default_asset::<T>(true);
|
||||
|
||||
let origin = T::ForceOrigin::successful_origin();
|
||||
let call = Call::<T>::force_asset_status(
|
||||
Default::default(),
|
||||
caller_lookup.clone(),
|
||||
caller_lookup.clone(),
|
||||
caller_lookup.clone(),
|
||||
caller_lookup.clone(),
|
||||
100u32.into(),
|
||||
true,
|
||||
false,
|
||||
);
|
||||
}: { call.dispatch_bypass_filter(origin)? }
|
||||
verify {
|
||||
assert_last_event::<T>(Event::AssetStatusChanged(Default::default()).into());
|
||||
}
|
||||
|
||||
approve_transfer {
|
||||
let (caller, _) = create_default_minted_asset::<T>(true, 100u32.into());
|
||||
T::Currency::make_free_balance_be(&caller, DepositBalanceOf::<T>::max_value());
|
||||
|
||||
let id = Default::default();
|
||||
let delegate: T::AccountId = account("delegate", 0, SEED);
|
||||
let delegate_lookup = T::Lookup::unlookup(delegate.clone());
|
||||
let amount = 100u32.into();
|
||||
}: _(SystemOrigin::Signed(caller.clone()), id, delegate_lookup, amount)
|
||||
verify {
|
||||
assert_last_event::<T>(Event::ApprovedTransfer(id, caller, delegate, amount).into());
|
||||
}
|
||||
|
||||
transfer_approved {
|
||||
let (owner, owner_lookup) = create_default_minted_asset::<T>(true, 100u32.into());
|
||||
T::Currency::make_free_balance_be(&owner, DepositBalanceOf::<T>::max_value());
|
||||
|
||||
let id = Default::default();
|
||||
let delegate: T::AccountId = account("delegate", 0, SEED);
|
||||
whitelist_account!(delegate);
|
||||
let delegate_lookup = T::Lookup::unlookup(delegate.clone());
|
||||
let amount = 100u32.into();
|
||||
let origin = SystemOrigin::Signed(owner.clone()).into();
|
||||
Assets::<T>::approve_transfer(origin, id, delegate_lookup.clone(), amount)?;
|
||||
|
||||
let dest: T::AccountId = account("dest", 0, SEED);
|
||||
let dest_lookup = T::Lookup::unlookup(dest.clone());
|
||||
}: _(SystemOrigin::Signed(delegate.clone()), id, owner_lookup, dest_lookup, amount)
|
||||
verify {
|
||||
assert_last_event::<T>(Event::TransferredApproved(id, owner, delegate, dest, amount).into());
|
||||
}
|
||||
|
||||
cancel_approval {
|
||||
let (caller, _) = create_default_minted_asset::<T>(true, 100u32.into());
|
||||
T::Currency::make_free_balance_be(&caller, DepositBalanceOf::<T>::max_value());
|
||||
|
||||
let id = Default::default();
|
||||
let delegate: T::AccountId = account("delegate", 0, SEED);
|
||||
let delegate_lookup = T::Lookup::unlookup(delegate.clone());
|
||||
let amount = 100u32.into();
|
||||
let origin = SystemOrigin::Signed(caller.clone()).into();
|
||||
Assets::<T>::approve_transfer(origin, id, delegate_lookup.clone(), amount)?;
|
||||
}: _(SystemOrigin::Signed(caller.clone()), id, delegate_lookup)
|
||||
verify {
|
||||
assert_last_event::<T>(Event::ApprovalCancelled(id, caller, delegate).into());
|
||||
}
|
||||
|
||||
force_cancel_approval {
|
||||
let (caller, caller_lookup) = create_default_minted_asset::<T>(true, 100u32.into());
|
||||
T::Currency::make_free_balance_be(&caller, DepositBalanceOf::<T>::max_value());
|
||||
|
||||
let id = Default::default();
|
||||
let delegate: T::AccountId = account("delegate", 0, SEED);
|
||||
let delegate_lookup = T::Lookup::unlookup(delegate.clone());
|
||||
let amount = 100u32.into();
|
||||
let origin = SystemOrigin::Signed(caller.clone()).into();
|
||||
Assets::<T>::approve_transfer(origin, id, delegate_lookup.clone(), amount)?;
|
||||
}: _(SystemOrigin::Signed(caller.clone()), id, caller_lookup, delegate_lookup)
|
||||
verify {
|
||||
assert_last_event::<T>(Event::ApprovalCancelled(id, caller, delegate).into());
|
||||
}
|
||||
}
|
||||
|
||||
impl_benchmark_test_suite!(Assets, crate::tests::new_test_ext(), crate::tests::Test);
|
||||
impl_benchmark_test_suite!(Assets, crate::mock::new_test_ext(), crate::mock::Test);
|
||||
|
||||
+787
-960
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,112 @@
|
||||
// This file is part of Substrate.
|
||||
|
||||
// Copyright (C) 2019-2021 Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//! Test environment for Assets pallet.
|
||||
|
||||
use super::*;
|
||||
use crate as pallet_assets;
|
||||
|
||||
use sp_core::H256;
|
||||
use sp_runtime::{traits::{BlakeTwo256, IdentityLookup}, testing::Header};
|
||||
use frame_support::{parameter_types, construct_runtime};
|
||||
|
||||
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
|
||||
type Block = frame_system::mocking::MockBlock<Test>;
|
||||
|
||||
construct_runtime!(
|
||||
pub enum Test where
|
||||
Block = Block,
|
||||
NodeBlock = Block,
|
||||
UncheckedExtrinsic = UncheckedExtrinsic,
|
||||
{
|
||||
System: frame_system::{Module, Call, Config, Storage, Event<T>},
|
||||
Balances: pallet_balances::{Module, Call, Storage, Config<T>, Event<T>},
|
||||
Assets: pallet_assets::{Module, Call, Storage, Event<T>},
|
||||
}
|
||||
);
|
||||
|
||||
parameter_types! {
|
||||
pub const BlockHashCount: u64 = 250;
|
||||
}
|
||||
impl frame_system::Config for Test {
|
||||
type BaseCallFilter = ();
|
||||
type BlockWeights = ();
|
||||
type BlockLength = ();
|
||||
type Origin = Origin;
|
||||
type Call = Call;
|
||||
type Index = u64;
|
||||
type BlockNumber = u64;
|
||||
type Hash = H256;
|
||||
type Hashing = BlakeTwo256;
|
||||
type AccountId = u64;
|
||||
type Lookup = IdentityLookup<Self::AccountId>;
|
||||
type Header = Header;
|
||||
type Event = Event;
|
||||
type BlockHashCount = BlockHashCount;
|
||||
type DbWeight = ();
|
||||
type Version = ();
|
||||
type PalletInfo = PalletInfo;
|
||||
type AccountData = pallet_balances::AccountData<u64>;
|
||||
type OnNewAccount = ();
|
||||
type OnKilledAccount = ();
|
||||
type SystemWeightInfo = ();
|
||||
type SS58Prefix = ();
|
||||
}
|
||||
|
||||
parameter_types! {
|
||||
pub const ExistentialDeposit: u64 = 1;
|
||||
}
|
||||
|
||||
impl pallet_balances::Config for Test {
|
||||
type Balance = u64;
|
||||
type DustRemoval = ();
|
||||
type Event = Event;
|
||||
type ExistentialDeposit = ExistentialDeposit;
|
||||
type AccountStore = System;
|
||||
type WeightInfo = ();
|
||||
type MaxLocks = ();
|
||||
}
|
||||
|
||||
parameter_types! {
|
||||
pub const AssetDeposit: u64 = 1;
|
||||
pub const ApprovalDeposit: u64 = 1;
|
||||
pub const StringLimit: u32 = 50;
|
||||
pub const MetadataDepositBase: u64 = 1;
|
||||
pub const MetadataDepositPerByte: u64 = 1;
|
||||
}
|
||||
|
||||
impl Config for Test {
|
||||
type Event = Event;
|
||||
type Balance = u64;
|
||||
type AssetId = u32;
|
||||
type Currency = Balances;
|
||||
type ForceOrigin = frame_system::EnsureRoot<u64>;
|
||||
type AssetDeposit = AssetDeposit;
|
||||
type MetadataDepositBase = MetadataDepositBase;
|
||||
type MetadataDepositPerByte = MetadataDepositPerByte;
|
||||
type ApprovalDeposit = ApprovalDeposit;
|
||||
type StringLimit = StringLimit;
|
||||
type WeightInfo = ();
|
||||
}
|
||||
|
||||
pub(crate) fn new_test_ext() -> sp_io::TestExternalities {
|
||||
let t = frame_system::GenesisConfig::default().build_storage::<Test>().unwrap();
|
||||
|
||||
let mut ext = sp_io::TestExternalities::new(t);
|
||||
ext.execute_with(|| System::set_block_number(1));
|
||||
ext
|
||||
}
|
||||
@@ -0,0 +1,493 @@
|
||||
// This file is part of Substrate.
|
||||
|
||||
// Copyright (C) 2019-2021 Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//! Tests for Assets pallet.
|
||||
|
||||
use super::*;
|
||||
use crate::{Error, mock::*};
|
||||
use frame_support::{assert_ok, assert_noop, traits::Currency};
|
||||
use pallet_balances::Error as BalancesError;
|
||||
|
||||
fn last_event() -> mock::Event {
|
||||
frame_system::Module::<Test>::events().pop().expect("Event expected").event
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn basic_minting_should_work() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_ok!(Assets::force_create(Origin::root(), 0, 1, true, 1));
|
||||
assert_ok!(Assets::mint(Origin::signed(1), 0, 1, 100));
|
||||
assert_eq!(Assets::balance(0, 1), 100);
|
||||
assert_ok!(Assets::mint(Origin::signed(1), 0, 2, 100));
|
||||
assert_eq!(Assets::balance(0, 2), 100);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn approval_lifecycle_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_ok!(Assets::force_create(Origin::root(), 0, 1, true, 1));
|
||||
assert_ok!(Assets::mint(Origin::signed(1), 0, 1, 100));
|
||||
Balances::make_free_balance_be(&1, 1);
|
||||
assert_ok!(Assets::approve_transfer(Origin::signed(1), 0, 2, 50));
|
||||
assert_eq!(Balances::reserved_balance(&1), 1);
|
||||
assert_ok!(Assets::transfer_approved(Origin::signed(2), 0, 1, 3, 40));
|
||||
assert_ok!(Assets::cancel_approval(Origin::signed(1), 0, 2));
|
||||
assert_eq!(Assets::balance(0, 1), 60);
|
||||
assert_eq!(Assets::balance(0, 3), 40);
|
||||
assert_eq!(Balances::reserved_balance(&1), 0);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn approval_deposits_work() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_ok!(Assets::force_create(Origin::root(), 0, 1, true, 1));
|
||||
assert_ok!(Assets::mint(Origin::signed(1), 0, 1, 100));
|
||||
let e = BalancesError::<Test>::InsufficientBalance;
|
||||
assert_noop!(Assets::approve_transfer(Origin::signed(1), 0, 2, 50), e);
|
||||
|
||||
Balances::make_free_balance_be(&1, 1);
|
||||
assert_ok!(Assets::approve_transfer(Origin::signed(1), 0, 2, 50));
|
||||
assert_eq!(Balances::reserved_balance(&1), 1);
|
||||
|
||||
assert_ok!(Assets::transfer_approved(Origin::signed(2), 0, 1, 3, 50));
|
||||
assert_eq!(Balances::reserved_balance(&1), 0);
|
||||
|
||||
assert_ok!(Assets::approve_transfer(Origin::signed(1), 0, 2, 50));
|
||||
assert_ok!(Assets::cancel_approval(Origin::signed(1), 0, 2));
|
||||
assert_eq!(Balances::reserved_balance(&1), 0);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cannot_transfer_more_than_approved() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_ok!(Assets::force_create(Origin::root(), 0, 1, true, 1));
|
||||
assert_ok!(Assets::mint(Origin::signed(1), 0, 1, 100));
|
||||
Balances::make_free_balance_be(&1, 1);
|
||||
assert_ok!(Assets::approve_transfer(Origin::signed(1), 0, 2, 50));
|
||||
let e = Error::<Test>::Unapproved;
|
||||
assert_noop!(Assets::transfer_approved(Origin::signed(2), 0, 1, 3, 51), e);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cannot_transfer_more_than_exists() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_ok!(Assets::force_create(Origin::root(), 0, 1, true, 1));
|
||||
assert_ok!(Assets::mint(Origin::signed(1), 0, 1, 100));
|
||||
Balances::make_free_balance_be(&1, 1);
|
||||
assert_ok!(Assets::approve_transfer(Origin::signed(1), 0, 2, 101));
|
||||
let e = Error::<Test>::BalanceLow;
|
||||
assert_noop!(Assets::transfer_approved(Origin::signed(2), 0, 1, 3, 101), e);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cancel_approval_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_ok!(Assets::force_create(Origin::root(), 0, 1, true, 1));
|
||||
assert_ok!(Assets::mint(Origin::signed(1), 0, 1, 100));
|
||||
Balances::make_free_balance_be(&1, 1);
|
||||
assert_ok!(Assets::approve_transfer(Origin::signed(1), 0, 2, 50));
|
||||
assert_noop!(Assets::cancel_approval(Origin::signed(1), 1, 2), Error::<Test>::Unknown);
|
||||
assert_noop!(Assets::cancel_approval(Origin::signed(2), 0, 2), Error::<Test>::Unknown);
|
||||
assert_noop!(Assets::cancel_approval(Origin::signed(1), 0, 3), Error::<Test>::Unknown);
|
||||
assert_ok!(Assets::cancel_approval(Origin::signed(1), 0, 2));
|
||||
assert_noop!(Assets::cancel_approval(Origin::signed(1), 0, 2), Error::<Test>::Unknown);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn force_cancel_approval_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_ok!(Assets::force_create(Origin::root(), 0, 1, true, 1));
|
||||
assert_ok!(Assets::mint(Origin::signed(1), 0, 1, 100));
|
||||
Balances::make_free_balance_be(&1, 1);
|
||||
assert_ok!(Assets::approve_transfer(Origin::signed(1), 0, 2, 50));
|
||||
let e = Error::<Test>::NoPermission;
|
||||
assert_noop!(Assets::force_cancel_approval(Origin::signed(2), 0, 1, 2), e);
|
||||
assert_noop!(Assets::force_cancel_approval(Origin::signed(1), 1, 1, 2), Error::<Test>::Unknown);
|
||||
assert_noop!(Assets::force_cancel_approval(Origin::signed(1), 0, 2, 2), Error::<Test>::Unknown);
|
||||
assert_noop!(Assets::force_cancel_approval(Origin::signed(1), 0, 1, 3), Error::<Test>::Unknown);
|
||||
assert_ok!(Assets::force_cancel_approval(Origin::signed(1), 0, 1, 2));
|
||||
assert_noop!(Assets::force_cancel_approval(Origin::signed(1), 0, 1, 2), Error::<Test>::Unknown);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn lifecycle_should_work() {
|
||||
new_test_ext().execute_with(|| {
|
||||
Balances::make_free_balance_be(&1, 100);
|
||||
assert_ok!(Assets::create(Origin::signed(1), 0, 1, 1));
|
||||
assert_eq!(Balances::reserved_balance(&1), 1);
|
||||
assert!(Asset::<Test>::contains_key(0));
|
||||
|
||||
assert_ok!(Assets::set_metadata(Origin::signed(1), 0, vec![0], vec![0], 12));
|
||||
assert_eq!(Balances::reserved_balance(&1), 4);
|
||||
assert!(Metadata::<Test>::contains_key(0));
|
||||
|
||||
Balances::make_free_balance_be(&10, 100);
|
||||
assert_ok!(Assets::mint(Origin::signed(1), 0, 10, 100));
|
||||
Balances::make_free_balance_be(&20, 100);
|
||||
assert_ok!(Assets::mint(Origin::signed(1), 0, 20, 100));
|
||||
assert_eq!(Account::<Test>::iter_prefix(0).count(), 2);
|
||||
|
||||
let w = Asset::<Test>::get(0).unwrap().destroy_witness();
|
||||
assert_ok!(Assets::destroy(Origin::signed(1), 0, w));
|
||||
assert_eq!(Balances::reserved_balance(&1), 0);
|
||||
|
||||
assert!(!Asset::<Test>::contains_key(0));
|
||||
assert!(!Metadata::<Test>::contains_key(0));
|
||||
assert_eq!(Account::<Test>::iter_prefix(0).count(), 0);
|
||||
|
||||
assert_ok!(Assets::create(Origin::signed(1), 0, 1, 1));
|
||||
assert_eq!(Balances::reserved_balance(&1), 1);
|
||||
assert!(Asset::<Test>::contains_key(0));
|
||||
|
||||
assert_ok!(Assets::set_metadata(Origin::signed(1), 0, vec![0], vec![0], 12));
|
||||
assert_eq!(Balances::reserved_balance(&1), 4);
|
||||
assert!(Metadata::<Test>::contains_key(0));
|
||||
|
||||
assert_ok!(Assets::mint(Origin::signed(1), 0, 10, 100));
|
||||
assert_ok!(Assets::mint(Origin::signed(1), 0, 20, 100));
|
||||
assert_eq!(Account::<Test>::iter_prefix(0).count(), 2);
|
||||
|
||||
let w = Asset::<Test>::get(0).unwrap().destroy_witness();
|
||||
assert_ok!(Assets::destroy(Origin::root(), 0, w));
|
||||
assert_eq!(Balances::reserved_balance(&1), 0);
|
||||
|
||||
assert!(!Asset::<Test>::contains_key(0));
|
||||
assert!(!Metadata::<Test>::contains_key(0));
|
||||
assert_eq!(Account::<Test>::iter_prefix(0).count(), 0);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn destroy_with_bad_witness_should_not_work() {
|
||||
new_test_ext().execute_with(|| {
|
||||
Balances::make_free_balance_be(&1, 100);
|
||||
assert_ok!(Assets::force_create(Origin::root(), 0, 1, true, 1));
|
||||
let w = Asset::<Test>::get(0).unwrap().destroy_witness();
|
||||
assert_ok!(Assets::mint(Origin::signed(1), 0, 10, 100));
|
||||
assert_noop!(Assets::destroy(Origin::signed(1), 0, w), Error::<Test>::BadWitness);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn non_providing_should_work() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_ok!(Assets::force_create(Origin::root(), 0, 1, false, 1));
|
||||
|
||||
Balances::make_free_balance_be(&0, 100);
|
||||
assert_ok!(Assets::mint(Origin::signed(1), 0, 0, 100));
|
||||
|
||||
// Cannot mint into account 2 since it doesn't (yet) exist...
|
||||
assert_noop!(Assets::mint(Origin::signed(1), 0, 1, 100), Error::<Test>::NoProvider);
|
||||
// ...or transfer...
|
||||
assert_noop!(Assets::transfer(Origin::signed(0), 0, 1, 50), Error::<Test>::NoProvider);
|
||||
// ...or force-transfer
|
||||
assert_noop!(Assets::force_transfer(Origin::signed(1), 0, 0, 1, 50), Error::<Test>::NoProvider);
|
||||
|
||||
Balances::make_free_balance_be(&1, 100);
|
||||
Balances::make_free_balance_be(&2, 100);
|
||||
assert_ok!(Assets::transfer(Origin::signed(0), 0, 1, 25));
|
||||
assert_ok!(Assets::force_transfer(Origin::signed(1), 0, 0, 2, 25));
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn min_balance_should_work() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_ok!(Assets::force_create(Origin::root(), 0, 1, true, 10));
|
||||
assert_ok!(Assets::mint(Origin::signed(1), 0, 1, 100));
|
||||
assert_eq!(Asset::<Test>::get(0).unwrap().accounts, 1);
|
||||
|
||||
// Cannot create a new account with a balance that is below minimum...
|
||||
assert_noop!(Assets::mint(Origin::signed(1), 0, 2, 9), Error::<Test>::BalanceLow);
|
||||
assert_noop!(Assets::transfer(Origin::signed(1), 0, 2, 9), Error::<Test>::BalanceLow);
|
||||
assert_noop!(Assets::force_transfer(Origin::signed(1), 0, 1, 2, 9), Error::<Test>::BalanceLow);
|
||||
|
||||
// When deducting from an account to below minimum, it should be reaped.
|
||||
|
||||
assert_ok!(Assets::transfer(Origin::signed(1), 0, 2, 91));
|
||||
assert!(Assets::balance(0, 1).is_zero());
|
||||
assert_eq!(Assets::balance(0, 2), 100);
|
||||
assert_eq!(Asset::<Test>::get(0).unwrap().accounts, 1);
|
||||
|
||||
assert_ok!(Assets::force_transfer(Origin::signed(1), 0, 2, 1, 91));
|
||||
assert!(Assets::balance(0, 2).is_zero());
|
||||
assert_eq!(Assets::balance(0, 1), 100);
|
||||
assert_eq!(Asset::<Test>::get(0).unwrap().accounts, 1);
|
||||
|
||||
assert_ok!(Assets::burn(Origin::signed(1), 0, 1, 91));
|
||||
assert!(Assets::balance(0, 1).is_zero());
|
||||
assert_eq!(Asset::<Test>::get(0).unwrap().accounts, 0);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn querying_total_supply_should_work() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_ok!(Assets::force_create(Origin::root(), 0, 1, true, 1));
|
||||
assert_ok!(Assets::mint(Origin::signed(1), 0, 1, 100));
|
||||
assert_eq!(Assets::balance(0, 1), 100);
|
||||
assert_ok!(Assets::transfer(Origin::signed(1), 0, 2, 50));
|
||||
assert_eq!(Assets::balance(0, 1), 50);
|
||||
assert_eq!(Assets::balance(0, 2), 50);
|
||||
assert_ok!(Assets::transfer(Origin::signed(2), 0, 3, 31));
|
||||
assert_eq!(Assets::balance(0, 1), 50);
|
||||
assert_eq!(Assets::balance(0, 2), 19);
|
||||
assert_eq!(Assets::balance(0, 3), 31);
|
||||
assert_ok!(Assets::burn(Origin::signed(1), 0, 3, u64::max_value()));
|
||||
assert_eq!(Assets::total_supply(0), 69);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn transferring_amount_below_available_balance_should_work() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_ok!(Assets::force_create(Origin::root(), 0, 1, true, 1));
|
||||
assert_ok!(Assets::mint(Origin::signed(1), 0, 1, 100));
|
||||
assert_eq!(Assets::balance(0, 1), 100);
|
||||
assert_ok!(Assets::transfer(Origin::signed(1), 0, 2, 50));
|
||||
assert_eq!(Assets::balance(0, 1), 50);
|
||||
assert_eq!(Assets::balance(0, 2), 50);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn transferring_enough_to_kill_source_when_keep_alive_should_fail() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_ok!(Assets::force_create(Origin::root(), 0, 1, true, 10));
|
||||
assert_ok!(Assets::mint(Origin::signed(1), 0, 1, 100));
|
||||
assert_eq!(Assets::balance(0, 1), 100);
|
||||
assert_noop!(Assets::transfer_keep_alive(Origin::signed(1), 0, 2, 91), Error::<Test>::WouldDie);
|
||||
assert_ok!(Assets::transfer_keep_alive(Origin::signed(1), 0, 2, 90));
|
||||
assert_eq!(Assets::balance(0, 1), 10);
|
||||
assert_eq!(Assets::balance(0, 2), 90);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn transferring_frozen_user_should_not_work() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_ok!(Assets::force_create(Origin::root(), 0, 1, true, 1));
|
||||
assert_ok!(Assets::mint(Origin::signed(1), 0, 1, 100));
|
||||
assert_eq!(Assets::balance(0, 1), 100);
|
||||
assert_ok!(Assets::freeze(Origin::signed(1), 0, 1));
|
||||
assert_noop!(Assets::transfer(Origin::signed(1), 0, 2, 50), Error::<Test>::Frozen);
|
||||
assert_ok!(Assets::thaw(Origin::signed(1), 0, 1));
|
||||
assert_ok!(Assets::transfer(Origin::signed(1), 0, 2, 50));
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn transferring_frozen_asset_should_not_work() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_ok!(Assets::force_create(Origin::root(), 0, 1, true, 1));
|
||||
assert_ok!(Assets::mint(Origin::signed(1), 0, 1, 100));
|
||||
assert_eq!(Assets::balance(0, 1), 100);
|
||||
assert_ok!(Assets::freeze_asset(Origin::signed(1), 0));
|
||||
assert_noop!(Assets::transfer(Origin::signed(1), 0, 2, 50), Error::<Test>::Frozen);
|
||||
assert_ok!(Assets::thaw_asset(Origin::signed(1), 0));
|
||||
assert_ok!(Assets::transfer(Origin::signed(1), 0, 2, 50));
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn origin_guards_should_work() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_ok!(Assets::force_create(Origin::root(), 0, 1, true, 1));
|
||||
assert_ok!(Assets::mint(Origin::signed(1), 0, 1, 100));
|
||||
assert_noop!(Assets::transfer_ownership(Origin::signed(2), 0, 2), Error::<Test>::NoPermission);
|
||||
assert_noop!(Assets::set_team(Origin::signed(2), 0, 2, 2, 2), Error::<Test>::NoPermission);
|
||||
assert_noop!(Assets::freeze(Origin::signed(2), 0, 1), Error::<Test>::NoPermission);
|
||||
assert_noop!(Assets::thaw(Origin::signed(2), 0, 2), Error::<Test>::NoPermission);
|
||||
assert_noop!(Assets::mint(Origin::signed(2), 0, 2, 100), Error::<Test>::NoPermission);
|
||||
assert_noop!(Assets::burn(Origin::signed(2), 0, 1, 100), Error::<Test>::NoPermission);
|
||||
assert_noop!(Assets::force_transfer(Origin::signed(2), 0, 1, 2, 100), Error::<Test>::NoPermission);
|
||||
let w = Asset::<Test>::get(0).unwrap().destroy_witness();
|
||||
assert_noop!(Assets::destroy(Origin::signed(2), 0, w), Error::<Test>::NoPermission);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn transfer_owner_should_work() {
|
||||
new_test_ext().execute_with(|| {
|
||||
Balances::make_free_balance_be(&1, 100);
|
||||
Balances::make_free_balance_be(&2, 100);
|
||||
assert_ok!(Assets::create(Origin::signed(1), 0, 1, 1));
|
||||
|
||||
assert_eq!(Balances::reserved_balance(&1), 1);
|
||||
|
||||
assert_ok!(Assets::transfer_ownership(Origin::signed(1), 0, 2));
|
||||
assert_eq!(Balances::reserved_balance(&2), 1);
|
||||
assert_eq!(Balances::reserved_balance(&1), 0);
|
||||
|
||||
assert_noop!(Assets::transfer_ownership(Origin::signed(1), 0, 1), Error::<Test>::NoPermission);
|
||||
|
||||
// Set metadata now and make sure that deposit gets transferred back.
|
||||
assert_ok!(Assets::set_metadata(Origin::signed(2), 0, vec![0u8; 10], vec![0u8; 10], 12));
|
||||
assert_ok!(Assets::transfer_ownership(Origin::signed(2), 0, 1));
|
||||
assert_eq!(Balances::reserved_balance(&1), 22);
|
||||
assert_eq!(Balances::reserved_balance(&2), 0);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn set_team_should_work() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_ok!(Assets::force_create(Origin::root(), 0, 1, true, 1));
|
||||
assert_ok!(Assets::set_team(Origin::signed(1), 0, 2, 3, 4));
|
||||
|
||||
assert_ok!(Assets::mint(Origin::signed(2), 0, 2, 100));
|
||||
assert_ok!(Assets::freeze(Origin::signed(4), 0, 2));
|
||||
assert_ok!(Assets::thaw(Origin::signed(3), 0, 2));
|
||||
assert_ok!(Assets::force_transfer(Origin::signed(3), 0, 2, 3, 100));
|
||||
assert_ok!(Assets::burn(Origin::signed(3), 0, 3, 100));
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn transferring_to_frozen_account_should_work() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_ok!(Assets::force_create(Origin::root(), 0, 1, true, 1));
|
||||
assert_ok!(Assets::mint(Origin::signed(1), 0, 1, 100));
|
||||
assert_ok!(Assets::mint(Origin::signed(1), 0, 2, 100));
|
||||
assert_eq!(Assets::balance(0, 1), 100);
|
||||
assert_eq!(Assets::balance(0, 2), 100);
|
||||
assert_ok!(Assets::freeze(Origin::signed(1), 0, 2));
|
||||
assert_ok!(Assets::transfer(Origin::signed(1), 0, 2, 50));
|
||||
assert_eq!(Assets::balance(0, 2), 150);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn transferring_amount_more_than_available_balance_should_not_work() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_ok!(Assets::force_create(Origin::root(), 0, 1, true, 1));
|
||||
assert_ok!(Assets::mint(Origin::signed(1), 0, 1, 100));
|
||||
assert_eq!(Assets::balance(0, 1), 100);
|
||||
assert_ok!(Assets::transfer(Origin::signed(1), 0, 2, 50));
|
||||
assert_eq!(Assets::balance(0, 1), 50);
|
||||
assert_eq!(Assets::balance(0, 2), 50);
|
||||
assert_ok!(Assets::burn(Origin::signed(1), 0, 1, u64::max_value()));
|
||||
assert_eq!(Assets::balance(0, 1), 0);
|
||||
assert_noop!(Assets::transfer(Origin::signed(1), 0, 1, 50), Error::<Test>::BalanceLow);
|
||||
assert_noop!(Assets::transfer(Origin::signed(2), 0, 1, 51), Error::<Test>::BalanceLow);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn transferring_less_than_one_unit_is_fine() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_ok!(Assets::force_create(Origin::root(), 0, 1, true, 1));
|
||||
assert_ok!(Assets::mint(Origin::signed(1), 0, 1, 100));
|
||||
assert_eq!(Assets::balance(0, 1), 100);
|
||||
assert_ok!(Assets::transfer(Origin::signed(1), 0, 2, 0));
|
||||
assert_eq!(
|
||||
last_event(),
|
||||
mock::Event::pallet_assets(crate::Event::Transferred(0, 1, 2, 0)),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn transferring_more_units_than_total_supply_should_not_work() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_ok!(Assets::force_create(Origin::root(), 0, 1, true, 1));
|
||||
assert_ok!(Assets::mint(Origin::signed(1), 0, 1, 100));
|
||||
assert_eq!(Assets::balance(0, 1), 100);
|
||||
assert_noop!(Assets::transfer(Origin::signed(1), 0, 2, 101), Error::<Test>::BalanceLow);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn burning_asset_balance_with_positive_balance_should_work() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_ok!(Assets::force_create(Origin::root(), 0, 1, true, 1));
|
||||
assert_ok!(Assets::mint(Origin::signed(1), 0, 1, 100));
|
||||
assert_eq!(Assets::balance(0, 1), 100);
|
||||
assert_ok!(Assets::burn(Origin::signed(1), 0, 1, u64::max_value()));
|
||||
assert_eq!(Assets::balance(0, 1), 0);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn burning_asset_balance_with_zero_balance_should_not_work() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_ok!(Assets::force_create(Origin::root(), 0, 1, true, 1));
|
||||
assert_ok!(Assets::mint(Origin::signed(1), 0, 1, 100));
|
||||
assert_eq!(Assets::balance(0, 2), 0);
|
||||
assert_noop!(Assets::burn(Origin::signed(1), 0, 2, u64::max_value()), Error::<Test>::BalanceZero);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn set_metadata_should_work() {
|
||||
new_test_ext().execute_with(|| {
|
||||
// Cannot add metadata to unknown asset
|
||||
assert_noop!(
|
||||
Assets::set_metadata(Origin::signed(1), 0, vec![0u8; 10], vec![0u8; 10], 12),
|
||||
Error::<Test>::Unknown,
|
||||
);
|
||||
assert_ok!(Assets::force_create(Origin::root(), 0, 1, true, 1));
|
||||
// Cannot add metadata to unowned asset
|
||||
assert_noop!(
|
||||
Assets::set_metadata(Origin::signed(2), 0, vec![0u8; 10], vec![0u8; 10], 12),
|
||||
Error::<Test>::NoPermission,
|
||||
);
|
||||
|
||||
// Cannot add oversized metadata
|
||||
assert_noop!(
|
||||
Assets::set_metadata(Origin::signed(1), 0, vec![0u8; 100], vec![0u8; 10], 12),
|
||||
Error::<Test>::BadMetadata,
|
||||
);
|
||||
assert_noop!(
|
||||
Assets::set_metadata(Origin::signed(1), 0, vec![0u8; 10], vec![0u8; 100], 12),
|
||||
Error::<Test>::BadMetadata,
|
||||
);
|
||||
|
||||
// Successfully add metadata and take deposit
|
||||
Balances::make_free_balance_be(&1, 30);
|
||||
assert_ok!(Assets::set_metadata(Origin::signed(1), 0, vec![0u8; 10], vec![0u8; 10], 12));
|
||||
assert_eq!(Balances::free_balance(&1), 9);
|
||||
|
||||
// Update deposit
|
||||
assert_ok!(Assets::set_metadata(Origin::signed(1), 0, vec![0u8; 10], vec![0u8; 5], 12));
|
||||
assert_eq!(Balances::free_balance(&1), 14);
|
||||
assert_ok!(Assets::set_metadata(Origin::signed(1), 0, vec![0u8; 10], vec![0u8; 15], 12));
|
||||
assert_eq!(Balances::free_balance(&1), 4);
|
||||
|
||||
// Cannot over-reserve
|
||||
assert_noop!(
|
||||
Assets::set_metadata(Origin::signed(1), 0, vec![0u8; 20], vec![0u8; 20], 12),
|
||||
BalancesError::<Test, _>::InsufficientBalance,
|
||||
);
|
||||
|
||||
// Clear Metadata
|
||||
assert!(Metadata::<Test>::contains_key(0));
|
||||
assert_noop!(Assets::clear_metadata(Origin::signed(2), 0), Error::<Test>::NoPermission);
|
||||
assert_noop!(Assets::clear_metadata(Origin::signed(1), 1), Error::<Test>::Unknown);
|
||||
assert_ok!(Assets::clear_metadata(Origin::signed(1), 0));
|
||||
assert!(!Metadata::<Test>::contains_key(0));
|
||||
});
|
||||
}
|
||||
|
||||
// TODO: tests for force_set_metadata, force_clear_metadata, force_asset_status
|
||||
@@ -17,8 +17,8 @@
|
||||
|
||||
//! Autogenerated weights for pallet_assets
|
||||
//!
|
||||
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 2.0.1
|
||||
//! DATE: 2021-01-18, STEPS: `[50, ]`, REPEAT: 20, LOW RANGE: [], HIGH RANGE: []
|
||||
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 3.0.0
|
||||
//! DATE: 2021-03-08, STEPS: `[50, ]`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]`
|
||||
//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 128
|
||||
|
||||
// Executed Command:
|
||||
@@ -46,11 +46,11 @@ use sp_std::marker::PhantomData;
|
||||
pub trait WeightInfo {
|
||||
fn create() -> Weight;
|
||||
fn force_create() -> Weight;
|
||||
fn destroy(z: u32, ) -> Weight;
|
||||
fn force_destroy(z: u32, ) -> Weight;
|
||||
fn destroy(c: u32, s: u32, a: u32, ) -> Weight;
|
||||
fn mint() -> Weight;
|
||||
fn burn() -> Weight;
|
||||
fn transfer() -> Weight;
|
||||
fn transfer_keep_alive() -> Weight;
|
||||
fn force_transfer() -> Weight;
|
||||
fn freeze() -> Weight;
|
||||
fn thaw() -> Weight;
|
||||
@@ -58,100 +58,147 @@ pub trait WeightInfo {
|
||||
fn thaw_asset() -> Weight;
|
||||
fn transfer_ownership() -> Weight;
|
||||
fn set_team() -> Weight;
|
||||
fn set_max_zombies() -> Weight;
|
||||
fn set_metadata(n: u32, s: u32, ) -> Weight;
|
||||
fn clear_metadata() -> Weight;
|
||||
fn force_set_metadata(n: u32, s: u32, ) -> Weight;
|
||||
fn force_clear_metadata() -> Weight;
|
||||
fn force_asset_status() -> Weight;
|
||||
fn approve_transfer() -> Weight;
|
||||
fn transfer_approved() -> Weight;
|
||||
fn cancel_approval() -> Weight;
|
||||
fn force_cancel_approval() -> Weight;
|
||||
}
|
||||
|
||||
/// Weights for pallet_assets using the Substrate node and recommended hardware.
|
||||
pub struct SubstrateWeight<T>(PhantomData<T>);
|
||||
impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
|
||||
fn create() -> Weight {
|
||||
(44_459_000 as Weight)
|
||||
(48_305_000 as Weight)
|
||||
.saturating_add(T::DbWeight::get().reads(1 as Weight))
|
||||
.saturating_add(T::DbWeight::get().writes(1 as Weight))
|
||||
}
|
||||
fn force_create() -> Weight {
|
||||
(21_480_000 as Weight)
|
||||
(23_827_000 as Weight)
|
||||
.saturating_add(T::DbWeight::get().reads(1 as Weight))
|
||||
.saturating_add(T::DbWeight::get().writes(1 as Weight))
|
||||
}
|
||||
fn destroy(z: u32, ) -> Weight {
|
||||
fn destroy(c: u32, s: u32, a: u32, ) -> Weight {
|
||||
(0 as Weight)
|
||||
// Standard Error: 2_000
|
||||
.saturating_add((1_149_000 as Weight).saturating_mul(z as Weight))
|
||||
.saturating_add(T::DbWeight::get().reads(2 as Weight))
|
||||
.saturating_add(T::DbWeight::get().writes(1 as Weight))
|
||||
.saturating_add(T::DbWeight::get().writes((1 as Weight).saturating_mul(z as Weight)))
|
||||
}
|
||||
fn force_destroy(z: u32, ) -> Weight {
|
||||
(0 as Weight)
|
||||
// Standard Error: 2_000
|
||||
.saturating_add((1_146_000 as Weight).saturating_mul(z as Weight))
|
||||
.saturating_add(T::DbWeight::get().reads(2 as Weight))
|
||||
.saturating_add(T::DbWeight::get().writes(1 as Weight))
|
||||
.saturating_add(T::DbWeight::get().writes((1 as Weight).saturating_mul(z as Weight)))
|
||||
// Standard Error: 38_000
|
||||
.saturating_add((24_232_000 as Weight).saturating_mul(c as Weight))
|
||||
// Standard Error: 38_000
|
||||
.saturating_add((30_467_000 as Weight).saturating_mul(s as Weight))
|
||||
// Standard Error: 383_000
|
||||
.saturating_add((2_343_000 as Weight).saturating_mul(a as Weight))
|
||||
.saturating_add(T::DbWeight::get().reads(4 as Weight))
|
||||
.saturating_add(T::DbWeight::get().reads((2 as Weight).saturating_mul(c as Weight)))
|
||||
.saturating_add(T::DbWeight::get().reads((2 as Weight).saturating_mul(s as Weight)))
|
||||
.saturating_add(T::DbWeight::get().writes(2 as Weight))
|
||||
.saturating_add(T::DbWeight::get().writes((2 as Weight).saturating_mul(c as Weight)))
|
||||
.saturating_add(T::DbWeight::get().writes((2 as Weight).saturating_mul(s as Weight)))
|
||||
.saturating_add(T::DbWeight::get().writes((1 as Weight).saturating_mul(a as Weight)))
|
||||
}
|
||||
fn mint() -> Weight {
|
||||
(32_995_000 as Weight)
|
||||
(46_433_000 as Weight)
|
||||
.saturating_add(T::DbWeight::get().reads(2 as Weight))
|
||||
.saturating_add(T::DbWeight::get().writes(2 as Weight))
|
||||
}
|
||||
fn burn() -> Weight {
|
||||
(29_245_000 as Weight)
|
||||
(46_000_000 as Weight)
|
||||
.saturating_add(T::DbWeight::get().reads(2 as Weight))
|
||||
.saturating_add(T::DbWeight::get().writes(2 as Weight))
|
||||
}
|
||||
fn transfer() -> Weight {
|
||||
(42_211_000 as Weight)
|
||||
(70_793_000 as Weight)
|
||||
.saturating_add(T::DbWeight::get().reads(4 as Weight))
|
||||
.saturating_add(T::DbWeight::get().writes(3 as Weight))
|
||||
.saturating_add(T::DbWeight::get().writes(4 as Weight))
|
||||
}
|
||||
fn transfer_keep_alive() -> Weight {
|
||||
(57_453_000 as Weight)
|
||||
.saturating_add(T::DbWeight::get().reads(4 as Weight))
|
||||
.saturating_add(T::DbWeight::get().writes(4 as Weight))
|
||||
}
|
||||
fn force_transfer() -> Weight {
|
||||
(42_218_000 as Weight)
|
||||
(70_968_000 as Weight)
|
||||
.saturating_add(T::DbWeight::get().reads(4 as Weight))
|
||||
.saturating_add(T::DbWeight::get().writes(3 as Weight))
|
||||
.saturating_add(T::DbWeight::get().writes(4 as Weight))
|
||||
}
|
||||
fn freeze() -> Weight {
|
||||
(31_079_000 as Weight)
|
||||
(34_290_000 as Weight)
|
||||
.saturating_add(T::DbWeight::get().reads(2 as Weight))
|
||||
.saturating_add(T::DbWeight::get().writes(1 as Weight))
|
||||
}
|
||||
fn thaw() -> Weight {
|
||||
(30_853_000 as Weight)
|
||||
(34_419_000 as Weight)
|
||||
.saturating_add(T::DbWeight::get().reads(2 as Weight))
|
||||
.saturating_add(T::DbWeight::get().writes(1 as Weight))
|
||||
}
|
||||
fn freeze_asset() -> Weight {
|
||||
(22_383_000 as Weight)
|
||||
(24_373_000 as Weight)
|
||||
.saturating_add(T::DbWeight::get().reads(1 as Weight))
|
||||
.saturating_add(T::DbWeight::get().writes(1 as Weight))
|
||||
}
|
||||
fn thaw_asset() -> Weight {
|
||||
(22_341_000 as Weight)
|
||||
(24_096_000 as Weight)
|
||||
.saturating_add(T::DbWeight::get().reads(1 as Weight))
|
||||
.saturating_add(T::DbWeight::get().writes(1 as Weight))
|
||||
}
|
||||
fn transfer_ownership() -> Weight {
|
||||
(22_782_000 as Weight)
|
||||
.saturating_add(T::DbWeight::get().reads(1 as Weight))
|
||||
(28_566_000 as Weight)
|
||||
.saturating_add(T::DbWeight::get().reads(2 as Weight))
|
||||
.saturating_add(T::DbWeight::get().writes(1 as Weight))
|
||||
}
|
||||
fn set_team() -> Weight {
|
||||
(23_293_000 as Weight)
|
||||
(25_297_000 as Weight)
|
||||
.saturating_add(T::DbWeight::get().reads(1 as Weight))
|
||||
.saturating_add(T::DbWeight::get().writes(1 as Weight))
|
||||
}
|
||||
fn set_max_zombies() -> Weight {
|
||||
(44_525_000 as Weight)
|
||||
fn set_metadata(_n: u32, s: u32, ) -> Weight {
|
||||
(53_367_000 as Weight)
|
||||
// Standard Error: 0
|
||||
.saturating_add((8_000 as Weight).saturating_mul(s as Weight))
|
||||
.saturating_add(T::DbWeight::get().reads(2 as Weight))
|
||||
.saturating_add(T::DbWeight::get().writes(1 as Weight))
|
||||
}
|
||||
fn clear_metadata() -> Weight {
|
||||
(51_721_000 as Weight)
|
||||
.saturating_add(T::DbWeight::get().reads(2 as Weight))
|
||||
.saturating_add(T::DbWeight::get().writes(1 as Weight))
|
||||
}
|
||||
fn force_set_metadata(_n: u32, s: u32, ) -> Weight {
|
||||
(27_117_000 as Weight)
|
||||
// Standard Error: 0
|
||||
.saturating_add((5_000 as Weight).saturating_mul(s as Weight))
|
||||
.saturating_add(T::DbWeight::get().reads(2 as Weight))
|
||||
.saturating_add(T::DbWeight::get().writes(1 as Weight))
|
||||
}
|
||||
fn force_clear_metadata() -> Weight {
|
||||
(51_598_000 as Weight)
|
||||
.saturating_add(T::DbWeight::get().reads(2 as Weight))
|
||||
.saturating_add(T::DbWeight::get().writes(1 as Weight))
|
||||
}
|
||||
fn force_asset_status() -> Weight {
|
||||
(23_366_000 as Weight)
|
||||
.saturating_add(T::DbWeight::get().reads(1 as Weight))
|
||||
.saturating_add(T::DbWeight::get().writes(1 as Weight))
|
||||
}
|
||||
fn set_metadata(n: u32, s: u32, ) -> Weight {
|
||||
(49_456_000 as Weight)
|
||||
// Standard Error: 0
|
||||
.saturating_add((1_000 as Weight).saturating_mul(n as Weight))
|
||||
// Standard Error: 0
|
||||
.saturating_add((6_000 as Weight).saturating_mul(s as Weight))
|
||||
fn approve_transfer() -> Weight {
|
||||
(47_906_000 as Weight)
|
||||
.saturating_add(T::DbWeight::get().reads(1 as Weight))
|
||||
.saturating_add(T::DbWeight::get().writes(1 as Weight))
|
||||
}
|
||||
fn transfer_approved() -> Weight {
|
||||
(90_338_000 as Weight)
|
||||
.saturating_add(T::DbWeight::get().reads(5 as Weight))
|
||||
.saturating_add(T::DbWeight::get().writes(5 as Weight))
|
||||
}
|
||||
fn cancel_approval() -> Weight {
|
||||
(48_591_000 as Weight)
|
||||
.saturating_add(T::DbWeight::get().reads(1 as Weight))
|
||||
.saturating_add(T::DbWeight::get().writes(1 as Weight))
|
||||
}
|
||||
fn force_cancel_approval() -> Weight {
|
||||
(54_879_000 as Weight)
|
||||
.saturating_add(T::DbWeight::get().reads(2 as Weight))
|
||||
.saturating_add(T::DbWeight::get().writes(1 as Weight))
|
||||
}
|
||||
@@ -160,92 +207,132 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
|
||||
// For backwards compatibility and tests
|
||||
impl WeightInfo for () {
|
||||
fn create() -> Weight {
|
||||
(44_459_000 as Weight)
|
||||
(48_305_000 as Weight)
|
||||
.saturating_add(RocksDbWeight::get().reads(1 as Weight))
|
||||
.saturating_add(RocksDbWeight::get().writes(1 as Weight))
|
||||
}
|
||||
fn force_create() -> Weight {
|
||||
(21_480_000 as Weight)
|
||||
(23_827_000 as Weight)
|
||||
.saturating_add(RocksDbWeight::get().reads(1 as Weight))
|
||||
.saturating_add(RocksDbWeight::get().writes(1 as Weight))
|
||||
}
|
||||
fn destroy(z: u32, ) -> Weight {
|
||||
fn destroy(c: u32, s: u32, a: u32, ) -> Weight {
|
||||
(0 as Weight)
|
||||
// Standard Error: 2_000
|
||||
.saturating_add((1_149_000 as Weight).saturating_mul(z as Weight))
|
||||
.saturating_add(RocksDbWeight::get().reads(2 as Weight))
|
||||
.saturating_add(RocksDbWeight::get().writes(1 as Weight))
|
||||
.saturating_add(RocksDbWeight::get().writes((1 as Weight).saturating_mul(z as Weight)))
|
||||
}
|
||||
fn force_destroy(z: u32, ) -> Weight {
|
||||
(0 as Weight)
|
||||
// Standard Error: 2_000
|
||||
.saturating_add((1_146_000 as Weight).saturating_mul(z as Weight))
|
||||
.saturating_add(RocksDbWeight::get().reads(2 as Weight))
|
||||
.saturating_add(RocksDbWeight::get().writes(1 as Weight))
|
||||
.saturating_add(RocksDbWeight::get().writes((1 as Weight).saturating_mul(z as Weight)))
|
||||
// Standard Error: 38_000
|
||||
.saturating_add((24_232_000 as Weight).saturating_mul(c as Weight))
|
||||
// Standard Error: 38_000
|
||||
.saturating_add((30_467_000 as Weight).saturating_mul(s as Weight))
|
||||
// Standard Error: 383_000
|
||||
.saturating_add((2_343_000 as Weight).saturating_mul(a as Weight))
|
||||
.saturating_add(RocksDbWeight::get().reads(4 as Weight))
|
||||
.saturating_add(RocksDbWeight::get().reads((2 as Weight).saturating_mul(c as Weight)))
|
||||
.saturating_add(RocksDbWeight::get().reads((2 as Weight).saturating_mul(s as Weight)))
|
||||
.saturating_add(RocksDbWeight::get().writes(2 as Weight))
|
||||
.saturating_add(RocksDbWeight::get().writes((2 as Weight).saturating_mul(c as Weight)))
|
||||
.saturating_add(RocksDbWeight::get().writes((2 as Weight).saturating_mul(s as Weight)))
|
||||
.saturating_add(RocksDbWeight::get().writes((1 as Weight).saturating_mul(a as Weight)))
|
||||
}
|
||||
fn mint() -> Weight {
|
||||
(32_995_000 as Weight)
|
||||
(46_433_000 as Weight)
|
||||
.saturating_add(RocksDbWeight::get().reads(2 as Weight))
|
||||
.saturating_add(RocksDbWeight::get().writes(2 as Weight))
|
||||
}
|
||||
fn burn() -> Weight {
|
||||
(29_245_000 as Weight)
|
||||
(46_000_000 as Weight)
|
||||
.saturating_add(RocksDbWeight::get().reads(2 as Weight))
|
||||
.saturating_add(RocksDbWeight::get().writes(2 as Weight))
|
||||
}
|
||||
fn transfer() -> Weight {
|
||||
(42_211_000 as Weight)
|
||||
(70_793_000 as Weight)
|
||||
.saturating_add(RocksDbWeight::get().reads(4 as Weight))
|
||||
.saturating_add(RocksDbWeight::get().writes(3 as Weight))
|
||||
.saturating_add(RocksDbWeight::get().writes(4 as Weight))
|
||||
}
|
||||
fn transfer_keep_alive() -> Weight {
|
||||
(57_453_000 as Weight)
|
||||
.saturating_add(RocksDbWeight::get().reads(4 as Weight))
|
||||
.saturating_add(RocksDbWeight::get().writes(4 as Weight))
|
||||
}
|
||||
fn force_transfer() -> Weight {
|
||||
(42_218_000 as Weight)
|
||||
(70_968_000 as Weight)
|
||||
.saturating_add(RocksDbWeight::get().reads(4 as Weight))
|
||||
.saturating_add(RocksDbWeight::get().writes(3 as Weight))
|
||||
.saturating_add(RocksDbWeight::get().writes(4 as Weight))
|
||||
}
|
||||
fn freeze() -> Weight {
|
||||
(31_079_000 as Weight)
|
||||
(34_290_000 as Weight)
|
||||
.saturating_add(RocksDbWeight::get().reads(2 as Weight))
|
||||
.saturating_add(RocksDbWeight::get().writes(1 as Weight))
|
||||
}
|
||||
fn thaw() -> Weight {
|
||||
(30_853_000 as Weight)
|
||||
(34_419_000 as Weight)
|
||||
.saturating_add(RocksDbWeight::get().reads(2 as Weight))
|
||||
.saturating_add(RocksDbWeight::get().writes(1 as Weight))
|
||||
}
|
||||
fn freeze_asset() -> Weight {
|
||||
(22_383_000 as Weight)
|
||||
(24_373_000 as Weight)
|
||||
.saturating_add(RocksDbWeight::get().reads(1 as Weight))
|
||||
.saturating_add(RocksDbWeight::get().writes(1 as Weight))
|
||||
}
|
||||
fn thaw_asset() -> Weight {
|
||||
(22_341_000 as Weight)
|
||||
(24_096_000 as Weight)
|
||||
.saturating_add(RocksDbWeight::get().reads(1 as Weight))
|
||||
.saturating_add(RocksDbWeight::get().writes(1 as Weight))
|
||||
}
|
||||
fn transfer_ownership() -> Weight {
|
||||
(22_782_000 as Weight)
|
||||
.saturating_add(RocksDbWeight::get().reads(1 as Weight))
|
||||
(28_566_000 as Weight)
|
||||
.saturating_add(RocksDbWeight::get().reads(2 as Weight))
|
||||
.saturating_add(RocksDbWeight::get().writes(1 as Weight))
|
||||
}
|
||||
fn set_team() -> Weight {
|
||||
(23_293_000 as Weight)
|
||||
(25_297_000 as Weight)
|
||||
.saturating_add(RocksDbWeight::get().reads(1 as Weight))
|
||||
.saturating_add(RocksDbWeight::get().writes(1 as Weight))
|
||||
}
|
||||
fn set_max_zombies() -> Weight {
|
||||
(44_525_000 as Weight)
|
||||
fn set_metadata(_n: u32, s: u32, ) -> Weight {
|
||||
(53_367_000 as Weight)
|
||||
// Standard Error: 0
|
||||
.saturating_add((8_000 as Weight).saturating_mul(s as Weight))
|
||||
.saturating_add(RocksDbWeight::get().reads(2 as Weight))
|
||||
.saturating_add(RocksDbWeight::get().writes(1 as Weight))
|
||||
}
|
||||
fn clear_metadata() -> Weight {
|
||||
(51_721_000 as Weight)
|
||||
.saturating_add(RocksDbWeight::get().reads(2 as Weight))
|
||||
.saturating_add(RocksDbWeight::get().writes(1 as Weight))
|
||||
}
|
||||
fn force_set_metadata(_n: u32, s: u32, ) -> Weight {
|
||||
(27_117_000 as Weight)
|
||||
// Standard Error: 0
|
||||
.saturating_add((5_000 as Weight).saturating_mul(s as Weight))
|
||||
.saturating_add(RocksDbWeight::get().reads(2 as Weight))
|
||||
.saturating_add(RocksDbWeight::get().writes(1 as Weight))
|
||||
}
|
||||
fn force_clear_metadata() -> Weight {
|
||||
(51_598_000 as Weight)
|
||||
.saturating_add(RocksDbWeight::get().reads(2 as Weight))
|
||||
.saturating_add(RocksDbWeight::get().writes(1 as Weight))
|
||||
}
|
||||
fn force_asset_status() -> Weight {
|
||||
(23_366_000 as Weight)
|
||||
.saturating_add(RocksDbWeight::get().reads(1 as Weight))
|
||||
.saturating_add(RocksDbWeight::get().writes(1 as Weight))
|
||||
}
|
||||
fn set_metadata(n: u32, s: u32, ) -> Weight {
|
||||
(49_456_000 as Weight)
|
||||
// Standard Error: 0
|
||||
.saturating_add((1_000 as Weight).saturating_mul(n as Weight))
|
||||
// Standard Error: 0
|
||||
.saturating_add((6_000 as Weight).saturating_mul(s as Weight))
|
||||
fn approve_transfer() -> Weight {
|
||||
(47_906_000 as Weight)
|
||||
.saturating_add(RocksDbWeight::get().reads(1 as Weight))
|
||||
.saturating_add(RocksDbWeight::get().writes(1 as Weight))
|
||||
}
|
||||
fn transfer_approved() -> Weight {
|
||||
(90_338_000 as Weight)
|
||||
.saturating_add(RocksDbWeight::get().reads(5 as Weight))
|
||||
.saturating_add(RocksDbWeight::get().writes(5 as Weight))
|
||||
}
|
||||
fn cancel_approval() -> Weight {
|
||||
(48_591_000 as Weight)
|
||||
.saturating_add(RocksDbWeight::get().reads(1 as Weight))
|
||||
.saturating_add(RocksDbWeight::get().writes(1 as Weight))
|
||||
}
|
||||
fn force_cancel_approval() -> Weight {
|
||||
(54_879_000 as Weight)
|
||||
.saturating_add(RocksDbWeight::get().reads(2 as Weight))
|
||||
.saturating_add(RocksDbWeight::get().writes(1 as Weight))
|
||||
}
|
||||
|
||||
@@ -50,7 +50,6 @@ impl frame_system::Config for Test {
|
||||
type BaseCallFilter = ();
|
||||
type BlockWeights = ();
|
||||
type BlockLength = ();
|
||||
type DbWeight = ();
|
||||
type Origin = Origin;
|
||||
type Call = Call;
|
||||
type Index = u64;
|
||||
@@ -62,6 +61,7 @@ impl frame_system::Config for Test {
|
||||
type Header = Header;
|
||||
type Event = Event;
|
||||
type BlockHashCount = BlockHashCount;
|
||||
type DbWeight = ();
|
||||
type Version = ();
|
||||
type PalletInfo = PalletInfo;
|
||||
type AccountData = pallet_balances::AccountData<u64>;
|
||||
@@ -76,13 +76,13 @@ parameter_types! {
|
||||
}
|
||||
|
||||
impl pallet_balances::Config for Test {
|
||||
type MaxLocks = ();
|
||||
type Balance = u64;
|
||||
type DustRemoval = ();
|
||||
type Event = Event;
|
||||
type ExistentialDeposit = ExistentialDeposit;
|
||||
type AccountStore = System;
|
||||
type WeightInfo = ();
|
||||
type MaxLocks = ();
|
||||
}
|
||||
|
||||
parameter_types! {
|
||||
|
||||
Reference in New Issue
Block a user