diff --git a/Cargo.lock b/Cargo.lock index 89220a1218..8a2f96f632 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6339,6 +6339,7 @@ name = "module-asset-registry" version = "2.25.0" dependencies = [ "acala-primitives", + "frame-benchmarking", "frame-support", "frame-system", "hex", @@ -6356,6 +6357,7 @@ dependencies = [ "sp-runtime", "sp-std", "staging-xcm", + "staging-xcm-builder", ] [[package]] diff --git a/modules/asset-registry/Cargo.toml b/modules/asset-registry/Cargo.toml index 748b5c848f..cb54e91624 100644 --- a/modules/asset-registry/Cargo.toml +++ b/modules/asset-registry/Cargo.toml @@ -17,21 +17,28 @@ primitives = { workspace = true } xcm = { workspace = true } module-support = { workspace = true } +module-evm = { workspace = true } +serde_json = { workspace = true } +hex = { workspace = true } + + +# Benchmarks +frame-benchmarking = { workspace = true, optional = true } [dev-dependencies] -serde_json = { workspace = true, features = ["std"] } -hex = { workspace = true, features = ["std"] } sp-core = { workspace = true, features = ["std"] } sp-io = { workspace = true, features = ["std"] } pallet-balances = { workspace = true, features = ["std"] } pallet-timestamp = { workspace = true, features = ["std"] } +xcm-builder = { workspace = true, features = ["std"] } -module-evm = { workspace = true, features = ["std"] } module-evm-bridge = { workspace = true, features = ["std"] } [features] default = ["std"] std = [ + "hex/std", + "serde_json/std", "log/std", "parity-scale-codec/std", "scale-info/std", @@ -41,8 +48,15 @@ std = [ "frame-system/std", "primitives/std", "xcm/std", + "module-evm/std", "module-support/std", ] +runtime-benchmarks = [ + "frame-benchmarking/runtime-benchmarks", + "frame-support/runtime-benchmarks", + "frame-system/runtime-benchmarks", + "xcm-builder/runtime-benchmarks", +] try-runtime = [ "frame-support/try-runtime", "frame-system/try-runtime", diff --git a/modules/asset-registry/src/benchmarks.rs b/modules/asset-registry/src/benchmarks.rs new file mode 100644 index 0000000000..f409b044fc --- /dev/null +++ b/modules/asset-registry/src/benchmarks.rs @@ -0,0 +1,201 @@ +// This file is part of Acala. + +// Copyright (C) 2020-2024 Acala Foundation. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +#![cfg(feature = "runtime-benchmarks")] + +use crate::{ + AssetIds, AssetMetadata, BalanceOf, Call, Config, CurrencyId, EvmAddress, Location, Pallet, Parachain, + VersionedLocation, +}; +use frame_benchmarking::{benchmarks, impl_benchmark_test_suite, BenchmarkError}; +use frame_support::{assert_ok, traits::Currency}; +use frame_system::RawOrigin; +use module_support::AddressMapping; +use sp_runtime::traits::One; +use sp_std::{boxed::Box, str::FromStr, vec}; + +pub fn alice() -> T::AccountId { + ::AddressMapping::get_account_id(&alice_evm_addr()) +} +pub fn alice_evm_addr() -> EvmAddress { + EvmAddress::from_str("1000000000000000000000000000000000000001").unwrap() +} + +pub fn erc20_address() -> EvmAddress { + EvmAddress::from_str("0x5dddfce53ee040d9eb21afbc0ae1bb4dbb0ba643").unwrap() +} + +pub fn dollar(amount: u32) -> BalanceOf { + BalanceOf::::one() * 1_000_000u32.into() * 1_000_000u32.into() * amount.into() +} + +pub fn deploy_contract() { + ::Currency::make_free_balance_be(&alice::(), dollar::(1000)); + + let json: serde_json::Value = + serde_json::from_str(include_str!("../../../ts-tests/build/Erc20DemoContract2.json")).unwrap(); + let code = hex::decode(json.get("bytecode").unwrap().as_str().unwrap()).unwrap(); + + assert_ok!(module_evm::Pallet::::create( + RawOrigin::Signed(alice::()).into(), + code, + 0, + 2_100_000, + 1_000_000, + vec![] + )); +} + +benchmarks! { + where_clause { where T: Config + module_evm::Config } + register_foreign_asset { + let location = VersionedLocation::V4(Location::new( + 0, + [Parachain(1000)], + )); + let asset_metadata = AssetMetadata { + name: b"Token Name".to_vec(), + symbol: b"TN".to_vec(), + decimals: 12, + minimal_balance: BalanceOf::::one(), + }; + let v3_location = xcm::v3::Location::try_from(location.clone()).map_err(|()| BenchmarkError::Weightless)?; + let foreign_asset_id = 0; + }: _(RawOrigin::Root, Box::new(location), Box::new(asset_metadata.clone())) + verify { + assert_eq!(Pallet::::location_to_currency_ids(v3_location), Some(CurrencyId::ForeignAsset(foreign_asset_id))); + assert_eq!(Pallet::::foreign_asset_locations(foreign_asset_id), Some(v3_location)); + assert_eq!(Pallet::::asset_metadatas(AssetIds::ForeignAssetId(foreign_asset_id)), Some(asset_metadata)); + } + + update_foreign_asset { + let location = VersionedLocation::V4(Location::new( + 0, + [Parachain(1000)], + )); + let asset_metadata = AssetMetadata { + name: b"Token Name".to_vec(), + symbol: b"TN".to_vec(), + decimals: 12, + minimal_balance: BalanceOf::::one(), + }; + let v3_location = xcm::v3::Location::try_from(location.clone()).map_err(|()| BenchmarkError::Weightless)?; + let foreign_asset_id = 0; + + Pallet::::register_foreign_asset(RawOrigin::Root.into(), Box::new(location.clone()), Box::new(asset_metadata.clone()))?; + }: _(RawOrigin::Root, 0, Box::new(location), Box::new(asset_metadata.clone())) + verify { + assert_eq!(Pallet::::location_to_currency_ids(v3_location), Some(CurrencyId::ForeignAsset(foreign_asset_id))); + assert_eq!(Pallet::::foreign_asset_locations(foreign_asset_id), Some(v3_location)); + assert_eq!(Pallet::::asset_metadatas(AssetIds::ForeignAssetId(foreign_asset_id)), Some(asset_metadata)); + } + + register_stable_asset { + let asset_metadata = AssetMetadata { + name: b"Token Name".to_vec(), + symbol: b"TN".to_vec(), + decimals: 12, + minimal_balance: BalanceOf::::one(), + }; + let stable_asset_id = 0; + }: _(RawOrigin::Root, Box::new(asset_metadata.clone())) + verify { + assert_eq!(Pallet::::asset_metadatas(AssetIds::StableAssetId(stable_asset_id)), Some(asset_metadata)); + } + + update_stable_asset { + let asset_metadata = AssetMetadata { + name: b"Token Name".to_vec(), + symbol: b"TN".to_vec(), + decimals: 12, + minimal_balance: BalanceOf::::one(), + }; + let stable_asset_id = 0; + + Pallet::::register_stable_asset(RawOrigin::Root.into(), Box::new(asset_metadata.clone()))?; + }: _(RawOrigin::Root, 0, Box::new(asset_metadata.clone())) + verify { + assert_eq!(Pallet::::asset_metadatas(AssetIds::StableAssetId(stable_asset_id)), Some(asset_metadata)); + } + + register_erc20_asset { + deploy_contract::(); + }: _(RawOrigin::Root, erc20_address(), BalanceOf::::one()) + verify { + assert!(Pallet::::asset_metadatas(AssetIds::Erc20(erc20_address())).is_some()); + } + + update_erc20_asset { + let asset_metadata = AssetMetadata { + name: b"Token Name".to_vec(), + symbol: b"TN".to_vec(), + decimals: 12, + minimal_balance: BalanceOf::::one(), + }; + + deploy_contract::(); + Pallet::::register_erc20_asset(RawOrigin::Root.into(), erc20_address(), BalanceOf::::one())?; + }: _(RawOrigin::Root, erc20_address(), Box::new(asset_metadata.clone())) + verify { + assert_eq!(Pallet::::asset_metadatas(AssetIds::Erc20(erc20_address())), Some(asset_metadata)); + } + + register_native_asset { + let currency_id = CurrencyId::LiquidCrowdloan(0); + let asset_metadata = AssetMetadata { + name: b"Token Name".to_vec(), + symbol: b"TN".to_vec(), + decimals: 12, + minimal_balance: BalanceOf::::one(), + }; + }: _(RawOrigin::Root, currency_id, Box::new(asset_metadata.clone())) + verify { + assert_eq!(Pallet::::asset_metadatas(AssetIds::NativeAssetId(currency_id)), Some(asset_metadata)); + } + + update_native_asset { + let currency_id = CurrencyId::LiquidCrowdloan(0); + let asset_metadata = AssetMetadata { + name: b"Token Name".to_vec(), + symbol: b"TN".to_vec(), + decimals: 12, + minimal_balance: BalanceOf::::one(), + }; + + Pallet::::register_native_asset(RawOrigin::Root.into(), currency_id, Box::new(asset_metadata.clone()))?; + }: _(RawOrigin::Root, currency_id, Box::new(asset_metadata.clone())) + verify { + assert_eq!(Pallet::::asset_metadatas(AssetIds::NativeAssetId(currency_id)), Some(asset_metadata)); + } +} + +#[cfg(test)] +mod tests { + use crate::mock::Runtime; + use sp_io::TestExternalities; + use sp_runtime::BuildStorage; + + pub fn new_test_ext() -> TestExternalities { + let t = frame_system::GenesisConfig::::default() + .build_storage() + .unwrap(); + TestExternalities::new(t) + } +} + +impl_benchmark_test_suite!(Pallet, crate::benchmarks::tests::new_test_ext(), crate::mock::Runtime); diff --git a/modules/asset-registry/src/lib.rs b/modules/asset-registry/src/lib.rs index d644aff00b..92de811230 100644 --- a/modules/asset-registry/src/lib.rs +++ b/modules/asset-registry/src/lib.rs @@ -49,6 +49,8 @@ use sp_std::{boxed::Box, vec::Vec}; use xcm::{v3, v4::prelude::*, VersionedLocation}; +#[cfg(feature = "runtime-benchmarks")] +mod benchmarks; mod mock; mod tests; mod weights; diff --git a/modules/asset-registry/src/mock.rs b/modules/asset-registry/src/mock.rs index 06e89eb909..813f7b62d7 100644 --- a/modules/asset-registry/src/mock.rs +++ b/modules/asset-registry/src/mock.rs @@ -25,7 +25,7 @@ use frame_support::{ assert_ok, construct_runtime, derive_impl, ord_parameter_types, parameter_types, traits::{ConstU128, ConstU32, ConstU64}, }; -use frame_system::EnsureSignedBy; +use frame_system::{EnsureRoot, EnsureSignedBy}; use module_support::{ mocks::{MockAddressMapping, TestRandomness}, AddressMapping, @@ -73,7 +73,6 @@ parameter_types! { } ord_parameter_types! { - pub const CouncilAccount: AccountId = AccountId::from([1u8; 32]); pub const TreasuryAccount: AccountId = AccountId::from([2u8; 32]); pub const NetworkContractAccount: AccountId = AccountId::from([0u8; 32]); pub const StorageDepositPerByte: u128 = convert_decimals_to_evm(10); @@ -97,7 +96,7 @@ impl module_evm::Config for Runtime { type DeveloperDeposit = ConstU128<1000>; type PublicationFee = ConstU128<200>; type TreasuryAccount = TreasuryAccount; - type FreePublicationOrigin = EnsureSignedBy; + type FreePublicationOrigin = EnsureRoot; type Runner = module_evm::runner::stack::Runner; type FindAuthor = (); @@ -119,7 +118,7 @@ impl asset_registry::Config for Runtime { type Currency = Balances; type StakingCurrencyId = KSMCurrencyId; type EVMBridge = module_evm_bridge::EVMBridge; - type RegisterOrigin = EnsureSignedBy; + type RegisterOrigin = EnsureRoot; type WeightInfo = (); } diff --git a/modules/asset-registry/src/tests.rs b/modules/asset-registry/src/tests.rs index e3d150a356..ce035fca97 100644 --- a/modules/asset-registry/src/tests.rs +++ b/modules/asset-registry/src/tests.rs @@ -22,9 +22,10 @@ use super::*; use frame_support::{assert_noop, assert_ok}; +use frame_system::RawOrigin; use mock::{ alice, deploy_contracts, deploy_contracts_same_prefix, erc20_address, erc20_address_not_exists, - erc20_address_same_prefix, AssetRegistry, CouncilAccount, ExtBuilder, Runtime, RuntimeEvent, RuntimeOrigin, System, + erc20_address_same_prefix, AssetRegistry, ExtBuilder, Runtime, RuntimeEvent, System, }; use primitives::TokenSymbol; use sp_core::H160; @@ -121,7 +122,7 @@ fn register_foreign_asset_work() { }); assert_ok!(AssetRegistry::register_foreign_asset( - RuntimeOrigin::signed(CouncilAccount::get()), + RawOrigin::Root.into(), Box::new(v2_versioned_location.clone()), Box::new(AssetMetadata { name: b"Token Name".to_vec(), @@ -169,7 +170,7 @@ fn register_foreign_asset_work() { }); assert_ok!(AssetRegistry::register_foreign_asset( - RuntimeOrigin::signed(CouncilAccount::get()), + RawOrigin::Root.into(), Box::new(v3_versioned_location.clone()), Box::new(AssetMetadata { name: b"Another Token Name".to_vec(), @@ -217,7 +218,7 @@ fn register_foreign_asset_work() { )); assert_ok!(AssetRegistry::register_foreign_asset( - RuntimeOrigin::signed(CouncilAccount::get()), + RawOrigin::Root.into(), Box::new(v4_versioned_location.clone()), Box::new(AssetMetadata { name: b"Another Token Name2".to_vec(), @@ -263,7 +264,7 @@ fn register_foreign_asset_should_not_work() { let v4_location = VersionedLocation::V4(Location::new(0, [Parachain(1000)])); assert_ok!(AssetRegistry::register_foreign_asset( - RuntimeOrigin::signed(CouncilAccount::get()), + RawOrigin::Root.into(), Box::new(v4_location.clone()), Box::new(AssetMetadata { name: b"Token Name".to_vec(), @@ -275,7 +276,7 @@ fn register_foreign_asset_should_not_work() { assert_noop!( AssetRegistry::register_foreign_asset( - RuntimeOrigin::signed(CouncilAccount::get()), + RawOrigin::Root.into(), Box::new(v4_location.clone()), Box::new(AssetMetadata { name: b"Token Name".to_vec(), @@ -290,7 +291,7 @@ fn register_foreign_asset_should_not_work() { NextForeignAssetId::::set(u16::MAX); assert_noop!( AssetRegistry::register_foreign_asset( - RuntimeOrigin::signed(CouncilAccount::get()), + RawOrigin::Root.into(), Box::new(v4_location), Box::new(AssetMetadata { name: b"Token Name".to_vec(), @@ -310,7 +311,7 @@ fn update_foreign_asset_work() { let v4_versioned_location = VersionedLocation::V4(Location::new(0, [Parachain(1000)])); assert_ok!(AssetRegistry::register_foreign_asset( - RuntimeOrigin::signed(CouncilAccount::get()), + RawOrigin::Root.into(), Box::new(v4_versioned_location.clone()), Box::new(AssetMetadata { name: b"Token Name".to_vec(), @@ -321,7 +322,7 @@ fn update_foreign_asset_work() { )); assert_ok!(AssetRegistry::update_foreign_asset( - RuntimeOrigin::signed(CouncilAccount::get()), + RawOrigin::Root.into(), 0, Box::new(v4_versioned_location.clone()), Box::new(AssetMetadata { @@ -364,7 +365,7 @@ fn update_foreign_asset_work() { let new_v4_versioned_location = VersionedLocation::V4(Location::new(0, [Parachain(2000)])); assert_ok!(AssetRegistry::update_foreign_asset( - RuntimeOrigin::signed(CouncilAccount::get()), + RawOrigin::Root.into(), 0, Box::new(new_v4_versioned_location.clone()), Box::new(AssetMetadata { @@ -400,7 +401,7 @@ fn update_foreign_asset_should_not_work() { assert_noop!( AssetRegistry::update_foreign_asset( - RuntimeOrigin::signed(CouncilAccount::get()), + RawOrigin::Root.into(), 0, Box::new(v4_location.clone()), Box::new(AssetMetadata { @@ -414,7 +415,7 @@ fn update_foreign_asset_should_not_work() { ); assert_ok!(AssetRegistry::register_foreign_asset( - RuntimeOrigin::signed(CouncilAccount::get()), + RawOrigin::Root.into(), Box::new(v4_location.clone()), Box::new(AssetMetadata { name: b"Token Name".to_vec(), @@ -425,7 +426,7 @@ fn update_foreign_asset_should_not_work() { )); assert_ok!(AssetRegistry::update_foreign_asset( - RuntimeOrigin::signed(CouncilAccount::get()), + RawOrigin::Root.into(), 0, Box::new(v4_location), Box::new(AssetMetadata { @@ -439,7 +440,7 @@ fn update_foreign_asset_should_not_work() { // existed location let new_v4_location = VersionedLocation::V4(Location::new(0, [Parachain(2000)])); assert_ok!(AssetRegistry::register_foreign_asset( - RuntimeOrigin::signed(CouncilAccount::get()), + RawOrigin::Root.into(), Box::new(new_v4_location.clone()), Box::new(AssetMetadata { name: b"Token Name".to_vec(), @@ -450,7 +451,7 @@ fn update_foreign_asset_should_not_work() { )); assert_noop!( AssetRegistry::update_foreign_asset( - RuntimeOrigin::signed(CouncilAccount::get()), + RawOrigin::Root.into(), 0, Box::new(new_v4_location), Box::new(AssetMetadata { @@ -469,7 +470,7 @@ fn update_foreign_asset_should_not_work() { fn register_stable_asset_work() { ExtBuilder::default().build().execute_with(|| { assert_ok!(AssetRegistry::register_stable_asset( - RuntimeOrigin::signed(CouncilAccount::get()), + RawOrigin::Root.into(), Box::new(AssetMetadata { name: b"Token Name".to_vec(), symbol: b"TN".to_vec(), @@ -504,7 +505,7 @@ fn register_stable_asset_work() { fn register_stable_asset_should_not_work() { ExtBuilder::default().build().execute_with(|| { assert_ok!(AssetRegistry::register_stable_asset( - RuntimeOrigin::signed(CouncilAccount::get()), + RawOrigin::Root.into(), Box::new(AssetMetadata { name: b"Token Name".to_vec(), symbol: b"TN".to_vec(), @@ -516,7 +517,7 @@ fn register_stable_asset_should_not_work() { NextStableAssetId::::set(0); assert_noop!( AssetRegistry::register_stable_asset( - RuntimeOrigin::signed(CouncilAccount::get()), + RawOrigin::Root.into(), Box::new(AssetMetadata { name: b"Token Name".to_vec(), symbol: b"TN".to_vec(), @@ -530,7 +531,7 @@ fn register_stable_asset_should_not_work() { NextStableAssetId::::set(u32::MAX); assert_noop!( AssetRegistry::register_stable_asset( - RuntimeOrigin::signed(CouncilAccount::get()), + RawOrigin::Root.into(), Box::new(AssetMetadata { name: b"Token Name".to_vec(), symbol: b"TN".to_vec(), @@ -547,7 +548,7 @@ fn register_stable_asset_should_not_work() { fn update_stable_asset_work() { ExtBuilder::default().build().execute_with(|| { assert_ok!(AssetRegistry::register_stable_asset( - RuntimeOrigin::signed(CouncilAccount::get()), + RawOrigin::Root.into(), Box::new(AssetMetadata { name: b"Token Name".to_vec(), symbol: b"TN".to_vec(), @@ -557,7 +558,7 @@ fn update_stable_asset_work() { )); assert_ok!(AssetRegistry::update_stable_asset( - RuntimeOrigin::signed(CouncilAccount::get()), + RawOrigin::Root.into(), 0, Box::new(AssetMetadata { name: b"New Token Name".to_vec(), @@ -594,7 +595,7 @@ fn update_stable_asset_should_not_work() { ExtBuilder::default().build().execute_with(|| { assert_noop!( AssetRegistry::update_stable_asset( - RuntimeOrigin::signed(CouncilAccount::get()), + RawOrigin::Root.into(), 0, Box::new(AssetMetadata { name: b"New Token Name".to_vec(), @@ -616,7 +617,7 @@ fn register_erc20_asset_work() { .execute_with(|| { deploy_contracts(); assert_ok!(AssetRegistry::register_erc20_asset( - RuntimeOrigin::signed(CouncilAccount::get()), + RawOrigin::Root.into(), erc20_address(), 1 )); @@ -656,26 +657,18 @@ fn register_erc20_asset_should_not_work() { deploy_contracts(); deploy_contracts_same_prefix(); assert_ok!(AssetRegistry::register_erc20_asset( - RuntimeOrigin::signed(CouncilAccount::get()), + RawOrigin::Root.into(), erc20_address(), 1 )); assert_noop!( - AssetRegistry::register_erc20_asset( - RuntimeOrigin::signed(CouncilAccount::get()), - erc20_address_same_prefix(), - 1 - ), + AssetRegistry::register_erc20_asset(RawOrigin::Root.into(), erc20_address_same_prefix(), 1), Error::::AssetIdExisted ); assert_noop!( - AssetRegistry::register_erc20_asset( - RuntimeOrigin::signed(CouncilAccount::get()), - erc20_address_not_exists(), - 1 - ), + AssetRegistry::register_erc20_asset(RawOrigin::Root.into(), erc20_address_not_exists(), 1), module_evm_bridge::Error::::InvalidReturnValue, ); }); @@ -689,13 +682,13 @@ fn update_erc20_asset_work() { .execute_with(|| { deploy_contracts(); assert_ok!(AssetRegistry::register_erc20_asset( - RuntimeOrigin::signed(CouncilAccount::get()), + RawOrigin::Root.into(), erc20_address(), 1 )); assert_ok!(AssetRegistry::update_erc20_asset( - RuntimeOrigin::signed(CouncilAccount::get()), + RawOrigin::Root.into(), erc20_address(), Box::new(AssetMetadata { name: b"New Token Name".to_vec(), @@ -731,7 +724,7 @@ fn update_erc20_asset_work() { fn register_native_asset_works() { ExtBuilder::default().build().execute_with(|| { assert_ok!(AssetRegistry::register_native_asset( - RuntimeOrigin::signed(CouncilAccount::get()), + RawOrigin::Root.into(), CurrencyId::Token(TokenSymbol::DOT), Box::new(AssetMetadata { name: b"Token Name".to_vec(), @@ -762,7 +755,7 @@ fn register_native_asset_works() { // Can't duplicate assert_noop!( AssetRegistry::register_native_asset( - RuntimeOrigin::signed(CouncilAccount::get()), + RawOrigin::Root.into(), CurrencyId::Token(TokenSymbol::DOT), Box::new(AssetMetadata { name: b"Token Name".to_vec(), @@ -781,7 +774,7 @@ fn update_native_asset_works() { ExtBuilder::default().build().execute_with(|| { assert_noop!( AssetRegistry::update_native_asset( - RuntimeOrigin::signed(CouncilAccount::get()), + RawOrigin::Root.into(), CurrencyId::Token(TokenSymbol::DOT), Box::new(AssetMetadata { name: b"New Token Name".to_vec(), @@ -794,7 +787,7 @@ fn update_native_asset_works() { ); assert_ok!(AssetRegistry::register_native_asset( - RuntimeOrigin::signed(CouncilAccount::get()), + RawOrigin::Root.into(), CurrencyId::Token(TokenSymbol::DOT), Box::new(AssetMetadata { name: b"Token Name".to_vec(), @@ -805,7 +798,7 @@ fn update_native_asset_works() { )); assert_ok!(AssetRegistry::update_native_asset( - RuntimeOrigin::signed(CouncilAccount::get()), + RawOrigin::Root.into(), CurrencyId::Token(TokenSymbol::DOT), Box::new(AssetMetadata { name: b"New Token Name".to_vec(), @@ -842,7 +835,7 @@ fn update_erc20_asset_should_not_work() { ExtBuilder::default().build().execute_with(|| { assert_noop!( AssetRegistry::update_stable_asset( - RuntimeOrigin::signed(CouncilAccount::get()), + RawOrigin::Root.into(), 0, Box::new(AssetMetadata { name: b"New Token Name".to_vec(), @@ -864,7 +857,7 @@ fn name_works() { .execute_with(|| { deploy_contracts(); assert_ok!(AssetRegistry::register_erc20_asset( - RuntimeOrigin::signed(CouncilAccount::get()), + RawOrigin::Root.into(), erc20_address(), 1 )); @@ -922,7 +915,7 @@ fn symbol_works() { .execute_with(|| { deploy_contracts(); assert_ok!(AssetRegistry::register_erc20_asset( - RuntimeOrigin::signed(CouncilAccount::get()), + RawOrigin::Root.into(), erc20_address(), 1 )); @@ -995,7 +988,7 @@ fn decimals_works() { .execute_with(|| { deploy_contracts(); assert_ok!(AssetRegistry::register_erc20_asset( - RuntimeOrigin::signed(CouncilAccount::get()), + RawOrigin::Root.into(), erc20_address(), 1 )); @@ -1060,7 +1053,7 @@ fn encode_evm_address_works() { .execute_with(|| { deploy_contracts(); assert_ok!(AssetRegistry::register_erc20_asset( - RuntimeOrigin::signed(CouncilAccount::get()), + RawOrigin::Root.into(), erc20_address(), 1 )); @@ -1174,7 +1167,7 @@ fn decode_evm_address_works() { .execute_with(|| { deploy_contracts(); assert_ok!(AssetRegistry::register_erc20_asset( - RuntimeOrigin::signed(CouncilAccount::get()), + RawOrigin::Root.into(), erc20_address(), 1 )); diff --git a/runtime/mandala/Cargo.toml b/runtime/mandala/Cargo.toml index 2034b973e7..50bd71a394 100644 --- a/runtime/mandala/Cargo.toml +++ b/runtime/mandala/Cargo.toml @@ -330,6 +330,7 @@ runtime-benchmarks = [ "orml-vesting/runtime-benchmarks", "orml-xtokens/runtime-benchmarks", + "module-asset-registry/runtime-benchmarks", "module-collator-selection/runtime-benchmarks", "module-evm-accounts/runtime-benchmarks", "module-evm-bridge/runtime-benchmarks", diff --git a/runtime/mandala/src/lib.rs b/runtime/mandala/src/lib.rs index ef30dd6d41..31c8ea983e 100644 --- a/runtime/mandala/src/lib.rs +++ b/runtime/mandala/src/lib.rs @@ -2181,42 +2181,43 @@ extern crate orml_benchmarking; #[cfg(feature = "runtime-benchmarks")] mod benches { - define_benchmarks!( - [module_dex, benchmarking::dex] - [module_dex_oracle, benchmarking::dex_oracle] - [module_asset_registry, benchmarking::asset_registry] - [module_auction_manager, benchmarking::auction_manager] - [module_cdp_engine, benchmarking::cdp_engine] - [module_earning, benchmarking::earning] - [module_emergency_shutdown, benchmarking::emergency_shutdown] - [module_evm, benchmarking::evm] - [module_homa, benchmarking::homa] - [module_homa_validator_list, benchmarking::homa_validator_list] - [module_honzon, benchmarking::honzon] - [module_cdp_treasury, benchmarking::cdp_treasury] - [module_collator_selection, benchmarking::collator_selection] - [module_nominees_election, benchmarking::nominees_election] - [module_transaction_pause, benchmarking::transaction_pause] - [module_transaction_payment, benchmarking::transaction_payment] - [module_incentives, benchmarking::incentives] - [module_prices, benchmarking::prices] - [module_evm_accounts, benchmarking::evm_accounts] - [module_currencies, benchmarking::currencies] - [module_session_manager, benchmarking::session_manager] - [module_liquid_crowdloan, benchmarking::liquid_crowdloan] - [orml_tokens, benchmarking::tokens] - [orml_vesting, benchmarking::vesting] - [orml_auction, benchmarking::auction] - [orml_authority, benchmarking::authority] - [orml_oracle, benchmarking::oracle] - [nutsfinance_stable_asset, benchmarking::nutsfinance_stable_asset] - [module_idle_scheduler, benchmarking::idle_scheduler] - [module_aggregated_dex, benchmarking::aggregated_dex] - ); - // frame_benchmarking::define_benchmarks!( - // // XCM - // [pallet_xcm, PalletXcmExtrinsicsBenchmark::] + // define_benchmarks!( + // [module_dex, benchmarking::dex] + // [module_dex_oracle, benchmarking::dex_oracle] + // [module_asset_registry, benchmarking::asset_registry] + // [module_auction_manager, benchmarking::auction_manager] + // [module_cdp_engine, benchmarking::cdp_engine] + // [module_earning, benchmarking::earning] + // [module_emergency_shutdown, benchmarking::emergency_shutdown] + // [module_evm, benchmarking::evm] + // [module_homa, benchmarking::homa] + // [module_homa_validator_list, benchmarking::homa_validator_list] + // [module_honzon, benchmarking::honzon] + // [module_cdp_treasury, benchmarking::cdp_treasury] + // [module_collator_selection, benchmarking::collator_selection] + // [module_nominees_election, benchmarking::nominees_election] + // [module_transaction_pause, benchmarking::transaction_pause] + // [module_transaction_payment, benchmarking::transaction_payment] + // [module_incentives, benchmarking::incentives] + // [module_prices, benchmarking::prices] + // [module_evm_accounts, benchmarking::evm_accounts] + // [module_currencies, benchmarking::currencies] + // [module_session_manager, benchmarking::session_manager] + // [module_liquid_crowdloan, benchmarking::liquid_crowdloan] + // [orml_tokens, benchmarking::tokens] + // [orml_vesting, benchmarking::vesting] + // [orml_auction, benchmarking::auction] + // [orml_authority, benchmarking::authority] + // [orml_oracle, benchmarking::oracle] + // [nutsfinance_stable_asset, benchmarking::nutsfinance_stable_asset] + // [module_idle_scheduler, benchmarking::idle_scheduler] + // [module_aggregated_dex, benchmarking::aggregated_dex] // ); + frame_benchmarking::define_benchmarks!( + [module_asset_registry, AssetRegistry] + // XCM + [pallet_xcm, PalletXcmExtrinsicsBenchmark::] + ); } #[cfg(not(feature = "disable-runtime-api"))] @@ -2552,11 +2553,11 @@ impl_runtime_apis! { use frame_support::traits::StorageInfoTrait; use module_nft::benchmarking::Pallet as NftBench; - // use pallet_xcm::benchmarking::Pallet as PalletXcmExtrinsicsBenchmark; + use pallet_xcm::benchmarking::Pallet as PalletXcmExtrinsicsBenchmark; let mut list = Vec::::new(); - frame_list_benchmark!(list, extra, module_nft, NftBench::); + // frame_list_benchmark!(list, extra, module_nft, NftBench::); list_benchmarks!(list, extra); let storage_info = AllPalletsWithSystem::storage_info(); @@ -2571,82 +2572,82 @@ impl_runtime_apis! { use module_nft::benchmarking::Pallet as NftBench; use frame_support::traits::{WhitelistedStorageKeys, TrackedStorageKey}; - // const UNITS: Balance = 1_000_000_000_000; - // const CENTS: Balance = UNITS / 100; - - // parameter_types! { - // pub FeeAssetId: AssetId = AssetId(Location::parent()); - // pub const BaseDeliveryFee: u128 = CENTS.saturating_mul(3); - // } - // pub type PriceForParentDelivery = polkadot_runtime_common::xcm_sender::ExponentialPrice< - // FeeAssetId, - // BaseDeliveryFee, - // TransactionByteFee, - // ParachainSystem, - // >; - - // use pallet_xcm::benchmarking::Pallet as PalletXcmExtrinsicsBenchmark; - // impl pallet_xcm::benchmarking::Config for Runtime { - // type DeliveryHelper = cumulus_primitives_utility::ToParentDeliveryHelper< - // xcm_config::XcmConfig, - // ExistentialDepositAsset, - // PriceForParentDelivery, - // >; - // fn reachable_dest() -> Option { - // Some(Parent.into()) - // } - - // fn teleportable_asset_and_dest() -> Option<(Asset, Location)> { - // Some(( - // Asset { - // fun: Fungible(NativeTokenExistentialDeposit::get()), - // id: AssetId(Parent.into()) - // }, - // Parent.into(), - // )) - // } - - // fn reserve_transferable_asset_and_dest() -> Option<(Asset, Location)> { - // None - // } - - // fn get_asset() -> Asset { - // Asset { - // id: AssetId(Location::parent()), - // fun: Fungible(UNITS), - // } - // } - // } - - // parameter_types! { - // pub ExistentialDepositAsset: Option = Some(( - // Location::parent(), - // NativeTokenExistentialDeposit::get() - // ).into()); - // } - - // impl pallet_xcm_benchmarks::Config for Runtime { - // type XcmConfig = xcm_config::XcmConfig; - // type AccountIdConverter = xcm_config::LocationToAccountId; - // type DeliveryHelper = cumulus_primitives_utility::ToParentDeliveryHelper< - // xcm_config::XcmConfig, - // ExistentialDepositAsset, - // PriceForParentDelivery, - // >; - // fn valid_destination() -> Result { - // Ok(Location::parent()) - // } - // fn worst_case_holding(_depositable_count: u32) -> Assets { - // // just concrete assets according to relay chain. - // let assets: Vec = vec![ - // Asset { - // id: AssetId(Location::parent()), - // fun: Fungible(1_000_000 * UNITS), - // } - // ]; - // assets.into() - // } - // } + const UNITS: Balance = 1_000_000_000_000; + const CENTS: Balance = UNITS / 100; + + parameter_types! { + pub FeeAssetId: AssetId = AssetId(Location::parent()); + pub const BaseDeliveryFee: u128 = CENTS.saturating_mul(3); + } + pub type PriceForParentDelivery = polkadot_runtime_common::xcm_sender::ExponentialPrice< + FeeAssetId, + BaseDeliveryFee, + TransactionByteFee, + ParachainSystem, + >; + + use pallet_xcm::benchmarking::Pallet as PalletXcmExtrinsicsBenchmark; + impl pallet_xcm::benchmarking::Config for Runtime { + type DeliveryHelper = cumulus_primitives_utility::ToParentDeliveryHelper< + xcm_config::XcmConfig, + ExistentialDepositAsset, + PriceForParentDelivery, + >; + fn reachable_dest() -> Option { + Some(Parent.into()) + } + + fn teleportable_asset_and_dest() -> Option<(Asset, Location)> { + Some(( + Asset { + fun: Fungible(NativeTokenExistentialDeposit::get()), + id: AssetId(Parent.into()) + }, + Parent.into(), + )) + } + + fn reserve_transferable_asset_and_dest() -> Option<(Asset, Location)> { + None + } + + fn get_asset() -> Asset { + Asset { + id: AssetId(Location::parent()), + fun: Fungible(UNITS), + } + } + } + + parameter_types! { + pub ExistentialDepositAsset: Option = Some(( + Location::parent(), + NativeTokenExistentialDeposit::get() + ).into()); + } + + impl pallet_xcm_benchmarks::Config for Runtime { + type XcmConfig = xcm_config::XcmConfig; + type AccountIdConverter = xcm_config::LocationToAccountId; + type DeliveryHelper = cumulus_primitives_utility::ToParentDeliveryHelper< + xcm_config::XcmConfig, + ExistentialDepositAsset, + PriceForParentDelivery, + >; + fn valid_destination() -> Result { + Ok(Location::parent()) + } + fn worst_case_holding(_depositable_count: u32) -> Assets { + // just concrete assets according to relay chain. + let assets: Vec = vec![ + Asset { + id: AssetId(Location::parent()), + fun: Fungible(1_000_000 * UNITS), + } + ]; + assets.into() + } + } let mut whitelist: Vec = AllPalletsWithSystem::whitelisted_storage_keys(); @@ -2659,7 +2660,7 @@ impl_runtime_apis! { let mut batches = Vec::::new(); let params = (&config, &whitelist); - frame_add_benchmark!(params, batches, module_nft, NftBench::); + // frame_add_benchmark!(params, batches, module_nft, NftBench::); add_benchmarks!(params, batches); if batches.is_empty() { return Err("Benchmark not found for this module.".into()) }