mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 01:11:10 +00:00
Features needed for reserve-backed stablecoins (#7152)
* Features needed for reserve-backed stablecoins * Builds & tests. * Double map for an efficient destroy. * Update frame/assets/src/lib.rs Co-authored-by: Nikolay Volf <nikvolf@gmail.com> * ED/zombie-count/refs Feature: ED/minimum balance enforcement Feature: enforce zombie count Feature: allow system-alive accounts to exist, but add reference * Update frame/assets/src/lib.rs Co-authored-by: Nikolay Volf <nikvolf@gmail.com> * Update frame/assets/Cargo.toml Co-authored-by: Niklas Adolfsson <niklasadolfsson1@gmail.com> * Docs * Some tests * More tests * Allow for max_zombies to be adjusted * Test for set_max_zombies * Tests and a couple of fixes * First few benchmarks * Benchmarks. * Fix error message in test * Fixes * Fixes * Fixes * cargo run --release --features runtime-benchmarks --manifest-path bin/node/cli/Cargo.toml -- benchmark --chain dev --steps 50 --repeat 20 --extrinsic * --execution=wasm --wasm-execution=compiled --output ./bin/node/runtime/src/weights --header ./HEADER --pallet pallet_assets * Update frame/assets/src/lib.rs Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com> * Fixes * Fixes * Fixes * cargo run --release --features runtime-benchmarks --manifest-path bin/node/cli/Cargo.toml -- benchmark --chain dev --steps 50 --repeat 20 --extrinsic * --execution=wasm --wasm-execution=compiled --output ./bin/node/runtime/src/weights --header ./HEADER --pallet pallet_assets * Fixes * Update default weight * Add proper verification to benchmarks * minor improvements to tests * Update frame/assets/src/benchmarking.rs Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> * Fix * New weights system * fix compile * 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: Nikolay Volf <nikvolf@gmail.com> Co-authored-by: Niklas Adolfsson <niklasadolfsson1@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> Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
This commit is contained in:
Generated
+3
@@ -3895,6 +3895,7 @@ dependencies = [
|
||||
"frame-system-rpc-runtime-api",
|
||||
"hex-literal",
|
||||
"node-primitives",
|
||||
"pallet-assets",
|
||||
"pallet-authority-discovery",
|
||||
"pallet-authorship",
|
||||
"pallet-babe",
|
||||
@@ -4228,8 +4229,10 @@ dependencies = [
|
||||
name = "pallet-assets"
|
||||
version = "2.0.0"
|
||||
dependencies = [
|
||||
"frame-benchmarking",
|
||||
"frame-support",
|
||||
"frame-system",
|
||||
"pallet-balances",
|
||||
"parity-scale-codec",
|
||||
"serde",
|
||||
"sp-core",
|
||||
|
||||
@@ -43,6 +43,7 @@ frame-support = { version = "2.0.0", default-features = false, path = "../../../
|
||||
frame-system = { version = "2.0.0", default-features = false, path = "../../../frame/system" }
|
||||
frame-system-benchmarking = { version = "2.0.0", default-features = false, path = "../../../frame/system/benchmarking", optional = true }
|
||||
frame-system-rpc-runtime-api = { version = "2.0.0", default-features = false, path = "../../../frame/system/rpc/runtime-api/" }
|
||||
pallet-assets = { version = "2.0.0", default-features = false, path = "../../../frame/assets" }
|
||||
pallet-authority-discovery = { version = "2.0.0", default-features = false, path = "../../../frame/authority-discovery" }
|
||||
pallet-authorship = { version = "2.0.0", default-features = false, path = "../../../frame/authorship" }
|
||||
pallet-babe = { version = "2.0.0", default-features = false, path = "../../../frame/babe" }
|
||||
@@ -89,6 +90,7 @@ default = ["std"]
|
||||
with-tracing = [ "frame-executive/with-tracing" ]
|
||||
std = [
|
||||
"sp-authority-discovery/std",
|
||||
"pallet-assets/std",
|
||||
"pallet-authority-discovery/std",
|
||||
"pallet-authorship/std",
|
||||
"sp-consensus-babe/std",
|
||||
@@ -147,6 +149,7 @@ runtime-benchmarks = [
|
||||
"frame-support/runtime-benchmarks",
|
||||
"frame-system/runtime-benchmarks",
|
||||
"sp-runtime/runtime-benchmarks",
|
||||
"pallet-assets/runtime-benchmarks",
|
||||
"pallet-babe/runtime-benchmarks",
|
||||
"pallet-balances/runtime-benchmarks",
|
||||
"pallet-collective/runtime-benchmarks",
|
||||
|
||||
@@ -892,6 +892,22 @@ impl pallet_vesting::Config for Runtime {
|
||||
type WeightInfo = pallet_vesting::weights::SubstrateWeight<Runtime>;
|
||||
}
|
||||
|
||||
parameter_types! {
|
||||
pub const AssetDepositBase: Balance = 100 * DOLLARS;
|
||||
pub const AssetDepositPerZombie: Balance = 1 * DOLLARS;
|
||||
}
|
||||
|
||||
impl pallet_assets::Config for Runtime {
|
||||
type Event = Event;
|
||||
type Balance = u64;
|
||||
type AssetId = u32;
|
||||
type Currency = Balances;
|
||||
type ForceOrigin = EnsureRoot<AccountId>;
|
||||
type AssetDepositBase = AssetDepositBase;
|
||||
type AssetDepositPerZombie = AssetDepositPerZombie;
|
||||
type WeightInfo = pallet_assets::weights::SubstrateWeight<Runtime>;
|
||||
}
|
||||
|
||||
construct_runtime!(
|
||||
pub enum Runtime where
|
||||
Block = Block,
|
||||
@@ -929,6 +945,7 @@ construct_runtime!(
|
||||
Scheduler: pallet_scheduler::{Module, Call, Storage, Event<T>},
|
||||
Proxy: pallet_proxy::{Module, Call, Storage, Event<T>},
|
||||
Multisig: pallet_multisig::{Module, Call, Storage, Event<T>},
|
||||
Assets: pallet_assets::{Module, Call, Storage, Event<T>},
|
||||
}
|
||||
);
|
||||
|
||||
@@ -1195,6 +1212,7 @@ impl_runtime_apis! {
|
||||
let mut batches = Vec::<BenchmarkBatch>::new();
|
||||
let params = (&config, &whitelist);
|
||||
|
||||
add_benchmark!(params, batches, pallet_assets, Assets);
|
||||
add_benchmark!(params, batches, pallet_babe, Babe);
|
||||
add_benchmark!(params, batches, pallet_balances, Balances);
|
||||
add_benchmark!(params, batches, pallet_collective, Council);
|
||||
|
||||
@@ -15,24 +15,34 @@ targets = ["x86_64-unknown-linux-gnu"]
|
||||
[dependencies]
|
||||
serde = { version = "1.0.101", optional = true }
|
||||
codec = { package = "parity-scale-codec", version = "1.3.4", default-features = false }
|
||||
sp-std = { version = "2.0.0", default-features = false, path = "../../primitives/std" }
|
||||
# Needed for various traits. In our case, `OnFinalize`.
|
||||
sp-runtime = { version = "2.0.0", default-features = false, path = "../../primitives/runtime" }
|
||||
# Needed for type-safe access to storage DB.
|
||||
frame-support = { version = "2.0.0", default-features = false, path = "../support" }
|
||||
# `system` module provides us with all sorts of useful stuff and macros depend on it being around.
|
||||
frame-system = { version = "2.0.0", default-features = false, path = "../system" }
|
||||
frame-benchmarking = { version = "2.0.0", default-features = false, path = "../benchmarking", optional = true }
|
||||
|
||||
[dev-dependencies]
|
||||
sp-core = { version = "2.0.0", path = "../../primitives/core" }
|
||||
sp-std = { version = "2.0.0", path = "../../primitives/std" }
|
||||
sp-io = { version = "2.0.0", path = "../../primitives/io" }
|
||||
pallet-balances = { version = "2.0.0", default-features = false, path = "../balances" }
|
||||
|
||||
[features]
|
||||
default = ["std"]
|
||||
std = [
|
||||
"serde",
|
||||
"codec/std",
|
||||
"sp-std/std",
|
||||
"sp-runtime/std",
|
||||
"frame-support/std",
|
||||
"frame-system/std",
|
||||
"frame-benchmarking/std",
|
||||
]
|
||||
runtime-benchmarks = [
|
||||
"frame-benchmarking",
|
||||
"sp-runtime/runtime-benchmarks",
|
||||
"frame-system/runtime-benchmarks",
|
||||
]
|
||||
|
||||
@@ -0,0 +1,298 @@
|
||||
// This file is part of Substrate.
|
||||
|
||||
// Copyright (C) 2020 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.
|
||||
|
||||
//! Assets pallet benchmarking.
|
||||
|
||||
use super::*;
|
||||
use sp_std::prelude::*;
|
||||
use sp_runtime::traits::Bounded;
|
||||
use frame_system::RawOrigin as SystemOrigin;
|
||||
use frame_benchmarking::{benchmarks, account, whitelisted_caller};
|
||||
|
||||
use crate::Module as Assets;
|
||||
|
||||
const SEED: u32 = 0;
|
||||
|
||||
fn create_default_asset<T: Config>(max_zombies: u32)
|
||||
-> (T::AccountId, <T::Lookup as StaticLookup>::Source)
|
||||
{
|
||||
let caller: T::AccountId = whitelisted_caller();
|
||||
let caller_lookup = T::Lookup::unlookup(caller.clone());
|
||||
let root = SystemOrigin::Root.into();
|
||||
assert!(Assets::<T>::force_create(
|
||||
root,
|
||||
Default::default(),
|
||||
caller_lookup.clone(),
|
||||
max_zombies,
|
||||
1u32.into(),
|
||||
).is_ok());
|
||||
(caller, caller_lookup)
|
||||
}
|
||||
|
||||
fn create_default_minted_asset<T: Config>(max_zombies: u32, amount: T::Balance)
|
||||
-> (T::AccountId, <T::Lookup as StaticLookup>::Source)
|
||||
{
|
||||
let (caller, caller_lookup) = create_default_asset::<T>(max_zombies);
|
||||
assert!(Assets::<T>::mint(
|
||||
SystemOrigin::Signed(caller.clone()).into(),
|
||||
Default::default(),
|
||||
caller_lookup.clone(),
|
||||
amount,
|
||||
).is_ok());
|
||||
(caller, caller_lookup)
|
||||
}
|
||||
|
||||
fn add_zombies<T: Config>(minter: T::AccountId, n: u32) {
|
||||
let origin = SystemOrigin::Signed(minter);
|
||||
for i in 0..n {
|
||||
let target = account("zombie", i, SEED);
|
||||
let target_lookup = T::Lookup::unlookup(target);
|
||||
assert!(Assets::<T>::mint(origin.clone().into(), Default::default(), target_lookup, 100u32.into()).is_ok());
|
||||
}
|
||||
}
|
||||
|
||||
fn assert_last_event<T: Config>(generic_event: <T as Config>::Event) {
|
||||
let events = frame_system::Module::<T>::events();
|
||||
let system_event: <T as frame_system::Config>::Event = generic_event.into();
|
||||
// compare to the last event record
|
||||
let frame_system::EventRecord { event, .. } = &events[events.len() - 1];
|
||||
assert_eq!(event, &system_event);
|
||||
}
|
||||
|
||||
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())
|
||||
verify {
|
||||
assert_last_event::<T>(RawEvent::Created(Default::default(), caller.clone(), caller).into());
|
||||
}
|
||||
|
||||
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())
|
||||
verify {
|
||||
assert_last_event::<T>(RawEvent::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>(RawEvent::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)
|
||||
verify {
|
||||
assert_last_event::<T>(RawEvent::Destroyed(Default::default()).into());
|
||||
}
|
||||
|
||||
mint {
|
||||
let (caller, caller_lookup) = create_default_asset::<T>(10);
|
||||
let amount = T::Balance::from(100u32);
|
||||
}: _(SystemOrigin::Signed(caller.clone()), Default::default(), caller_lookup, amount)
|
||||
verify {
|
||||
assert_last_event::<T>(RawEvent::Issued(Default::default(), caller, amount).into());
|
||||
}
|
||||
|
||||
burn {
|
||||
let amount = T::Balance::from(100u32);
|
||||
let (caller, caller_lookup) = create_default_minted_asset::<T>(10, amount);
|
||||
}: _(SystemOrigin::Signed(caller.clone()), Default::default(), caller_lookup, amount)
|
||||
verify {
|
||||
assert_last_event::<T>(RawEvent::Burned(Default::default(), caller, amount).into());
|
||||
}
|
||||
|
||||
transfer {
|
||||
let amount = T::Balance::from(100u32);
|
||||
let (caller, caller_lookup) = create_default_minted_asset::<T>(10, 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_last_event::<T>(RawEvent::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 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>(RawEvent::ForceTransferred(Default::default(), caller, target, amount).into());
|
||||
}
|
||||
|
||||
freeze {
|
||||
let (caller, caller_lookup) = create_default_minted_asset::<T>(10, 100u32.into());
|
||||
}: _(SystemOrigin::Signed(caller.clone()), Default::default(), caller_lookup)
|
||||
verify {
|
||||
assert_last_event::<T>(RawEvent::Frozen(Default::default(), caller).into());
|
||||
}
|
||||
|
||||
thaw {
|
||||
let (caller, caller_lookup) = create_default_minted_asset::<T>(10, 100u32.into());
|
||||
assert!(Assets::<T>::freeze(
|
||||
SystemOrigin::Signed(caller.clone()).into(),
|
||||
Default::default(),
|
||||
caller_lookup.clone()
|
||||
).is_ok());
|
||||
}: _(SystemOrigin::Signed(caller.clone()), Default::default(), caller_lookup)
|
||||
verify {
|
||||
assert_last_event::<T>(RawEvent::Thawed(Default::default(), caller).into());
|
||||
}
|
||||
|
||||
transfer_ownership {
|
||||
let (caller, _) = create_default_asset::<T>(10);
|
||||
let target: T::AccountId = account("target", 0, SEED);
|
||||
let target_lookup = T::Lookup::unlookup(target.clone());
|
||||
}: _(SystemOrigin::Signed(caller), Default::default(), target_lookup)
|
||||
verify {
|
||||
assert_last_event::<T>(RawEvent::OwnerChanged(Default::default(), target).into());
|
||||
}
|
||||
|
||||
set_team {
|
||||
let (caller, _) = create_default_asset::<T>(10);
|
||||
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), Default::default(), target0.clone(), target1.clone(), target2.clone())
|
||||
verify {
|
||||
assert_last_event::<T>(RawEvent::TeamChanged(
|
||||
Default::default(),
|
||||
account("target", 0, SEED),
|
||||
account("target", 1, SEED),
|
||||
account("target", 2, SEED),
|
||||
).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>(RawEvent::MaxZombiesChanged(Default::default(), max_zombies).into());
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::tests::{new_test_ext, Test};
|
||||
|
||||
#[test]
|
||||
fn create() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert!(test_benchmark_create::<Test>().is_ok());
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn force_create() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert!(test_benchmark_force_create::<Test>().is_ok());
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn destroy() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert!(test_benchmark_destroy::<Test>().is_ok());
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn force_destroy() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert!(test_benchmark_force_destroy::<Test>().is_ok());
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn mint() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert!(test_benchmark_mint::<Test>().is_ok());
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn burn() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert!(test_benchmark_burn::<Test>().is_ok());
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn transfer() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert!(test_benchmark_transfer::<Test>().is_ok());
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn force_transfer() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert!(test_benchmark_force_transfer::<Test>().is_ok());
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn freeze() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert!(test_benchmark_freeze::<Test>().is_ok());
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn thaw() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert!(test_benchmark_thaw::<Test>().is_ok());
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn transfer_ownership() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert!(test_benchmark_transfer_ownership::<Test>().is_ok());
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn set_team() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert!(test_benchmark_set_team::<Test>().is_ok());
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn set_max_zombies() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert!(test_benchmark_set_max_zombies::<Test>().is_ok());
|
||||
});
|
||||
}
|
||||
}
|
||||
+1071
-181
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,207 @@
|
||||
// This file is part of Substrate.
|
||||
|
||||
// Copyright (C) 2020 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.
|
||||
|
||||
//! Autogenerated weights for pallet_assets
|
||||
//!
|
||||
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 2.0.0
|
||||
//! DATE: 2020-12-03, STEPS: [50, ], REPEAT: 20, LOW RANGE: [], HIGH RANGE: []
|
||||
//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 128
|
||||
|
||||
// Executed Command:
|
||||
// target/release/substrate
|
||||
// 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
|
||||
|
||||
|
||||
#![allow(unused_parens)]
|
||||
#![allow(unused_imports)]
|
||||
|
||||
use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}};
|
||||
use sp_std::marker::PhantomData;
|
||||
|
||||
/// Weight functions needed for pallet_assets.
|
||||
pub trait WeightInfo {
|
||||
fn create() -> Weight;
|
||||
fn force_create() -> Weight;
|
||||
fn destroy(z: u32, ) -> Weight;
|
||||
fn force_destroy(z: u32, ) -> Weight;
|
||||
fn mint() -> Weight;
|
||||
fn burn() -> Weight;
|
||||
fn transfer() -> Weight;
|
||||
fn force_transfer() -> Weight;
|
||||
fn freeze() -> Weight;
|
||||
fn thaw() -> Weight;
|
||||
fn transfer_ownership() -> Weight;
|
||||
fn set_team() -> Weight;
|
||||
fn set_max_zombies() -> 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 {
|
||||
(58_077_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 {
|
||||
(30_497_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 {
|
||||
(0 as Weight)
|
||||
.saturating_add((1_153_000 as Weight).saturating_mul(z as Weight))
|
||||
.saturating_add(T::DbWeight::get().reads(1 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)
|
||||
.saturating_add((1_153_000 as Weight).saturating_mul(z as Weight))
|
||||
.saturating_add(T::DbWeight::get().reads(1 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 mint() -> Weight {
|
||||
(45_600_000 as Weight)
|
||||
.saturating_add(T::DbWeight::get().reads(2 as Weight))
|
||||
.saturating_add(T::DbWeight::get().writes(2 as Weight))
|
||||
}
|
||||
fn burn() -> Weight {
|
||||
(40_143_000 as Weight)
|
||||
.saturating_add(T::DbWeight::get().reads(2 as Weight))
|
||||
.saturating_add(T::DbWeight::get().writes(2 as Weight))
|
||||
}
|
||||
fn transfer() -> Weight {
|
||||
(58_903_000 as Weight)
|
||||
.saturating_add(T::DbWeight::get().reads(4 as Weight))
|
||||
.saturating_add(T::DbWeight::get().writes(3 as Weight))
|
||||
}
|
||||
fn force_transfer() -> Weight {
|
||||
(59_025_000 as Weight)
|
||||
.saturating_add(T::DbWeight::get().reads(4 as Weight))
|
||||
.saturating_add(T::DbWeight::get().writes(3 as Weight))
|
||||
}
|
||||
fn freeze() -> Weight {
|
||||
(43_308_000 as Weight)
|
||||
.saturating_add(T::DbWeight::get().reads(2 as Weight))
|
||||
.saturating_add(T::DbWeight::get().writes(1 as Weight))
|
||||
}
|
||||
fn thaw() -> Weight {
|
||||
(43_383_000 as Weight)
|
||||
.saturating_add(T::DbWeight::get().reads(2 as Weight))
|
||||
.saturating_add(T::DbWeight::get().writes(1 as Weight))
|
||||
}
|
||||
fn transfer_ownership() -> Weight {
|
||||
(31_380_000 as Weight)
|
||||
.saturating_add(T::DbWeight::get().reads(1 as Weight))
|
||||
.saturating_add(T::DbWeight::get().writes(1 as Weight))
|
||||
}
|
||||
fn set_team() -> Weight {
|
||||
(32_049_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 {
|
||||
(57_745_000 as Weight)
|
||||
.saturating_add(T::DbWeight::get().reads(1 as Weight))
|
||||
.saturating_add(T::DbWeight::get().writes(1 as Weight))
|
||||
}
|
||||
}
|
||||
|
||||
// For backwards compatibility and tests
|
||||
impl WeightInfo for () {
|
||||
fn create() -> Weight {
|
||||
(58_077_000 as Weight)
|
||||
.saturating_add(RocksDbWeight::get().reads(1 as Weight))
|
||||
.saturating_add(RocksDbWeight::get().writes(1 as Weight))
|
||||
}
|
||||
fn force_create() -> Weight {
|
||||
(30_497_000 as Weight)
|
||||
.saturating_add(RocksDbWeight::get().reads(1 as Weight))
|
||||
.saturating_add(RocksDbWeight::get().writes(1 as Weight))
|
||||
}
|
||||
fn destroy(z: u32, ) -> Weight {
|
||||
(0 as Weight)
|
||||
.saturating_add((1_153_000 as Weight).saturating_mul(z as Weight))
|
||||
.saturating_add(RocksDbWeight::get().reads(1 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)
|
||||
.saturating_add((1_153_000 as Weight).saturating_mul(z as Weight))
|
||||
.saturating_add(RocksDbWeight::get().reads(1 as Weight))
|
||||
.saturating_add(RocksDbWeight::get().writes(1 as Weight))
|
||||
.saturating_add(RocksDbWeight::get().writes((1 as Weight).saturating_mul(z as Weight)))
|
||||
}
|
||||
fn mint() -> Weight {
|
||||
(45_600_000 as Weight)
|
||||
.saturating_add(RocksDbWeight::get().reads(2 as Weight))
|
||||
.saturating_add(RocksDbWeight::get().writes(2 as Weight))
|
||||
}
|
||||
fn burn() -> Weight {
|
||||
(40_143_000 as Weight)
|
||||
.saturating_add(RocksDbWeight::get().reads(2 as Weight))
|
||||
.saturating_add(RocksDbWeight::get().writes(2 as Weight))
|
||||
}
|
||||
fn transfer() -> Weight {
|
||||
(58_903_000 as Weight)
|
||||
.saturating_add(RocksDbWeight::get().reads(4 as Weight))
|
||||
.saturating_add(RocksDbWeight::get().writes(3 as Weight))
|
||||
}
|
||||
fn force_transfer() -> Weight {
|
||||
(59_025_000 as Weight)
|
||||
.saturating_add(RocksDbWeight::get().reads(4 as Weight))
|
||||
.saturating_add(RocksDbWeight::get().writes(3 as Weight))
|
||||
}
|
||||
fn freeze() -> Weight {
|
||||
(43_308_000 as Weight)
|
||||
.saturating_add(RocksDbWeight::get().reads(2 as Weight))
|
||||
.saturating_add(RocksDbWeight::get().writes(1 as Weight))
|
||||
}
|
||||
fn thaw() -> Weight {
|
||||
(43_383_000 as Weight)
|
||||
.saturating_add(RocksDbWeight::get().reads(2 as Weight))
|
||||
.saturating_add(RocksDbWeight::get().writes(1 as Weight))
|
||||
}
|
||||
fn transfer_ownership() -> Weight {
|
||||
(31_380_000 as Weight)
|
||||
.saturating_add(RocksDbWeight::get().reads(1 as Weight))
|
||||
.saturating_add(RocksDbWeight::get().writes(1 as Weight))
|
||||
}
|
||||
fn set_team() -> Weight {
|
||||
(32_049_000 as Weight)
|
||||
.saturating_add(RocksDbWeight::get().reads(1 as Weight))
|
||||
.saturating_add(RocksDbWeight::get().writes(1 as Weight))
|
||||
}
|
||||
fn set_max_zombies() -> Weight {
|
||||
(57_745_000 as Weight)
|
||||
.saturating_add(RocksDbWeight::get().reads(1 as Weight))
|
||||
.saturating_add(RocksDbWeight::get().writes(1 as Weight))
|
||||
}
|
||||
}
|
||||
@@ -409,7 +409,7 @@ decl_storage! {
|
||||
for (_, balance) in &config.balances {
|
||||
assert!(
|
||||
*balance >= <T as Config<I>>::ExistentialDeposit::get(),
|
||||
"the balance of any account should always be more than existential deposit.",
|
||||
"the balance of any account should always be at least the existential deposit.",
|
||||
)
|
||||
}
|
||||
for &(ref who, free) in config.balances.iter() {
|
||||
|
||||
@@ -630,7 +630,7 @@ macro_rules! decl_tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic = "the balance of any account should always be more than existential deposit."]
|
||||
#[should_panic = "the balance of any account should always be at least the existential deposit."]
|
||||
fn cannot_set_genesis_value_below_ed() {
|
||||
($existential_deposit).with(|v| *v.borrow_mut() = 11);
|
||||
let mut t = frame_system::GenesisConfig::default().build_storage::<$test>().unwrap();
|
||||
|
||||
@@ -903,6 +903,10 @@ impl<T: Config> Module<T> {
|
||||
Self::deposit_event_indexed(&[], event.into());
|
||||
}
|
||||
|
||||
pub fn account_exists(who: &T::AccountId) -> bool {
|
||||
Account::<T>::contains_key(who)
|
||||
}
|
||||
|
||||
/// Increment the reference counter on an account.
|
||||
pub fn inc_ref(who: &T::AccountId) {
|
||||
Account::<T>::mutate(who, |a| a.refcount = a.refcount.saturating_add(1));
|
||||
|
||||
Reference in New Issue
Block a user