Freeze Assets and Asset Metadata (#7346)

* 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

* Add `freeze_asset` and `thaw_asset`

* Add metadata

* fix build

* Update benchmarks

* fix line width

* 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 default weights

* destroy cleans up metadata

* more comprehensive lifecycle test

* update docs

* 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

* fix compile

* fix up

* 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 to pallet compile

* fix node build

* remote diff artifacts

* less diff

* 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/assets/src/lib.rs

* Update frame/assets/src/lib.rs

* usize to u32

* missed some usize

* 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: Gav Wood <gavin@parity.io>
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: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
This commit is contained in:
Shawn Tabrizi
2021-01-19 07:14:32 -04:00
committed by GitHub
parent 8e04515912
commit 748bdf65d3
4 changed files with 416 additions and 41 deletions
+57 -4
View File
@@ -18,7 +18,6 @@
//! 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};
@@ -154,16 +153,34 @@ benchmarks! {
thaw {
let (caller, caller_lookup) = create_default_minted_asset::<T>(10, 100u32.into());
assert!(Assets::<T>::freeze(
Assets::<T>::freeze(
SystemOrigin::Signed(caller.clone()).into(),
Default::default(),
caller_lookup.clone()
).is_ok());
caller_lookup.clone(),
)?;
}: _(SystemOrigin::Signed(caller.clone()), Default::default(), caller_lookup)
verify {
assert_last_event::<T>(RawEvent::Thawed(Default::default(), caller).into());
}
freeze_asset {
let (caller, caller_lookup) = create_default_minted_asset::<T>(10, 100u32.into());
}: _(SystemOrigin::Signed(caller.clone()), Default::default())
verify {
assert_last_event::<T>(RawEvent::AssetFrozen(Default::default()).into());
}
thaw_asset {
let (caller, caller_lookup) = create_default_minted_asset::<T>(10, 100u32.into());
Assets::<T>::freeze_asset(
SystemOrigin::Signed(caller.clone()).into(),
Default::default(),
)?;
}: _(SystemOrigin::Signed(caller.clone()), Default::default())
verify {
assert_last_event::<T>(RawEvent::AssetThawed(Default::default()).into());
}
transfer_ownership {
let (caller, _) = create_default_asset::<T>(10);
let target: T::AccountId = account("target", 0, SEED);
@@ -196,6 +213,21 @@ benchmarks! {
verify {
assert_last_event::<T>(RawEvent::MaxZombiesChanged(Default::default(), max_zombies).into());
}
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;
let (caller, _) = create_default_asset::<T>(10);
T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value());
}: _(SystemOrigin::Signed(caller), Default::default(), name.clone(), symbol.clone(), decimals)
verify {
assert_last_event::<T>(RawEvent::MetadataSet(Default::default(), name, symbol, decimals).into());
}
}
#[cfg(test)]
@@ -273,6 +305,20 @@ mod tests {
});
}
#[test]
fn freeze_asset() {
new_test_ext().execute_with(|| {
assert!(test_benchmark_freeze_asset::<Test>().is_ok());
});
}
#[test]
fn thaw_asset() {
new_test_ext().execute_with(|| {
assert!(test_benchmark_thaw_asset::<Test>().is_ok());
});
}
#[test]
fn transfer_ownership() {
new_test_ext().execute_with(|| {
@@ -293,4 +339,11 @@ mod tests {
assert!(test_benchmark_set_max_zombies::<Test>().is_ok());
});
}
#[test]
fn set_metadata() {
new_test_ext().execute_with(|| {
assert!(test_benchmark_set_metadata::<Test>().is_ok());
});
}
}