From 57901a722b4833f58202ac81e79b0594d35dc271 Mon Sep 17 00:00:00 2001 From: Dreyhh Date: Fri, 29 Mar 2024 17:59:54 -0600 Subject: [PATCH 1/5] Developed benchmarks and weights for afloat, closes #36 --- .vscode/extensions.json | 5 - .vscode/settings.json | 21 +- .vscode/tasks.json | 97 ---- pallets/afloat/src/benchmarking.rs | 441 +++++++++++++++ pallets/afloat/src/functions.rs | 33 +- pallets/afloat/src/lib.rs | 78 ++- pallets/afloat/src/mock.rs | 35 +- pallets/afloat/src/types.rs | 1 - pallets/afloat/src/weights.rs | 782 ++++++++++++++++++++++++++ pallets/fruniques/src/lib.rs | 4 + pallets/fruniques/src/mock.rs | 3 + pallets/fruniques/src/tests.rs | 13 +- pallets/fruniques/src/types.rs | 4 +- pallets/gated-marketplace/src/mock.rs | 2 + pallets/mapped-assets/src/mock.rs | 1 + 15 files changed, 1345 insertions(+), 175 deletions(-) delete mode 100644 .vscode/extensions.json delete mode 100644 .vscode/tasks.json create mode 100644 pallets/afloat/src/benchmarking.rs create mode 100644 pallets/afloat/src/weights.rs diff --git a/.vscode/extensions.json b/.vscode/extensions.json deleted file mode 100644 index 4dfb2730..00000000 --- a/.vscode/extensions.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "recommendations": [ - "rust-lang.rust-analyzer" - ] -} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index b85ed873..d0445d23 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,19 +1,6 @@ { - "cSpell.words": [ - "Drawdowns", - "Frunique", - "fruniques", - "Permill" - ], - "task.allowAutomaticTasks": "on", - "editor.tabSize": 4, - "editor.formatOnSave": true, - "github.gitProtocol": "ssh", - "[rust]": { - "editor.insertSpaces": true, - "editor.tabSize": 4 - }, - "rust-analyzer.linkedProjects": [ - "./pallets/confidential-docs/Cargo.toml" - ], + "rust-analyzer.linkedProjects": [ + "./pallets/afloat/Cargo.toml" + ], + "rust-analyzer.showUnlinkedFileNotification": false } \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json deleted file mode 100644 index 9fa7e0ea..00000000 --- a/.vscode/tasks.json +++ /dev/null @@ -1,97 +0,0 @@ -{ - // See https://go.microsoft.com/fwlink/?LinkId=733558 - // for the documentation about the tasks.json format - "version": "2.0.0", - "tasks": [ - { - "label": "Test", - "type": "shell", - "command": "cargo", - "args": [ - "run", - "--release", - "--bin", - "hashed", - "--", - "--dev" - ], - "group": { - "kind": "test", - "isDefault": true - }, - "presentation": { - "reveal": "always", - "panel": "new" - }, - "problemMatcher": [ - { - "owner": "rust", - "fileLocation": [ - "relative", - "${workspaceRoot}" - ], - "pattern": { - "regexp": "^(.*):(\\d+):(\\d+):\\s+(\\d+):(\\d+)\\s+(warning|error):\\s+(.*)$", - "file": 1, - "line": 2, - "column": 3, - "endLine": 4, - "endColumn": 5, - "severity": 6, - "message": 7 - } - } - ] - }, - { - "label": "Compile", - "type": "shell", - "command": "cargo", - "args": [ - "build", - "--release", - "-p", - "hashed-runtime", - ], - "group": { - "kind": "build", - "isDefault": false - }, - "presentation": { - "reveal": "always", - "panel": "new" - }, - "problemMatcher": [ - { - "owner": "rust", - "fileLocation": [ - "relative", - "${workspaceRoot}" - ], - "pattern": { - "regexp": "^(.*):(\\d+):(\\d+):\\s+(\\d+):(\\d+)\\s+(warning|error):\\s+(.*)$", - "file": 1, - "line": 2, - "column": 3, - "endLine": 4, - "endColumn": 5, - "severity": 6, - "message": 7 - } - } - ] - }, - { - "type": "cargo", - "command": "test", - "problemMatcher": [ - "$rustc" - ], - "group": { - "kind": "test", - "isDefault": true - }, - "label": "rust: cargo test" - } - ] -} diff --git a/pallets/afloat/src/benchmarking.rs b/pallets/afloat/src/benchmarking.rs new file mode 100644 index 00000000..de5f3898 --- /dev/null +++ b/pallets/afloat/src/benchmarking.rs @@ -0,0 +1,441 @@ +#![cfg(feature = "runtime-benchmarks")] + +use super::*; +use crate::{types::*, Pallet as Afloat}; +use frame_benchmarking::v2::*; +use frame_support::{ + pallet_prelude::*, + traits::{Currency, Get}, +}; +use frame_system::{Config as SystemConfig, RawOrigin}; +use pallet_fruniques::types::{Attributes, ParentInfo}; +use scale_info::prelude::{vec::Vec, *}; +use sp_runtime::{traits::Bounded, Permill}; +type DepositBalanceOf = <::Currency as Currency< + ::AccountId, +>>::Balance; + +const SEED: u32 = 0; +const MAX_U32: u32 = u32::MAX; +const MAX_U64: u64 = u64::MAX; +const MAX_TAX_CREDIT_AMOUNT: u32 = 100; + +fn set_max_balance(account: T::AccountId) -> Result<(), sp_runtime::DispatchError> { + let max_balance = DepositBalanceOf::::max_value(); + ::Currency::make_free_balance_be(&account, max_balance); + Ok(()) +} + +fn init() -> Result<(), sp_runtime::DispatchError> +where + ::ItemId: From, + ::CollectionId: From, +{ + let admin: T::AccountId = account("admin", 0, SEED); + let creator: T::AccountId = account("creator", 0, SEED); + set_max_balance::(admin.clone())?; + set_max_balance::(creator.clone())?; + let asset_id: T::AssetId = T::AfloatBenchHelper::asset(0); + let min_balance: T::Balance = T::AfloatBenchHelper::balance(1); + let asset: CreateAsset = CreateAsset::New { asset_id, min_balance }; + + Afloat::initial_setup(RawOrigin::Root.into(), InitialSetupArgs::All { admin, asset, creator }) +} + +fn register_user( + user: ::AccountId, + id: &str, +) -> Result<(), sp_runtime::DispatchError> +where + ::ItemId: From, + ::CollectionId: From, +{ + let cid: ShortString = ShortString::try_from(id.as_bytes().to_vec()).unwrap(); + let cid_creator: ShortString = ShortString::try_from(id.as_bytes().to_vec()).unwrap(); + let group: ShortString = ShortString::try_from(id.as_bytes().to_vec()).unwrap(); + Afloat::::sign_up( + RawOrigin::Signed(user).into(), + SignUpArgs::BuyerOrSeller { cid, cid_creator, group }, + ) +} + +fn create_sized_description( + size: u32, +) -> BoundedVec::StringLimit> { + let mut v = vec![0; size as usize]; + v[0] = 0; + BoundedVec::::StringLimit>::try_from(v).unwrap() +} + +fn create_sized_attributes(a: u32, k: u32, v: u32) -> Attributes { + let vk = vec![0; k as usize]; + let vv = vec![0; v as usize]; + let attribute_keys = + BoundedVec::::KeyLimit>::try_from(vk).unwrap(); + let attribute_values = + BoundedVec::::ValueLimit>::try_from(vv).unwrap(); + let mut attributes = Attributes::::default(); + for _ in 0..a { + let _ = attributes.try_push((attribute_keys.clone(), attribute_values.clone())); + } + attributes +} + +fn create_sized_parent_info( + collection_id: u32, + parent_id: u32, + parent_weight: u32, + is_hierarchical: bool, +) -> ParentInfo { + ParentInfo { + collection_id: T::AfloatBenchHelper::collection(collection_id), + parent_id: T::AfloatBenchHelper::item(parent_id), + parent_weight: Permill::from_percent(parent_weight), + is_hierarchical, + } +} + +fn add_tax_credit( + user: ::AccountId, +) -> Result<(), sp_runtime::DispatchError> +where + ::ItemId: From, + ::CollectionId: From, +{ + let description = create_sized_description::(10); + Afloat::::create_tax_credit(RawOrigin::Signed(user).into(), description, None, None) +} + +fn add_sell_order( + user: ::AccountId, +) -> Result<[u8; 32], sp_runtime::DispatchError> +where + ::ItemId: From, + ::CollectionId: From, +{ + Afloat::::create_offer( + RawOrigin::Signed(user.clone()).into(), + CreateOfferArgs::::Sell { + tax_credit_id: T::AfloatBenchHelper::item(0), + price_per_credit: MAX_U32.into(), + tax_credit_amount: MAX_U32, + expiration_date: MAX_U32.into(), + }, + )?; + let offer_id = AfloatOffers::::iter().last().unwrap().0; + ensure!(AfloatOffers::::contains_key(offer_id), Error::::OfferNotFound); + Ok(offer_id) +} + +fn add_start_take_sell_order( + user: ::AccountId, + offer_id: [u8; 32], +) -> Result<[u8; 32], sp_runtime::DispatchError> +where + ::ItemId: From, + ::CollectionId: From, +{ + let offer = AfloatOffers::::get(offer_id).unwrap(); + let offer_trxs = offer.transactions.clone(); + assert_eq!(offer.status, OfferStatus::CREATED); + assert!(offer_trxs.is_empty()); + let admin: T::AccountId = account("admin", 0, SEED); + Afloat::::set_afloat_balance( + RawOrigin::Signed(admin).into(), + user.clone(), + T::Balance::max_value().into(), + )?; + + Afloat::::start_take_sell_order(RawOrigin::Signed(user).into(), offer_id, 99)?; + let offer = AfloatOffers::::get(offer_id).unwrap(); + let offer_trxs = offer.transactions.clone(); + let trx_id = offer_trxs.last().unwrap(); + Ok(*trx_id) +} + +fn add_confirm_sell_transaction( + user: ::AccountId, + transaction_id: [u8; 32], +) -> Result<(), sp_runtime::DispatchError> +where + ::ItemId: From, + ::CollectionId: From, +{ + Afloat::::confirm_sell_transaction(RawOrigin::Signed(user).into(), transaction_id) +} + +// largest short string +const LSS: u32 = 55; + +pub fn generate_vector(prefix: u8, id: u8, size: u32) -> Vec { + assert!(size > 0, "vector size must be greater than 0"); + let mut v = vec![id; size as usize]; + v[0] = prefix; + v +} + +#[benchmarks(where T : Config, + ::ItemId: From, + ::CollectionId: From + )] +mod benchmarks { + use super::*; + #[benchmark] + fn initial_setup() { + let admin: T::AccountId = account("admin", 0, SEED); + let creator: T::AccountId = account("creator", 0, SEED); + set_max_balance::(admin.clone()).unwrap(); + set_max_balance::(creator.clone()).unwrap(); + let asset_id: T::AssetId = T::AfloatBenchHelper::asset(0); + let min_balance: T::Balance = T::AfloatBenchHelper::balance(1); + let asset: CreateAsset = CreateAsset::New { asset_id, min_balance }; + assert!(Afloat::::user_info(&creator).is_none()); + assert!(Afloat::::user_info(&admin).is_none()); + #[extrinsic_call] + _( + RawOrigin::Root, + InitialSetupArgs::All { admin: admin.clone(), asset, creator: creator.clone() }, + ); + assert!(Afloat::::user_info(&creator).is_some()); + assert!(Afloat::::user_info(&admin).is_some()); + } + + #[benchmark] + fn kill_storage() { + init::().unwrap(); + assert!(Afloat::::marketplace_id().is_some()); + assert!(Afloat::::collection_id().is_some()); + assert!(Afloat::::asset_id().is_some()); + #[extrinsic_call] + _(RawOrigin::Root, KillStorageArgs::All); + assert!(Afloat::::marketplace_id().is_none()); + assert!(Afloat::::collection_id().is_none()); + assert!(Afloat::::asset_id().is_none()); + } + + #[benchmark] + fn sign_up() { + let cid: ShortString = ShortString::try_from(generate_vector(0, 1, LSS)).unwrap(); + let cid_creator: ShortString = ShortString::try_from(generate_vector(0, 1, LSS)).unwrap(); + let group: ShortString = ShortString::try_from(generate_vector(0, 1, LSS)).unwrap(); + + let sign_up_args = SignUpArgs::BuyerOrSeller { cid: cid.clone(), cid_creator, group }; + let user: T::AccountId = account("user", 0, SEED); + + init::().unwrap(); + + #[extrinsic_call] + _(RawOrigin::Signed(user.clone()), sign_up_args); + + assert_eq!(Afloat::::user_info(&user).unwrap().cid, cid); + } + + #[benchmark] + fn update_user_info() { + init::().unwrap(); + + let user: T::AccountId = account("user", 0, SEED); + register_user::(user.clone(), "user").unwrap(); + + assert_eq!(Afloat::::user_info(&user).unwrap().cid, b"user".to_vec()); + + let new_cid: ShortString = ShortString::try_from(generate_vector(0, 1, LSS)).unwrap(); + let new_cid_creator: ShortString = + ShortString::try_from(generate_vector(0, 1, LSS)).unwrap(); + let new_group: ShortString = ShortString::try_from(generate_vector(0, 1, LSS)).unwrap(); + + let update_user_info_args = UpdateUserArgs::AdminEdit { + cid: new_cid.clone(), + cid_creator: new_cid_creator, + group: new_group, + }; + + let admin: T::AccountId = account("admin", 0, SEED); + #[extrinsic_call] + _(RawOrigin::Signed(admin.clone()), user.clone(), update_user_info_args); + + assert_eq!(Afloat::::user_info(&user).unwrap().cid, new_cid); + } + + #[benchmark] + fn create_tax_credit(a: Linear<0, { ::MaxAttributes::get() }>) { + let user: T::AccountId = account("user", 0, SEED); + init::().unwrap(); + register_user::(user.clone(), "user").unwrap(); + + let attributes: Attributes = create_sized_attributes::( + a, + ::KeyLimit::get(), + ::ValueLimit::get(), + ); + let description = + create_sized_description::(::StringLimit::get()); + let parent_info = create_sized_parent_info::(0, 0, MAX_U32, true); + let _ = Afloat::::create_tax_credit( + RawOrigin::Signed(user.clone()).into(), + description.clone(), + None, + None, + ); + assert_eq!(attributes.len() as u32, a); + #[extrinsic_call] + _(RawOrigin::Signed(user.clone()), description, Some(attributes), Some(parent_info)); + } + + #[benchmark] + fn create_offer() { + let user: T::AccountId = account("user", 0, SEED); + init::().unwrap(); + register_user::(user.clone(), "user").unwrap(); + add_tax_credit::(user.clone()).unwrap(); + let args = CreateOfferArgs::Sell { + tax_credit_amount: MAX_TAX_CREDIT_AMOUNT, + tax_credit_id: T::AfloatBenchHelper::item(0), + price_per_credit: T::AfloatBenchHelper::balance(MAX_U64), + expiration_date: u64::MAX, + }; + + #[extrinsic_call] + _(RawOrigin::Signed(user.clone()), args); + } + + #[benchmark] + fn start_take_sell_order() { + let user: T::AccountId = account("user", 0, SEED); + let other_user: T::AccountId = account("other_user", 0, SEED); + set_max_balance::(other_user.clone()).unwrap(); + set_max_balance::(user.clone()).unwrap(); + init::().unwrap(); + register_user::(user.clone(), "user").unwrap(); + register_user::(other_user.clone(), "other_user").unwrap(); + add_tax_credit::(user.clone()).unwrap(); + let offer_id = add_sell_order::(user.clone()).unwrap(); + let offer = AfloatOffers::::get(offer_id).unwrap(); + let offer_trxs = offer.transactions.clone(); + assert_eq!(offer.status, OfferStatus::CREATED); + assert!(offer_trxs.is_empty()); + let admin: T::AccountId = account("admin", 0, SEED); + let _ = Afloat::::set_afloat_balance( + RawOrigin::Signed(admin).into(), + other_user.clone(), + T::Balance::max_value().into(), + ); + + #[extrinsic_call] + _(RawOrigin::Signed(other_user), offer_id, MAX_U32.into()); + + let offer = AfloatOffers::::get(offer_id).unwrap(); + let offer_trxs = offer.transactions.clone(); + assert_eq!(offer.status, OfferStatus::CREATED); + assert_eq!(offer_trxs.len() as u32, 1); + } + + #[benchmark] + fn confirm_sell_transaction() { + let user: T::AccountId = account("user", 0, SEED); + let other_user: T::AccountId = account("other_user", 0, SEED); + set_max_balance::(other_user.clone()).unwrap(); + set_max_balance::(user.clone()).unwrap(); + init::().unwrap(); + register_user::(user.clone(), "user").unwrap(); + register_user::(other_user.clone(), "other_user").unwrap(); + add_tax_credit::(user.clone()).unwrap(); + let offer_id = add_sell_order::(user.clone()).unwrap(); + + let transaction_id = add_start_take_sell_order::(other_user.clone(), offer_id).unwrap(); + let transaction = AfloatTransactions::::get(transaction_id).unwrap(); + assert_eq!(transaction.confirmed, false); + + #[extrinsic_call] + _(RawOrigin::Signed(user.clone()), transaction_id); + + let transaction = AfloatTransactions::::get(transaction_id).unwrap(); + assert_eq!(transaction.confirmed, true); + } + + #[benchmark] + fn finish_take_sell_transaction() { + let user: T::AccountId = account("user", 0, SEED); + let other_user: T::AccountId = account("other_user", 0, SEED); + set_max_balance::(other_user.clone()).unwrap(); + set_max_balance::(user.clone()).unwrap(); + init::().unwrap(); + register_user::(user.clone(), "user").unwrap(); + register_user::(other_user.clone(), "other_user").unwrap(); + add_tax_credit::(user.clone()).unwrap(); + let offer_id = add_sell_order::(user.clone()).unwrap(); + let transaction_id = add_start_take_sell_order::(other_user.clone(), offer_id).unwrap(); + add_confirm_sell_transaction::(user.clone(), transaction_id).unwrap(); + let transaction = AfloatTransactions::::get(transaction_id).unwrap(); + assert_eq!(transaction.completed, false); + + #[extrinsic_call] + _(RawOrigin::Signed(other_user.clone()), transaction_id); + + let transaction = AfloatTransactions::::get(transaction_id).unwrap(); + assert_eq!(transaction.completed, true); + } + + #[benchmark] + fn set_afloat_balance() { + let user: T::AccountId = account("user", 0, SEED); + set_max_balance::(user.clone()).unwrap(); + init::().unwrap(); + register_user::(user.clone(), "user").unwrap(); + let admin: T::AccountId = account("admin", 0, SEED); + let amount = T::AfloatBenchHelper::balance(MAX_U64); + assert_eq!( + Afloat::::do_get_afloat_balance(user.clone()).unwrap(), + T::AfloatBenchHelper::balance(0) + ); + #[extrinsic_call] + _(RawOrigin::Signed(admin.clone()), user.clone(), amount); + assert_eq!(Afloat::::do_get_afloat_balance(user).unwrap(), amount.into()); + } + + #[benchmark] + fn cancel_offer() { + let user: T::AccountId = account("user", 0, SEED); + init::().unwrap(); + register_user::(user.clone(), "user").unwrap(); + add_tax_credit::(user.clone()).unwrap(); + let offer_id = add_sell_order::(user.clone()).unwrap(); + let offer = AfloatOffers::::get(offer_id).unwrap(); + assert_eq!(offer.status, OfferStatus::CREATED); + #[extrinsic_call] + _(RawOrigin::Signed(user.clone()), offer_id); + let offer = AfloatOffers::::get(offer_id).unwrap(); + assert_eq!(offer.status, OfferStatus::CANCELLED); + } + + #[benchmark] + fn add_afloat_admin() { + let user: T::AccountId = account("user", 0, SEED); + let admin: T::AccountId = account("admin", 0, SEED); + init::().unwrap(); + register_user::(user.clone(), "user").unwrap(); + assert!(!Afloat::::is_admin(user.clone()).unwrap()); + #[extrinsic_call] + _(RawOrigin::Signed(admin.clone()), user.clone()); + assert!(Afloat::::is_admin(user).unwrap()); + } + + #[benchmark] + fn assign_user_to_role() { + let user: T::AccountId = account("user", 0, SEED); + let admin: T::AccountId = account("admin", 0, SEED); + init::().unwrap(); + register_user::(user.clone(), "user").unwrap(); + let role: AfloatRole = AfloatRole::CPA; + assert!(!Afloat::::is_cpa(user.clone()).unwrap()); + #[extrinsic_call] + _(RawOrigin::Signed(admin.clone()), user.clone(), role); + assert!(Afloat::::is_cpa(user).unwrap()); + } + + impl_benchmark_test_suite! { + Afloat, + crate::mock::new_test_ext_2(), + crate::mock::Test, + } +} diff --git a/pallets/afloat/src/functions.rs b/pallets/afloat/src/functions.rs index 15c83801..ec0c637c 100644 --- a/pallets/afloat/src/functions.rs +++ b/pallets/afloat/src/functions.rs @@ -11,9 +11,9 @@ use pallet_rbac::types::{IdOrVec, RoleBasedAccessControl, RoleId}; use scale_info::prelude::vec; use sp_io::hashing::blake2_256; use sp_runtime::{ - Permill, sp_std::{str, vec::Vec}, - traits::{Zero, StaticLookup, CheckedMul}, + traits::{CheckedMul, StaticLookup, Zero}, + Permill, }; impl Pallet { @@ -448,10 +448,7 @@ impl Pallet { authority: OriginFor, order_id: [u8; 32], tax_credit_amount: T::Balance, - ) -> DispatchResult - where - ::ItemId: From, - { + ) -> DispatchResult { let who = ensure_signed(authority.clone())?; let maybe_roles = Self::get_all_roles_for_user(who.clone())?; @@ -475,7 +472,8 @@ impl Pallet { ); let price_per_credit: T::Balance = offer.price_per_credit.into(); - let total_price: T::Balance = Self::safe_multiply_offer(price_per_credit, tax_credit_amount)?; + let total_price: T::Balance = + Self::safe_multiply_offer(price_per_credit, tax_credit_amount)?; //ensure user has enough afloat balance ensure!( Self::do_get_afloat_balance(who.clone())? >= total_price, @@ -531,8 +529,6 @@ impl Pallet { Ok(()) } - - /// Confirms a sell transaction. /// /// # Arguments @@ -577,10 +573,7 @@ impl Pallet { pub fn do_confirm_sell_transaction( authority: OriginFor, transaction_id: [u8; 32], - ) -> DispatchResult - where - ::ItemId: From, - { + ) -> DispatchResult { let who = ensure_signed(authority.clone())?; let maybe_roles = Self::get_all_roles_for_user(who.clone())?; @@ -767,7 +760,6 @@ impl Pallet { ) -> DispatchResult where ::ItemId: From, - ::CollectionId: From, { let maybe_roles = Self::get_all_roles_for_user(owner.clone())?; ensure!(!maybe_roles.is_empty(), Error::::Unauthorized); @@ -840,6 +832,17 @@ impl Pallet { Ok(maybe_owner.is_ok()) } + pub fn is_admin(account: T::AccountId) -> Result { + let maybe_admin = ::Rbac::has_role( + account.clone(), + Self::pallet_id(), + &Self::scope_id(), + [AfloatRole::Admin.id()].to_vec(), + ); + + Ok(maybe_admin.is_ok()) + } + pub fn is_cpa(account: T::AccountId) -> Result { let maybe_cpa = ::Rbac::has_role( account.clone(), @@ -937,7 +940,7 @@ impl Pallet { fn safe_multiply_offer( factor1: T::Balance, - factor2: T::Balance + factor2: T::Balance, ) -> Result { let result = factor1.checked_mul(&factor2).ok_or_else(|| Error::::ArithmeticOverflow)?; Ok(result) diff --git a/pallets/afloat/src/lib.rs b/pallets/afloat/src/lib.rs index 9edaad82..8582de85 100644 --- a/pallets/afloat/src/lib.rs +++ b/pallets/afloat/src/lib.rs @@ -8,19 +8,19 @@ mod mock; #[cfg(test)] mod tests; +mod benchmarking; mod functions; pub mod types; +pub mod weights; +use weights::WeightInfo; #[frame_support::pallet] pub mod pallet { - use frame_support::{ - pallet_prelude::*, - traits::{Currency, Time}, - }; + use super::*; + use frame_support::{pallet_prelude::*, traits::Currency}; use frame_system::{pallet_prelude::*, RawOrigin}; use pallet_fruniques::types::{Attributes, CollectionDescription, FruniqueRole, ParentInfo}; use pallet_gated_marketplace::types::*; - use sp_runtime::traits::Scale; const STORAGE_VERSION: StorageVersion = StorageVersion::new(0); use crate::types::*; @@ -29,6 +29,30 @@ pub mod pallet { ::AccountId, >>::Balance; + #[cfg(feature = "runtime-benchmarks")] + pub trait BenchmarkHelper { + fn collection(i: u32) -> CollectionId; + fn item(i: u32) -> ItemId; + fn asset(i: u32) -> AssetId; + fn balance(i: u64) -> Balance; + } + #[cfg(feature = "runtime-benchmarks")] + impl, ItemId: From, AssetId: From, Balance: From> + BenchmarkHelper for () + { + fn collection(i: u32) -> CollectionId { + i.into() + } + fn item(i: u32) -> ItemId { + i.into() + } + fn asset(i: u32) -> AssetId { + i.into() + } + fn balance(i: u64) -> Balance { + i.into() + } + } /// Configure the pallet by specifying the parameters and types on which it depends. #[pallet::config] pub trait Config: @@ -42,9 +66,17 @@ pub mod pallet { type Rbac: RoleBasedAccessControl; // type RemoveOrigin: EnsureOrigin; type Currency: Currency; - type ItemId: Parameter + Member + Default; - } + #[cfg(feature = "runtime-benchmarks")] + type AfloatBenchHelper: BenchmarkHelper< + Self::CollectionId, + Self::ItemId, + Self::AssetId, + Self::Balance, + >; + + type WeightInfo: WeightInfo; + } #[pallet::pallet] #[pallet::storage_version(STORAGE_VERSION)] @@ -199,11 +231,11 @@ pub mod pallet { #[pallet::call] impl Pallet where - T: pallet_uniques::Config, ::ItemId: From, + ::CollectionId: From, { #[pallet::call_index(0)] - #[pallet::weight(Weight::from_parts(10_000,0) + T::DbWeight::get().reads_writes(1,1))] + #[pallet::weight(::WeightInfo::initial_setup())] pub fn initial_setup(origin: OriginFor, args: InitialSetupArgs) -> DispatchResult { // Ensure sudo origin let _ = T::RemoveOrigin::ensure_origin(origin.clone())?; @@ -240,7 +272,7 @@ pub mod pallet { } #[pallet::call_index(1)] - #[pallet::weight(Weight::from_parts(10_000,0) + T::DbWeight::get().reads_writes(1,1))] + #[pallet::weight(::WeightInfo::kill_storage())] pub fn kill_storage(origin: OriginFor, args: KillStorageArgs) -> DispatchResult { // ensure sudo origin T::RemoveOrigin::ensure_origin(origin.clone())?; @@ -277,14 +309,14 @@ pub mod pallet { } #[pallet::call_index(2)] - #[pallet::weight(Weight::from_parts(10_000,0) + T::DbWeight::get().reads_writes(1,1))] + #[pallet::weight(::WeightInfo::sign_up())] pub fn sign_up(origin: OriginFor, args: SignUpArgs) -> DispatchResult { let who = ensure_signed(origin)?; Self::do_create_user(who.clone(), who, args) } #[pallet::call_index(3)] - #[pallet::weight(Weight::from_parts(10_000,0) + T::DbWeight::get().reads_writes(1,1))] + #[pallet::weight(::WeightInfo::update_user_info())] pub fn update_user_info( origin: OriginFor, address: T::AccountId, @@ -313,7 +345,7 @@ pub mod pallet { } #[pallet::call_index(4)] - #[pallet::weight(Weight::from_parts(10_000,0) + T::DbWeight::get().reads_writes(1,1))] + #[pallet::weight(::WeightInfo::create_offer())] pub fn create_offer(origin: OriginFor, args: CreateOfferArgs) -> DispatchResult { let who = ensure_signed(origin)?; match args { @@ -350,18 +382,18 @@ pub mod pallet { } #[pallet::call_index(5)] - #[pallet::weight(Weight::from_parts(10_000,0) + T::DbWeight::get().reads_writes(1,1))] + #[pallet::weight(::WeightInfo::start_take_sell_order())] pub fn start_take_sell_order( origin: OriginFor, offer_id: [u8; 32], - tax_credit_amount: T::Balance, + tax_credit_amount: u32, ) -> DispatchResult { ensure_signed(origin.clone())?; - Self::do_start_take_sell_order(origin, offer_id, tax_credit_amount) + Self::do_start_take_sell_order(origin, offer_id, tax_credit_amount.into()) } #[pallet::call_index(6)] - #[pallet::weight(Weight::from_parts(10_000,0) + T::DbWeight::get().reads_writes(1,1))] + #[pallet::weight(::WeightInfo::confirm_sell_transaction())] pub fn confirm_sell_transaction( origin: OriginFor, transaction_id: [u8; 32], @@ -371,7 +403,7 @@ pub mod pallet { } #[pallet::call_index(7)] - #[pallet::weight(Weight::from_parts(10_000,0) + T::DbWeight::get().reads_writes(1,1))] + #[pallet::weight(::WeightInfo::finish_take_sell_transaction())] pub fn finish_take_sell_transaction( origin: OriginFor, transaction_id: [u8; 32], @@ -381,7 +413,7 @@ pub mod pallet { } #[pallet::call_index(8)] - #[pallet::weight(Weight::from_parts(10_000,0) + T::DbWeight::get().reads_writes(1,1))] + #[pallet::weight(::WeightInfo::create_tax_credit(attributes.clone().unwrap_or(Attributes::::default()).len() as u32))] pub fn create_tax_credit( origin: OriginFor, metadata: CollectionDescription, @@ -393,7 +425,7 @@ pub mod pallet { } #[pallet::call_index(9)] - #[pallet::weight(Weight::from_parts(10_000,0) + T::DbWeight::get().reads_writes(1,1))] + #[pallet::weight(::WeightInfo::set_afloat_balance())] pub fn set_afloat_balance( origin: OriginFor, beneficiary: T::AccountId, @@ -406,7 +438,7 @@ pub mod pallet { } #[pallet::call_index(10)] - #[pallet::weight(Weight::from_parts(10_000,0) + T::DbWeight::get().reads_writes(1,1))] + #[pallet::weight(::WeightInfo::add_afloat_admin())] pub fn add_afloat_admin(origin: OriginFor, admin: T::AccountId) -> DispatchResult { let who = ensure_signed(origin.clone())?; let is_admin_or_owner = Self::is_admin_or_owner(who.clone())?; @@ -415,14 +447,14 @@ pub mod pallet { } #[pallet::call_index(11)] - #[pallet::weight(Weight::from_parts(10_000,0) + T::DbWeight::get().reads_writes(1,1))] + #[pallet::weight(::WeightInfo::cancel_offer())] pub fn cancel_offer(origin: OriginFor, order_id: StorageId) -> DispatchResult { let who = ensure_signed(origin.clone())?; Self::do_cancel_offer(who, order_id) } #[pallet::call_index(12)] - #[pallet::weight(Weight::from_parts(10_000,0) + T::DbWeight::get().reads_writes(1,1))] + #[pallet::weight(::WeightInfo::assign_user_to_role())] pub fn assign_user_to_role( origin: OriginFor, user_address: T::AccountId, diff --git a/pallets/afloat/src/mock.rs b/pallets/afloat/src/mock.rs index ff935bc6..25215b14 100644 --- a/pallets/afloat/src/mock.rs +++ b/pallets/afloat/src/mock.rs @@ -9,7 +9,6 @@ use sp_runtime::{ traits::{BlakeTwo256, IdentityLookup}, BuildStorage, }; -type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; type Block = frame_system::mocking::MockBlock; use frame_system::EnsureRoot; use system::EnsureSigned; @@ -71,13 +70,15 @@ impl pallet_afloat::Config for Test { //type RemoveOrigin = frame_system::EnsureSigned; type Currency = pallet_balances::Pallet; type Rbac = RBAC; - type ItemId = u32; + #[cfg(feature = "runtime-benchmarks")] + type AfloatBenchHelper = (); + type WeightInfo = (); } parameter_types! { pub const LabelMaxLen: u32 = 32; pub const MaxAuthsPerMarket: u32 = 3; - pub const MaxRolesPerAuth : u32 = 1; + pub const MaxRolesPerAuth : u32 = 10; pub const MaxApplicants: u32 = 3; pub const MaxBlockedUsersPerMarket: u32 = 100; pub const NotesMaxLen: u32 = 256; @@ -111,6 +112,7 @@ impl pallet_gated_marketplace::Config for Test { parameter_types! { pub const ChildMaxLen: u32 = 10; pub const MaxParentsInCollection: u32 = 10; + pub const MaxAttributes : u32 = 10; } impl pallet_fruniques::Config for Test { @@ -118,6 +120,7 @@ impl pallet_fruniques::Config for Test { type RemoveOrigin = EnsureRoot; type ChildMaxLen = ChildMaxLen; type MaxParentsInCollection = MaxParentsInCollection; + type MaxAttributes = MaxAttributes; type Rbac = RBAC; } @@ -169,13 +172,13 @@ impl pallet_balances::Config for Test { } parameter_types! { - pub const MaxScopesPerPallet: u32 = 2; - pub const MaxRolesPerPallet: u32 = 6; - pub const RoleMaxLen: u32 = 25; - pub const PermissionMaxLen: u32 = 25; + pub const MaxScopesPerPallet: u32 = 10; + pub const MaxRolesPerPallet: u32 = 10; + pub const RoleMaxLen: u32 = 255; + pub const PermissionMaxLen: u32 = 255; pub const MaxPermissionsPerRole: u32 = 30; - pub const MaxRolesPerUser: u32 = 2; - pub const MaxUsersPerRole: u32 = 2; + pub const MaxRolesPerUser: u32 = 10; + pub const MaxUsersPerRole: u32 = 10; } impl pallet_rbac::Config for Test { type RuntimeEvent = RuntimeEvent; @@ -236,8 +239,6 @@ impl pallet_mapped_assets::Config for Test { type Extra = (); type RemoveItemsLimit = ConstU32<5>; type Rbac = RBAC; - #[cfg(feature = "runtime-benchmarks")] - type BenchmarkHelper = (); } pub struct TestExternalitiesBuilder { @@ -308,3 +309,15 @@ pub fn new_test_ext() -> sp_io::TestExternalities { }); t } + +pub fn new_test_ext_2() -> sp_io::TestExternalities { + // TODO: get initial conf? + let mut t: sp_io::TestExternalities = + frame_system::GenesisConfig::::default().build_storage().unwrap().into(); + t.execute_with(|| { + Balances::make_free_balance_be(&1, 100); + Balances::make_free_balance_be(&2, 100); + Balances::make_free_balance_be(&3, 100); + }); + t +} diff --git a/pallets/afloat/src/types.rs b/pallets/afloat/src/types.rs index 4b5dc017..825485b5 100644 --- a/pallets/afloat/src/types.rs +++ b/pallets/afloat/src/types.rs @@ -7,7 +7,6 @@ use sp_runtime::sp_std::vec::Vec; pub type ShortString = BoundedVec>; pub type LongString = BoundedVec>; pub type Date = u64; -pub type CollectionId = u32; pub type StorageId = [u8; 32]; pub type TransactionBoundedVec = BoundedVec<[u8; 32], ConstU32<100>>; // ! User structures diff --git a/pallets/afloat/src/weights.rs b/pallets/afloat/src/weights.rs new file mode 100644 index 00000000..36eee363 --- /dev/null +++ b/pallets/afloat/src/weights.rs @@ -0,0 +1,782 @@ + +//! Autogenerated weights for `pallet_afloat` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev +//! DATE: 2024-03-29, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! WORST CASE MAP SIZE: `1000000` +//! HOSTNAME: `armando-hashed`, CPU: `AMD Ryzen 5 4600H with Radeon Graphics` +//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: `1024` + +// Executed Command: +// ../target/release/hashed-parachain +// benchmark +// pallet +// --chain +// dev +// --wasm-execution=compiled +// --pallet +// pallet_afloat +// --extrinsic +// * +// --steps +// 50 +// --repeat +// 20 +// --output +// /home/armando/Desktop/hashed-pallets/hashed-pallets/pallets/afloat/src/weights.rs +// --template +// /home/armando/Desktop/hashed-substrate-parachain/frame-weight-template.hbs + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] +#![allow(missing_docs)] + +use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; +use core::marker::PhantomData; + +/// Weight functions needed for `pallet_afloat`. +pub trait WeightInfo { + fn initial_setup() -> Weight; + fn kill_storage() -> Weight; + fn sign_up() -> Weight; + fn update_user_info() -> Weight; + fn create_tax_credit(a: u32, ) -> Weight; + fn create_offer() -> Weight; + fn start_take_sell_order() -> Weight; + fn confirm_sell_transaction() -> Weight; + fn finish_take_sell_transaction() -> Weight; + fn set_afloat_balance() -> Weight; + fn cancel_offer() -> Weight; + fn add_afloat_admin() -> Weight; + fn assign_user_to_role() -> Weight; +} + +/// Weights for `pallet_afloat` using the Substrate node and recommended hardware. +pub struct SubstrateWeight(PhantomData); +impl WeightInfo for SubstrateWeight { + /// Storage: `RBAC::Roles` (r:10 w:10) + /// Proof: `RBAC::Roles` (`max_values`: None, `max_size`: Some(83), added: 2558, mode: `MaxEncodedLen`) + /// Storage: `RBAC::PalletRoles` (r:3 w:3) + /// Proof: `RBAC::PalletRoles` (`max_values`: None, `max_size`: Some(1633), added: 4108, mode: `MaxEncodedLen`) + /// Storage: `RBAC::Permissions` (r:23 w:23) + /// Proof: `RBAC::Permissions` (`max_values`: None, `max_size`: Some(115), added: 2590, mode: `MaxEncodedLen`) + /// Storage: `RBAC::PermissionsByRole` (r:10 w:10) + /// Proof: `RBAC::PermissionsByRole` (`max_values`: None, `max_size`: Some(3266), added: 5741, mode: `MaxEncodedLen`) + /// Storage: `Fruniques::NextCollection` (r:1 w:1) + /// Proof: `Fruniques::NextCollection` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `RBAC::Scopes` (r:3 w:3) + /// Proof: `RBAC::Scopes` (`max_values`: None, `max_size`: Some(32034), added: 34509, mode: `MaxEncodedLen`) + /// Storage: `RBAC::RolesByUser` (r:6 w:6) + /// Proof: `RBAC::RolesByUser` (`max_values`: None, `max_size`: Some(433), added: 2908, mode: `MaxEncodedLen`) + /// Storage: `RBAC::UsersByScope` (r:6 w:6) + /// Proof: `RBAC::UsersByScope` (`max_values`: None, `max_size`: Some(80098), added: 82573, mode: `MaxEncodedLen`) + /// Storage: `Uniques::Class` (r:1 w:1) + /// Proof: `Uniques::Class` (`max_values`: None, `max_size`: Some(178), added: 2653, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// Storage: `Uniques::ClassMetadataOf` (r:1 w:1) + /// Proof: `Uniques::ClassMetadataOf` (`max_values`: None, `max_size`: Some(88), added: 2563, mode: `MaxEncodedLen`) + /// Storage: `MappedAssets::Asset` (r:1 w:1) + /// Proof: `MappedAssets::Asset` (`max_values`: None, `max_size`: Some(210), added: 2685, mode: `MaxEncodedLen`) + /// Storage: `GatedMarketplace::Marketplaces` (r:1 w:1) + /// Proof: `GatedMarketplace::Marketplaces` (`max_values`: None, `max_size`: Some(109), added: 2584, mode: `MaxEncodedLen`) + /// Storage: `Timestamp::Now` (r:1 w:0) + /// Proof: `Timestamp::Now` (`max_values`: Some(1), `max_size`: Some(8), added: 503, mode: `MaxEncodedLen`) + /// Storage: `Uniques::ClassAccount` (r:0 w:1) + /// Proof: `Uniques::ClassAccount` (`max_values`: None, `max_size`: Some(68), added: 2543, mode: `MaxEncodedLen`) + /// Storage: `Afloat::UserInfo` (r:0 w:2) + /// Proof: `Afloat::UserInfo` (`max_values`: None, `max_size`: Some(300), added: 2775, mode: `MaxEncodedLen`) + /// Storage: `Afloat::AfloatMarketPlaceId` (r:0 w:1) + /// Proof: `Afloat::AfloatMarketPlaceId` (`max_values`: Some(1), `max_size`: Some(32), added: 527, mode: `MaxEncodedLen`) + /// Storage: `Afloat::AfloatAssetId` (r:0 w:1) + /// Proof: `Afloat::AfloatAssetId` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `Afloat::AfloatCollectionId` (r:0 w:1) + /// Proof: `Afloat::AfloatCollectionId` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + fn initial_setup() -> Weight { + // Proof Size summary in bytes: + // Measured: `450` + // Estimated: `496428` + // Minimum execution time: 961_583_000 picoseconds. + Weight::from_parts(994_270_000, 496428) + .saturating_add(T::DbWeight::get().reads(68_u64)) + .saturating_add(T::DbWeight::get().writes(73_u64)) + } + /// Storage: `Afloat::UserInfo` (r:3 w:0) + /// Proof: `Afloat::UserInfo` (`max_values`: None, `max_size`: Some(300), added: 2775, mode: `MaxEncodedLen`) + /// Storage: `RBAC::Scopes` (r:1 w:1) + /// Proof: `RBAC::Scopes` (`max_values`: None, `max_size`: Some(32034), added: 34509, mode: `MaxEncodedLen`) + /// Storage: `RBAC::RolesByUser` (r:2 w:2) + /// Proof: `RBAC::RolesByUser` (`max_values`: None, `max_size`: Some(433), added: 2908, mode: `MaxEncodedLen`) + /// Storage: `RBAC::UsersByScope` (r:3 w:2) + /// Proof: `RBAC::UsersByScope` (`max_values`: None, `max_size`: Some(80098), added: 82573, mode: `MaxEncodedLen`) + /// Storage: `RBAC::PalletRoles` (r:4 w:1) + /// Proof: `RBAC::PalletRoles` (`max_values`: None, `max_size`: Some(1633), added: 4108, mode: `MaxEncodedLen`) + /// Storage: `RBAC::PermissionsByRole` (r:2 w:2) + /// Proof: `RBAC::PermissionsByRole` (`max_values`: None, `max_size`: Some(3266), added: 5741, mode: `MaxEncodedLen`) + /// Storage: `RBAC::Permissions` (r:3 w:3) + /// Proof: `RBAC::Permissions` (`max_values`: None, `max_size`: Some(115), added: 2590, mode: `MaxEncodedLen`) + /// Storage: `Afloat::AfloatMarketPlaceId` (r:0 w:1) + /// Proof: `Afloat::AfloatMarketPlaceId` (`max_values`: Some(1), `max_size`: Some(32), added: 527, mode: `MaxEncodedLen`) + /// Storage: `Afloat::AfloatAssetId` (r:0 w:1) + /// Proof: `Afloat::AfloatAssetId` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `Afloat::AfloatCollectionId` (r:0 w:1) + /// Proof: `Afloat::AfloatCollectionId` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `RBAC::Roles` (r:0 w:2) + /// Proof: `RBAC::Roles` (`max_values`: None, `max_size`: Some(83), added: 2558, mode: `MaxEncodedLen`) + fn kill_storage() -> Weight { + // Proof Size summary in bytes: + // Measured: `3033` + // Estimated: `248709` + // Minimum execution time: 177_538_000 picoseconds. + Weight::from_parts(188_364_000, 248709) + .saturating_add(T::DbWeight::get().reads(18_u64)) + .saturating_add(T::DbWeight::get().writes(16_u64)) + } + /// Storage: `Afloat::UserInfo` (r:1 w:1) + /// Proof: `Afloat::UserInfo` (`max_values`: None, `max_size`: Some(300), added: 2775, mode: `MaxEncodedLen`) + /// Storage: `Timestamp::Now` (r:1 w:0) + /// Proof: `Timestamp::Now` (`max_values`: Some(1), `max_size`: Some(8), added: 503, mode: `MaxEncodedLen`) + /// Storage: `RBAC::Scopes` (r:3 w:0) + /// Proof: `RBAC::Scopes` (`max_values`: None, `max_size`: Some(32034), added: 34509, mode: `MaxEncodedLen`) + /// Storage: `RBAC::PalletRoles` (r:3 w:0) + /// Proof: `RBAC::PalletRoles` (`max_values`: None, `max_size`: Some(1633), added: 4108, mode: `MaxEncodedLen`) + /// Storage: `RBAC::RolesByUser` (r:3 w:3) + /// Proof: `RBAC::RolesByUser` (`max_values`: None, `max_size`: Some(433), added: 2908, mode: `MaxEncodedLen`) + /// Storage: `RBAC::UsersByScope` (r:6 w:3) + /// Proof: `RBAC::UsersByScope` (`max_values`: None, `max_size`: Some(80098), added: 82573, mode: `MaxEncodedLen`) + /// Storage: `Afloat::AfloatMarketPlaceId` (r:1 w:0) + /// Proof: `Afloat::AfloatMarketPlaceId` (`max_values`: Some(1), `max_size`: Some(32), added: 527, mode: `MaxEncodedLen`) + /// Storage: `Afloat::AfloatCollectionId` (r:1 w:0) + /// Proof: `Afloat::AfloatCollectionId` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `GatedMarketplace::BlockedUsersByMarketplace` (r:1 w:0) + /// Proof: `GatedMarketplace::BlockedUsersByMarketplace` (`max_values`: None, `max_size`: Some(3234), added: 5709, mode: `MaxEncodedLen`) + /// Storage: `GatedMarketplace::Marketplaces` (r:1 w:0) + /// Proof: `GatedMarketplace::Marketplaces` (`max_values`: None, `max_size`: Some(109), added: 2584, mode: `MaxEncodedLen`) + fn sign_up() -> Weight { + // Proof Size summary in bytes: + // Measured: `2158` + // Estimated: `496428` + // Minimum execution time: 180_891_000 picoseconds. + Weight::from_parts(196_745_000, 496428) + .saturating_add(T::DbWeight::get().reads(21_u64)) + .saturating_add(T::DbWeight::get().writes(7_u64)) + } + /// Storage: `RBAC::Scopes` (r:1 w:0) + /// Proof: `RBAC::Scopes` (`max_values`: None, `max_size`: Some(32034), added: 34509, mode: `MaxEncodedLen`) + /// Storage: `RBAC::RolesByUser` (r:1 w:0) + /// Proof: `RBAC::RolesByUser` (`max_values`: None, `max_size`: Some(433), added: 2908, mode: `MaxEncodedLen`) + /// Storage: `Afloat::UserInfo` (r:1 w:1) + /// Proof: `Afloat::UserInfo` (`max_values`: None, `max_size`: Some(300), added: 2775, mode: `MaxEncodedLen`) + /// Storage: `Timestamp::Now` (r:1 w:0) + /// Proof: `Timestamp::Now` (`max_values`: Some(1), `max_size`: Some(8), added: 503, mode: `MaxEncodedLen`) + fn update_user_info() -> Weight { + // Proof Size summary in bytes: + // Measured: `1159` + // Estimated: `35499` + // Minimum execution time: 51_055_000 picoseconds. + Weight::from_parts(57_131_000, 35499) + .saturating_add(T::DbWeight::get().reads(4_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: `RBAC::RolesByUser` (r:1 w:0) + /// Proof: `RBAC::RolesByUser` (`max_values`: None, `max_size`: Some(433), added: 2908, mode: `MaxEncodedLen`) + /// Storage: `Afloat::AfloatCollectionId` (r:1 w:0) + /// Proof: `Afloat::AfloatCollectionId` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `Uniques::Class` (r:1 w:1) + /// Proof: `Uniques::Class` (`max_values`: None, `max_size`: Some(178), added: 2653, mode: `MaxEncodedLen`) + /// Storage: `Fruniques::NextFrunique` (r:1 w:1) + /// Proof: `Fruniques::NextFrunique` (`max_values`: None, `max_size`: Some(24), added: 2499, mode: `MaxEncodedLen`) + /// Storage: `Uniques::Asset` (r:2 w:1) + /// Proof: `Uniques::Asset` (`max_values`: None, `max_size`: Some(122), added: 2597, mode: `MaxEncodedLen`) + /// Storage: `Uniques::CollectionMaxSupply` (r:1 w:0) + /// Proof: `Uniques::CollectionMaxSupply` (`max_values`: None, `max_size`: Some(24), added: 2499, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// Storage: `Uniques::InstanceMetadataOf` (r:1 w:1) + /// Proof: `Uniques::InstanceMetadataOf` (`max_values`: None, `max_size`: Some(108), added: 2583, mode: `MaxEncodedLen`) + /// Storage: `Uniques::Attribute` (r:1 w:1) + /// Proof: `Uniques::Attribute` (`max_values`: None, `max_size`: Some(364), added: 2839, mode: `MaxEncodedLen`) + /// Storage: `Fruniques::FruniqueInfo` (r:1 w:2) + /// Proof: `Fruniques::FruniqueInfo` (`max_values`: None, `max_size`: Some(505), added: 2980, mode: `MaxEncodedLen`) + /// Storage: `Uniques::Account` (r:0 w:1) + /// Proof: `Uniques::Account` (`max_values`: None, `max_size`: Some(88), added: 2563, mode: `MaxEncodedLen`) + /// The range of component `a` is `[0, 200]`. + fn create_tax_credit(a: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `1886` + // Estimated: `6184` + // Minimum execution time: 149_182_000 picoseconds. + Weight::from_parts(110_726_535, 6184) + // Standard Error: 45_795 + .saturating_add(Weight::from_parts(28_739_579, 0).saturating_mul(a.into())) + .saturating_add(T::DbWeight::get().reads(11_u64)) + .saturating_add(T::DbWeight::get().writes(9_u64)) + } + /// Storage: `RBAC::RolesByUser` (r:1 w:0) + /// Proof: `RBAC::RolesByUser` (`max_values`: None, `max_size`: Some(433), added: 2908, mode: `MaxEncodedLen`) + /// Storage: `Timestamp::Now` (r:1 w:0) + /// Proof: `Timestamp::Now` (`max_values`: Some(1), `max_size`: Some(8), added: 503, mode: `MaxEncodedLen`) + /// Storage: `Afloat::AfloatOffers` (r:0 w:1) + /// Proof: `Afloat::AfloatOffers` (`max_values`: None, `max_size`: Some(3349), added: 5824, mode: `MaxEncodedLen`) + fn create_offer() -> Weight { + // Proof Size summary in bytes: + // Measured: `563` + // Estimated: `3898` + // Minimum execution time: 40_089_000 picoseconds. + Weight::from_parts(42_324_000, 3898) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: `RBAC::RolesByUser` (r:1 w:0) + /// Proof: `RBAC::RolesByUser` (`max_values`: None, `max_size`: Some(433), added: 2908, mode: `MaxEncodedLen`) + /// Storage: `Afloat::AfloatOffers` (r:1 w:1) + /// Proof: `Afloat::AfloatOffers` (`max_values`: None, `max_size`: Some(3349), added: 5824, mode: `MaxEncodedLen`) + /// Storage: `Timestamp::Now` (r:1 w:0) + /// Proof: `Timestamp::Now` (`max_values`: Some(1), `max_size`: Some(8), added: 503, mode: `MaxEncodedLen`) + /// Storage: `Afloat::AfloatAssetId` (r:1 w:0) + /// Proof: `Afloat::AfloatAssetId` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `MappedAssets::Account` (r:1 w:0) + /// Proof: `MappedAssets::Account` (`max_values`: None, `max_size`: Some(134), added: 2609, mode: `MaxEncodedLen`) + /// Storage: `Afloat::AfloatTransactions` (r:0 w:1) + /// Proof: `Afloat::AfloatTransactions` (`max_values`: None, `max_size`: Some(283), added: 2758, mode: `MaxEncodedLen`) + fn start_take_sell_order() -> Weight { + // Proof Size summary in bytes: + // Measured: `1278` + // Estimated: `6814` + // Minimum execution time: 60_833_000 picoseconds. + Weight::from_parts(63_417_000, 6814) + .saturating_add(T::DbWeight::get().reads(5_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) + } + /// Storage: `RBAC::RolesByUser` (r:2 w:0) + /// Proof: `RBAC::RolesByUser` (`max_values`: None, `max_size`: Some(433), added: 2908, mode: `MaxEncodedLen`) + /// Storage: `Afloat::AfloatTransactions` (r:1 w:1) + /// Proof: `Afloat::AfloatTransactions` (`max_values`: None, `max_size`: Some(283), added: 2758, mode: `MaxEncodedLen`) + /// Storage: `Timestamp::Now` (r:1 w:0) + /// Proof: `Timestamp::Now` (`max_values`: Some(1), `max_size`: Some(8), added: 503, mode: `MaxEncodedLen`) + /// Storage: `Afloat::AfloatMarketPlaceId` (r:1 w:0) + /// Proof: `Afloat::AfloatMarketPlaceId` (`max_values`: Some(1), `max_size`: Some(32), added: 527, mode: `MaxEncodedLen`) + /// Storage: `Afloat::AfloatCollectionId` (r:1 w:0) + /// Proof: `Afloat::AfloatCollectionId` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `GatedMarketplace::Marketplaces` (r:1 w:0) + /// Proof: `GatedMarketplace::Marketplaces` (`max_values`: None, `max_size`: Some(109), added: 2584, mode: `MaxEncodedLen`) + /// Storage: `RBAC::Scopes` (r:1 w:0) + /// Proof: `RBAC::Scopes` (`max_values`: None, `max_size`: Some(32034), added: 34509, mode: `MaxEncodedLen`) + /// Storage: `RBAC::Permissions` (r:1 w:0) + /// Proof: `RBAC::Permissions` (`max_values`: None, `max_size`: Some(115), added: 2590, mode: `MaxEncodedLen`) + /// Storage: `RBAC::PermissionsByRole` (r:1 w:0) + /// Proof: `RBAC::PermissionsByRole` (`max_values`: None, `max_size`: Some(3266), added: 5741, mode: `MaxEncodedLen`) + /// Storage: `Uniques::Asset` (r:1 w:0) + /// Proof: `Uniques::Asset` (`max_values`: None, `max_size`: Some(122), added: 2597, mode: `MaxEncodedLen`) + /// Storage: `GatedMarketplace::OffersByItem` (r:1 w:1) + /// Proof: `GatedMarketplace::OffersByItem` (`max_values`: None, `max_size`: Some(3242), added: 5717, mode: `MaxEncodedLen`) + /// Storage: `GatedMarketplace::OffersByAccount` (r:1 w:1) + /// Proof: `GatedMarketplace::OffersByAccount` (`max_values`: None, `max_size`: Some(3250), added: 5725, mode: `MaxEncodedLen`) + /// Storage: `GatedMarketplace::OffersInfo` (r:1 w:1) + /// Proof: `GatedMarketplace::OffersInfo` (`max_values`: None, `max_size`: Some(215), added: 2690, mode: `MaxEncodedLen`) + /// Storage: `GatedMarketplace::OffersByMarketplace` (r:1 w:1) + /// Proof: `GatedMarketplace::OffersByMarketplace` (`max_values`: None, `max_size`: Some(3234), added: 5709, mode: `MaxEncodedLen`) + /// Storage: `Fruniques::FruniqueInfo` (r:1 w:1) + /// Proof: `Fruniques::FruniqueInfo` (`max_values`: None, `max_size`: Some(505), added: 2980, mode: `MaxEncodedLen`) + fn confirm_sell_transaction() -> Weight { + // Proof Size summary in bytes: + // Measured: `3022` + // Estimated: `35499` + // Minimum execution time: 139_684_000 picoseconds. + Weight::from_parts(146_528_000, 35499) + .saturating_add(T::DbWeight::get().reads(16_u64)) + .saturating_add(T::DbWeight::get().writes(6_u64)) + } + /// Storage: `RBAC::RolesByUser` (r:2 w:0) + /// Proof: `RBAC::RolesByUser` (`max_values`: None, `max_size`: Some(433), added: 2908, mode: `MaxEncodedLen`) + /// Storage: `Afloat::AfloatTransactions` (r:1 w:1) + /// Proof: `Afloat::AfloatTransactions` (`max_values`: None, `max_size`: Some(283), added: 2758, mode: `MaxEncodedLen`) + /// Storage: `GatedMarketplace::OffersInfo` (r:1 w:1) + /// Proof: `GatedMarketplace::OffersInfo` (`max_values`: None, `max_size`: Some(215), added: 2690, mode: `MaxEncodedLen`) + /// Storage: `RBAC::Scopes` (r:1 w:0) + /// Proof: `RBAC::Scopes` (`max_values`: None, `max_size`: Some(32034), added: 34509, mode: `MaxEncodedLen`) + /// Storage: `RBAC::Permissions` (r:1 w:0) + /// Proof: `RBAC::Permissions` (`max_values`: None, `max_size`: Some(115), added: 2590, mode: `MaxEncodedLen`) + /// Storage: `RBAC::PermissionsByRole` (r:1 w:0) + /// Proof: `RBAC::PermissionsByRole` (`max_values`: None, `max_size`: Some(3266), added: 5741, mode: `MaxEncodedLen`) + /// Storage: `Uniques::Asset` (r:2 w:1) + /// Proof: `Uniques::Asset` (`max_values`: None, `max_size`: Some(122), added: 2597, mode: `MaxEncodedLen`) + /// Storage: `GatedMarketplace::OffersByItem` (r:1 w:1) + /// Proof: `GatedMarketplace::OffersByItem` (`max_values`: None, `max_size`: Some(3242), added: 5717, mode: `MaxEncodedLen`) + /// Storage: `GatedMarketplace::Marketplaces` (r:1 w:0) + /// Proof: `GatedMarketplace::Marketplaces` (`max_values`: None, `max_size`: Some(109), added: 2584, mode: `MaxEncodedLen`) + /// Storage: `MappedAssets::Account` (r:3 w:3) + /// Proof: `MappedAssets::Account` (`max_values`: None, `max_size`: Some(134), added: 2609, mode: `MaxEncodedLen`) + /// Storage: `MappedAssets::Asset` (r:1 w:1) + /// Proof: `MappedAssets::Asset` (`max_values`: None, `max_size`: Some(210), added: 2685, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:2 w:2) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// Storage: `Fruniques::FruniqueInfo` (r:1 w:2) + /// Proof: `Fruniques::FruniqueInfo` (`max_values`: None, `max_size`: Some(505), added: 2980, mode: `MaxEncodedLen`) + /// Storage: `Uniques::Class` (r:1 w:1) + /// Proof: `Uniques::Class` (`max_values`: None, `max_size`: Some(178), added: 2653, mode: `MaxEncodedLen`) + /// Storage: `Fruniques::NextFrunique` (r:1 w:1) + /// Proof: `Fruniques::NextFrunique` (`max_values`: None, `max_size`: Some(24), added: 2499, mode: `MaxEncodedLen`) + /// Storage: `Uniques::CollectionMaxSupply` (r:1 w:0) + /// Proof: `Uniques::CollectionMaxSupply` (`max_values`: None, `max_size`: Some(24), added: 2499, mode: `MaxEncodedLen`) + /// Storage: `Uniques::InstanceMetadataOf` (r:1 w:1) + /// Proof: `Uniques::InstanceMetadataOf` (`max_values`: None, `max_size`: Some(108), added: 2583, mode: `MaxEncodedLen`) + /// Storage: `Afloat::AfloatOffers` (r:1 w:1) + /// Proof: `Afloat::AfloatOffers` (`max_values`: None, `max_size`: Some(3349), added: 5824, mode: `MaxEncodedLen`) + /// Storage: `Uniques::Account` (r:0 w:1) + /// Proof: `Uniques::Account` (`max_values`: None, `max_size`: Some(88), added: 2563, mode: `MaxEncodedLen`) + fn finish_take_sell_transaction() -> Weight { + // Proof Size summary in bytes: + // Measured: `4512` + // Estimated: `35499` + // Minimum execution time: 349_210_000 picoseconds. + Weight::from_parts(362_549_000, 35499) + .saturating_add(T::DbWeight::get().reads(23_u64)) + .saturating_add(T::DbWeight::get().writes(17_u64)) + } + /// Storage: `RBAC::Scopes` (r:1 w:0) + /// Proof: `RBAC::Scopes` (`max_values`: None, `max_size`: Some(32034), added: 34509, mode: `MaxEncodedLen`) + /// Storage: `RBAC::RolesByUser` (r:1 w:0) + /// Proof: `RBAC::RolesByUser` (`max_values`: None, `max_size`: Some(433), added: 2908, mode: `MaxEncodedLen`) + /// Storage: `Afloat::AfloatAssetId` (r:1 w:0) + /// Proof: `Afloat::AfloatAssetId` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `Afloat::UserInfo` (r:1 w:0) + /// Proof: `Afloat::UserInfo` (`max_values`: None, `max_size`: Some(300), added: 2775, mode: `MaxEncodedLen`) + /// Storage: `MappedAssets::Account` (r:1 w:1) + /// Proof: `MappedAssets::Account` (`max_values`: None, `max_size`: Some(134), added: 2609, mode: `MaxEncodedLen`) + /// Storage: `MappedAssets::Asset` (r:1 w:1) + /// Proof: `MappedAssets::Asset` (`max_values`: None, `max_size`: Some(210), added: 2685, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + fn set_afloat_balance() -> Weight { + // Proof Size summary in bytes: + // Measured: `1606` + // Estimated: `35499` + // Minimum execution time: 100_503_000 picoseconds. + Weight::from_parts(108_535_000, 35499) + .saturating_add(T::DbWeight::get().reads(7_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) + } + /// Storage: `Afloat::AfloatOffers` (r:1 w:1) + /// Proof: `Afloat::AfloatOffers` (`max_values`: None, `max_size`: Some(3349), added: 5824, mode: `MaxEncodedLen`) + /// Storage: `RBAC::Scopes` (r:1 w:0) + /// Proof: `RBAC::Scopes` (`max_values`: None, `max_size`: Some(32034), added: 34509, mode: `MaxEncodedLen`) + /// Storage: `RBAC::RolesByUser` (r:1 w:0) + /// Proof: `RBAC::RolesByUser` (`max_values`: None, `max_size`: Some(433), added: 2908, mode: `MaxEncodedLen`) + /// Storage: `Timestamp::Now` (r:1 w:0) + /// Proof: `Timestamp::Now` (`max_values`: Some(1), `max_size`: Some(8), added: 503, mode: `MaxEncodedLen`) + fn cancel_offer() -> Weight { + // Proof Size summary in bytes: + // Measured: `1117` + // Estimated: `35499` + // Minimum execution time: 50_705_000 picoseconds. + Weight::from_parts(51_892_000, 35499) + .saturating_add(T::DbWeight::get().reads(4_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: `RBAC::Scopes` (r:2 w:0) + /// Proof: `RBAC::Scopes` (`max_values`: None, `max_size`: Some(32034), added: 34509, mode: `MaxEncodedLen`) + /// Storage: `RBAC::RolesByUser` (r:3 w:2) + /// Proof: `RBAC::RolesByUser` (`max_values`: None, `max_size`: Some(433), added: 2908, mode: `MaxEncodedLen`) + /// Storage: `Afloat::UserInfo` (r:1 w:0) + /// Proof: `Afloat::UserInfo` (`max_values`: None, `max_size`: Some(300), added: 2775, mode: `MaxEncodedLen`) + /// Storage: `RBAC::PalletRoles` (r:2 w:0) + /// Proof: `RBAC::PalletRoles` (`max_values`: None, `max_size`: Some(1633), added: 4108, mode: `MaxEncodedLen`) + /// Storage: `RBAC::UsersByScope` (r:2 w:2) + /// Proof: `RBAC::UsersByScope` (`max_values`: None, `max_size`: Some(80098), added: 82573, mode: `MaxEncodedLen`) + /// Storage: `Afloat::AfloatCollectionId` (r:1 w:0) + /// Proof: `Afloat::AfloatCollectionId` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + fn add_afloat_admin() -> Weight { + // Proof Size summary in bytes: + // Measured: `2217` + // Estimated: `166136` + // Minimum execution time: 117_754_000 picoseconds. + Weight::from_parts(126_623_000, 166136) + .saturating_add(T::DbWeight::get().reads(11_u64)) + .saturating_add(T::DbWeight::get().writes(4_u64)) + } + /// Storage: `RBAC::Scopes` (r:1 w:0) + /// Proof: `RBAC::Scopes` (`max_values`: None, `max_size`: Some(32034), added: 34509, mode: `MaxEncodedLen`) + /// Storage: `RBAC::RolesByUser` (r:2 w:1) + /// Proof: `RBAC::RolesByUser` (`max_values`: None, `max_size`: Some(433), added: 2908, mode: `MaxEncodedLen`) + /// Storage: `Afloat::UserInfo` (r:1 w:0) + /// Proof: `Afloat::UserInfo` (`max_values`: None, `max_size`: Some(300), added: 2775, mode: `MaxEncodedLen`) + /// Storage: `RBAC::PalletRoles` (r:1 w:0) + /// Proof: `RBAC::PalletRoles` (`max_values`: None, `max_size`: Some(1633), added: 4108, mode: `MaxEncodedLen`) + /// Storage: `RBAC::UsersByScope` (r:1 w:1) + /// Proof: `RBAC::UsersByScope` (`max_values`: None, `max_size`: Some(80098), added: 82573, mode: `MaxEncodedLen`) + fn assign_user_to_role() -> Weight { + // Proof Size summary in bytes: + // Measured: `1726` + // Estimated: `83563` + // Minimum execution time: 84_649_000 picoseconds. + Weight::from_parts(87_861_000, 83563) + .saturating_add(T::DbWeight::get().reads(6_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) + } +} + +// For backwards compatibility and tests. +impl WeightInfo for () { + /// Storage: `RBAC::Roles` (r:10 w:10) + /// Proof: `RBAC::Roles` (`max_values`: None, `max_size`: Some(83), added: 2558, mode: `MaxEncodedLen`) + /// Storage: `RBAC::PalletRoles` (r:3 w:3) + /// Proof: `RBAC::PalletRoles` (`max_values`: None, `max_size`: Some(1633), added: 4108, mode: `MaxEncodedLen`) + /// Storage: `RBAC::Permissions` (r:23 w:23) + /// Proof: `RBAC::Permissions` (`max_values`: None, `max_size`: Some(115), added: 2590, mode: `MaxEncodedLen`) + /// Storage: `RBAC::PermissionsByRole` (r:10 w:10) + /// Proof: `RBAC::PermissionsByRole` (`max_values`: None, `max_size`: Some(3266), added: 5741, mode: `MaxEncodedLen`) + /// Storage: `Fruniques::NextCollection` (r:1 w:1) + /// Proof: `Fruniques::NextCollection` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `RBAC::Scopes` (r:3 w:3) + /// Proof: `RBAC::Scopes` (`max_values`: None, `max_size`: Some(32034), added: 34509, mode: `MaxEncodedLen`) + /// Storage: `RBAC::RolesByUser` (r:6 w:6) + /// Proof: `RBAC::RolesByUser` (`max_values`: None, `max_size`: Some(433), added: 2908, mode: `MaxEncodedLen`) + /// Storage: `RBAC::UsersByScope` (r:6 w:6) + /// Proof: `RBAC::UsersByScope` (`max_values`: None, `max_size`: Some(80098), added: 82573, mode: `MaxEncodedLen`) + /// Storage: `Uniques::Class` (r:1 w:1) + /// Proof: `Uniques::Class` (`max_values`: None, `max_size`: Some(178), added: 2653, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// Storage: `Uniques::ClassMetadataOf` (r:1 w:1) + /// Proof: `Uniques::ClassMetadataOf` (`max_values`: None, `max_size`: Some(88), added: 2563, mode: `MaxEncodedLen`) + /// Storage: `MappedAssets::Asset` (r:1 w:1) + /// Proof: `MappedAssets::Asset` (`max_values`: None, `max_size`: Some(210), added: 2685, mode: `MaxEncodedLen`) + /// Storage: `GatedMarketplace::Marketplaces` (r:1 w:1) + /// Proof: `GatedMarketplace::Marketplaces` (`max_values`: None, `max_size`: Some(109), added: 2584, mode: `MaxEncodedLen`) + /// Storage: `Timestamp::Now` (r:1 w:0) + /// Proof: `Timestamp::Now` (`max_values`: Some(1), `max_size`: Some(8), added: 503, mode: `MaxEncodedLen`) + /// Storage: `Uniques::ClassAccount` (r:0 w:1) + /// Proof: `Uniques::ClassAccount` (`max_values`: None, `max_size`: Some(68), added: 2543, mode: `MaxEncodedLen`) + /// Storage: `Afloat::UserInfo` (r:0 w:2) + /// Proof: `Afloat::UserInfo` (`max_values`: None, `max_size`: Some(300), added: 2775, mode: `MaxEncodedLen`) + /// Storage: `Afloat::AfloatMarketPlaceId` (r:0 w:1) + /// Proof: `Afloat::AfloatMarketPlaceId` (`max_values`: Some(1), `max_size`: Some(32), added: 527, mode: `MaxEncodedLen`) + /// Storage: `Afloat::AfloatAssetId` (r:0 w:1) + /// Proof: `Afloat::AfloatAssetId` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `Afloat::AfloatCollectionId` (r:0 w:1) + /// Proof: `Afloat::AfloatCollectionId` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + fn initial_setup() -> Weight { + // Proof Size summary in bytes: + // Measured: `450` + // Estimated: `496428` + // Minimum execution time: 961_583_000 picoseconds. + Weight::from_parts(994_270_000, 496428) + .saturating_add(RocksDbWeight::get().reads(68_u64)) + .saturating_add(RocksDbWeight::get().writes(73_u64)) + } + /// Storage: `Afloat::UserInfo` (r:3 w:0) + /// Proof: `Afloat::UserInfo` (`max_values`: None, `max_size`: Some(300), added: 2775, mode: `MaxEncodedLen`) + /// Storage: `RBAC::Scopes` (r:1 w:1) + /// Proof: `RBAC::Scopes` (`max_values`: None, `max_size`: Some(32034), added: 34509, mode: `MaxEncodedLen`) + /// Storage: `RBAC::RolesByUser` (r:2 w:2) + /// Proof: `RBAC::RolesByUser` (`max_values`: None, `max_size`: Some(433), added: 2908, mode: `MaxEncodedLen`) + /// Storage: `RBAC::UsersByScope` (r:3 w:2) + /// Proof: `RBAC::UsersByScope` (`max_values`: None, `max_size`: Some(80098), added: 82573, mode: `MaxEncodedLen`) + /// Storage: `RBAC::PalletRoles` (r:4 w:1) + /// Proof: `RBAC::PalletRoles` (`max_values`: None, `max_size`: Some(1633), added: 4108, mode: `MaxEncodedLen`) + /// Storage: `RBAC::PermissionsByRole` (r:2 w:2) + /// Proof: `RBAC::PermissionsByRole` (`max_values`: None, `max_size`: Some(3266), added: 5741, mode: `MaxEncodedLen`) + /// Storage: `RBAC::Permissions` (r:3 w:3) + /// Proof: `RBAC::Permissions` (`max_values`: None, `max_size`: Some(115), added: 2590, mode: `MaxEncodedLen`) + /// Storage: `Afloat::AfloatMarketPlaceId` (r:0 w:1) + /// Proof: `Afloat::AfloatMarketPlaceId` (`max_values`: Some(1), `max_size`: Some(32), added: 527, mode: `MaxEncodedLen`) + /// Storage: `Afloat::AfloatAssetId` (r:0 w:1) + /// Proof: `Afloat::AfloatAssetId` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `Afloat::AfloatCollectionId` (r:0 w:1) + /// Proof: `Afloat::AfloatCollectionId` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `RBAC::Roles` (r:0 w:2) + /// Proof: `RBAC::Roles` (`max_values`: None, `max_size`: Some(83), added: 2558, mode: `MaxEncodedLen`) + fn kill_storage() -> Weight { + // Proof Size summary in bytes: + // Measured: `3033` + // Estimated: `248709` + // Minimum execution time: 177_538_000 picoseconds. + Weight::from_parts(188_364_000, 248709) + .saturating_add(RocksDbWeight::get().reads(18_u64)) + .saturating_add(RocksDbWeight::get().writes(16_u64)) + } + /// Storage: `Afloat::UserInfo` (r:1 w:1) + /// Proof: `Afloat::UserInfo` (`max_values`: None, `max_size`: Some(300), added: 2775, mode: `MaxEncodedLen`) + /// Storage: `Timestamp::Now` (r:1 w:0) + /// Proof: `Timestamp::Now` (`max_values`: Some(1), `max_size`: Some(8), added: 503, mode: `MaxEncodedLen`) + /// Storage: `RBAC::Scopes` (r:3 w:0) + /// Proof: `RBAC::Scopes` (`max_values`: None, `max_size`: Some(32034), added: 34509, mode: `MaxEncodedLen`) + /// Storage: `RBAC::PalletRoles` (r:3 w:0) + /// Proof: `RBAC::PalletRoles` (`max_values`: None, `max_size`: Some(1633), added: 4108, mode: `MaxEncodedLen`) + /// Storage: `RBAC::RolesByUser` (r:3 w:3) + /// Proof: `RBAC::RolesByUser` (`max_values`: None, `max_size`: Some(433), added: 2908, mode: `MaxEncodedLen`) + /// Storage: `RBAC::UsersByScope` (r:6 w:3) + /// Proof: `RBAC::UsersByScope` (`max_values`: None, `max_size`: Some(80098), added: 82573, mode: `MaxEncodedLen`) + /// Storage: `Afloat::AfloatMarketPlaceId` (r:1 w:0) + /// Proof: `Afloat::AfloatMarketPlaceId` (`max_values`: Some(1), `max_size`: Some(32), added: 527, mode: `MaxEncodedLen`) + /// Storage: `Afloat::AfloatCollectionId` (r:1 w:0) + /// Proof: `Afloat::AfloatCollectionId` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `GatedMarketplace::BlockedUsersByMarketplace` (r:1 w:0) + /// Proof: `GatedMarketplace::BlockedUsersByMarketplace` (`max_values`: None, `max_size`: Some(3234), added: 5709, mode: `MaxEncodedLen`) + /// Storage: `GatedMarketplace::Marketplaces` (r:1 w:0) + /// Proof: `GatedMarketplace::Marketplaces` (`max_values`: None, `max_size`: Some(109), added: 2584, mode: `MaxEncodedLen`) + fn sign_up() -> Weight { + // Proof Size summary in bytes: + // Measured: `2158` + // Estimated: `496428` + // Minimum execution time: 180_891_000 picoseconds. + Weight::from_parts(196_745_000, 496428) + .saturating_add(RocksDbWeight::get().reads(21_u64)) + .saturating_add(RocksDbWeight::get().writes(7_u64)) + } + /// Storage: `RBAC::Scopes` (r:1 w:0) + /// Proof: `RBAC::Scopes` (`max_values`: None, `max_size`: Some(32034), added: 34509, mode: `MaxEncodedLen`) + /// Storage: `RBAC::RolesByUser` (r:1 w:0) + /// Proof: `RBAC::RolesByUser` (`max_values`: None, `max_size`: Some(433), added: 2908, mode: `MaxEncodedLen`) + /// Storage: `Afloat::UserInfo` (r:1 w:1) + /// Proof: `Afloat::UserInfo` (`max_values`: None, `max_size`: Some(300), added: 2775, mode: `MaxEncodedLen`) + /// Storage: `Timestamp::Now` (r:1 w:0) + /// Proof: `Timestamp::Now` (`max_values`: Some(1), `max_size`: Some(8), added: 503, mode: `MaxEncodedLen`) + fn update_user_info() -> Weight { + // Proof Size summary in bytes: + // Measured: `1159` + // Estimated: `35499` + // Minimum execution time: 51_055_000 picoseconds. + Weight::from_parts(57_131_000, 35499) + .saturating_add(RocksDbWeight::get().reads(4_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) + } + /// Storage: `RBAC::RolesByUser` (r:1 w:0) + /// Proof: `RBAC::RolesByUser` (`max_values`: None, `max_size`: Some(433), added: 2908, mode: `MaxEncodedLen`) + /// Storage: `Afloat::AfloatCollectionId` (r:1 w:0) + /// Proof: `Afloat::AfloatCollectionId` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `Uniques::Class` (r:1 w:1) + /// Proof: `Uniques::Class` (`max_values`: None, `max_size`: Some(178), added: 2653, mode: `MaxEncodedLen`) + /// Storage: `Fruniques::NextFrunique` (r:1 w:1) + /// Proof: `Fruniques::NextFrunique` (`max_values`: None, `max_size`: Some(24), added: 2499, mode: `MaxEncodedLen`) + /// Storage: `Uniques::Asset` (r:2 w:1) + /// Proof: `Uniques::Asset` (`max_values`: None, `max_size`: Some(122), added: 2597, mode: `MaxEncodedLen`) + /// Storage: `Uniques::CollectionMaxSupply` (r:1 w:0) + /// Proof: `Uniques::CollectionMaxSupply` (`max_values`: None, `max_size`: Some(24), added: 2499, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// Storage: `Uniques::InstanceMetadataOf` (r:1 w:1) + /// Proof: `Uniques::InstanceMetadataOf` (`max_values`: None, `max_size`: Some(108), added: 2583, mode: `MaxEncodedLen`) + /// Storage: `Uniques::Attribute` (r:1 w:1) + /// Proof: `Uniques::Attribute` (`max_values`: None, `max_size`: Some(364), added: 2839, mode: `MaxEncodedLen`) + /// Storage: `Fruniques::FruniqueInfo` (r:1 w:2) + /// Proof: `Fruniques::FruniqueInfo` (`max_values`: None, `max_size`: Some(505), added: 2980, mode: `MaxEncodedLen`) + /// Storage: `Uniques::Account` (r:0 w:1) + /// Proof: `Uniques::Account` (`max_values`: None, `max_size`: Some(88), added: 2563, mode: `MaxEncodedLen`) + /// The range of component `a` is `[0, 200]`. + fn create_tax_credit(a: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `1886` + // Estimated: `6184` + // Minimum execution time: 149_182_000 picoseconds. + Weight::from_parts(110_726_535, 6184) + // Standard Error: 45_795 + .saturating_add(Weight::from_parts(28_739_579, 0).saturating_mul(a.into())) + .saturating_add(RocksDbWeight::get().reads(11_u64)) + .saturating_add(RocksDbWeight::get().writes(9_u64)) + } + /// Storage: `RBAC::RolesByUser` (r:1 w:0) + /// Proof: `RBAC::RolesByUser` (`max_values`: None, `max_size`: Some(433), added: 2908, mode: `MaxEncodedLen`) + /// Storage: `Timestamp::Now` (r:1 w:0) + /// Proof: `Timestamp::Now` (`max_values`: Some(1), `max_size`: Some(8), added: 503, mode: `MaxEncodedLen`) + /// Storage: `Afloat::AfloatOffers` (r:0 w:1) + /// Proof: `Afloat::AfloatOffers` (`max_values`: None, `max_size`: Some(3349), added: 5824, mode: `MaxEncodedLen`) + fn create_offer() -> Weight { + // Proof Size summary in bytes: + // Measured: `563` + // Estimated: `3898` + // Minimum execution time: 40_089_000 picoseconds. + Weight::from_parts(42_324_000, 3898) + .saturating_add(RocksDbWeight::get().reads(2_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) + } + /// Storage: `RBAC::RolesByUser` (r:1 w:0) + /// Proof: `RBAC::RolesByUser` (`max_values`: None, `max_size`: Some(433), added: 2908, mode: `MaxEncodedLen`) + /// Storage: `Afloat::AfloatOffers` (r:1 w:1) + /// Proof: `Afloat::AfloatOffers` (`max_values`: None, `max_size`: Some(3349), added: 5824, mode: `MaxEncodedLen`) + /// Storage: `Timestamp::Now` (r:1 w:0) + /// Proof: `Timestamp::Now` (`max_values`: Some(1), `max_size`: Some(8), added: 503, mode: `MaxEncodedLen`) + /// Storage: `Afloat::AfloatAssetId` (r:1 w:0) + /// Proof: `Afloat::AfloatAssetId` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `MappedAssets::Account` (r:1 w:0) + /// Proof: `MappedAssets::Account` (`max_values`: None, `max_size`: Some(134), added: 2609, mode: `MaxEncodedLen`) + /// Storage: `Afloat::AfloatTransactions` (r:0 w:1) + /// Proof: `Afloat::AfloatTransactions` (`max_values`: None, `max_size`: Some(283), added: 2758, mode: `MaxEncodedLen`) + fn start_take_sell_order() -> Weight { + // Proof Size summary in bytes: + // Measured: `1278` + // Estimated: `6814` + // Minimum execution time: 60_833_000 picoseconds. + Weight::from_parts(63_417_000, 6814) + .saturating_add(RocksDbWeight::get().reads(5_u64)) + .saturating_add(RocksDbWeight::get().writes(2_u64)) + } + /// Storage: `RBAC::RolesByUser` (r:2 w:0) + /// Proof: `RBAC::RolesByUser` (`max_values`: None, `max_size`: Some(433), added: 2908, mode: `MaxEncodedLen`) + /// Storage: `Afloat::AfloatTransactions` (r:1 w:1) + /// Proof: `Afloat::AfloatTransactions` (`max_values`: None, `max_size`: Some(283), added: 2758, mode: `MaxEncodedLen`) + /// Storage: `Timestamp::Now` (r:1 w:0) + /// Proof: `Timestamp::Now` (`max_values`: Some(1), `max_size`: Some(8), added: 503, mode: `MaxEncodedLen`) + /// Storage: `Afloat::AfloatMarketPlaceId` (r:1 w:0) + /// Proof: `Afloat::AfloatMarketPlaceId` (`max_values`: Some(1), `max_size`: Some(32), added: 527, mode: `MaxEncodedLen`) + /// Storage: `Afloat::AfloatCollectionId` (r:1 w:0) + /// Proof: `Afloat::AfloatCollectionId` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `GatedMarketplace::Marketplaces` (r:1 w:0) + /// Proof: `GatedMarketplace::Marketplaces` (`max_values`: None, `max_size`: Some(109), added: 2584, mode: `MaxEncodedLen`) + /// Storage: `RBAC::Scopes` (r:1 w:0) + /// Proof: `RBAC::Scopes` (`max_values`: None, `max_size`: Some(32034), added: 34509, mode: `MaxEncodedLen`) + /// Storage: `RBAC::Permissions` (r:1 w:0) + /// Proof: `RBAC::Permissions` (`max_values`: None, `max_size`: Some(115), added: 2590, mode: `MaxEncodedLen`) + /// Storage: `RBAC::PermissionsByRole` (r:1 w:0) + /// Proof: `RBAC::PermissionsByRole` (`max_values`: None, `max_size`: Some(3266), added: 5741, mode: `MaxEncodedLen`) + /// Storage: `Uniques::Asset` (r:1 w:0) + /// Proof: `Uniques::Asset` (`max_values`: None, `max_size`: Some(122), added: 2597, mode: `MaxEncodedLen`) + /// Storage: `GatedMarketplace::OffersByItem` (r:1 w:1) + /// Proof: `GatedMarketplace::OffersByItem` (`max_values`: None, `max_size`: Some(3242), added: 5717, mode: `MaxEncodedLen`) + /// Storage: `GatedMarketplace::OffersByAccount` (r:1 w:1) + /// Proof: `GatedMarketplace::OffersByAccount` (`max_values`: None, `max_size`: Some(3250), added: 5725, mode: `MaxEncodedLen`) + /// Storage: `GatedMarketplace::OffersInfo` (r:1 w:1) + /// Proof: `GatedMarketplace::OffersInfo` (`max_values`: None, `max_size`: Some(215), added: 2690, mode: `MaxEncodedLen`) + /// Storage: `GatedMarketplace::OffersByMarketplace` (r:1 w:1) + /// Proof: `GatedMarketplace::OffersByMarketplace` (`max_values`: None, `max_size`: Some(3234), added: 5709, mode: `MaxEncodedLen`) + /// Storage: `Fruniques::FruniqueInfo` (r:1 w:1) + /// Proof: `Fruniques::FruniqueInfo` (`max_values`: None, `max_size`: Some(505), added: 2980, mode: `MaxEncodedLen`) + fn confirm_sell_transaction() -> Weight { + // Proof Size summary in bytes: + // Measured: `3022` + // Estimated: `35499` + // Minimum execution time: 139_684_000 picoseconds. + Weight::from_parts(146_528_000, 35499) + .saturating_add(RocksDbWeight::get().reads(16_u64)) + .saturating_add(RocksDbWeight::get().writes(6_u64)) + } + /// Storage: `RBAC::RolesByUser` (r:2 w:0) + /// Proof: `RBAC::RolesByUser` (`max_values`: None, `max_size`: Some(433), added: 2908, mode: `MaxEncodedLen`) + /// Storage: `Afloat::AfloatTransactions` (r:1 w:1) + /// Proof: `Afloat::AfloatTransactions` (`max_values`: None, `max_size`: Some(283), added: 2758, mode: `MaxEncodedLen`) + /// Storage: `GatedMarketplace::OffersInfo` (r:1 w:1) + /// Proof: `GatedMarketplace::OffersInfo` (`max_values`: None, `max_size`: Some(215), added: 2690, mode: `MaxEncodedLen`) + /// Storage: `RBAC::Scopes` (r:1 w:0) + /// Proof: `RBAC::Scopes` (`max_values`: None, `max_size`: Some(32034), added: 34509, mode: `MaxEncodedLen`) + /// Storage: `RBAC::Permissions` (r:1 w:0) + /// Proof: `RBAC::Permissions` (`max_values`: None, `max_size`: Some(115), added: 2590, mode: `MaxEncodedLen`) + /// Storage: `RBAC::PermissionsByRole` (r:1 w:0) + /// Proof: `RBAC::PermissionsByRole` (`max_values`: None, `max_size`: Some(3266), added: 5741, mode: `MaxEncodedLen`) + /// Storage: `Uniques::Asset` (r:2 w:1) + /// Proof: `Uniques::Asset` (`max_values`: None, `max_size`: Some(122), added: 2597, mode: `MaxEncodedLen`) + /// Storage: `GatedMarketplace::OffersByItem` (r:1 w:1) + /// Proof: `GatedMarketplace::OffersByItem` (`max_values`: None, `max_size`: Some(3242), added: 5717, mode: `MaxEncodedLen`) + /// Storage: `GatedMarketplace::Marketplaces` (r:1 w:0) + /// Proof: `GatedMarketplace::Marketplaces` (`max_values`: None, `max_size`: Some(109), added: 2584, mode: `MaxEncodedLen`) + /// Storage: `MappedAssets::Account` (r:3 w:3) + /// Proof: `MappedAssets::Account` (`max_values`: None, `max_size`: Some(134), added: 2609, mode: `MaxEncodedLen`) + /// Storage: `MappedAssets::Asset` (r:1 w:1) + /// Proof: `MappedAssets::Asset` (`max_values`: None, `max_size`: Some(210), added: 2685, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:2 w:2) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// Storage: `Fruniques::FruniqueInfo` (r:1 w:2) + /// Proof: `Fruniques::FruniqueInfo` (`max_values`: None, `max_size`: Some(505), added: 2980, mode: `MaxEncodedLen`) + /// Storage: `Uniques::Class` (r:1 w:1) + /// Proof: `Uniques::Class` (`max_values`: None, `max_size`: Some(178), added: 2653, mode: `MaxEncodedLen`) + /// Storage: `Fruniques::NextFrunique` (r:1 w:1) + /// Proof: `Fruniques::NextFrunique` (`max_values`: None, `max_size`: Some(24), added: 2499, mode: `MaxEncodedLen`) + /// Storage: `Uniques::CollectionMaxSupply` (r:1 w:0) + /// Proof: `Uniques::CollectionMaxSupply` (`max_values`: None, `max_size`: Some(24), added: 2499, mode: `MaxEncodedLen`) + /// Storage: `Uniques::InstanceMetadataOf` (r:1 w:1) + /// Proof: `Uniques::InstanceMetadataOf` (`max_values`: None, `max_size`: Some(108), added: 2583, mode: `MaxEncodedLen`) + /// Storage: `Afloat::AfloatOffers` (r:1 w:1) + /// Proof: `Afloat::AfloatOffers` (`max_values`: None, `max_size`: Some(3349), added: 5824, mode: `MaxEncodedLen`) + /// Storage: `Uniques::Account` (r:0 w:1) + /// Proof: `Uniques::Account` (`max_values`: None, `max_size`: Some(88), added: 2563, mode: `MaxEncodedLen`) + fn finish_take_sell_transaction() -> Weight { + // Proof Size summary in bytes: + // Measured: `4512` + // Estimated: `35499` + // Minimum execution time: 349_210_000 picoseconds. + Weight::from_parts(362_549_000, 35499) + .saturating_add(RocksDbWeight::get().reads(23_u64)) + .saturating_add(RocksDbWeight::get().writes(17_u64)) + } + /// Storage: `RBAC::Scopes` (r:1 w:0) + /// Proof: `RBAC::Scopes` (`max_values`: None, `max_size`: Some(32034), added: 34509, mode: `MaxEncodedLen`) + /// Storage: `RBAC::RolesByUser` (r:1 w:0) + /// Proof: `RBAC::RolesByUser` (`max_values`: None, `max_size`: Some(433), added: 2908, mode: `MaxEncodedLen`) + /// Storage: `Afloat::AfloatAssetId` (r:1 w:0) + /// Proof: `Afloat::AfloatAssetId` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `Afloat::UserInfo` (r:1 w:0) + /// Proof: `Afloat::UserInfo` (`max_values`: None, `max_size`: Some(300), added: 2775, mode: `MaxEncodedLen`) + /// Storage: `MappedAssets::Account` (r:1 w:1) + /// Proof: `MappedAssets::Account` (`max_values`: None, `max_size`: Some(134), added: 2609, mode: `MaxEncodedLen`) + /// Storage: `MappedAssets::Asset` (r:1 w:1) + /// Proof: `MappedAssets::Asset` (`max_values`: None, `max_size`: Some(210), added: 2685, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + fn set_afloat_balance() -> Weight { + // Proof Size summary in bytes: + // Measured: `1606` + // Estimated: `35499` + // Minimum execution time: 100_503_000 picoseconds. + Weight::from_parts(108_535_000, 35499) + .saturating_add(RocksDbWeight::get().reads(7_u64)) + .saturating_add(RocksDbWeight::get().writes(3_u64)) + } + /// Storage: `Afloat::AfloatOffers` (r:1 w:1) + /// Proof: `Afloat::AfloatOffers` (`max_values`: None, `max_size`: Some(3349), added: 5824, mode: `MaxEncodedLen`) + /// Storage: `RBAC::Scopes` (r:1 w:0) + /// Proof: `RBAC::Scopes` (`max_values`: None, `max_size`: Some(32034), added: 34509, mode: `MaxEncodedLen`) + /// Storage: `RBAC::RolesByUser` (r:1 w:0) + /// Proof: `RBAC::RolesByUser` (`max_values`: None, `max_size`: Some(433), added: 2908, mode: `MaxEncodedLen`) + /// Storage: `Timestamp::Now` (r:1 w:0) + /// Proof: `Timestamp::Now` (`max_values`: Some(1), `max_size`: Some(8), added: 503, mode: `MaxEncodedLen`) + fn cancel_offer() -> Weight { + // Proof Size summary in bytes: + // Measured: `1117` + // Estimated: `35499` + // Minimum execution time: 50_705_000 picoseconds. + Weight::from_parts(51_892_000, 35499) + .saturating_add(RocksDbWeight::get().reads(4_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) + } + /// Storage: `RBAC::Scopes` (r:2 w:0) + /// Proof: `RBAC::Scopes` (`max_values`: None, `max_size`: Some(32034), added: 34509, mode: `MaxEncodedLen`) + /// Storage: `RBAC::RolesByUser` (r:3 w:2) + /// Proof: `RBAC::RolesByUser` (`max_values`: None, `max_size`: Some(433), added: 2908, mode: `MaxEncodedLen`) + /// Storage: `Afloat::UserInfo` (r:1 w:0) + /// Proof: `Afloat::UserInfo` (`max_values`: None, `max_size`: Some(300), added: 2775, mode: `MaxEncodedLen`) + /// Storage: `RBAC::PalletRoles` (r:2 w:0) + /// Proof: `RBAC::PalletRoles` (`max_values`: None, `max_size`: Some(1633), added: 4108, mode: `MaxEncodedLen`) + /// Storage: `RBAC::UsersByScope` (r:2 w:2) + /// Proof: `RBAC::UsersByScope` (`max_values`: None, `max_size`: Some(80098), added: 82573, mode: `MaxEncodedLen`) + /// Storage: `Afloat::AfloatCollectionId` (r:1 w:0) + /// Proof: `Afloat::AfloatCollectionId` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + fn add_afloat_admin() -> Weight { + // Proof Size summary in bytes: + // Measured: `2217` + // Estimated: `166136` + // Minimum execution time: 117_754_000 picoseconds. + Weight::from_parts(126_623_000, 166136) + .saturating_add(RocksDbWeight::get().reads(11_u64)) + .saturating_add(RocksDbWeight::get().writes(4_u64)) + } + /// Storage: `RBAC::Scopes` (r:1 w:0) + /// Proof: `RBAC::Scopes` (`max_values`: None, `max_size`: Some(32034), added: 34509, mode: `MaxEncodedLen`) + /// Storage: `RBAC::RolesByUser` (r:2 w:1) + /// Proof: `RBAC::RolesByUser` (`max_values`: None, `max_size`: Some(433), added: 2908, mode: `MaxEncodedLen`) + /// Storage: `Afloat::UserInfo` (r:1 w:0) + /// Proof: `Afloat::UserInfo` (`max_values`: None, `max_size`: Some(300), added: 2775, mode: `MaxEncodedLen`) + /// Storage: `RBAC::PalletRoles` (r:1 w:0) + /// Proof: `RBAC::PalletRoles` (`max_values`: None, `max_size`: Some(1633), added: 4108, mode: `MaxEncodedLen`) + /// Storage: `RBAC::UsersByScope` (r:1 w:1) + /// Proof: `RBAC::UsersByScope` (`max_values`: None, `max_size`: Some(80098), added: 82573, mode: `MaxEncodedLen`) + fn assign_user_to_role() -> Weight { + // Proof Size summary in bytes: + // Measured: `1726` + // Estimated: `83563` + // Minimum execution time: 84_649_000 picoseconds. + Weight::from_parts(87_861_000, 83563) + .saturating_add(RocksDbWeight::get().reads(6_u64)) + .saturating_add(RocksDbWeight::get().writes(2_u64)) + } +} diff --git a/pallets/fruniques/src/lib.rs b/pallets/fruniques/src/lib.rs index 785aca56..3c1cf990 100644 --- a/pallets/fruniques/src/lib.rs +++ b/pallets/fruniques/src/lib.rs @@ -42,6 +42,10 @@ pub mod pallet { #[pallet::constant] type MaxParentsInCollection: Get; + /// Maximum number of attributes + #[pallet::constant] + type MaxAttributes: Get; + /// The fruniques pallet id, used for deriving its sovereign account ID. // #[pallet::constant] // type PalletId: Get; diff --git a/pallets/fruniques/src/mock.rs b/pallets/fruniques/src/mock.rs index 77daab35..8b8e986e 100644 --- a/pallets/fruniques/src/mock.rs +++ b/pallets/fruniques/src/mock.rs @@ -24,6 +24,7 @@ parameter_types! { pub const BlockHashCount: u64 = 250; pub const ChildMaxLen: u32 = 10; pub const MaxParentsInCollection: u32 = 100; + pub const MaxAttributes : u32 = 10; } impl frame_system::Config for Test { @@ -57,6 +58,7 @@ impl pallet_fruniques::Config for Test { type RemoveOrigin = EnsureRoot; type ChildMaxLen = ChildMaxLen; type MaxParentsInCollection = MaxParentsInCollection; + type MaxAttributes = MaxAttributes; type Rbac = RBAC; } @@ -126,6 +128,7 @@ impl pallet_rbac::Config for Test { type MaxRolesPerUser = MaxRolesPerUser; type MaxUsersPerRole = MaxUsersPerRole; type RemoveOrigin = EnsureRoot; + type WeightInfo = (); } // Build genesis storage according to the mock runtime. // pub(crate) fn new_test_ext() -> sp_io::TestExternalities { diff --git a/pallets/fruniques/src/tests.rs b/pallets/fruniques/src/tests.rs index f78281b2..aa903590 100644 --- a/pallets/fruniques/src/tests.rs +++ b/pallets/fruniques/src/tests.rs @@ -37,17 +37,20 @@ fn dummy_description() -> BoundedVec { BoundedVec::::try_from(b"dummy description".to_vec()).unwrap() } -fn dummy_attributes() -> Vec<(BoundedVec, BoundedVec)> { - vec![( +fn dummy_attributes( +) -> BoundedVec<(BoundedVec, BoundedVec), MaxAttributes> { + BoundedVec::<_, _>::try_from(vec![( BoundedVec::::try_from(b"dummy key".encode()) .expect("Error on encoding key to BoundedVec"), BoundedVec::::try_from(b"dummy value".encode()) .expect("Error on encoding value to BoundedVec"), - )] + )]) + .unwrap() } -fn dummy_empty_attributes() -> Vec<(BoundedVec, BoundedVec)> { - vec![] +fn dummy_empty_attributes( +) -> BoundedVec<(BoundedVec, BoundedVec), MaxAttributes> { + BoundedVec::<_, _>::try_from(vec![]).unwrap() } fn dummy_parent(collection_id: u32, parent_id: u32) -> ParentInfoCall { diff --git a/pallets/fruniques/src/types.rs b/pallets/fruniques/src/types.rs index bc2ca6c5..428106b1 100644 --- a/pallets/fruniques/src/types.rs +++ b/pallets/fruniques/src/types.rs @@ -7,7 +7,9 @@ use sp_runtime::{sp_std::vec::Vec, Permill}; pub type AttributeKey = BoundedVec::KeyLimit>; pub type AttributeValue = BoundedVec::ValueLimit>; -pub type Attributes = Vec<(AttributeKey, AttributeValue)>; +// pub type Attributes = Vec<(AttributeKey, AttributeValue)>; +pub type Attributes = + BoundedVec<(AttributeKey, AttributeValue), ::MaxAttributes>; pub type Children = BoundedVec, ::ChildMaxLen>; pub type StringLimit = BoundedVec::StringLimit>; diff --git a/pallets/gated-marketplace/src/mock.rs b/pallets/gated-marketplace/src/mock.rs index 00125cc0..6ce97d96 100644 --- a/pallets/gated-marketplace/src/mock.rs +++ b/pallets/gated-marketplace/src/mock.rs @@ -105,6 +105,7 @@ impl pallet_gated_marketplace::Config for Test { parameter_types! { pub const ChildMaxLen: u32 = 10; pub const MaxParentsInCollection: u32 = 10; + pub const MaxAttributes: u32 = 10; } impl pallet_fruniques::Config for Test { @@ -113,6 +114,7 @@ impl pallet_fruniques::Config for Test { type ChildMaxLen = ChildMaxLen; type MaxParentsInCollection = MaxParentsInCollection; type Rbac = RBAC; + type MaxAttributes = MaxAttributes; } parameter_types! { diff --git a/pallets/mapped-assets/src/mock.rs b/pallets/mapped-assets/src/mock.rs index 8c7761af..61d5fb0a 100644 --- a/pallets/mapped-assets/src/mock.rs +++ b/pallets/mapped-assets/src/mock.rs @@ -94,6 +94,7 @@ impl pallet_rbac::Config for Test { type MaxPermissionsPerRole = MaxPermissionsPerRole; type MaxRolesPerUser = MaxRolesPerUser; type MaxUsersPerRole = MaxUsersPerRole; + type WeightInfo = (); } impl pallet_balances::Config for Test { From 9667bcc7e59ad8e62690014b1b5a796bfd590411 Mon Sep 17 00:00:00 2001 From: Dreyhh Date: Wed, 3 Apr 2024 18:36:26 -0600 Subject: [PATCH 2/5] Updated afloat benchmarks to use worst-case scenarios of dependent extrinsics from: rbac, gated_marketplace and fruniques --- .vscode/settings.json | 5 +- pallets/afloat/src/benchmarking.rs | 196 ++++++++++++++++++++++++++--- pallets/afloat/src/functions.rs | 4 +- pallets/afloat/src/lib.rs | 4 +- pallets/afloat/src/mock.rs | 2 +- pallets/rbac/src/functions.rs | 2 + pallets/rbac/src/types.rs | 1 + 7 files changed, 192 insertions(+), 22 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index d0445d23..60cb534e 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,6 +1,9 @@ { "rust-analyzer.linkedProjects": [ - "./pallets/afloat/Cargo.toml" + "./pallets/afloat/Cargo.toml", + "./pallets/rbac/Cargo.toml", + "./pallets/gated-marketplace/Cargo.toml", + "./pallets/fruniques/Cargo.toml", ], "rust-analyzer.showUnlinkedFileNotification": false } \ No newline at end of file diff --git a/pallets/afloat/src/benchmarking.rs b/pallets/afloat/src/benchmarking.rs index de5f3898..d7730f0a 100644 --- a/pallets/afloat/src/benchmarking.rs +++ b/pallets/afloat/src/benchmarking.rs @@ -4,6 +4,7 @@ use super::*; use crate::{types::*, Pallet as Afloat}; use frame_benchmarking::v2::*; use frame_support::{ + assert_ok, pallet_prelude::*, traits::{Currency, Get}, }; @@ -15,10 +16,134 @@ type DepositBalanceOf = <::Currency as Cur ::AccountId, >>::Balance; +use pallet_rbac::types::{IdOrVec, RoleBasedAccessControl, RoleId}; +use sp_io::hashing::blake2_256; +use std::cmp; + const SEED: u32 = 0; const MAX_U32: u32 = u32::MAX; const MAX_U64: u64 = u64::MAX; const MAX_TAX_CREDIT_AMOUNT: u32 = 100; +const NUM_AFLOAT_ROLES: u32 = 4; + +pub fn generate_pallet_id_sized(id: u8, size: u32) -> IdOrVec { + IdOrVec::Vec(generate_vector(0, id, size)) +} + +pub fn generate_role_sized(id: u8, size: u32) -> Vec { + generate_vector(1, id, size) +} + +pub fn generate_scope_sized(id: u32, size: u32) -> Vec { + generate_vector((id / u8::MAX as u32) as u8, (id % u8::MAX as u32) as u8, size) +} + +pub fn generate_roles_sized(id: u8, num_roles: u32, size: u32) -> Vec> { + let mut roles = Vec::new(); + for r in 0..num_roles { + roles.push(generate_role_sized(r as u8 + id, size)); + } + roles +} + +pub fn generate_id(item: Vec) -> [u8; 32] { + item.using_encoded(blake2_256) +} + +fn set_rbac_assign_role_to_user_worst_case( + user: ::AccountId, + num_roles_available_user: u32, + inital_setup: bool, +) -> Result<(), sp_runtime::DispatchError> { + // Leave only one Scope available for the pallet + let max_scopes = + <::Rbac as RoleBasedAccessControl>::MaxScopesPerPallet::get( + ) - 1; + let mut scope_ids = Vec::new(); + let pallet_id = Afloat::::pallet_id(); + for s in 0..max_scopes { + let scope = generate_scope_sized(s, 10); + let mut scope_id = generate_id(scope); + assert_ok!( + <::Rbac as RoleBasedAccessControl>::create_scope( + pallet_id.clone(), + scope_id + ) + ); + scope_ids.push(scope_id); + } + // Leave n roles available for the pallet + let num_roles = <::Rbac as RoleBasedAccessControl>::MaxRolesPerPallet::get() - NUM_AFLOAT_ROLES; + let size = + <::Rbac as RoleBasedAccessControl>::RoleMaxLen::get(); + + let roles = generate_roles_sized(1, num_roles, size); + assert_ok!( + <::Rbac as RoleBasedAccessControl>::create_and_set_roles( + pallet_id.clone(), + roles.clone() + ) + ); + + if !inital_setup { + let role_ids: Vec = roles.into_iter().map(|role| generate_id(role)).collect(); + let l = role_ids.len(); + let r = l - num_roles_available_user as usize; + let n = cmp::min(l, r); + let role_ids = &role_ids[0..n]; + let scope_id = Afloat::::scope_id(); + for role_id in role_ids { + assert_ok!(<::Rbac as RoleBasedAccessControl>::assign_role_to_user( + user.clone(), + pallet_id.clone(), + &scope_id, + role_id.clone() + )); + } + } + + Ok(()) +} + +fn set_start_take_sell_offer_worst_case( + user: ::AccountId, + offer_id: [u8; 32], +) -> Result<(), sp_runtime::DispatchError> +where + ::ItemId: From, + ::CollectionId: From, +{ + let max_trxs = TransactionBoundedVec::bound(); + let num_trxs = max_trxs - 1; + + for _ in 0..num_trxs { + Afloat::::start_take_sell_order( + RawOrigin::Signed(user.clone()).into(), + offer_id, + T::AfloatBenchHelper::balance(99), + )?; + } + let offer = AfloatOffers::::get(offer_id).unwrap(); + let offer_trxs = offer.transactions.clone(); + assert_eq!(offer.status, OfferStatus::CREATED); + assert_eq!(offer_trxs.len(), num_trxs); + Ok(()) +} + +fn set_gm_do_enlist_sell_offer_worst_case( + user: T::AccountId, + offer_id: [u8; 32], +) -> Result<(), sp_runtime::DispatchError> +where + ::ItemId: From, + ::CollectionId: From, +{ + let max_offers_by_item = ::MaxOffersPerMarket::get() - 1; + for _ in 0..max_offers_by_item { + add_start_take_sell_order::(user.clone(), offer_id.clone()).unwrap(); + } + Ok(()) +} fn set_max_balance(account: T::AccountId) -> Result<(), sp_runtime::DispatchError> { let max_balance = DepositBalanceOf::::max_value(); @@ -106,6 +231,43 @@ where Afloat::::create_tax_credit(RawOrigin::Signed(user).into(), description, None, None) } +fn set_up_fruniques_do_spawn_worst_case( + user: ::AccountId, +) -> Result<(), sp_runtime::DispatchError> +where + ::ItemId: From, + ::CollectionId: From, +{ + let max_children = ::ChildMaxLen::get() - 1; // since we still want to pass parent info when creating the actual tax credit + let max_attributes = ::MaxAttributes::get(); + for c in 0..max_children { + let attributes = create_sized_attributes::( + max_attributes, + ::KeyLimit::get(), + ::ValueLimit::get(), + ); + let description = + create_sized_description::(::StringLimit::get()); + if c == 0 { + assert_ok!(Afloat::::do_create_tax_credit( + user.clone(), + description, + Some(attributes), + None, + )); + } else { + let parent_info = create_sized_parent_info::(0, 0, MAX_U32, true); + assert_ok!(Afloat::::do_create_tax_credit( + user.clone(), + description, + Some(attributes), + Some(parent_info), + )); + } + } + Ok(()) +} + fn add_sell_order( user: ::AccountId, ) -> Result<[u8; 32], sp_runtime::DispatchError> @@ -136,9 +298,7 @@ where ::CollectionId: From, { let offer = AfloatOffers::::get(offer_id).unwrap(); - let offer_trxs = offer.transactions.clone(); assert_eq!(offer.status, OfferStatus::CREATED); - assert!(offer_trxs.is_empty()); let admin: T::AccountId = account("admin", 0, SEED); Afloat::::set_afloat_balance( RawOrigin::Signed(admin).into(), @@ -146,7 +306,11 @@ where T::Balance::max_value().into(), )?; - Afloat::::start_take_sell_order(RawOrigin::Signed(user).into(), offer_id, 99)?; + Afloat::::start_take_sell_order( + RawOrigin::Signed(user).into(), + offer_id, + T::AfloatBenchHelper::balance(99), + )?; let offer = AfloatOffers::::get(offer_id).unwrap(); let offer_trxs = offer.transactions.clone(); let trx_id = offer_trxs.last().unwrap(); @@ -186,6 +350,7 @@ mod benchmarks { let creator: T::AccountId = account("creator", 0, SEED); set_max_balance::(admin.clone()).unwrap(); set_max_balance::(creator.clone()).unwrap(); + set_rbac_assign_role_to_user_worst_case::(admin.clone(), 0, true).unwrap(); let asset_id: T::AssetId = T::AfloatBenchHelper::asset(0); let min_balance: T::Balance = T::AfloatBenchHelper::balance(1); let asset: CreateAsset = CreateAsset::New { asset_id, min_balance }; @@ -244,17 +409,15 @@ mod benchmarks { ShortString::try_from(generate_vector(0, 1, LSS)).unwrap(); let new_group: ShortString = ShortString::try_from(generate_vector(0, 1, LSS)).unwrap(); - let update_user_info_args = UpdateUserArgs::AdminEdit { - cid: new_cid.clone(), - cid_creator: new_cid_creator, - group: new_group, - }; + let update_user_info_args = UpdateUserArgs::Delete; + + set_rbac_assign_role_to_user_worst_case::(user.clone(), 1, false).unwrap(); let admin: T::AccountId = account("admin", 0, SEED); #[extrinsic_call] _(RawOrigin::Signed(admin.clone()), user.clone(), update_user_info_args); - assert_eq!(Afloat::::user_info(&user).unwrap().cid, new_cid); + assert!(Afloat::::user_info(&user).is_none()); } #[benchmark] @@ -271,13 +434,8 @@ mod benchmarks { let description = create_sized_description::(::StringLimit::get()); let parent_info = create_sized_parent_info::(0, 0, MAX_U32, true); - let _ = Afloat::::create_tax_credit( - RawOrigin::Signed(user.clone()).into(), - description.clone(), - None, - None, - ); assert_eq!(attributes.len() as u32, a); + set_up_fruniques_do_spawn_worst_case::(user.clone()).unwrap(); #[extrinsic_call] _(RawOrigin::Signed(user.clone()), description, Some(attributes), Some(parent_info)); } @@ -321,13 +479,15 @@ mod benchmarks { T::Balance::max_value().into(), ); + set_start_take_sell_offer_worst_case::(other_user.clone(), offer_id.clone()).unwrap(); + #[extrinsic_call] _(RawOrigin::Signed(other_user), offer_id, MAX_U32.into()); let offer = AfloatOffers::::get(offer_id).unwrap(); let offer_trxs = offer.transactions.clone(); assert_eq!(offer.status, OfferStatus::CREATED); - assert_eq!(offer_trxs.len() as u32, 1); + assert_eq!(offer_trxs.len() as u32, 100); } #[benchmark] @@ -346,6 +506,8 @@ mod benchmarks { let transaction = AfloatTransactions::::get(transaction_id).unwrap(); assert_eq!(transaction.confirmed, false); + set_gm_do_enlist_sell_offer_worst_case::(other_user.clone(), offer_id).unwrap(); + #[extrinsic_call] _(RawOrigin::Signed(user.clone()), transaction_id); @@ -414,6 +576,7 @@ mod benchmarks { let admin: T::AccountId = account("admin", 0, SEED); init::().unwrap(); register_user::(user.clone(), "user").unwrap(); + set_rbac_assign_role_to_user_worst_case::(user.clone(), 2, false).unwrap(); assert!(!Afloat::::is_admin(user.clone()).unwrap()); #[extrinsic_call] _(RawOrigin::Signed(admin.clone()), user.clone()); @@ -426,6 +589,7 @@ mod benchmarks { let admin: T::AccountId = account("admin", 0, SEED); init::().unwrap(); register_user::(user.clone(), "user").unwrap(); + set_rbac_assign_role_to_user_worst_case::(user.clone(), 2, false).unwrap(); let role: AfloatRole = AfloatRole::CPA; assert!(!Afloat::::is_cpa(user.clone()).unwrap()); #[extrinsic_call] diff --git a/pallets/afloat/src/functions.rs b/pallets/afloat/src/functions.rs index ec0c637c..38382d12 100644 --- a/pallets/afloat/src/functions.rs +++ b/pallets/afloat/src/functions.rs @@ -891,11 +891,11 @@ impl Pallet { Ok(()) } - fn scope_id() -> [u8; 32] { + pub fn scope_id() -> [u8; 32] { "AfloatScope".as_bytes().using_encoded(blake2_256) } - fn pallet_id() -> IdOrVec { + pub fn pallet_id() -> IdOrVec { IdOrVec::Vec("AfloatPallet".as_bytes().to_vec()) } diff --git a/pallets/afloat/src/lib.rs b/pallets/afloat/src/lib.rs index 8582de85..b7e0fc30 100644 --- a/pallets/afloat/src/lib.rs +++ b/pallets/afloat/src/lib.rs @@ -386,10 +386,10 @@ pub mod pallet { pub fn start_take_sell_order( origin: OriginFor, offer_id: [u8; 32], - tax_credit_amount: u32, + tax_credit_amount: T::Balance, ) -> DispatchResult { ensure_signed(origin.clone())?; - Self::do_start_take_sell_order(origin, offer_id, tax_credit_amount.into()) + Self::do_start_take_sell_order(origin, offer_id, tax_credit_amount) } #[pallet::call_index(6)] diff --git a/pallets/afloat/src/mock.rs b/pallets/afloat/src/mock.rs index 25215b14..8f70888a 100644 --- a/pallets/afloat/src/mock.rs +++ b/pallets/afloat/src/mock.rs @@ -177,7 +177,7 @@ parameter_types! { pub const RoleMaxLen: u32 = 255; pub const PermissionMaxLen: u32 = 255; pub const MaxPermissionsPerRole: u32 = 30; - pub const MaxRolesPerUser: u32 = 10; + pub const MaxRolesPerUser: u32 = 6; pub const MaxUsersPerRole: u32 = 10; } impl pallet_rbac::Config for Test { diff --git a/pallets/rbac/src/functions.rs b/pallets/rbac/src/functions.rs index 23c164a5..865b24eb 100644 --- a/pallets/rbac/src/functions.rs +++ b/pallets/rbac/src/functions.rs @@ -606,6 +606,8 @@ impl RoleBasedAccessControl for Pallet { type PermissionMaxLen = T::PermissionMaxLen; type RoleMaxLen = T::RoleMaxLen; + + type MaxScopesPerPallet = T::MaxScopesPerPallet; } impl Pallet { diff --git a/pallets/rbac/src/types.rs b/pallets/rbac/src/types.rs index 5f638e11..bc57e8e1 100644 --- a/pallets/rbac/src/types.rs +++ b/pallets/rbac/src/types.rs @@ -42,6 +42,7 @@ pub trait RoleBasedAccessControl { type MaxPermissionsPerRole: Get; type RoleMaxLen: Get; type PermissionMaxLen: Get; + type MaxScopesPerPallet: Get; // scopes fn create_scope(pallet: IdOrVec, scope_id: ScopeId) -> DispatchResult; // scope removal From 7f9cf81b6526cc697e22261ab71693c34e70cd2b Mon Sep 17 00:00:00 2001 From: Dreyhh Date: Thu, 4 Apr 2024 10:26:46 -0600 Subject: [PATCH 3/5] Added rbac's assign role worst case to afloat's sign up benchmark --- pallets/afloat/src/benchmarking.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pallets/afloat/src/benchmarking.rs b/pallets/afloat/src/benchmarking.rs index d7730f0a..6c2f254b 100644 --- a/pallets/afloat/src/benchmarking.rs +++ b/pallets/afloat/src/benchmarking.rs @@ -388,6 +388,7 @@ mod benchmarks { let user: T::AccountId = account("user", 0, SEED); init::().unwrap(); + set_rbac_assign_role_to_user_worst_case::(user.clone(), 1, false).unwrap(); #[extrinsic_call] _(RawOrigin::Signed(user.clone()), sign_up_args); @@ -436,6 +437,7 @@ mod benchmarks { let parent_info = create_sized_parent_info::(0, 0, MAX_U32, true); assert_eq!(attributes.len() as u32, a); set_up_fruniques_do_spawn_worst_case::(user.clone()).unwrap(); + #[extrinsic_call] _(RawOrigin::Signed(user.clone()), description, Some(attributes), Some(parent_info)); } From bd05e7f7a708c83d6ef493f85c47e276ee20a661 Mon Sep 17 00:00:00 2001 From: Dreyhh Date: Thu, 4 Apr 2024 11:41:32 -0600 Subject: [PATCH 4/5] Added call to set_fruniques_do_spawn for afloatfinish_take_sell_transaction benchmark, replaced unwraps with assert_ok for calls to helpers functions that dont return a value in afloat benchmarks --- pallets/afloat/src/benchmarking.rs | 96 +++++++++++++++--------------- 1 file changed, 49 insertions(+), 47 deletions(-) diff --git a/pallets/afloat/src/benchmarking.rs b/pallets/afloat/src/benchmarking.rs index 6c2f254b..9102a6a2 100644 --- a/pallets/afloat/src/benchmarking.rs +++ b/pallets/afloat/src/benchmarking.rs @@ -348,9 +348,9 @@ mod benchmarks { fn initial_setup() { let admin: T::AccountId = account("admin", 0, SEED); let creator: T::AccountId = account("creator", 0, SEED); - set_max_balance::(admin.clone()).unwrap(); - set_max_balance::(creator.clone()).unwrap(); - set_rbac_assign_role_to_user_worst_case::(admin.clone(), 0, true).unwrap(); + assert_ok!(set_max_balance::(admin.clone())); + assert_ok!(set_max_balance::(creator.clone())); + assert_ok!(set_rbac_assign_role_to_user_worst_case::(admin.clone(), 0, true)); let asset_id: T::AssetId = T::AfloatBenchHelper::asset(0); let min_balance: T::Balance = T::AfloatBenchHelper::balance(1); let asset: CreateAsset = CreateAsset::New { asset_id, min_balance }; @@ -367,7 +367,7 @@ mod benchmarks { #[benchmark] fn kill_storage() { - init::().unwrap(); + assert_ok!(init::()); assert!(Afloat::::marketplace_id().is_some()); assert!(Afloat::::collection_id().is_some()); assert!(Afloat::::asset_id().is_some()); @@ -387,8 +387,8 @@ mod benchmarks { let sign_up_args = SignUpArgs::BuyerOrSeller { cid: cid.clone(), cid_creator, group }; let user: T::AccountId = account("user", 0, SEED); - init::().unwrap(); - set_rbac_assign_role_to_user_worst_case::(user.clone(), 1, false).unwrap(); + assert_ok!(init::()); + assert_ok!(set_rbac_assign_role_to_user_worst_case::(user.clone(), 1, false)); #[extrinsic_call] _(RawOrigin::Signed(user.clone()), sign_up_args); @@ -398,7 +398,7 @@ mod benchmarks { #[benchmark] fn update_user_info() { - init::().unwrap(); + assert_ok!(init::()); let user: T::AccountId = account("user", 0, SEED); register_user::(user.clone(), "user").unwrap(); @@ -412,7 +412,7 @@ mod benchmarks { let update_user_info_args = UpdateUserArgs::Delete; - set_rbac_assign_role_to_user_worst_case::(user.clone(), 1, false).unwrap(); + assert_ok!(set_rbac_assign_role_to_user_worst_case::(user.clone(), 1, false)); let admin: T::AccountId = account("admin", 0, SEED); #[extrinsic_call] @@ -424,8 +424,8 @@ mod benchmarks { #[benchmark] fn create_tax_credit(a: Linear<0, { ::MaxAttributes::get() }>) { let user: T::AccountId = account("user", 0, SEED); - init::().unwrap(); - register_user::(user.clone(), "user").unwrap(); + assert_ok!(init::()); + assert_ok!(register_user::(user.clone(), "user")); let attributes: Attributes = create_sized_attributes::( a, @@ -436,7 +436,7 @@ mod benchmarks { create_sized_description::(::StringLimit::get()); let parent_info = create_sized_parent_info::(0, 0, MAX_U32, true); assert_eq!(attributes.len() as u32, a); - set_up_fruniques_do_spawn_worst_case::(user.clone()).unwrap(); + assert_ok!(set_up_fruniques_do_spawn_worst_case::(user.clone())); #[extrinsic_call] _(RawOrigin::Signed(user.clone()), description, Some(attributes), Some(parent_info)); @@ -445,9 +445,9 @@ mod benchmarks { #[benchmark] fn create_offer() { let user: T::AccountId = account("user", 0, SEED); - init::().unwrap(); - register_user::(user.clone(), "user").unwrap(); - add_tax_credit::(user.clone()).unwrap(); + assert_ok!(init::()); + assert_ok!(register_user::(user.clone(), "user")); + assert_ok!(add_tax_credit::(user.clone())); let args = CreateOfferArgs::Sell { tax_credit_amount: MAX_TAX_CREDIT_AMOUNT, tax_credit_id: T::AfloatBenchHelper::item(0), @@ -463,12 +463,12 @@ mod benchmarks { fn start_take_sell_order() { let user: T::AccountId = account("user", 0, SEED); let other_user: T::AccountId = account("other_user", 0, SEED); - set_max_balance::(other_user.clone()).unwrap(); - set_max_balance::(user.clone()).unwrap(); - init::().unwrap(); - register_user::(user.clone(), "user").unwrap(); - register_user::(other_user.clone(), "other_user").unwrap(); - add_tax_credit::(user.clone()).unwrap(); + assert_ok!(set_max_balance::(other_user.clone())); + assert_ok!(set_max_balance::(user.clone())); + assert_ok!(init::()); + assert_ok!(register_user::(user.clone(), "user")); + assert_ok!(register_user::(other_user.clone(), "other_user")); + assert_ok!(add_tax_credit::(user.clone())); let offer_id = add_sell_order::(user.clone()).unwrap(); let offer = AfloatOffers::::get(offer_id).unwrap(); let offer_trxs = offer.transactions.clone(); @@ -481,7 +481,7 @@ mod benchmarks { T::Balance::max_value().into(), ); - set_start_take_sell_offer_worst_case::(other_user.clone(), offer_id.clone()).unwrap(); + assert_ok!(set_start_take_sell_offer_worst_case::(other_user.clone(), offer_id.clone())); #[extrinsic_call] _(RawOrigin::Signed(other_user), offer_id, MAX_U32.into()); @@ -496,19 +496,19 @@ mod benchmarks { fn confirm_sell_transaction() { let user: T::AccountId = account("user", 0, SEED); let other_user: T::AccountId = account("other_user", 0, SEED); - set_max_balance::(other_user.clone()).unwrap(); - set_max_balance::(user.clone()).unwrap(); - init::().unwrap(); - register_user::(user.clone(), "user").unwrap(); - register_user::(other_user.clone(), "other_user").unwrap(); - add_tax_credit::(user.clone()).unwrap(); + assert_ok!(set_max_balance::(other_user.clone())); + assert_ok!(set_max_balance::(user.clone())); + assert_ok!(init::()); + assert_ok!(register_user::(user.clone(), "user")); + assert_ok!(register_user::(other_user.clone(), "other_user")); + assert_ok!(add_tax_credit::(user.clone())); let offer_id = add_sell_order::(user.clone()).unwrap(); let transaction_id = add_start_take_sell_order::(other_user.clone(), offer_id).unwrap(); let transaction = AfloatTransactions::::get(transaction_id).unwrap(); assert_eq!(transaction.confirmed, false); - set_gm_do_enlist_sell_offer_worst_case::(other_user.clone(), offer_id).unwrap(); + assert_ok!(set_gm_do_enlist_sell_offer_worst_case::(other_user.clone(), offer_id)); #[extrinsic_call] _(RawOrigin::Signed(user.clone()), transaction_id); @@ -521,15 +521,17 @@ mod benchmarks { fn finish_take_sell_transaction() { let user: T::AccountId = account("user", 0, SEED); let other_user: T::AccountId = account("other_user", 0, SEED); - set_max_balance::(other_user.clone()).unwrap(); - set_max_balance::(user.clone()).unwrap(); - init::().unwrap(); - register_user::(user.clone(), "user").unwrap(); - register_user::(other_user.clone(), "other_user").unwrap(); - add_tax_credit::(user.clone()).unwrap(); + assert_ok!(set_max_balance::(other_user.clone())); + assert_ok!(set_max_balance::(user.clone())); + assert_ok!(init::()); + assert_ok!(register_user::(user.clone(), "user")); + assert_ok!(register_user::(other_user.clone(), "other_user")); + assert_ok!(add_tax_credit::(user.clone())); let offer_id = add_sell_order::(user.clone()).unwrap(); let transaction_id = add_start_take_sell_order::(other_user.clone(), offer_id).unwrap(); - add_confirm_sell_transaction::(user.clone(), transaction_id).unwrap(); + // used internally by gm do_take_sell_offer when tax credit amount < 100 + assert_ok!(set_up_fruniques_do_spawn_worst_case::(other_user.clone())); + assert_ok!(add_confirm_sell_transaction::(user.clone(), transaction_id)); let transaction = AfloatTransactions::::get(transaction_id).unwrap(); assert_eq!(transaction.completed, false); @@ -543,9 +545,9 @@ mod benchmarks { #[benchmark] fn set_afloat_balance() { let user: T::AccountId = account("user", 0, SEED); - set_max_balance::(user.clone()).unwrap(); - init::().unwrap(); - register_user::(user.clone(), "user").unwrap(); + assert_ok!(set_max_balance::(user.clone())); + assert_ok!(init::()); + assert_ok!(register_user::(user.clone(), "user")); let admin: T::AccountId = account("admin", 0, SEED); let amount = T::AfloatBenchHelper::balance(MAX_U64); assert_eq!( @@ -560,9 +562,9 @@ mod benchmarks { #[benchmark] fn cancel_offer() { let user: T::AccountId = account("user", 0, SEED); - init::().unwrap(); - register_user::(user.clone(), "user").unwrap(); - add_tax_credit::(user.clone()).unwrap(); + assert_ok!(init::()); + assert_ok!(register_user::(user.clone(), "user")); + assert_ok!(add_tax_credit::(user.clone())); let offer_id = add_sell_order::(user.clone()).unwrap(); let offer = AfloatOffers::::get(offer_id).unwrap(); assert_eq!(offer.status, OfferStatus::CREATED); @@ -576,9 +578,9 @@ mod benchmarks { fn add_afloat_admin() { let user: T::AccountId = account("user", 0, SEED); let admin: T::AccountId = account("admin", 0, SEED); - init::().unwrap(); - register_user::(user.clone(), "user").unwrap(); - set_rbac_assign_role_to_user_worst_case::(user.clone(), 2, false).unwrap(); + assert_ok!(init::()); + assert_ok!(register_user::(user.clone(), "user")); + assert_ok!(set_rbac_assign_role_to_user_worst_case::(user.clone(), 2, false)); assert!(!Afloat::::is_admin(user.clone()).unwrap()); #[extrinsic_call] _(RawOrigin::Signed(admin.clone()), user.clone()); @@ -589,9 +591,9 @@ mod benchmarks { fn assign_user_to_role() { let user: T::AccountId = account("user", 0, SEED); let admin: T::AccountId = account("admin", 0, SEED); - init::().unwrap(); - register_user::(user.clone(), "user").unwrap(); - set_rbac_assign_role_to_user_worst_case::(user.clone(), 2, false).unwrap(); + assert_ok!(init::()); + assert_ok!(register_user::(user.clone(), "user")); + assert_ok!(set_rbac_assign_role_to_user_worst_case::(user.clone(), 2, false)); let role: AfloatRole = AfloatRole::CPA; assert!(!Afloat::::is_cpa(user.clone()).unwrap()); #[extrinsic_call] From a4ac3aec996d959a7b9e1c8b808a18756fc22506 Mon Sep 17 00:00:00 2001 From: Dreyhh Date: Tue, 9 Apr 2024 10:14:53 -0600 Subject: [PATCH 5/5] Updated set_rbac_assign_role_to_user_worst_case() to populate also StorageMaps values for Fruniques and GM, fixed set_gm_do_enlist_sell_offer_worst_case(), updated do_create_sell/buy_order() methods signature to return the created offer_id given that there was no other way to reliably get the offer_id, updated gm's offer_id creation to include also the item_id, removed unused variables and imports --- .gitignore | 2 +- pallets/afloat/src/benchmarking.rs | 296 ++++++++++++++------- pallets/afloat/src/functions.rs | 12 +- pallets/afloat/src/mock.rs | 12 +- pallets/gated-marketplace/src/functions.rs | 23 +- 5 files changed, 234 insertions(+), 111 deletions(-) diff --git a/.gitignore b/.gitignore index 6ea5fa0e..cba13b15 100644 --- a/.gitignore +++ b/.gitignore @@ -32,7 +32,7 @@ gcloud-md5-ingress.yml .secrets collator-data relay-data -.vscode/settings.json +.vscode lcov.info dist/ md5*.json diff --git a/pallets/afloat/src/benchmarking.rs b/pallets/afloat/src/benchmarking.rs index 9102a6a2..bedfd41c 100644 --- a/pallets/afloat/src/benchmarking.rs +++ b/pallets/afloat/src/benchmarking.rs @@ -12,33 +12,35 @@ use frame_system::{Config as SystemConfig, RawOrigin}; use pallet_fruniques::types::{Attributes, ParentInfo}; use scale_info::prelude::{vec::Vec, *}; use sp_runtime::{traits::Bounded, Permill}; -type DepositBalanceOf = <::Currency as Currency< - ::AccountId, ->>::Balance; +use pallet_fruniques::Pallet as Fruniques; +use pallet_gated_marketplace::Pallet as GatedMarketplace; use pallet_rbac::types::{IdOrVec, RoleBasedAccessControl, RoleId}; use sp_io::hashing::blake2_256; use std::cmp; +type DepositBalanceOf = <::Currency as Currency< + ::AccountId, +>>::Balance; + +const LSS: u32 = 55; const SEED: u32 = 0; const MAX_U32: u32 = u32::MAX; const MAX_U64: u64 = u64::MAX; const MAX_TAX_CREDIT_AMOUNT: u32 = 100; const NUM_AFLOAT_ROLES: u32 = 4; +const NUM_GM_ROLES: u32 = 5; +const NUM_FRUNIQUES_ROLES: u32 = 5; -pub fn generate_pallet_id_sized(id: u8, size: u32) -> IdOrVec { - IdOrVec::Vec(generate_vector(0, id, size)) -} - -pub fn generate_role_sized(id: u8, size: u32) -> Vec { +fn generate_role_sized(id: u8, size: u32) -> Vec { generate_vector(1, id, size) } -pub fn generate_scope_sized(id: u32, size: u32) -> Vec { +fn generate_scope_sized(id: u32, size: u32) -> Vec { generate_vector((id / u8::MAX as u32) as u8, (id % u8::MAX as u32) as u8, size) } -pub fn generate_roles_sized(id: u8, num_roles: u32, size: u32) -> Vec> { +fn generate_roles_sized(id: u8, num_roles: u32, size: u32) -> Vec> { let mut roles = Vec::new(); for r in 0..num_roles { roles.push(generate_role_sized(r as u8 + id, size)); @@ -46,7 +48,7 @@ pub fn generate_roles_sized(id: u8, num_roles: u32, size: u32) -> Vec> { roles } -pub fn generate_id(item: Vec) -> [u8; 32] { +fn generate_id(item: Vec) -> [u8; 32] { item.using_encoded(blake2_256) } @@ -54,51 +56,76 @@ fn set_rbac_assign_role_to_user_worst_case( user: ::AccountId, num_roles_available_user: u32, inital_setup: bool, + pallet_ids: Vec, ) -> Result<(), sp_runtime::DispatchError> { // Leave only one Scope available for the pallet let max_scopes = <::Rbac as RoleBasedAccessControl>::MaxScopesPerPallet::get( ) - 1; - let mut scope_ids = Vec::new(); - let pallet_id = Afloat::::pallet_id(); - for s in 0..max_scopes { - let scope = generate_scope_sized(s, 10); - let mut scope_id = generate_id(scope); - assert_ok!( - <::Rbac as RoleBasedAccessControl>::create_scope( - pallet_id.clone(), - scope_id - ) - ); - scope_ids.push(scope_id); - } - // Leave n roles available for the pallet - let num_roles = <::Rbac as RoleBasedAccessControl>::MaxRolesPerPallet::get() - NUM_AFLOAT_ROLES; - let size = - <::Rbac as RoleBasedAccessControl>::RoleMaxLen::get(); - let roles = generate_roles_sized(1, num_roles, size); - assert_ok!( + let afloat_pallet_id = Afloat::::pallet_id().to_id(); + let afloat_scope_id = Afloat::::scope_id(); + let fruniques_pallet_id = Fruniques::::pallet_id().to_id(); + let fruniques_scope_id = Afloat::::collection_id() + .unwrap_or(T::AfloatBenchHelper::collection(0)) + .using_encoded(blake2_256); + let gm_pallet_id = GatedMarketplace::::pallet_id().to_id(); + let gm_scope_id = Afloat::::marketplace_id().unwrap_or(0.using_encoded(blake2_256)); + + for pallet_id in pallet_ids { + let mut scope_ids = Vec::new(); + for s in 0..max_scopes { + let scope = generate_scope_sized(s, 10); + let scope_id = generate_id(scope); + assert_ok!( + <::Rbac as RoleBasedAccessControl>::create_scope( + pallet_id.clone(), + scope_id + ) + ); + scope_ids.push(scope_id); + } + + let max_roles = <::Rbac as RoleBasedAccessControl>::MaxRolesPerPallet::get(); + let num_roles = match pallet_id.clone().to_id() { + v if v == afloat_pallet_id => max_roles - NUM_AFLOAT_ROLES, + v if v == gm_pallet_id => max_roles - NUM_GM_ROLES, + v if v == fruniques_pallet_id => max_roles - NUM_FRUNIQUES_ROLES, + _ => max_roles, + }; + + let size = + <::Rbac as RoleBasedAccessControl>::RoleMaxLen::get( + ); + + let roles = generate_roles_sized(1, num_roles, size); + + assert_ok!( <::Rbac as RoleBasedAccessControl>::create_and_set_roles( pallet_id.clone(), roles.clone() - ) - ); - - if !inital_setup { - let role_ids: Vec = roles.into_iter().map(|role| generate_id(role)).collect(); - let l = role_ids.len(); - let r = l - num_roles_available_user as usize; - let n = cmp::min(l, r); - let role_ids = &role_ids[0..n]; - let scope_id = Afloat::::scope_id(); - for role_id in role_ids { - assert_ok!(<::Rbac as RoleBasedAccessControl>::assign_role_to_user( + )); + + if !inital_setup { + let role_ids: Vec = roles.into_iter().map(|role| generate_id(role)).collect(); + let l = role_ids.len(); + let r = l - num_roles_available_user as usize; + let n = cmp::min(l, r); + let role_ids = &role_ids[0..n]; + let scope_id = match pallet_id.clone().to_id() { + v if v == afloat_pallet_id => afloat_scope_id, + v if v == fruniques_pallet_id => fruniques_scope_id, + v if v == gm_pallet_id => gm_scope_id, + _ => scope_ids[0], + }; + for role_id in role_ids { + assert_ok!(<::Rbac as RoleBasedAccessControl>::assign_role_to_user( user.clone(), pallet_id.clone(), &scope_id, role_id.clone() )); + } } } @@ -130,17 +157,67 @@ where Ok(()) } -fn set_gm_do_enlist_sell_offer_worst_case( +fn add_max_afloat_balance(user: T::AccountId) -> Result<(), sp_runtime::DispatchError> +where + ::ItemId: From, + ::CollectionId: From, +{ + let admin: T::AccountId = account("admin", 0, SEED); + + Afloat::::set_afloat_balance( + RawOrigin::Signed(admin).into(), + user, + T::Balance::max_value().into(), + ) +} + +fn set_afloat_balance_to_zero( user: T::AccountId, - offer_id: [u8; 32], ) -> Result<(), sp_runtime::DispatchError> where ::ItemId: From, ::CollectionId: From, { - let max_offers_by_item = ::MaxOffersPerMarket::get() - 1; - for _ in 0..max_offers_by_item { - add_start_take_sell_order::(user.clone(), offer_id.clone()).unwrap(); + let admin: T::AccountId = account("admin", 0, SEED); + + Afloat::::set_afloat_balance( + RawOrigin::Signed(admin).into(), + user, + T::AfloatBenchHelper::balance(0), + ) +} + +fn set_gm_do_enlist_sell_offer_worst_case( + owner: T::AccountId, +) -> Result<(), sp_runtime::DispatchError> +where + ::ItemId: From, + ::CollectionId: From, +{ + // MaxOffersPerMarket is the limit for OffersByAccount, OffersByMarket and OffersByItem + // add_confirm_sell_transaction() populates those StorageMaps + // we need to create different accounts and different fruniques since the uniqueness of the + // item_id (created and checked by gm) relies on the use of a timestamp that doesn't work for + // the benchmark + + let max_offers_by_market = + ::MaxOffersPerMarket::get() - 1; + + for i in 0..max_offers_by_market { + let acc: T::AccountId = account("acc", 0, i + 1); + assert_ok!(register_user::(acc.clone(), "acc")); + assert_ok!(set_max_balance::(acc.clone())); + assert_ok!(add_max_afloat_balance::(acc.clone())); + let item_id = add_tax_credit::(owner.clone()).unwrap(); + let offer_id = add_sell_order::(owner.clone(), item_id).unwrap(); + let trx_id = add_start_take_sell_order::(acc.clone(), offer_id.clone()).unwrap(); + assert_ok!(add_confirm_sell_transaction::(owner.clone(), trx_id.clone())); + assert_ok!(set_afloat_balance_to_zero::(acc.clone())); + assert_ok!(Afloat::::update_user_info( + RawOrigin::Signed(account("admin", 0, SEED)).into(), + acc.clone(), + UpdateUserArgs::Delete + )); } Ok(()) } @@ -222,13 +299,18 @@ fn create_sized_parent_info( fn add_tax_credit( user: ::AccountId, -) -> Result<(), sp_runtime::DispatchError> +) -> Result where ::ItemId: From, ::CollectionId: From, { + let collection_id = Afloat::::collection_id().unwrap(); + let current_next_frunique_id = Fruniques::::next_frunique(collection_id.clone()); let description = create_sized_description::(10); - Afloat::::create_tax_credit(RawOrigin::Signed(user).into(), description, None, None) + Afloat::::create_tax_credit(RawOrigin::Signed(user).into(), description, None, None)?; + let frunique_id = Fruniques::::next_frunique(collection_id.clone()); + assert_eq!(frunique_id.clone(), current_next_frunique_id + 1); + Ok((frunique_id - 1).into()) } fn set_up_fruniques_do_spawn_worst_case( @@ -270,21 +352,21 @@ where fn add_sell_order( user: ::AccountId, + tax_credit_id: T::ItemId, ) -> Result<[u8; 32], sp_runtime::DispatchError> where ::ItemId: From, ::CollectionId: From, { - Afloat::::create_offer( - RawOrigin::Signed(user.clone()).into(), - CreateOfferArgs::::Sell { - tax_credit_id: T::AfloatBenchHelper::item(0), - price_per_credit: MAX_U32.into(), - tax_credit_amount: MAX_U32, - expiration_date: MAX_U32.into(), - }, - )?; - let offer_id = AfloatOffers::::iter().last().unwrap().0; + let offer_id = Afloat::::do_create_sell_order( + user.clone(), + tax_credit_id, + MAX_U32.into(), + MAX_U32, + MAX_U32.into(), + ) + .unwrap(); + ensure!(AfloatOffers::::contains_key(offer_id), Error::::OfferNotFound); Ok(offer_id) } @@ -299,12 +381,6 @@ where { let offer = AfloatOffers::::get(offer_id).unwrap(); assert_eq!(offer.status, OfferStatus::CREATED); - let admin: T::AccountId = account("admin", 0, SEED); - Afloat::::set_afloat_balance( - RawOrigin::Signed(admin).into(), - user.clone(), - T::Balance::max_value().into(), - )?; Afloat::::start_take_sell_order( RawOrigin::Signed(user).into(), @@ -328,10 +404,7 @@ where Afloat::::confirm_sell_transaction(RawOrigin::Signed(user).into(), transaction_id) } -// largest short string -const LSS: u32 = 55; - -pub fn generate_vector(prefix: u8, id: u8, size: u32) -> Vec { +fn generate_vector(prefix: u8, id: u8, size: u32) -> Vec { assert!(size > 0, "vector size must be greater than 0"); let mut v = vec![id; size as usize]; v[0] = prefix; @@ -350,7 +423,17 @@ mod benchmarks { let creator: T::AccountId = account("creator", 0, SEED); assert_ok!(set_max_balance::(admin.clone())); assert_ok!(set_max_balance::(creator.clone())); - assert_ok!(set_rbac_assign_role_to_user_worst_case::(admin.clone(), 0, true)); + let pallet_ids = vec![ + Afloat::::pallet_id(), + Fruniques::::pallet_id(), + GatedMarketplace::::pallet_id(), + ]; + assert_ok!(set_rbac_assign_role_to_user_worst_case::( + admin.clone(), + 0, + true, + pallet_ids + )); let asset_id: T::AssetId = T::AfloatBenchHelper::asset(0); let min_balance: T::Balance = T::AfloatBenchHelper::balance(1); let asset: CreateAsset = CreateAsset::New { asset_id, min_balance }; @@ -386,9 +469,19 @@ mod benchmarks { let sign_up_args = SignUpArgs::BuyerOrSeller { cid: cid.clone(), cid_creator, group }; let user: T::AccountId = account("user", 0, SEED); - + let pallet_ids = vec![ + Afloat::::pallet_id(), + Fruniques::::pallet_id(), + // GatedMarketplace::::pallet_id(), if the user already has *any* role in GM, + // sign_up fails because of a validation in gm's self_enroll() + ]; assert_ok!(init::()); - assert_ok!(set_rbac_assign_role_to_user_worst_case::(user.clone(), 1, false)); + assert_ok!(set_rbac_assign_role_to_user_worst_case::( + user.clone(), + 1, + false, + pallet_ids + )); #[extrinsic_call] _(RawOrigin::Signed(user.clone()), sign_up_args); @@ -405,14 +498,19 @@ mod benchmarks { assert_eq!(Afloat::::user_info(&user).unwrap().cid, b"user".to_vec()); - let new_cid: ShortString = ShortString::try_from(generate_vector(0, 1, LSS)).unwrap(); - let new_cid_creator: ShortString = - ShortString::try_from(generate_vector(0, 1, LSS)).unwrap(); - let new_group: ShortString = ShortString::try_from(generate_vector(0, 1, LSS)).unwrap(); - let update_user_info_args = UpdateUserArgs::Delete; + let pallet_ids = vec![ + Afloat::::pallet_id(), + Fruniques::::pallet_id(), + GatedMarketplace::::pallet_id(), + ]; - assert_ok!(set_rbac_assign_role_to_user_worst_case::(user.clone(), 1, false)); + assert_ok!(set_rbac_assign_role_to_user_worst_case::( + user.clone(), + 1, + false, + pallet_ids + )); let admin: T::AccountId = account("admin", 0, SEED); #[extrinsic_call] @@ -469,7 +567,7 @@ mod benchmarks { assert_ok!(register_user::(user.clone(), "user")); assert_ok!(register_user::(other_user.clone(), "other_user")); assert_ok!(add_tax_credit::(user.clone())); - let offer_id = add_sell_order::(user.clone()).unwrap(); + let offer_id = add_sell_order::(user.clone(), T::AfloatBenchHelper::item(0)).unwrap(); let offer = AfloatOffers::::get(offer_id).unwrap(); let offer_trxs = offer.transactions.clone(); assert_eq!(offer.status, OfferStatus::CREATED); @@ -502,14 +600,13 @@ mod benchmarks { assert_ok!(register_user::(user.clone(), "user")); assert_ok!(register_user::(other_user.clone(), "other_user")); assert_ok!(add_tax_credit::(user.clone())); - let offer_id = add_sell_order::(user.clone()).unwrap(); - + assert_ok!(set_gm_do_enlist_sell_offer_worst_case::(user.clone())); + let offer_id = add_sell_order::(user.clone(), T::AfloatBenchHelper::item(0)).unwrap(); + assert_ok!(add_max_afloat_balance::(other_user.clone())); let transaction_id = add_start_take_sell_order::(other_user.clone(), offer_id).unwrap(); + let transaction = AfloatTransactions::::get(transaction_id).unwrap(); assert_eq!(transaction.confirmed, false); - - assert_ok!(set_gm_do_enlist_sell_offer_worst_case::(other_user.clone(), offer_id)); - #[extrinsic_call] _(RawOrigin::Signed(user.clone()), transaction_id); @@ -527,7 +624,8 @@ mod benchmarks { assert_ok!(register_user::(user.clone(), "user")); assert_ok!(register_user::(other_user.clone(), "other_user")); assert_ok!(add_tax_credit::(user.clone())); - let offer_id = add_sell_order::(user.clone()).unwrap(); + let offer_id = add_sell_order::(user.clone(), T::AfloatBenchHelper::item(0)).unwrap(); + assert_ok!(add_max_afloat_balance::(other_user.clone())); let transaction_id = add_start_take_sell_order::(other_user.clone(), offer_id).unwrap(); // used internally by gm do_take_sell_offer when tax credit amount < 100 assert_ok!(set_up_fruniques_do_spawn_worst_case::(other_user.clone())); @@ -565,7 +663,7 @@ mod benchmarks { assert_ok!(init::()); assert_ok!(register_user::(user.clone(), "user")); assert_ok!(add_tax_credit::(user.clone())); - let offer_id = add_sell_order::(user.clone()).unwrap(); + let offer_id = add_sell_order::(user.clone(), T::AfloatBenchHelper::item(0)).unwrap(); let offer = AfloatOffers::::get(offer_id).unwrap(); assert_eq!(offer.status, OfferStatus::CREATED); #[extrinsic_call] @@ -578,9 +676,19 @@ mod benchmarks { fn add_afloat_admin() { let user: T::AccountId = account("user", 0, SEED); let admin: T::AccountId = account("admin", 0, SEED); + let pallet_ids = vec![ + Afloat::::pallet_id(), + Fruniques::::pallet_id(), + GatedMarketplace::::pallet_id(), + ]; assert_ok!(init::()); assert_ok!(register_user::(user.clone(), "user")); - assert_ok!(set_rbac_assign_role_to_user_worst_case::(user.clone(), 2, false)); + assert_ok!(set_rbac_assign_role_to_user_worst_case::( + user.clone(), + 2, + false, + pallet_ids + )); assert!(!Afloat::::is_admin(user.clone()).unwrap()); #[extrinsic_call] _(RawOrigin::Signed(admin.clone()), user.clone()); @@ -591,9 +699,19 @@ mod benchmarks { fn assign_user_to_role() { let user: T::AccountId = account("user", 0, SEED); let admin: T::AccountId = account("admin", 0, SEED); + let pallet_ids = vec![ + Afloat::::pallet_id(), + Fruniques::::pallet_id(), + GatedMarketplace::::pallet_id(), + ]; assert_ok!(init::()); assert_ok!(register_user::(user.clone(), "user")); - assert_ok!(set_rbac_assign_role_to_user_worst_case::(user.clone(), 2, false)); + assert_ok!(set_rbac_assign_role_to_user_worst_case::( + user.clone(), + 2, + false, + pallet_ids + )); let role: AfloatRole = AfloatRole::CPA; assert!(!Afloat::::is_cpa(user.clone()).unwrap()); #[extrinsic_call] @@ -603,7 +721,7 @@ mod benchmarks { impl_benchmark_test_suite! { Afloat, - crate::mock::new_test_ext_2(), + crate::mock::new_test_ext_bench(), crate::mock::Test, } } diff --git a/pallets/afloat/src/functions.rs b/pallets/afloat/src/functions.rs index 38382d12..90410e36 100644 --- a/pallets/afloat/src/functions.rs +++ b/pallets/afloat/src/functions.rs @@ -345,7 +345,7 @@ impl Pallet { price: T::Balance, tax_credit_amount: u32, expiration_date: Date, - ) -> DispatchResult { + ) -> Result { let maybe_roles = Self::get_all_roles_for_user(authority.clone())?; ensure!(!maybe_roles.is_empty(), Error::::Unauthorized); @@ -366,11 +366,11 @@ impl Pallet { }; let offer_id = offer.using_encoded(blake2_256); - >::insert(offer_id, offer); + >::insert(offer_id.clone(), offer); Self::deposit_event(Event::SellOrderCreated(authority)); - Ok(()) + Ok(offer_id) } pub fn do_create_buy_order( @@ -379,7 +379,7 @@ impl Pallet { price: T::Balance, tax_credit_amount: u32, expiration_date: Date, - ) -> DispatchResult { + ) -> Result { let maybe_roles = Self::get_all_roles_for_user(authority.clone())?; ensure!(!maybe_roles.is_empty(), Error::::Unauthorized); @@ -401,11 +401,11 @@ impl Pallet { let offer_id = offer.using_encoded(blake2_256); - >::insert(offer_id, offer); + >::insert(offer_id.clone(), offer); Self::deposit_event(Event::BuyOrderCreated(authority)); - Ok(()) + Ok(offer_id) } /// Starts the process of taking a sell order. diff --git a/pallets/afloat/src/mock.rs b/pallets/afloat/src/mock.rs index 8f70888a..b67180ab 100644 --- a/pallets/afloat/src/mock.rs +++ b/pallets/afloat/src/mock.rs @@ -228,7 +228,7 @@ impl pallet_mapped_assets::Config for Test { type CreateOrigin = AsEnsureOriginWithArg>; type ForceOrigin = frame_system::EnsureRoot; type AssetDeposit = ConstU64<1>; - type AssetAccountDeposit = ConstU64<10>; + type AssetAccountDeposit = ConstU64<1>; type MetadataDepositBase = ConstU64<1>; type MetadataDepositPerByte = ConstU64<1>; type ApprovalDeposit = ConstU64<1>; @@ -310,14 +310,8 @@ pub fn new_test_ext() -> sp_io::TestExternalities { t } -pub fn new_test_ext_2() -> sp_io::TestExternalities { - // TODO: get initial conf? - let mut t: sp_io::TestExternalities = +pub fn new_test_ext_bench() -> sp_io::TestExternalities { + let t: sp_io::TestExternalities = frame_system::GenesisConfig::::default().build_storage().unwrap().into(); - t.execute_with(|| { - Balances::make_free_balance_be(&1, 100); - Balances::make_free_balance_be(&2, 100); - Balances::make_free_balance_be(&3, 100); - }); t } diff --git a/pallets/gated-marketplace/src/functions.rs b/pallets/gated-marketplace/src/functions.rs index 3d8ee6ba..59560598 100644 --- a/pallets/gated-marketplace/src/functions.rs +++ b/pallets/gated-marketplace/src/functions.rs @@ -350,9 +350,14 @@ impl Pallet { Self::get_timestamp_in_milliseconds().ok_or(Error::::TimestampError)?; //create an offer_id - let offer_id = (marketplace_id, authority.clone(), collection_id.clone(), creation_date) + let offer_id = ( + marketplace_id, + authority.clone(), + collection_id.clone(), + creation_date, + item_id.clone(), + ) .using_encoded(blake2_256); - //create offer structure let marketplace = @@ -447,7 +452,13 @@ impl Pallet { Self::get_timestamp_in_milliseconds().ok_or(Error::::TimestampError)?; //create an offer_id - let offer_id = (marketplace_id, authority.clone(), collection_id.clone(), creation_date) + let offer_id = ( + marketplace_id, + authority.clone(), + collection_id.clone(), + creation_date, + item_id.clone(), + ) .using_encoded(blake2_256); //create offer structure @@ -797,7 +808,7 @@ impl Pallet { pub fn set_up_application( fields: Fields, custodian_fields: Option>, - ) -> Result<(Option, BoundedVec), DispatchError> { + ) -> Result<(Option, BoundedVec), DispatchError> { ensure!(!fields.is_empty(), Error::::FieldsNotProvided); let mut f: Vec = fields @@ -822,8 +833,8 @@ impl Pallet { _ => None, }; - let fields = BoundedVec::::try_from(f). - map_err(|_| Error::::ExceedMaxFilesApplication)?; + let fields = BoundedVec::::try_from(f) + .map_err(|_| Error::::ExceedMaxFilesApplication)?; Ok((custodian, fields)) }