From cde806b03a96623a01fcb9ad2f9148928af9d5ef Mon Sep 17 00:00:00 2001 From: Yura Date: Thu, 27 Oct 2022 18:19:58 +0200 Subject: [PATCH 01/49] Remove unused migration. (#111) * Remove unused migration. * Remove empty migration.rs files * Fix tests. --- control/src/lib.rs | 16 +------------- control/src/migration.rs | 34 ----------------------------- flow/src/lib.rs | 13 ++--------- flow/src/migration.rs | 41 ----------------------------------- signal/src/lib.rs | 10 +-------- signal/src/migration.rs | 47 ---------------------------------------- signal/src/mock.rs | 2 +- 7 files changed, 5 insertions(+), 158 deletions(-) delete mode 100644 control/src/migration.rs delete mode 100644 flow/src/migration.rs delete mode 100644 signal/src/migration.rs diff --git a/control/src/lib.rs b/control/src/lib.rs index 3b97bcdb0..8056a4fe0 100755 --- a/control/src/lib.rs +++ b/control/src/lib.rs @@ -17,13 +17,12 @@ pub mod types; mod mock; mod tests; -mod migration; mod benchmarking; pub mod weights; use codec::Codec; use frame_support::{dispatch::{DispatchResult, DispatchError, RawOrigin}, - ensure, PalletId, traits::{Get, StorageVersion}, weights::Weight, BoundedVec, transactional + ensure, PalletId, traits::Get, weights::Weight, BoundedVec, transactional }; use gamedao_traits::{ControlTrait, ControlBenchmarkingTrait}; use orml_traits::{MultiCurrency, MultiReservableCurrency}; @@ -53,12 +52,8 @@ pub mod pallet { use frame_support::pallet_prelude::*; use frame_system::pallet_prelude::*; - /// The current storage version. - const STORAGE_VERSION: StorageVersion = StorageVersion::new(0); - #[pallet::pallet] #[pallet::generate_store(pub(super) trait Store)] - #[pallet::storage_version(STORAGE_VERSION)] pub struct Pallet(_); #[pallet::config] @@ -272,15 +267,6 @@ pub mod pallet { WrongOrganizationType } - #[pallet::hooks] - impl Hooks for Pallet { - - fn on_runtime_upgrade() -> Weight { - migration::migrate::() - } - - } - #[pallet::call] impl Pallet { diff --git a/control/src/migration.rs b/control/src/migration.rs deleted file mode 100644 index 1af62394c..000000000 --- a/control/src/migration.rs +++ /dev/null @@ -1,34 +0,0 @@ -use frame_support::{ - traits::{Get, GetStorageVersion, PalletInfoAccess, StorageVersion}, - Blake2_128Concat, - BoundedVec -}; -use sp_std::prelude::*; -use crate::{Config, Pallet, Weight}; - - -pub fn migrate() -> Weight { - - let version = StorageVersion::get::>(); - let mut weight: Weight = 0; - - if version < 1 { - weight = weight.saturating_add(v1::migrate::()); - StorageVersion::new(1).put::>(); - } - - weight -} - -mod v1 { - use super::*; - use sp_io::hashing::twox_128; - - pub fn migrate() -> Weight { - let _ = frame_support::storage::unhashed::clear_prefix( - &twox_128(>::name().as_bytes()), None, None - ); - - T::DbWeight::get().writes(1) - } -} diff --git a/flow/src/lib.rs b/flow/src/lib.rs index ee42df7f0..057a19041 100644 --- a/flow/src/lib.rs +++ b/flow/src/lib.rs @@ -41,14 +41,13 @@ pub use types::{FlowProtocol, CampaignState, FlowGovernance, BlockType}; mod mock; mod tests; -mod migration; #[cfg(feature = "runtime-benchmarks")] mod benchmarking; pub mod weights; use frame_support::{ dispatch::{DispatchResult, DispatchError, DispatchResultWithPostInfo}, - traits::{Get, BalanceStatus, Hooks, StorageVersion}, + traits::{Get, BalanceStatus, Hooks}, weights::Weight, BoundedVec, log, transactional }; @@ -77,12 +76,8 @@ pub mod pallet { use frame_support::pallet_prelude::*; use frame_system::pallet_prelude::*; - /// The current storage version. - const STORAGE_VERSION: StorageVersion = StorageVersion::new(1); - #[pallet::pallet] #[pallet::generate_store(pub(super) trait Store)] - #[pallet::storage_version(STORAGE_VERSION)] pub struct Pallet(_); #[pallet::config] @@ -366,11 +361,7 @@ pub mod pallet { } let c = BoundedVec::try_from(contributors.clone()).unwrap(); CampaignFinalizationQueue::::insert(campaign_id, (campaign, campaign_balance, state, treasury_id, c)); - } - } - - fn on_runtime_upgrade() -> Weight { - migration::migrate::() + } } } diff --git a/flow/src/migration.rs b/flow/src/migration.rs deleted file mode 100644 index 999a05c1d..000000000 --- a/flow/src/migration.rs +++ /dev/null @@ -1,41 +0,0 @@ -use frame_support::{ - traits::{Get, GetStorageVersion, PalletInfoAccess, StorageVersion}, - Blake2_128Concat, - BoundedVec -}; -use sp_std::prelude::*; -use crate::{ - // CampaignsByState as CampaignsByStateNew, - // CampaignOrg, - Config, - // FlowState, - Pallet, - Weight -}; - - -pub fn migrate() -> Weight { - - let version = StorageVersion::get::>(); - let mut weight: Weight = 0; - - if version < 2 { - weight = weight.saturating_add(v2::migrate::()); - StorageVersion::new(2).put::>(); - } - - weight -} - -mod v2 { - use super::*; - use sp_io::hashing::twox_128; - - pub fn migrate() -> Weight { - let _ = frame_support::storage::unhashed::clear_prefix( - &twox_128(>::name().as_bytes()), None, None - ); - - T::DbWeight::get().writes(1) - } -} diff --git a/signal/src/lib.rs b/signal/src/lib.rs index ac0e7a12f..18c3e957d 100644 --- a/signal/src/lib.rs +++ b/signal/src/lib.rs @@ -14,7 +14,6 @@ #![cfg_attr(not(feature = "std"), no_std)] #![allow(deprecated)] // TODO: clean transactional pub mod types; -pub mod migration; #[cfg(test)] pub mod mock; @@ -26,7 +25,7 @@ pub mod weights; use frame_support::{ BoundedVec, - traits::{StorageVersion, BalanceStatus}, + traits::BalanceStatus, dispatch::DispatchResult, weights::Weight, transactional @@ -67,12 +66,8 @@ pub mod pallet { use frame_support::pallet_prelude::*; use frame_system::pallet_prelude::*; - /// The current storage version. - const STORAGE_VERSION: StorageVersion = StorageVersion::new(1); - #[pallet::pallet] #[pallet::generate_store(pub(super) trait Store)] - #[pallet::storage_version(STORAGE_VERSION)] pub struct Pallet(_); #[pallet::config] @@ -401,9 +396,6 @@ pub mod pallet { #[pallet::hooks] impl Hooks> for Pallet { - fn on_runtime_upgrade() -> Weight { - migration::migrate::() - } fn on_initialize(block_number: T::BlockNumber) -> Weight { let proposals = ProposalsByBlock::::get(BlockType::Start, &block_number); diff --git a/signal/src/migration.rs b/signal/src/migration.rs deleted file mode 100644 index b3888b558..000000000 --- a/signal/src/migration.rs +++ /dev/null @@ -1,47 +0,0 @@ -// _______ ________ ________ ________ ______ _______ _______ -// ╱╱ ╲╱ ╲╱ ╲╱ ╲_╱ ╲╲╱ ╲╲╱ ╲╲ -// ╱╱ __╱ ╱ ╱ ╱ ╱╱ ╱╱ ╱╱ -// ╱ ╱ ╱ ╱ ╱ _╱ ╱ ╱ ╱ -// ╲________╱╲___╱____╱╲__╱__╱__╱╲________╱╲________╱╲___╱____╱╲________╱ -// -// This file is part of GameDAO Protocol. -// Copyright (C) 2018-2022 GameDAO AG. -// SPDX-License-Identifier: Apache-2.0 - -use crate::{Config, Pallet, Weight}; -use frame_support::{ - traits::{Get, PalletInfoAccess}, -}; - -pub fn migrate() -> Weight { - use frame_support::traits::StorageVersion; - - let version = StorageVersion::get::>(); - let mut weight: Weight = 0; - - if version < 1 { - weight = weight.saturating_add(v1::migrate::()); - StorageVersion::new(1).put::>(); - } - if version < 2 { - weight = weight.saturating_add(v1::migrate::()); - StorageVersion::new(2).put::>(); - } - - weight -} - -/// V1: Clean up pallet storage -mod v1 { - use super::*; - use sp_io::hashing::twox_128; - - pub fn migrate() -> Weight { - - let _ = frame_support::storage::unhashed::clear_prefix( - &twox_128(>::name().as_bytes()), None, None - ); - - T::DbWeight::get().writes(1) - } -} diff --git a/signal/src/mock.rs b/signal/src/mock.rs index ec3207321..d54c4fd96 100644 --- a/signal/src/mock.rs +++ b/signal/src/mock.rs @@ -273,7 +273,7 @@ pub fn create_org(members: &Vec) -> (H256, AccountId) { let init_balance = 100 * DOLLARS; assert_ok!(Tokens::set_balance(RawOrigin::Root.into(), treasury_id, PROTOCOL_TOKEN_ID, init_balance, 0)); for x in members { - assert_ok!(Control::add_member(Origin::signed(ALICE), org_id, *x)); + assert_ok!(Control::add_member(Origin::signed(x.clone()), org_id, *x)); } (org_id, treasury_id) } From 0eef7d2d12d061ca54bfff829813ae68eefb951d Mon Sep 17 00:00:00 2001 From: Daniel Bigos Date: Fri, 21 Oct 2022 18:21:22 +0200 Subject: [PATCH 02/49] Add M2 review comments --- control/src/lib.rs | 50 ++++++++++++++++++++++++++++++++----------- control/src/tests.rs | 15 +++++++------ flow/src/lib.rs | 49 ++++++++++++++++++++++++------------------ flow/src/tests.rs | 7 +++--- sense/src/lib.rs | 51 ++++++++++++++++++++++++-------------------- signal/src/lib.rs | 39 +++++++++++++++++++++------------ signal/src/tests.rs | 38 +++++++++++++++++---------------- 7 files changed, 152 insertions(+), 97 deletions(-) diff --git a/control/src/lib.rs b/control/src/lib.rs index 8056a4fe0..0dcbe8aca 100755 --- a/control/src/lib.rs +++ b/control/src/lib.rs @@ -120,7 +120,7 @@ pub mod pallet { pub(super) type Orgs = StorageMap<_, Blake2_128Concat, T::Hash, Org, OptionQuery>; - /// Org state (Inactive | Active | Locked) by org id. + /// Org state (Inactive | Active | Locked) by org id. /// /// OrgStates: map Hash => OrgState #[pallet::storage] @@ -177,8 +177,10 @@ pub mod pallet { .iter() .for_each(|(creator, prime, treasury_id, name, cid, org_type, access_model, fee_model, membership_fee, gov_currency, pay_currency, member_limit, deposit)| { + // SBP-M2 review: for genesis build block number should be known let now = frame_system::Pallet::::block_number(); let index = OrgCount::::get(); + // SBP-M2 review: think about some kind of `new` function for `types::Org` let org: Org = types::Org { index, creator: creator.clone(), prime: prime.clone(), name: name.clone(), cid: cid.clone(), org_type: org_type.clone(), fee_model: fee_model.clone(), membership_fee: Some(*membership_fee), @@ -187,6 +189,8 @@ pub mod pallet { }; let org_id = ::Hashing::hash_of(&org); + // SBP-M2 review: you should print some logs if sth goes wrong while genesis build + // Unwrap will not help you with debugging Pallet::::do_create_org(org_id.clone(), &org, treasury_id.clone(), *deposit).unwrap(); Pallet::::do_add_member(org_id, creator.clone(), MemberState::Active).unwrap(); Pallet::::pay_membership_fee( @@ -197,6 +201,8 @@ pub mod pallet { #[pallet::event] #[pallet::generate_deposit(pub(super) fn deposit_event)] + // SBP-M2 review: I would suggest limiting events' attributes. + // When someone is interested, there should be a possibility to query current state. pub enum Event { /// Org was successfully created. OrgCreated { @@ -271,7 +277,7 @@ pub mod pallet { impl Pallet { /// Create an on chain organization - /// + /// /// Parameters: /// - `origin`: Org creator. /// - `name`: Org name. @@ -279,7 +285,7 @@ pub mod pallet { /// - `org_type`: Individual | Company | Dao | Hybrid. /// - `access_model`: /// - `fee_model`: - /// + /// /// Optional parameters: /// - `member_limit`: max members. Default: MaxMembers. /// - `member_fee`: fees amount to be applied to new members based on fee model (in `gov_asset` tokens). @@ -327,6 +333,7 @@ pub mod pallet { ensure!(!>::account_exists(&treasury_id), Error::::TreasuryExists); let now = frame_system::Pallet::::block_number(); + // SBP-M2 review: I definiately suggest having `types::Org::new` function :) let org = types::Org { index, creator: sender.clone(), prime: sender.clone(), name, cid, org_type, fee_model: fee_model.clone(), membership_fee: membership_fee.clone(), gov_currency, @@ -348,7 +355,7 @@ pub mod pallet { /// /// Parameters: /// - `org_id`: Org hash. - /// + /// /// Optional parameters: /// - `prime_id`: new prime id. /// - `access_model`: new access model. @@ -371,12 +378,16 @@ pub mod pallet { membership_fee: Option, ) -> DispatchResult { let mut org = Orgs::::get(&org_id).ok_or(Error::::OrganizationUnknown)?; + // SBP-M2 review: Get rid of Sudo calls + // Create entity like a council Self::ensure_root_or_prime(origin, org.prime.clone(), org.org_type.clone())?; let args = [prime_id.is_some(), fee_model.is_some(), membership_fee.is_some(), access_model.is_some(), member_limit.is_some(), org_type.is_some()]; ensure!(args.iter().any(|x| *x == true), Error::::NoChangesProvided); + // SBP-M2 review: I do not like these instructions with pattern matching + // I would use quick check `is_some`: https://doc.rust-lang.org/std/option/enum.Option.html#method.is_some if let Some(access_model) = access_model.clone() { org.access_model = access_model; }; if let Some(org_type) = org_type.clone() { org.org_type = org_type; }; if let Some(member_limit) = member_limit.clone() { org.member_limit = member_limit; }; @@ -393,7 +404,7 @@ pub mod pallet { }; Orgs::::insert(&org_id, org); - + let block_number = frame_system::Pallet::::block_number(); Self::deposit_event(Event::OrgUpdated { org_id, prime_id, org_type, access_model, member_limit, @@ -417,6 +428,7 @@ pub mod pallet { #[pallet::weight(T::WeightInfo::enable_org())] pub fn enable_org(origin: OriginFor, org_id: T::Hash) -> DispatchResult { let org = Orgs::::get(&org_id).ok_or(Error::::OrganizationUnknown)?; + // SBP-M2 review: same comment about Sudo pallet Self::ensure_root_or_prime(origin, org.prime, org.org_type)?; OrgStates::::insert(org_id.clone(), OrgState::Active); @@ -428,7 +440,7 @@ pub mod pallet { /// /// Disables an Org to be used and changes it's state to Inactive. /// Allowed origins: Root or prime if OrgType::Individual - /// + /// /// Parameters: /// - `org_id`: Org hash. /// @@ -438,6 +450,7 @@ pub mod pallet { #[pallet::weight(T::WeightInfo::disable_org())] pub fn disable_org(origin: OriginFor, org_id: T::Hash) -> DispatchResult { let org = Orgs::::get(&org_id).ok_or(Error::::OrganizationUnknown)?; + // SBP-M2 review: same comment about Sudo pallet Self::ensure_root_or_prime(origin, org.prime, org.org_type)?; OrgStates::::insert(org_id.clone(), OrgState::Inactive); @@ -446,7 +459,7 @@ pub mod pallet { } /// Add Member to Org - /// + /// /// Parameters: /// - `org_id`: Org id /// - `who`: Account to be added @@ -467,14 +480,16 @@ pub mod pallet { _ => MemberState::Pending, }; let treasury_id = OrgTreasury::::get(org_id).ok_or(Error::::TreasuryUnknown)?; + // SBP-M2 review: you could rewrite this function to pass `org` struct and then unpack it inside Self::pay_membership_fee(&org.prime, &treasury_id, org.membership_fee, org.fee_model, org.gov_currency)?; let members_count = Self::do_add_member(org_id, who.clone(), member_state)?; + // SBP-M2 review: why do you return WeightInfo in extrinsics? Ok(Some(T::WeightInfo::add_member(members_count)).into()) } /// Remove member from Org - /// + /// /// Parameters: /// - `org_id`: Org id /// - `who`: Account to be removed @@ -488,14 +503,17 @@ pub mod pallet { Self::ensure_membership_permissions(origin, who.clone(), org.prime.clone(), org.org_type.clone(), org.access_model.clone())?; let member_count = Self::do_remove_member(org_id.clone(), who.clone())?; if org.fee_model == FeeModel::Reserve { + // SBP-M2 review: you should not use `unwrap` in extrinsics + // Apply error handling T::Currency::unreserve(org.gov_currency, &who, org.membership_fee.unwrap()); } + // SBP-M2 review: same comment about returning `WeightInfo` Ok(Some(T::WeightInfo::remove_member(member_count)).into()) } /// Make spending from the org treasury - /// + /// /// Allowed origins: Root or prime if OrgType::Individual /// /// Parameters: @@ -518,11 +536,12 @@ pub mod pallet { ) -> DispatchResult { let org = Orgs::::get(&org_id).ok_or(Error::::OrganizationUnknown)?; let treasury_id = OrgTreasury::::get(org_id).ok_or(Error::::TreasuryUnknown)?; + // SBP-M2 review: same comment about Sudo pallet Self::ensure_root_or_prime(origin, org.prime, org.org_type)?; T::Currency::transfer(currency_id, &treasury_id, &beneficiary, amount ).map_err(|_| Error::::BalanceLow)?; - + let block_number = frame_system::Pallet::::block_number(); Self::deposit_event(Event::FundsSpended { org_id, beneficiary, amount, currency_id, block_number }); @@ -548,6 +567,8 @@ impl Pallet { Orgs::::insert(&org_id, org); + // SBP-M2 review: I strongly suggest emitting events in extrinsics + // It clarifies code and its responsibility Self::deposit_event(Event::OrgCreated { org_id, creator, treasury_id, created_at, realm_index: 0 }); Ok(()) } @@ -564,10 +585,11 @@ impl Pallet { Members::::insert(&org_id, &members); OrgMemberCount::::insert(&org_id, members_count); MemberStates::::insert(&org_id, &who, member_state); - + let block_number = frame_system::Pallet::::block_number(); + // SBP-M2 review: same comment about events Self::deposit_event(Event::MemberAdded { org_id, who, block_number }); - + Ok(members_count) } @@ -609,6 +631,7 @@ impl Pallet { Ok(()) } + // SBP-M2 review: same comment about Sudo pallet fn ensure_membership_permissions( origin: T::Origin, who: T::AccountId, @@ -645,6 +668,7 @@ impl Pallet { fn ensure_root_or_governance(origin: T::Origin) -> Result<(), BadOrigin> { match origin.into() { Ok(RawOrigin::Root) => Ok(()), + // SBP-M2 review: #TODO comment not implemented // TODO: implement governance origin type _ => Err(BadOrigin), } @@ -687,6 +711,8 @@ impl ControlTrait for Pallet { } } +// SBP-M2 review: if functions for benchmarking +// Move to benchmarking or mock module impl ControlBenchmarkingTrait for Pallet { /// ** Should be used for benchmarking only!!! ** #[cfg(feature = "runtime-benchmarks")] diff --git a/control/src/tests.rs b/control/src/tests.rs index 31abc1cbe..9c63d19a0 100644 --- a/control/src/tests.rs +++ b/control/src/tests.rs @@ -30,6 +30,9 @@ fn create_org(access_model: AccessModel) -> H256 { #[test] +// SBP-M2 review: I would split into separated test cases +// It would be easier to find bug if exists +// And this attitude follows unit testing fn control_create_org() { new_test_ext().execute_with(|| { let current_block = 3; @@ -42,7 +45,7 @@ fn control_create_org() { Origin::signed(ALICE), bounded_str.clone(), bounded_str.clone(), OrgType::Company, AccessModel::Prime, FeeModel::NoFees, None, None, None, None, None), Error::::WrongOrganizationType); - + // Create org with org type Hybrid // Error: WrongOrganizationType assert_noop!(Control::create_org( @@ -64,7 +67,7 @@ fn control_create_org() { AccessModel::Prime, FeeModel::Transfer, None, None, None, None, None), Error::::MissingParameter); - // Check if creator (sender) has enough protocol token free balance + // Check if creator (sender) has enough protocol token free balance // to make a deposit into org's treasury // Error: BalanceLow assert_noop!(Control::create_org( @@ -107,7 +110,7 @@ fn control_update_org() { assert_noop!(Control::update_org( Origin::signed(ALICE), org_id, None, None, None, None, Some(FeeModel::Transfer), None), Error::::MissingParameter); - + // Check if prime can be not a member // Error: NotMember assert_noop!(Control::update_org( @@ -115,13 +118,13 @@ fn control_update_org() { Error::::NotMember); assert_ok!(Control::add_member(Origin::signed(ALICE), org_id, BOB)); - + // Check if only prime can perform update_org // Error: BadOrigin assert_noop!(Control::update_org( Origin::signed(BOB), org_id, None, Some(OrgType::Dao), None, None, None, None), BadOrigin); - + // Check if root can update assert_ok!(Control::update_org(Origin::root(), org_id, None, None, None, None, None, Some(199 * DOLLARS))); @@ -152,7 +155,7 @@ fn control_update_org() { } ) ); - + }) } diff --git a/flow/src/lib.rs b/flow/src/lib.rs index 057a19041..90af3cf95 100644 --- a/flow/src/lib.rs +++ b/flow/src/lib.rs @@ -95,7 +95,7 @@ pub mod pallet { + MaybeSerializeDeserialize + MaxEncodedLen + TypeInfo; - + /// The currency ID type type CurrencyId: Member + Parameter @@ -103,7 +103,7 @@ pub mod pallet { + MaybeSerializeDeserialize + MaxEncodedLen + TypeInfo; - + /// Weight information for extrinsics in this module. type WeightInfo: WeightInfo; @@ -121,7 +121,7 @@ pub mod pallet { /// The min length of a campaign name. #[pallet::constant] type MinNameLength: Get; - + /// The max number of campaigns per one block. #[pallet::constant] type MaxCampaignsPerBlock: Get; @@ -146,12 +146,12 @@ pub mod pallet { /// The CurrencyId which is used as a protokol token. #[pallet::constant] type ProtocolTokenId: Get; - + /// The CurrencyId which is used as a payment token. #[pallet::constant] type PaymentTokenId: Get; - /// The amount of comission to be paid from the Org treasury to GameDAO treasury + /// The amount of comission to be paid from the Org treasury to GameDAO treasury /// after successfull Campaign finalization #[pallet::constant] type CampaignFee: Get; @@ -166,27 +166,27 @@ pub mod pallet { } /// Campaign by its id. - /// + /// /// CampaignOf: map Hash => Campaign #[pallet::storage] pub(super) type CampaignOf = StorageMap<_, Blake2_128Concat, T::Hash, Campaign, OptionQuery>; /// Total number of campaigns. - /// + /// /// CampaignCount: u32 #[pallet::storage] #[pallet::getter(fn campaign_count)] pub type CampaignCount = StorageValue<_, u32, ValueQuery>; /// Total contributions balance per campaign. - /// + /// /// CampaignBalance: map Hash => Balance #[pallet::storage] pub(super) type CampaignBalance = StorageMap<_, Blake2_128Concat, T::Hash, T::Balance, ValueQuery>; /// Total contribution made by account id for particular campaign. /// campaign id, account id -> contribution. - /// + /// /// CampaignContribution: double map Hash, AccountId => Balance #[pallet::storage] pub(super) type CampaignContribution = @@ -194,14 +194,14 @@ pub mod pallet { /// Campaign state by campaign id. /// 0 created, 1 activated, 2 paused, ... - /// + /// /// CampaignStates: map Hash => CampaignState #[pallet::storage] pub(super) type CampaignStates = StorageMap<_, Blake2_128Concat, T::Hash, CampaignState, ValueQuery, GetDefault>; /// Campaigns starting/ending in block x. - /// + /// /// CampaignsByBlock: double map BlockType, BlockNumber => BoundedVec #[pallet::storage] pub(super) type CampaignsByBlock = @@ -214,14 +214,14 @@ pub mod pallet { /// Offset value - number of processed and sucessfully finalized contributions. /// Used during campaign finalization for processing contributors in batches. /// When MaxContributorsProcessing is achieved, set this offset to save the progress. - /// + /// /// ProcessingOffset: map Hash => u32 #[pallet::storage] pub(super) type ProcessingOffset = StorageMap<_, Blake2_128Concat, T::Hash, u32, ValueQuery>; /// Total number of contributors for particular campaign. This is needed for voting /// in order do determine eligible voters for Withdrawal proposal. - /// + /// /// CampaignContributors: map Hash => u64 #[pallet::storage] pub(super) type CampaignContributorsCount = StorageMap<_, Blake2_128Concat, T::Hash, u64, ValueQuery>; @@ -328,6 +328,8 @@ pub mod pallet { T::WeightInfo::on_initialize(processed, campaigns.len() as u32) } + // SBP-M2 reviews: I am wondering if just `continue` in case of unexpected state in this functions is a + // correct & proper way of handling fn on_finalize(block_number: T::BlockNumber) { // Prepare and validate data for campaign settlement for campaign_id in &CampaignsByBlock::::get(BlockType::Expiry, block_number) { @@ -336,6 +338,8 @@ pub mod pallet { log::error!(target: "runtime::gamedao_flow", "Campaign unknown: '{:?}'", campaign_id); continue } + // SBP-M2 review: Do not unwrap + // Use error handling let campaign = maybe_campaign.unwrap(); let maybe_treasury_id = T::Control::org_treasury_account(&campaign.org_id); if maybe_treasury_id.is_none() { @@ -353,7 +357,7 @@ pub mod pallet { } if contributors.len() as u32 > T::MaxCampaignContributors::get() { log::error!( - target: "runtime::gamedao_flow", "MaxCampaignContributors exceeds limits {}, + target: "runtime::gamedao_flow", "MaxCampaignContributors exceeds limits {}, campaign '{:?}' haven't been scheduled for settlement", T::MaxCampaignContributors::get(), campaign_id, ); @@ -382,9 +386,9 @@ pub mod pallet { /// - `token_symbol`: a new custom token symbol /// - `token_name`: a new custom token name /// - `start`: - /// - /// The two params `token_symbol` and `token_name` are meant for setting up a new custom token if creator wants to - /// conduct a token generation event. Therefore these two are optionals and would result in a TGE dropping + /// + /// The two params `token_symbol` and `token_name` are meant for setting up a new custom token if creator wants to + /// conduct a token generation event. Therefore these two are optionals and would result in a TGE dropping /// fungible token with a new currency id to contributors. /// /// Emits `CampaignCreated` event when successful. @@ -416,7 +420,7 @@ pub mod pallet { let min_deposit = T::MinCampaignDeposit::get().mul_floor(target); ensure!(deposit >= min_deposit, Error::::DepositInsufficient); ensure!(deposit <= target, Error::::DepositTooHigh); - + // Campaign start/expiry validation: let current_block = >::block_number(); let starts = start.unwrap_or(current_block); @@ -429,7 +433,7 @@ pub mod pallet { let index = CampaignCount::::get(); let campaign = types::Campaign { index, org_id, name: name.clone(), owner: creator.clone(), - admin: admin_id.clone(), deposit, start: starts, expiry, cap: target, + admin: admin_id.clone(), deposit, start: starts, expiry, cap: target, protocol, governance, cid, token_symbol, token_name, created: current_block, }; @@ -463,7 +467,7 @@ pub mod pallet { Error::::NoContributionsAllowed ); ensure!(contribution >= T::MinContribution::get(), Error::::ContributionInsufficient); - + Self::create_contribution(sender.clone(), campaign_id, contribution)?; Self::deposit_event(Event::Contributed { campaign_id, sender, @@ -534,6 +538,7 @@ impl Pallet { campaign_id: T::Hash, org_treasury: &T::AccountId, ) { + // SBP-M2 review: consider match clause if campaign_state == &CampaignState::Succeeded { let contributor_balance = CampaignContribution::::get(campaign_id, &contributor); let _transfer_amount = T::Currency::repatriate_reserved( @@ -557,6 +562,7 @@ impl Pallet { org_treasury: T::AccountId, block_number: T::BlockNumber, ) { + // SBP-M2 review: consider match clause if campaign_state == &CampaignState::Succeeded { let commission = T::CampaignFee::get().mul_floor(campaign_balance.clone()); let _transfer_commission = T::Currency::repatriate_reserved( @@ -607,6 +613,7 @@ impl FlowTrait for Pallet { } } +// SBP-M2 review: move benchmarking stuff to benchmarking/mock module impl FlowBenchmarkingTrait for Pallet { /// ** Should be used for benchmarking only!!! ** @@ -626,7 +633,7 @@ impl FlowBenchmarkingTrait for deposit: T::MinContribution::get(), start, expiry: start + 57_600_u32.into(), // 60/3*60*24*2 (2 days with 3 sec block time) - cap: target, + cap: target, protocol: FlowProtocol::default(), governance: FlowGovernance::default(), cid: bounded_str.clone(), diff --git a/flow/src/tests.rs b/flow/src/tests.rs index 2e77030d3..8d65c8e0f 100644 --- a/flow/src/tests.rs +++ b/flow/src/tests.rs @@ -53,7 +53,7 @@ pub fn create_campaign( deposit, start, expiry, - cap: target, + cap: target, protocol: FlowProtocol::default(), governance: FlowGovernance::default(), cid: bounded_str.clone(), @@ -68,6 +68,7 @@ pub fn create_campaign( // TODO: error ContributionInsufficient #[test] +// SBP-M2 review: I would split into separate test cases fn flow_create_errors() { new_test_ext().execute_with(|| { let (org_id, _, _) = create_org_treasury(); @@ -324,7 +325,7 @@ fn flow_on_finalize_campaign_succeess() { campaign_rev.deposit, campaign_rev.expiry, campaign_rev.protocol.clone(), campaign_rev.governance.clone(), campaign_rev.cid.clone(), None, None, None )); - + // Contribute (10/500) assert_ok!(Flow::contribute(Origin::signed(1), campaign_id_rev, 10 * DOLLARS)); @@ -483,7 +484,7 @@ fn flow_on_finalize_campaign_failed() { System::set_block_number(expiry + 1); Flow::on_initialize(expiry + 1); - // Account's balance from the first batch was unlocked + // Account's balance from the first batch was unlocked assert_eq!(::Currency::free_balance(PAYMENT_TOKEN_ID, &c[0]), INIT_BALANCE); assert_eq!(::Currency::free_balance(PAYMENT_TOKEN_ID, &c[1]), INIT_BALANCE); assert_eq!(::Currency::free_balance(PAYMENT_TOKEN_ID, &c[2]), INIT_BALANCE); diff --git a/sense/src/lib.rs b/sense/src/lib.rs index 0e0a50a99..087498dfd 100644 --- a/sense/src/lib.rs +++ b/sense/src/lib.rs @@ -48,33 +48,33 @@ pub mod pallet { pub struct Pallet(_); /// Sense Entity of the account. - /// + /// /// Entities: map AccountId => Entity #[pallet::storage] #[pallet::getter(fn get_entity)] - pub(super) type Entities = StorageMap<_, - Blake2_128Concat, + pub(super) type Entities = StorageMap<_, + Blake2_128Concat, T::AccountId, - Entity>, + Entity>, OptionQuery >; /// EntityCount. Increase per each entity creation. - /// + /// /// EntityCount: u128 #[pallet::storage] #[pallet::getter(fn get_entity_count)] pub type EntityCount = StorageValue<_, u128, ValueQuery>; /// All properties of the account. - /// + /// /// Properties: map (PropertyType, AccountId) => EntityProperty #[pallet::storage] #[pallet::getter(fn get_property)] - pub(super) type Properties = StorageDoubleMap<_, + pub(super) type Properties = StorageDoubleMap<_, Blake2_128Concat, PropertyType, - Blake2_128Concat, T::AccountId, - EntityProperty, + Blake2_128Concat, T::AccountId, + EntityProperty, OptionQuery >; @@ -83,13 +83,13 @@ pub mod pallet { pub enum Event { /// New Sense Entity was created. EntityCreated{ - account_id: T::AccountId, + account_id: T::AccountId, block_number: T::BlockNumber }, /// Property was updated. PropertyUpdated{ property_type: PropertyType, - account_id: T::AccountId, + account_id: T::AccountId, block_number: T::BlockNumber }, } @@ -112,7 +112,7 @@ pub mod pallet { impl Pallet { /// Create a Sense Entity for the account. - /// + /// /// Parameters: /// - `account_id`: account id. /// - `cid`: IPFS content identifier. @@ -126,6 +126,7 @@ pub mod pallet { account_id: T::AccountId, cid: BoundedVec, ) -> DispatchResult { + // SBP-M2 review: create entity like a council instead of Sudo ensure_root(origin)?; ensure!(cid.len() > 0, Error::::InvalidParam); ensure!(!Entities::::contains_key(account_id.clone()), Error::::EntityExists); @@ -142,12 +143,13 @@ pub mod pallet { Self::save_entity(account_id.clone(), entity, count, experience, reputation, trust); Self::deposit_event(Event::EntityCreated{ - account_id, + account_id, block_number: current_block }); Ok(()) } + // SBP-M2 review: #TODO comment // TODO: // mutation of values should be restricted // certain roles are allowed to mutate values @@ -158,7 +160,7 @@ pub mod pallet { // sudo ( until its removal ) /// Modifies a property of the account. - /// + /// /// Parameters: /// - `account_id`: account id. /// - `property_type`: property type (Experience, Reputation, Trust). @@ -169,16 +171,19 @@ pub mod pallet { /// Weight: `O(1)` #[pallet::weight(::WeightInfo::update_property())] pub fn update_property( - origin: OriginFor, - account_id: T::AccountId, - property_type: PropertyType, + origin: OriginFor, + account_id: T::AccountId, + property_type: PropertyType, value: u8 ) -> DispatchResult { + // SBP-M2 review: another Sudo call... ensure_root(origin)?; ensure!(Entities::::contains_key(account_id.clone()), Error::::EntityUnknown); let current_block = >::block_number(); let v = u64::from(value); + // SBP-M2 review: do not use `unwrap` + // Apply error handling let current = Self::get_property(property_type.clone(), account_id.clone()).unwrap(); let updated = EntityProperty::new( current.get_value().checked_add(v).ok_or(Error::::EntityPropertyOverflow)?, @@ -189,7 +194,7 @@ pub mod pallet { Self::deposit_event(Event::PropertyUpdated{ property_type, - account_id, + account_id, block_number: current_block }); Ok(()) @@ -198,11 +203,11 @@ pub mod pallet { impl Pallet { fn save_entity( - account_id: T::AccountId, - entity: Entity>, - count: u128, - experience: EntityProperty, - reputation: EntityProperty, + account_id: T::AccountId, + entity: Entity>, + count: u128, + experience: EntityProperty, + reputation: EntityProperty, trust: EntityProperty ) { Entities::::insert(account_id.clone(), entity); diff --git a/signal/src/lib.rs b/signal/src/lib.rs index 18c3e957d..56f5e4ecb 100644 --- a/signal/src/lib.rs +++ b/signal/src/lib.rs @@ -49,8 +49,8 @@ pub use pallet::*; pub use weights::WeightInfo; type Proposal = types::Proposal< - ::Hash, ::BlockNumber, - ::AccountId, ::Balance, + ::Hash, ::BlockNumber, + ::AccountId, ::Balance, ::CurrencyId, BoundedVec::StringLimit> >; @@ -111,7 +111,7 @@ pub mod pallet { /// Weight information for extrinsics in this module. type WeightInfo: WeightInfo; - + /// The CurrencyId which is used as a payment token. #[pallet::constant] type PaymentTokenId: Get; @@ -158,7 +158,7 @@ pub mod pallet { /// /// Proposals: map Hash => Proposal #[pallet::storage] - pub(super) type ProposalOf = + pub(super) type ProposalOf = StorageMap<_, Blake2_128Concat, T::Hash, Proposal, OptionQuery>; @@ -166,7 +166,7 @@ pub mod pallet { /// /// ProposalStates: map Hash => ProposalState #[pallet::storage] - pub(super) type ProposalStates = + pub(super) type ProposalStates = StorageMap<_, Blake2_128Concat, T::Hash, ProposalState, ValueQuery, GetDefault>; /// Proposals ending in a block. @@ -175,7 +175,7 @@ pub mod pallet { #[pallet::storage] pub(super) type ProposalsByBlock = StorageDoubleMap<_, Blake2_128Concat, BlockType, Blake2_128Concat, T::BlockNumber, BoundedVec, ValueQuery>; - + #[pallet::storage] pub type ProposalCount = StorageValue<_, ProposalIndex, ValueQuery>; @@ -242,6 +242,7 @@ pub mod pallet { #[pallet::weight(T::WeightInfo::proposal())] #[transactional] + // SBP-M2 review: I would recommend some refactor; too long function pub fn proposal( origin: OriginFor, proposal_type: ProposalType, @@ -288,7 +289,7 @@ pub mod pallet { ensure!(scale != Scale::Quadratic, Error::::WrongParameter); } Unit::Token => { - // Since it's not possible to calculate eligible voting power, + // Since it's not possible to calculate eligible voting power, // Absolute majority and quorum doesn't work for Unit::Token ensure!(majority != Majority::Absolute, Error::::WrongParameter); ensure!(quorum.is_none(), Error::::WrongParameter); @@ -306,7 +307,7 @@ pub mod pallet { let campaign_owner = T::Flow::campaign_owner(&c_id).ok_or(Error::::AuthorizationError)?; ensure!(proposer == campaign_owner, Error::::AuthorizationError); ensure!(T::Flow::is_campaign_succeeded(&c_id), Error::::CampaignUnsucceeded); - + let used_balance = CampaignBalanceUsed::::get(&c_id); let total_balance = T::Flow::campaign_balance(&c_id); let remaining_balance = total_balance @@ -376,6 +377,8 @@ pub mod pallet { }, ProposalType::Withdrawal => { ensure!( + // SBP-M2 review: do not use `unwrap` + // Add error handling T::Flow::is_campaign_contributor(&proposal.campaign_id.unwrap(), &who), Error::::AuthorizationError ); @@ -423,11 +426,12 @@ pub mod pallet { if !voting_exists || !proposal_exists { continue; // should never happen } + // SBP-M2 review: just another comment about `unwrap` let voting = ProposalVoting::::get(&proposal_id).unwrap(); // Get the final state based on Voting participation, quorum, majority proposal_state = Self::get_final_proposal_state(&voting); - + Self::finalize_proposal(&proposal_id, proposal_state, &voting); } } @@ -440,21 +444,22 @@ pub mod pallet { match voting.unit { Unit::Account => { match voting.scale { - Scale::Linear => { + Scale::Linear => { power = 1; } - Scale::Quadratic => { + Scale::Quadratic => { // So far not possible, maybe in case of delegation } } } Unit::Token => { + // SBP-M2 review: `unwrap` let linear_power: VotingPower = deposit.unwrap().saturated_into(); match voting.scale { - Scale::Linear => { + Scale::Linear => { power = linear_power; } - Scale::Quadratic => { + Scale::Quadratic => { let linear_power: VotingPower = deposit.unwrap().saturated_into(); power = linear_power.integer_sqrt(); } @@ -491,6 +496,7 @@ pub mod pallet { } } _ => { + // SBP-M2 review: #TODO comment // TODO: Collect other cases when voting could be finalized earlier } } @@ -552,6 +558,8 @@ pub mod pallet { ProposalVoting::::insert(&proposal_id, &voting); + // SBP-M2 review: what if proposal is not finalized? + // Is it properly handled? // For Absolute majority if more then 50% of members vote for one option, the proposal period ends earlier. if let Some(final_proposal_state) = Self::try_finalize_proposal(&voting) { Self::finalize_proposal(&proposal_id, final_proposal_state, &voting); @@ -679,6 +687,7 @@ pub mod pallet { let campaign_id = proposal.campaign_id.unwrap(); let amount = proposal.amount.unwrap(); T::Currency::unreserve( + // SBP-M2 review: `unwrap` proposal.currency_id.unwrap(), &T::Control::org_treasury_account(&proposal.org_id).unwrap(), amount); let used_balance = CampaignBalanceUsed::::get(&campaign_id); @@ -692,6 +701,7 @@ pub mod pallet { &proposal.beneficiary.as_ref().unwrap(), proposal.amount.unwrap(), BalanceStatus::Free); + // SBP-M2 review: why not proper error handling here? debug_assert!(res.is_ok()); return ProposalState::Finalized; } @@ -714,7 +724,8 @@ pub mod pallet { let org_share = proposal.deposit - gamedao_share; let gamedo_trsry = T::GameDAOTreasury::get(); let org_trsry = T::Control::org_treasury_account(&proposal.org_id).unwrap(); - + + // SBP-M2 review: there must be proper error handling on these operations let res = T::Currency::transfer(currency_id, &proposal.owner, &gamedo_trsry, gamedao_share); debug_assert!(res.is_ok()); let res = T::Currency::transfer(currency_id, &proposal.owner, &org_trsry, org_share); diff --git a/signal/src/tests.rs b/signal/src/tests.rs index bd0f34193..d8d369d28 100644 --- a/signal/src/tests.rs +++ b/signal/src/tests.rs @@ -18,6 +18,8 @@ use frame_support::{ /// Test 0.0 /// - Proposal validation Errors +// SBP-M2 review: I would split into separate test cases +// SBP-M2 review: Tests should have self-explanatory names #[test] fn signal_0_0() { ExtBuilder::default().build().execute_with(|| { @@ -287,7 +289,7 @@ fn signal_0_2() { let expiry: BlockNumber = now + 20; let (proposal_id, proposal) = create_proposal( ProposalType::General, org_id, start, expiry, 20 * DOLLARS, None, None, None, None); - + assert_ok!(Signal::proposal( Origin::signed(ALICE), proposal.proposal_type.clone(), proposal.org_id, proposal.title.clone(), proposal.cid.clone(), proposal.expiry, @@ -404,7 +406,7 @@ fn signal_1_0() { // Check if deposit was reserved assert_eq!(::Currency::total_balance(PROTOCOL_TOKEN_ID, &ALICE), total_balance); assert_eq!(::Currency::free_balance(PROTOCOL_TOKEN_ID, &ALICE), total_balance - deposit); - + System::assert_has_event(Event::Signal(crate::Event::Created { account: ALICE, proposal_id: proposal_id.clone(), @@ -438,7 +440,7 @@ fn signal_1_0() { yes: members.len().saturated_into(), no: 1, })); - + // Hop to the proposal's expiry block and check proposal finalized System::set_block_number(expiry); Signal::on_finalize(expiry); @@ -496,7 +498,7 @@ fn signal_1_1() { yes: 0, no: (members.len() + 1).saturated_into(), })); - + // Hop to the proposal's expiry block and check proposal finalized System::set_block_number(expiry); Signal::on_finalize(expiry); @@ -508,7 +510,7 @@ fn signal_1_1() { // Check if deposit was slashed assert_eq!(::Currency::free_balance(PROTOCOL_TOKEN_ID, &ALICE), total_balance - deposit); - + // TODO: check balances of GameDAO and Org treasury }); @@ -733,7 +735,7 @@ fn signal_1_6() { } // Proposal creator votes "NO" assert_ok!(Signal::vote(Origin::signed(ALICE), proposal_id, false, Some(voting_deposit))); - + // Hop to the proposal's expiry block and check proposal finalized System::set_block_number(expiry); Signal::on_finalize(expiry); @@ -780,7 +782,7 @@ fn signal_1_7() { } // Proposal creator votes "YES" assert_ok!(Signal::vote(Origin::signed(ALICE), proposal_id, true, None)); - + // Hop to the proposal's expiry block and check proposal finalized System::set_block_number(expiry); Signal::on_finalize(expiry); @@ -827,7 +829,7 @@ fn signal_1_8() { assert_ok!(Signal::vote(Origin::signed(0), proposal_id, false, None)); // Proposal creator votes "YES" assert_ok!(Signal::vote(Origin::signed(ALICE), proposal_id, true, None)); - + // Hop to the proposal's expiry block and check proposal finalized System::set_block_number(expiry); Signal::on_finalize(expiry); @@ -870,11 +872,11 @@ fn signal_2_0() { let total_balance = 100 * DOLLARS - 1 * DOLLARS; // org creation fee let deposit = 20 * DOLLARS; let withdrawal_amount = 10 * DOLLARS; - + let campaign_expiry = now + 2 * DAYS; let campaign_id = create_finalize_campaign(now, org_id, &contributors, contribution, campaign_expiry, true); - + // Check if campaign was finalized and all treasury balance is reserved assert_eq!(::Currency::total_balance(currency, &treasury_id), total_contribution - commission); assert_eq!(::Currency::free_balance(currency, &treasury_id), 0); @@ -897,7 +899,7 @@ fn signal_2_0() { for x in &contributors { assert_ok!(Signal::vote(Origin::signed(*x), proposal_id, true, None)); } - + // Check if proposal finalized earlier System::assert_has_event(Event::Signal(crate::Event::Finalized { proposal_id: proposal_id.clone(), @@ -941,7 +943,7 @@ fn signal_2_0() { for x in &members { assert_ok!(Signal::vote(Origin::signed(*x), proposal_id, true, None)); } - + // Hop to the proposal's expiry block and check proposal finalized System::set_block_number(expiry); Signal::on_finalize(expiry); @@ -988,10 +990,10 @@ fn signal_2_1() { let total_balance = 100 * DOLLARS - 1 * DOLLARS; // org creation fee let deposit = 20 * DOLLARS; let withdrawal_amount = 10 * DOLLARS; - + let campaign_expiry = now + 2 * DAYS; let campaign_id = create_finalize_campaign(now, org_id, &contributors, contribution, campaign_expiry, true); - + // Check if campaign was finalized and all treasury balance is reserved assert_eq!(::Currency::total_balance(currency, &treasury_id), total_contribution - commission); assert_eq!(::Currency::free_balance(currency, &treasury_id), 0); @@ -1014,7 +1016,7 @@ fn signal_2_1() { for x in &contributors { assert_ok!(Signal::vote(Origin::signed(*x), proposal_id, true, None)); } - + // Check if proposal finalized earlier System::assert_has_event(Event::Signal(crate::Event::Finalized { proposal_id: proposal_id.clone(), @@ -1055,7 +1057,7 @@ fn signal_2_1() { for x in &members { assert_ok!(Signal::vote(Origin::signed(*x), proposal_id, false, None)); } - + // Hop to the proposal's expiry block and check proposal finalized System::set_block_number(expiry); Signal::on_finalize(expiry); @@ -1096,7 +1098,7 @@ fn signal_2_2() { let withdrawal_amount = 10 * DOLLARS; let campaign_expiry = now + 2 * DAYS; let campaign_id = create_finalize_campaign(now, org_id, &contributors, contribution, campaign_expiry, true); - + // Check if campaign was finalized and all treasury balance is reserved assert_eq!(::Currency::total_balance(currency, &treasury_id), total_contribution - commission); assert_eq!(::Currency::free_balance(currency, &treasury_id), 0); @@ -1119,7 +1121,7 @@ fn signal_2_2() { for x in &contributors { assert_ok!(Signal::vote(Origin::signed(*x), proposal_id, false, None)); } - + // Hop to the proposal's expiry block and check proposal finalized System::set_block_number(expiry); Signal::on_finalize(expiry); From 764f40ce77299f7c3a0c817f35d95f64d5d3fa70 Mon Sep 17 00:00:00 2001 From: vasylenko-yevhen Date: Wed, 2 Nov 2022 22:43:21 +0200 Subject: [PATCH 03/49] USE ORML dependencies from github instead of local version --- control/Cargo.toml | 6 +++--- flow/Cargo.toml | 6 +++--- signal/Cargo.toml | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/control/Cargo.toml b/control/Cargo.toml index c6ba4934e..8f4e4f792 100755 --- a/control/Cargo.toml +++ b/control/Cargo.toml @@ -32,7 +32,7 @@ sp-io = { git = "https://github.com/paritytech/substrate.git", branch = "polkado pallet-balances = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.28" } -orml-traits = { path = "../../orml/traits", default-features = false } +orml-traits = { git = 'https://github.com/open-web3-stack/open-runtime-module-library', branch= 'polkadot-v0.9.28', default-features = false } gamedao-traits = { package = "gamedao-traits", path = "../traits", default-features = false } # tangram = { package = "module-tangram", path = "../../zero/tangram", default-features = false } @@ -42,8 +42,8 @@ sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkad sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.28" } frame-support-test = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.28" } pallet-balances = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.28" } -orml-tokens = { path = "../../orml/tokens", default-features = false } -orml-currencies = { path = "../../orml/currencies", default-features = false } +orml-tokens = { git = 'https://github.com/open-web3-stack/open-runtime-module-library', branch= 'polkadot-v0.9.28', default-features = false } +orml-currencies = { git = 'https://github.com/open-web3-stack/open-runtime-module-library', branch= 'polkadot-v0.9.28', default-features = false } [features] default = ["std"] diff --git a/flow/Cargo.toml b/flow/Cargo.toml index c7ae09af7..8784d5bd4 100644 --- a/flow/Cargo.toml +++ b/flow/Cargo.toml @@ -23,9 +23,9 @@ frame-system = { git = "https://github.com/paritytech/substrate", branch = "polk frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.28", default-features = false, optional = true } sp-io = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.28", default-features=false } -orml-traits = { path = "../../orml/traits", default-features = false } -orml-tokens = { path = "../../orml/tokens", optional = true } -orml-currencies = { path = "../../orml/currencies", optional = true } +orml-traits = { git = 'https://github.com/open-web3-stack/open-runtime-module-library', branch= 'polkadot-v0.9.28', default-features = false } +orml-tokens = { git = 'https://github.com/open-web3-stack/open-runtime-module-library', branch= 'polkadot-v0.9.28', optional = true } +orml-currencies = { git = 'https://github.com/open-web3-stack/open-runtime-module-library', branch= 'polkadot-v0.9.28', optional = true } gamedao-traits = { package = "gamedao-traits", path = "../traits", default-features = false } gamedao-control = { package = "gamedao-control", path = "../control", optional = true } diff --git a/signal/Cargo.toml b/signal/Cargo.toml index dd4fa23f9..74c1b43b3 100644 --- a/signal/Cargo.toml +++ b/signal/Cargo.toml @@ -29,7 +29,7 @@ sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.28", default-features = false } frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.28", default-features = false } frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.28", default-features = false, optional = true } -orml-traits = { path = "../../orml/traits", default-features = false } +orml-traits = { git = 'https://github.com/open-web3-stack/open-runtime-module-library', branch= 'polkadot-v0.9.28', default-features = false } gamedao-traits = { package = "gamedao-traits", path = "../traits", default-features = false } sp-io = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.28", default-features=false } @@ -41,8 +41,8 @@ frame-support-test = { git = "https://github.com/paritytech/substrate.git", bran pallet-balances = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.28" } pallet-timestamp = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.28" } -orml-tokens = { path = "../../orml/tokens", default-features = false } -orml-currencies = { path = "../../orml/currencies", default-features = false } +orml-tokens = { git = 'https://github.com/open-web3-stack/open-runtime-module-library', branch= 'polkadot-v0.9.28', default-features = false } +orml-currencies = { git = 'https://github.com/open-web3-stack/open-runtime-module-library', branch= 'polkadot-v0.9.28', default-features = false } gamedao-control = { path = "../control", default-features = true } gamedao-flow = { path = "../flow", default-features = true } From b023d59a4dc14b95e58578ac1f33014e8646ee04 Mon Sep 17 00:00:00 2001 From: 2075 <2075@zero.io> Date: Fri, 11 Nov 2022 20:43:27 +0100 Subject: [PATCH 04/49] fix: rm warnings --- control/src/lib.rs | 2 +- flow/src/lib.rs | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/control/src/lib.rs b/control/src/lib.rs index 0dcbe8aca..25b9bcb8c 100755 --- a/control/src/lib.rs +++ b/control/src/lib.rs @@ -22,7 +22,7 @@ pub mod weights; use codec::Codec; use frame_support::{dispatch::{DispatchResult, DispatchError, RawOrigin}, - ensure, PalletId, traits::Get, weights::Weight, BoundedVec, transactional + ensure, PalletId, traits::Get, BoundedVec, transactional }; use gamedao_traits::{ControlTrait, ControlBenchmarkingTrait}; use orml_traits::{MultiCurrency, MultiReservableCurrency}; diff --git a/flow/src/lib.rs b/flow/src/lib.rs index 90af3cf95..cd91702cf 100644 --- a/flow/src/lib.rs +++ b/flow/src/lib.rs @@ -46,7 +46,7 @@ mod benchmarking; pub mod weights; use frame_support::{ - dispatch::{DispatchResult, DispatchError, DispatchResultWithPostInfo}, + dispatch::{DispatchResult, DispatchError}, traits::{Get, BalanceStatus, Hooks}, weights::Weight, BoundedVec, log, transactional }; @@ -54,8 +54,7 @@ use frame_support::{ use scale_info::TypeInfo; use sp_runtime::{traits::{AtLeast32BitUnsigned, Hash}, Permill, ArithmeticError::Overflow}; -use sp_std::{vec, vec::Vec, convert::{TryFrom, TryInto}}; - +use sp_std::{vec::Vec, convert::{TryFrom, TryInto}}; use gamedao_traits::{ControlTrait, ControlBenchmarkingTrait, FlowTrait, FlowBenchmarkingTrait}; use orml_traits::{MultiCurrency, MultiReservableCurrency}; From 41fbf3c09cfe57a2d030ebdde6aaf96dd156d948 Mon Sep 17 00:00:00 2001 From: Yura Date: Tue, 13 Dec 2022 16:15:02 +0100 Subject: [PATCH 05/49] M2 review fixes (#115) --- control/src/lib.rs | 66 ++++++++------------------ control/src/tests.rs | 3 -- flow/src/lib.rs | 89 +++++++++++++++++----------------- flow/src/tests.rs | 1 - sense/src/lib.rs | 18 ++----- sense/src/tests.rs | 5 ++ signal/src/lib.rs | 110 ++++++++++++++++++++++--------------------- signal/src/tests.rs | 2 - signal/src/types.rs | 22 ++++++--- 9 files changed, 145 insertions(+), 171 deletions(-) mode change 100755 => 100644 control/src/lib.rs diff --git a/control/src/lib.rs b/control/src/lib.rs old mode 100755 new mode 100644 index 25b9bcb8c..fa631566e --- a/control/src/lib.rs +++ b/control/src/lib.rs @@ -22,7 +22,7 @@ pub mod weights; use codec::Codec; use frame_support::{dispatch::{DispatchResult, DispatchError, RawOrigin}, - ensure, PalletId, traits::Get, BoundedVec, transactional + ensure, PalletId, traits::Get, BoundedVec, transactional, log }; use gamedao_traits::{ControlTrait, ControlBenchmarkingTrait}; use orml_traits::{MultiCurrency, MultiReservableCurrency}; @@ -177,10 +177,8 @@ pub mod pallet { .iter() .for_each(|(creator, prime, treasury_id, name, cid, org_type, access_model, fee_model, membership_fee, gov_currency, pay_currency, member_limit, deposit)| { - // SBP-M2 review: for genesis build block number should be known - let now = frame_system::Pallet::::block_number(); + let now = T::BlockNumber::from(0u32); let index = OrgCount::::get(); - // SBP-M2 review: think about some kind of `new` function for `types::Org` let org: Org = types::Org { index, creator: creator.clone(), prime: prime.clone(), name: name.clone(), cid: cid.clone(), org_type: org_type.clone(), fee_model: fee_model.clone(), membership_fee: Some(*membership_fee), @@ -189,20 +187,15 @@ pub mod pallet { }; let org_id = ::Hashing::hash_of(&org); - // SBP-M2 review: you should print some logs if sth goes wrong while genesis build - // Unwrap will not help you with debugging - Pallet::::do_create_org(org_id.clone(), &org, treasury_id.clone(), *deposit).unwrap(); - Pallet::::do_add_member(org_id, creator.clone(), MemberState::Active).unwrap(); - Pallet::::pay_membership_fee( - &creator, &treasury_id, Some(*membership_fee), fee_model.clone(), *gov_currency).unwrap(); + if Pallet::::do_create_org(org_id.clone(), &org, treasury_id.clone(), *deposit).is_err() { log::error!("Error creating organization in genesis.") }; + if Pallet::::do_add_member(org_id, creator.clone(), MemberState::Active).is_err() { log::error!("Error adding member in genesis.") }; + if Pallet::::pay_membership_fee(&creator, &treasury_id, &org).is_err() { log::error!("Error paying membership fee in genesis.") }; }); } } #[pallet::event] #[pallet::generate_deposit(pub(super) fn deposit_event)] - // SBP-M2 review: I would suggest limiting events' attributes. - // When someone is interested, there should be a possibility to query current state. pub enum Event { /// Org was successfully created. OrgCreated { @@ -333,7 +326,6 @@ pub mod pallet { ensure!(!>::account_exists(&treasury_id), Error::::TreasuryExists); let now = frame_system::Pallet::::block_number(); - // SBP-M2 review: I definiately suggest having `types::Org::new` function :) let org = types::Org { index, creator: sender.clone(), prime: sender.clone(), name, cid, org_type, fee_model: fee_model.clone(), membership_fee: membership_fee.clone(), gov_currency, @@ -344,7 +336,7 @@ pub mod pallet { Self::do_create_org(org_id, &org, treasury_id.clone(), deposit)?; Self::do_add_member(org_id, sender.clone(), MemberState::Active)?; - Self::pay_membership_fee(&sender, &treasury_id, membership_fee, fee_model, gov_currency)?; + Self::pay_membership_fee(&sender, &treasury_id, &org)?; Ok(()) } @@ -378,7 +370,6 @@ pub mod pallet { membership_fee: Option, ) -> DispatchResult { let mut org = Orgs::::get(&org_id).ok_or(Error::::OrganizationUnknown)?; - // SBP-M2 review: Get rid of Sudo calls // Create entity like a council Self::ensure_root_or_prime(origin, org.prime.clone(), org.org_type.clone())?; @@ -386,17 +377,17 @@ pub mod pallet { access_model.is_some(), member_limit.is_some(), org_type.is_some()]; ensure!(args.iter().any(|x| *x == true), Error::::NoChangesProvided); - // SBP-M2 review: I do not like these instructions with pattern matching - // I would use quick check `is_some`: https://doc.rust-lang.org/std/option/enum.Option.html#method.is_some - if let Some(access_model) = access_model.clone() { org.access_model = access_model; }; - if let Some(org_type) = org_type.clone() { org.org_type = org_type; }; - if let Some(member_limit) = member_limit.clone() { org.member_limit = member_limit; }; - if let Some(_) = membership_fee.clone() { org.membership_fee = membership_fee; }; - if let Some(prime_id) = prime_id.clone() { + if access_model.is_some() { org.access_model = access_model.clone().unwrap(); }; + if org_type.is_some() { org.org_type = org_type.clone().unwrap(); }; + if member_limit.is_some() { org.member_limit = member_limit.clone().unwrap(); }; + if membership_fee.is_some() { org.membership_fee = membership_fee.clone(); }; + if prime_id.is_some() { + let prime_id = prime_id.clone().unwrap(); ensure!(MemberStates::::contains_key(&org_id, &prime_id), Error::::NotMember); org.prime = prime_id; }; - if let Some(fee_model) = fee_model.clone() { + if fee_model.is_some() { + let fee_model = fee_model.clone().unwrap(); if fee_model != FeeModel::NoFees && membership_fee.is_none() { return Err(Error::::MissingParameter)? }; @@ -428,7 +419,6 @@ pub mod pallet { #[pallet::weight(T::WeightInfo::enable_org())] pub fn enable_org(origin: OriginFor, org_id: T::Hash) -> DispatchResult { let org = Orgs::::get(&org_id).ok_or(Error::::OrganizationUnknown)?; - // SBP-M2 review: same comment about Sudo pallet Self::ensure_root_or_prime(origin, org.prime, org.org_type)?; OrgStates::::insert(org_id.clone(), OrgState::Active); @@ -450,7 +440,6 @@ pub mod pallet { #[pallet::weight(T::WeightInfo::disable_org())] pub fn disable_org(origin: OriginFor, org_id: T::Hash) -> DispatchResult { let org = Orgs::::get(&org_id).ok_or(Error::::OrganizationUnknown)?; - // SBP-M2 review: same comment about Sudo pallet Self::ensure_root_or_prime(origin, org.prime, org.org_type)?; OrgStates::::insert(org_id.clone(), OrgState::Inactive); @@ -480,11 +469,9 @@ pub mod pallet { _ => MemberState::Pending, }; let treasury_id = OrgTreasury::::get(org_id).ok_or(Error::::TreasuryUnknown)?; - // SBP-M2 review: you could rewrite this function to pass `org` struct and then unpack it inside - Self::pay_membership_fee(&org.prime, &treasury_id, org.membership_fee, org.fee_model, org.gov_currency)?; + Self::pay_membership_fee(&org.prime, &treasury_id, &org)?; let members_count = Self::do_add_member(org_id, who.clone(), member_state)?; - // SBP-M2 review: why do you return WeightInfo in extrinsics? Ok(Some(T::WeightInfo::add_member(members_count)).into()) } @@ -503,12 +490,9 @@ pub mod pallet { Self::ensure_membership_permissions(origin, who.clone(), org.prime.clone(), org.org_type.clone(), org.access_model.clone())?; let member_count = Self::do_remove_member(org_id.clone(), who.clone())?; if org.fee_model == FeeModel::Reserve { - // SBP-M2 review: you should not use `unwrap` in extrinsics - // Apply error handling - T::Currency::unreserve(org.gov_currency, &who, org.membership_fee.unwrap()); + T::Currency::unreserve(org.gov_currency, &who, org.membership_fee.ok_or(Error::::MissingParameter)?); } - // SBP-M2 review: same comment about returning `WeightInfo` Ok(Some(T::WeightInfo::remove_member(member_count)).into()) } @@ -536,7 +520,6 @@ pub mod pallet { ) -> DispatchResult { let org = Orgs::::get(&org_id).ok_or(Error::::OrganizationUnknown)?; let treasury_id = OrgTreasury::::get(org_id).ok_or(Error::::TreasuryUnknown)?; - // SBP-M2 review: same comment about Sudo pallet Self::ensure_root_or_prime(origin, org.prime, org.org_type)?; T::Currency::transfer(currency_id, &treasury_id, &beneficiary, amount @@ -567,8 +550,6 @@ impl Pallet { Orgs::::insert(&org_id, org); - // SBP-M2 review: I strongly suggest emitting events in extrinsics - // It clarifies code and its responsibility Self::deposit_event(Event::OrgCreated { org_id, creator, treasury_id, created_at, realm_index: 0 }); Ok(()) } @@ -587,7 +568,6 @@ impl Pallet { MemberStates::::insert(&org_id, &who, member_state); let block_number = frame_system::Pallet::::block_number(); - // SBP-M2 review: same comment about events Self::deposit_event(Event::MemberAdded { org_id, who, block_number }); Ok(members_count) @@ -612,26 +592,23 @@ impl Pallet { fn pay_membership_fee( who: &T::AccountId, treasury_id: &T::AccountId, - fee: Option, - fee_model: FeeModel, - gov_currency_id: T::CurrencyId + org: &Org ) -> Result<(), DispatchError> { - match fee_model { + match org.fee_model { FeeModel::NoFees => {}, FeeModel::Reserve => { - T::Currency::reserve(gov_currency_id, &who, fee.unwrap() + T::Currency::reserve(org.gov_currency, &who, org.membership_fee.unwrap() ).map_err(|_| Error::::BalanceLow)?; }, FeeModel::Transfer => { T::Currency::transfer( - gov_currency_id, &who, &treasury_id, fee.unwrap() + org.gov_currency, &who, &treasury_id, org.membership_fee.unwrap() ).map_err(|_| Error::::BalanceLow)?; } }; Ok(()) } - // SBP-M2 review: same comment about Sudo pallet fn ensure_membership_permissions( origin: T::Origin, who: T::AccountId, @@ -668,7 +645,6 @@ impl Pallet { fn ensure_root_or_governance(origin: T::Origin) -> Result<(), BadOrigin> { match origin.into() { Ok(RawOrigin::Root) => Ok(()), - // SBP-M2 review: #TODO comment not implemented // TODO: implement governance origin type _ => Err(BadOrigin), } @@ -711,8 +687,6 @@ impl ControlTrait for Pallet { } } -// SBP-M2 review: if functions for benchmarking -// Move to benchmarking or mock module impl ControlBenchmarkingTrait for Pallet { /// ** Should be used for benchmarking only!!! ** #[cfg(feature = "runtime-benchmarks")] diff --git a/control/src/tests.rs b/control/src/tests.rs index 9c63d19a0..d7e440268 100644 --- a/control/src/tests.rs +++ b/control/src/tests.rs @@ -30,9 +30,6 @@ fn create_org(access_model: AccessModel) -> H256 { #[test] -// SBP-M2 review: I would split into separated test cases -// It would be easier to find bug if exists -// And this attitude follows unit testing fn control_create_org() { new_test_ext().execute_with(|| { let current_block = 3; diff --git a/flow/src/lib.rs b/flow/src/lib.rs index cd91702cf..353279945 100644 --- a/flow/src/lib.rs +++ b/flow/src/lib.rs @@ -54,7 +54,7 @@ use frame_support::{ use scale_info::TypeInfo; use sp_runtime::{traits::{AtLeast32BitUnsigned, Hash}, Permill, ArithmeticError::Overflow}; -use sp_std::{vec::Vec, convert::{TryFrom, TryInto}}; +use sp_std::{vec, vec::Vec, convert::{TryFrom, TryInto}}; use gamedao_traits::{ControlTrait, ControlBenchmarkingTrait, FlowTrait, FlowBenchmarkingTrait}; use orml_traits::{MultiCurrency, MultiReservableCurrency}; @@ -327,8 +327,6 @@ pub mod pallet { T::WeightInfo::on_initialize(processed, campaigns.len() as u32) } - // SBP-M2 reviews: I am wondering if just `continue` in case of unexpected state in this functions is a - // correct & proper way of handling fn on_finalize(block_number: T::BlockNumber) { // Prepare and validate data for campaign settlement for campaign_id in &CampaignsByBlock::::get(BlockType::Expiry, block_number) { @@ -337,8 +335,6 @@ pub mod pallet { log::error!(target: "runtime::gamedao_flow", "Campaign unknown: '{:?}'", campaign_id); continue } - // SBP-M2 review: Do not unwrap - // Use error handling let campaign = maybe_campaign.unwrap(); let maybe_treasury_id = T::Control::org_treasury_account(&campaign.org_id); if maybe_treasury_id.is_none() { @@ -537,19 +533,24 @@ impl Pallet { campaign_id: T::Hash, org_treasury: &T::AccountId, ) { - // SBP-M2 review: consider match clause - if campaign_state == &CampaignState::Succeeded { - let contributor_balance = CampaignContribution::::get(campaign_id, &contributor); - let _transfer_amount = T::Currency::repatriate_reserved( - T::PaymentTokenId::get(), - &contributor, - &org_treasury, - contributor_balance.clone(), - BalanceStatus::Reserved - ); - } else if campaign_state == &CampaignState::Failed { - let contribution = CampaignContribution::::get(campaign_id, contributor.clone()); - T::Currency::unreserve(T::PaymentTokenId::get(), &contributor, contribution); + match campaign_state { + &CampaignState::Succeeded => { + let contributor_balance = CampaignContribution::::get(campaign_id, &contributor); + let _transfer_amount = T::Currency::repatriate_reserved( + T::PaymentTokenId::get(), + &contributor, + &org_treasury, + contributor_balance.clone(), + BalanceStatus::Reserved + ); + }, + + &CampaignState::Failed => { + let contribution = CampaignContribution::::get(campaign_id, contributor.clone()); + T::Currency::unreserve(T::PaymentTokenId::get(), &contributor, contribution); + }, + + _ => {}, } } @@ -561,31 +562,34 @@ impl Pallet { org_treasury: T::AccountId, block_number: T::BlockNumber, ) { - // SBP-M2 review: consider match clause - if campaign_state == &CampaignState::Succeeded { - let commission = T::CampaignFee::get().mul_floor(campaign_balance.clone()); - let _transfer_commission = T::Currency::repatriate_reserved( - T::PaymentTokenId::get(), - &org_treasury, - &T::GameDAOTreasury::get(), - commission, - BalanceStatus::Free - ); - // Update campaign balance - let updated_balance = campaign_balance - commission; - CampaignBalance::::insert(campaign_id, updated_balance); - CampaignStates::::insert(&campaign_id, CampaignState::Succeeded); - - Self::deposit_event(Event::Succeeded { campaign_id, campaign_balance: updated_balance, block_number }); - - } else if campaign_state == &CampaignState::Failed { - // Unreserve Initial deposit - T::Currency::unreserve(T::ProtocolTokenId::get(), &org_treasury, campaign.deposit); - CampaignStates::::insert(campaign_id, CampaignState::Failed); - - Self::deposit_event(Event::Failed { campaign_id, campaign_balance, block_number }); + match campaign_state { + &CampaignState::Succeeded => { + let commission = T::CampaignFee::get().mul_floor(campaign_balance.clone()); + let _transfer_commission = T::Currency::repatriate_reserved( + T::PaymentTokenId::get(), + &org_treasury, + &T::GameDAOTreasury::get(), + commission, + BalanceStatus::Free + ); + // Update campaign balance + let updated_balance = campaign_balance - commission; + CampaignBalance::::insert(campaign_id, updated_balance); + CampaignStates::::insert(&campaign_id, CampaignState::Succeeded); + + Self::deposit_event(Event::Succeeded { campaign_id, campaign_balance: updated_balance, block_number }); + }, + + &CampaignState::Failed => { + // Unreserve Initial deposit + T::Currency::unreserve(T::ProtocolTokenId::get(), &org_treasury, campaign.deposit); + CampaignStates::::insert(campaign_id, CampaignState::Failed); + + Self::deposit_event(Event::Failed { campaign_id, campaign_balance, block_number }); + }, + + _ => {}, } - } } @@ -612,7 +616,6 @@ impl FlowTrait for Pallet { } } -// SBP-M2 review: move benchmarking stuff to benchmarking/mock module impl FlowBenchmarkingTrait for Pallet { /// ** Should be used for benchmarking only!!! ** diff --git a/flow/src/tests.rs b/flow/src/tests.rs index 8d65c8e0f..bb7cfabd4 100644 --- a/flow/src/tests.rs +++ b/flow/src/tests.rs @@ -68,7 +68,6 @@ pub fn create_campaign( // TODO: error ContributionInsufficient #[test] -// SBP-M2 review: I would split into separate test cases fn flow_create_errors() { new_test_ext().execute_with(|| { let (org_id, _, _) = create_org_treasury(); diff --git a/sense/src/lib.rs b/sense/src/lib.rs index 087498dfd..b7493416a 100644 --- a/sense/src/lib.rs +++ b/sense/src/lib.rs @@ -104,6 +104,8 @@ pub mod pallet { InvalidParam, /// Overflow adding a value to the entity property EntityPropertyOverflow, + /// No EntityProperty found for account. + EntityPropertyUnknown, /// Overflow adding a value to the entity count EntityCountOverflow, } @@ -126,7 +128,6 @@ pub mod pallet { account_id: T::AccountId, cid: BoundedVec, ) -> DispatchResult { - // SBP-M2 review: create entity like a council instead of Sudo ensure_root(origin)?; ensure!(cid.len() > 0, Error::::InvalidParam); ensure!(!Entities::::contains_key(account_id.clone()), Error::::EntityExists); @@ -149,16 +150,6 @@ pub mod pallet { Ok(()) } - // SBP-M2 review: #TODO comment - // TODO: - // mutation of values should be restricted - // certain roles are allowed to mutate values - // xp: realm - // rep: social - // trust: id - // all: governance - // sudo ( until its removal ) - /// Modifies a property of the account. /// /// Parameters: @@ -176,15 +167,12 @@ pub mod pallet { property_type: PropertyType, value: u8 ) -> DispatchResult { - // SBP-M2 review: another Sudo call... ensure_root(origin)?; ensure!(Entities::::contains_key(account_id.clone()), Error::::EntityUnknown); let current_block = >::block_number(); let v = u64::from(value); - // SBP-M2 review: do not use `unwrap` - // Apply error handling - let current = Self::get_property(property_type.clone(), account_id.clone()).unwrap(); + let current = Self::get_property(property_type.clone(), account_id.clone()).ok_or(Error::::EntityPropertyUnknown)?; let updated = EntityProperty::new( current.get_value().checked_add(v).ok_or(Error::::EntityPropertyOverflow)?, current_block diff --git a/sense/src/tests.rs b/sense/src/tests.rs index a9ba04650..75b6c08f8 100644 --- a/sense/src/tests.rs +++ b/sense/src/tests.rs @@ -61,6 +61,11 @@ fn should_update_properties() { ); Entities::::insert(account, Entity::new(account, block_number, 0, cid)); + + assert_noop!(Sense::update_property(RawOrigin::Root.into(), account, PropertyType::Experience, 125), Error::::EntityPropertyUnknown); + assert_noop!(Sense::update_property(RawOrigin::Root.into(), account, PropertyType::Reputation, 234), Error::::EntityPropertyUnknown); + assert_noop!(Sense::update_property(RawOrigin::Root.into(), account, PropertyType::Trust, 250), Error::::EntityPropertyUnknown); + Properties::::insert(PropertyType::Experience, account, EntityProperty::new(0, block_number)); Properties::::insert(PropertyType::Reputation, account, EntityProperty::new(0, block_number)); Properties::::insert(PropertyType::Trust, account, EntityProperty::new(0, block_number)); diff --git a/signal/src/lib.rs b/signal/src/lib.rs index 56f5e4ecb..4960cef8b 100644 --- a/signal/src/lib.rs +++ b/signal/src/lib.rs @@ -28,6 +28,7 @@ use frame_support::{ traits::BalanceStatus, dispatch::DispatchResult, weights::Weight, + log, transactional }; use frame_system::ensure_signed; @@ -228,12 +229,14 @@ pub mod pallet { OrgInactive, OutOfBounds, ProposalExists, + ProposalInvalid, ProposalNotActive, ProposalUnknown, TooManyProposals, TreasuryBalanceLow, TreasuryUnknown, VoteLimitReached, + VotingInvalid, WrongParameter, } @@ -242,7 +245,6 @@ pub mod pallet { #[pallet::weight(T::WeightInfo::proposal())] #[transactional] - // SBP-M2 review: I would recommend some refactor; too long function pub fn proposal( origin: OriginFor, proposal_type: ProposalType, @@ -376,9 +378,8 @@ pub mod pallet { ); }, ProposalType::Withdrawal => { + ensure!(proposal.campaign_id.is_some(), Error::::ProposalInvalid); ensure!( - // SBP-M2 review: do not use `unwrap` - // Add error handling T::Flow::is_campaign_contributor(&proposal.campaign_id.unwrap(), &who), Error::::AuthorizationError ); @@ -420,26 +421,28 @@ pub mod pallet { if proposal_state != ProposalState::Active { continue; }; - let voting_exists = ProposalVoting::::contains_key(&proposal_id); + let maybe_voting = ProposalVoting::::get(&proposal_id); let proposal_exists = ProposalOf::::contains_key(&proposal_id); - if !voting_exists || !proposal_exists { + if maybe_voting.is_none() || !proposal_exists { + log::error!(target: "runtime::gamedao_signal", "Proposal [{:?}] or voting [{:?}] is missing for proposal id: {:?}.", proposal_exists, maybe_voting.is_some(), proposal_id); continue; // should never happen } - // SBP-M2 review: just another comment about `unwrap` - let voting = ProposalVoting::::get(&proposal_id).unwrap(); + let voting = maybe_voting.unwrap(); // Get the final state based on Voting participation, quorum, majority proposal_state = Self::get_final_proposal_state(&voting); - Self::finalize_proposal(&proposal_id, proposal_state, &voting); + if Self::finalize_proposal(&proposal_id, proposal_state, &voting).is_err() { + log::error!(target: "runtime::gamedao_signal", "Failed to finalize a proposal {:?}.", proposal_id); + }; } } } impl Pallet { - pub fn get_voting_power(voting: &Voting, deposit: &Option) -> VotingPower { + pub fn get_voting_power(voting: &Voting, deposit: &Option) -> Result { let mut power: VotingPower = 1; match voting.unit { Unit::Account => { @@ -453,20 +456,18 @@ pub mod pallet { } } Unit::Token => { - // SBP-M2 review: `unwrap` - let linear_power: VotingPower = deposit.unwrap().saturated_into(); + let linear_power: VotingPower = deposit.ok_or(Error::::MissingParameter)?.saturated_into(); match voting.scale { Scale::Linear => { power = linear_power; } Scale::Quadratic => { - let linear_power: VotingPower = deposit.unwrap().saturated_into(); power = linear_power.integer_sqrt(); } } } } - power + Ok(power) } pub fn process_voting_deposits( @@ -496,7 +497,6 @@ pub mod pallet { } } _ => { - // SBP-M2 review: #TODO comment // TODO: Collect other cases when voting could be finalized earlier } } @@ -516,7 +516,7 @@ pub mod pallet { ) -> Result { let position_yes = voting.ayes.iter().position(|a| a.0 == who); let position_no = voting.nays.iter().position(|a| a.0 == who); - let power = Self::get_voting_power(&voting, &deposit); + let power = Self::get_voting_power(&voting, &deposit)?; let mut old_deposit: Option = None; if approve { @@ -558,11 +558,11 @@ pub mod pallet { ProposalVoting::::insert(&proposal_id, &voting); - // SBP-M2 review: what if proposal is not finalized? - // Is it properly handled? // For Absolute majority if more then 50% of members vote for one option, the proposal period ends earlier. if let Some(final_proposal_state) = Self::try_finalize_proposal(&voting) { - Self::finalize_proposal(&proposal_id, final_proposal_state, &voting); + Self::finalize_proposal(&proposal_id, final_proposal_state, &voting)?; + } else { + log::error!("Proposal finalization failed for proposal_id: {:?}.", proposal_id); } Ok(voting.participating as u32) @@ -681,36 +681,37 @@ pub mod pallet { } } - fn apply_proposal_actions(proposal: &Proposal, proposal_state: ProposalState) -> ProposalState { + fn apply_proposal_actions(proposal: &Proposal, proposal_state: ProposalState) -> Result { match proposal.proposal_type { ProposalType::Withdrawal => { - let campaign_id = proposal.campaign_id.unwrap(); - let amount = proposal.amount.unwrap(); - T::Currency::unreserve( - // SBP-M2 review: `unwrap` - proposal.currency_id.unwrap(), - &T::Control::org_treasury_account(&proposal.org_id).unwrap(), amount); + let campaign_id = proposal.campaign_id.ok_or(Error::::ProposalInvalid)?; + let amount = proposal.amount.ok_or(Error::::ProposalInvalid)?; + let currency_id = proposal.currency_id.ok_or(Error::::ProposalInvalid)?; + let treasury = T::Control::org_treasury_account(&proposal.org_id).ok_or(Error::::TreasuryUnknown)?; + T::Currency::unreserve(currency_id, &treasury, amount); let used_balance = CampaignBalanceUsed::::get(&campaign_id); CampaignBalanceUsed::::insert(&campaign_id, used_balance + amount); - return ProposalState::Finalized; + return Ok(ProposalState::Finalized); } ProposalType::Spending => { - let res = T::Currency::repatriate_reserved( - proposal.currency_id.unwrap(), - &T::Control::org_treasury_account(&proposal.org_id).unwrap(), - &proposal.beneficiary.as_ref().unwrap(), - proposal.amount.unwrap(), - BalanceStatus::Free); - // SBP-M2 review: why not proper error handling here? - debug_assert!(res.is_ok()); - return ProposalState::Finalized; + let amount = proposal.amount.ok_or(Error::::ProposalInvalid)?; + let currency_id = proposal.currency_id.ok_or(Error::::ProposalInvalid)?; + let treasury = T::Control::org_treasury_account(&proposal.org_id).ok_or(Error::::TreasuryUnknown)?; + let beneficiary = proposal.beneficiary.as_ref().ok_or(Error::::ProposalInvalid)?; + T::Currency::repatriate_reserved( + currency_id, + &treasury, + &beneficiary, + amount, + BalanceStatus::Free)?; + return Ok(ProposalState::Finalized); } - _ => { return proposal_state } + _ => { return Ok(proposal_state) } } } - fn process_proposal_deposit(proposal: &Proposal, voting: &Voting, proposal_state: &ProposalState) { + fn process_proposal_deposit(proposal: &Proposal, voting: &Voting, proposal_state: &ProposalState) -> DispatchResult { let currency_id = T::ProtocolTokenId::get(); match proposal_state { ProposalState::Rejected => { @@ -723,13 +724,9 @@ pub mod pallet { let gamedao_share = T::GameDAOGetsFromSlashing::get().mul_floor(proposal.deposit); let org_share = proposal.deposit - gamedao_share; let gamedo_trsry = T::GameDAOTreasury::get(); - let org_trsry = T::Control::org_treasury_account(&proposal.org_id).unwrap(); - - // SBP-M2 review: there must be proper error handling on these operations - let res = T::Currency::transfer(currency_id, &proposal.owner, &gamedo_trsry, gamedao_share); - debug_assert!(res.is_ok()); - let res = T::Currency::transfer(currency_id, &proposal.owner, &org_trsry, org_share); - debug_assert!(res.is_ok()); + let org_trsry = T::Control::org_treasury_account(&proposal.org_id).ok_or(Error::::TreasuryUnknown)?; + T::Currency::transfer(currency_id, &proposal.owner, &gamedo_trsry, gamedao_share)?; + T::Currency::transfer(currency_id, &proposal.owner, &org_trsry, org_share)?; } } SlashingRule::Tribunal => { @@ -739,7 +736,7 @@ pub mod pallet { } _ => { T::Currency::unreserve(currency_id, &proposal.owner, proposal.deposit); } } - + Ok(()) } fn emit_event(proposal_state: &ProposalState, proposal_id: &T::Hash) { @@ -760,19 +757,22 @@ pub mod pallet { } } - fn finalize_proposal(proposal_id: &T::Hash, mut proposal_state: ProposalState, voting: &Voting) { - let proposal = ProposalOf::::get(&proposal_id).unwrap(); // should not fail, checked before + fn finalize_proposal(proposal_id: &T::Hash, mut proposal_state: ProposalState, voting: &Voting) -> DispatchResult { + let proposal = ProposalOf::::get(&proposal_id).ok_or(Error::::ProposalUnknown)?; match proposal_state { ProposalState::Accepted => { - proposal_state = Self::apply_proposal_actions(&proposal, proposal_state); + proposal_state = Self::apply_proposal_actions(&proposal, proposal_state)?; } _ => { if proposal.proposal_type == ProposalType::Spending { + let amount = proposal.amount.ok_or(Error::::ProposalInvalid)?; + let currency_id = proposal.currency_id.ok_or(Error::::ProposalInvalid)?; + let treasury = T::Control::org_treasury_account(&proposal.org_id).ok_or(Error::::TreasuryUnknown)?; T::Currency::unreserve( - proposal.currency_id.unwrap(), - & T::Control::org_treasury_account(&proposal.org_id).unwrap(), - proposal.amount.unwrap()); + currency_id, + &treasury, + amount); }; } } @@ -781,17 +781,19 @@ pub mod pallet { let currency_id = T::ProtocolTokenId::get(); // TODO: chain - &voting.ayes.iter().chain(&voting.nays.iter()) for (who, _, deposit) in &voting.ayes { - let _ = T::Currency::unreserve(currency_id, &who, deposit.unwrap()); + let _ = T::Currency::unreserve(currency_id, &who, deposit.ok_or(Error::::VotingInvalid)?); }; for (who, _, deposit) in &voting.nays { - let _ = T::Currency::unreserve(currency_id, &who, deposit.unwrap()); + let _ = T::Currency::unreserve(currency_id, &who, deposit.ok_or(Error::::VotingInvalid)?); }; } // Refund or slash proposal's deposit based on proposal state and majority of rejection - Self::process_proposal_deposit(&proposal, &voting, &proposal_state); + Self::process_proposal_deposit(&proposal, &voting, &proposal_state)?; Self::emit_event(&proposal_state, &proposal_id); ProposalStates::::insert(proposal_id, proposal_state); + + Ok(()) } } } diff --git a/signal/src/tests.rs b/signal/src/tests.rs index d8d369d28..6cfe90047 100644 --- a/signal/src/tests.rs +++ b/signal/src/tests.rs @@ -18,8 +18,6 @@ use frame_support::{ /// Test 0.0 /// - Proposal validation Errors -// SBP-M2 review: I would split into separate test cases -// SBP-M2 review: Tests should have self-explanatory names #[test] fn signal_0_0() { ExtBuilder::default().build().execute_with(|| { diff --git a/signal/src/types.rs b/signal/src/types.rs index 35dc52897..b4a9d91cc 100644 --- a/signal/src/types.rs +++ b/signal/src/types.rs @@ -40,14 +40,22 @@ impl Default for SlashingRule { #[derive(Encode, Decode, PartialEq, Clone, TypeInfo, MaxEncodedLen)] #[cfg_attr(feature = "std", derive(Debug))] pub enum ProposalState { - Created = 0, // waiting for start block - Active = 1, // voting is active - Accepted = 2, // voters did approve - Rejected = 3, // voters did not approve - Expired = 4, // ended without votes + /// Waiting for start block + Created = 0, + /// Voting is active + Active = 1, + /// Voters did approve + Accepted = 2, + /// Voters did not approve + Rejected = 3, + /// Ended without votes + Expired = 4, + /// Sudo abort + Aborted = 5, + /// Proposal's action applied + Finalized = 6, + // TODO: Aborted - Aborted = 5, // sudo abort - Finalized = 6, // proposal's action applied } impl Default for ProposalState { fn default() -> Self { From 328330e681859cda98396cad5aa1359a431f147b Mon Sep 17 00:00:00 2001 From: 2075 <1140449+2075@users.noreply.github.com> Date: Fri, 16 Dec 2022 19:29:55 +0100 Subject: [PATCH 06/49] feat: update member state (#119) * feat: update orml references to git * feat: add update member ext * feat: update missing member state * feat: update event, api * Updated extrinsic. Added benchmarks Co-authored-by: vasylenko-yevhen --- control/Cargo.toml | 6 ++-- control/src/benchmarking.rs | 22 +++++++++++-- control/src/lib.rs | 46 ++++++++++++++++++++++++++++ control/src/weights.rs | 61 +++++++++++++++++++++++-------------- flow/Cargo.toml | 7 +++-- sense/Cargo.toml | 1 + signal/Cargo.toml | 4 +-- 7 files changed, 113 insertions(+), 34 deletions(-) diff --git a/control/Cargo.toml b/control/Cargo.toml index 8f4e4f792..71a4b55a9 100755 --- a/control/Cargo.toml +++ b/control/Cargo.toml @@ -32,7 +32,7 @@ sp-io = { git = "https://github.com/paritytech/substrate.git", branch = "polkado pallet-balances = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.28" } -orml-traits = { git = 'https://github.com/open-web3-stack/open-runtime-module-library', branch= 'polkadot-v0.9.28', default-features = false } +orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.28", default-features = false } gamedao-traits = { package = "gamedao-traits", path = "../traits", default-features = false } # tangram = { package = "module-tangram", path = "../../zero/tangram", default-features = false } @@ -42,8 +42,8 @@ sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkad sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.28" } frame-support-test = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.28" } pallet-balances = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.28" } -orml-tokens = { git = 'https://github.com/open-web3-stack/open-runtime-module-library', branch= 'polkadot-v0.9.28', default-features = false } -orml-currencies = { git = 'https://github.com/open-web3-stack/open-runtime-module-library', branch= 'polkadot-v0.9.28', default-features = false } +orml-currencies = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.28", default-features = false } +orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.28", default-features = false } [features] default = ["std"] diff --git a/control/src/benchmarking.rs b/control/src/benchmarking.rs index 753fe7319..e60d01e27 100644 --- a/control/src/benchmarking.rs +++ b/control/src/benchmarking.rs @@ -1,7 +1,7 @@ #![cfg(feature = "runtime-benchmarks")] use crate::*; -use frame_benchmarking::{account, benchmarks, impl_benchmark_test_suite, whitelisted_caller}; +use frame_benchmarking::{account, benchmarks, whitelisted_caller}; use frame_system::RawOrigin; use sp_runtime::{DispatchError, traits::SaturatedConversion}; use sp_std::vec; @@ -88,7 +88,7 @@ benchmarks! { } add_member { - let r in 1 .. T::MaxMembers::get(); + let r in 1 .. T::MaxMembers::get()-1; // Prepare org creator and members let creator: T::AccountId = whitelisted_caller(); @@ -111,8 +111,24 @@ benchmarks! { assert!(Members::::get(&org_id).contains(&member)); } + update_member_state { + // Prepare org creator and members + let creator: T::AccountId = whitelisted_caller(); + fund_account::(&creator)?; + let org_id = as ControlBenchmarkingTrait>::create_org(creator.clone()).unwrap(); + let member: T::AccountId = account("member", 0, SEED); + fund_account::(&member)?; + + // Add member to org + Pallet::::fill_org_with_members(&org_id, vec![member.clone()])?; + }: _(RawOrigin::Signed(creator), org_id, member.clone(), MemberState::Active) + + verify { + assert!(MemberStates::::get(org_id.clone(), member.clone()) == MemberState::Active); + } + remove_member { - let r in 1 .. T::MaxMembers::get(); + let r in 1 .. T::MaxMembers::get()-1; // Prepare org creator and members let creator: T::AccountId = whitelisted_caller(); diff --git a/control/src/lib.rs b/control/src/lib.rs index fa631566e..d9ed1080d 100644 --- a/control/src/lib.rs +++ b/control/src/lib.rs @@ -221,6 +221,13 @@ pub mod pallet { who: T::AccountId, block_number: T::BlockNumber, }, + /// A member state has been updated + MemberUpdated { + org_id: T::Hash, + who: T::AccountId, + state: MemberState, + block_number: T::BlockNumber, + }, OrgUpdated { org_id: T::Hash, prime_id: Option, @@ -475,6 +482,33 @@ pub mod pallet { Ok(Some(T::WeightInfo::add_member(members_count)).into()) } + /// Update member state in the organization + /// + /// Parameters: + /// - `org_id`: Org id + /// - `who`: Account to change state for + /// - `state`: new state value + /// + /// Emits `MemberUpdated` event when successful. + /// + /// Weight: `O(log n)` + #[pallet::weight(T::WeightInfo::update_member_state())] + pub fn update_member_state( + origin: OriginFor, + org_id: T::Hash, + who: T::AccountId, + state: MemberState + ) -> DispatchResult { + let org = Orgs::::get(&org_id).ok_or(Error::::OrganizationUnknown)?; + Self::ensure_membership_permissions(origin, who.clone(), org.prime.clone(), org.org_type.clone(), org.access_model.clone())?; + + let current_member_state = MemberStates::::get(org_id.clone(), who.clone()); + if current_member_state == MemberState::Pending { + Self::do_update_member(org_id, who.clone(), state)?; + } + Ok(()) + } + /// Remove member from Org /// /// Parameters: @@ -563,6 +597,7 @@ impl Pallet { .map_err(|_| Error::::MembershipLimitReached)?; let members_count = members.len() as u32; + // TODO: flatten Members and MemberStates Members::::insert(&org_id, &members); OrgMemberCount::::insert(&org_id, members_count); MemberStates::::insert(&org_id, &who, member_state); @@ -573,6 +608,17 @@ impl Pallet { Ok(members_count) } + fn do_update_member( + org_id: T::Hash, + who: T::AccountId, + state: MemberState + ) -> Result<(), DispatchError> { + MemberStates::::set(&org_id, &who, state.clone()); + let block_number = frame_system::Pallet::::block_number(); + Self::deposit_event(Event::MemberUpdated { org_id, who, state, block_number }); + Ok(()) + } + fn do_remove_member(org_id: T::Hash, who: T::AccountId) -> Result { let mut members = Members::::get(&org_id); let location = members.binary_search(&who).ok().ok_or(Error::::NotMember)?; diff --git a/control/src/weights.rs b/control/src/weights.rs index cfba7b00c..1963eb0ba 100644 --- a/control/src/weights.rs +++ b/control/src/weights.rs @@ -18,18 +18,18 @@ //! Autogenerated weights for gamedao_control //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2022-09-13, STEPS: `20`, REPEAT: 10, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2022-12-16, STEPS: `20`, REPEAT: 10, LOW RANGE: `[]`, HIGH RANGE: `[]` //! EXECUTION: None, WASM-EXECUTION: Compiled, CHAIN: None, DB CACHE: 1024 // Executed Command: -// ./target/release/subzero +// ./target/release/subzero-dev // benchmark // pallet // --pallet=gamedao_control // --extrinsic=* // --steps=20 // --repeat=10 -// --output=gamedao-protocol/control/src/weights.rs +// --output=modules/gamedao-protocol/control/src/weights.rs // --template=./.maintain/frame-weight-template.hbs #![cfg_attr(rustfmt, rustfmt_skip)] @@ -46,6 +46,7 @@ pub trait WeightInfo { fn disable_org() -> Weight; fn enable_org() -> Weight; fn add_member(r: u32, ) -> Weight; + fn update_member_state() -> Weight; fn remove_member(r: u32, ) -> Weight; fn spend_funds() -> Weight; } @@ -63,28 +64,28 @@ impl WeightInfo for SubstrateWeight { // Storage: Control MemberStates (r:0 w:1) // Storage: Control OrgStates (r:0 w:1) fn create_org() -> Weight { - (54_000_000 as Weight) + (75_523_000 as Weight) .saturating_add(T::DbWeight::get().reads(6 as Weight)) .saturating_add(T::DbWeight::get().writes(10 as Weight)) } // Storage: Control Orgs (r:1 w:1) // Storage: Control MemberStates (r:1 w:0) fn update_org() -> Weight { - (22_000_000 as Weight) + (33_049_000 as Weight) .saturating_add(T::DbWeight::get().reads(2 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } // Storage: Control Orgs (r:1 w:0) // Storage: Control OrgStates (r:0 w:1) fn disable_org() -> Weight { - (18_000_000 as Weight) + (26_400_000 as Weight) .saturating_add(T::DbWeight::get().reads(1 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } // Storage: Control Orgs (r:1 w:0) // Storage: Control OrgStates (r:0 w:1) fn enable_org() -> Weight { - (18_000_000 as Weight) + (25_846_000 as Weight) .saturating_add(T::DbWeight::get().reads(1 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } @@ -94,20 +95,27 @@ impl WeightInfo for SubstrateWeight { // Storage: Control OrgMemberCount (r:0 w:1) // Storage: Control MemberStates (r:0 w:1) fn add_member(r: u32, ) -> Weight { - (27_200_000 as Weight) + (46_146_000 as Weight) // Standard Error: 2_000 - .saturating_add((36_000 as Weight).saturating_mul(r as Weight)) + .saturating_add((63_000 as Weight).saturating_mul(r as Weight)) .saturating_add(T::DbWeight::get().reads(3 as Weight)) .saturating_add(T::DbWeight::get().writes(3 as Weight)) } // Storage: Control Orgs (r:1 w:0) + // Storage: Control MemberStates (r:1 w:1) + fn update_member_state() -> Weight { + (26_240_000 as Weight) + .saturating_add(T::DbWeight::get().reads(2 as Weight)) + .saturating_add(T::DbWeight::get().writes(1 as Weight)) + } + // Storage: Control Orgs (r:1 w:0) // Storage: Control Members (r:1 w:1) // Storage: Control OrgMemberCount (r:0 w:1) // Storage: Control MemberStates (r:0 w:1) fn remove_member(r: u32, ) -> Weight { - (24_323_000 as Weight) - // Standard Error: 2_000 - .saturating_add((31_000 as Weight).saturating_mul(r as Weight)) + (44_807_000 as Weight) + // Standard Error: 3_000 + .saturating_add((66_000 as Weight).saturating_mul(r as Weight)) .saturating_add(T::DbWeight::get().reads(2 as Weight)) .saturating_add(T::DbWeight::get().writes(3 as Weight)) } @@ -116,7 +124,7 @@ impl WeightInfo for SubstrateWeight { // Storage: Tokens Accounts (r:2 w:2) // Storage: System Account (r:2 w:1) fn spend_funds() -> Weight { - (45_000_000 as Weight) + (50_764_000 as Weight) .saturating_add(T::DbWeight::get().reads(6 as Weight)) .saturating_add(T::DbWeight::get().writes(3 as Weight)) } @@ -134,28 +142,28 @@ impl WeightInfo for () { // Storage: Control MemberStates (r:0 w:1) // Storage: Control OrgStates (r:0 w:1) fn create_org() -> Weight { - (54_000_000 as Weight) + (75_523_000 as Weight) .saturating_add(RocksDbWeight::get().reads(6 as Weight)) .saturating_add(RocksDbWeight::get().writes(10 as Weight)) } // Storage: Control Orgs (r:1 w:1) // Storage: Control MemberStates (r:1 w:0) fn update_org() -> Weight { - (22_000_000 as Weight) + (33_049_000 as Weight) .saturating_add(RocksDbWeight::get().reads(2 as Weight)) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } // Storage: Control Orgs (r:1 w:0) // Storage: Control OrgStates (r:0 w:1) fn disable_org() -> Weight { - (18_000_000 as Weight) + (26_400_000 as Weight) .saturating_add(RocksDbWeight::get().reads(1 as Weight)) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } // Storage: Control Orgs (r:1 w:0) // Storage: Control OrgStates (r:0 w:1) fn enable_org() -> Weight { - (18_000_000 as Weight) + (25_846_000 as Weight) .saturating_add(RocksDbWeight::get().reads(1 as Weight)) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } @@ -165,20 +173,27 @@ impl WeightInfo for () { // Storage: Control OrgMemberCount (r:0 w:1) // Storage: Control MemberStates (r:0 w:1) fn add_member(r: u32, ) -> Weight { - (27_200_000 as Weight) + (46_146_000 as Weight) // Standard Error: 2_000 - .saturating_add((36_000 as Weight).saturating_mul(r as Weight)) + .saturating_add((63_000 as Weight).saturating_mul(r as Weight)) .saturating_add(RocksDbWeight::get().reads(3 as Weight)) .saturating_add(RocksDbWeight::get().writes(3 as Weight)) } // Storage: Control Orgs (r:1 w:0) + // Storage: Control MemberStates (r:1 w:1) + fn update_member_state() -> Weight { + (26_240_000 as Weight) + .saturating_add(RocksDbWeight::get().reads(2 as Weight)) + .saturating_add(RocksDbWeight::get().writes(1 as Weight)) + } + // Storage: Control Orgs (r:1 w:0) // Storage: Control Members (r:1 w:1) // Storage: Control OrgMemberCount (r:0 w:1) // Storage: Control MemberStates (r:0 w:1) fn remove_member(r: u32, ) -> Weight { - (24_323_000 as Weight) - // Standard Error: 2_000 - .saturating_add((31_000 as Weight).saturating_mul(r as Weight)) + (44_807_000 as Weight) + // Standard Error: 3_000 + .saturating_add((66_000 as Weight).saturating_mul(r as Weight)) .saturating_add(RocksDbWeight::get().reads(2 as Weight)) .saturating_add(RocksDbWeight::get().writes(3 as Weight)) } @@ -187,7 +202,7 @@ impl WeightInfo for () { // Storage: Tokens Accounts (r:2 w:2) // Storage: System Account (r:2 w:1) fn spend_funds() -> Weight { - (45_000_000 as Weight) + (50_764_000 as Weight) .saturating_add(RocksDbWeight::get().reads(6 as Weight)) .saturating_add(RocksDbWeight::get().writes(3 as Weight)) } diff --git a/flow/Cargo.toml b/flow/Cargo.toml index 8784d5bd4..0cc44d6f3 100644 --- a/flow/Cargo.toml +++ b/flow/Cargo.toml @@ -3,6 +3,7 @@ # ███░█▄▀█░▀▀░█░█▄█░█░▄▄█░█░█░▀▀░█░██░██ # ███▄▄▄▄█▄██▄█▄███▄█▄▄▄█▄▄██▄██▄██▄▄███ # ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ + [package] name = "gamedao-flow" version = "1.2.0" @@ -23,9 +24,9 @@ frame-system = { git = "https://github.com/paritytech/substrate", branch = "polk frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.28", default-features = false, optional = true } sp-io = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.28", default-features=false } -orml-traits = { git = 'https://github.com/open-web3-stack/open-runtime-module-library', branch= 'polkadot-v0.9.28', default-features = false } -orml-tokens = { git = 'https://github.com/open-web3-stack/open-runtime-module-library', branch= 'polkadot-v0.9.28', optional = true } -orml-currencies = { git = 'https://github.com/open-web3-stack/open-runtime-module-library', branch= 'polkadot-v0.9.28', optional = true } +orml-currencies = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.28", default-features = false } +orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.28", default-features = false } +orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.28", default-features = false } gamedao-traits = { package = "gamedao-traits", path = "../traits", default-features = false } gamedao-control = { package = "gamedao-control", path = "../control", optional = true } diff --git a/sense/Cargo.toml b/sense/Cargo.toml index cdc833795..dfe541f8f 100755 --- a/sense/Cargo.toml +++ b/sense/Cargo.toml @@ -3,6 +3,7 @@ # ███░█▄▀█░▀▀░█░█▄█░█░▄▄█░█░█░▀▀░█░██░██ # ███▄▄▄▄█▄██▄█▄███▄█▄▄▄█▄▄██▄██▄██▄▄███ # ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ + [package] name = "gamedao-sense" version = "1.2.0" diff --git a/signal/Cargo.toml b/signal/Cargo.toml index 74c1b43b3..5cc29247b 100644 --- a/signal/Cargo.toml +++ b/signal/Cargo.toml @@ -41,8 +41,8 @@ frame-support-test = { git = "https://github.com/paritytech/substrate.git", bran pallet-balances = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.28" } pallet-timestamp = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.28" } -orml-tokens = { git = 'https://github.com/open-web3-stack/open-runtime-module-library', branch= 'polkadot-v0.9.28', default-features = false } -orml-currencies = { git = 'https://github.com/open-web3-stack/open-runtime-module-library', branch= 'polkadot-v0.9.28', default-features = false } +orml-currencies = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.28", default-features = false } +orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.28", default-features = false } gamedao-control = { path = "../control", default-features = true } gamedao-flow = { path = "../flow", default-features = true } From e6b8f77f6ac8f03a814e9907a93e407cfee09219 Mon Sep 17 00:00:00 2001 From: Yura Date: Fri, 16 Dec 2022 19:32:12 +0100 Subject: [PATCH 07/49] feat: battlepass (#120) * Create Battlepass pallete * docs: add readme * Update extrinsics. * Add RMRK integration, mint Battlepass NFTs. Co-authored-by: 2075 <1140449+2075@users.noreply.github.com> --- battlepass/Cargo.toml | 59 +++++++++ battlepass/readme.md | 142 ++++++++++++++++++++++ battlepass/src/lib.rs | 257 ++++++++++++++++++++++++++++++++++++++++ battlepass/src/types.rs | 34 ++++++ flow/src/lib.rs | 4 +- 5 files changed, 494 insertions(+), 2 deletions(-) create mode 100644 battlepass/Cargo.toml create mode 100644 battlepass/readme.md create mode 100644 battlepass/src/lib.rs create mode 100644 battlepass/src/types.rs diff --git a/battlepass/Cargo.toml b/battlepass/Cargo.toml new file mode 100644 index 000000000..f3d4a97a1 --- /dev/null +++ b/battlepass/Cargo.toml @@ -0,0 +1,59 @@ +# ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄ +# ███░▄▄▄█░▄▄▀█░▄▀▄░█░▄▄█░▄▀█░▄▄▀█▀▄▄▀██ +# ███░█▄▀█░▀▀░█░█▄█░█░▄▄█░█░█░▀▀░█░██░██ +# ███▄▄▄▄█▄██▄█▄███▄█▄▄▄█▄▄██▄██▄██▄▄███ +# ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ +[package] +name = "gamedao-battlepass" +version = "1.2.0" +authors = ["zero.io","gamedao.co"] +repository = "https://github.com/gamedaoco/gamedao-protocol" +edition = "2018" +license = "GPL-3.0-or-later" +description = "BattlePass pallet provides functionality to create, manage and participate in battlepasses." + +[dependencies] +serde = { version = "1.0.143", optional = true } +codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] } +scale-info = { version = "2.1.1", default-features = false, features = ["derive"] } +sp-core = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.28" } +sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.28" } +sp-std = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.28" } +sp-storage = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.28" } +sp-io = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.28", default-features=false } +frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.28", default-features = false } +frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.28", default-features = false } +frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.28", default-features = false, optional = true } + +pallet-rmrk-core = { git = "https://github.com/rmrk-team/rmrk-substrate", default-features = false, branch = "polkadot-v0.9.28" } +rmrk-traits = { git = "https://github.com/rmrk-team/rmrk-substrate", default-features = false, branch = "polkadot-v0.9.28" } + +gamedao-control = { package = "gamedao-control", path = "../control", optional = true } +gamedao-traits = { package = "gamedao-traits", path = "../traits", default-features = false } + +[dev-dependencies] +frame-support-test = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.28" } + +[features] +default = ['std'] +runtime-benchmarks = ["frame-benchmarking"] +std = [ + "serde/std", + 'codec/std', + "scale-info/std", + + "frame-support/std", + "frame-system/std", + "frame-benchmarking/std", + + "sp-core/std", + "sp-std/std", + "sp-runtime/std", + + "pallet-rmrk-core/std", + "rmrk-traits/std", + + "gamedao-control/std", + "gamedao-traits/std", +] +try-runtime = ["frame-support/try-runtime"] \ No newline at end of file diff --git a/battlepass/readme.md b/battlepass/readme.md new file mode 100644 index 000000000..f119b1d89 --- /dev/null +++ b/battlepass/readme.md @@ -0,0 +1,142 @@ +# BattlePass Beta + + + +## Definitions + Dictionary + + - Guild -> A group of people gaming together. + also Clan, Team, Crew, Squad, Party + + - BattlePass (BP) -> A subscription based engagement protocol for gaming guilds + + - Quest (Q) -> A group of tasks, bounties, etc on related games and media, like discord, twitter, twitch, Fortnite, CS, ... resulting in receiving points (XP,REP,TRUST,...) upon verifiable completion of its parts. + + - Quest Progress (QP) -> ( NonBinary / Float ) Fulfilled 0...1 of Quest Q + + - Points (P) -> Named individually in a guild, reference score based on the following + + - XP -> Experience Points based on tasks fulfilled in context of a Quest and BattlePass, may reset each season + + - REP -> Reputation Points based on street cred of a user on global level + + - TRUST -> Trust level based on verifiable credentials, e.g. connect twitter, discord, twitch, web3name, etc + + - Level (L) -> achieved by collecting points + + - Achievement -> + 1 NFT proof of achievement + 2 this enables account controller to redeem a reward + 3 to mint an achievement we use a template struct defining -> + a. data struct for the immutable nft part / configuration + b. data struct for the im/mutable payload part + + +## Overview + +BattlePass is a subscription based engagement protocol for gaming guilds. It enables claiming and dropping rewards based on completing quests. These achievements are based on verifiable activity and contribute to xp, rep, trust in SENSE. + + +## BattlePass for DAOs + + 1. It can be invoked by a DAO through staking (1000) GAME token on the protocol treasury. + + 2. Staking automatically enables the BattlePass section in a DAO. + + 3. The DAO invoking wishing to enable BattlePass needs verified credentials and be in good standing: + - (XP) > (100) + - (REP) > (100) + - (TRUST) > (100) + - MEMBERS > 10 + +BattlePass starts operating immediately when the staking deposit has been transferred. To make proper use of it, some defaults are in place to make it work: + + - By default a BattlePass utilizes xp,rep,trust in relation to a DAO + + - therefore a DAO specific map for xp,rep,trust has to be setup on DAO creation + + - a BP operates in seasons. a season is by default 100 days based on the respective blocktime of the host chain this results with 6s blocktime in in 10 * 60 * 24 = 14400 blocks per day and 144000 blocks per season. + + - after a season has finished, a new season starts, resetting the achieved score + + - a user subscribes for a BP over one to n seasons + + - a user collects points during the season based on their verifiable activity in games, on socials, etc + + - based on a score table, user is allowed to claim rewards from a level L and can use points P to claim rewards up to level L + + - P are calculated based on a formula like: + + *** DRAFT *** + + P = + MAP * + ( 1 * subscription_mul ) + -> local + 0 * ( -> activated? + 1 + + XP( season ) * -> local + ( 1 + REP / 100 ) * -> global + ( 1 + TRUST * 100 ) -> global + ) + + - where MAP is the individual mapping for achievements / levels, etc + + everybody can play, but only with a subscription you get the multiplier to make real progress into the claimable scores + + *** DRAFT *** + + - rewards will be delivered as nft based collectable, like + - proof of achievement + - proof of participation + - ticket + - collectable + ... + + - DAO needs to create a reward map based on a + score_threshold ST, + a reward object R, + a price in points P: + + { ST , ( R , P ) } + +example: 1000, ( item_drop_dragonball_nft, 0 ) + +## BattlePass for gamers and creators + +Battlepass provides the following functions: + + 0. Signup with discord **and** wallet + + 1. Connecting the following social accounts to start collecting points + - discord -> 1st poc e2e + - twitter -> 2nd due to relevance + - twitch -> tbd + - polkadot compatible wallet -> talisman preferred + - suggestions welcome + + 2. One-time or subscription payment for a Battlepass settled through PSP in FIAT or directly via stablecoin (USDT) + + 3. Browsing the rewards showing + - xp bar + - cta to join if not joined + - levels and/or required points to claim reward x + - enabling claim button when score is sufficient + + 4. Browsing Quests and Quest Progress + + +## Pallet + +### Sense + + map global ( season, xp , rep, trust ) + map local ( season, xp , rep, trust ) + +### BattlePass + +### Control + + + +### + +© 2022 GameDAO AG \ No newline at end of file diff --git a/battlepass/src/lib.rs b/battlepass/src/lib.rs new file mode 100644 index 000000000..32b988069 --- /dev/null +++ b/battlepass/src/lib.rs @@ -0,0 +1,257 @@ +// _______ ________ ________ ________ ______ _______ _______ +// ╱╱ ╲╱ ╲╱ ╲╱ ╲_╱ ╲╲╱ ╲╲╱ ╲╲ +// ╱╱ __╱ ╱ ╱ ╱ ╱╱ ╱╱ ╱╱ +// ╱ ╱ ╱ ╱ ╱ _╱ ╱ ╱ ╱ +// ╲________╱╲___╱____╱╲__╱__╱__╱╲________╱╲________╱╲___╱____╱╲________╱ +// +// This file is part of GameDAO Protocol. +// Copyright (C) 2018-2022 GameDAO AG. +// SPDX-License-Identifier: Apache-2.0 + +//! BATTLEPASS +//! This pallet provides functionality to create, manage and participate in battlepasses. +#![cfg_attr(not(feature = "std"), no_std)] + +pub use pallet::*; +use frame_support::pallet_prelude::*; +use frame_system::pallet_prelude::*; +use sp_std::convert::TryInto; +use sp_runtime::traits::Hash; +use gamedao_traits::ControlTrait; +use rmrk_traits::{primitives::PartId, Collection, Nft, ResourceInfoMin}; + +pub mod types; +pub use types::*; + +pub type String = BoundedVec::StringLimit>; +pub type Symbol = BoundedVec::SymbolLimit>; +pub type Resource = BoundedVec< + ResourceInfoMin< + BoundedVec::StringLimit>, + BoundedVec::PartsLimit>, + >, + ::MaxResourcesOnMint, +>; + +#[frame_support::pallet] +pub mod pallet { + use super::*; + + #[pallet::pallet] + #[pallet::generate_store(pub(super) trait Store)] + pub struct Pallet(_); + + #[pallet::config] + pub trait Config: frame_system::Config + pallet_rmrk_core::Config { + type Event: From> + + IsType<::Event> + + Into<::Event>; + + type Control: ControlTrait; + + type Rmrk: Collection, Symbol, Self::AccountId> + + Nft, Resource>; + + /// The maximum length of a name, cid or metadata strings stored on-chain. + #[pallet::constant] + type StringLimit: Get; + + /// The maximum length of a Collection symbol. + #[pallet::constant] + type SymbolLimit: Get; + + /// The maximum number of parts each resource may have + #[pallet::constant] + type PartsLimit: Get; + + type MaxResourcesOnMint: Get; + } + + #[pallet::event] + #[pallet::generate_deposit(pub(super) fn deposit_event)] + pub enum Event { + /// New BattlePass created + BattlepassCreated { + org_id: T::Hash, + battlepass_id: T::Hash, + season: u32 + }, + + /// BattlePass claimed + BattlepassClaimed { + claimer: T::AccountId, + org_id: T::Hash, + battlepass_id: T::Hash + }, + + /// BattlePass closed + BattlepassClosed { + closed_by: T::AccountId, + org_id: T::Hash, + battlepass_id: T::Hash + }, + } + + #[pallet::error] + pub enum Error { + AuthorizationError, + OrgPrimeUnknown, + OrgUnknown, + BattlepassExists, + BattlepassClaimed, + BattlepassUnknown, + NotMember, + CollectionUnknown, + } + + /// Battlepass by its id. + /// + /// Battlepasses: map Hash => Battlepass + #[pallet::storage] + #[pallet::getter(fn get_battlepass)] + pub(super) type Battlepasses = StorageMap<_, Blake2_128Concat, T::Hash, Battlepass>, OptionQuery>; + + /// Battlepass state. + /// + /// BattlepassStates: map Hash => BattlepassState + #[pallet::storage] + #[pallet::getter(fn get_battlepass_state)] + pub type BattlepassStates = StorageMap<_, Blake2_128Concat, T::Hash, BattlepassState, OptionQuery>; + + /// Total number of battlepasses per organization. + /// + /// BattlepassCount: map Hash => u32 + #[pallet::storage] + #[pallet::getter(fn get_battlepass_count)] + pub type BattlepassCount = StorageMap<_, Blake2_128Concat, T::Hash, u32, ValueQuery>; + + /// Current active battlepass in organization. + /// + /// ActiveBattlepassByOrg: map Hash => Hash + #[pallet::storage] + #[pallet::getter(fn get_active_battlepass)] + pub type ActiveBattlepassByOrg = StorageMap<_, Blake2_128Concat, T::Hash, T::Hash, OptionQuery>; + + /// Claimed Battlepass-NFT by user account. + /// + /// ClaimedBattlepass: map (AccountId, Hash) => BattlepassNft + #[pallet::storage] + #[pallet::getter(fn get_claimed_battlepass)] + pub(super) type ClaimedBattlepass = StorageDoubleMap<_, + Blake2_128Concat, T::AccountId, + Blake2_128Concat, T::Hash, + BattlepassNft, + OptionQuery + >; + + #[pallet::call] + impl Pallet { + #[pallet::weight(0)] + pub fn create_battlepass( + origin: OriginFor, + org_id: T::Hash, + name: String, + cid: String, + price: u16, + ) -> DispatchResult { + let creator = ensure_signed(origin)?; + // check if Org exists + ensure!(T::Control::is_org_active(&org_id), Error::::OrgUnknown); + // check if origin is an Org Prime + let prime = T::Control::org_prime_account(&org_id).ok_or(Error::::OrgPrimeUnknown)?; + ensure!(creator == prime, Error::::AuthorizationError); // TODO: Add Root temporaryly + // check is there is no active battlepass for the Org + ensure!(!ActiveBattlepassByOrg::::contains_key(&org_id), Error::::BattlepassExists); + let new_season = Self::get_battlepass_count(org_id) + 1; + let now = >::block_number(); + + // Create collection + let metadata = BoundedVec::truncate_from(b"meta".to_vec()); // TODO: what should be here? + let symbol = BoundedVec::truncate_from(b"symbol".to_vec()); // TODO: what should be here? + let collection_id = T::Rmrk::collection_create(creator.clone(), metadata, None, symbol)?; + + // Create Battlepass + let battlepass: Battlepass> = types::Battlepass { + creator, + org_id, + name, + cid, + season: new_season, + collection_id, + price, + created: now.clone(), mutated: now + }; + let battlepass_id = ::Hashing::hash_of(&battlepass); + + Battlepasses::::insert(&battlepass_id, battlepass); + BattlepassStates::::insert(&battlepass_id, types::BattlepassState::Active); // TODO: change to Draft + ActiveBattlepassByOrg::::insert(org_id, battlepass_id); + BattlepassCount::::insert(org_id, new_season); + + Self::deposit_event(Event::BattlepassCreated { org_id, battlepass_id, season: new_season }); + + Ok(()) + } + + #[pallet::weight(0)] + pub fn claim_battlepass( + origin: OriginFor, + org_id: T::Hash, + ) -> DispatchResult { + let claimer = ensure_signed(origin)?; + // check if Org exists + ensure!(T::Control::is_org_active(&org_id), Error::::OrgUnknown); + // check if user is a member of organization + ensure!(T::Control::is_org_member_active(&org_id, &claimer), Error::::NotMember); + // check if Org has active battlepass + let battlepass_id = Self::get_active_battlepass(org_id).ok_or(Error::::BattlepassUnknown)?; + // check if Battlepass already claimed + ensure!(!ClaimedBattlepass::::contains_key(claimer.clone(), battlepass_id), Error::::BattlepassClaimed); + + let battlepass = Self::get_battlepass(battlepass_id).ok_or(Error::::BattlepassUnknown)?; + let collection = >::collections(battlepass.collection_id).ok_or(Error::::CollectionUnknown)?; + + // Create NFT + let (collection_id, nft_id) = T::Rmrk::nft_mint( + claimer.clone(), // sender + claimer.clone(), // owner + collection.nfts_count, // nft_id + battlepass.collection_id, // collection_id + None, // royalty_recipient + None, // royalty_amount + BoundedVec::truncate_from(b"NFT meta".to_vec()), // metadata TODO: what should be here? + false, // transferable + None // resources + )?; + + ClaimedBattlepass::::insert(&claimer, battlepass_id, BattlepassNft{collection_id, nft_id}); + + Self::deposit_event(Event::BattlepassClaimed { claimer, org_id, battlepass_id }); + + Ok(()) + } + + #[pallet::weight(0)] + pub fn close_battlepass( + origin: OriginFor, + org_id: T::Hash, + ) -> DispatchResult { + let sender = ensure_signed(origin)?; + // check if Org exists + ensure!(T::Control::is_org_active(&org_id), Error::::OrgUnknown); + // check if origin is an Org Prime + let prime = T::Control::org_prime_account(&org_id).ok_or(Error::::OrgPrimeUnknown)?; + ensure!(sender == prime, Error::::AuthorizationError); // TODO: Add Root temporaryly + // check if Org has active battlepass + let battlepass_id = Self::get_active_battlepass(org_id).ok_or(Error::::BattlepassUnknown)?; + + BattlepassStates::::insert(&battlepass_id, types::BattlepassState::Closed); + ActiveBattlepassByOrg::::remove(org_id); + + Self::deposit_event(Event::BattlepassClosed { closed_by: sender, org_id, battlepass_id }); + + Ok(()) + } + + } +} \ No newline at end of file diff --git a/battlepass/src/types.rs b/battlepass/src/types.rs new file mode 100644 index 000000000..a5921acca --- /dev/null +++ b/battlepass/src/types.rs @@ -0,0 +1,34 @@ +use frame_support::pallet_prelude::*; +use codec::MaxEncodedLen; + +#[derive(Encode, Decode, Clone, PartialEq, Eq, PartialOrd, Ord, TypeInfo, MaxEncodedLen)] +pub enum BattlepassState { + Draft = 0, + Active = 1, + Closed = 2, +} +impl Default for BattlepassState { + fn default() -> Self { + Self::Draft + } +} + +#[derive(Encode, Decode, Default, PartialEq, Eq, TypeInfo, MaxEncodedLen)] +pub struct Battlepass { + pub creator: AccountId, + pub org_id: Hash, + pub name: BoundedString, + pub cid: BoundedString, + pub season: u32, + pub price: u16, // TODO: introduce currency + /// Collection that will store all claimed Battlepass-NFTs + pub collection_id: u32, + pub created: BlockNumber, + pub mutated: BlockNumber, +} + +#[derive(Encode, Decode, Default, PartialEq, Eq, TypeInfo, MaxEncodedLen)] +pub struct BattlepassNft { + pub collection_id: u32, + pub nft_id: u32, +} \ No newline at end of file diff --git a/flow/src/lib.rs b/flow/src/lib.rs index 353279945..6a8390a2c 100644 --- a/flow/src/lib.rs +++ b/flow/src/lib.rs @@ -53,8 +53,7 @@ use frame_support::{ use scale_info::TypeInfo; use sp_runtime::{traits::{AtLeast32BitUnsigned, Hash}, Permill, ArithmeticError::Overflow}; - -use sp_std::{vec, vec::Vec, convert::{TryFrom, TryInto}}; +use sp_std::{vec::Vec, convert::{TryFrom, TryInto}}; use gamedao_traits::{ControlTrait, ControlBenchmarkingTrait, FlowTrait, FlowBenchmarkingTrait}; use orml_traits::{MultiCurrency, MultiReservableCurrency}; @@ -622,6 +621,7 @@ impl FlowBenchmarkingTrait for #[cfg(feature = "runtime-benchmarks")] fn create_campaign(caller: &T::AccountId, org_id: &T::Hash, start: T::BlockNumber) -> Result { use sp_runtime::traits::Saturating; + use sp_std::vec; let bounded_str: BoundedVec = BoundedVec::truncate_from(vec![0; T::StringLimit::get() as usize]); let now = frame_system::Pallet::::block_number(); let index = CampaignCount::::get(); From 41fbc9548b8f9da2634c2f036598e78c53d76d09 Mon Sep 17 00:00:00 2001 From: Vasylenko Yevhen Date: Mon, 19 Dec 2022 20:23:32 +0200 Subject: [PATCH 08/49] Allow users to join to prime type org (#121) --- control/src/lib.rs | 11 ++++++++++- control/src/tests.rs | 5 +++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/control/src/lib.rs b/control/src/lib.rs index d9ed1080d..cb631ff6d 100644 --- a/control/src/lib.rs +++ b/control/src/lib.rs @@ -24,6 +24,7 @@ use codec::Codec; use frame_support::{dispatch::{DispatchResult, DispatchError, RawOrigin}, ensure, PalletId, traits::Get, BoundedVec, transactional, log }; +use frame_system::ensure_root; use gamedao_traits::{ControlTrait, ControlBenchmarkingTrait}; use orml_traits::{MultiCurrency, MultiReservableCurrency}; use scale_info::TypeInfo; @@ -470,7 +471,15 @@ pub mod pallet { who: T::AccountId ) -> DispatchResultWithPostInfo { let org = Orgs::::get(&org_id).ok_or(Error::::OrganizationUnknown)?; - Self::ensure_membership_permissions(origin, who.clone(), org.prime.clone(), org.org_type.clone(), org.access_model.clone())?; + if let Ok(sender) = ensure_signed(origin.clone()) { + ensure!( + sender == who || (org.access_model == AccessModel::Prime && sender == org.prime.clone()), + BadOrigin + ); + } + else { + ensure_root(origin)?; + } let member_state = match org.access_model { AccessModel::Open => MemberState::Active, _ => MemberState::Pending, diff --git a/control/src/tests.rs b/control/src/tests.rs index d7e440268..eb5b92361 100644 --- a/control/src/tests.rs +++ b/control/src/tests.rs @@ -215,6 +215,11 @@ fn control_add_remove_member_access_prime() { assert_ok!(Control::remove_member(Origin::root(), org_id, CHARLIE)); assert!(!Members::::get(org_id).contains(&CHARLIE)); + // Add member signed + assert_ok!(Control::add_member(Origin::signed(CHARLIE), org_id, CHARLIE)); + assert!(Members::::get(org_id).contains(&CHARLIE)); + assert_eq!(MemberStates::::get(org_id, CHARLIE), MemberState::Pending); + // TODO: since membership_fee logic is unclear for the moment, there is no tests for it yet }) } From 6f4762afc150cd42d8dd6133e93f72d4cda05fd9 Mon Sep 17 00:00:00 2001 From: FiberMan Date: Thu, 15 Dec 2022 12:44:38 +0100 Subject: [PATCH 09/49] Create Battlepass pallete --- battlepass/src/lib.rs | 211 ++++++++++++++++++++++++---------------- battlepass/src/types.rs | 29 +++--- 2 files changed, 145 insertions(+), 95 deletions(-) diff --git a/battlepass/src/lib.rs b/battlepass/src/lib.rs index 32b988069..4a3c65129 100644 --- a/battlepass/src/lib.rs +++ b/battlepass/src/lib.rs @@ -18,7 +18,7 @@ use frame_system::pallet_prelude::*; use sp_std::convert::TryInto; use sp_runtime::traits::Hash; use gamedao_traits::ControlTrait; -use rmrk_traits::{primitives::PartId, Collection, Nft, ResourceInfoMin}; +use rmrk_traits::{primitives::{PartId, NftId}, Collection, Nft, ResourceInfoMin}; pub mod types; pub use types::*; @@ -81,7 +81,8 @@ pub mod pallet { BattlepassClaimed { claimer: T::AccountId, org_id: T::Hash, - battlepass_id: T::Hash + battlepass_id: T::Hash, + nft_id: NftId }, /// BattlePass closed @@ -96,10 +97,12 @@ pub mod pallet { pub enum Error { AuthorizationError, OrgPrimeUnknown, - OrgUnknown, + OrgUnknownOrInactive, BattlepassExists, BattlepassClaimed, + BattlepassInactive, BattlepassUnknown, + BattlepassInfoUnknown, NotMember, CollectionUnknown, } @@ -109,7 +112,7 @@ pub mod pallet { /// Battlepasses: map Hash => Battlepass #[pallet::storage] #[pallet::getter(fn get_battlepass)] - pub(super) type Battlepasses = StorageMap<_, Blake2_128Concat, T::Hash, Battlepass>, OptionQuery>; + pub(super) type Battlepasses = StorageMap<_, Blake2_128Concat, T::Hash, Battlepass>, OptionQuery>; /// Battlepass state. /// @@ -118,29 +121,22 @@ pub mod pallet { #[pallet::getter(fn get_battlepass_state)] pub type BattlepassStates = StorageMap<_, Blake2_128Concat, T::Hash, BattlepassState, OptionQuery>; - /// Total number of battlepasses per organization. + /// Battlepass info by organization. /// - /// BattlepassCount: map Hash => u32 + /// BattlepassInfoByOrg: map Hash => Hash #[pallet::storage] - #[pallet::getter(fn get_battlepass_count)] - pub type BattlepassCount = StorageMap<_, Blake2_128Concat, T::Hash, u32, ValueQuery>; + // #[pallet::getter(fn get_battlepass_info)] + pub type BattlepassInfoByOrg = StorageMap<_, Blake2_128Concat, T::Hash, BattlepassInfo, OptionQuery>; - /// Current active battlepass in organization. + /// Claimed Battlepass-NFT by user and battlepass. /// - /// ActiveBattlepassByOrg: map Hash => Hash - #[pallet::storage] - #[pallet::getter(fn get_active_battlepass)] - pub type ActiveBattlepassByOrg = StorageMap<_, Blake2_128Concat, T::Hash, T::Hash, OptionQuery>; - - /// Claimed Battlepass-NFT by user account. - /// - /// ClaimedBattlepass: map (AccountId, Hash) => BattlepassNft + /// ClaimedBattlepasses: map (AccountId, Hash) => NftId #[pallet::storage] #[pallet::getter(fn get_claimed_battlepass)] - pub(super) type ClaimedBattlepass = StorageDoubleMap<_, + pub(super) type ClaimedBattlepasses = StorageDoubleMap<_, Blake2_128Concat, T::AccountId, Blake2_128Concat, T::Hash, - BattlepassNft, + NftId, OptionQuery >; @@ -155,38 +151,19 @@ pub mod pallet { price: u16, ) -> DispatchResult { let creator = ensure_signed(origin)?; - // check if Org exists - ensure!(T::Control::is_org_active(&org_id), Error::::OrgUnknown); + // check if Org is active + ensure!(T::Control::is_org_active(&org_id), Error::::OrgUnknownOrInactive); // check if origin is an Org Prime let prime = T::Control::org_prime_account(&org_id).ok_or(Error::::OrgPrimeUnknown)?; ensure!(creator == prime, Error::::AuthorizationError); // TODO: Add Root temporaryly - // check is there is no active battlepass for the Org - ensure!(!ActiveBattlepassByOrg::::contains_key(&org_id), Error::::BattlepassExists); - let new_season = Self::get_battlepass_count(org_id) + 1; - let now = >::block_number(); - - // Create collection - let metadata = BoundedVec::truncate_from(b"meta".to_vec()); // TODO: what should be here? - let symbol = BoundedVec::truncate_from(b"symbol".to_vec()); // TODO: what should be here? - let collection_id = T::Rmrk::collection_create(creator.clone(), metadata, None, symbol)?; - - // Create Battlepass - let battlepass: Battlepass> = types::Battlepass { - creator, - org_id, - name, - cid, - season: new_season, - collection_id, - price, - created: now.clone(), mutated: now - }; - let battlepass_id = ::Hashing::hash_of(&battlepass); - - Battlepasses::::insert(&battlepass_id, battlepass); - BattlepassStates::::insert(&battlepass_id, types::BattlepassState::Active); // TODO: change to Draft - ActiveBattlepassByOrg::::insert(org_id, battlepass_id); - BattlepassCount::::insert(org_id, new_season); + let (battlepass_count, maybe_active) = Self::get_battlepass_info(org_id); + // check if there is no active battlepass for the Org + ensure!(maybe_active.is_none(), Error::::BattlepassExists); + let new_season = battlepass_count + 1; + + // Create a collection to store Battlepass NFTs + let collection_id = Self::create_collection(creator.clone())?; + let battlepass_id = Self::do_create_battlepass(creator, org_id, name, cid, collection_id, price, new_season)?; Self::deposit_event(Event::BattlepassCreated { org_id, battlepass_id, season: new_season }); @@ -196,37 +173,26 @@ pub mod pallet { #[pallet::weight(0)] pub fn claim_battlepass( origin: OriginFor, - org_id: T::Hash, + battlepass_id: T::Hash, ) -> DispatchResult { let claimer = ensure_signed(origin)?; - // check if Org exists - ensure!(T::Control::is_org_active(&org_id), Error::::OrgUnknown); + // check if Battlepass exists + let battlepass = Self::get_battlepass(battlepass_id).ok_or(Error::::BattlepassUnknown)?; + // check if Battlepass is active + ensure!(Self::is_battlepass_active(battlepass_id), Error::::BattlepassInactive); + // check if Org is active + ensure!(T::Control::is_org_active(&battlepass.org_id), Error::::OrgUnknownOrInactive); // check if user is a member of organization - ensure!(T::Control::is_org_member_active(&org_id, &claimer), Error::::NotMember); - // check if Org has active battlepass - let battlepass_id = Self::get_active_battlepass(org_id).ok_or(Error::::BattlepassUnknown)?; + ensure!(T::Control::is_org_member_active(&battlepass.org_id, &claimer), Error::::NotMember); // check if Battlepass already claimed - ensure!(!ClaimedBattlepass::::contains_key(claimer.clone(), battlepass_id), Error::::BattlepassClaimed); - - let battlepass = Self::get_battlepass(battlepass_id).ok_or(Error::::BattlepassUnknown)?; - let collection = >::collections(battlepass.collection_id).ok_or(Error::::CollectionUnknown)?; + ensure!(!ClaimedBattlepasses::::contains_key(claimer.clone(), battlepass_id), Error::::BattlepassClaimed); - // Create NFT - let (collection_id, nft_id) = T::Rmrk::nft_mint( - claimer.clone(), // sender - claimer.clone(), // owner - collection.nfts_count, // nft_id - battlepass.collection_id, // collection_id - None, // royalty_recipient - None, // royalty_amount - BoundedVec::truncate_from(b"NFT meta".to_vec()), // metadata TODO: what should be here? - false, // transferable - None // resources - )?; + let collection = >::collections(battlepass.collection_id).ok_or(Error::::CollectionUnknown)?; + let new_nft_id = collection.nfts_count; - ClaimedBattlepass::::insert(&claimer, battlepass_id, BattlepassNft{collection_id, nft_id}); + Self::do_claim_battlepass(claimer.clone(), battlepass_id, new_nft_id, battlepass.collection_id)?; - Self::deposit_event(Event::BattlepassClaimed { claimer, org_id, battlepass_id }); + Self::deposit_event(Event::BattlepassClaimed { claimer, org_id: battlepass.org_id, battlepass_id, nft_id: new_nft_id }); Ok(()) } @@ -234,24 +200,105 @@ pub mod pallet { #[pallet::weight(0)] pub fn close_battlepass( origin: OriginFor, - org_id: T::Hash, + battlepass_id: T::Hash, ) -> DispatchResult { let sender = ensure_signed(origin)?; - // check if Org exists - ensure!(T::Control::is_org_active(&org_id), Error::::OrgUnknown); + // check if Battlepass exists + let battlepass = Self::get_battlepass(battlepass_id).ok_or(Error::::BattlepassUnknown)?; + // check if Battlepass is active + ensure!(Self::is_battlepass_active(battlepass_id), Error::::BattlepassInactive); + // check if Org is active + ensure!(T::Control::is_org_active(&battlepass.org_id), Error::::OrgUnknownOrInactive); // check if origin is an Org Prime - let prime = T::Control::org_prime_account(&org_id).ok_or(Error::::OrgPrimeUnknown)?; - ensure!(sender == prime, Error::::AuthorizationError); // TODO: Add Root temporaryly - // check if Org has active battlepass - let battlepass_id = Self::get_active_battlepass(org_id).ok_or(Error::::BattlepassUnknown)?; + let prime = T::Control::org_prime_account(&battlepass.org_id).ok_or(Error::::OrgPrimeUnknown)?; + ensure!(sender == prime, Error::::AuthorizationError); // TODO: Add Root temporarily - BattlepassStates::::insert(&battlepass_id, types::BattlepassState::Closed); - ActiveBattlepassByOrg::::remove(org_id); + Self::do_close_battlepass(battlepass.org_id, battlepass_id)?; - Self::deposit_event(Event::BattlepassClosed { closed_by: sender, org_id, battlepass_id }); + Self::deposit_event(Event::BattlepassClosed { closed_by: sender, org_id: battlepass.org_id, battlepass_id }); Ok(()) } } +} + +impl Pallet { + fn create_collection(owner: T::AccountId) -> Result { + let metadata = BoundedVec::truncate_from(b"meta".to_vec()); // TODO: what should be here? + let symbol = BoundedVec::truncate_from(b"symbol".to_vec()); // TODO: what should be here? + let collection_id = T::Rmrk::collection_create(owner, metadata, None, symbol)?; + + Ok(collection_id) + } + + fn is_battlepass_active(battlepass_id: T::Hash) -> bool { + if let Some(bp_state) = Self::get_battlepass_state(battlepass_id) { + return bp_state == BattlepassState::ACTIVE; + } + return false; + } + + fn get_battlepass_info(org_id: T::Hash) -> (u32, Option) { + if let Some(bp_info) = BattlepassInfoByOrg::::get(&org_id) { + return (bp_info.count, bp_info.active); + } else { + return (0, None); + } + } + + fn do_create_battlepass(creator: T::AccountId, org_id: T::Hash, name: String, cid: String, collection_id: u32, price: u16, new_season:u32) -> Result { + let battlepass: Battlepass> = types::Battlepass { + creator, + org_id, + name, + cid, + season: new_season, + collection_id, + price + }; + let battlepass_id = ::Hashing::hash_of(&battlepass); + + Battlepasses::::insert(&battlepass_id, battlepass); + BattlepassStates::::insert(&battlepass_id, types::BattlepassState::ACTIVE); // TODO: change to Draft + BattlepassInfoByOrg::::insert(org_id, BattlepassInfo{count: new_season, active: Some(battlepass_id)}); + + Ok(battlepass_id) + } + + fn do_claim_battlepass(claimer: T::AccountId, battlepass_id: T::Hash, nft_id: u32, collection_id: u32) -> DispatchResult { + + // Create Battlepass NFT + // let metadata = battlepass_id.to_string().into_bytes(); + let metadata = b"meta".to_vec(); + let (_, nft_id) = T::Rmrk::nft_mint( + claimer.clone(), // sender + claimer.clone(), // owner + nft_id, // nft_id + collection_id, // collection_id + None, // royalty_recipient + None, // royalty_amount + BoundedVec::truncate_from(metadata), // metadata TODO: what should be here? + false, // transferable + None // resources + )?; + + ClaimedBattlepasses::::insert(&claimer, battlepass_id, nft_id); + + Ok(()) + } + + fn do_close_battlepass(org_id: T::Hash, battlepass_id: T::Hash) -> DispatchResult { + BattlepassStates::::insert(&battlepass_id, types::BattlepassState::CLOSED); + BattlepassInfoByOrg::::try_mutate(org_id, |info| -> Result<(), DispatchError> { + if let Some(inf) = info { + inf.active = None; + Ok(()) + } else { + return Err(Error::::BattlepassInfoUnknown)?; + } + })?; + + Ok(()) + } } \ No newline at end of file diff --git a/battlepass/src/types.rs b/battlepass/src/types.rs index a5921acca..1a7c0eb87 100644 --- a/battlepass/src/types.rs +++ b/battlepass/src/types.rs @@ -3,32 +3,35 @@ use codec::MaxEncodedLen; #[derive(Encode, Decode, Clone, PartialEq, Eq, PartialOrd, Ord, TypeInfo, MaxEncodedLen)] pub enum BattlepassState { - Draft = 0, - Active = 1, - Closed = 2, + DRAFT = 0, + ACTIVE = 1, + CLOSED = 2, } impl Default for BattlepassState { fn default() -> Self { - Self::Draft + Self::DRAFT } } #[derive(Encode, Decode, Default, PartialEq, Eq, TypeInfo, MaxEncodedLen)] -pub struct Battlepass { +/// Battlepass struct +/// +/// `collection_id`: Collection that will store all claimed Battlepass-NFTs +pub struct Battlepass { pub creator: AccountId, pub org_id: Hash, pub name: BoundedString, pub cid: BoundedString, - pub season: u32, - pub price: u16, // TODO: introduce currency + pub season: u32, + pub price: u16, // TODO: introduce currency /// Collection that will store all claimed Battlepass-NFTs - pub collection_id: u32, - pub created: BlockNumber, - pub mutated: BlockNumber, + pub collection_id: u32 } #[derive(Encode, Decode, Default, PartialEq, Eq, TypeInfo, MaxEncodedLen)] -pub struct BattlepassNft { - pub collection_id: u32, - pub nft_id: u32, +pub struct BattlepassInfo { + /// Total number of battlepasses per organization. + pub count: u32, + /// Curent active battlepass + pub active: Option } \ No newline at end of file From d4dd5e7c5a05f0acd463c925cf5a08c08dd18545 Mon Sep 17 00:00:00 2001 From: FiberMan Date: Thu, 22 Dec 2022 11:45:52 +0100 Subject: [PATCH 10/49] Add Battlepass activation, refactor. --- battlepass/src/lib.rs | 105 +++++++++++++++++++++++++++------------- battlepass/src/types.rs | 4 +- 2 files changed, 73 insertions(+), 36 deletions(-) diff --git a/battlepass/src/lib.rs b/battlepass/src/lib.rs index 4a3c65129..18a8edcde 100644 --- a/battlepass/src/lib.rs +++ b/battlepass/src/lib.rs @@ -36,7 +36,7 @@ pub type Resource = BoundedVec< #[frame_support::pallet] pub mod pallet { use super::*; - + #[pallet::pallet] #[pallet::generate_store(pub(super) trait Store)] pub struct Pallet(_); @@ -79,15 +79,23 @@ pub mod pallet { /// BattlePass claimed BattlepassClaimed { - claimer: T::AccountId, + by_who: T::AccountId, + for_who: T::AccountId, org_id: T::Hash, battlepass_id: T::Hash, nft_id: NftId }, - /// BattlePass closed - BattlepassClosed { - closed_by: T::AccountId, + /// BattlePass activated + BattlepassActivated { + by_who: T::AccountId, + org_id: T::Hash, + battlepass_id: T::Hash + }, + + /// BattlePass ended + BattlepassEnded { + by_who: T::AccountId, org_id: T::Hash, battlepass_id: T::Hash }, @@ -102,6 +110,8 @@ pub mod pallet { BattlepassClaimed, BattlepassInactive, BattlepassUnknown, + BattlepassStateUnknown, + BattlepassStateWrong, BattlepassInfoUnknown, NotMember, CollectionUnknown, @@ -123,19 +133,19 @@ pub mod pallet { /// Battlepass info by organization. /// - /// BattlepassInfoByOrg: map Hash => Hash + /// BattlepassInfoByOrg: map Hash => BattlepassInfo #[pallet::storage] // #[pallet::getter(fn get_battlepass_info)] pub type BattlepassInfoByOrg = StorageMap<_, Blake2_128Concat, T::Hash, BattlepassInfo, OptionQuery>; /// Claimed Battlepass-NFT by user and battlepass. /// - /// ClaimedBattlepasses: map (AccountId, Hash) => NftId + /// ClaimedBattlepasses: map (Hash, AccountId) => NftId #[pallet::storage] #[pallet::getter(fn get_claimed_battlepass)] pub(super) type ClaimedBattlepasses = StorageDoubleMap<_, - Blake2_128Concat, T::AccountId, Blake2_128Concat, T::Hash, + Blake2_128Concat, T::AccountId, NftId, OptionQuery >; @@ -155,7 +165,7 @@ pub mod pallet { ensure!(T::Control::is_org_active(&org_id), Error::::OrgUnknownOrInactive); // check if origin is an Org Prime let prime = T::Control::org_prime_account(&org_id).ok_or(Error::::OrgPrimeUnknown)?; - ensure!(creator == prime, Error::::AuthorizationError); // TODO: Add Root temporaryly + ensure!(creator == prime, Error::::AuthorizationError); // TODO: Add Bot account let (battlepass_count, maybe_active) = Self::get_battlepass_info(org_id); // check if there is no active battlepass for the Org ensure!(maybe_active.is_none(), Error::::BattlepassExists); @@ -174,52 +184,78 @@ pub mod pallet { pub fn claim_battlepass( origin: OriginFor, battlepass_id: T::Hash, + for_who: T::AccountId, ) -> DispatchResult { - let claimer = ensure_signed(origin)?; + let by_who = ensure_signed(origin)?; // check if Battlepass exists let battlepass = Self::get_battlepass(battlepass_id).ok_or(Error::::BattlepassUnknown)?; - // check if Battlepass is active - ensure!(Self::is_battlepass_active(battlepass_id), Error::::BattlepassInactive); + // check if Battlepass in ACTIVE state + ensure!(Self::check_battlepass_state(battlepass_id, BattlepassState::ACTIVE)?, Error::::BattlepassInactive); // check if Org is active ensure!(T::Control::is_org_active(&battlepass.org_id), Error::::OrgUnknownOrInactive); + // check if origin is an Org Prime + let prime = T::Control::org_prime_account(&battlepass.org_id).ok_or(Error::::OrgPrimeUnknown)?; + ensure!(by_who == prime, Error::::AuthorizationError); // TODO: Add Root temporarily + // check if user is a member of organization - ensure!(T::Control::is_org_member_active(&battlepass.org_id, &claimer), Error::::NotMember); + ensure!(T::Control::is_org_member_active(&battlepass.org_id, &for_who), Error::::NotMember); // check if Battlepass already claimed - ensure!(!ClaimedBattlepasses::::contains_key(claimer.clone(), battlepass_id), Error::::BattlepassClaimed); + ensure!(!ClaimedBattlepasses::::contains_key(battlepass_id, for_who.clone()), Error::::BattlepassClaimed); let collection = >::collections(battlepass.collection_id).ok_or(Error::::CollectionUnknown)?; let new_nft_id = collection.nfts_count; - Self::do_claim_battlepass(claimer.clone(), battlepass_id, new_nft_id, battlepass.collection_id)?; + Self::do_claim_battlepass(by_who.clone(), for_who.clone(), battlepass_id, new_nft_id, battlepass.collection_id)?; - Self::deposit_event(Event::BattlepassClaimed { claimer, org_id: battlepass.org_id, battlepass_id, nft_id: new_nft_id }); + Self::deposit_event(Event::BattlepassClaimed { by_who, for_who, org_id: battlepass.org_id, battlepass_id, nft_id: new_nft_id }); Ok(()) } #[pallet::weight(0)] - pub fn close_battlepass( + pub fn activate_battlepass( origin: OriginFor, battlepass_id: T::Hash, ) -> DispatchResult { let sender = ensure_signed(origin)?; // check if Battlepass exists let battlepass = Self::get_battlepass(battlepass_id).ok_or(Error::::BattlepassUnknown)?; - // check if Battlepass is active - ensure!(Self::is_battlepass_active(battlepass_id), Error::::BattlepassInactive); + // check if Battlepass in DRAFT state + ensure!(Self::check_battlepass_state(battlepass_id, BattlepassState::DRAFT)?, Error::::BattlepassStateWrong); // check if Org is active ensure!(T::Control::is_org_active(&battlepass.org_id), Error::::OrgUnknownOrInactive); // check if origin is an Org Prime let prime = T::Control::org_prime_account(&battlepass.org_id).ok_or(Error::::OrgPrimeUnknown)?; ensure!(sender == prime, Error::::AuthorizationError); // TODO: Add Root temporarily - Self::do_close_battlepass(battlepass.org_id, battlepass_id)?; + Self::change_battlepass_state(battlepass.org_id, battlepass_id, types::BattlepassState::ACTIVE)?; - Self::deposit_event(Event::BattlepassClosed { closed_by: sender, org_id: battlepass.org_id, battlepass_id }); + Self::deposit_event(Event::BattlepassActivated { by_who: sender, org_id: battlepass.org_id, battlepass_id }); Ok(()) } + #[pallet::weight(0)] + pub fn conclude_battlepass( + origin: OriginFor, + battlepass_id: T::Hash, + ) -> DispatchResult { + let sender = ensure_signed(origin)?; + // check if Battlepass exists + let battlepass = Self::get_battlepass(battlepass_id).ok_or(Error::::BattlepassUnknown)?; + // check if Battlepass in ACTIVE state + ensure!(Self::check_battlepass_state(battlepass_id, BattlepassState::ACTIVE)?, Error::::BattlepassStateWrong); + // check if Org is active - no need to conclude battlepass + // check if origin is an Org Prime + let prime = T::Control::org_prime_account(&battlepass.org_id).ok_or(Error::::OrgPrimeUnknown)?; + ensure!(sender == prime, Error::::AuthorizationError); // TODO: Add Bot account + + Self::change_battlepass_state(battlepass.org_id, battlepass_id, types::BattlepassState::ENDED)?; + + Self::deposit_event(Event::BattlepassEnded { by_who: sender, org_id: battlepass.org_id, battlepass_id }); + + Ok(()) + } } } @@ -232,11 +268,10 @@ impl Pallet { Ok(collection_id) } - fn is_battlepass_active(battlepass_id: T::Hash) -> bool { - if let Some(bp_state) = Self::get_battlepass_state(battlepass_id) { - return bp_state == BattlepassState::ACTIVE; - } - return false; + fn check_battlepass_state(battlepass_id: T::Hash, state: types::BattlepassState) -> Result { + let current_state = Self::get_battlepass_state(battlepass_id).ok_or(Error::::BattlepassStateUnknown)?; + + Ok(current_state == state) } fn get_battlepass_info(org_id: T::Hash) -> (u32, Option) { @@ -260,20 +295,20 @@ impl Pallet { let battlepass_id = ::Hashing::hash_of(&battlepass); Battlepasses::::insert(&battlepass_id, battlepass); - BattlepassStates::::insert(&battlepass_id, types::BattlepassState::ACTIVE); // TODO: change to Draft + BattlepassStates::::insert(&battlepass_id, types::BattlepassState::DRAFT); BattlepassInfoByOrg::::insert(org_id, BattlepassInfo{count: new_season, active: Some(battlepass_id)}); Ok(battlepass_id) } - fn do_claim_battlepass(claimer: T::AccountId, battlepass_id: T::Hash, nft_id: u32, collection_id: u32) -> DispatchResult { + fn do_claim_battlepass(by_who: T::AccountId, for_who: T::AccountId, battlepass_id: T::Hash, nft_id: u32, collection_id: u32) -> DispatchResult { // Create Battlepass NFT // let metadata = battlepass_id.to_string().into_bytes(); let metadata = b"meta".to_vec(); let (_, nft_id) = T::Rmrk::nft_mint( - claimer.clone(), // sender - claimer.clone(), // owner + by_who.clone(), // sender + for_who.clone(), // owner nft_id, // nft_id collection_id, // collection_id None, // royalty_recipient @@ -283,16 +318,18 @@ impl Pallet { None // resources )?; - ClaimedBattlepasses::::insert(&claimer, battlepass_id, nft_id); + ClaimedBattlepasses::::insert(battlepass_id, &for_who, nft_id); Ok(()) } - fn do_close_battlepass(org_id: T::Hash, battlepass_id: T::Hash) -> DispatchResult { - BattlepassStates::::insert(&battlepass_id, types::BattlepassState::CLOSED); + fn change_battlepass_state(org_id: T::Hash, battlepass_id: T::Hash, state: types::BattlepassState) -> DispatchResult { + let active_battlepass = if state == types::BattlepassState::ACTIVE { Some(battlepass_id) } else { None }; + + BattlepassStates::::insert(&battlepass_id, state); BattlepassInfoByOrg::::try_mutate(org_id, |info| -> Result<(), DispatchError> { if let Some(inf) = info { - inf.active = None; + inf.active = active_battlepass; Ok(()) } else { return Err(Error::::BattlepassInfoUnknown)?; diff --git a/battlepass/src/types.rs b/battlepass/src/types.rs index 1a7c0eb87..816cd90f7 100644 --- a/battlepass/src/types.rs +++ b/battlepass/src/types.rs @@ -1,11 +1,11 @@ use frame_support::pallet_prelude::*; use codec::MaxEncodedLen; -#[derive(Encode, Decode, Clone, PartialEq, Eq, PartialOrd, Ord, TypeInfo, MaxEncodedLen)] +#[derive(Encode, Decode, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, TypeInfo, MaxEncodedLen)] pub enum BattlepassState { DRAFT = 0, ACTIVE = 1, - CLOSED = 2, + ENDED = 2, } impl Default for BattlepassState { fn default() -> Self { From faa8262afa117b6017041dee097953b9b698f78a Mon Sep 17 00:00:00 2001 From: Vasylenko Yevhen Date: Thu, 29 Dec 2022 13:52:13 +0200 Subject: [PATCH 11/49] Update lib.rs (#123) --- control/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/control/src/lib.rs b/control/src/lib.rs index cb631ff6d..6ad3b990e 100644 --- a/control/src/lib.rs +++ b/control/src/lib.rs @@ -688,7 +688,7 @@ impl Pallet { match origin.into() { Ok(RawOrigin::Root) => Ok(()), Ok(RawOrigin::Signed(t)) => { - if org_type == OrgType::Individual && t == prime { + if t == prime { return Ok(()); } Err(BadOrigin) From 6246e36bcf3c28229b31ba7718352bc063412d96 Mon Sep 17 00:00:00 2001 From: Yura Date: Fri, 13 Jan 2023 08:29:15 +0100 Subject: [PATCH 12/49] add levels and rewards to battlepass. (#124) --- battlepass/src/lib.rs | 378 ++++++++++++++++++++++++++++++++++++---- battlepass/src/types.rs | 31 +++- 2 files changed, 375 insertions(+), 34 deletions(-) diff --git a/battlepass/src/lib.rs b/battlepass/src/lib.rs index 18a8edcde..8fc12b753 100644 --- a/battlepass/src/lib.rs +++ b/battlepass/src/lib.rs @@ -99,22 +99,71 @@ pub mod pallet { org_id: T::Hash, battlepass_id: T::Hash }, + + /// Points updated for user + PointsUpdated { + by_who: T::AccountId, + for_who: T::AccountId, + battlepass_id: T::Hash, + amount: u32 + }, + + /// New Reward created + RewardCreated { + reward_id: T::Hash, + battlepass_id: T::Hash, + level: u8 + }, + + /// Reward claimed by user + RewardClaimed { + reward_id: T::Hash, + claimer: T::AccountId, + collection_id: u32, + nft_id: NftId + }, + + /// Reward state updated + RewardStateUpdated { + reward_id: T::Hash, + state: RewardState + }, + + /// Achievement level added for Battlepass + LevelAdded { + battlepass_id: T::Hash, + level: u8, + points: u32 + }, + + /// Achievement level removed from Battlepass + LevelRemoved { + battlepass_id: T::Hash, + level: u8 + } } #[pallet::error] pub enum Error { AuthorizationError, - OrgPrimeUnknown, - OrgUnknownOrInactive, + CollectionUnknown, BattlepassExists, BattlepassClaimed, BattlepassInactive, + BattlepassNotClaimed, BattlepassUnknown, BattlepassStateUnknown, BattlepassStateWrong, BattlepassInfoUnknown, + NftUnknown, + NftInvalid, NotMember, - CollectionUnknown, + NotEnoughPoints, + OrgPrimeUnknown, + OrgUnknownOrInactive, + RewardInactive, + RewardUnknown, + RewardStateUnknown, } /// Battlepass by its id. @@ -150,6 +199,56 @@ pub mod pallet { OptionQuery >; + /// Total earned Points for users per each Battlepass. + /// + /// Points: map (Hash, AccountId) => NftId + #[pallet::storage] + #[pallet::getter(fn get_points)] + pub(super) type Points = StorageDoubleMap<_, + Blake2_128Concat, T::Hash, + Blake2_128Concat, T::AccountId, + u32, + ValueQuery + >; + + /// Reward by its id. + /// + /// Rewards: map Hash => Reward + #[pallet::storage] + #[pallet::getter(fn get_reward)] + pub(super) type Rewards = StorageMap<_, Blake2_128Concat, T::Hash, Reward>, OptionQuery>; + + /// Reward state by its id. + /// + /// RewardStates: map Hash => RewardState + #[pallet::storage] + #[pallet::getter(fn get_reward_state)] + pub(super) type RewardStates = StorageMap<_, Blake2_128Concat, T::Hash, RewardState, OptionQuery>; + + /// Claimed Reward-NFT by user. + /// + /// ClaimedRewards: map (AccountId, Hash) => NftId + #[pallet::storage] + #[pallet::getter(fn get_claimed_rewards)] + pub(super) type ClaimedRewards = StorageDoubleMap<_, + Blake2_128Concat, T::AccountId, + Blake2_128Concat, T::Hash, + NftId, + OptionQuery + >; + + /// Achievement levels mapping for Battlepass + /// + /// Levels: map (Hash, u8) => u32 + #[pallet::storage] + #[pallet::getter(fn get_levels)] + pub(super) type Levels = StorageDoubleMap<_, + Blake2_128Concat, T::Hash, + Blake2_128Concat, u8, + u32, + OptionQuery + >; + #[pallet::call] impl Pallet { #[pallet::weight(0)] @@ -163,16 +262,15 @@ pub mod pallet { let creator = ensure_signed(origin)?; // check if Org is active ensure!(T::Control::is_org_active(&org_id), Error::::OrgUnknownOrInactive); - // check if origin is an Org Prime - let prime = T::Control::org_prime_account(&org_id).ok_or(Error::::OrgPrimeUnknown)?; - ensure!(creator == prime, Error::::AuthorizationError); // TODO: Add Bot account + // check permissions (prime) + ensure!(Self::is_prime(&org_id, creator.clone())?, Error::::AuthorizationError); let (battlepass_count, maybe_active) = Self::get_battlepass_info(org_id); // check if there is no active battlepass for the Org ensure!(maybe_active.is_none(), Error::::BattlepassExists); let new_season = battlepass_count + 1; // Create a collection to store Battlepass NFTs - let collection_id = Self::create_collection(creator.clone())?; + let collection_id = Self::create_collection(creator.clone(), None)?; let battlepass_id = Self::do_create_battlepass(creator, org_id, name, cid, collection_id, price, new_season)?; Self::deposit_event(Event::BattlepassCreated { org_id, battlepass_id, season: new_season }); @@ -193,10 +291,9 @@ pub mod pallet { ensure!(Self::check_battlepass_state(battlepass_id, BattlepassState::ACTIVE)?, Error::::BattlepassInactive); // check if Org is active ensure!(T::Control::is_org_active(&battlepass.org_id), Error::::OrgUnknownOrInactive); - // check if origin is an Org Prime - let prime = T::Control::org_prime_account(&battlepass.org_id).ok_or(Error::::OrgPrimeUnknown)?; - ensure!(by_who == prime, Error::::AuthorizationError); // TODO: Add Root temporarily - + // check permissions (prime, bot, self - temp) + // TODO: remove self when bot is ready + ensure!(by_who == for_who || Self::is_prime_or_bot(&battlepass.org_id, by_who.clone())?, Error::::AuthorizationError); // check if user is a member of organization ensure!(T::Control::is_org_member_active(&battlepass.org_id, &for_who), Error::::NotMember); // check if Battlepass already claimed @@ -224,11 +321,10 @@ pub mod pallet { ensure!(Self::check_battlepass_state(battlepass_id, BattlepassState::DRAFT)?, Error::::BattlepassStateWrong); // check if Org is active ensure!(T::Control::is_org_active(&battlepass.org_id), Error::::OrgUnknownOrInactive); - // check if origin is an Org Prime - let prime = T::Control::org_prime_account(&battlepass.org_id).ok_or(Error::::OrgPrimeUnknown)?; - ensure!(sender == prime, Error::::AuthorizationError); // TODO: Add Root temporarily + // check permissions (prime) + ensure!(Self::is_prime(&battlepass.org_id, sender.clone())?, Error::::AuthorizationError); - Self::change_battlepass_state(battlepass.org_id, battlepass_id, types::BattlepassState::ACTIVE)?; + Self::change_battlepass_state(battlepass.org_id, battlepass_id, BattlepassState::ACTIVE)?; Self::deposit_event(Event::BattlepassActivated { by_who: sender, org_id: battlepass.org_id, battlepass_id }); @@ -245,35 +341,221 @@ pub mod pallet { let battlepass = Self::get_battlepass(battlepass_id).ok_or(Error::::BattlepassUnknown)?; // check if Battlepass in ACTIVE state ensure!(Self::check_battlepass_state(battlepass_id, BattlepassState::ACTIVE)?, Error::::BattlepassStateWrong); - // check if Org is active - no need to conclude battlepass - // check if origin is an Org Prime - let prime = T::Control::org_prime_account(&battlepass.org_id).ok_or(Error::::OrgPrimeUnknown)?; - ensure!(sender == prime, Error::::AuthorizationError); // TODO: Add Bot account + // check permissions (prime) + ensure!(Self::is_prime(&battlepass.org_id, sender.clone())?, Error::::AuthorizationError); - Self::change_battlepass_state(battlepass.org_id, battlepass_id, types::BattlepassState::ENDED)?; + Self::change_battlepass_state(battlepass.org_id, battlepass_id, BattlepassState::ENDED)?; Self::deposit_event(Event::BattlepassEnded { by_who: sender, org_id: battlepass.org_id, battlepass_id }); Ok(()) } + + #[pallet::weight(0)] + pub fn set_points( + origin: OriginFor, + battlepass_id: T::Hash, + account: T::AccountId, + amount: u32 + ) -> DispatchResult { + let sender = ensure_signed(origin)?; + // check if Battlepass exists + let battlepass = Self::get_battlepass(battlepass_id).ok_or(Error::::BattlepassUnknown)?; + // check if Battlepass in ACTIVE state + ensure!(Self::check_battlepass_state(battlepass_id, BattlepassState::ACTIVE)?, Error::::BattlepassStateWrong); + // check if Org is active + ensure!(T::Control::is_org_active(&battlepass.org_id), Error::::OrgUnknownOrInactive); + // check permissions (prime, bot) + ensure!(Self::is_prime_or_bot(&battlepass.org_id, sender.clone())?, Error::::AuthorizationError); + // check if user is a member of organization + ensure!(T::Control::is_org_member_active(&battlepass.org_id, &account), Error::::NotMember); + + Points::::insert(battlepass_id, &account, amount); + + Self::deposit_event(Event::PointsUpdated { by_who: sender, for_who: account, battlepass_id, amount }); + + Ok(()) + } + + #[pallet::weight(0)] + pub fn create_reward( + origin: OriginFor, + battlepass_id: T::Hash, + name: String, + cid: String, + max: Option, + level: u8, + transferable: bool, + ) -> DispatchResult { + let creator = ensure_signed(origin)?; + // check if Battlepass exists + let battlepass = Self::get_battlepass(battlepass_id).ok_or(Error::::BattlepassUnknown)?; + // check if Battlepass in ACTIVE state + ensure!(Self::check_battlepass_state(battlepass_id, BattlepassState::ACTIVE)?, Error::::BattlepassStateWrong); + // check if Org is active + ensure!(T::Control::is_org_active(&battlepass.org_id), Error::::OrgUnknownOrInactive); + // check permissions (prime) + ensure!(Self::is_prime(&battlepass.org_id, creator.clone())?, Error::::AuthorizationError); + + let collection_id = Self::create_collection(creator.clone(), max)?; + let reward_id = Self::do_create_reward(battlepass_id, name, cid, level, transferable, collection_id)?; + + Self::deposit_event(Event::RewardCreated { reward_id, battlepass_id, level }); + + Ok(()) + } + + #[pallet::weight(0)] + pub fn disable_reward( + origin: OriginFor, + reward_id: T::Hash + ) -> DispatchResult { + let creator = ensure_signed(origin)?; + // check if Reward exists + let reward = Self::get_reward(reward_id).ok_or(Error::::RewardUnknown)?; + // check if Reward is active + ensure!(Self::check_reward_state(reward_id, RewardState::ACTIVE)?, Error::::RewardInactive); + // check if Battlepass exists + let battlepass = Self::get_battlepass(reward.battlepass_id).ok_or(Error::::BattlepassUnknown)?; + // check permissions (prime) + ensure!(Self::is_prime(&battlepass.org_id, creator.clone())?, Error::::AuthorizationError); + + let state = RewardState::INACTIVE; + + RewardStates::::insert(reward_id, state.clone()); + + Self::deposit_event(Event::RewardStateUpdated {reward_id, state} ); + + Ok(()) + } + + #[pallet::weight(0)] + pub fn claim_reward( + origin: OriginFor, + reward_id: T::Hash, + ) -> DispatchResult { + let claimer = ensure_signed(origin)?; + // check if Reward exists + let reward = Self::get_reward(reward_id).ok_or(Error::::RewardUnknown)?; + // check if Reward is active + ensure!(Self::check_reward_state(reward_id, RewardState::ACTIVE)?, Error::::RewardInactive); + // check if Battlepass exists + let battlepass = Self::get_battlepass(&reward.battlepass_id).ok_or(Error::::BattlepassUnknown)?; + // check if Battlepass in ACTIVE state + ensure!(Self::check_battlepass_state(reward.battlepass_id, BattlepassState::ACTIVE)?, Error::::BattlepassStateWrong); + // check if Org is active + ensure!(T::Control::is_org_active(&battlepass.org_id), Error::::OrgUnknownOrInactive); + // check if user is a member of organization + ensure!(T::Control::is_org_member_active(&battlepass.org_id, &claimer), Error::::NotMember); + // check if user owns Battlepass NFT + let nft_id = Self::get_claimed_battlepass(reward.battlepass_id, &claimer).ok_or(Error::::BattlepassNotClaimed)?; + // check if NFT exists + let bp_nft = >::nfts(&reward.collection_id, nft_id).ok_or(Error::::NftUnknown)?; + // validate NFT + let metadata: String = BoundedVec::truncate_from(reward.battlepass_id.encode()); + ensure!(metadata == bp_nft.metadata, Error::::NftInvalid); + // check if user has enough Points + ensure!(Self::is_enough_points(&reward.battlepass_id, &claimer, reward.level), Error::::NotEnoughPoints); + + Self::do_claim_reward(claimer.clone(), reward_id, nft_id, reward.collection_id, reward.transferable)?; + + Self::deposit_event(Event::RewardClaimed {reward_id, claimer, collection_id: reward.collection_id, nft_id} ); + + Ok(()) + } + + #[pallet::weight(0)] + pub fn add_level( + origin: OriginFor, + battlepass_id: T::Hash, + level: u8, + points: u32 + ) -> DispatchResult { + let sender = ensure_signed(origin)?; + // check if Battlepass exists + let battlepass = Self::get_battlepass(battlepass_id).ok_or(Error::::BattlepassUnknown)?; + // check if Battlepass is not ended + ensure!(!Self::check_battlepass_state(battlepass_id, BattlepassState::ENDED)?, Error::::BattlepassStateWrong); + // check if Org is active + ensure!(T::Control::is_org_active(&battlepass.org_id), Error::::OrgUnknownOrInactive); + // check permissions (prime) + ensure!(Self::is_prime(&battlepass.org_id, sender.clone())?, Error::::AuthorizationError); + + Levels::::insert(battlepass_id, level, points); + + Self::deposit_event(Event::LevelAdded { battlepass_id, level, points } ); + + Ok(()) + } + + #[pallet::weight(0)] + pub fn remove_level( + origin: OriginFor, + battlepass_id: T::Hash, + level: u8 + ) -> DispatchResult { + let sender = ensure_signed(origin)?; + // check if Battlepass exists + let battlepass = Self::get_battlepass(battlepass_id).ok_or(Error::::BattlepassUnknown)?; + // check if Battlepass is not ended + ensure!(!Self::check_battlepass_state(battlepass_id, BattlepassState::ENDED)?, Error::::BattlepassStateWrong); + // check if Org is active + ensure!(T::Control::is_org_active(&battlepass.org_id), Error::::OrgUnknownOrInactive); + // check permissions (prime) + ensure!(Self::is_prime(&battlepass.org_id, sender.clone())?, Error::::AuthorizationError); + + Levels::::remove(battlepass_id, level); + + Self::deposit_event(Event::LevelRemoved { battlepass_id, level } ); + + Ok(()) + } } } impl Pallet { - fn create_collection(owner: T::AccountId) -> Result { + + fn is_prime(org_id: &T::Hash, who: T::AccountId) -> Result { + let prime = T::Control::org_prime_account(org_id).ok_or(Error::::OrgPrimeUnknown)?; + Ok(who == prime) + } + + fn is_prime_or_bot(org_id: &T::Hash, who: T::AccountId) -> Result { + // TODO: implement check + let is_bot = false; + Ok(Self::is_prime(org_id, who)? || is_bot) + } + + fn is_enough_points(battlepass_id: &T::Hash, account: &T::AccountId, level: u8) -> bool { + let user_points = Self::get_points(battlepass_id, account); + let levels = Levels::::iter_prefix(battlepass_id) + .filter( + |(lvl, pnt)| level == *lvl && user_points >= *pnt + ); + + levels.count() == 1 + } + + fn create_collection(owner: T::AccountId, max: Option) -> Result { let metadata = BoundedVec::truncate_from(b"meta".to_vec()); // TODO: what should be here? let symbol = BoundedVec::truncate_from(b"symbol".to_vec()); // TODO: what should be here? - let collection_id = T::Rmrk::collection_create(owner, metadata, None, symbol)?; + let collection_id = T::Rmrk::collection_create(owner, metadata, max, symbol)?; Ok(collection_id) } - fn check_battlepass_state(battlepass_id: T::Hash, state: types::BattlepassState) -> Result { + fn check_battlepass_state(battlepass_id: T::Hash, state: BattlepassState) -> Result { let current_state = Self::get_battlepass_state(battlepass_id).ok_or(Error::::BattlepassStateUnknown)?; Ok(current_state == state) } + fn check_reward_state(reward_id: T::Hash, state: RewardState) -> Result { + let current_state = Self::get_reward_state(reward_id).ok_or(Error::::RewardStateUnknown)?; + + Ok(current_state == state) + } + fn get_battlepass_info(org_id: T::Hash) -> (u32, Option) { if let Some(bp_info) = BattlepassInfoByOrg::::get(&org_id) { return (bp_info.count, bp_info.active); @@ -283,7 +565,7 @@ impl Pallet { } fn do_create_battlepass(creator: T::AccountId, org_id: T::Hash, name: String, cid: String, collection_id: u32, price: u16, new_season:u32) -> Result { - let battlepass: Battlepass> = types::Battlepass { + let battlepass: Battlepass> = Battlepass { creator, org_id, name, @@ -295,7 +577,7 @@ impl Pallet { let battlepass_id = ::Hashing::hash_of(&battlepass); Battlepasses::::insert(&battlepass_id, battlepass); - BattlepassStates::::insert(&battlepass_id, types::BattlepassState::DRAFT); + BattlepassStates::::insert(&battlepass_id, BattlepassState::DRAFT); BattlepassInfoByOrg::::insert(org_id, BattlepassInfo{count: new_season, active: Some(battlepass_id)}); Ok(battlepass_id) @@ -304,10 +586,9 @@ impl Pallet { fn do_claim_battlepass(by_who: T::AccountId, for_who: T::AccountId, battlepass_id: T::Hash, nft_id: u32, collection_id: u32) -> DispatchResult { // Create Battlepass NFT - // let metadata = battlepass_id.to_string().into_bytes(); - let metadata = b"meta".to_vec(); + let metadata = battlepass_id.encode(); let (_, nft_id) = T::Rmrk::nft_mint( - by_who.clone(), // sender + by_who.clone(), // sender for_who.clone(), // owner nft_id, // nft_id collection_id, // collection_id @@ -323,8 +604,8 @@ impl Pallet { Ok(()) } - fn change_battlepass_state(org_id: T::Hash, battlepass_id: T::Hash, state: types::BattlepassState) -> DispatchResult { - let active_battlepass = if state == types::BattlepassState::ACTIVE { Some(battlepass_id) } else { None }; + fn change_battlepass_state(org_id: T::Hash, battlepass_id: T::Hash, state: BattlepassState) -> DispatchResult { + let active_battlepass = if state == BattlepassState::ACTIVE { Some(battlepass_id) } else { None }; BattlepassStates::::insert(&battlepass_id, state); BattlepassInfoByOrg::::try_mutate(org_id, |info| -> Result<(), DispatchError> { @@ -338,4 +619,41 @@ impl Pallet { Ok(()) } + + fn do_create_reward(battlepass_id: T::Hash, name: String, cid: String, level: u8, transferable: bool, collection_id: u32) -> Result { + let reward = Reward{ + battlepass_id, + name, + cid, + level, + transferable, + collection_id + }; + let reward_id = ::Hashing::hash_of(&reward); + + Rewards::::insert(reward_id, reward); + RewardStates::::insert(reward_id, RewardState::ACTIVE); + + Ok(reward_id) + } + + fn do_claim_reward(claimer: T::AccountId, reward_id: T::Hash, nft_id: u32, collection_id: u32, transferable: bool) -> DispatchResult { + // Create Battlepass NFT + let metadata = reward_id.encode(); + let (_, nft_id) = T::Rmrk::nft_mint( + claimer.clone(), // sender + claimer.clone(), // owner + nft_id, // nft_id + collection_id, // collection_id + None, // royalty_recipient + None, // royalty_amount + BoundedVec::truncate_from(metadata), // metadata TODO: what should be here? + transferable, // transferable + None // resources + )?; + + ClaimedRewards::::insert(&claimer, &reward_id, nft_id); + + Ok(()) + } } \ No newline at end of file diff --git a/battlepass/src/types.rs b/battlepass/src/types.rs index 816cd90f7..4cf98c4e5 100644 --- a/battlepass/src/types.rs +++ b/battlepass/src/types.rs @@ -3,9 +3,9 @@ use codec::MaxEncodedLen; #[derive(Encode, Decode, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, TypeInfo, MaxEncodedLen)] pub enum BattlepassState { - DRAFT = 0, - ACTIVE = 1, - ENDED = 2, + DRAFT, + ACTIVE, + ENDED, } impl Default for BattlepassState { fn default() -> Self { @@ -24,7 +24,6 @@ pub struct Battlepass { pub cid: BoundedString, pub season: u32, pub price: u16, // TODO: introduce currency - /// Collection that will store all claimed Battlepass-NFTs pub collection_id: u32 } @@ -34,4 +33,28 @@ pub struct BattlepassInfo { pub count: u32, /// Curent active battlepass pub active: Option +} + +#[derive(Encode, Decode, Default, PartialEq, Eq, TypeInfo, MaxEncodedLen)] +/// Reward struct +/// +/// `collection_id`: Collection that will store all claimed Reward-NFTs +pub struct Reward { + pub battlepass_id: Hash, + pub name: BoundedString, + pub cid: BoundedString, + pub level: u8, + pub transferable: bool, + pub collection_id: u32 +} + +#[derive(Encode, Decode, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, TypeInfo, MaxEncodedLen)] +pub enum RewardState { + ACTIVE, + INACTIVE, +} +impl Default for RewardState { + fn default() -> Self { + Self::ACTIVE + } } \ No newline at end of file From a91178e5829eab76c5504f33c3ba58cf341f26d5 Mon Sep 17 00:00:00 2001 From: Yura Date: Wed, 18 Jan 2023 14:14:05 +0100 Subject: [PATCH 13/49] Unit tests for Battlepass (#125) --- battlepass/Cargo.toml | 14 + battlepass/src/lib.rs | 87 ++-- battlepass/src/mock.rs | 254 +++++++++++ battlepass/src/tests.rs | 978 ++++++++++++++++++++++++++++++++++++++++ battlepass/src/types.rs | 2 +- 5 files changed, 1300 insertions(+), 35 deletions(-) create mode 100644 battlepass/src/mock.rs create mode 100644 battlepass/src/tests.rs diff --git a/battlepass/Cargo.toml b/battlepass/Cargo.toml index f3d4a97a1..f595ceabc 100644 --- a/battlepass/Cargo.toml +++ b/battlepass/Cargo.toml @@ -25,6 +25,7 @@ frame-support = { git = "https://github.com/paritytech/substrate", branch = "pol frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.28", default-features = false } frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.28", default-features = false, optional = true } +pallet-uniques = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.28" } pallet-rmrk-core = { git = "https://github.com/rmrk-team/rmrk-substrate", default-features = false, branch = "polkadot-v0.9.28" } rmrk-traits = { git = "https://github.com/rmrk-team/rmrk-substrate", default-features = false, branch = "polkadot-v0.9.28" } @@ -33,6 +34,15 @@ gamedao-traits = { package = "gamedao-traits", path = "../traits", default-featu [dev-dependencies] frame-support-test = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.28" } +sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.28" } +codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] } +rand = "0.8.5" + +pallet-balances = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.28" } +pallet-uniques = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.28" } +orml-currencies = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.28", default-features = false } +orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.28", default-features = false } +orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.28", default-features = false } [features] default = ['std'] @@ -50,6 +60,10 @@ std = [ "sp-std/std", "sp-runtime/std", + "orml-traits/std", + "orml-tokens/std", + "orml-currencies/std", + "pallet-rmrk-core/std", "rmrk-traits/std", diff --git a/battlepass/src/lib.rs b/battlepass/src/lib.rs index 8fc12b753..2c94ee3ec 100644 --- a/battlepass/src/lib.rs +++ b/battlepass/src/lib.rs @@ -13,16 +13,19 @@ #![cfg_attr(not(feature = "std"), no_std)] pub use pallet::*; -use frame_support::pallet_prelude::*; +use frame_support::{pallet_prelude::*, transactional}; use frame_system::pallet_prelude::*; use sp_std::convert::TryInto; use sp_runtime::traits::Hash; use gamedao_traits::ControlTrait; -use rmrk_traits::{primitives::{PartId, NftId}, Collection, Nft, ResourceInfoMin}; +use rmrk_traits::{primitives::{PartId, NftId, CollectionId}, Collection, Nft, ResourceInfoMin}; pub mod types; pub use types::*; +mod mock; +mod tests; + pub type String = BoundedVec::StringLimit>; pub type Symbol = BoundedVec::SymbolLimit>; pub type Resource = BoundedVec< @@ -42,7 +45,7 @@ pub mod pallet { pub struct Pallet(_); #[pallet::config] - pub trait Config: frame_system::Config + pallet_rmrk_core::Config { + pub trait Config: frame_system::Config + pallet_rmrk_core::Config + pallet_uniques::Config { type Event: From> + IsType<::Event> + Into<::Event>; @@ -82,8 +85,7 @@ pub mod pallet { by_who: T::AccountId, for_who: T::AccountId, org_id: T::Hash, - battlepass_id: T::Hash, - nft_id: NftId + battlepass_id: T::Hash }, /// BattlePass activated @@ -149,18 +151,20 @@ pub mod pallet { CollectionUnknown, BattlepassExists, BattlepassClaimed, - BattlepassInactive, BattlepassNotClaimed, BattlepassUnknown, BattlepassStateUnknown, BattlepassStateWrong, BattlepassInfoUnknown, - NftUnknown, - NftInvalid, + BattlepassNftUnknown, + BattlepassNftInvalid, + LevelNotReached, + LevelUnknown, NotMember, - NotEnoughPoints, + NotOwnNft, OrgPrimeUnknown, OrgUnknownOrInactive, + RewardClaimed, RewardInactive, RewardUnknown, RewardStateUnknown, @@ -231,8 +235,8 @@ pub mod pallet { #[pallet::storage] #[pallet::getter(fn get_claimed_rewards)] pub(super) type ClaimedRewards = StorageDoubleMap<_, - Blake2_128Concat, T::AccountId, Blake2_128Concat, T::Hash, + Blake2_128Concat, T::AccountId, NftId, OptionQuery >; @@ -241,7 +245,7 @@ pub mod pallet { /// /// Levels: map (Hash, u8) => u32 #[pallet::storage] - #[pallet::getter(fn get_levels)] + #[pallet::getter(fn get_level)] pub(super) type Levels = StorageDoubleMap<_, Blake2_128Concat, T::Hash, Blake2_128Concat, u8, @@ -250,8 +254,11 @@ pub mod pallet { >; #[pallet::call] - impl Pallet { + impl Pallet + where T: pallet_uniques::Config, + { #[pallet::weight(0)] + #[transactional] pub fn create_battlepass( origin: OriginFor, org_id: T::Hash, @@ -279,6 +286,7 @@ pub mod pallet { } #[pallet::weight(0)] + #[transactional] pub fn claim_battlepass( origin: OriginFor, battlepass_id: T::Hash, @@ -288,7 +296,7 @@ pub mod pallet { // check if Battlepass exists let battlepass = Self::get_battlepass(battlepass_id).ok_or(Error::::BattlepassUnknown)?; // check if Battlepass in ACTIVE state - ensure!(Self::check_battlepass_state(battlepass_id, BattlepassState::ACTIVE)?, Error::::BattlepassInactive); + ensure!(Self::check_battlepass_state(battlepass_id, BattlepassState::ACTIVE)?, Error::::BattlepassStateWrong); // check if Org is active ensure!(T::Control::is_org_active(&battlepass.org_id), Error::::OrgUnknownOrInactive); // check permissions (prime, bot, self - temp) @@ -299,17 +307,15 @@ pub mod pallet { // check if Battlepass already claimed ensure!(!ClaimedBattlepasses::::contains_key(battlepass_id, for_who.clone()), Error::::BattlepassClaimed); - let collection = >::collections(battlepass.collection_id).ok_or(Error::::CollectionUnknown)?; - let new_nft_id = collection.nfts_count; + Pallet::::do_claim_battlepass(by_who.clone(), for_who.clone(), battlepass_id, battlepass.collection_id)?; - Self::do_claim_battlepass(by_who.clone(), for_who.clone(), battlepass_id, new_nft_id, battlepass.collection_id)?; - - Self::deposit_event(Event::BattlepassClaimed { by_who, for_who, org_id: battlepass.org_id, battlepass_id, nft_id: new_nft_id }); + Self::deposit_event(Event::BattlepassClaimed { by_who, for_who, org_id: battlepass.org_id, battlepass_id }); Ok(()) } #[pallet::weight(0)] + #[transactional] pub fn activate_battlepass( origin: OriginFor, battlepass_id: T::Hash, @@ -332,6 +338,7 @@ pub mod pallet { } #[pallet::weight(0)] + #[transactional] pub fn conclude_battlepass( origin: OriginFor, battlepass_id: T::Hash, @@ -378,6 +385,7 @@ pub mod pallet { } #[pallet::weight(0)] + #[transactional] pub fn create_reward( origin: OriginFor, battlepass_id: T::Hash, @@ -390,8 +398,8 @@ pub mod pallet { let creator = ensure_signed(origin)?; // check if Battlepass exists let battlepass = Self::get_battlepass(battlepass_id).ok_or(Error::::BattlepassUnknown)?; - // check if Battlepass in ACTIVE state - ensure!(Self::check_battlepass_state(battlepass_id, BattlepassState::ACTIVE)?, Error::::BattlepassStateWrong); + // check if Battlepass is not ended + ensure!(!Self::check_battlepass_state(battlepass_id, BattlepassState::ENDED)?, Error::::BattlepassStateWrong); // check if Org is active ensure!(T::Control::is_org_active(&battlepass.org_id), Error::::OrgUnknownOrInactive); // check permissions (prime) @@ -430,6 +438,7 @@ pub mod pallet { } #[pallet::weight(0)] + #[transactional] pub fn claim_reward( origin: OriginFor, reward_id: T::Hash, @@ -439,6 +448,8 @@ pub mod pallet { let reward = Self::get_reward(reward_id).ok_or(Error::::RewardUnknown)?; // check if Reward is active ensure!(Self::check_reward_state(reward_id, RewardState::ACTIVE)?, Error::::RewardInactive); + // check if Reward has not been claimed yet + ensure!(!ClaimedRewards::::contains_key(&reward_id, &claimer), Error::::RewardClaimed); // check if Battlepass exists let battlepass = Self::get_battlepass(&reward.battlepass_id).ok_or(Error::::BattlepassUnknown)?; // check if Battlepass in ACTIVE state @@ -447,17 +458,20 @@ pub mod pallet { ensure!(T::Control::is_org_active(&battlepass.org_id), Error::::OrgUnknownOrInactive); // check if user is a member of organization ensure!(T::Control::is_org_member_active(&battlepass.org_id, &claimer), Error::::NotMember); - // check if user owns Battlepass NFT + // check if user claimed Battlepass NFT let nft_id = Self::get_claimed_battlepass(reward.battlepass_id, &claimer).ok_or(Error::::BattlepassNotClaimed)?; - // check if NFT exists - let bp_nft = >::nfts(&reward.collection_id, nft_id).ok_or(Error::::NftUnknown)?; - // validate NFT + // check if Battlepass NFT exists + let bp_nft = pallet_rmrk_core::Pallet::::nfts(&battlepass.collection_id, nft_id).ok_or(Error::::BattlepassNftUnknown)?; + // validate Battlepass NFT ownership + let (root_owner, _) = pallet_rmrk_core::Pallet::::lookup_root_owner(battlepass.collection_id, nft_id)?; + ensure!(root_owner == claimer, Error::::NotOwnNft); + // validate Battlepass NFT metadata let metadata: String = BoundedVec::truncate_from(reward.battlepass_id.encode()); - ensure!(metadata == bp_nft.metadata, Error::::NftInvalid); + ensure!(metadata == bp_nft.metadata, Error::::BattlepassNftInvalid); // check if user has enough Points - ensure!(Self::is_enough_points(&reward.battlepass_id, &claimer, reward.level), Error::::NotEnoughPoints); + ensure!(Self::is_level_reached(&reward.battlepass_id, &claimer, reward.level), Error::::LevelNotReached); - Self::do_claim_reward(claimer.clone(), reward_id, nft_id, reward.collection_id, reward.transferable)?; + Self::do_claim_reward(claimer.clone(), reward_id, reward.collection_id, reward.transferable)?; Self::deposit_event(Event::RewardClaimed {reward_id, claimer, collection_id: reward.collection_id, nft_id} ); @@ -503,6 +517,8 @@ pub mod pallet { ensure!(T::Control::is_org_active(&battlepass.org_id), Error::::OrgUnknownOrInactive); // check permissions (prime) ensure!(Self::is_prime(&battlepass.org_id, sender.clone())?, Error::::AuthorizationError); + // check if Level exists + ensure!(Levels::::contains_key(battlepass_id, level), Error::::LevelUnknown); Levels::::remove(battlepass_id, level); @@ -526,7 +542,7 @@ impl Pallet { Ok(Self::is_prime(org_id, who)? || is_bot) } - fn is_enough_points(battlepass_id: &T::Hash, account: &T::AccountId, level: u8) -> bool { + fn is_level_reached(battlepass_id: &T::Hash, account: &T::AccountId, level: u8) -> bool { let user_points = Self::get_points(battlepass_id, account); let levels = Levels::::iter_prefix(battlepass_id) .filter( @@ -566,7 +582,7 @@ impl Pallet { fn do_create_battlepass(creator: T::AccountId, org_id: T::Hash, name: String, cid: String, collection_id: u32, price: u16, new_season:u32) -> Result { let battlepass: Battlepass> = Battlepass { - creator, + creator, org_id, name, cid, @@ -578,12 +594,13 @@ impl Pallet { Battlepasses::::insert(&battlepass_id, battlepass); BattlepassStates::::insert(&battlepass_id, BattlepassState::DRAFT); - BattlepassInfoByOrg::::insert(org_id, BattlepassInfo{count: new_season, active: Some(battlepass_id)}); + BattlepassInfoByOrg::::insert(org_id, BattlepassInfo{count: new_season, active: None}); Ok(battlepass_id) } - fn do_claim_battlepass(by_who: T::AccountId, for_who: T::AccountId, battlepass_id: T::Hash, nft_id: u32, collection_id: u32) -> DispatchResult { + fn do_claim_battlepass(by_who: T::AccountId, for_who: T::AccountId, battlepass_id: T::Hash, collection_id: u32) -> DispatchResult { + let nft_id = ClaimedBattlepasses::::iter_key_prefix(battlepass_id).count() as u32; // Create Battlepass NFT let metadata = battlepass_id.encode(); @@ -595,7 +612,7 @@ impl Pallet { None, // royalty_recipient None, // royalty_amount BoundedVec::truncate_from(metadata), // metadata TODO: what should be here? - false, // transferable + true, // transferable None // resources )?; @@ -637,7 +654,9 @@ impl Pallet { Ok(reward_id) } - fn do_claim_reward(claimer: T::AccountId, reward_id: T::Hash, nft_id: u32, collection_id: u32, transferable: bool) -> DispatchResult { + fn do_claim_reward(claimer: T::AccountId, reward_id: T::Hash, collection_id: u32, transferable: bool) -> DispatchResult { + let nft_id = ClaimedRewards::::iter_key_prefix(reward_id).count() as u32; + // Create Battlepass NFT let metadata = reward_id.encode(); let (_, nft_id) = T::Rmrk::nft_mint( @@ -652,7 +671,7 @@ impl Pallet { None // resources )?; - ClaimedRewards::::insert(&claimer, &reward_id, nft_id); + ClaimedRewards::::insert(&reward_id, &claimer, nft_id); Ok(()) } diff --git a/battlepass/src/mock.rs b/battlepass/src/mock.rs new file mode 100644 index 000000000..c09c3e787 --- /dev/null +++ b/battlepass/src/mock.rs @@ -0,0 +1,254 @@ +#![cfg(test)] + +use crate as gamedao_battlepass; +// use frame_support::traits::{ConstU16, ConstU64}; +use frame_support::{construct_runtime, parameter_types, PalletId, + traits::{AsEnsureOriginWithArg, Nothing, GenesisBuild}, + pallet_prelude::*, +}; +use frame_system; +use frame_system::{EnsureRoot, EnsureSigned}; +use sp_std::convert::{TryFrom, TryInto}; +use sp_core::H256; +use sp_runtime::{ + testing::Header, + traits::{BlakeTwo256, IdentityLookup}, +}; +use orml_traits::parameter_type_with_key; + +type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; +type Block = frame_system::mocking::MockBlock; + +// types +pub type Hash = H256; +pub type Balance = u128; +pub type BlockNumber = u64; +pub type AccountId = u32; +pub type CurrencyId = u32; +pub type Amount = i128; + +/// Constants: +pub const MILLICENTS: Balance = 1_000_000_000; +pub const CENTS: Balance = 1_000 * MILLICENTS; +pub const DOLLARS: Balance = 100 * CENTS; +pub const PROTOCOL_TOKEN_ID: CurrencyId = 1; +pub const PAYMENT_TOKEN_ID: CurrencyId = 2; +// Org creator: +pub const ALICE: AccountId = 11; +// Contributors: +pub const BOB: AccountId = 12; +pub const EVA: AccountId = 13; +pub const TOM: AccountId = 14; + +pub const INIT_BALANCE: Balance = 100 * DOLLARS; + +#[derive(Encode, Decode, Eq, PartialEq, Copy, Clone, RuntimeDebug, PartialOrd, Ord, MaxEncodedLen, TypeInfo)] +#[repr(u8)] +pub enum ReserveIdentifier { + CollatorSelection, + Nft, + TransactionPayment, + TransactionPaymentDeposit, + + // always the last, indicate number of variants + Count, +} + +// Configure a mock runtime to test the pallet. +construct_runtime!( + pub enum Test where + Block = Block, + NodeBlock = Block, + UncheckedExtrinsic = UncheckedExtrinsic, + { + System: frame_system::{Pallet, Call, Config, Storage, Event}, + PalletBalances: pallet_balances::{Pallet, Call, Storage, Event}, + Tokens: orml_tokens::{Pallet, Storage, Event, Config}, + Currencies: orml_currencies::{Pallet, Call}, + Uniques: pallet_uniques::{Pallet, Call, Storage, Event}, + RmrkCore: pallet_rmrk_core::{Pallet, Call, Event, Storage}, + Control: gamedao_control, + Battlepass: gamedao_battlepass::{Pallet, Call, Event, Storage}, + } +); + +parameter_types! { + pub const BlockHashCount: u32 = 250; +} + +impl frame_system::Config for Test { + type BaseCallFilter = frame_support::traits::Everything; + type BlockWeights = (); + type BlockLength = (); + type DbWeight = (); + type Origin = Origin; + type Call = Call; + type Index = u64; + type BlockNumber = u64; + type Hash = Hash; + type Hashing = BlakeTwo256; + type AccountId = AccountId; + type Lookup = IdentityLookup; + type Header = Header; + type Event = Event; + type BlockHashCount = BlockHashCount; + type Version = (); + type PalletInfo = PalletInfo; + type AccountData = pallet_balances::AccountData; + type OnNewAccount = (); + type OnKilledAccount = (); + type SystemWeightInfo = (); + type SS58Prefix = (); //SS58Prefix; + type OnSetCode = (); + type MaxConsumers = ConstU32<128>; +} + +parameter_type_with_key! { + pub ExistentialDeposits: |_currency_id: CurrencyId| -> Balance { + Default::default() + }; +} + +parameter_types! { + pub const MaxReserves: u32 = ReserveIdentifier::Count as u32; +} + +impl orml_tokens::Config for Test { + type Event = Event; + type Balance = Balance; + type Amount = Amount; + type CurrencyId = CurrencyId; + type WeightInfo = (); + type ExistentialDeposits = ExistentialDeposits; + type OnDust = (); + type MaxLocks = (); + type MaxReserves = MaxReserves; + type OnNewTokenAccount = (); + type OnKilledTokenAccount = (); + type DustRemovalWhitelist = Nothing; + type ReserveIdentifier = ReserveIdentifier; +} + +parameter_types! { + pub const ExistentialDeposit: Balance = 1; +} + +impl pallet_balances::Config for Test { + type Balance = Balance; + type DustRemoval = (); + type Event = Event; + type ExistentialDeposit = ExistentialDeposit; + type AccountStore = frame_system::Pallet; + type MaxLocks = (); + type MaxReserves = (); + type ReserveIdentifier = ReserveIdentifier; + type WeightInfo = (); +} + +pub type AdaptedBasicCurrency = orml_currencies::BasicCurrencyAdapter; + +impl orml_currencies::Config for Test { + type MultiCurrency = Tokens; + type NativeCurrency = AdaptedBasicCurrency; + type GetNativeCurrencyId = (); + type WeightInfo = (); +} + +// parameter_types! { +// pub CollectionDeposit: Balance = cent(ZERO) * 10; +// pub ItemDeposit: Balance = dollar(ZERO); +// } + +impl pallet_uniques::Config for Test { + type Event = Event; + type CollectionId = u32; + type ItemId = u32; + type Currency = (); //Balances; + type ForceOrigin = frame_system::EnsureRoot; + type CollectionDeposit = (); //CollectionDeposit; + type ItemDeposit = (); //ItemDeposit; + type MetadataDepositBase = (); //MetadataDepositBase; + type AttributeDepositBase = (); //MetadataDepositBase; + type DepositPerByte = (); //MetadataDepositPerByte; + type StringLimit = StringLimit; + type KeyLimit = ConstU32<32>; + type ValueLimit = ConstU32<256>; + type WeightInfo = (); //pallet_uniques::weights::SubstrateWeight; + #[cfg(feature = "runtime-benchmarks")] + type Helper = (); + type CreateOrigin = AsEnsureOriginWithArg>; + type Locker = pallet_rmrk_core::Pallet; +} + +parameter_types! { + pub const PartsLimit: u32 = 25; + pub const CollectionSymbolLimit: u32 = 100; + pub const MaxResourcesOnMint: u32 = 100; + pub const StringLimit: u32 = 64; +} + +impl pallet_rmrk_core::Config for Test { + type Event = Event; + type ProtocolOrigin = EnsureRoot; + type MaxRecursions = ConstU32<10>; + type ResourceSymbolLimit = ConstU32<10>; + type PartsLimit = PartsLimit; + type MaxPriorities = ConstU32<25>; + type CollectionSymbolLimit = CollectionSymbolLimit; + type MaxResourcesOnMint = MaxResourcesOnMint; +} + +parameter_types! { + pub const ProtocolTokenId: u32 = PROTOCOL_TOKEN_ID; + pub const PaymentTokenId: CurrencyId = PAYMENT_TOKEN_ID; + pub const MinimumDeposit: Balance = 5 * DOLLARS; + pub const ControlPalletId: PalletId = PalletId(*b"gd/cntrl"); + pub const MaxMembers: u32 = 1000; +} +impl gamedao_control::Config for Test { + type Balance = Balance; + type CurrencyId = CurrencyId; + type WeightInfo = (); + type Event = Event; + type Currency = Currencies; + type MaxMembers = MaxMembers;//ConstU32<10000>; + type ProtocolTokenId = ProtocolTokenId; + type PaymentTokenId = PaymentTokenId; + type MinimumDeposit = MinimumDeposit; + type PalletId = ControlPalletId; + type StringLimit = ConstU32<256>; +} + +impl gamedao_battlepass::Config for Test { + type Event = Event; + type Control = Control; + type Rmrk = RmrkCore; + type StringLimit = StringLimit; + type SymbolLimit = CollectionSymbolLimit; + type PartsLimit = PartsLimit; + type MaxResourcesOnMint = MaxResourcesOnMint; +} + +// Build genesis storage according to the mock runtime. +pub fn new_test_ext() -> sp_io::TestExternalities { + let mut t = frame_system::GenesisConfig::default().build_storage::().unwrap(); + orml_tokens::GenesisConfig:: { + balances: vec![ + // ALICE org creator + (ALICE, PROTOCOL_TOKEN_ID, INIT_BALANCE), + (ALICE, PAYMENT_TOKEN_ID, INIT_BALANCE), + + // Contributors + (BOB, PAYMENT_TOKEN_ID, INIT_BALANCE), + (EVA, PAYMENT_TOKEN_ID, INIT_BALANCE), + (1, PAYMENT_TOKEN_ID, INIT_BALANCE), + (2, PAYMENT_TOKEN_ID, INIT_BALANCE), + (3, PAYMENT_TOKEN_ID, INIT_BALANCE), + (4, PAYMENT_TOKEN_ID, INIT_BALANCE), + (5, PAYMENT_TOKEN_ID, INIT_BALANCE), + ], + } + .assimilate_storage(&mut t) + .unwrap(); + t.into() +} \ No newline at end of file diff --git a/battlepass/src/tests.rs b/battlepass/src/tests.rs new file mode 100644 index 000000000..37c32f736 --- /dev/null +++ b/battlepass/src/tests.rs @@ -0,0 +1,978 @@ +#![cfg(test)] + +use frame_support::{assert_noop, assert_ok}; +use pallet_rmrk_core::Nfts; +use rmrk_traits::AccountIdOrCollectionNftTuple; +use sp_core::H256; + +use crate::mock::{ + new_test_ext, Origin, Test, + //System, + Battlepass, Control, RmrkCore, + ALICE, BOB, EVA, TOM, PROTOCOL_TOKEN_ID, PAYMENT_TOKEN_ID, DOLLARS, + AccountId, StringLimit, //Event +}; +use gamedao_control::types::{AccessModel, FeeModel, OrgType, Org}; + +use super::*; + +fn create_org() -> H256 { + let bounded_str = BoundedVec::truncate_from(vec![1,2]); + let index = Control::org_count(); + let now = frame_system::Pallet::::block_number(); + let org = Org { + index, creator: ALICE, prime: ALICE, name: bounded_str.clone(), cid: bounded_str.clone(), + org_type: OrgType::Individual, fee_model: FeeModel::NoFees, membership_fee: Some(1 * DOLLARS), + gov_currency: PROTOCOL_TOKEN_ID, pay_currency: PAYMENT_TOKEN_ID, access_model: AccessModel::Open, + member_limit: ::MaxMembers::get(), created: now.clone(), mutated: now + }; + let org_id = ::Hashing::hash_of(&org); + + assert_ok!( + Control::create_org( + Origin::signed(ALICE), org.name, org.cid, org.org_type, org.access_model, + org.fee_model, None, org.membership_fee, None, None, None + )); + + org_id +} + +fn get_battlepass_hash(creator: AccountId, org_id: H256, season: u32, price: u16, collection_id: u32) -> H256 { + let battlepass = types::Battlepass { + creator, + org_id, + name: string(), + cid: string(), + season, + price, + collection_id + }; + + ::Hashing::hash_of(&battlepass) +} + +fn create_battlepass(org_id: H256) -> H256 { + let creator = ALICE; + let season = Battlepass::get_battlepass_info(org_id).0 + 1; + let price = 10; + let collection_id = pallet_rmrk_core::CollectionIndex::::get(); + + assert_ok!( + Battlepass::create_battlepass(Origin::signed(creator), org_id, string(), string(), price) + ); + + get_battlepass_hash(creator, org_id, season, price, collection_id) +} + +fn get_reward_hash(battlepass_id: H256, level: u8, transferable: bool, collection_id: u32) -> H256 { + let reward = Reward{ + battlepass_id, + name: string(), + cid: string(), + level, + transferable, + collection_id + }; + + ::Hashing::hash_of(&reward) +} + +fn create_reward(battlepass_id: H256) -> H256 { + let creator = ALICE; + let level = 1; + let max = 1; + let transferable = true; + let collection_id = (Rewards::::iter().count() + 1) as u32; + + assert_ok!( + Battlepass::create_reward(Origin::signed(creator), battlepass_id, string(), string(), Some(max), level, transferable) + ); + + get_reward_hash(battlepass_id, level, transferable, collection_id) +} + +fn add_member(org_id: H256, account: AccountId) { + assert_ok!( + Control::add_member(Origin::signed(account), org_id, account) + ); +} + +fn string() -> BoundedVec{ + BoundedVec::truncate_from(vec![1,2]) +} + +#[test] +fn should_be_prime() { + new_test_ext().execute_with(|| { + let org_id = create_org(); + let prime = Battlepass::is_prime(&org_id, ALICE); + assert_eq!(prime.is_ok(), true); + assert_eq!(prime.unwrap(), true); + }) +} + +#[test] +fn create_battlepass_test(){ + new_test_ext().execute_with(|| { + let org_id = create_org(); + let wrong_org_id = ::Hashing::hash_of(&"123"); + let bounded_str = BoundedVec::truncate_from(vec![1,2]); + let creator = ALICE; + let not_creator = BOB; + let not_member = EVA; + let battlepass_id_1 = get_battlepass_hash(creator, org_id, 1, 10, 0); + let battlepass_id_2 = get_battlepass_hash(creator, org_id, 2, 10, 1); + + // Should not create for non existing Org + assert_noop!( + Battlepass::create_battlepass(Origin::signed(creator), wrong_org_id, bounded_str.clone(), bounded_str.clone(), 10), + Error::::OrgUnknownOrInactive + ); + + // Should not create for inactive Org + assert_ok!( + Control::disable_org(Origin::signed(creator), org_id) + ); + assert_noop!( + Battlepass::create_battlepass(Origin::signed(creator), org_id, bounded_str.clone(), bounded_str.clone(), 10), + Error::::OrgUnknownOrInactive + ); + assert_ok!( + Control::enable_org(Origin::signed(creator), org_id) + ); + + // Should not create if origin is not a Prime + assert_ok!( + Control::add_member(Origin::signed(not_creator), org_id, not_creator) + ); + assert_noop!( + Battlepass::create_battlepass(Origin::signed(not_creator), org_id, bounded_str.clone(), bounded_str.clone(), 10), + Error::::AuthorizationError + ); + assert_noop!( + Battlepass::create_battlepass(Origin::signed(not_member), org_id, bounded_str.clone(), bounded_str.clone(), 10), + Error::::AuthorizationError + ); + + // Should create new Battlepass + assert_ok!( + Battlepass::create_battlepass(Origin::signed(creator), org_id, bounded_str.clone(), bounded_str.clone(), 10) + ); + // Check if NFT collection created + assert_eq!(pallet_rmrk_core::Collections::::contains_key(0), true); + // Check if Battlepass created + let battlepass = Battlepasses::::get(battlepass_id_1); + assert_eq!(battlepass.is_some(), true); + assert_eq!(battlepass.unwrap().season, 1); + assert_eq!(Battlepasses::::contains_key(battlepass_id_1), true); + // Check if BattlepassState is DRAFT + assert_eq!(Battlepass::get_battlepass_state(battlepass_id_1), Some(types::BattlepassState::DRAFT)); + // Check if BattlepassInfo created (count = 1, active = None) + let bp_info = BattlepassInfoByOrg::::get(org_id); + assert_eq!(bp_info.is_some(), true); + assert_eq!(bp_info.clone().unwrap().count, 1); + assert_eq!(bp_info.clone().unwrap().active, None); + + + // Should create another Battlepass (may be multiple in DRAFT state) + assert_ok!( + Battlepass::create_battlepass(Origin::signed(creator), org_id, bounded_str.clone(), bounded_str.clone(), 10) + ); + // Check if NFT collection created + assert_eq!(pallet_rmrk_core::Collections::::contains_key(1), true); + // Check if Battlepass created + let battlepass = Battlepasses::::get(battlepass_id_2); + assert_eq!(battlepass.is_some(), true); + assert_eq!(battlepass.unwrap().season, 2); + assert_eq!(Battlepasses::::contains_key(battlepass_id_2), true); + // Check if BattlepassState is DRAFT + assert_eq!(Battlepass::get_battlepass_state(battlepass_id_2), Some(types::BattlepassState::DRAFT)); + // Check if BattlepassInfo created (count = 2, active = None) + let bp_info = BattlepassInfoByOrg::::get(org_id); + assert_eq!(bp_info.is_some(), true); + assert_eq!(bp_info.clone().unwrap().count, 2); + assert_eq!(bp_info.clone().unwrap().active, None); + + // Check events (collection created, battlepass created) + // println!("Events: {}", System::events().len()); + // System::assert_has_event(Event::Battlepass(crate::Event::BattlepassCreated { org_id, battlepass_id, season: 1 })); + // System::assert_has_event(mock::Event::RmrkCore(pallet_rmrk_core::Event::CollectionCreated { issuer: creator, collection_id: 0 })); + }) +} + +#[test] +fn activate_battlepass_test() { + new_test_ext().execute_with(|| { + let org_id = create_org(); + let battlepass_id = create_battlepass(org_id); + let wrong_battlepass_id = ::Hashing::hash_of(&"123"); + let creator = ALICE; + let not_creator = BOB; + let not_member = EVA; + let bounded_str = BoundedVec::truncate_from(vec![1,2]); + + // Should not activate unknown Battlepass + assert_noop!( + Battlepass::activate_battlepass(Origin::signed(creator), wrong_battlepass_id), + Error::::BattlepassUnknown + ); + + // Should not activate if Org is inactive + assert_ok!( + Control::disable_org(Origin::signed(creator), org_id) + ); + assert_noop!( + Battlepass::activate_battlepass(Origin::signed(creator), battlepass_id), + Error::::OrgUnknownOrInactive + ); + assert_ok!( + Control::enable_org(Origin::signed(creator), org_id) + ); + + // Should not activate if origin is not a Prime + assert_ok!( + Control::add_member(Origin::signed(not_creator), org_id, not_creator) + ); + assert_noop!( + Battlepass::activate_battlepass(Origin::signed(not_creator), battlepass_id), + Error::::AuthorizationError + ); + assert_noop!( + Battlepass::activate_battlepass(Origin::signed(not_member), battlepass_id), + Error::::AuthorizationError + ); + + // Should activate battlepass + assert_ok!( + Battlepass::activate_battlepass(Origin::signed(creator), battlepass_id) + ); + // Check if BattlepassState is ACTIVE + assert_eq!(Battlepass::get_battlepass_state(battlepass_id), Some(types::BattlepassState::ACTIVE)); + // Check if BattlepassInfo changed (count = 1, active = battlepass_id) + let bp_info = BattlepassInfoByOrg::::get(org_id); + assert_eq!(bp_info.is_some(), true); + assert_eq!(bp_info.clone().unwrap().count, 1); + assert_eq!(bp_info.clone().unwrap().active, Some(battlepass_id)); + + + // Should not activate already active Battlepass + assert_noop!( + Battlepass::activate_battlepass(Origin::signed(creator), battlepass_id), + Error::::BattlepassStateWrong + ); + + // Should not create if Org has an active battlepass + assert_noop!( + Battlepass::create_battlepass(Origin::signed(creator), org_id, bounded_str.clone(), bounded_str.clone(), 10), + Error::::BattlepassExists + ); + + // Check events (battlepass activated) + // println!("Events: {}", System::events().len()); + // System::assert_has_event(Event::Battlepass(crate::Event::BattlepassActivated { by_who: creator, org_id, battlepass_id } )); + + }) +} + +#[test] +fn deactivate_battlepass_test() { + new_test_ext().execute_with(|| { + let org_id = create_org(); + let battlepass_id = create_battlepass(org_id); + let wrong_battlepass_id = ::Hashing::hash_of(&"123"); + let creator = ALICE; + let not_creator = BOB; + let not_member = EVA; + + // Should not deactivate unknown Battlepass + assert_noop!( + Battlepass::conclude_battlepass(Origin::signed(creator), wrong_battlepass_id), + Error::::BattlepassUnknown + ); + + // Should not deactivate Battlepass in DRAFT state + assert_noop!( + Battlepass::conclude_battlepass(Origin::signed(creator), battlepass_id), + Error::::BattlepassStateWrong + ); + + // Should not deactivate if origin is not a Prime + assert_ok!( + Battlepass::activate_battlepass(Origin::signed(creator), battlepass_id) + ); + assert_ok!( + Control::add_member(Origin::signed(not_creator), org_id, not_creator) + ); + assert_noop!( + Battlepass::conclude_battlepass(Origin::signed(not_creator), battlepass_id), + Error::::AuthorizationError + ); + assert_noop!( + Battlepass::conclude_battlepass(Origin::signed(not_member), battlepass_id), + Error::::AuthorizationError + ); + + // Should deactivate battlepass + assert_ok!( + Battlepass::conclude_battlepass(Origin::signed(creator), battlepass_id) + ); + // Check if BattlepassState is ENDED + assert_eq!(Battlepass::get_battlepass_state(battlepass_id), Some(types::BattlepassState::ENDED)); + // Check if BattlepassInfo changed (count = 1, active = None) + let bp_info = BattlepassInfoByOrg::::get(org_id); + assert_eq!(bp_info.is_some(), true); + assert_eq!(bp_info.clone().unwrap().count, 1); + assert_eq!(bp_info.clone().unwrap().active, None); + + // Should not activate already ended Battlepass + assert_noop!( + Battlepass::activate_battlepass(Origin::signed(creator), battlepass_id), + Error::::BattlepassStateWrong + ); + + // Should not deactivate already ended Battlepass + assert_noop!( + Battlepass::conclude_battlepass(Origin::signed(creator), battlepass_id), + Error::::BattlepassStateWrong + ); + + // Check events + + }) +} + +#[test] +fn claim_battlepass_test() { + new_test_ext().execute_with(|| { + let org_id = create_org(); + let battlepass_id = create_battlepass(org_id); + let wrong_battlepass_id = ::Hashing::hash_of(&"123"); + let creator = ALICE; + let not_creator = BOB; + let not_creator_2 = TOM; + let not_member = EVA; + add_member(org_id, not_creator); + add_member(org_id, not_creator_2); + + // Should not claim unknown Battlepass + assert_noop!( + Battlepass::claim_battlepass(Origin::signed(creator), wrong_battlepass_id, creator), + Error::::BattlepassUnknown + ); + + // Should not claim Battlepass in DRAFT state + assert_noop!( + Battlepass::claim_battlepass(Origin::signed(creator), battlepass_id, creator), + Error::::BattlepassStateWrong + ); + + // Should not claim if Org is inactive + assert_ok!( + Battlepass::activate_battlepass(Origin::signed(creator), battlepass_id) + ); + assert_ok!( + Control::disable_org(Origin::signed(creator), org_id) + ); + assert_noop!( + Battlepass::claim_battlepass(Origin::signed(creator), battlepass_id, creator), + Error::::OrgUnknownOrInactive + ); + assert_ok!( + Control::enable_org(Origin::signed(creator), org_id) + ); + + // Should not claim for others if origin is not a Prime + assert_noop!( + Battlepass::claim_battlepass(Origin::signed(not_creator), battlepass_id, creator), + Error::::AuthorizationError + ); + assert_noop!( + Battlepass::claim_battlepass(Origin::signed(not_member), battlepass_id, creator), + Error::::AuthorizationError + ); + + // Should not claim for non members + assert_noop!( + Battlepass::claim_battlepass(Origin::signed(creator), battlepass_id, not_member), + Error::::NotMember + ); + + // Should claim for others if origin is a Prime + assert_ok!( + Battlepass::claim_battlepass(Origin::signed(creator), battlepass_id, not_creator) + ); + // Check if ClaimedBattlepasses record created + let nft_id = ClaimedBattlepasses::::get(battlepass_id, not_creator); + assert_eq!(nft_id.is_some(), true); + assert_eq!(nft_id.unwrap(), 0); + // Check if NFT minted + assert_eq!(pallet_rmrk_core::Nfts::::contains_key(0, 0), true); + + // Should claim for self + assert_ok!( + Battlepass::claim_battlepass(Origin::signed(not_creator_2), battlepass_id, not_creator_2) + ); + // Check if ClaimedBattlepasses record created + let nft_id = ClaimedBattlepasses::::get(battlepass_id, not_creator_2); + assert_eq!(nft_id.is_some(), true); + assert_eq!(nft_id.unwrap(), 1); + // Check if NFT minted + assert_eq!(pallet_rmrk_core::Nfts::::contains_key(0, 1), true); + + // Should not claim if it was already claimed + assert_noop!( + Battlepass::claim_battlepass(Origin::signed(not_creator), battlepass_id, not_creator), + Error::::BattlepassClaimed + ); + + // Should not claim Battlepass in ENDED state + assert_ok!( + Battlepass::conclude_battlepass(Origin::signed(creator), battlepass_id) + ); + assert_noop!( + Battlepass::claim_battlepass(Origin::signed(creator), battlepass_id, creator), + Error::::BattlepassStateWrong + ); + // Check events + + }) +} + +#[test] +fn set_points_test() { + new_test_ext().execute_with(|| { + let org_id = create_org(); + let battlepass_id = create_battlepass(org_id); + let wrong_battlepass_id = ::Hashing::hash_of(&"123"); + let creator = ALICE; + let not_creator = BOB; + let not_member = EVA; + + // Should not set if Battlepass unknown + assert_noop!( + Battlepass::set_points(Origin::signed(creator), wrong_battlepass_id, creator, 10), + Error::::BattlepassUnknown + ); + + // Should not set if Battlepass in DRAFT state + assert_noop!( + Battlepass::set_points(Origin::signed(creator), battlepass_id, creator, 10), + Error::::BattlepassStateWrong + ); + + // Should not set if Org is inactive + assert_ok!( + Battlepass::activate_battlepass(Origin::signed(creator), battlepass_id) + ); + assert_ok!( + Control::disable_org(Origin::signed(creator), org_id) + ); + assert_noop!( + Battlepass::set_points(Origin::signed(creator), battlepass_id, creator, 10), + Error::::OrgUnknownOrInactive + ); + assert_ok!( + Control::enable_org(Origin::signed(creator), org_id) + ); + + // Should not set if origin is not a Prime + assert_ok!( + Control::add_member(Origin::signed(not_creator), org_id, not_creator) + ); + assert_noop!( + Battlepass::set_points(Origin::signed(not_creator), battlepass_id, not_creator, 10), + Error::::AuthorizationError + ); + assert_noop!( + Battlepass::set_points(Origin::signed(not_member), battlepass_id, creator, 10), + Error::::AuthorizationError + ); + + // Should not set for non members + assert_noop!( + Battlepass::set_points(Origin::signed(creator), battlepass_id, not_member, 10), + Error::::NotMember + ); + + // Should set points + assert_ok!( + Battlepass::set_points(Origin::signed(creator), battlepass_id, not_creator, 10) + ); + // Check if Points record created + assert_eq!(Points::::contains_key(battlepass_id, not_creator), true); + + // Should not set if Battlepass in ENDED state + assert_ok!( + Battlepass::conclude_battlepass(Origin::signed(creator), battlepass_id) + ); + assert_noop!( + Battlepass::set_points(Origin::signed(creator), battlepass_id, creator, 10), + Error::::BattlepassStateWrong + ); + + // Check events + + }) +} + +#[test] +fn create_reward_test() { + new_test_ext().execute_with(|| { + let org_id = create_org(); + let battlepass_id = create_battlepass(org_id); + let wrong_battlepass_id = ::Hashing::hash_of(&"123"); + let bounded_str = BoundedVec::truncate_from(vec![1,2]); + let creator = ALICE; + let not_creator = BOB; + let not_member = EVA; + + + // Should not create if Battlepass unknown + assert_noop!( + Battlepass::create_reward(Origin::signed(creator), wrong_battlepass_id, bounded_str.clone(), bounded_str.clone(), Some(1), 1, true), + Error::::BattlepassUnknown + ); + + // Should not create if Org is inactive + assert_ok!( + Control::disable_org(Origin::signed(creator), org_id) + ); + assert_noop!( + Battlepass::create_reward(Origin::signed(creator), battlepass_id, bounded_str.clone(), bounded_str.clone(), Some(1), 1, true), + Error::::OrgUnknownOrInactive + ); + assert_ok!( + Control::enable_org(Origin::signed(creator), org_id) + ); + + // Should not create if origin is not a Prime + assert_ok!( + Control::add_member(Origin::signed(not_creator), org_id, not_creator) + ); + assert_noop!( + Battlepass::create_reward(Origin::signed(not_creator), battlepass_id, bounded_str.clone(), bounded_str.clone(), Some(1), 1, true), + Error::::AuthorizationError + ); + assert_noop!( + Battlepass::create_reward(Origin::signed(not_member), battlepass_id, bounded_str.clone(), bounded_str.clone(), Some(1), 1, true), + Error::::AuthorizationError + ); + + // Should create Reward if Battlepass state is DRAFT + assert_ok!( + Battlepass::create_reward(Origin::signed(creator), battlepass_id, bounded_str.clone(), bounded_str.clone(), Some(1), 1, true) + ); + // Check if NFT collection created + assert_eq!(pallet_rmrk_core::Collections::::contains_key(1), true); + // Check if Reward created + let reward_id = get_reward_hash(battlepass_id, 1, true, 1); + let reward = Rewards::::get(reward_id); + assert_eq!(reward.is_some(), true); + assert_eq!(reward.unwrap().collection_id, 1); + // Check if RewardState is ACTIVE + assert_eq!(RewardStates::::get(reward_id), Some(RewardState::ACTIVE)); + + // Should create Reward if Battlepass state is ACTIVE + assert_ok!( + Battlepass::activate_battlepass(Origin::signed(creator), battlepass_id) + ); + assert_ok!( + Battlepass::create_reward(Origin::signed(creator), battlepass_id, bounded_str.clone(), bounded_str.clone(), Some(1), 1, true) + ); + // Check if NFT collection created + assert_eq!(pallet_rmrk_core::Collections::::contains_key(2), true); + // Check if Reward created + let reward_id = get_reward_hash(battlepass_id, 1, true, 2); + let reward = Rewards::::get(reward_id); + assert_eq!(reward.is_some(), true); + assert_eq!(reward.unwrap().collection_id, 2); + // Check if RewardState is ACTIVE + assert_eq!(RewardStates::::get(reward_id), Some(RewardState::ACTIVE)); + + + // Should not create Reward if Battlepass state is ENDED + assert_ok!( + Battlepass::conclude_battlepass(Origin::signed(creator), battlepass_id) + ); + assert_noop!( + Battlepass::create_reward(Origin::signed(creator), battlepass_id, bounded_str.clone(), bounded_str.clone(), Some(1), 1, true), + Error::::BattlepassStateWrong + ); + + + // Check events + + }) +} + +#[test] +fn disable_reward_test() { + new_test_ext().execute_with(|| { + let org_id = create_org(); + let battlepass_id = create_battlepass(org_id); + let reward_id = create_reward(battlepass_id); + let reward_id_2 = create_reward(battlepass_id); + let wrong_id = ::Hashing::hash_of(&"123"); + let creator = ALICE; + let not_creator = BOB; + let not_member = EVA; + + // Should not disable if Reward unknown + assert_noop!( + Battlepass::disable_reward(Origin::signed(creator), wrong_id), + Error::::RewardUnknown + ); + + // Should not disable if Battlepass unknown + Rewards::::mutate(reward_id_2, |reward| { + if let Some(r) = reward { + r.battlepass_id = wrong_id; + } + } ); + assert_noop!( + Battlepass::disable_reward(Origin::signed(creator), reward_id_2), + Error::::BattlepassUnknown + ); + + // Should not disable if origin is not a Prime + assert_ok!( + Control::add_member(Origin::signed(not_creator), org_id, not_creator) + ); + assert_noop!( + Battlepass::disable_reward(Origin::signed(not_creator), reward_id), + Error::::AuthorizationError + ); + assert_noop!( + Battlepass::disable_reward(Origin::signed(not_member), reward_id), + Error::::AuthorizationError + ); + + // Should disable Reward + assert_ok!( + Battlepass::disable_reward(Origin::signed(creator), reward_id) + ); + // Check if RewardState is INACTIVE + assert_eq!(RewardStates::::get(reward_id), Some(RewardState::INACTIVE)); + + // Should not disable if Reward inactive + assert_noop!( + Battlepass::disable_reward(Origin::signed(creator), reward_id), + Error::::RewardInactive + ); + + + // Check events + + }) +} + +#[test] +fn claim_reward_test() { + new_test_ext().execute_with(|| { + let org_id = create_org(); + let battlepass_id = create_battlepass(org_id); + let wrong_id = ::Hashing::hash_of(&"123"); + let creator = ALICE; + let not_creator = BOB; + let not_creator_2 = TOM; + let not_creator_3 = 30; + let not_creator_4 = 31; + let not_member = EVA; + add_member(org_id, not_creator); + add_member(org_id, not_creator_2); + add_member(org_id, not_creator_3); + add_member(org_id, not_creator_4); + + // Should not claim if Reward unknown + assert_noop!( + Battlepass::claim_reward(Origin::signed(creator), wrong_id), + Error::::RewardUnknown + ); + + // Should not claim if Reward is INACTIVE + let reward_id = create_reward(battlepass_id); + assert_ok!( + Battlepass::disable_reward(Origin::signed(creator), reward_id) + ); + assert_noop!( + Battlepass::claim_reward(Origin::signed(creator), reward_id), + Error::::RewardInactive + ); + + // Should not disable if Battlepass unknown + let reward_id = create_reward(battlepass_id); + Rewards::::mutate(reward_id, |reward| { + if let Some(r) = reward { + r.battlepass_id = wrong_id; + } + } ); + assert_noop!( + Battlepass::claim_reward(Origin::signed(creator), reward_id), + Error::::BattlepassUnknown + ); + + // Should not claim if Battlepass state is DRAFT + let reward_id = create_reward(battlepass_id); + assert_noop!( + Battlepass::claim_reward(Origin::signed(creator), reward_id), + Error::::BattlepassStateWrong + ); + + // Should not claim if Org is inactive + assert_ok!( + Battlepass::activate_battlepass(Origin::signed(creator), battlepass_id) + ); + assert_ok!( + Control::disable_org(Origin::signed(creator), org_id) + ); + assert_noop!( + Battlepass::claim_reward(Origin::signed(creator), reward_id), + Error::::OrgUnknownOrInactive + ); + assert_ok!( + Control::enable_org(Origin::signed(creator), org_id) + ); + + // Should not claim for non members + assert_noop!( + Battlepass::claim_reward(Origin::signed(not_member), reward_id), + Error::::NotMember + ); + + // Should not claim Reward if user didn't claim Battlepass + assert_noop!( + Battlepass::claim_reward(Origin::signed(not_creator), reward_id), + Error::::BattlepassNotClaimed + ); + + // Should not claim Reward if no NFT for claimed Battlepass + assert_ok!( + Battlepass::claim_battlepass(Origin::signed(not_creator), battlepass_id, not_creator) + ); + assert_ok!( + RmrkCore::burn_nft(Origin::signed(not_creator), 0, 0, 5) + ); + assert_noop!( + Battlepass::claim_reward(Origin::signed(not_creator), reward_id), + Error::::BattlepassNftUnknown + ); + + // Should not claim Reward if user lost ownership of Battlepass NFT + assert_ok!( + Battlepass::claim_battlepass(Origin::signed(creator), battlepass_id, creator) + ); + assert_ok!( + RmrkCore::send(Origin::signed(creator), 0, 1, AccountIdOrCollectionNftTuple::AccountId(not_member)) + ); + assert_noop!( + Battlepass::claim_reward(Origin::signed(creator), reward_id), + Error::::NotOwnNft + ); + + // Should not claim Reward if Battlepass NFT is not valid + assert_ok!( + Battlepass::claim_battlepass(Origin::signed(not_creator_2), battlepass_id, not_creator_2) + ); + Nfts::::mutate(0, 2, |nft| { + if let Some(n) = nft { + n.metadata = BoundedVec::truncate_from(b"crap".to_vec()) + } + }); + assert_noop!( + Battlepass::claim_reward(Origin::signed(not_creator_2), reward_id), + Error::::BattlepassNftInvalid + ); + + // Should not claim if user's level is too low + assert_ok!( + Battlepass::claim_battlepass(Origin::signed(not_creator_3), battlepass_id, not_creator_3) + ); + assert_noop!( + Battlepass::claim_reward(Origin::signed(not_creator_3), reward_id), + Error::::LevelNotReached + ); + + // Should claim Reward + assert_ok!( + Battlepass::set_points(Origin::signed(creator), battlepass_id, not_creator_3, 10) + ); + assert_ok!( + Battlepass::add_level(Origin::signed(creator), battlepass_id, 1, 10) + ); + assert_ok!( + Battlepass::claim_reward(Origin::signed(not_creator_3), reward_id) + ); + // Check if Reward claimed + assert_eq!(ClaimedRewards::::contains_key(reward_id, not_creator_3), true); + + // Should not claim if Reward already claimed + assert_noop!( + Battlepass::claim_reward(Origin::signed(not_creator_3), reward_id), + Error::::RewardClaimed + ); + + // Should claim Reward after receiving Battlepass NFT from elsewhere + // TODO: need to 'apply' the received Battlepass NFT so it will appear in ClaimedBattlepasses + + // Should not claim if max limit reached + assert_ok!( + Battlepass::claim_battlepass(Origin::signed(not_creator_4), battlepass_id, not_creator_4) + ); + assert_ok!( + Battlepass::set_points(Origin::signed(creator), battlepass_id, not_creator_4, 10) + ); + assert_noop!( + Battlepass::claim_reward(Origin::signed(not_creator_4), reward_id), + pallet_rmrk_core::Error::::CollectionFullOrLocked + ); + + // Should not claim if Battlepass state is ENDED + assert_ok!( + Battlepass::conclude_battlepass(Origin::signed(creator), battlepass_id) + ); + assert_noop!( + Battlepass::claim_reward(Origin::signed(not_creator_4), reward_id), + Error::::BattlepassStateWrong + ); + + // Check events + + }) +} + +#[test] +fn add_level_test() { + new_test_ext().execute_with(|| { + let org_id = create_org(); + let battlepass_id = create_battlepass(org_id); + let wrong_battlepass_id = ::Hashing::hash_of(&"123"); + let creator = ALICE; + let not_creator = BOB; + let not_member = EVA; + add_member(org_id, not_creator); + + // Should not add if Battlepass unknown + assert_noop!( + Battlepass::add_level(Origin::signed(creator), wrong_battlepass_id, 1, 10), + Error::::BattlepassUnknown + ); + + // Should not add if Org is inactive + assert_ok!( + Control::disable_org(Origin::signed(creator), org_id) + ); + assert_noop!( + Battlepass::add_level(Origin::signed(creator), battlepass_id, 1, 10), + Error::::OrgUnknownOrInactive + ); + assert_ok!( + Control::enable_org(Origin::signed(creator), org_id) + ); + + // Should not add if origin is not a Prime + assert_noop!( + Battlepass::add_level(Origin::signed(not_creator), battlepass_id, 1, 10), + Error::::AuthorizationError + ); + assert_noop!( + Battlepass::add_level(Origin::signed(not_member), battlepass_id, 1, 10), + Error::::AuthorizationError + ); + + // Should add Level + assert_ok!( + Battlepass::activate_battlepass(Origin::signed(creator), battlepass_id) + ); + assert_ok!( + Battlepass::add_level(Origin::signed(creator), battlepass_id, 1, 10) + ); + // Check if Level added + assert_eq!(Levels::::contains_key(battlepass_id, 1), true); + + // Should not add if Battlepass in ENDED state + assert_ok!( + Battlepass::conclude_battlepass(Origin::signed(creator), battlepass_id) + ); + assert_noop!( + Battlepass::add_level(Origin::signed(creator), battlepass_id, 1, 10), + Error::::BattlepassStateWrong + ); + + // Check events + + }) +} + +#[test] +fn remove_level_test() { + new_test_ext().execute_with(|| { + let org_id = create_org(); + let battlepass_id = create_battlepass(org_id); + let wrong_battlepass_id = ::Hashing::hash_of(&"123"); + let creator = ALICE; + let not_creator = BOB; + let not_member = EVA; + add_member(org_id, not_creator); + + // Should not remove if Battlepass unknown + assert_noop!( + Battlepass::remove_level(Origin::signed(creator), wrong_battlepass_id, 1), + Error::::BattlepassUnknown + ); + + // Should not remove if Org is inactive + assert_ok!( + Control::disable_org(Origin::signed(creator), org_id) + ); + assert_noop!( + Battlepass::remove_level(Origin::signed(creator), battlepass_id, 1), + Error::::OrgUnknownOrInactive + ); + assert_ok!( + Control::enable_org(Origin::signed(creator), org_id) + ); + + // Should not remove if origin is not a Prime + assert_noop!( + Battlepass::remove_level(Origin::signed(not_creator), battlepass_id, 1), + Error::::AuthorizationError + ); + assert_noop!( + Battlepass::remove_level(Origin::signed(not_member), battlepass_id, 1), + Error::::AuthorizationError + ); + + // Should not remove if no such Level + assert_noop!( + Battlepass::remove_level(Origin::signed(creator), battlepass_id, 1), + Error::::LevelUnknown + ); + + // Should remove Level + assert_ok!( + Battlepass::activate_battlepass(Origin::signed(creator), battlepass_id) + ); + assert_ok!( + Battlepass::add_level(Origin::signed(creator), battlepass_id, 1, 10) + ); + assert_eq!(Levels::::contains_key(battlepass_id, 1), true); + assert_ok!( + Battlepass::remove_level(Origin::signed(creator), battlepass_id, 1) + ); + // Check if Level removed + assert_eq!(Levels::::contains_key(battlepass_id, 1), false); + + // Should not remove if Battlepass in ENDED state + assert_ok!( + Battlepass::conclude_battlepass(Origin::signed(creator), battlepass_id) + ); + assert_noop!( + Battlepass::remove_level(Origin::signed(creator), battlepass_id, 1), + Error::::BattlepassStateWrong + ); + + + // Check events + + }) +} \ No newline at end of file diff --git a/battlepass/src/types.rs b/battlepass/src/types.rs index 4cf98c4e5..63c2f54c0 100644 --- a/battlepass/src/types.rs +++ b/battlepass/src/types.rs @@ -27,7 +27,7 @@ pub struct Battlepass { pub collection_id: u32 } -#[derive(Encode, Decode, Default, PartialEq, Eq, TypeInfo, MaxEncodedLen)] +#[derive(Encode, Decode, Default, Clone, PartialEq, Eq, TypeInfo, MaxEncodedLen)] pub struct BattlepassInfo { /// Total number of battlepasses per organization. pub count: u32, From f3af19ac9f550d60db4a8a2071638fe1e7787f0b Mon Sep 17 00:00:00 2001 From: FiberMan Date: Thu, 19 Jan 2023 13:45:49 +0100 Subject: [PATCH 14/49] Add wallet for battlepass Bot --- battlepass/src/lib.rs | 91 +++++++++++++++++-------- battlepass/src/tests.rs | 142 ++++++++++++++++++++++++++++++++++++---- battlepass/src/types.rs | 6 +- 3 files changed, 198 insertions(+), 41 deletions(-) diff --git a/battlepass/src/lib.rs b/battlepass/src/lib.rs index 2c94ee3ec..146ec5003 100644 --- a/battlepass/src/lib.rs +++ b/battlepass/src/lib.rs @@ -85,7 +85,8 @@ pub mod pallet { by_who: T::AccountId, for_who: T::AccountId, org_id: T::Hash, - battlepass_id: T::Hash + battlepass_id: T::Hash, + nft_id: NftId }, /// BattlePass activated @@ -142,6 +143,11 @@ pub mod pallet { LevelRemoved { battlepass_id: T::Hash, level: u8 + }, + + BotAdded { + battlepass_id: T::Hash, + bot: T::AccountId } } @@ -188,8 +194,7 @@ pub mod pallet { /// /// BattlepassInfoByOrg: map Hash => BattlepassInfo #[pallet::storage] - // #[pallet::getter(fn get_battlepass_info)] - pub type BattlepassInfoByOrg = StorageMap<_, Blake2_128Concat, T::Hash, BattlepassInfo, OptionQuery>; + pub type BattlepassInfoByOrg = StorageMap<_, Blake2_128Concat, T::Hash, BattlepassInfo, OptionQuery>; /// Claimed Battlepass-NFT by user and battlepass. /// @@ -271,7 +276,7 @@ pub mod pallet { ensure!(T::Control::is_org_active(&org_id), Error::::OrgUnknownOrInactive); // check permissions (prime) ensure!(Self::is_prime(&org_id, creator.clone())?, Error::::AuthorizationError); - let (battlepass_count, maybe_active) = Self::get_battlepass_info(org_id); + let (battlepass_count, maybe_active, _) = Self::get_battlepass_info(&org_id); // check if there is no active battlepass for the Org ensure!(maybe_active.is_none(), Error::::BattlepassExists); let new_season = battlepass_count + 1; @@ -300,16 +305,15 @@ pub mod pallet { // check if Org is active ensure!(T::Control::is_org_active(&battlepass.org_id), Error::::OrgUnknownOrInactive); // check permissions (prime, bot, self - temp) - // TODO: remove self when bot is ready - ensure!(by_who == for_who || Self::is_prime_or_bot(&battlepass.org_id, by_who.clone())?, Error::::AuthorizationError); + ensure!(by_who == for_who || Self::is_prime(&battlepass.org_id, by_who.clone())?, Error::::AuthorizationError); // check if user is a member of organization ensure!(T::Control::is_org_member_active(&battlepass.org_id, &for_who), Error::::NotMember); // check if Battlepass already claimed ensure!(!ClaimedBattlepasses::::contains_key(battlepass_id, for_who.clone()), Error::::BattlepassClaimed); - Pallet::::do_claim_battlepass(by_who.clone(), for_who.clone(), battlepass_id, battlepass.collection_id)?; + let nft_id = Self::do_claim_battlepass(by_who.clone(), for_who.clone(), battlepass_id, battlepass.collection_id)?; - Self::deposit_event(Event::BattlepassClaimed { by_who, for_who, org_id: battlepass.org_id, battlepass_id }); + Self::deposit_event(Event::BattlepassClaimed { by_who, for_who, org_id: battlepass.org_id, battlepass_id, nft_id }); Ok(()) } @@ -459,11 +463,11 @@ pub mod pallet { // check if user is a member of organization ensure!(T::Control::is_org_member_active(&battlepass.org_id, &claimer), Error::::NotMember); // check if user claimed Battlepass NFT - let nft_id = Self::get_claimed_battlepass(reward.battlepass_id, &claimer).ok_or(Error::::BattlepassNotClaimed)?; + let bp_nft_id = Self::get_claimed_battlepass(reward.battlepass_id, &claimer).ok_or(Error::::BattlepassNotClaimed)?; // check if Battlepass NFT exists - let bp_nft = pallet_rmrk_core::Pallet::::nfts(&battlepass.collection_id, nft_id).ok_or(Error::::BattlepassNftUnknown)?; + let bp_nft = pallet_rmrk_core::Pallet::::nfts(&battlepass.collection_id, bp_nft_id).ok_or(Error::::BattlepassNftUnknown)?; // validate Battlepass NFT ownership - let (root_owner, _) = pallet_rmrk_core::Pallet::::lookup_root_owner(battlepass.collection_id, nft_id)?; + let (root_owner, _) = pallet_rmrk_core::Pallet::::lookup_root_owner(battlepass.collection_id, bp_nft_id)?; ensure!(root_owner == claimer, Error::::NotOwnNft); // validate Battlepass NFT metadata let metadata: String = BoundedVec::truncate_from(reward.battlepass_id.encode()); @@ -471,7 +475,7 @@ pub mod pallet { // check if user has enough Points ensure!(Self::is_level_reached(&reward.battlepass_id, &claimer, reward.level), Error::::LevelNotReached); - Self::do_claim_reward(claimer.clone(), reward_id, reward.collection_id, reward.transferable)?; + let nft_id = Self::do_claim_reward(claimer.clone(), reward_id, reward.collection_id, reward.transferable)?; Self::deposit_event(Event::RewardClaimed {reward_id, claimer, collection_id: reward.collection_id, nft_id} ); @@ -526,6 +530,36 @@ pub mod pallet { Ok(()) } + + #[pallet::weight(0)] + pub fn add_bot( + origin: OriginFor, + battlepass_id: T::Hash, + bot: T::AccountId + ) -> DispatchResult { + let sender = ensure_signed(origin)?; + // check if Battlepass exists + let battlepass = Self::get_battlepass(battlepass_id).ok_or(Error::::BattlepassUnknown)?; + // check if Battlepass is not ended + ensure!(!Self::check_battlepass_state(battlepass_id, BattlepassState::ENDED)?, Error::::BattlepassStateWrong); + // check if Org is active + ensure!(T::Control::is_org_active(&battlepass.org_id), Error::::OrgUnknownOrInactive); + // check permissions (prime) + ensure!(Self::is_prime(&battlepass.org_id, sender.clone())?, Error::::AuthorizationError); + + BattlepassInfoByOrg::::try_mutate(battlepass.org_id, |info| -> Result<(), DispatchError> { + if let Some(inf) = info { + inf.bot = Some(bot.clone()); + Ok(()) + } else { + return Err(Error::::BattlepassInfoUnknown)?; + } + })?; + + Self::deposit_event(Event::BotAdded { battlepass_id, bot } ); + + Ok(()) + } } } @@ -536,10 +570,13 @@ impl Pallet { Ok(who == prime) } + fn is_bot(org_id: &T::Hash, who: T::AccountId) -> Result { + let (_, _, bot) = Self::get_battlepass_info(org_id); + Ok(Some(who) == bot) + } + fn is_prime_or_bot(org_id: &T::Hash, who: T::AccountId) -> Result { - // TODO: implement check - let is_bot = false; - Ok(Self::is_prime(org_id, who)? || is_bot) + Ok(Self::is_prime(org_id, who.clone())? || Self::is_bot(org_id, who)?) } fn is_level_reached(battlepass_id: &T::Hash, account: &T::AccountId, level: u8) -> bool { @@ -572,11 +609,11 @@ impl Pallet { Ok(current_state == state) } - fn get_battlepass_info(org_id: T::Hash) -> (u32, Option) { - if let Some(bp_info) = BattlepassInfoByOrg::::get(&org_id) { - return (bp_info.count, bp_info.active); + fn get_battlepass_info(org_id: &T::Hash) -> (u32, Option, Option) { + if let Some(bp_info) = BattlepassInfoByOrg::::get(org_id) { + return (bp_info.count, bp_info.active, bp_info.bot); } else { - return (0, None); + return (0, None, None); } } @@ -594,13 +631,13 @@ impl Pallet { Battlepasses::::insert(&battlepass_id, battlepass); BattlepassStates::::insert(&battlepass_id, BattlepassState::DRAFT); - BattlepassInfoByOrg::::insert(org_id, BattlepassInfo{count: new_season, active: None}); + BattlepassInfoByOrg::::insert(org_id, BattlepassInfo{count: new_season, active: None, bot: None}); Ok(battlepass_id) } - fn do_claim_battlepass(by_who: T::AccountId, for_who: T::AccountId, battlepass_id: T::Hash, collection_id: u32) -> DispatchResult { - let nft_id = ClaimedBattlepasses::::iter_key_prefix(battlepass_id).count() as u32; + fn do_claim_battlepass(by_who: T::AccountId, for_who: T::AccountId, battlepass_id: T::Hash, collection_id: u32) -> Result { + let nft_id = ClaimedBattlepasses::::iter_key_prefix(battlepass_id).count() as NftId; // Create Battlepass NFT let metadata = battlepass_id.encode(); @@ -612,13 +649,13 @@ impl Pallet { None, // royalty_recipient None, // royalty_amount BoundedVec::truncate_from(metadata), // metadata TODO: what should be here? - true, // transferable + false, // transferable None // resources )?; ClaimedBattlepasses::::insert(battlepass_id, &for_who, nft_id); - Ok(()) + Ok(nft_id) } fn change_battlepass_state(org_id: T::Hash, battlepass_id: T::Hash, state: BattlepassState) -> DispatchResult { @@ -654,8 +691,8 @@ impl Pallet { Ok(reward_id) } - fn do_claim_reward(claimer: T::AccountId, reward_id: T::Hash, collection_id: u32, transferable: bool) -> DispatchResult { - let nft_id = ClaimedRewards::::iter_key_prefix(reward_id).count() as u32; + fn do_claim_reward(claimer: T::AccountId, reward_id: T::Hash, collection_id: u32, transferable: bool) -> Result { + let nft_id = ClaimedRewards::::iter_key_prefix(reward_id).count() as NftId; // Create Battlepass NFT let metadata = reward_id.encode(); @@ -673,6 +710,6 @@ impl Pallet { ClaimedRewards::::insert(&reward_id, &claimer, nft_id); - Ok(()) + Ok(nft_id) } } \ No newline at end of file diff --git a/battlepass/src/tests.rs b/battlepass/src/tests.rs index 37c32f736..600ce6a7f 100644 --- a/battlepass/src/tests.rs +++ b/battlepass/src/tests.rs @@ -53,7 +53,7 @@ fn get_battlepass_hash(creator: AccountId, org_id: H256, season: u32, price: u16 fn create_battlepass(org_id: H256) -> H256 { let creator = ALICE; - let season = Battlepass::get_battlepass_info(org_id).0 + 1; + let season = Battlepass::get_battlepass_info(&org_id).0 + 1; let price = 10; let collection_id = pallet_rmrk_core::CollectionIndex::::get(); @@ -172,7 +172,6 @@ fn create_battlepass_test(){ assert_eq!(bp_info.is_some(), true); assert_eq!(bp_info.clone().unwrap().count, 1); assert_eq!(bp_info.clone().unwrap().active, None); - // Should create another Battlepass (may be multiple in DRAFT state) assert_ok!( @@ -447,6 +446,7 @@ fn set_points_test() { let creator = ALICE; let not_creator = BOB; let not_member = EVA; + let bot = 333u32; // Should not set if Battlepass unknown assert_noop!( @@ -487,6 +487,12 @@ fn set_points_test() { Battlepass::set_points(Origin::signed(not_member), battlepass_id, creator, 10), Error::::AuthorizationError ); + + // Should not set by Bot if Bot is not authorized + assert_noop!( + Battlepass::set_points(Origin::signed(bot), battlepass_id, creator, 10), + Error::::AuthorizationError + ); // Should not set for non members assert_noop!( @@ -494,12 +500,22 @@ fn set_points_test() { Error::::NotMember ); - // Should set points + // Should set points by Prime assert_ok!( Battlepass::set_points(Origin::signed(creator), battlepass_id, not_creator, 10) ); - // Check if Points record created - assert_eq!(Points::::contains_key(battlepass_id, not_creator), true); + // Check if Points record updated + assert_eq!(Points::::get(battlepass_id, not_creator) == 10, true); + + // Should set points by Bot + assert_ok!( + Battlepass::add_bot(Origin::signed(creator), battlepass_id, bot) + ); + assert_ok!( + Battlepass::set_points(Origin::signed(bot), battlepass_id, not_creator, 20) + ); + // Check if Points record updated + assert_eq!(Points::::get(battlepass_id, not_creator) == 20, true); // Should not set if Battlepass in ENDED state assert_ok!( @@ -761,6 +777,11 @@ fn claim_reward_test() { assert_ok!( Battlepass::claim_battlepass(Origin::signed(creator), battlepass_id, creator) ); + Nfts::::mutate(0, 1, |nft| { + if let Some(n) = nft { + n.transferable = true + } + }); assert_ok!( RmrkCore::send(Origin::signed(creator), 0, 1, AccountIdOrCollectionNftTuple::AccountId(not_member)) ); @@ -879,15 +900,22 @@ fn add_level_test() { Error::::AuthorizationError ); - // Should add Level + // Should add Level for DRAFT Battlepass + assert_ok!( + Battlepass::add_level(Origin::signed(creator), battlepass_id, 1, 10) + ); + // Check if Level added + assert_eq!(Levels::::contains_key(battlepass_id, 1), true); + + // Should add Level for ACTIVE Battlepass assert_ok!( Battlepass::activate_battlepass(Origin::signed(creator), battlepass_id) ); assert_ok!( - Battlepass::add_level(Origin::signed(creator), battlepass_id, 1, 10) + Battlepass::add_level(Origin::signed(creator), battlepass_id, 2, 10) ); // Check if Level added - assert_eq!(Levels::::contains_key(battlepass_id, 1), true); + assert_eq!(Levels::::contains_key(battlepass_id, 2), true); // Should not add if Battlepass in ENDED state assert_ok!( @@ -948,10 +976,7 @@ fn remove_level_test() { Error::::LevelUnknown ); - // Should remove Level - assert_ok!( - Battlepass::activate_battlepass(Origin::signed(creator), battlepass_id) - ); + // Should remove Level for DRAFT Battlepass assert_ok!( Battlepass::add_level(Origin::signed(creator), battlepass_id, 1, 10) ); @@ -962,6 +987,20 @@ fn remove_level_test() { // Check if Level removed assert_eq!(Levels::::contains_key(battlepass_id, 1), false); + // Should remove Level for ACTIVE Battlepass + assert_ok!( + Battlepass::activate_battlepass(Origin::signed(creator), battlepass_id) + ); + assert_ok!( + Battlepass::add_level(Origin::signed(creator), battlepass_id, 2, 10) + ); + assert_eq!(Levels::::contains_key(battlepass_id, 2), true); + assert_ok!( + Battlepass::remove_level(Origin::signed(creator), battlepass_id, 2) + ); + // Check if Level removed + assert_eq!(Levels::::contains_key(battlepass_id, 2), false); + // Should not remove if Battlepass in ENDED state assert_ok!( Battlepass::conclude_battlepass(Origin::signed(creator), battlepass_id) @@ -972,6 +1011,85 @@ fn remove_level_test() { ); + // Check events + + }) +} + +#[test] +fn add_bot_test() { + new_test_ext().execute_with(|| { + let org_id = create_org(); + let battlepass_id = create_battlepass(org_id); + let wrong_battlepass_id = ::Hashing::hash_of(&"123"); + let creator = ALICE; + let not_creator = BOB; + let not_member = EVA; + add_member(org_id, not_creator); + + // Should not add if Battlepass unknown + assert_noop!( + Battlepass::add_bot(Origin::signed(creator), wrong_battlepass_id, 1), + Error::::BattlepassUnknown + ); + + // Should not add if Org is inactive + assert_ok!( + Control::disable_org(Origin::signed(creator), org_id) + ); + assert_noop!( + Battlepass::add_bot(Origin::signed(creator), battlepass_id, 1), + Error::::OrgUnknownOrInactive + ); + assert_ok!( + Control::enable_org(Origin::signed(creator), org_id) + ); + + // Should not add if origin is not a Prime + assert_noop!( + Battlepass::add_bot(Origin::signed(not_creator), battlepass_id, 1), + Error::::AuthorizationError + ); + assert_noop!( + Battlepass::add_bot(Origin::signed(not_member), battlepass_id, 1), + Error::::AuthorizationError + ); + + // Should add Bot for DRAFT Battlepass + assert_ok!( + Battlepass::add_bot(Origin::signed(creator), battlepass_id, 1) + ); + // Check if bot added + let bp_info = BattlepassInfoByOrg::::get(org_id); + assert_eq!(bp_info.is_some(), true); + assert_eq!(bp_info.clone().unwrap().count, 1); + assert_eq!(bp_info.clone().unwrap().active, None); + assert_eq!(bp_info.clone().unwrap().bot, Some(1)); + + // Should add Bot for ACTIVE Battlepass + assert_ok!( + Battlepass::activate_battlepass(Origin::signed(creator), battlepass_id) + ); + assert_ok!( + Battlepass::add_bot(Origin::signed(creator), battlepass_id, 2) + ); + // Check if bot added + let bp_info = BattlepassInfoByOrg::::get(org_id); + assert_eq!(bp_info.is_some(), true); + assert_eq!(bp_info.clone().unwrap().count, 1); + assert_eq!(bp_info.clone().unwrap().active, Some(battlepass_id)); + assert_eq!(bp_info.clone().unwrap().bot, Some(2)); + + // Should not add if Battlepass in ENDED state + assert_ok!( + Battlepass::conclude_battlepass(Origin::signed(creator), battlepass_id) + ); + assert_noop!( + Battlepass::add_bot(Origin::signed(creator), battlepass_id, 1), + Error::::BattlepassStateWrong + ); + + // Check events }) diff --git a/battlepass/src/types.rs b/battlepass/src/types.rs index 63c2f54c0..cb3da881a 100644 --- a/battlepass/src/types.rs +++ b/battlepass/src/types.rs @@ -28,11 +28,13 @@ pub struct Battlepass { } #[derive(Encode, Decode, Default, Clone, PartialEq, Eq, TypeInfo, MaxEncodedLen)] -pub struct BattlepassInfo { +pub struct BattlepassInfo { /// Total number of battlepasses per organization. pub count: u32, /// Curent active battlepass - pub active: Option + pub active: Option, + /// Account of the authorized service which can update users' data + pub bot: Option } #[derive(Encode, Decode, Default, PartialEq, Eq, TypeInfo, MaxEncodedLen)] From 54cb69bded09f9785c4f824a356c811e41dcd565 Mon Sep 17 00:00:00 2001 From: 2075 Date: Tue, 24 Jan 2023 13:06:57 +0100 Subject: [PATCH 15/49] feat: change root_or_governance for approval --- control/src/lib.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/control/src/lib.rs b/control/src/lib.rs index 6ad3b990e..07d3cf603 100644 --- a/control/src/lib.rs +++ b/control/src/lib.rs @@ -679,7 +679,9 @@ impl Pallet { return Ok(Self::ensure_root_or_prime(origin, prime, org_type)?); }, AccessModel::Voting => { - return Ok(Self::ensure_root_or_governance(origin)?); + return Ok(Self::ensure_root_or_prime(origin, prime, org_type)?); + // TODO: add voting when membership voting is available + // return Ok(Self::ensure_root_or_governance(origin)?); }, } } From f913a356f302b597ed750a9f53d7253cf03a5828 Mon Sep 17 00:00:00 2001 From: FiberMan Date: Mon, 6 Feb 2023 16:11:05 +0100 Subject: [PATCH 16/49] feat: benchmarks for battlepass --- battlepass/Cargo.toml | 21 +- battlepass/src/benchmarking.rs | 171 +++++++++++++++++ battlepass/src/lib.rs | 92 +++++++-- battlepass/src/mock.rs | 46 +++-- battlepass/src/weights.rs | 338 +++++++++++++++++++++++++++++++++ control/Cargo.toml | 16 +- control/src/benchmarking.rs | 4 +- control/src/lib.rs | 17 +- control/src/weights.rs | 56 +++--- flow/Cargo.toml | 14 +- flow/src/benchmarking.rs | 8 +- flow/src/lib.rs | 17 +- flow/src/mock.rs | 2 + flow/src/weights.rs | 34 ++-- sense/Cargo.toml | 10 +- sense/src/benchmarking.rs | 4 +- sense/src/weights.rs | 10 +- signal/Cargo.toml | 16 +- signal/src/benchmarking.rs | 34 ++-- signal/src/lib.rs | 18 +- signal/src/mock.rs | 8 +- signal/src/tests.rs | 35 ++-- signal/src/weights.rs | 60 +++--- traits/Cargo.toml | 3 +- traits/src/lib.rs | 13 +- 25 files changed, 812 insertions(+), 235 deletions(-) create mode 100644 battlepass/src/benchmarking.rs create mode 100644 battlepass/src/weights.rs diff --git a/battlepass/Cargo.toml b/battlepass/Cargo.toml index f595ceabc..72c18b1b6 100644 --- a/battlepass/Cargo.toml +++ b/battlepass/Cargo.toml @@ -13,7 +13,7 @@ license = "GPL-3.0-or-later" description = "BattlePass pallet provides functionality to create, manage and participate in battlepasses." [dependencies] -serde = { version = "1.0.143", optional = true } +serde = { version = "1.0.143", default-features = false } codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] } scale-info = { version = "2.1.1", default-features = false, features = ["derive"] } sp-core = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.28" } @@ -29,14 +29,14 @@ pallet-uniques = { default-features = false, git = "https://github.com/paritytec pallet-rmrk-core = { git = "https://github.com/rmrk-team/rmrk-substrate", default-features = false, branch = "polkadot-v0.9.28" } rmrk-traits = { git = "https://github.com/rmrk-team/rmrk-substrate", default-features = false, branch = "polkadot-v0.9.28" } -gamedao-control = { package = "gamedao-control", path = "../control", optional = true } +orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.28", default-features = false } + +gamedao-control = { package = "gamedao-control", path = "../control", default-features = false } gamedao-traits = { package = "gamedao-traits", path = "../traits", default-features = false } [dev-dependencies] -frame-support-test = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.28" } -sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.28" } +sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.28" } codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] } -rand = "0.8.5" pallet-balances = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.28" } pallet-uniques = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.28" } @@ -46,7 +46,11 @@ orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-li [features] default = ['std'] -runtime-benchmarks = ["frame-benchmarking"] +runtime-benchmarks = [ + "frame-benchmarking/runtime-benchmarks", + "gamedao-traits/runtime-benchmarks", + "gamedao-control/runtime-benchmarks" +] std = [ "serde/std", 'codec/std', @@ -56,14 +60,15 @@ std = [ "frame-system/std", "frame-benchmarking/std", - "sp-core/std", "sp-std/std", - "sp-runtime/std", + + "pallet-balances/std", "orml-traits/std", "orml-tokens/std", "orml-currencies/std", + "pallet-uniques/std", "pallet-rmrk-core/std", "rmrk-traits/std", diff --git a/battlepass/src/benchmarking.rs b/battlepass/src/benchmarking.rs new file mode 100644 index 000000000..545fa28fd --- /dev/null +++ b/battlepass/src/benchmarking.rs @@ -0,0 +1,171 @@ +#![cfg(feature = "runtime-benchmarks")] + +use super::*; +use crate::Pallet as BPass; + +use frame_benchmarking::{benchmarks, impl_benchmark_test_suite, whitelisted_caller}; +use frame_system::RawOrigin; +use sp_runtime::{DispatchError, traits::SaturatedConversion}; +use sp_std::vec; + +const DEPOSIT_AMOUNT: u128 = 10_000_000_000_000_000_000; + +/// Fund account with tokens, needed for org and campaign interactions +fn fund_account(account_id: &T::AccountId) -> Result<(), DispatchError> { + let balance_amount: T::Balance = DEPOSIT_AMOUNT.saturated_into(); + ::Currency::deposit(T::NativeTokenId::get(), &account_id, balance_amount)?; + ::Currency::deposit(T::ProtocolTokenId::get(), &account_id, balance_amount)?; + Ok(()) +} + +/// Fund account with tokens, needed for org and battlepass interactions +fn get_funded_caller() -> Result { + let caller: T::AccountId = whitelisted_caller(); + fund_account::(&caller)?; + + Ok(caller) +} + + +fn get_org(caller: T::AccountId) -> T::Hash { + let org_id = T::ControlBenchmarkHelper::create_org(caller.clone()).unwrap(); + let treasury_id = T::Control::org_treasury_account(&org_id).unwrap(); + fund_account::(&treasury_id).unwrap(); + + org_id +} + +fn get_battlepass(caller: T::AccountId, org_id: T::Hash) -> T::Hash { + let str = BoundedVec::truncate_from(vec![1,2]); + let battlepass = types::Battlepass { + creator: caller.clone(), + org_id, + name: str.clone(), + cid: str.clone(), + season: 1, + price: 10, + collection_id: 0 + }; + + let _ = BPass::::create_battlepass(RawOrigin::Signed(caller.clone()).into(), org_id, battlepass.cid.clone(), battlepass.name.clone(), battlepass.price.clone()); + + ::Hashing::hash_of(&battlepass) +} + +fn activate_bpass(caller: T::AccountId, battlepass_id: T::Hash) { + let _ = BPass::::activate_battlepass(RawOrigin::Signed(caller).into(), battlepass_id); +} + +fn claim_bpass(caller: T::AccountId, battlepass_id: T::Hash) { + let _ = BPass::::claim_battlepass(RawOrigin::Signed(caller.clone()).into(), battlepass_id, caller); +} + +fn set_bpass_points(caller: T::AccountId, battlepass_id: T::Hash) { + let _ = BPass::::set_points(RawOrigin::Signed(caller.clone()).into(), battlepass_id, caller, 10); +} + +fn set_bpass_level(caller: T::AccountId, battlepass_id: T::Hash) { + let _ = BPass::::add_level(RawOrigin::Signed(caller.clone()).into(), battlepass_id, 1, 10); +} + +fn get_reward(caller: T::AccountId, battlepass_id: T::Hash) -> T::Hash { + let str = BoundedVec::truncate_from(vec![1,2]); + let reward = Reward{ + battlepass_id, + name: str.clone(), + cid: str.clone(), + level: 1, + transferable: true, + collection_id: 1 + }; + + let _ = BPass::::create_reward(RawOrigin::Signed(caller).into(), battlepass_id, reward.name.clone(), reward.cid.clone(), Some(10), reward.level.clone(), reward.transferable.clone()); + + ::Hashing::hash_of(&reward) +} + + +benchmarks! { + + create_battlepass { + let caller: T::AccountId = get_funded_caller::()?; + let org_id = get_org::(caller.clone()); + let str = BoundedVec::truncate_from(vec![1,2]); + }: _(RawOrigin::Signed(caller), org_id, str.clone(), str.clone(), 10) + + claim_battlepass { + let caller: T::AccountId = get_funded_caller::()?; + let org_id = get_org::(caller.clone()); + let battlepass_id = get_battlepass::(caller.clone(), org_id); + activate_bpass::(caller.clone(), battlepass_id); + }: _(RawOrigin::Signed(caller.clone()), battlepass_id, caller.clone()) + + activate_battlepass { + let caller: T::AccountId = get_funded_caller::()?; + let org_id = get_org::(caller.clone()); + let battlepass_id = get_battlepass::(caller.clone(), org_id); + }: _(RawOrigin::Signed(caller), battlepass_id) + + conclude_battlepass { + let caller: T::AccountId = get_funded_caller::()?; + let org_id = get_org::(caller.clone()); + let battlepass_id = get_battlepass::(caller.clone(), org_id); + activate_bpass::(caller.clone(), battlepass_id); + }: _(RawOrigin::Signed(caller), battlepass_id) + + set_points { + let caller: T::AccountId = get_funded_caller::()?; + let org_id = get_org::(caller.clone()); + let battlepass_id = get_battlepass::(caller.clone(), org_id); + activate_bpass::(caller.clone(), battlepass_id); + }: _(RawOrigin::Signed(caller.clone()), battlepass_id, caller.clone(), 10) + + create_reward { + let caller: T::AccountId = get_funded_caller::()?; + let org_id = get_org::(caller.clone()); + let battlepass_id = get_battlepass::(caller.clone(), org_id); + let str = BoundedVec::truncate_from(vec![1,2]); + activate_bpass::(caller.clone(), battlepass_id); + }: _(RawOrigin::Signed(caller), battlepass_id, str.clone(), str.clone(), Some(10), 1, false) + + disable_reward { + let caller: T::AccountId = get_funded_caller::()?; + let org_id = get_org::(caller.clone()); + let battlepass_id = get_battlepass::(caller.clone(), org_id); + let reward_id = get_reward::(caller.clone(), battlepass_id); + }: _(RawOrigin::Signed(caller), reward_id) + + claim_reward { + let caller: T::AccountId = get_funded_caller::()?; + let org_id = get_org::(caller.clone()); + let battlepass_id = get_battlepass::(caller.clone(), org_id); + activate_bpass::(caller.clone(), battlepass_id); + claim_bpass::(caller.clone(), battlepass_id); + set_bpass_points::(caller.clone(), battlepass_id); + set_bpass_level::(caller.clone(), battlepass_id); + let reward_id = get_reward::(caller.clone(), battlepass_id); + }: _(RawOrigin::Signed(caller), reward_id) + + add_level { + let caller: T::AccountId = get_funded_caller::()?; + let org_id = get_org::(caller.clone()); + let battlepass_id = get_battlepass::(caller.clone(), org_id); + }: _(RawOrigin::Signed(caller.clone()), battlepass_id, 1, 10) + + remove_level { + let caller: T::AccountId = get_funded_caller::()?; + let org_id = get_org::(caller.clone()); + let battlepass_id = get_battlepass::(caller.clone(), org_id); + set_bpass_level::(caller.clone(), battlepass_id); + }: _(RawOrigin::Signed(caller.clone()), battlepass_id, 1) + + add_bot { + let caller: T::AccountId = get_funded_caller::()?; + let org_id = get_org::(caller.clone()); + let battlepass_id = get_battlepass::(caller.clone(), org_id); + }: _(RawOrigin::Signed(caller.clone()), battlepass_id, caller.clone()) + + impl_benchmark_test_suite!(BPass, crate::mock::new_test_ext(), crate::mock::Test); +} + + diff --git a/battlepass/src/lib.rs b/battlepass/src/lib.rs index 146ec5003..941795ab7 100644 --- a/battlepass/src/lib.rs +++ b/battlepass/src/lib.rs @@ -16,15 +16,22 @@ pub use pallet::*; use frame_support::{pallet_prelude::*, transactional}; use frame_system::pallet_prelude::*; use sp_std::convert::TryInto; -use sp_runtime::traits::Hash; +use sp_runtime::traits::{AtLeast32BitUnsigned, Hash}; use gamedao_traits::ControlTrait; -use rmrk_traits::{primitives::{PartId, NftId, CollectionId}, Collection, Nft, ResourceInfoMin}; +#[cfg(feature = "runtime-benchmarks")] +use gamedao_traits::ControlBenchmarkingTrait; +use orml_traits::{MultiCurrency, MultiReservableCurrency}; +use rmrk_traits::{primitives::{PartId, NftId}, Collection, Nft, ResourceInfoMin, AccountIdOrCollectionNftTuple}; pub mod types; pub use types::*; mod mock; mod tests; +mod benchmarking; + +pub mod weights; +pub use weights::WeightInfo; pub type String = BoundedVec::StringLimit>; pub type Symbol = BoundedVec::SymbolLimit>; @@ -45,13 +52,38 @@ pub mod pallet { pub struct Pallet(_); #[pallet::config] - pub trait Config: frame_system::Config + pallet_rmrk_core::Config + pallet_uniques::Config { + pub trait Config: frame_system::Config + pallet_rmrk_core::Config { type Event: From> + IsType<::Event> + Into<::Event>; + /// The units in which we record balances. + type Balance: Member + + Parameter + + AtLeast32BitUnsigned + + Default + + Copy + + MaybeSerializeDeserialize + + MaxEncodedLen + + TypeInfo; + + /// The currency ID type + type CurrencyId: Member + + Parameter + + Copy + + MaybeSerializeDeserialize + + MaxEncodedLen + + TypeInfo; + + /// Multi-currency support for asset management. + type Currency: MultiCurrency + + MultiReservableCurrency; + type Control: ControlTrait; + #[cfg(feature = "runtime-benchmarks")] + type ControlBenchmarkHelper: ControlBenchmarkingTrait; + type Rmrk: Collection, Symbol, Self::AccountId> + Nft, Resource>; @@ -68,6 +100,17 @@ pub mod pallet { type PartsLimit: Get; type MaxResourcesOnMint: Get; + + /// The CurrencyId which is used as a native token. + #[pallet::constant] + type NativeTokenId: Get; + + /// The CurrencyId which is used as a protokol token. + #[pallet::constant] + type ProtocolTokenId: Get; + + /// Weight information for extrinsics in this module. + type WeightInfo: WeightInfo; } #[pallet::event] @@ -259,10 +302,10 @@ pub mod pallet { >; #[pallet::call] - impl Pallet - where T: pallet_uniques::Config, - { - #[pallet::weight(0)] + impl Pallet { + + #[pallet::call_index(0)] + #[pallet::weight(::WeightInfo::create_battlepass())] #[transactional] pub fn create_battlepass( origin: OriginFor, @@ -290,7 +333,8 @@ pub mod pallet { Ok(()) } - #[pallet::weight(0)] + #[pallet::call_index(1)] + #[pallet::weight(::WeightInfo::claim_battlepass())] #[transactional] pub fn claim_battlepass( origin: OriginFor, @@ -318,7 +362,8 @@ pub mod pallet { Ok(()) } - #[pallet::weight(0)] + #[pallet::call_index(2)] + #[pallet::weight(::WeightInfo::activate_battlepass())] #[transactional] pub fn activate_battlepass( origin: OriginFor, @@ -341,7 +386,8 @@ pub mod pallet { Ok(()) } - #[pallet::weight(0)] + #[pallet::call_index(3)] + #[pallet::weight(::WeightInfo::conclude_battlepass())] #[transactional] pub fn conclude_battlepass( origin: OriginFor, @@ -362,7 +408,8 @@ pub mod pallet { Ok(()) } - #[pallet::weight(0)] + #[pallet::call_index(4)] + #[pallet::weight(::WeightInfo::set_points())] pub fn set_points( origin: OriginFor, battlepass_id: T::Hash, @@ -388,7 +435,8 @@ pub mod pallet { Ok(()) } - #[pallet::weight(0)] + #[pallet::call_index(5)] + #[pallet::weight(::WeightInfo::create_reward())] #[transactional] pub fn create_reward( origin: OriginFor, @@ -417,7 +465,8 @@ pub mod pallet { Ok(()) } - #[pallet::weight(0)] + #[pallet::call_index(6)] + #[pallet::weight(::WeightInfo::disable_reward())] pub fn disable_reward( origin: OriginFor, reward_id: T::Hash @@ -441,7 +490,8 @@ pub mod pallet { Ok(()) } - #[pallet::weight(0)] + #[pallet::call_index(7)] + #[pallet::weight(::WeightInfo::claim_reward())] #[transactional] pub fn claim_reward( origin: OriginFor, @@ -466,9 +516,8 @@ pub mod pallet { let bp_nft_id = Self::get_claimed_battlepass(reward.battlepass_id, &claimer).ok_or(Error::::BattlepassNotClaimed)?; // check if Battlepass NFT exists let bp_nft = pallet_rmrk_core::Pallet::::nfts(&battlepass.collection_id, bp_nft_id).ok_or(Error::::BattlepassNftUnknown)?; - // validate Battlepass NFT ownership - let (root_owner, _) = pallet_rmrk_core::Pallet::::lookup_root_owner(battlepass.collection_id, bp_nft_id)?; - ensure!(root_owner == claimer, Error::::NotOwnNft); + // validate Battlepass NFT ownership + ensure!(AccountIdOrCollectionNftTuple::AccountId(claimer.clone()) == bp_nft.owner, Error::::NotOwnNft); // validate Battlepass NFT metadata let metadata: String = BoundedVec::truncate_from(reward.battlepass_id.encode()); ensure!(metadata == bp_nft.metadata, Error::::BattlepassNftInvalid); @@ -482,7 +531,8 @@ pub mod pallet { Ok(()) } - #[pallet::weight(0)] + #[pallet::call_index(8)] + #[pallet::weight(::WeightInfo::add_level())] pub fn add_level( origin: OriginFor, battlepass_id: T::Hash, @@ -506,7 +556,8 @@ pub mod pallet { Ok(()) } - #[pallet::weight(0)] + #[pallet::call_index(9)] + #[pallet::weight(::WeightInfo::remove_level())] pub fn remove_level( origin: OriginFor, battlepass_id: T::Hash, @@ -531,7 +582,8 @@ pub mod pallet { Ok(()) } - #[pallet::weight(0)] + #[pallet::call_index(10)] + #[pallet::weight(::WeightInfo::add_bot())] pub fn add_bot( origin: OriginFor, battlepass_id: T::Hash, diff --git a/battlepass/src/mock.rs b/battlepass/src/mock.rs index c09c3e787..f67ef699d 100644 --- a/battlepass/src/mock.rs +++ b/battlepass/src/mock.rs @@ -31,8 +31,10 @@ pub type Amount = i128; pub const MILLICENTS: Balance = 1_000_000_000; pub const CENTS: Balance = 1_000 * MILLICENTS; pub const DOLLARS: Balance = 100 * CENTS; +pub const NATIVE_TOKEN_ID: CurrencyId = 0; pub const PROTOCOL_TOKEN_ID: CurrencyId = 1; pub const PAYMENT_TOKEN_ID: CurrencyId = 2; + // Org creator: pub const ALICE: AccountId = 11; // Contributors: @@ -74,6 +76,7 @@ construct_runtime!( parameter_types! { pub const BlockHashCount: u32 = 250; + pub const SS58Prefix: u8 = 42; } impl frame_system::Config for Test { @@ -98,7 +101,7 @@ impl frame_system::Config for Test { type OnNewAccount = (); type OnKilledAccount = (); type SystemWeightInfo = (); - type SS58Prefix = (); //SS58Prefix; + type SS58Prefix = SS58Prefix; type OnSetCode = (); type MaxConsumers = ConstU32<128>; } @@ -154,28 +157,29 @@ impl orml_currencies::Config for Test { type WeightInfo = (); } -// parameter_types! { -// pub CollectionDeposit: Balance = cent(ZERO) * 10; -// pub ItemDeposit: Balance = dollar(ZERO); -// } +parameter_types! { + pub CollectionDeposit: Balance = 0; + pub ItemDeposit: Balance = 0; + pub MetadataDepositBase: Balance = 0; + pub MetadataDepositPerByte: Balance = 0; + +} impl pallet_uniques::Config for Test { type Event = Event; type CollectionId = u32; type ItemId = u32; - type Currency = (); //Balances; + type Currency = PalletBalances; type ForceOrigin = frame_system::EnsureRoot; - type CollectionDeposit = (); //CollectionDeposit; - type ItemDeposit = (); //ItemDeposit; - type MetadataDepositBase = (); //MetadataDepositBase; - type AttributeDepositBase = (); //MetadataDepositBase; - type DepositPerByte = (); //MetadataDepositPerByte; + type CollectionDeposit = CollectionDeposit; + type ItemDeposit = ItemDeposit; + type MetadataDepositBase = MetadataDepositBase; + type AttributeDepositBase = MetadataDepositBase; + type DepositPerByte = MetadataDepositPerByte; type StringLimit = StringLimit; type KeyLimit = ConstU32<32>; type ValueLimit = ConstU32<256>; - type WeightInfo = (); //pallet_uniques::weights::SubstrateWeight; - #[cfg(feature = "runtime-benchmarks")] - type Helper = (); + type WeightInfo = (); type CreateOrigin = AsEnsureOriginWithArg>; type Locker = pallet_rmrk_core::Pallet; } @@ -199,7 +203,8 @@ impl pallet_rmrk_core::Config for Test { } parameter_types! { - pub const ProtocolTokenId: u32 = PROTOCOL_TOKEN_ID; + pub const NativeTokenId: CurrencyId = NATIVE_TOKEN_ID; + pub const ProtocolTokenId: CurrencyId = PROTOCOL_TOKEN_ID; pub const PaymentTokenId: CurrencyId = PAYMENT_TOKEN_ID; pub const MinimumDeposit: Balance = 5 * DOLLARS; pub const ControlPalletId: PalletId = PalletId(*b"gd/cntrl"); @@ -211,7 +216,7 @@ impl gamedao_control::Config for Test { type WeightInfo = (); type Event = Event; type Currency = Currencies; - type MaxMembers = MaxMembers;//ConstU32<10000>; + type MaxMembers = MaxMembers; type ProtocolTokenId = ProtocolTokenId; type PaymentTokenId = PaymentTokenId; type MinimumDeposit = MinimumDeposit; @@ -221,12 +226,20 @@ impl gamedao_control::Config for Test { impl gamedao_battlepass::Config for Test { type Event = Event; + type Balance = Balance; + type CurrencyId = CurrencyId; + type Currency = Currencies; type Control = Control; + #[cfg(feature = "runtime-benchmarks")] + type ControlBenchmarkHelper = Control; type Rmrk = RmrkCore; type StringLimit = StringLimit; type SymbolLimit = CollectionSymbolLimit; type PartsLimit = PartsLimit; type MaxResourcesOnMint = MaxResourcesOnMint; + type NativeTokenId = NativeTokenId; + type ProtocolTokenId = ProtocolTokenId; + type WeightInfo = (); } // Build genesis storage according to the mock runtime. @@ -235,6 +248,7 @@ pub fn new_test_ext() -> sp_io::TestExternalities { orml_tokens::GenesisConfig:: { balances: vec![ // ALICE org creator + (ALICE, NATIVE_TOKEN_ID, INIT_BALANCE), (ALICE, PROTOCOL_TOKEN_ID, INIT_BALANCE), (ALICE, PAYMENT_TOKEN_ID, INIT_BALANCE), diff --git a/battlepass/src/weights.rs b/battlepass/src/weights.rs new file mode 100644 index 000000000..a715c9c61 --- /dev/null +++ b/battlepass/src/weights.rs @@ -0,0 +1,338 @@ +// This file is part of Substrate. + +// Copyright (C) 2021 Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//! Autogenerated weights for gamedao_battlepass +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev +//! DATE: 2023-02-06, STEPS: `20`, REPEAT: 10, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! EXECUTION: None, WASM-EXECUTION: Compiled, CHAIN: None, DB CACHE: 1024 + +// Executed Command: +// ./target/release/subzero-dev +// benchmark +// pallet +// --pallet=gamedao_battlepass +// --extrinsic=* +// --steps=20 +// --repeat=10 +// --output=modules/gamedao-protocol/battlepass/src/weights.rs +// --template=./.maintain/frame-weight-template.hbs + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] + +use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; +use sp_std::marker::PhantomData; + +/// Weight functions needed for gamedao_battlepass. +pub trait WeightInfo { + fn create_battlepass() -> Weight; + fn claim_battlepass() -> Weight; + fn activate_battlepass() -> Weight; + fn conclude_battlepass() -> Weight; + fn set_points() -> Weight; + fn create_reward() -> Weight; + fn disable_reward() -> Weight; + fn claim_reward() -> Weight; + fn add_level() -> Weight; + fn remove_level() -> Weight; + fn add_bot() -> Weight; +} + +/// Weights for gamedao_battlepass using the Substrate node and recommended hardware. +pub struct SubstrateWeight(PhantomData); +impl WeightInfo for SubstrateWeight { + // Storage: Control OrgStates (r:1 w:0) + // Storage: Control Orgs (r:1 w:0) + // Storage: Battlepass BattlepassInfoByOrg (r:1 w:1) + // Storage: RmrkCore CollectionIndex (r:1 w:1) + // Storage: Uniques Class (r:1 w:1) + // Storage: RmrkCore Collections (r:0 w:1) + // Storage: Uniques ClassAccount (r:0 w:1) + // Storage: Uniques NextCollectionId (r:0 w:1) + // Storage: Battlepass BattlepassStates (r:0 w:1) + // Storage: Battlepass Battlepasses (r:0 w:1) + fn create_battlepass() -> Weight { + (44_000_000 as Weight) + .saturating_add(T::DbWeight::get().reads(5 as Weight)) + .saturating_add(T::DbWeight::get().writes(8 as Weight)) + } + // Storage: Battlepass Battlepasses (r:1 w:0) + // Storage: Battlepass BattlepassStates (r:1 w:0) + // Storage: Control OrgStates (r:1 w:0) + // Storage: Control MemberStates (r:1 w:0) + // Storage: Battlepass ClaimedBattlepasses (r:2 w:1) + // Storage: RmrkCore Nfts (r:1 w:1) + // Storage: RmrkCore Collections (r:1 w:1) + // Storage: Uniques Asset (r:1 w:1) + // Storage: Uniques Class (r:1 w:1) + // Storage: Uniques CollectionMaxSupply (r:1 w:0) + // Storage: Uniques Account (r:0 w:1) + fn claim_battlepass() -> Weight { + (63_000_000 as Weight) + .saturating_add(T::DbWeight::get().reads(11 as Weight)) + .saturating_add(T::DbWeight::get().writes(6 as Weight)) + } + // Storage: Battlepass Battlepasses (r:1 w:0) + // Storage: Battlepass BattlepassStates (r:1 w:1) + // Storage: Control OrgStates (r:1 w:0) + // Storage: Control Orgs (r:1 w:0) + // Storage: Battlepass BattlepassInfoByOrg (r:1 w:1) + fn activate_battlepass() -> Weight { + (28_000_000 as Weight) + .saturating_add(T::DbWeight::get().reads(5 as Weight)) + .saturating_add(T::DbWeight::get().writes(2 as Weight)) + } + // Storage: Battlepass Battlepasses (r:1 w:0) + // Storage: Battlepass BattlepassStates (r:1 w:1) + // Storage: Control Orgs (r:1 w:0) + // Storage: Battlepass BattlepassInfoByOrg (r:1 w:1) + fn conclude_battlepass() -> Weight { + (27_000_000 as Weight) + .saturating_add(T::DbWeight::get().reads(4 as Weight)) + .saturating_add(T::DbWeight::get().writes(2 as Weight)) + } + // Storage: Battlepass Battlepasses (r:1 w:0) + // Storage: Battlepass BattlepassStates (r:1 w:0) + // Storage: Control OrgStates (r:1 w:0) + // Storage: Control Orgs (r:1 w:0) + // Storage: Control MemberStates (r:1 w:0) + // Storage: Battlepass Points (r:0 w:1) + fn set_points() -> Weight { + (27_000_000 as Weight) + .saturating_add(T::DbWeight::get().reads(5 as Weight)) + .saturating_add(T::DbWeight::get().writes(1 as Weight)) + } + // Storage: Battlepass Battlepasses (r:1 w:0) + // Storage: Battlepass BattlepassStates (r:1 w:0) + // Storage: Control OrgStates (r:1 w:0) + // Storage: Control Orgs (r:1 w:0) + // Storage: RmrkCore CollectionIndex (r:1 w:1) + // Storage: Uniques Class (r:1 w:1) + // Storage: RmrkCore Collections (r:0 w:1) + // Storage: Uniques ClassAccount (r:0 w:1) + // Storage: Uniques NextCollectionId (r:0 w:1) + // Storage: Battlepass Rewards (r:0 w:1) + // Storage: Battlepass RewardStates (r:0 w:1) + fn create_reward() -> Weight { + (48_000_000 as Weight) + .saturating_add(T::DbWeight::get().reads(6 as Weight)) + .saturating_add(T::DbWeight::get().writes(7 as Weight)) + } + // Storage: Battlepass Rewards (r:1 w:0) + // Storage: Battlepass RewardStates (r:1 w:1) + // Storage: Battlepass Battlepasses (r:1 w:0) + // Storage: Control Orgs (r:1 w:0) + fn disable_reward() -> Weight { + (25_000_000 as Weight) + .saturating_add(T::DbWeight::get().reads(4 as Weight)) + .saturating_add(T::DbWeight::get().writes(1 as Weight)) + } + // Storage: Battlepass Rewards (r:1 w:0) + // Storage: Battlepass RewardStates (r:1 w:0) + // Storage: Battlepass ClaimedRewards (r:2 w:1) + // Storage: Battlepass Battlepasses (r:1 w:0) + // Storage: Battlepass BattlepassStates (r:1 w:0) + // Storage: Control OrgStates (r:1 w:0) + // Storage: Control MemberStates (r:1 w:0) + // Storage: Battlepass ClaimedBattlepasses (r:1 w:0) + // Storage: RmrkCore Nfts (r:2 w:1) + // Storage: Battlepass Points (r:1 w:0) + // Storage: Battlepass Levels (r:2 w:0) + // Storage: RmrkCore Collections (r:1 w:1) + // Storage: Uniques Asset (r:1 w:1) + // Storage: Uniques Class (r:1 w:1) + // Storage: Uniques CollectionMaxSupply (r:1 w:0) + // Storage: Uniques Account (r:0 w:1) + fn claim_reward() -> Weight { + (95_000_000 as Weight) + .saturating_add(T::DbWeight::get().reads(18 as Weight)) + .saturating_add(T::DbWeight::get().writes(6 as Weight)) + } + // Storage: Battlepass Battlepasses (r:1 w:0) + // Storage: Battlepass BattlepassStates (r:1 w:0) + // Storage: Control OrgStates (r:1 w:0) + // Storage: Control Orgs (r:1 w:0) + // Storage: Battlepass Levels (r:0 w:1) + fn add_level() -> Weight { + (24_000_000 as Weight) + .saturating_add(T::DbWeight::get().reads(4 as Weight)) + .saturating_add(T::DbWeight::get().writes(1 as Weight)) + } + // Storage: Battlepass Battlepasses (r:1 w:0) + // Storage: Battlepass BattlepassStates (r:1 w:0) + // Storage: Control OrgStates (r:1 w:0) + // Storage: Control Orgs (r:1 w:0) + // Storage: Battlepass Levels (r:1 w:1) + fn remove_level() -> Weight { + (27_000_000 as Weight) + .saturating_add(T::DbWeight::get().reads(5 as Weight)) + .saturating_add(T::DbWeight::get().writes(1 as Weight)) + } + // Storage: Battlepass Battlepasses (r:1 w:0) + // Storage: Battlepass BattlepassStates (r:1 w:0) + // Storage: Control OrgStates (r:1 w:0) + // Storage: Control Orgs (r:1 w:0) + // Storage: Battlepass BattlepassInfoByOrg (r:1 w:1) + fn add_bot() -> Weight { + (26_000_000 as Weight) + .saturating_add(T::DbWeight::get().reads(5 as Weight)) + .saturating_add(T::DbWeight::get().writes(1 as Weight)) + } +} + +// For backwards compatibility and tests +impl WeightInfo for () { + // Storage: Control OrgStates (r:1 w:0) + // Storage: Control Orgs (r:1 w:0) + // Storage: Battlepass BattlepassInfoByOrg (r:1 w:1) + // Storage: RmrkCore CollectionIndex (r:1 w:1) + // Storage: Uniques Class (r:1 w:1) + // Storage: RmrkCore Collections (r:0 w:1) + // Storage: Uniques ClassAccount (r:0 w:1) + // Storage: Uniques NextCollectionId (r:0 w:1) + // Storage: Battlepass BattlepassStates (r:0 w:1) + // Storage: Battlepass Battlepasses (r:0 w:1) + fn create_battlepass() -> Weight { + (44_000_000 as Weight) + .saturating_add(RocksDbWeight::get().reads(5 as Weight)) + .saturating_add(RocksDbWeight::get().writes(8 as Weight)) + } + // Storage: Battlepass Battlepasses (r:1 w:0) + // Storage: Battlepass BattlepassStates (r:1 w:0) + // Storage: Control OrgStates (r:1 w:0) + // Storage: Control MemberStates (r:1 w:0) + // Storage: Battlepass ClaimedBattlepasses (r:2 w:1) + // Storage: RmrkCore Nfts (r:1 w:1) + // Storage: RmrkCore Collections (r:1 w:1) + // Storage: Uniques Asset (r:1 w:1) + // Storage: Uniques Class (r:1 w:1) + // Storage: Uniques CollectionMaxSupply (r:1 w:0) + // Storage: Uniques Account (r:0 w:1) + fn claim_battlepass() -> Weight { + (63_000_000 as Weight) + .saturating_add(RocksDbWeight::get().reads(11 as Weight)) + .saturating_add(RocksDbWeight::get().writes(6 as Weight)) + } + // Storage: Battlepass Battlepasses (r:1 w:0) + // Storage: Battlepass BattlepassStates (r:1 w:1) + // Storage: Control OrgStates (r:1 w:0) + // Storage: Control Orgs (r:1 w:0) + // Storage: Battlepass BattlepassInfoByOrg (r:1 w:1) + fn activate_battlepass() -> Weight { + (28_000_000 as Weight) + .saturating_add(RocksDbWeight::get().reads(5 as Weight)) + .saturating_add(RocksDbWeight::get().writes(2 as Weight)) + } + // Storage: Battlepass Battlepasses (r:1 w:0) + // Storage: Battlepass BattlepassStates (r:1 w:1) + // Storage: Control Orgs (r:1 w:0) + // Storage: Battlepass BattlepassInfoByOrg (r:1 w:1) + fn conclude_battlepass() -> Weight { + (27_000_000 as Weight) + .saturating_add(RocksDbWeight::get().reads(4 as Weight)) + .saturating_add(RocksDbWeight::get().writes(2 as Weight)) + } + // Storage: Battlepass Battlepasses (r:1 w:0) + // Storage: Battlepass BattlepassStates (r:1 w:0) + // Storage: Control OrgStates (r:1 w:0) + // Storage: Control Orgs (r:1 w:0) + // Storage: Control MemberStates (r:1 w:0) + // Storage: Battlepass Points (r:0 w:1) + fn set_points() -> Weight { + (27_000_000 as Weight) + .saturating_add(RocksDbWeight::get().reads(5 as Weight)) + .saturating_add(RocksDbWeight::get().writes(1 as Weight)) + } + // Storage: Battlepass Battlepasses (r:1 w:0) + // Storage: Battlepass BattlepassStates (r:1 w:0) + // Storage: Control OrgStates (r:1 w:0) + // Storage: Control Orgs (r:1 w:0) + // Storage: RmrkCore CollectionIndex (r:1 w:1) + // Storage: Uniques Class (r:1 w:1) + // Storage: RmrkCore Collections (r:0 w:1) + // Storage: Uniques ClassAccount (r:0 w:1) + // Storage: Uniques NextCollectionId (r:0 w:1) + // Storage: Battlepass Rewards (r:0 w:1) + // Storage: Battlepass RewardStates (r:0 w:1) + fn create_reward() -> Weight { + (48_000_000 as Weight) + .saturating_add(RocksDbWeight::get().reads(6 as Weight)) + .saturating_add(RocksDbWeight::get().writes(7 as Weight)) + } + // Storage: Battlepass Rewards (r:1 w:0) + // Storage: Battlepass RewardStates (r:1 w:1) + // Storage: Battlepass Battlepasses (r:1 w:0) + // Storage: Control Orgs (r:1 w:0) + fn disable_reward() -> Weight { + (25_000_000 as Weight) + .saturating_add(RocksDbWeight::get().reads(4 as Weight)) + .saturating_add(RocksDbWeight::get().writes(1 as Weight)) + } + // Storage: Battlepass Rewards (r:1 w:0) + // Storage: Battlepass RewardStates (r:1 w:0) + // Storage: Battlepass ClaimedRewards (r:2 w:1) + // Storage: Battlepass Battlepasses (r:1 w:0) + // Storage: Battlepass BattlepassStates (r:1 w:0) + // Storage: Control OrgStates (r:1 w:0) + // Storage: Control MemberStates (r:1 w:0) + // Storage: Battlepass ClaimedBattlepasses (r:1 w:0) + // Storage: RmrkCore Nfts (r:2 w:1) + // Storage: Battlepass Points (r:1 w:0) + // Storage: Battlepass Levels (r:2 w:0) + // Storage: RmrkCore Collections (r:1 w:1) + // Storage: Uniques Asset (r:1 w:1) + // Storage: Uniques Class (r:1 w:1) + // Storage: Uniques CollectionMaxSupply (r:1 w:0) + // Storage: Uniques Account (r:0 w:1) + fn claim_reward() -> Weight { + (95_000_000 as Weight) + .saturating_add(RocksDbWeight::get().reads(18 as Weight)) + .saturating_add(RocksDbWeight::get().writes(6 as Weight)) + } + // Storage: Battlepass Battlepasses (r:1 w:0) + // Storage: Battlepass BattlepassStates (r:1 w:0) + // Storage: Control OrgStates (r:1 w:0) + // Storage: Control Orgs (r:1 w:0) + // Storage: Battlepass Levels (r:0 w:1) + fn add_level() -> Weight { + (24_000_000 as Weight) + .saturating_add(RocksDbWeight::get().reads(4 as Weight)) + .saturating_add(RocksDbWeight::get().writes(1 as Weight)) + } + // Storage: Battlepass Battlepasses (r:1 w:0) + // Storage: Battlepass BattlepassStates (r:1 w:0) + // Storage: Control OrgStates (r:1 w:0) + // Storage: Control Orgs (r:1 w:0) + // Storage: Battlepass Levels (r:1 w:1) + fn remove_level() -> Weight { + (27_000_000 as Weight) + .saturating_add(RocksDbWeight::get().reads(5 as Weight)) + .saturating_add(RocksDbWeight::get().writes(1 as Weight)) + } + // Storage: Battlepass Battlepasses (r:1 w:0) + // Storage: Battlepass BattlepassStates (r:1 w:0) + // Storage: Control OrgStates (r:1 w:0) + // Storage: Control Orgs (r:1 w:0) + // Storage: Battlepass BattlepassInfoByOrg (r:1 w:1) + fn add_bot() -> Weight { + (26_000_000 as Weight) + .saturating_add(RocksDbWeight::get().reads(5 as Weight)) + .saturating_add(RocksDbWeight::get().writes(1 as Weight)) + } +} diff --git a/control/Cargo.toml b/control/Cargo.toml index 71a4b55a9..0c1034cc2 100755 --- a/control/Cargo.toml +++ b/control/Cargo.toml @@ -16,7 +16,7 @@ description = "DAO Factory" hex-literal = "0.3.4" num_enum = { version = "0.5.1", default-features = false } -serde = { version = "1.0.143", optional = true } +serde = { version = "1.0.143", default-features = false } codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] } scale-info = { version = "2.1.1", default-features = false, features = ["derive"] } @@ -38,9 +38,8 @@ gamedao-traits = { package = "gamedao-traits", path = "../traits", default-featu # tangram = { package = "module-tangram", path = "../../zero/tangram", default-features = false } [dev-dependencies] -sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.28" } -sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.28" } -frame-support-test = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.28" } +sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.28" } +sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.28" } pallet-balances = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.28" } orml-currencies = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.28", default-features = false } orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.28", default-features = false } @@ -48,8 +47,8 @@ orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-li [features] default = ["std"] runtime-benchmarks = [ - "frame-benchmarking", - "gamedao-traits/frame-benchmarking" + "frame-benchmarking/runtime-benchmarks", + "gamedao-traits/runtime-benchmarks" ] std = [ "codec/std", @@ -62,11 +61,8 @@ std = [ "frame-system/std", "frame-benchmarking/std", - "sp-core/std", "sp-std/std", - "sp-runtime/std", - # "sp-storage/std", - + # "tangram/std", "orml-traits/std", "orml-tokens/std", diff --git a/control/src/benchmarking.rs b/control/src/benchmarking.rs index e60d01e27..d9e72442d 100644 --- a/control/src/benchmarking.rs +++ b/control/src/benchmarking.rs @@ -1,6 +1,8 @@ #![cfg(feature = "runtime-benchmarks")] -use crate::*; +use super::*; +use crate::Pallet as Control; + use frame_benchmarking::{account, benchmarks, whitelisted_caller}; use frame_system::RawOrigin; use sp_runtime::{DispatchError, traits::SaturatedConversion}; diff --git a/control/src/lib.rs b/control/src/lib.rs index 6ad3b990e..7a9cc38cb 100644 --- a/control/src/lib.rs +++ b/control/src/lib.rs @@ -25,13 +25,15 @@ use frame_support::{dispatch::{DispatchResult, DispatchError, RawOrigin}, ensure, PalletId, traits::Get, BoundedVec, transactional, log }; use frame_system::ensure_root; -use gamedao_traits::{ControlTrait, ControlBenchmarkingTrait}; +#[cfg(feature = "runtime-benchmarks")] +use gamedao_traits::ControlBenchmarkingTrait; +use gamedao_traits::ControlTrait; use orml_traits::{MultiCurrency, MultiReservableCurrency}; use scale_info::TypeInfo; use sp_runtime::{ traits::{AccountIdConversion, AtLeast32BitUnsigned, Hash, BadOrigin}, ArithmeticError::Overflow}; -use sp_std::{fmt::Debug, convert::TryInto, vec, vec::{Vec}}; +use sp_std::{fmt::Debug, convert::TryInto, vec, vec::Vec}; #[cfg(feature = "std")] use serde::{Deserialize, Serialize}; @@ -742,9 +744,8 @@ impl ControlTrait for Pallet { } } +#[cfg(feature = "runtime-benchmarks")] impl ControlBenchmarkingTrait for Pallet { - /// ** Should be used for benchmarking only!!! ** - #[cfg(feature = "runtime-benchmarks")] fn create_org(caller: T::AccountId) -> Result { let text = BoundedVec::truncate_from(vec![1, 2, 3, 4]); let index = OrgCount::::get(); @@ -765,8 +766,6 @@ impl ControlBenchmarkingTrait for Pallet { Ok(org_id) } - /// ** Should be used for benchmarking only!!! ** - #[cfg(feature = "runtime-benchmarks")] fn fill_org_with_members(org_id: &T::Hash, accounts: Vec) -> Result<(), DispatchError> { for acc in BoundedVec::::truncate_from(accounts) { Pallet::::add_member( @@ -774,6 +773,12 @@ impl ControlBenchmarkingTrait for Pallet { org_id.clone(), acc.clone() ).unwrap(); + Pallet::::update_member_state( + frame_system::RawOrigin::Root.into(), + org_id.clone(), + acc.clone(), + MemberState::Active + ).unwrap(); } Ok(()) } diff --git a/control/src/weights.rs b/control/src/weights.rs index 1963eb0ba..30744569e 100644 --- a/control/src/weights.rs +++ b/control/src/weights.rs @@ -18,7 +18,7 @@ //! Autogenerated weights for gamedao_control //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2022-12-16, STEPS: `20`, REPEAT: 10, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2023-02-06, STEPS: `20`, REPEAT: 10, LOW RANGE: `[]`, HIGH RANGE: `[]` //! EXECUTION: None, WASM-EXECUTION: Compiled, CHAIN: None, DB CACHE: 1024 // Executed Command: @@ -64,28 +64,28 @@ impl WeightInfo for SubstrateWeight { // Storage: Control MemberStates (r:0 w:1) // Storage: Control OrgStates (r:0 w:1) fn create_org() -> Weight { - (75_523_000 as Weight) + (50_000_000 as Weight) .saturating_add(T::DbWeight::get().reads(6 as Weight)) .saturating_add(T::DbWeight::get().writes(10 as Weight)) } // Storage: Control Orgs (r:1 w:1) // Storage: Control MemberStates (r:1 w:0) fn update_org() -> Weight { - (33_049_000 as Weight) + (19_000_000 as Weight) .saturating_add(T::DbWeight::get().reads(2 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } // Storage: Control Orgs (r:1 w:0) // Storage: Control OrgStates (r:0 w:1) fn disable_org() -> Weight { - (26_400_000 as Weight) + (15_000_000 as Weight) .saturating_add(T::DbWeight::get().reads(1 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } // Storage: Control Orgs (r:1 w:0) // Storage: Control OrgStates (r:0 w:1) fn enable_org() -> Weight { - (25_846_000 as Weight) + (15_000_000 as Weight) .saturating_add(T::DbWeight::get().reads(1 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } @@ -95,27 +95,26 @@ impl WeightInfo for SubstrateWeight { // Storage: Control OrgMemberCount (r:0 w:1) // Storage: Control MemberStates (r:0 w:1) fn add_member(r: u32, ) -> Weight { - (46_146_000 as Weight) - // Standard Error: 2_000 - .saturating_add((63_000 as Weight).saturating_mul(r as Weight)) + (19_798_000 as Weight) + // Standard Error: 1_000 + .saturating_add((45_000 as Weight).saturating_mul(r as Weight)) .saturating_add(T::DbWeight::get().reads(3 as Weight)) .saturating_add(T::DbWeight::get().writes(3 as Weight)) } // Storage: Control Orgs (r:1 w:0) - // Storage: Control MemberStates (r:1 w:1) + // Storage: Control MemberStates (r:1 w:0) fn update_member_state() -> Weight { - (26_240_000 as Weight) + (11_000_000 as Weight) .saturating_add(T::DbWeight::get().reads(2 as Weight)) - .saturating_add(T::DbWeight::get().writes(1 as Weight)) } // Storage: Control Orgs (r:1 w:0) // Storage: Control Members (r:1 w:1) // Storage: Control OrgMemberCount (r:0 w:1) // Storage: Control MemberStates (r:0 w:1) fn remove_member(r: u32, ) -> Weight { - (44_807_000 as Weight) - // Standard Error: 3_000 - .saturating_add((66_000 as Weight).saturating_mul(r as Weight)) + (19_160_000 as Weight) + // Standard Error: 1_000 + .saturating_add((41_000 as Weight).saturating_mul(r as Weight)) .saturating_add(T::DbWeight::get().reads(2 as Weight)) .saturating_add(T::DbWeight::get().writes(3 as Weight)) } @@ -124,7 +123,7 @@ impl WeightInfo for SubstrateWeight { // Storage: Tokens Accounts (r:2 w:2) // Storage: System Account (r:2 w:1) fn spend_funds() -> Weight { - (50_764_000 as Weight) + (40_000_000 as Weight) .saturating_add(T::DbWeight::get().reads(6 as Weight)) .saturating_add(T::DbWeight::get().writes(3 as Weight)) } @@ -142,28 +141,28 @@ impl WeightInfo for () { // Storage: Control MemberStates (r:0 w:1) // Storage: Control OrgStates (r:0 w:1) fn create_org() -> Weight { - (75_523_000 as Weight) + (50_000_000 as Weight) .saturating_add(RocksDbWeight::get().reads(6 as Weight)) .saturating_add(RocksDbWeight::get().writes(10 as Weight)) } // Storage: Control Orgs (r:1 w:1) // Storage: Control MemberStates (r:1 w:0) fn update_org() -> Weight { - (33_049_000 as Weight) + (19_000_000 as Weight) .saturating_add(RocksDbWeight::get().reads(2 as Weight)) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } // Storage: Control Orgs (r:1 w:0) // Storage: Control OrgStates (r:0 w:1) fn disable_org() -> Weight { - (26_400_000 as Weight) + (15_000_000 as Weight) .saturating_add(RocksDbWeight::get().reads(1 as Weight)) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } // Storage: Control Orgs (r:1 w:0) // Storage: Control OrgStates (r:0 w:1) fn enable_org() -> Weight { - (25_846_000 as Weight) + (15_000_000 as Weight) .saturating_add(RocksDbWeight::get().reads(1 as Weight)) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } @@ -173,27 +172,26 @@ impl WeightInfo for () { // Storage: Control OrgMemberCount (r:0 w:1) // Storage: Control MemberStates (r:0 w:1) fn add_member(r: u32, ) -> Weight { - (46_146_000 as Weight) - // Standard Error: 2_000 - .saturating_add((63_000 as Weight).saturating_mul(r as Weight)) + (19_798_000 as Weight) + // Standard Error: 1_000 + .saturating_add((45_000 as Weight).saturating_mul(r as Weight)) .saturating_add(RocksDbWeight::get().reads(3 as Weight)) .saturating_add(RocksDbWeight::get().writes(3 as Weight)) } // Storage: Control Orgs (r:1 w:0) - // Storage: Control MemberStates (r:1 w:1) + // Storage: Control MemberStates (r:1 w:0) fn update_member_state() -> Weight { - (26_240_000 as Weight) + (11_000_000 as Weight) .saturating_add(RocksDbWeight::get().reads(2 as Weight)) - .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } // Storage: Control Orgs (r:1 w:0) // Storage: Control Members (r:1 w:1) // Storage: Control OrgMemberCount (r:0 w:1) // Storage: Control MemberStates (r:0 w:1) fn remove_member(r: u32, ) -> Weight { - (44_807_000 as Weight) - // Standard Error: 3_000 - .saturating_add((66_000 as Weight).saturating_mul(r as Weight)) + (19_160_000 as Weight) + // Standard Error: 1_000 + .saturating_add((41_000 as Weight).saturating_mul(r as Weight)) .saturating_add(RocksDbWeight::get().reads(2 as Weight)) .saturating_add(RocksDbWeight::get().writes(3 as Weight)) } @@ -202,7 +200,7 @@ impl WeightInfo for () { // Storage: Tokens Accounts (r:2 w:2) // Storage: System Account (r:2 w:1) fn spend_funds() -> Weight { - (50_764_000 as Weight) + (40_000_000 as Weight) .saturating_add(RocksDbWeight::get().reads(6 as Weight)) .saturating_add(RocksDbWeight::get().writes(3 as Weight)) } diff --git a/flow/Cargo.toml b/flow/Cargo.toml index 0cc44d6f3..9925e74fa 100644 --- a/flow/Cargo.toml +++ b/flow/Cargo.toml @@ -14,7 +14,7 @@ description = "Simple Crowdfunding module, supporting multiple campaigns, which repository = "https://github.com/gamedaoco/gamedao-protocol" [dependencies] -serde = { version = "1.0.143", optional = true } +serde = { version = "1.0.143", default-features = false } codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] } scale-info = { version = "2.1.1", default-features = false, features = ["derive"] } sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.28", default-features = false } @@ -29,11 +29,10 @@ orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-li orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.28", default-features = false } gamedao-traits = { package = "gamedao-traits", path = "../traits", default-features = false } -gamedao-control = { package = "gamedao-control", path = "../control", optional = true } +gamedao-control = { package = "gamedao-control", path = "../control", default-features = false } [dev-dependencies] -sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.28" } -frame-support-test = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.28" } +sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.28" } pallet-timestamp = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.28" } pallet-balances = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.28" } @@ -43,8 +42,9 @@ gamedao-control = { package = "gamedao-control", path = "../control", default-fe [features] default = ["std"] runtime-benchmarks = [ - "frame-benchmarking", - "gamedao-traits/frame-benchmarking", + "frame-benchmarking/runtime-benchmarks", + "gamedao-traits/runtime-benchmarks", + "gamedao-control/runtime-benchmarks" ] std = [ "codec/std", @@ -55,9 +55,7 @@ std = [ "frame-system/std", "frame-benchmarking/std", - "sp-core/std", "sp-std/std", - "sp-runtime/std", "orml-traits/std", "orml-tokens/std", diff --git a/flow/src/benchmarking.rs b/flow/src/benchmarking.rs index 38db539cb..6cc4c7aa3 100644 --- a/flow/src/benchmarking.rs +++ b/flow/src/benchmarking.rs @@ -1,7 +1,7 @@ //! Benchmarking setup for gamedao-flow use super::*; - use crate::Pallet as Flow; + use frame_benchmarking::{account, benchmarks, impl_benchmark_test_suite, whitelisted_caller}; use frame_system::RawOrigin; use frame_support::traits::Hooks; @@ -42,7 +42,7 @@ benchmarks! { fund_account::(&caller)?; // Prepare organization and treasury - let org_id = T::Control::create_org(caller.clone().into())?; + let org_id = T::ControlBenchmarkHelper::create_org(caller.clone().into())?; let treasury_id = T::Control::org_treasury_account(&org_id).unwrap(); let bounded_vec = BoundedVec::truncate_from(vec![0; T::StringLimit::get() as usize]); fund_account::(&treasury_id)?; @@ -71,7 +71,7 @@ benchmarks! { fund_accounts::(&vec![owner.clone(), contributor.clone()])?; // Prepare organization and treasury - let org_id = T::Control::create_org(owner.clone().into())?; + let org_id = T::ControlBenchmarkHelper::create_org(owner.clone().into())?; let treasury_id = T::Control::org_treasury_account(&org_id).unwrap(); fund_account::(&treasury_id)?; @@ -94,7 +94,7 @@ benchmarks! { let now = frame_system::Pallet::::block_number(); let owner: T::AccountId = whitelisted_caller(); fund_account::(&owner)?; - let org_id = T::Control::create_org(owner.clone().into())?; + let org_id = T::ControlBenchmarkHelper::create_org(owner.clone().into())?; let treasury_id = T::Control::org_treasury_account(&org_id).unwrap(); fund_account::(&treasury_id)?; diff --git a/flow/src/lib.rs b/flow/src/lib.rs index 6a8390a2c..a8cc146b9 100644 --- a/flow/src/lib.rs +++ b/flow/src/lib.rs @@ -55,7 +55,9 @@ use scale_info::TypeInfo; use sp_runtime::{traits::{AtLeast32BitUnsigned, Hash}, Permill, ArithmeticError::Overflow}; use sp_std::{vec::Vec, convert::{TryFrom, TryInto}}; -use gamedao_traits::{ControlTrait, ControlBenchmarkingTrait, FlowTrait, FlowBenchmarkingTrait}; +#[cfg(feature = "runtime-benchmarks")] +use gamedao_traits::{ControlBenchmarkingTrait, FlowBenchmarkingTrait}; +use gamedao_traits::{ControlTrait, FlowTrait}; use orml_traits::{MultiCurrency, MultiReservableCurrency}; pub use pallet::*; @@ -109,8 +111,10 @@ pub mod pallet { type Currency: MultiCurrency + MultiReservableCurrency; - type Control: ControlTrait - + ControlBenchmarkingTrait; + type Control: ControlTrait; + + #[cfg(feature = "runtime-benchmarks")] + type ControlBenchmarkHelper: ControlBenchmarkingTrait; /// The GameDAO Treasury AccountId. #[pallet::constant] @@ -615,10 +619,9 @@ impl FlowTrait for Pallet { } } +#[cfg(feature = "runtime-benchmarks")] impl FlowBenchmarkingTrait for Pallet { - /// ** Should be used for benchmarking only!!! ** - #[cfg(feature = "runtime-benchmarks")] fn create_campaign(caller: &T::AccountId, org_id: &T::Hash, start: T::BlockNumber) -> Result { use sp_runtime::traits::Saturating; use sp_std::vec; @@ -654,8 +657,6 @@ impl FlowBenchmarkingTrait for Ok(campaign_id) } - /// ** Should be used for benchmarking only!!! ** - #[cfg(feature = "runtime-benchmarks")] fn create_contributions(campaign_id: &T::Hash, contributors: Vec) -> Result<(), DispatchError> { for account_id in BoundedVec::::truncate_from(contributors) { Pallet::::contribute( @@ -667,8 +668,6 @@ impl FlowBenchmarkingTrait for Ok(()) } - /// ** Should be used for benchmarking only!!! ** - #[cfg(feature = "runtime-benchmarks")] fn finalize_campaigns_by_block(block_number: T::BlockNumber) { use sp_runtime::traits::Saturating; frame_system::Pallet::::set_block_number(block_number); diff --git a/flow/src/mock.rs b/flow/src/mock.rs index 6a410a03e..63687ca32 100644 --- a/flow/src/mock.rs +++ b/flow/src/mock.rs @@ -179,6 +179,8 @@ impl gamedao_flow::Config for Test { type WeightInfo = (); type Currency = Currencies; type Control = Control; + #[cfg(feature = "runtime-benchmarks")] + type ControlBenchmarkHelper = Control; type GameDAOTreasury = GameDAOTreasury; type MinNameLength = MinNameLength; type MaxCampaignsPerBlock = MaxCampaignsPerBlock; diff --git a/flow/src/weights.rs b/flow/src/weights.rs index 65f6db6ad..eff3a6e9a 100644 --- a/flow/src/weights.rs +++ b/flow/src/weights.rs @@ -18,18 +18,18 @@ //! Autogenerated weights for gamedao_flow //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2022-08-12, STEPS: `20`, REPEAT: 10, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2023-02-06, STEPS: `20`, REPEAT: 10, LOW RANGE: `[]`, HIGH RANGE: `[]` //! EXECUTION: None, WASM-EXECUTION: Compiled, CHAIN: None, DB CACHE: 1024 // Executed Command: -// ./target/release/subzero +// ./target/release/subzero-dev // benchmark // pallet // --pallet=gamedao_flow // --extrinsic=* // --steps=20 // --repeat=10 -// --output=gamedao-protocol/flow/src/weights.rs +// --output=modules/gamedao-protocol/flow/src/weights.rs // --template=./.maintain/frame-weight-template.hbs #![cfg_attr(rustfmt, rustfmt_skip)] @@ -49,7 +49,7 @@ pub trait WeightInfo { /// Weights for gamedao_flow using the Substrate node and recommended hardware. pub struct SubstrateWeight(PhantomData); impl WeightInfo for SubstrateWeight { - // Storage: Control OrgController (r:1 w:0) + // Storage: Control Orgs (r:1 w:0) // Storage: Flow CampaignCount (r:1 w:1) // Storage: Flow CampaignsByBlock (r:2 w:2) // Storage: Control OrgTreasury (r:1 w:0) @@ -68,7 +68,7 @@ impl WeightInfo for SubstrateWeight { // Storage: Tokens Accounts (r:1 w:1) // Storage: Flow CampaignBalance (r:1 w:1) fn contribute() -> Weight { - (37_000_000 as Weight) + (36_000_000 as Weight) .saturating_add(T::DbWeight::get().reads(6 as Weight)) .saturating_add(T::DbWeight::get().writes(4 as Weight)) } @@ -80,11 +80,11 @@ impl WeightInfo for SubstrateWeight { // Storage: System Account (r:1 w:1) // Storage: Flow CampaignBalance (r:0 w:1) fn on_initialize(c: u32, p: u32, ) -> Weight { - (32_693_000 as Weight) - // Standard Error: 51_000 - .saturating_add((15_609_000 as Weight).saturating_mul(c as Weight)) - // Standard Error: 585_000 - .saturating_add((6_409_000 as Weight).saturating_mul(p as Weight)) + (28_545_000 as Weight) + // Standard Error: 39_000 + .saturating_add((14_636_000 as Weight).saturating_mul(c as Weight)) + // Standard Error: 393_000 + .saturating_add((6_443_000 as Weight).saturating_mul(p as Weight)) .saturating_add(T::DbWeight::get().reads(5 as Weight)) .saturating_add(T::DbWeight::get().reads((2 as Weight).saturating_mul(c as Weight))) .saturating_add(T::DbWeight::get().reads((1 as Weight).saturating_mul(p as Weight))) @@ -96,7 +96,7 @@ impl WeightInfo for SubstrateWeight { // For backwards compatibility and tests impl WeightInfo for () { - // Storage: Control OrgController (r:1 w:0) + // Storage: Control Orgs (r:1 w:0) // Storage: Flow CampaignCount (r:1 w:1) // Storage: Flow CampaignsByBlock (r:2 w:2) // Storage: Control OrgTreasury (r:1 w:0) @@ -115,7 +115,7 @@ impl WeightInfo for () { // Storage: Tokens Accounts (r:1 w:1) // Storage: Flow CampaignBalance (r:1 w:1) fn contribute() -> Weight { - (37_000_000 as Weight) + (36_000_000 as Weight) .saturating_add(RocksDbWeight::get().reads(6 as Weight)) .saturating_add(RocksDbWeight::get().writes(4 as Weight)) } @@ -127,11 +127,11 @@ impl WeightInfo for () { // Storage: System Account (r:1 w:1) // Storage: Flow CampaignBalance (r:0 w:1) fn on_initialize(c: u32, p: u32, ) -> Weight { - (32_693_000 as Weight) - // Standard Error: 51_000 - .saturating_add((15_609_000 as Weight).saturating_mul(c as Weight)) - // Standard Error: 585_000 - .saturating_add((6_409_000 as Weight).saturating_mul(p as Weight)) + (28_545_000 as Weight) + // Standard Error: 39_000 + .saturating_add((14_636_000 as Weight).saturating_mul(c as Weight)) + // Standard Error: 393_000 + .saturating_add((6_443_000 as Weight).saturating_mul(p as Weight)) .saturating_add(RocksDbWeight::get().reads(5 as Weight)) .saturating_add(RocksDbWeight::get().reads((2 as Weight).saturating_mul(c as Weight))) .saturating_add(RocksDbWeight::get().reads((1 as Weight).saturating_mul(p as Weight))) diff --git a/sense/Cargo.toml b/sense/Cargo.toml index dfe541f8f..b4321fab8 100755 --- a/sense/Cargo.toml +++ b/sense/Cargo.toml @@ -20,7 +20,7 @@ categories = [ ] [dependencies] -serde = { version = "1.0.143", optional = true } +serde = { version = "1.0.143", default-features = false } codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] } scale-info = { version = "2.1.1", default-features = false, features = ["derive"] } sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.28", default-features = false } @@ -30,9 +30,9 @@ frame-system = { git = "https://github.com/paritytech/substrate", branch = "polk frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.28", default-features = false, optional = true } [dev-dependencies] -sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.28" } -sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.28" } -sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.28" } +sp-io = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.28" } +sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.28" } +sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.28" } [features] default = ["std"] @@ -46,8 +46,6 @@ std = [ "frame-system/std", "frame-benchmarking/std", - "sp-core/std", "sp-std/std", - "sp-runtime/std", ] try-runtime = ["frame-support/try-runtime"] diff --git a/sense/src/benchmarking.rs b/sense/src/benchmarking.rs index 7aacf493b..cfe970ad0 100644 --- a/sense/src/benchmarking.rs +++ b/sense/src/benchmarking.rs @@ -16,6 +16,6 @@ benchmarks! { let property_type = PropertyType::Experience; Sense::::create_entity(caller_origin, account("1", 0, 0), BoundedVec::truncate_from(vec![1; 1]))?; }: _(RawOrigin::Root, account("1", 0, 0), property_type, 255) -} -impl_benchmark_test_suite!(Sense, crate::mock::new_test_ext(), crate::mock::Test); + impl_benchmark_test_suite!(Sense, crate::mock::new_test_ext(), crate::mock::Test); +} diff --git a/sense/src/weights.rs b/sense/src/weights.rs index 6483032ac..27867f665 100644 --- a/sense/src/weights.rs +++ b/sense/src/weights.rs @@ -18,18 +18,18 @@ //! Autogenerated weights for gamedao_sense //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2022-08-03, STEPS: `20`, REPEAT: 10, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2023-02-06, STEPS: `20`, REPEAT: 10, LOW RANGE: `[]`, HIGH RANGE: `[]` //! EXECUTION: None, WASM-EXECUTION: Compiled, CHAIN: None, DB CACHE: 1024 // Executed Command: -// ./target/release/subzero +// ./target/release/subzero-dev // benchmark // pallet // --pallet=gamedao_sense // --extrinsic=* // --steps=20 // --repeat=10 -// --output=gamedao-protocol/sense/src/weights.rs +// --output=modules/gamedao-protocol/sense/src/weights.rs // --template=./.maintain/frame-weight-template.hbs #![cfg_attr(rustfmt, rustfmt_skip)] @@ -52,7 +52,7 @@ impl WeightInfo for SubstrateWeight { // Storage: Sense EntityCount (r:1 w:1) // Storage: Sense Properties (r:0 w:3) fn create_entity() -> Weight { - (22_100_000 as Weight) + (20_000_000 as Weight) .saturating_add(T::DbWeight::get().reads(2 as Weight)) .saturating_add(T::DbWeight::get().writes(5 as Weight)) } @@ -71,7 +71,7 @@ impl WeightInfo for () { // Storage: Sense EntityCount (r:1 w:1) // Storage: Sense Properties (r:0 w:3) fn create_entity() -> Weight { - (22_100_000 as Weight) + (20_000_000 as Weight) .saturating_add(RocksDbWeight::get().reads(2 as Weight)) .saturating_add(RocksDbWeight::get().writes(5 as Weight)) } diff --git a/signal/Cargo.toml b/signal/Cargo.toml index 5cc29247b..cd103b6cd 100644 --- a/signal/Cargo.toml +++ b/signal/Cargo.toml @@ -21,7 +21,7 @@ categories = [ ] [dependencies] -serde = { version = "1.0.143", optional = true } +serde = { version = "1.0.143", default-features = false } codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] } scale-info = { version = "2.1.1", default-features = false, features = ["derive"] } sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.28", default-features = false } @@ -34,10 +34,9 @@ gamedao-traits = { package = "gamedao-traits", path = "../traits", default-featu sp-io = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.28", default-features=false } [dev-dependencies] -sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.28" } -sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.28" } +sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.28" } +sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.28" } -frame-support-test = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.28" } pallet-balances = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.28" } pallet-timestamp = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.28" } @@ -49,7 +48,12 @@ gamedao-flow = { path = "../flow", default-features = true } [features] default = ["std"] -runtime-benchmarks = ["frame-benchmarking"] +runtime-benchmarks = [ + "frame-benchmarking/runtime-benchmarks", + "gamedao-traits/runtime-benchmarks", + "gamedao-control/runtime-benchmarks", + "gamedao-flow/runtime-benchmarks" +] std = [ "codec/std", "serde/std", @@ -59,9 +63,7 @@ std = [ "frame-system/std", "frame-benchmarking/std", - "sp-core/std", "sp-std/std", - "sp-runtime/std", "orml-traits/std", "orml-tokens/std", diff --git a/signal/src/benchmarking.rs b/signal/src/benchmarking.rs index 507484b05..b4fcb7478 100644 --- a/signal/src/benchmarking.rs +++ b/signal/src/benchmarking.rs @@ -1,14 +1,14 @@ #![cfg(feature = "runtime-benchmarks")] +use super::*; +use crate::Pallet as Signal; + use frame_benchmarking::{account, benchmarks, impl_benchmark_test_suite, whitelisted_caller}; use frame_system::RawOrigin; use frame_support::{dispatch::DispatchError, traits::{Get, Hooks}, BoundedVec}; use sp_runtime::traits::SaturatedConversion; use sp_std::vec::Vec; -use crate::*; - - const SEED: u32 = 0; const DEPOSIT_AMOUNT: u128 = 10_000_000_000_000_000_000; @@ -28,26 +28,27 @@ fn fund_accounts(account_ids: &Vec) -> Result<(), Dispa } fn create_org_campaign(caller: T::AccountId, contributors_count: u32, members: Option>) -> Result<(T::Hash, T::Hash), DispatchError> { - let org_id = T::Control::create_org(caller.clone())?; + let org_id = T::ControlBenchmarkHelper::create_org(caller.clone())?; let treasury_account_id = T::Control::org_treasury_account(&org_id).unwrap(); fund_account::(&treasury_account_id)?; let now = frame_system::Pallet::::block_number(); - let campaign_id = T::Flow::create_campaign(&caller, &org_id, now)?; + let campaign_id = T::FlowBenchmarkHelper::create_campaign(&caller, &org_id, now)?; let contributors: Vec = (0..contributors_count).collect::>().iter() .map(|i| account("contributor", *i, SEED)).collect(); fund_accounts::(&contributors)?; - T::Flow::create_contributions(&campaign_id, contributors)?; + T::FlowBenchmarkHelper::create_contributions(&campaign_id, contributors)?; let current_block = frame_system::Pallet::::block_number(); - let mut expiry = current_block + 200_u32.into(); + let mut expiry = current_block + 57_600_u32.into(); for _ in 0 .. 10 { - T::Flow::finalize_campaigns_by_block(expiry); + + T::FlowBenchmarkHelper::finalize_campaigns_by_block(expiry); if T::Flow::is_campaign_succeeded(&campaign_id) { break; } expiry = expiry + 1_u32.into(); } if let Some(members) = members { - T::Control::fill_org_with_members(&org_id, members)?; + T::ControlBenchmarkHelper::fill_org_with_members(&org_id, members)?; } Ok((campaign_id, org_id)) } @@ -60,8 +61,9 @@ benchmarks! { fund_account::(&caller)?; let (campaign_id, org_id) = create_org_campaign::(caller.clone(), 10, None)?; let bounded_str = BoundedVec::truncate_from((0..255).collect()); + frame_system::Pallet::::set_block_number(3u32.into()); let start = frame_system::Pallet::::block_number(); - let expiry = frame_system::Pallet::::block_number() + 200_u32.into(); + let expiry = frame_system::Pallet::::block_number() + T::ProposalDurationLimits::get().0; let deposit = T::MinProposalDeposit::get(); let amount: T::Balance = 10_000u32.saturated_into(); let currency = T::PaymentTokenId::get(); @@ -102,8 +104,9 @@ benchmarks! { } let (campaign_id, org_id) = create_org_campaign::(proposer.clone(), 10, Some(members.clone()))?; let bounded_str: BoundedVec = BoundedVec::truncate_from((0..255).collect()); + frame_system::Pallet::::set_block_number(3u32.into()); let start = frame_system::Pallet::::block_number(); - let expiry = frame_system::Pallet::::block_number() + 200_u32.into(); + let expiry = frame_system::Pallet::::block_number() + T::ProposalDurationLimits::get().0; let deposit = T::MinProposalDeposit::get(); let amount: T::Balance = 10_000u32.saturated_into(); let currency_id = T::PaymentTokenId::get(); @@ -163,8 +166,9 @@ benchmarks! { fund_account::(&caller)?; let (campaign_id, org_id) = create_org_campaign::(caller.clone(), 10, None)?; let bounded_str: BoundedVec = BoundedVec::truncate_from((0..255).collect()); - let start = frame_system::Pallet::::block_number() + 10_u32.into(); - let expiry = frame_system::Pallet::::block_number() + 200_u32.into(); + frame_system::Pallet::::set_block_number(3u32.into()); + let start = frame_system::Pallet::::block_number(); + let expiry = frame_system::Pallet::::block_number() + T::ProposalDurationLimits::get().0; let deposit = T::MinProposalDeposit::get(); let amount: T::Balance = 10_000u32.saturated_into(); let currency_id = T::PaymentTokenId::get(); @@ -186,7 +190,7 @@ benchmarks! { prop.campaign_id, prop.amount, prop.beneficiary, prop.currency_id, )?; // Ensure that proposal exists and Activated - assert!(ProposalStates::::get(&proposal_id) == ProposalState::Created); + assert!(ProposalStates::::get(&proposal_id) == ProposalState::Active); } }: { Pallet::::on_initialize(start); } @@ -206,6 +210,6 @@ benchmarks! { } } - impl_benchmark_test_suite!(Signal, crate::tests::new_test_ext(), crate::tests::Test); + impl_benchmark_test_suite!(Signal, crate::mock::ExtBuilder::default().build(), crate::mock::Test); } diff --git a/signal/src/lib.rs b/signal/src/lib.rs index 4960cef8b..943deee44 100644 --- a/signal/src/lib.rs +++ b/signal/src/lib.rs @@ -39,7 +39,9 @@ use sp_runtime::{ }; use sp_std::vec; -use gamedao_traits::{ControlTrait, ControlBenchmarkingTrait, FlowTrait, FlowBenchmarkingTrait}; +#[cfg(feature = "runtime-benchmarks")] +use gamedao_traits::{ControlBenchmarkingTrait, FlowBenchmarkingTrait}; +use gamedao_traits::{ControlTrait, FlowTrait}; use types::{ ProposalIndex, ProposalType, ProposalState, SlashingRule, @@ -103,12 +105,16 @@ pub mod pallet { + MultiReservableCurrency; /// Control pallet's public interface. - type Control: ControlTrait - + ControlBenchmarkingTrait; + type Control: ControlTrait; /// Flow pallet's public interface. - type Flow: FlowTrait - + FlowBenchmarkingTrait; + type Flow: FlowTrait; + + #[cfg(feature = "runtime-benchmarks")] + type ControlBenchmarkHelper: ControlBenchmarkingTrait; + + #[cfg(feature = "runtime-benchmarks")] + type FlowBenchmarkHelper: FlowBenchmarkingTrait; /// Weight information for extrinsics in this module. type WeightInfo: WeightInfo; @@ -561,8 +567,6 @@ pub mod pallet { // For Absolute majority if more then 50% of members vote for one option, the proposal period ends earlier. if let Some(final_proposal_state) = Self::try_finalize_proposal(&voting) { Self::finalize_proposal(&proposal_id, final_proposal_state, &voting)?; - } else { - log::error!("Proposal finalization failed for proposal_id: {:?}.", proposal_id); } Ok(voting.participating as u32) diff --git a/signal/src/mock.rs b/signal/src/mock.rs index d54c4fd96..ea95b23ad 100644 --- a/signal/src/mock.rs +++ b/signal/src/mock.rs @@ -203,6 +203,8 @@ impl gamedao_flow::Config for Test { type WeightInfo = (); type Currency = Currencies; type Control = Control; + #[cfg(feature = "runtime-benchmarks")] + type ControlBenchmarkHelper = Control; type GameDAOTreasury = GameDAOTreasury; type MinNameLength = MinNameLength; type MaxCampaignsPerBlock = MaxCampaignsPerBlock; @@ -222,7 +224,7 @@ parameter_types! { pub const MinProposalDeposit: Balance = 10 * DOLLARS; pub SlashingMajority: Permill = Permill::from_rational(2u32, 3u32); pub GameDAOGetsFromSlashing: Permill = Permill::from_rational(1u32, 10u32); - pub const ProposalDurationLimits: (BlockNumber, BlockNumber) = (10, 100); + pub const ProposalDurationLimits: (BlockNumber, BlockNumber) = (100, 864000); } impl gamedao_signal::Config for Test { type Event = Event; @@ -231,6 +233,10 @@ impl gamedao_signal::Config for Test { type Currency = Currencies; type Control = Control; type Flow = Flow; + #[cfg(feature = "runtime-benchmarks")] + type ControlBenchmarkHelper = Control; + #[cfg(feature = "runtime-benchmarks")] + type FlowBenchmarkHelper = Flow; type WeightInfo = (); type ProtocolTokenId = ProtocolTokenId; type PaymentTokenId = PaymentTokenId; diff --git a/signal/src/tests.rs b/signal/src/tests.rs index 6cfe90047..f7ac637c9 100644 --- a/signal/src/tests.rs +++ b/signal/src/tests.rs @@ -3,7 +3,8 @@ use super::{ mock::{ BlockNumber, AccountId, Balance, Control, Event, ExtBuilder, Origin, Signal, System, Test, ALICE, BOB, CHARLIE, DOLLARS, DAYS, - PROTOCOL_TOKEN_ID, PAYMENT_TOKEN_ID, create_proposal, create_finalize_campaign, create_org, set_balance + PROTOCOL_TOKEN_ID, PAYMENT_TOKEN_ID, create_proposal, create_finalize_campaign, create_org, set_balance, + ProposalDurationLimits }, types::{ProposalType, ProposalState, Majority}, *, @@ -34,7 +35,7 @@ fn signal_0_0() { let campaign_id = create_finalize_campaign(now, org_id, &contributors, contribution, campaign_expiry, true); let start: BlockNumber = campaign_expiry + 1; - let expiry: BlockNumber = start + 10; + let expiry: BlockNumber = start + ProposalDurationLimits::get().0; let (_, proposal) = create_proposal( ProposalType::Withdrawal, org_id, start, expiry, 20 * DOLLARS, Some(campaign_id), Some(PAYMENT_TOKEN_ID), None, Some(10 * DOLLARS) @@ -181,7 +182,7 @@ fn signal_0_1() { let campaign_id = create_finalize_campaign(now, org_id, &contributors, contribution, campaign_expiry, true); let start: BlockNumber = campaign_expiry + 1; - let expiry: BlockNumber = start + 10; + let expiry: BlockNumber = start + ProposalDurationLimits::get().0; let (_, proposal) = create_proposal( ProposalType::Withdrawal, org_id, start, expiry, 20 * DOLLARS, Some(campaign_id), Some(PAYMENT_TOKEN_ID), None, Some(10 * DOLLARS) @@ -284,7 +285,7 @@ fn signal_0_2() { let now: BlockNumber = 3; System::set_block_number(now); let start: BlockNumber = now + 1; - let expiry: BlockNumber = now + 20; + let expiry: BlockNumber = now + 1 + ProposalDurationLimits::get().0; let (proposal_id, proposal) = create_proposal( ProposalType::General, org_id, start, expiry, 20 * DOLLARS, None, None, None, None); @@ -316,7 +317,7 @@ fn signal_0_2() { let campaign_expiry = start + 2 * DAYS; let campaign_id = create_finalize_campaign(start, org_id, &contributors, 50 * DOLLARS, campaign_expiry, true); let start: BlockNumber = campaign_expiry + 1; - let expiry: BlockNumber = start + 10; + let expiry: BlockNumber = start + ProposalDurationLimits::get().0; let (proposal_id, proposal) = create_proposal( ProposalType::Withdrawal, org_id, start, expiry, 20 * DOLLARS, Some(campaign_id), Some(PAYMENT_TOKEN_ID), None, Some(withdrawal_amount) @@ -385,7 +386,7 @@ fn signal_1_0() { let now: BlockNumber = 3; System::set_block_number(now); let start: BlockNumber = now + 1; - let expiry: BlockNumber = now + 20; + let expiry: BlockNumber = now + 1 + ProposalDurationLimits::get().0; let total_balance = 100 * DOLLARS - 1 * DOLLARS; // org creation fee let deposit = 20 * DOLLARS; let (proposal_id, proposal) = create_proposal( @@ -466,7 +467,7 @@ fn signal_1_1() { set_balance(&members, 100 * DOLLARS); let now: BlockNumber = 3; let start: BlockNumber = now; - let expiry: BlockNumber = now + 10; + let expiry: BlockNumber = now + ProposalDurationLimits::get().0; let total_balance = 100 * DOLLARS - 1 * DOLLARS; // org creation fee let deposit = 20 * DOLLARS; System::set_block_number(now); @@ -527,7 +528,7 @@ fn signal_1_2() { set_balance(&members, 100 * DOLLARS); let now: BlockNumber = 3; let start: BlockNumber = now; - let expiry: BlockNumber = now + 10; + let expiry: BlockNumber = now + ProposalDurationLimits::get().0; let total_balance = 100 * DOLLARS - 1 * DOLLARS; // org creation fee let deposit = 20 * DOLLARS; System::set_block_number(now); @@ -569,7 +570,7 @@ fn signal_1_3() { set_balance(&members, 100 * DOLLARS); let now: BlockNumber = 3; let start: BlockNumber = now; - let expiry: BlockNumber = now + 10; + let expiry: BlockNumber = now + ProposalDurationLimits::get().0; let total_balance = 100 * DOLLARS - 1 * DOLLARS; // org creation fee let deposit = 20 * DOLLARS; System::set_block_number(now); @@ -616,7 +617,7 @@ fn signal_1_4() { set_balance(&members, 100 * DOLLARS); let now: BlockNumber = 3; let start: BlockNumber = now; - let expiry: BlockNumber = now + 10; + let expiry: BlockNumber = now + ProposalDurationLimits::get().0; let total_balance = 100 * DOLLARS - 1 * DOLLARS; // org creation fee let deposit = 20 * DOLLARS; System::set_block_number(now); @@ -661,7 +662,7 @@ fn signal_1_5() { set_balance(&members, 100 * DOLLARS); let now: BlockNumber = 3; let start: BlockNumber = now; - let expiry: BlockNumber = now + 10; + let expiry: BlockNumber = now + ProposalDurationLimits::get().0; let total_balance = 100 * DOLLARS - 1 * DOLLARS; // org creation fee let deposit = 20 * DOLLARS; System::set_block_number(now); @@ -711,7 +712,7 @@ fn signal_1_6() { set_balance(&members, 100 * DOLLARS); let now: BlockNumber = 3; let start: BlockNumber = now; - let expiry: BlockNumber = now + 10; + let expiry: BlockNumber = now + ProposalDurationLimits::get().0; let total_balance = 100 * DOLLARS - 1 * DOLLARS; // org creation fee let deposit = 20 * DOLLARS; System::set_block_number(now); @@ -760,7 +761,7 @@ fn signal_1_7() { set_balance(&members, 100 * DOLLARS); let now: BlockNumber = 3; let start: BlockNumber = now; - let expiry: BlockNumber = now + 10; + let expiry: BlockNumber = now + ProposalDurationLimits::get().0; let total_balance = 100 * DOLLARS - 1 * DOLLARS; // org creation fee let deposit = 20 * DOLLARS; System::set_block_number(now); @@ -809,7 +810,7 @@ fn signal_1_8() { set_balance(&members, 100 * DOLLARS); let now: BlockNumber = 3; let start: BlockNumber = now; - let expiry: BlockNumber = now + 10; + let expiry: BlockNumber = now + ProposalDurationLimits::get().0; let total_balance = 100 * DOLLARS - 1 * DOLLARS; // org creation fee let deposit = 20 * DOLLARS; System::set_block_number(now); @@ -880,7 +881,7 @@ fn signal_2_0() { assert_eq!(::Currency::free_balance(currency, &treasury_id), 0); let start: BlockNumber = campaign_expiry + 1; - let expiry: BlockNumber = start + 20; + let expiry: BlockNumber = start + ProposalDurationLimits::get().0; let (proposal_id, proposal) = create_proposal( ProposalType::Withdrawal, org_id, start, expiry, deposit, Some(campaign_id), Some(currency), None, Some(withdrawal_amount) @@ -997,7 +998,7 @@ fn signal_2_1() { assert_eq!(::Currency::free_balance(currency, &treasury_id), 0); let start: BlockNumber = campaign_expiry + 1; - let expiry: BlockNumber = start + 20; + let expiry: BlockNumber = start + ProposalDurationLimits::get().0; let (proposal_id, proposal) = create_proposal( ProposalType::Withdrawal, org_id, start, expiry, deposit, Some(campaign_id), Some(currency), None, Some(withdrawal_amount) @@ -1102,7 +1103,7 @@ fn signal_2_2() { assert_eq!(::Currency::free_balance(currency, &treasury_id), 0); let start: BlockNumber = campaign_expiry + 1; - let expiry: BlockNumber = start + 20; + let expiry: BlockNumber = start + ProposalDurationLimits::get().0; let (proposal_id, proposal) = create_proposal( ProposalType::Withdrawal, org_id, start, expiry, deposit, Some(campaign_id), Some(currency), None, Some(withdrawal_amount) diff --git a/signal/src/weights.rs b/signal/src/weights.rs index 2ae7061c5..e56f4282b 100644 --- a/signal/src/weights.rs +++ b/signal/src/weights.rs @@ -18,18 +18,18 @@ //! Autogenerated weights for gamedao_signal //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2022-08-02, STEPS: `20`, REPEAT: 10, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2023-02-06, STEPS: `20`, REPEAT: 10, LOW RANGE: `[]`, HIGH RANGE: `[]` //! EXECUTION: None, WASM-EXECUTION: Compiled, CHAIN: None, DB CACHE: 1024 // Executed Command: -// ./target/release/subzero +// ./target/release/subzero-dev // benchmark // pallet // --pallet=gamedao_signal // --extrinsic=* // --steps=20 // --repeat=10 -// --output=gamedao-protocol/signal/src/weights.rs +// --output=modules/gamedao-protocol/signal/src/weights.rs // --template=./.maintain/frame-weight-template.hbs #![cfg_attr(rustfmt, rustfmt_skip)] @@ -49,12 +49,8 @@ pub trait WeightInfo { /// Weights for gamedao_signal using the Substrate node and recommended hardware. pub struct SubstrateWeight(PhantomData); impl WeightInfo for SubstrateWeight { - // Storage: Control OrgState (r:1 w:0) - // Storage: Control OrgMemberState (r:1 w:0) - // Storage: Flow CampaignOwner (r:1 w:0) - // Storage: Flow CampaignState (r:1 w:0) - // Storage: Signal CampaignBalanceUsed (r:1 w:0) - // Storage: Flow CampaignBalance (r:1 w:0) + // Storage: Control OrgStates (r:1 w:0) + // Storage: Control MemberStates (r:1 w:0) // Storage: Signal ProposalCount (r:1 w:1) // Storage: Signal ProposalOf (r:1 w:1) // Storage: Tokens Accounts (r:2 w:2) @@ -64,44 +60,39 @@ impl WeightInfo for SubstrateWeight { // Storage: Signal ProposalVoting (r:0 w:1) // Storage: Signal ProposalStates (r:0 w:1) fn proposal() -> Weight { - (76_000_000 as Weight) - .saturating_add(T::DbWeight::get().reads(14 as Weight)) + (65_000_000 as Weight) + .saturating_add(T::DbWeight::get().reads(10 as Weight)) .saturating_add(T::DbWeight::get().writes(8 as Weight)) } // Storage: Signal ProposalVoting (r:1 w:1) // Storage: Signal ProposalOf (r:1 w:0) - // Storage: Control OrgMemberState (r:1 w:0) + // Storage: Control MemberStates (r:1 w:0) // Storage: Signal ProposalStates (r:1 w:1) // Storage: Control OrgTreasury (r:1 w:0) // Storage: Tokens Accounts (r:4 w:4) // Storage: System Account (r:2 w:2) fn vote(m: u32, ) -> Weight { - (83_015_000 as Weight) + (80_488_000 as Weight) // Standard Error: 4_000 - .saturating_add((152_000 as Weight).saturating_mul(m as Weight)) + .saturating_add((127_000 as Weight).saturating_mul(m as Weight)) .saturating_add(T::DbWeight::get().reads(11 as Weight)) .saturating_add(T::DbWeight::get().writes(8 as Weight)) } // Storage: Signal ProposalsByBlock (r:1 w:0) - // Storage: Signal ProposalStates (r:5 w:5) + // Storage: Signal ProposalStates (r:5 w:0) fn on_initialize(p: u32, ) -> Weight { - (10_472_000 as Weight) - // Standard Error: 18_000 - .saturating_add((5_249_000 as Weight).saturating_mul(p as Weight)) + (401_000 as Weight) + // Standard Error: 9_000 + .saturating_add((3_147_000 as Weight).saturating_mul(p as Weight)) .saturating_add(T::DbWeight::get().reads(1 as Weight)) .saturating_add(T::DbWeight::get().reads((1 as Weight).saturating_mul(p as Weight))) - .saturating_add(T::DbWeight::get().writes((1 as Weight).saturating_mul(p as Weight))) } } // For backwards compatibility and tests impl WeightInfo for () { - // Storage: Control OrgState (r:1 w:0) - // Storage: Control OrgMemberState (r:1 w:0) - // Storage: Flow CampaignOwner (r:1 w:0) - // Storage: Flow CampaignState (r:1 w:0) - // Storage: Signal CampaignBalanceUsed (r:1 w:0) - // Storage: Flow CampaignBalance (r:1 w:0) + // Storage: Control OrgStates (r:1 w:0) + // Storage: Control MemberStates (r:1 w:0) // Storage: Signal ProposalCount (r:1 w:1) // Storage: Signal ProposalOf (r:1 w:1) // Storage: Tokens Accounts (r:2 w:2) @@ -111,32 +102,31 @@ impl WeightInfo for () { // Storage: Signal ProposalVoting (r:0 w:1) // Storage: Signal ProposalStates (r:0 w:1) fn proposal() -> Weight { - (76_000_000 as Weight) - .saturating_add(RocksDbWeight::get().reads(14 as Weight)) + (65_000_000 as Weight) + .saturating_add(RocksDbWeight::get().reads(10 as Weight)) .saturating_add(RocksDbWeight::get().writes(8 as Weight)) } // Storage: Signal ProposalVoting (r:1 w:1) // Storage: Signal ProposalOf (r:1 w:0) - // Storage: Control OrgMemberState (r:1 w:0) + // Storage: Control MemberStates (r:1 w:0) // Storage: Signal ProposalStates (r:1 w:1) // Storage: Control OrgTreasury (r:1 w:0) // Storage: Tokens Accounts (r:4 w:4) // Storage: System Account (r:2 w:2) fn vote(m: u32, ) -> Weight { - (83_015_000 as Weight) + (80_488_000 as Weight) // Standard Error: 4_000 - .saturating_add((152_000 as Weight).saturating_mul(m as Weight)) + .saturating_add((127_000 as Weight).saturating_mul(m as Weight)) .saturating_add(RocksDbWeight::get().reads(11 as Weight)) .saturating_add(RocksDbWeight::get().writes(8 as Weight)) } // Storage: Signal ProposalsByBlock (r:1 w:0) - // Storage: Signal ProposalStates (r:5 w:5) + // Storage: Signal ProposalStates (r:5 w:0) fn on_initialize(p: u32, ) -> Weight { - (10_472_000 as Weight) - // Standard Error: 18_000 - .saturating_add((5_249_000 as Weight).saturating_mul(p as Weight)) + (401_000 as Weight) + // Standard Error: 9_000 + .saturating_add((3_147_000 as Weight).saturating_mul(p as Weight)) .saturating_add(RocksDbWeight::get().reads(1 as Weight)) .saturating_add(RocksDbWeight::get().reads((1 as Weight).saturating_mul(p as Weight))) - .saturating_add(RocksDbWeight::get().writes((1 as Weight).saturating_mul(p as Weight))) } } diff --git a/traits/Cargo.toml b/traits/Cargo.toml index e8939267a..c8b1c319e 100644 --- a/traits/Cargo.toml +++ b/traits/Cargo.toml @@ -15,7 +15,7 @@ repository = "https://github.com/gamedaoco/gamedao-protocol" [dependencies] -serde = { version = "1.0.124", optional = true } +serde = { version = "1.0.124", default-features = false } codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] } scale-info = { version = "2.0.1", default-features = false, features = ["derive"] } frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.28", default-features = false } @@ -28,6 +28,7 @@ std = [ "codec/std", "serde/std", "scale-info/std", + "frame-benchmarking/std", "frame-support/std", "sp-std/std", ] diff --git a/traits/src/lib.rs b/traits/src/lib.rs index 9ee4daca9..0c2094421 100644 --- a/traits/src/lib.rs +++ b/traits/src/lib.rs @@ -28,17 +28,14 @@ pub trait ControlTrait { fn org_member_count(org_id: &Hash) -> u32; } +#[cfg(feature = "runtime-benchmarks")] pub trait ControlBenchmarkingTrait { /// Helper method to create organization. - /// ** Should be used for benchmarking only!!! ** - #[cfg(feature = "runtime-benchmarks")] fn create_org(caller: AccountId) -> Result; /// Helper method to add accounts to organisation. /// It is assumed those accounts have enough of currency to pay org joining fee. - /// ** Should be used for benchmarking only!!! ** - #[cfg(feature = "runtime-benchmarks")] fn fill_org_with_members(org_id: &Hash, members: Vec) -> Result<(), DispatchError>; } @@ -51,22 +48,16 @@ pub trait FlowTrait { fn campaign_owner(campaign_id: &Hash) -> Option; } -/// ** Should be used for benchmarking only!!! ** +#[cfg(feature = "runtime-benchmarks")] pub trait FlowBenchmarkingTrait { /// Helper method to create campaign - /// ** Should be used for benchmarking only!!! ** - #[cfg(feature = "runtime-benchmarks")] fn create_campaign(caller: &AccountId, org_id: &Hash, start: BlockNumber) -> Result; /// Helper method to fill campaign with contributions /// It is assumed those accounts have enought currency to contribute - /// ** Should be used for benchmarking only!!! ** - #[cfg(feature = "runtime-benchmarks")] fn create_contributions(campaign_id: &Hash, contributors: Vec) -> Result<(), DispatchError>; /// Trigger campaigns finalization by setting block number to specified value and calling appropriate hooks - /// ** Should be used for benchmarking only!!! ** - #[cfg(feature = "runtime-benchmarks")] fn finalize_campaigns_by_block(block_number: BlockNumber); } From 8e2e44669971364a613c731fba302dbd47467fe7 Mon Sep 17 00:00:00 2001 From: FiberMan Date: Mon, 13 Feb 2023 03:34:37 +0100 Subject: [PATCH 17/49] feat: bump substrate version from 0.9.28 to 0.9.36 --- battlepass/Cargo.toml | 36 +++---- battlepass/src/benchmarking.rs | 35 +++++- battlepass/src/lib.rs | 81 +++++++++----- battlepass/src/mock.rs | 48 +++++---- battlepass/src/tests.rs | 6 +- battlepass/src/types.rs | 8 +- battlepass/src/weights.rs | 189 +++++++++++++++++---------------- control/Cargo.toml | 30 +++--- control/src/lib.rs | 14 +-- control/src/mock.rs | 29 +++-- control/src/tests.rs | 14 +-- control/src/weights.rs | 151 +++++++++++++------------- flow/Cargo.toml | 24 ++--- flow/src/lib.rs | 6 +- flow/src/mock.rs | 21 ++-- flow/src/tests.rs | 8 +- flow/src/weights.rs | 101 +++++++++--------- sense/Cargo.toml | 16 +-- sense/src/benchmarking.rs | 2 +- sense/src/lib.rs | 8 +- sense/src/mock.rs | 10 +- sense/src/tests.rs | 2 +- sense/src/weights.rs | 51 ++++----- signal/Cargo.toml | 26 ++--- signal/src/lib.rs | 7 +- signal/src/mock.rs | 137 +++--------------------- signal/src/tests.rs | 113 ++++++++++++++++++-- signal/src/weights.rs | 93 ++++++++-------- traits/Cargo.toml | 6 +- 29 files changed, 658 insertions(+), 614 deletions(-) diff --git a/battlepass/Cargo.toml b/battlepass/Cargo.toml index 72c18b1b6..0a297b9c8 100644 --- a/battlepass/Cargo.toml +++ b/battlepass/Cargo.toml @@ -16,33 +16,33 @@ description = "BattlePass pallet provides functionality to create, manage and pa serde = { version = "1.0.143", default-features = false } codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] } scale-info = { version = "2.1.1", default-features = false, features = ["derive"] } -sp-core = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.28" } -sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.28" } -sp-std = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.28" } -sp-storage = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.28" } -sp-io = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.28", default-features=false } -frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.28", default-features = false } -frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.28", default-features = false } -frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.28", default-features = false, optional = true } +sp-core = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } +sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } +sp-std = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } +sp-storage = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } +sp-io = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.36", default-features=false } +frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36", default-features = false } +frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36", default-features = false } +frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36", default-features = false, optional = true } -pallet-uniques = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.28" } -pallet-rmrk-core = { git = "https://github.com/rmrk-team/rmrk-substrate", default-features = false, branch = "polkadot-v0.9.28" } -rmrk-traits = { git = "https://github.com/rmrk-team/rmrk-substrate", default-features = false, branch = "polkadot-v0.9.28" } +pallet-uniques = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } +pallet-rmrk-core = { git = "https://github.com/rmrk-team/rmrk-substrate", default-features = false, tag = "0.3.0" } +rmrk-traits = { git = "https://github.com/rmrk-team/rmrk-substrate", default-features = false, tag = "0.3.0" } -orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.28", default-features = false } +orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.36", default-features = false } gamedao-control = { package = "gamedao-control", path = "../control", default-features = false } gamedao-traits = { package = "gamedao-traits", path = "../traits", default-features = false } [dev-dependencies] -sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.28" } +sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.36" } codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] } -pallet-balances = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.28" } -pallet-uniques = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.28" } -orml-currencies = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.28", default-features = false } -orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.28", default-features = false } -orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.28", default-features = false } +pallet-balances = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } +pallet-uniques = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } +orml-currencies = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.36", default-features = false } +orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.36", default-features = false } +orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.36", default-features = false } [features] default = ['std'] diff --git a/battlepass/src/benchmarking.rs b/battlepass/src/benchmarking.rs index 545fa28fd..ee1a0eee3 100644 --- a/battlepass/src/benchmarking.rs +++ b/battlepass/src/benchmarking.rs @@ -92,6 +92,9 @@ benchmarks! { let org_id = get_org::(caller.clone()); let str = BoundedVec::truncate_from(vec![1,2]); }: _(RawOrigin::Signed(caller), org_id, str.clone(), str.clone(), 10) + verify { + assert!(BattlepassInfoByOrg::::get(org_id).is_some()); + } claim_battlepass { let caller: T::AccountId = get_funded_caller::()?; @@ -99,12 +102,18 @@ benchmarks! { let battlepass_id = get_battlepass::(caller.clone(), org_id); activate_bpass::(caller.clone(), battlepass_id); }: _(RawOrigin::Signed(caller.clone()), battlepass_id, caller.clone()) + verify { + assert!(ClaimedBattlepasses::::get(battlepass_id, caller).is_some()); + } activate_battlepass { let caller: T::AccountId = get_funded_caller::()?; let org_id = get_org::(caller.clone()); let battlepass_id = get_battlepass::(caller.clone(), org_id); }: _(RawOrigin::Signed(caller), battlepass_id) + verify { + assert!(BattlepassStates::::get(battlepass_id) == Some(BattlepassState::ACTIVE)); + } conclude_battlepass { let caller: T::AccountId = get_funded_caller::()?; @@ -112,6 +121,9 @@ benchmarks! { let battlepass_id = get_battlepass::(caller.clone(), org_id); activate_bpass::(caller.clone(), battlepass_id); }: _(RawOrigin::Signed(caller), battlepass_id) + verify { + assert!(BattlepassStates::::get(battlepass_id) == Some(BattlepassState::ENDED)); + } set_points { let caller: T::AccountId = get_funded_caller::()?; @@ -119,6 +131,9 @@ benchmarks! { let battlepass_id = get_battlepass::(caller.clone(), org_id); activate_bpass::(caller.clone(), battlepass_id); }: _(RawOrigin::Signed(caller.clone()), battlepass_id, caller.clone(), 10) + verify { + assert!(Points::::get(battlepass_id, caller) == 10); + } create_reward { let caller: T::AccountId = get_funded_caller::()?; @@ -127,6 +142,9 @@ benchmarks! { let str = BoundedVec::truncate_from(vec![1,2]); activate_bpass::(caller.clone(), battlepass_id); }: _(RawOrigin::Signed(caller), battlepass_id, str.clone(), str.clone(), Some(10), 1, false) + verify { + assert!(Rewards::::iter_keys().count() == 1); + } disable_reward { let caller: T::AccountId = get_funded_caller::()?; @@ -134,6 +152,9 @@ benchmarks! { let battlepass_id = get_battlepass::(caller.clone(), org_id); let reward_id = get_reward::(caller.clone(), battlepass_id); }: _(RawOrigin::Signed(caller), reward_id) + verify { + assert!(RewardStates::::get(reward_id) == Some(RewardState::INACTIVE)); + } claim_reward { let caller: T::AccountId = get_funded_caller::()?; @@ -144,13 +165,19 @@ benchmarks! { set_bpass_points::(caller.clone(), battlepass_id); set_bpass_level::(caller.clone(), battlepass_id); let reward_id = get_reward::(caller.clone(), battlepass_id); - }: _(RawOrigin::Signed(caller), reward_id) + }: _(RawOrigin::Signed(caller.clone()), reward_id) + verify { + assert!(ClaimedRewards::::get(reward_id, caller).is_some()); + } add_level { let caller: T::AccountId = get_funded_caller::()?; let org_id = get_org::(caller.clone()); let battlepass_id = get_battlepass::(caller.clone(), org_id); }: _(RawOrigin::Signed(caller.clone()), battlepass_id, 1, 10) + verify { + assert!(Levels::::get(battlepass_id, 1) == Some(10)); + } remove_level { let caller: T::AccountId = get_funded_caller::()?; @@ -158,12 +185,18 @@ benchmarks! { let battlepass_id = get_battlepass::(caller.clone(), org_id); set_bpass_level::(caller.clone(), battlepass_id); }: _(RawOrigin::Signed(caller.clone()), battlepass_id, 1) + verify { + assert!(Levels::::get(battlepass_id, 1) == None); + } add_bot { let caller: T::AccountId = get_funded_caller::()?; let org_id = get_org::(caller.clone()); let battlepass_id = get_battlepass::(caller.clone(), org_id); }: _(RawOrigin::Signed(caller.clone()), battlepass_id, caller.clone()) + verify { + assert!(BattlepassInfoByOrg::::get(org_id).unwrap().bot == Some(caller)); + } impl_benchmark_test_suite!(BPass, crate::mock::new_test_ext(), crate::mock::Test); } diff --git a/battlepass/src/lib.rs b/battlepass/src/lib.rs index 941795ab7..60617274a 100644 --- a/battlepass/src/lib.rs +++ b/battlepass/src/lib.rs @@ -21,7 +21,7 @@ use gamedao_traits::ControlTrait; #[cfg(feature = "runtime-benchmarks")] use gamedao_traits::ControlBenchmarkingTrait; use orml_traits::{MultiCurrency, MultiReservableCurrency}; -use rmrk_traits::{primitives::{PartId, NftId}, Collection, Nft, ResourceInfoMin, AccountIdOrCollectionNftTuple}; +use rmrk_traits::{primitives::PartId, Collection, Nft, ResourceInfoMin, AccountIdOrCollectionNftTuple}; pub mod types; pub use types::*; @@ -43,6 +43,22 @@ pub type Resource = BoundedVec< ::MaxResourcesOnMint, >; +pub trait BattlepassHelper { + fn collection(i: u32) -> CollectionId; + fn item(i: u32) -> ItemId; +} + +pub struct BpHelper; + +impl, ItemId: From> BattlepassHelper for BpHelper { + fn collection(i: u32) -> CollectionId { + i.into() + } + fn item(i: u32) -> ItemId { + i.into() + } +} + #[frame_support::pallet] pub mod pallet { use super::*; @@ -53,9 +69,9 @@ pub mod pallet { #[pallet::config] pub trait Config: frame_system::Config + pallet_rmrk_core::Config { - type Event: From> - + IsType<::Event> - + Into<::Event>; + type RuntimeEvent: From> + + IsType<::RuntimeEvent> + + Into<::RuntimeEvent>; /// The units in which we record balances. type Balance: Member @@ -84,8 +100,10 @@ pub mod pallet { #[cfg(feature = "runtime-benchmarks")] type ControlBenchmarkHelper: ControlBenchmarkingTrait; - type Rmrk: Collection, Symbol, Self::AccountId> - + Nft, Resource>; + type Rmrk: Collection, Symbol, Self::AccountId, Self::CollectionId> + + Nft, Resource, Self::CollectionId, Self::ItemId>; + + type BattlepassHelper: BattlepassHelper; /// The maximum length of a name, cid or metadata strings stored on-chain. #[pallet::constant] @@ -129,7 +147,7 @@ pub mod pallet { for_who: T::AccountId, org_id: T::Hash, battlepass_id: T::Hash, - nft_id: NftId + nft_id: T::ItemId }, /// BattlePass activated @@ -165,8 +183,8 @@ pub mod pallet { RewardClaimed { reward_id: T::Hash, claimer: T::AccountId, - collection_id: u32, - nft_id: NftId + collection_id: T::CollectionId, + nft_id: T::ItemId }, /// Reward state updated @@ -209,6 +227,7 @@ pub mod pallet { BattlepassNftInvalid, LevelNotReached, LevelUnknown, + NoAvailableCollectionId, NotMember, NotOwnNft, OrgPrimeUnknown, @@ -224,7 +243,7 @@ pub mod pallet { /// Battlepasses: map Hash => Battlepass #[pallet::storage] #[pallet::getter(fn get_battlepass)] - pub(super) type Battlepasses = StorageMap<_, Blake2_128Concat, T::Hash, Battlepass>, OptionQuery>; + pub(super) type Battlepasses = StorageMap<_, Blake2_128Concat, T::Hash, Battlepass, T::CollectionId>, OptionQuery>; /// Battlepass state. /// @@ -247,7 +266,7 @@ pub mod pallet { pub(super) type ClaimedBattlepasses = StorageDoubleMap<_, Blake2_128Concat, T::Hash, Blake2_128Concat, T::AccountId, - NftId, + T::ItemId, OptionQuery >; @@ -268,7 +287,7 @@ pub mod pallet { /// Rewards: map Hash => Reward #[pallet::storage] #[pallet::getter(fn get_reward)] - pub(super) type Rewards = StorageMap<_, Blake2_128Concat, T::Hash, Reward>, OptionQuery>; + pub(super) type Rewards = StorageMap<_, Blake2_128Concat, T::Hash, Reward, T::CollectionId>, OptionQuery>; /// Reward state by its id. /// @@ -285,7 +304,7 @@ pub mod pallet { pub(super) type ClaimedRewards = StorageDoubleMap<_, Blake2_128Concat, T::Hash, Blake2_128Concat, T::AccountId, - NftId, + T::ItemId, OptionQuery >; @@ -301,6 +320,10 @@ pub mod pallet { OptionQuery >; + #[pallet::storage] + #[pallet::getter(fn collection_index)] + pub type CollectionIndex = StorageValue<_, u32, ValueQuery>; + #[pallet::call] impl Pallet { @@ -641,10 +664,18 @@ impl Pallet { levels.count() == 1 } - fn create_collection(owner: T::AccountId, max: Option) -> Result { + fn create_collection(owner: T::AccountId, max: Option) -> Result { let metadata = BoundedVec::truncate_from(b"meta".to_vec()); // TODO: what should be here? let symbol = BoundedVec::truncate_from(b"symbol".to_vec()); // TODO: what should be here? - let collection_id = T::Rmrk::collection_create(owner, metadata, max, symbol)?; + let collection_index = CollectionIndex::::try_mutate(|n| -> Result { + let id = *n; + ensure!(id != u32::max_value(), Error::::NoAvailableCollectionId); + *n += 1; + Ok(id) + })?; + let collection_id = T::BattlepassHelper::collection(collection_index); + + T::Rmrk::collection_create(owner, collection_id, metadata, max, symbol)?; Ok(collection_id) } @@ -669,8 +700,8 @@ impl Pallet { } } - fn do_create_battlepass(creator: T::AccountId, org_id: T::Hash, name: String, cid: String, collection_id: u32, price: u16, new_season:u32) -> Result { - let battlepass: Battlepass> = Battlepass { + fn do_create_battlepass(creator: T::AccountId, org_id: T::Hash, name: String, cid: String, collection_id: T::CollectionId, price: u16, new_season:u32) -> Result { + let battlepass: Battlepass, T::CollectionId> = Battlepass { creator, org_id, name, @@ -688,12 +719,13 @@ impl Pallet { Ok(battlepass_id) } - fn do_claim_battlepass(by_who: T::AccountId, for_who: T::AccountId, battlepass_id: T::Hash, collection_id: u32) -> Result { - let nft_id = ClaimedBattlepasses::::iter_key_prefix(battlepass_id).count() as NftId; + fn do_claim_battlepass(by_who: T::AccountId, for_who: T::AccountId, battlepass_id: T::Hash, collection_id: T::CollectionId) -> Result { + let nft_count = ClaimedBattlepasses::::iter_key_prefix(battlepass_id).count() as u32; + let nft_id: T::ItemId = T::BattlepassHelper::item(nft_count); // Create Battlepass NFT let metadata = battlepass_id.encode(); - let (_, nft_id) = T::Rmrk::nft_mint( + let _ = T::Rmrk::nft_mint( by_who.clone(), // sender for_who.clone(), // owner nft_id, // nft_id @@ -726,7 +758,7 @@ impl Pallet { Ok(()) } - fn do_create_reward(battlepass_id: T::Hash, name: String, cid: String, level: u8, transferable: bool, collection_id: u32) -> Result { + fn do_create_reward(battlepass_id: T::Hash, name: String, cid: String, level: u8, transferable: bool, collection_id: T::CollectionId) -> Result { let reward = Reward{ battlepass_id, name, @@ -743,12 +775,13 @@ impl Pallet { Ok(reward_id) } - fn do_claim_reward(claimer: T::AccountId, reward_id: T::Hash, collection_id: u32, transferable: bool) -> Result { - let nft_id = ClaimedRewards::::iter_key_prefix(reward_id).count() as NftId; + fn do_claim_reward(claimer: T::AccountId, reward_id: T::Hash, collection_id: T::CollectionId, transferable: bool) -> Result { + let nft_count = ClaimedRewards::::iter_key_prefix(reward_id).count() as u32; + let nft_id = T::BattlepassHelper::item(nft_count); // Create Battlepass NFT let metadata = reward_id.encode(); - let (_, nft_id) = T::Rmrk::nft_mint( + let _ = T::Rmrk::nft_mint( claimer.clone(), // sender claimer.clone(), // owner nft_id, // nft_id diff --git a/battlepass/src/mock.rs b/battlepass/src/mock.rs index f67ef699d..d01b8cbcd 100644 --- a/battlepass/src/mock.rs +++ b/battlepass/src/mock.rs @@ -84,8 +84,8 @@ impl frame_system::Config for Test { type BlockWeights = (); type BlockLength = (); type DbWeight = (); - type Origin = Origin; - type Call = Call; + type RuntimeOrigin = RuntimeOrigin; + type RuntimeCall = RuntimeCall; type Index = u64; type BlockNumber = u64; type Hash = Hash; @@ -93,7 +93,7 @@ impl frame_system::Config for Test { type AccountId = AccountId; type Lookup = IdentityLookup; type Header = Header; - type Event = Event; + type RuntimeEvent = RuntimeEvent; type BlockHashCount = BlockHashCount; type Version = (); type PalletInfo = PalletInfo; @@ -117,19 +117,17 @@ parameter_types! { } impl orml_tokens::Config for Test { - type Event = Event; + type RuntimeEvent = RuntimeEvent; type Balance = Balance; type Amount = Amount; type CurrencyId = CurrencyId; type WeightInfo = (); type ExistentialDeposits = ExistentialDeposits; - type OnDust = (); + type CurrencyHooks = (); type MaxLocks = (); type MaxReserves = MaxReserves; - type OnNewTokenAccount = (); - type OnKilledTokenAccount = (); - type DustRemovalWhitelist = Nothing; type ReserveIdentifier = ReserveIdentifier; + type DustRemovalWhitelist = Nothing; } parameter_types! { @@ -139,7 +137,7 @@ parameter_types! { impl pallet_balances::Config for Test { type Balance = Balance; type DustRemoval = (); - type Event = Event; + type RuntimeEvent = RuntimeEvent; type ExistentialDeposit = ExistentialDeposit; type AccountStore = frame_system::Pallet; type MaxLocks = (); @@ -160,46 +158,53 @@ impl orml_currencies::Config for Test { parameter_types! { pub CollectionDeposit: Balance = 0; pub ItemDeposit: Balance = 0; + pub const KeyLimit: u32 = 32; // Max 32 bytes per key + pub const ValueLimit: u32 = 64; // Max 64 bytes per value pub MetadataDepositBase: Balance = 0; pub MetadataDepositPerByte: Balance = 0; } impl pallet_uniques::Config for Test { - type Event = Event; + type RuntimeEvent = RuntimeEvent; type CollectionId = u32; type ItemId = u32; type Currency = PalletBalances; - type ForceOrigin = frame_system::EnsureRoot; + type ForceOrigin = EnsureRoot; + type CreateOrigin = AsEnsureOriginWithArg>; + type Locker = pallet_rmrk_core::Pallet; type CollectionDeposit = CollectionDeposit; type ItemDeposit = ItemDeposit; type MetadataDepositBase = MetadataDepositBase; type AttributeDepositBase = MetadataDepositBase; type DepositPerByte = MetadataDepositPerByte; type StringLimit = StringLimit; - type KeyLimit = ConstU32<32>; - type ValueLimit = ConstU32<256>; + type KeyLimit = KeyLimit; + type ValueLimit = ValueLimit; type WeightInfo = (); - type CreateOrigin = AsEnsureOriginWithArg>; - type Locker = pallet_rmrk_core::Pallet; } parameter_types! { + pub const ResourceSymbolLimit: u32 = 10; pub const PartsLimit: u32 = 25; pub const CollectionSymbolLimit: u32 = 100; + pub const MaxPriorities: u32 = 25; + pub const NestingBudget: u32 = 3; pub const MaxResourcesOnMint: u32 = 100; pub const StringLimit: u32 = 64; } impl pallet_rmrk_core::Config for Test { - type Event = Event; + type RuntimeEvent = RuntimeEvent; type ProtocolOrigin = EnsureRoot; - type MaxRecursions = ConstU32<10>; - type ResourceSymbolLimit = ConstU32<10>; + type ResourceSymbolLimit = ResourceSymbolLimit; type PartsLimit = PartsLimit; - type MaxPriorities = ConstU32<25>; + type MaxPriorities = MaxPriorities; type CollectionSymbolLimit = CollectionSymbolLimit; type MaxResourcesOnMint = MaxResourcesOnMint; + type NestingBudget = NestingBudget; + type WeightInfo = pallet_rmrk_core::weights::SubstrateWeight; + type TransferHooks = (); } parameter_types! { @@ -214,7 +219,7 @@ impl gamedao_control::Config for Test { type Balance = Balance; type CurrencyId = CurrencyId; type WeightInfo = (); - type Event = Event; + type RuntimeEvent = RuntimeEvent; type Currency = Currencies; type MaxMembers = MaxMembers; type ProtocolTokenId = ProtocolTokenId; @@ -225,7 +230,7 @@ impl gamedao_control::Config for Test { } impl gamedao_battlepass::Config for Test { - type Event = Event; + type RuntimeEvent = RuntimeEvent; type Balance = Balance; type CurrencyId = CurrencyId; type Currency = Currencies; @@ -233,6 +238,7 @@ impl gamedao_battlepass::Config for Test { #[cfg(feature = "runtime-benchmarks")] type ControlBenchmarkHelper = Control; type Rmrk = RmrkCore; + type BattlepassHelper = gamedao_battlepass::BpHelper; type StringLimit = StringLimit; type SymbolLimit = CollectionSymbolLimit; type PartsLimit = PartsLimit; diff --git a/battlepass/src/tests.rs b/battlepass/src/tests.rs index 600ce6a7f..d301924ff 100644 --- a/battlepass/src/tests.rs +++ b/battlepass/src/tests.rs @@ -6,7 +6,7 @@ use rmrk_traits::AccountIdOrCollectionNftTuple; use sp_core::H256; use crate::mock::{ - new_test_ext, Origin, Test, + new_test_ext, RuntimeOrigin as Origin, Test, //System, Battlepass, Control, RmrkCore, ALICE, BOB, EVA, TOM, PROTOCOL_TOKEN_ID, PAYMENT_TOKEN_ID, DOLLARS, @@ -55,7 +55,7 @@ fn create_battlepass(org_id: H256) -> H256 { let creator = ALICE; let season = Battlepass::get_battlepass_info(&org_id).0 + 1; let price = 10; - let collection_id = pallet_rmrk_core::CollectionIndex::::get(); + let collection_id = CollectionIndex::::get(); assert_ok!( Battlepass::create_battlepass(Origin::signed(creator), org_id, string(), string(), price) @@ -766,7 +766,7 @@ fn claim_reward_test() { Battlepass::claim_battlepass(Origin::signed(not_creator), battlepass_id, not_creator) ); assert_ok!( - RmrkCore::burn_nft(Origin::signed(not_creator), 0, 0, 5) + RmrkCore::burn_nft(Origin::signed(not_creator), 0, 0) ); assert_noop!( Battlepass::claim_reward(Origin::signed(not_creator), reward_id), diff --git a/battlepass/src/types.rs b/battlepass/src/types.rs index cb3da881a..18789b437 100644 --- a/battlepass/src/types.rs +++ b/battlepass/src/types.rs @@ -17,14 +17,14 @@ impl Default for BattlepassState { /// Battlepass struct /// /// `collection_id`: Collection that will store all claimed Battlepass-NFTs -pub struct Battlepass { +pub struct Battlepass { pub creator: AccountId, pub org_id: Hash, pub name: BoundedString, pub cid: BoundedString, pub season: u32, pub price: u16, // TODO: introduce currency - pub collection_id: u32 + pub collection_id: CollectionId } #[derive(Encode, Decode, Default, Clone, PartialEq, Eq, TypeInfo, MaxEncodedLen)] @@ -41,13 +41,13 @@ pub struct BattlepassInfo { /// Reward struct /// /// `collection_id`: Collection that will store all claimed Reward-NFTs -pub struct Reward { +pub struct Reward { pub battlepass_id: Hash, pub name: BoundedString, pub cid: BoundedString, pub level: u8, pub transferable: bool, - pub collection_id: u32 + pub collection_id: CollectionId } #[derive(Encode, Decode, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, TypeInfo, MaxEncodedLen)] diff --git a/battlepass/src/weights.rs b/battlepass/src/weights.rs index a715c9c61..556cb6a55 100644 --- a/battlepass/src/weights.rs +++ b/battlepass/src/weights.rs @@ -1,30 +1,15 @@ -// This file is part of Substrate. - -// Copyright (C) 2021 Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. //! Autogenerated weights for gamedao_battlepass //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-02-06, STEPS: `20`, REPEAT: 10, LOW RANGE: `[]`, HIGH RANGE: `[]` -//! EXECUTION: None, WASM-EXECUTION: Compiled, CHAIN: None, DB CACHE: 1024 +//! DATE: 2023-02-10, STEPS: `20`, REPEAT: 10, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: None, DB CACHE: 1024 // Executed Command: // ./target/release/subzero-dev // benchmark // pallet +// --execution=wasm // --pallet=gamedao_battlepass // --extrinsic=* // --steps=20 @@ -60,17 +45,17 @@ impl WeightInfo for SubstrateWeight { // Storage: Control OrgStates (r:1 w:0) // Storage: Control Orgs (r:1 w:0) // Storage: Battlepass BattlepassInfoByOrg (r:1 w:1) - // Storage: RmrkCore CollectionIndex (r:1 w:1) + // Storage: Battlepass CollectionIndex (r:1 w:1) // Storage: Uniques Class (r:1 w:1) // Storage: RmrkCore Collections (r:0 w:1) // Storage: Uniques ClassAccount (r:0 w:1) - // Storage: Uniques NextCollectionId (r:0 w:1) // Storage: Battlepass BattlepassStates (r:0 w:1) // Storage: Battlepass Battlepasses (r:0 w:1) fn create_battlepass() -> Weight { - (44_000_000 as Weight) - .saturating_add(T::DbWeight::get().reads(5 as Weight)) - .saturating_add(T::DbWeight::get().writes(8 as Weight)) + // Minimum execution time: 68_000 nanoseconds. + Weight::from_ref_time(70_000_000) + .saturating_add(T::DbWeight::get().reads(5)) + .saturating_add(T::DbWeight::get().writes(7)) } // Storage: Battlepass Battlepasses (r:1 w:0) // Storage: Battlepass BattlepassStates (r:1 w:0) @@ -84,9 +69,10 @@ impl WeightInfo for SubstrateWeight { // Storage: Uniques CollectionMaxSupply (r:1 w:0) // Storage: Uniques Account (r:0 w:1) fn claim_battlepass() -> Weight { - (63_000_000 as Weight) - .saturating_add(T::DbWeight::get().reads(11 as Weight)) - .saturating_add(T::DbWeight::get().writes(6 as Weight)) + // Minimum execution time: 97_000 nanoseconds. + Weight::from_ref_time(99_000_000) + .saturating_add(T::DbWeight::get().reads(11)) + .saturating_add(T::DbWeight::get().writes(6)) } // Storage: Battlepass Battlepasses (r:1 w:0) // Storage: Battlepass BattlepassStates (r:1 w:1) @@ -94,18 +80,20 @@ impl WeightInfo for SubstrateWeight { // Storage: Control Orgs (r:1 w:0) // Storage: Battlepass BattlepassInfoByOrg (r:1 w:1) fn activate_battlepass() -> Weight { - (28_000_000 as Weight) - .saturating_add(T::DbWeight::get().reads(5 as Weight)) - .saturating_add(T::DbWeight::get().writes(2 as Weight)) + // Minimum execution time: 41_000 nanoseconds. + Weight::from_ref_time(42_000_000) + .saturating_add(T::DbWeight::get().reads(5)) + .saturating_add(T::DbWeight::get().writes(2)) } // Storage: Battlepass Battlepasses (r:1 w:0) // Storage: Battlepass BattlepassStates (r:1 w:1) // Storage: Control Orgs (r:1 w:0) // Storage: Battlepass BattlepassInfoByOrg (r:1 w:1) fn conclude_battlepass() -> Weight { - (27_000_000 as Weight) - .saturating_add(T::DbWeight::get().reads(4 as Weight)) - .saturating_add(T::DbWeight::get().writes(2 as Weight)) + // Minimum execution time: 39_000 nanoseconds. + Weight::from_ref_time(40_000_000) + .saturating_add(T::DbWeight::get().reads(4)) + .saturating_add(T::DbWeight::get().writes(2)) } // Storage: Battlepass Battlepasses (r:1 w:0) // Storage: Battlepass BattlepassStates (r:1 w:0) @@ -114,34 +102,36 @@ impl WeightInfo for SubstrateWeight { // Storage: Control MemberStates (r:1 w:0) // Storage: Battlepass Points (r:0 w:1) fn set_points() -> Weight { - (27_000_000 as Weight) - .saturating_add(T::DbWeight::get().reads(5 as Weight)) - .saturating_add(T::DbWeight::get().writes(1 as Weight)) + // Minimum execution time: 39_000 nanoseconds. + Weight::from_ref_time(40_000_000) + .saturating_add(T::DbWeight::get().reads(5)) + .saturating_add(T::DbWeight::get().writes(1)) } // Storage: Battlepass Battlepasses (r:1 w:0) // Storage: Battlepass BattlepassStates (r:1 w:0) // Storage: Control OrgStates (r:1 w:0) // Storage: Control Orgs (r:1 w:0) - // Storage: RmrkCore CollectionIndex (r:1 w:1) + // Storage: Battlepass CollectionIndex (r:1 w:1) // Storage: Uniques Class (r:1 w:1) // Storage: RmrkCore Collections (r:0 w:1) // Storage: Uniques ClassAccount (r:0 w:1) - // Storage: Uniques NextCollectionId (r:0 w:1) // Storage: Battlepass Rewards (r:0 w:1) // Storage: Battlepass RewardStates (r:0 w:1) fn create_reward() -> Weight { - (48_000_000 as Weight) - .saturating_add(T::DbWeight::get().reads(6 as Weight)) - .saturating_add(T::DbWeight::get().writes(7 as Weight)) + // Minimum execution time: 73_000 nanoseconds. + Weight::from_ref_time(76_000_000) + .saturating_add(T::DbWeight::get().reads(6)) + .saturating_add(T::DbWeight::get().writes(6)) } // Storage: Battlepass Rewards (r:1 w:0) // Storage: Battlepass RewardStates (r:1 w:1) // Storage: Battlepass Battlepasses (r:1 w:0) // Storage: Control Orgs (r:1 w:0) fn disable_reward() -> Weight { - (25_000_000 as Weight) - .saturating_add(T::DbWeight::get().reads(4 as Weight)) - .saturating_add(T::DbWeight::get().writes(1 as Weight)) + // Minimum execution time: 37_000 nanoseconds. + Weight::from_ref_time(39_000_000) + .saturating_add(T::DbWeight::get().reads(4)) + .saturating_add(T::DbWeight::get().writes(1)) } // Storage: Battlepass Rewards (r:1 w:0) // Storage: Battlepass RewardStates (r:1 w:0) @@ -160,9 +150,10 @@ impl WeightInfo for SubstrateWeight { // Storage: Uniques CollectionMaxSupply (r:1 w:0) // Storage: Uniques Account (r:0 w:1) fn claim_reward() -> Weight { - (95_000_000 as Weight) - .saturating_add(T::DbWeight::get().reads(18 as Weight)) - .saturating_add(T::DbWeight::get().writes(6 as Weight)) + // Minimum execution time: 130_000 nanoseconds. + Weight::from_ref_time(132_000_000) + .saturating_add(T::DbWeight::get().reads(18)) + .saturating_add(T::DbWeight::get().writes(6)) } // Storage: Battlepass Battlepasses (r:1 w:0) // Storage: Battlepass BattlepassStates (r:1 w:0) @@ -170,9 +161,10 @@ impl WeightInfo for SubstrateWeight { // Storage: Control Orgs (r:1 w:0) // Storage: Battlepass Levels (r:0 w:1) fn add_level() -> Weight { - (24_000_000 as Weight) - .saturating_add(T::DbWeight::get().reads(4 as Weight)) - .saturating_add(T::DbWeight::get().writes(1 as Weight)) + // Minimum execution time: 35_000 nanoseconds. + Weight::from_ref_time(36_000_000) + .saturating_add(T::DbWeight::get().reads(4)) + .saturating_add(T::DbWeight::get().writes(1)) } // Storage: Battlepass Battlepasses (r:1 w:0) // Storage: Battlepass BattlepassStates (r:1 w:0) @@ -180,9 +172,10 @@ impl WeightInfo for SubstrateWeight { // Storage: Control Orgs (r:1 w:0) // Storage: Battlepass Levels (r:1 w:1) fn remove_level() -> Weight { - (27_000_000 as Weight) - .saturating_add(T::DbWeight::get().reads(5 as Weight)) - .saturating_add(T::DbWeight::get().writes(1 as Weight)) + // Minimum execution time: 39_000 nanoseconds. + Weight::from_ref_time(41_000_000) + .saturating_add(T::DbWeight::get().reads(5)) + .saturating_add(T::DbWeight::get().writes(1)) } // Storage: Battlepass Battlepasses (r:1 w:0) // Storage: Battlepass BattlepassStates (r:1 w:0) @@ -190,9 +183,10 @@ impl WeightInfo for SubstrateWeight { // Storage: Control Orgs (r:1 w:0) // Storage: Battlepass BattlepassInfoByOrg (r:1 w:1) fn add_bot() -> Weight { - (26_000_000 as Weight) - .saturating_add(T::DbWeight::get().reads(5 as Weight)) - .saturating_add(T::DbWeight::get().writes(1 as Weight)) + // Minimum execution time: 38_000 nanoseconds. + Weight::from_ref_time(38_000_000) + .saturating_add(T::DbWeight::get().reads(5)) + .saturating_add(T::DbWeight::get().writes(1)) } } @@ -201,17 +195,17 @@ impl WeightInfo for () { // Storage: Control OrgStates (r:1 w:0) // Storage: Control Orgs (r:1 w:0) // Storage: Battlepass BattlepassInfoByOrg (r:1 w:1) - // Storage: RmrkCore CollectionIndex (r:1 w:1) + // Storage: Battlepass CollectionIndex (r:1 w:1) // Storage: Uniques Class (r:1 w:1) // Storage: RmrkCore Collections (r:0 w:1) // Storage: Uniques ClassAccount (r:0 w:1) - // Storage: Uniques NextCollectionId (r:0 w:1) // Storage: Battlepass BattlepassStates (r:0 w:1) // Storage: Battlepass Battlepasses (r:0 w:1) fn create_battlepass() -> Weight { - (44_000_000 as Weight) - .saturating_add(RocksDbWeight::get().reads(5 as Weight)) - .saturating_add(RocksDbWeight::get().writes(8 as Weight)) + // Minimum execution time: 68_000 nanoseconds. + Weight::from_ref_time(70_000_000) + .saturating_add(RocksDbWeight::get().reads(5)) + .saturating_add(RocksDbWeight::get().writes(7)) } // Storage: Battlepass Battlepasses (r:1 w:0) // Storage: Battlepass BattlepassStates (r:1 w:0) @@ -225,9 +219,10 @@ impl WeightInfo for () { // Storage: Uniques CollectionMaxSupply (r:1 w:0) // Storage: Uniques Account (r:0 w:1) fn claim_battlepass() -> Weight { - (63_000_000 as Weight) - .saturating_add(RocksDbWeight::get().reads(11 as Weight)) - .saturating_add(RocksDbWeight::get().writes(6 as Weight)) + // Minimum execution time: 97_000 nanoseconds. + Weight::from_ref_time(99_000_000) + .saturating_add(RocksDbWeight::get().reads(11)) + .saturating_add(RocksDbWeight::get().writes(6)) } // Storage: Battlepass Battlepasses (r:1 w:0) // Storage: Battlepass BattlepassStates (r:1 w:1) @@ -235,18 +230,20 @@ impl WeightInfo for () { // Storage: Control Orgs (r:1 w:0) // Storage: Battlepass BattlepassInfoByOrg (r:1 w:1) fn activate_battlepass() -> Weight { - (28_000_000 as Weight) - .saturating_add(RocksDbWeight::get().reads(5 as Weight)) - .saturating_add(RocksDbWeight::get().writes(2 as Weight)) + // Minimum execution time: 41_000 nanoseconds. + Weight::from_ref_time(42_000_000) + .saturating_add(RocksDbWeight::get().reads(5)) + .saturating_add(RocksDbWeight::get().writes(2)) } // Storage: Battlepass Battlepasses (r:1 w:0) // Storage: Battlepass BattlepassStates (r:1 w:1) // Storage: Control Orgs (r:1 w:0) // Storage: Battlepass BattlepassInfoByOrg (r:1 w:1) fn conclude_battlepass() -> Weight { - (27_000_000 as Weight) - .saturating_add(RocksDbWeight::get().reads(4 as Weight)) - .saturating_add(RocksDbWeight::get().writes(2 as Weight)) + // Minimum execution time: 39_000 nanoseconds. + Weight::from_ref_time(40_000_000) + .saturating_add(RocksDbWeight::get().reads(4)) + .saturating_add(RocksDbWeight::get().writes(2)) } // Storage: Battlepass Battlepasses (r:1 w:0) // Storage: Battlepass BattlepassStates (r:1 w:0) @@ -255,34 +252,36 @@ impl WeightInfo for () { // Storage: Control MemberStates (r:1 w:0) // Storage: Battlepass Points (r:0 w:1) fn set_points() -> Weight { - (27_000_000 as Weight) - .saturating_add(RocksDbWeight::get().reads(5 as Weight)) - .saturating_add(RocksDbWeight::get().writes(1 as Weight)) + // Minimum execution time: 39_000 nanoseconds. + Weight::from_ref_time(40_000_000) + .saturating_add(RocksDbWeight::get().reads(5)) + .saturating_add(RocksDbWeight::get().writes(1)) } // Storage: Battlepass Battlepasses (r:1 w:0) // Storage: Battlepass BattlepassStates (r:1 w:0) // Storage: Control OrgStates (r:1 w:0) // Storage: Control Orgs (r:1 w:0) - // Storage: RmrkCore CollectionIndex (r:1 w:1) + // Storage: Battlepass CollectionIndex (r:1 w:1) // Storage: Uniques Class (r:1 w:1) // Storage: RmrkCore Collections (r:0 w:1) // Storage: Uniques ClassAccount (r:0 w:1) - // Storage: Uniques NextCollectionId (r:0 w:1) // Storage: Battlepass Rewards (r:0 w:1) // Storage: Battlepass RewardStates (r:0 w:1) fn create_reward() -> Weight { - (48_000_000 as Weight) - .saturating_add(RocksDbWeight::get().reads(6 as Weight)) - .saturating_add(RocksDbWeight::get().writes(7 as Weight)) + // Minimum execution time: 73_000 nanoseconds. + Weight::from_ref_time(76_000_000) + .saturating_add(RocksDbWeight::get().reads(6)) + .saturating_add(RocksDbWeight::get().writes(6)) } // Storage: Battlepass Rewards (r:1 w:0) // Storage: Battlepass RewardStates (r:1 w:1) // Storage: Battlepass Battlepasses (r:1 w:0) // Storage: Control Orgs (r:1 w:0) fn disable_reward() -> Weight { - (25_000_000 as Weight) - .saturating_add(RocksDbWeight::get().reads(4 as Weight)) - .saturating_add(RocksDbWeight::get().writes(1 as Weight)) + // Minimum execution time: 37_000 nanoseconds. + Weight::from_ref_time(39_000_000) + .saturating_add(RocksDbWeight::get().reads(4)) + .saturating_add(RocksDbWeight::get().writes(1)) } // Storage: Battlepass Rewards (r:1 w:0) // Storage: Battlepass RewardStates (r:1 w:0) @@ -301,9 +300,10 @@ impl WeightInfo for () { // Storage: Uniques CollectionMaxSupply (r:1 w:0) // Storage: Uniques Account (r:0 w:1) fn claim_reward() -> Weight { - (95_000_000 as Weight) - .saturating_add(RocksDbWeight::get().reads(18 as Weight)) - .saturating_add(RocksDbWeight::get().writes(6 as Weight)) + // Minimum execution time: 130_000 nanoseconds. + Weight::from_ref_time(132_000_000) + .saturating_add(RocksDbWeight::get().reads(18)) + .saturating_add(RocksDbWeight::get().writes(6)) } // Storage: Battlepass Battlepasses (r:1 w:0) // Storage: Battlepass BattlepassStates (r:1 w:0) @@ -311,9 +311,10 @@ impl WeightInfo for () { // Storage: Control Orgs (r:1 w:0) // Storage: Battlepass Levels (r:0 w:1) fn add_level() -> Weight { - (24_000_000 as Weight) - .saturating_add(RocksDbWeight::get().reads(4 as Weight)) - .saturating_add(RocksDbWeight::get().writes(1 as Weight)) + // Minimum execution time: 35_000 nanoseconds. + Weight::from_ref_time(36_000_000) + .saturating_add(RocksDbWeight::get().reads(4)) + .saturating_add(RocksDbWeight::get().writes(1)) } // Storage: Battlepass Battlepasses (r:1 w:0) // Storage: Battlepass BattlepassStates (r:1 w:0) @@ -321,9 +322,10 @@ impl WeightInfo for () { // Storage: Control Orgs (r:1 w:0) // Storage: Battlepass Levels (r:1 w:1) fn remove_level() -> Weight { - (27_000_000 as Weight) - .saturating_add(RocksDbWeight::get().reads(5 as Weight)) - .saturating_add(RocksDbWeight::get().writes(1 as Weight)) + // Minimum execution time: 39_000 nanoseconds. + Weight::from_ref_time(41_000_000) + .saturating_add(RocksDbWeight::get().reads(5)) + .saturating_add(RocksDbWeight::get().writes(1)) } // Storage: Battlepass Battlepasses (r:1 w:0) // Storage: Battlepass BattlepassStates (r:1 w:0) @@ -331,8 +333,9 @@ impl WeightInfo for () { // Storage: Control Orgs (r:1 w:0) // Storage: Battlepass BattlepassInfoByOrg (r:1 w:1) fn add_bot() -> Weight { - (26_000_000 as Weight) - .saturating_add(RocksDbWeight::get().reads(5 as Weight)) - .saturating_add(RocksDbWeight::get().writes(1 as Weight)) + // Minimum execution time: 38_000 nanoseconds. + Weight::from_ref_time(38_000_000) + .saturating_add(RocksDbWeight::get().reads(5)) + .saturating_add(RocksDbWeight::get().writes(1)) } -} +} \ No newline at end of file diff --git a/control/Cargo.toml b/control/Cargo.toml index 0c1034cc2..b3132c03b 100755 --- a/control/Cargo.toml +++ b/control/Cargo.toml @@ -20,29 +20,29 @@ serde = { version = "1.0.143", default-features = false } codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] } scale-info = { version = "2.1.1", default-features = false, features = ["derive"] } -sp-core = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.28" } -sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.28" } -sp-std = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.28" } -sp-storage = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.28" } +sp-core = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } +sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } +sp-std = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } +sp-storage = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } -frame-support = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.28" } -frame-system = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.28" } -frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.28", default-features = false, optional = true } -sp-io = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.28", default-features=false } +frame-support = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } +frame-system = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } +frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36", default-features = false, optional = true } +sp-io = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.36", default-features=false } -pallet-balances = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.28" } +pallet-balances = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } -orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.28", default-features = false } +orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.36", default-features = false } gamedao-traits = { package = "gamedao-traits", path = "../traits", default-features = false } # tangram = { package = "module-tangram", path = "../../zero/tangram", default-features = false } [dev-dependencies] -sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.28" } -sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.28" } -pallet-balances = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.28" } -orml-currencies = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.28", default-features = false } -orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.28", default-features = false } +sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.36" } +sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.36" } +pallet-balances = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } +orml-currencies = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.36", default-features = false } +orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.36", default-features = false } [features] default = ["std"] diff --git a/control/src/lib.rs b/control/src/lib.rs index 7a9cc38cb..89a06ebaa 100644 --- a/control/src/lib.rs +++ b/control/src/lib.rs @@ -61,9 +61,9 @@ pub mod pallet { #[pallet::config] pub trait Config: frame_system::Config { - type Event: From> - + IsType<::Event> - + Into<::Event>; + type RuntimeEvent: From> + + IsType<::RuntimeEvent> + + Into<::RuntimeEvent>; /// The units in which we record balances. type Balance: Member @@ -667,7 +667,7 @@ impl Pallet { } fn ensure_membership_permissions( - origin: T::Origin, + origin: T::RuntimeOrigin, who: T::AccountId, prime: T::AccountId, org_type: OrgType, @@ -686,7 +686,7 @@ impl Pallet { } } - fn ensure_root_or_prime(origin: T::Origin, prime: T::AccountId, org_type: OrgType) -> Result<(), BadOrigin> { + fn ensure_root_or_prime(origin: T::RuntimeOrigin, prime: T::AccountId, _org_type: OrgType) -> Result<(), BadOrigin> { match origin.into() { Ok(RawOrigin::Root) => Ok(()), Ok(RawOrigin::Signed(t)) => { @@ -699,7 +699,7 @@ impl Pallet { } } - fn ensure_root_or_governance(origin: T::Origin) -> Result<(), BadOrigin> { + fn ensure_root_or_governance(origin: T::RuntimeOrigin) -> Result<(), BadOrigin> { match origin.into() { Ok(RawOrigin::Root) => Ok(()), // TODO: implement governance origin type @@ -707,7 +707,7 @@ impl Pallet { } } - fn ensure_root_or_self(origin: T::Origin, who: T::AccountId) -> Result<(), BadOrigin> { + fn ensure_root_or_self(origin: T::RuntimeOrigin, who: T::AccountId) -> Result<(), BadOrigin> { match origin.into() { Ok(RawOrigin::Root) => Ok(()), Ok(RawOrigin::Signed(t)) => { diff --git a/control/src/mock.rs b/control/src/mock.rs index c78d68a57..4d85abc65 100644 --- a/control/src/mock.rs +++ b/control/src/mock.rs @@ -1,7 +1,7 @@ #![cfg(test)] use crate as pallet_control; -use frame_support::{PalletId, {traits::GenesisBuild}, pallet_prelude::*}; +use frame_support::{PalletId, {traits::GenesisBuild}, pallet_prelude::*, traits::Nothing}; use frame_system; use codec::MaxEncodedLen; use sp_core::H256; @@ -64,8 +64,6 @@ frame_support::construct_runtime!( frame_support::parameter_types! { pub const BlockHashCount: u32 = 250; pub const SS58Prefix: u8 = 42; - pub BlockWeights: frame_system::limits::BlockWeights = - frame_system::limits::BlockWeights::simple_max(1024); } impl frame_system::Config for Test { @@ -73,8 +71,8 @@ impl frame_system::Config for Test { type BlockWeights = (); type BlockLength = (); type DbWeight = (); - type Origin = Origin; - type Call = Call; + type RuntimeOrigin = RuntimeOrigin; + type RuntimeCall = RuntimeCall; type Index = u64; type BlockNumber = u64; type Hash = Hash; @@ -82,7 +80,7 @@ impl frame_system::Config for Test { type AccountId = AccountId; type Lookup = IdentityLookup; type Header = Header; - type Event = Event; + type RuntimeEvent = RuntimeEvent; type BlockHashCount = BlockHashCount; type Version = (); type PalletInfo = PalletInfo; @@ -104,19 +102,17 @@ orml_traits::parameter_type_with_key! { }; } impl orml_tokens::Config for Test { - type Event = Event; + type RuntimeEvent = RuntimeEvent; type Balance = Balance; type Amount = Amount; type CurrencyId = CurrencyId; type WeightInfo = (); type ExistentialDeposits = ExistentialDeposits; - type OnDust = (); + type CurrencyHooks = (); type MaxLocks = (); - type DustRemovalWhitelist = frame_support::traits::Nothing; - type OnNewTokenAccount = (); - type OnKilledTokenAccount = (); - type ReserveIdentifier = ReserveIdentifier; type MaxReserves = MaxReserves; + type ReserveIdentifier = ReserveIdentifier; + type DustRemovalWhitelist = Nothing; } frame_support::parameter_types! { @@ -125,11 +121,11 @@ frame_support::parameter_types! { impl pallet_balances::Config for Test { type Balance = Balance; type DustRemoval = (); - type Event = Event; + type RuntimeEvent = RuntimeEvent; type ExistentialDeposit = ExistentialDeposit; type AccountStore = frame_system::Pallet; type MaxLocks = (); - type MaxReserves = MaxReserves; + type MaxReserves = (); type ReserveIdentifier = ReserveIdentifier; type WeightInfo = (); } @@ -146,14 +142,15 @@ frame_support::parameter_types! { pub const PaymentTokenId: CurrencyId = PAYMENT_TOKEN_ID; pub const MinimumDeposit: Balance = 5 * DOLLARS; pub const ControlPalletId: PalletId = PalletId(*b"gd/cntrl"); + pub const MaxMembers: u32 = 10000; } impl pallet_control::Config for Test { type Balance = Balance; type CurrencyId = CurrencyId; type WeightInfo = (); - type Event = Event; + type RuntimeEvent = RuntimeEvent; type Currency = Currencies; - type MaxMembers = ConstU32<10000>; + type MaxMembers = MaxMembers; type ProtocolTokenId = ProtocolTokenId; type PaymentTokenId = PaymentTokenId; type MinimumDeposit = MinimumDeposit; diff --git a/control/src/tests.rs b/control/src/tests.rs index eb5b92361..d32748ae0 100644 --- a/control/src/tests.rs +++ b/control/src/tests.rs @@ -1,10 +1,10 @@ #![cfg(test)] use frame_support::{assert_noop, assert_ok}; -use sp_runtime::traits::{BadOrigin}; +use sp_runtime::traits::BadOrigin; use sp_core::H256; use super::*; -use mock::{new_test_ext, System, Test, Event, Control, Origin, Tokens, CurrencyId, Balance, AccountId, +use mock::{new_test_ext, System, Test, RuntimeEvent as Event, Control, RuntimeOrigin as Origin, Tokens, CurrencyId, Balance, AccountId, ALICE, BOB, CHARLIE, PAYMENT_TOKEN_ID, PROTOCOL_TOKEN_ID, DOLLARS}; @@ -166,12 +166,12 @@ fn control_enable_deisable_org() { assert_noop!(Control::disable_org(Origin::signed(BOB), org_id), BadOrigin); assert_ok!(Control::disable_org(Origin::root(), org_id)); assert_eq!(OrgStates::::get(org_id), OrgState::Inactive); - System::assert_has_event(mock::Event::Control(crate::Event::OrgDisabled(org_id))); + System::assert_has_event(Event::Control(crate::Event::OrgDisabled(org_id))); // Enable org root assert_noop!(Control::enable_org(Origin::signed(BOB), org_id), BadOrigin); assert_ok!(Control::enable_org(Origin::root(), org_id)); assert_eq!(OrgStates::::get(org_id), OrgState::Active); - System::assert_has_event(mock::Event::Control(crate::Event::OrgEnabled(org_id))); + System::assert_has_event(Event::Control(crate::Event::OrgEnabled(org_id))); // Disable org prime assert_ok!(Control::disable_org(Origin::signed(ALICE), org_id)); assert_eq!(OrgStates::::get(org_id), OrgState::Inactive); @@ -193,7 +193,7 @@ fn control_add_remove_member_access_prime() { assert!(Members::::get(org_id).contains(&CHARLIE)); assert_noop!(Control::add_member(Origin::signed(ALICE), org_id, CHARLIE), Error::::AlreadyMember); System::assert_has_event( - mock::Event::Control(crate::Event::MemberAdded{ + Event::Control(crate::Event::MemberAdded{ org_id, who: CHARLIE, block_number: current_block }) ); @@ -203,7 +203,7 @@ fn control_add_remove_member_access_prime() { assert!(!Members::::get(org_id).contains(&CHARLIE)); assert_noop!(Control::remove_member(Origin::signed(ALICE), org_id, CHARLIE), Error::::NotMember); System::assert_has_event( - mock::Event::Control(crate::Event::MemberRemoved{ + Event::Control(crate::Event::MemberRemoved{ org_id, who: CHARLIE, block_number: current_block }) ); @@ -297,7 +297,7 @@ fn control_spend_funds() { Control::spend_funds(Origin::signed(BOB), org_id, PAYMENT_TOKEN_ID, beneficiary, amount), BadOrigin); System::assert_has_event( - mock::Event::Control(crate::Event::FundsSpended{ + Event::Control(crate::Event::FundsSpended{ org_id, beneficiary, amount, currency_id, block_number: current_block }) ); diff --git a/control/src/weights.rs b/control/src/weights.rs index 30744569e..c92926dea 100644 --- a/control/src/weights.rs +++ b/control/src/weights.rs @@ -1,30 +1,15 @@ -// This file is part of Substrate. - -// Copyright (C) 2021 Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. //! Autogenerated weights for gamedao_control //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-02-06, STEPS: `20`, REPEAT: 10, LOW RANGE: `[]`, HIGH RANGE: `[]` -//! EXECUTION: None, WASM-EXECUTION: Compiled, CHAIN: None, DB CACHE: 1024 +//! DATE: 2023-02-10, STEPS: `20`, REPEAT: 10, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: None, DB CACHE: 1024 // Executed Command: // ./target/release/subzero-dev // benchmark // pallet +// --execution=wasm // --pallet=gamedao_control // --extrinsic=* // --steps=20 @@ -64,68 +49,78 @@ impl WeightInfo for SubstrateWeight { // Storage: Control MemberStates (r:0 w:1) // Storage: Control OrgStates (r:0 w:1) fn create_org() -> Weight { - (50_000_000 as Weight) - .saturating_add(T::DbWeight::get().reads(6 as Weight)) - .saturating_add(T::DbWeight::get().writes(10 as Weight)) + // Minimum execution time: 79_000 nanoseconds. + Weight::from_ref_time(81_000_000) + .saturating_add(T::DbWeight::get().reads(6)) + .saturating_add(T::DbWeight::get().writes(10)) } // Storage: Control Orgs (r:1 w:1) // Storage: Control MemberStates (r:1 w:0) fn update_org() -> Weight { - (19_000_000 as Weight) - .saturating_add(T::DbWeight::get().reads(2 as Weight)) - .saturating_add(T::DbWeight::get().writes(1 as Weight)) + // Minimum execution time: 28_000 nanoseconds. + Weight::from_ref_time(29_000_000) + .saturating_add(T::DbWeight::get().reads(2)) + .saturating_add(T::DbWeight::get().writes(1)) } // Storage: Control Orgs (r:1 w:0) // Storage: Control OrgStates (r:0 w:1) fn disable_org() -> Weight { - (15_000_000 as Weight) - .saturating_add(T::DbWeight::get().reads(1 as Weight)) - .saturating_add(T::DbWeight::get().writes(1 as Weight)) + // Minimum execution time: 23_000 nanoseconds. + Weight::from_ref_time(24_000_000) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)) } // Storage: Control Orgs (r:1 w:0) // Storage: Control OrgStates (r:0 w:1) fn enable_org() -> Weight { - (15_000_000 as Weight) - .saturating_add(T::DbWeight::get().reads(1 as Weight)) - .saturating_add(T::DbWeight::get().writes(1 as Weight)) + // Minimum execution time: 24_000 nanoseconds. + Weight::from_ref_time(25_000_000) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)) } // Storage: Control Orgs (r:1 w:0) // Storage: Control OrgTreasury (r:1 w:0) // Storage: Control Members (r:1 w:1) // Storage: Control OrgMemberCount (r:0 w:1) // Storage: Control MemberStates (r:0 w:1) + /// The range of component `r` is `[1, 999]`. fn add_member(r: u32, ) -> Weight { - (19_798_000 as Weight) - // Standard Error: 1_000 - .saturating_add((45_000 as Weight).saturating_mul(r as Weight)) - .saturating_add(T::DbWeight::get().reads(3 as Weight)) - .saturating_add(T::DbWeight::get().writes(3 as Weight)) + // Minimum execution time: 36_000 nanoseconds. + Weight::from_ref_time(34_091_687) + // Standard Error: 1_851 + .saturating_add(Weight::from_ref_time(65_158).saturating_mul(r.into())) + .saturating_add(T::DbWeight::get().reads(3)) + .saturating_add(T::DbWeight::get().writes(3)) } // Storage: Control Orgs (r:1 w:0) // Storage: Control MemberStates (r:1 w:0) fn update_member_state() -> Weight { - (11_000_000 as Weight) - .saturating_add(T::DbWeight::get().reads(2 as Weight)) + // Minimum execution time: 15_000 nanoseconds. + Weight::from_ref_time(16_000_000) + .saturating_add(T::DbWeight::get().reads(2)) } // Storage: Control Orgs (r:1 w:0) // Storage: Control Members (r:1 w:1) // Storage: Control OrgMemberCount (r:0 w:1) // Storage: Control MemberStates (r:0 w:1) + /// The range of component `r` is `[1, 999]`. fn remove_member(r: u32, ) -> Weight { - (19_160_000 as Weight) - // Standard Error: 1_000 - .saturating_add((41_000 as Weight).saturating_mul(r as Weight)) - .saturating_add(T::DbWeight::get().reads(2 as Weight)) - .saturating_add(T::DbWeight::get().writes(3 as Weight)) + // Minimum execution time: 30_000 nanoseconds. + Weight::from_ref_time(37_544_684) + // Standard Error: 2_351 + .saturating_add(Weight::from_ref_time(43_383).saturating_mul(r.into())) + .saturating_add(T::DbWeight::get().reads(2)) + .saturating_add(T::DbWeight::get().writes(3)) } // Storage: Control Orgs (r:1 w:0) // Storage: Control OrgTreasury (r:1 w:0) // Storage: Tokens Accounts (r:2 w:2) // Storage: System Account (r:2 w:1) fn spend_funds() -> Weight { - (40_000_000 as Weight) - .saturating_add(T::DbWeight::get().reads(6 as Weight)) - .saturating_add(T::DbWeight::get().writes(3 as Weight)) + // Minimum execution time: 63_000 nanoseconds. + Weight::from_ref_time(64_000_000) + .saturating_add(T::DbWeight::get().reads(6)) + .saturating_add(T::DbWeight::get().writes(3)) } } @@ -141,67 +136,77 @@ impl WeightInfo for () { // Storage: Control MemberStates (r:0 w:1) // Storage: Control OrgStates (r:0 w:1) fn create_org() -> Weight { - (50_000_000 as Weight) - .saturating_add(RocksDbWeight::get().reads(6 as Weight)) - .saturating_add(RocksDbWeight::get().writes(10 as Weight)) + // Minimum execution time: 79_000 nanoseconds. + Weight::from_ref_time(81_000_000) + .saturating_add(RocksDbWeight::get().reads(6)) + .saturating_add(RocksDbWeight::get().writes(10)) } // Storage: Control Orgs (r:1 w:1) // Storage: Control MemberStates (r:1 w:0) fn update_org() -> Weight { - (19_000_000 as Weight) - .saturating_add(RocksDbWeight::get().reads(2 as Weight)) - .saturating_add(RocksDbWeight::get().writes(1 as Weight)) + // Minimum execution time: 28_000 nanoseconds. + Weight::from_ref_time(29_000_000) + .saturating_add(RocksDbWeight::get().reads(2)) + .saturating_add(RocksDbWeight::get().writes(1)) } // Storage: Control Orgs (r:1 w:0) // Storage: Control OrgStates (r:0 w:1) fn disable_org() -> Weight { - (15_000_000 as Weight) - .saturating_add(RocksDbWeight::get().reads(1 as Weight)) - .saturating_add(RocksDbWeight::get().writes(1 as Weight)) + // Minimum execution time: 23_000 nanoseconds. + Weight::from_ref_time(24_000_000) + .saturating_add(RocksDbWeight::get().reads(1)) + .saturating_add(RocksDbWeight::get().writes(1)) } // Storage: Control Orgs (r:1 w:0) // Storage: Control OrgStates (r:0 w:1) fn enable_org() -> Weight { - (15_000_000 as Weight) - .saturating_add(RocksDbWeight::get().reads(1 as Weight)) - .saturating_add(RocksDbWeight::get().writes(1 as Weight)) + // Minimum execution time: 24_000 nanoseconds. + Weight::from_ref_time(25_000_000) + .saturating_add(RocksDbWeight::get().reads(1)) + .saturating_add(RocksDbWeight::get().writes(1)) } // Storage: Control Orgs (r:1 w:0) // Storage: Control OrgTreasury (r:1 w:0) // Storage: Control Members (r:1 w:1) // Storage: Control OrgMemberCount (r:0 w:1) // Storage: Control MemberStates (r:0 w:1) + /// The range of component `r` is `[1, 999]`. fn add_member(r: u32, ) -> Weight { - (19_798_000 as Weight) - // Standard Error: 1_000 - .saturating_add((45_000 as Weight).saturating_mul(r as Weight)) - .saturating_add(RocksDbWeight::get().reads(3 as Weight)) - .saturating_add(RocksDbWeight::get().writes(3 as Weight)) + // Minimum execution time: 36_000 nanoseconds. + Weight::from_ref_time(34_091_687) + // Standard Error: 1_851 + .saturating_add(Weight::from_ref_time(65_158).saturating_mul(r.into())) + .saturating_add(RocksDbWeight::get().reads(3)) + .saturating_add(RocksDbWeight::get().writes(3)) } // Storage: Control Orgs (r:1 w:0) // Storage: Control MemberStates (r:1 w:0) fn update_member_state() -> Weight { - (11_000_000 as Weight) - .saturating_add(RocksDbWeight::get().reads(2 as Weight)) + // Minimum execution time: 15_000 nanoseconds. + Weight::from_ref_time(16_000_000) + .saturating_add(RocksDbWeight::get().reads(2)) } // Storage: Control Orgs (r:1 w:0) // Storage: Control Members (r:1 w:1) // Storage: Control OrgMemberCount (r:0 w:1) // Storage: Control MemberStates (r:0 w:1) + /// The range of component `r` is `[1, 999]`. fn remove_member(r: u32, ) -> Weight { - (19_160_000 as Weight) - // Standard Error: 1_000 - .saturating_add((41_000 as Weight).saturating_mul(r as Weight)) - .saturating_add(RocksDbWeight::get().reads(2 as Weight)) - .saturating_add(RocksDbWeight::get().writes(3 as Weight)) + // Minimum execution time: 30_000 nanoseconds. + Weight::from_ref_time(37_544_684) + // Standard Error: 2_351 + .saturating_add(Weight::from_ref_time(43_383).saturating_mul(r.into())) + .saturating_add(RocksDbWeight::get().reads(2)) + .saturating_add(RocksDbWeight::get().writes(3)) } // Storage: Control Orgs (r:1 w:0) // Storage: Control OrgTreasury (r:1 w:0) // Storage: Tokens Accounts (r:2 w:2) // Storage: System Account (r:2 w:1) fn spend_funds() -> Weight { - (40_000_000 as Weight) - .saturating_add(RocksDbWeight::get().reads(6 as Weight)) - .saturating_add(RocksDbWeight::get().writes(3 as Weight)) + // Minimum execution time: 63_000 nanoseconds. + Weight::from_ref_time(64_000_000) + .saturating_add(RocksDbWeight::get().reads(6)) + .saturating_add(RocksDbWeight::get().writes(3)) } -} +} \ No newline at end of file diff --git a/flow/Cargo.toml b/flow/Cargo.toml index 9925e74fa..bb918ccc0 100644 --- a/flow/Cargo.toml +++ b/flow/Cargo.toml @@ -17,25 +17,25 @@ repository = "https://github.com/gamedaoco/gamedao-protocol" serde = { version = "1.0.143", default-features = false } codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] } scale-info = { version = "2.1.1", default-features = false, features = ["derive"] } -sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.28", default-features = false } -sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.28", default-features = false } -frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.28", default-features = false } -frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.28", default-features = false } -frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.28", default-features = false, optional = true } -sp-io = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.28", default-features=false } +sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36", default-features = false } +sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36", default-features = false } +frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36", default-features = false } +frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36", default-features = false } +frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36", default-features = false, optional = true } +sp-io = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.36", default-features=false } -orml-currencies = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.28", default-features = false } -orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.28", default-features = false } -orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.28", default-features = false } +orml-currencies = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.36", default-features = false } +orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.36", default-features = false } +orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.36", default-features = false } gamedao-traits = { package = "gamedao-traits", path = "../traits", default-features = false } gamedao-control = { package = "gamedao-control", path = "../control", default-features = false } [dev-dependencies] -sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.28" } +sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.36" } -pallet-timestamp = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.28" } -pallet-balances = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.28" } +pallet-timestamp = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } +pallet-balances = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } gamedao-control = { package = "gamedao-control", path = "../control", default-features = true } diff --git a/flow/src/lib.rs b/flow/src/lib.rs index a8cc146b9..731428ee5 100644 --- a/flow/src/lib.rs +++ b/flow/src/lib.rs @@ -82,9 +82,9 @@ pub mod pallet { #[pallet::config] pub trait Config: frame_system::Config { - type Event: From> - + IsType<::Event> - + Into<::Event>; + type RuntimeEvent: From> + + IsType<::RuntimeEvent> + + Into<::RuntimeEvent>; /// The units in which we record balances. type Balance: Member diff --git a/flow/src/mock.rs b/flow/src/mock.rs index 63687ca32..0ab186cc7 100644 --- a/flow/src/mock.rs +++ b/flow/src/mock.rs @@ -1,6 +1,5 @@ #![cfg(test)] -use super::{FlowProtocol, FlowGovernance}; use sp_std::{vec, vec::Vec, convert::{TryFrom, TryInto}}; use frame_support::{ construct_runtime, parameter_types, PalletId, @@ -66,16 +65,16 @@ parameter_types! { } impl frame_system::Config for Test { - type Origin = Origin; + type RuntimeOrigin = RuntimeOrigin; type Index = u64; type BlockNumber = BlockNumber; - type Call = Call; + type RuntimeCall = RuntimeCall; type Hash = Hash; type Hashing = BlakeTwo256; type AccountId = AccountId; type Lookup = IdentityLookup; type Header = sp_runtime::testing::Header; - type Event = Event; + type RuntimeEvent = RuntimeEvent; type BlockHashCount = BlockHashCount; type BlockWeights = (); type BlockLength = (); @@ -102,19 +101,17 @@ parameter_types! { } impl orml_tokens::Config for Test { - type Event = Event; + type RuntimeEvent = RuntimeEvent; type Balance = Balance; type Amount = Amount; type CurrencyId = CurrencyId; type WeightInfo = (); type ExistentialDeposits = ExistentialDeposits; - type OnDust = (); + type CurrencyHooks = (); type MaxLocks = (); type MaxReserves = MaxReserves; - type OnNewTokenAccount = (); - type OnKilledTokenAccount = (); - type DustRemovalWhitelist = Nothing; type ReserveIdentifier = ReserveIdentifier; + type DustRemovalWhitelist = Nothing; } parameter_types! { @@ -124,7 +121,7 @@ parameter_types! { impl pallet_balances::Config for Test { type Balance = Balance; type DustRemoval = (); - type Event = Event; + type RuntimeEvent = RuntimeEvent; type ExistentialDeposit = ExistentialDeposit; type AccountStore = frame_system::Pallet; type MaxLocks = (); @@ -151,7 +148,7 @@ impl gamedao_control::Config for Test { type Balance = Balance; type CurrencyId = CurrencyId; type WeightInfo = (); - type Event = Event; + type RuntimeEvent = RuntimeEvent; type Currency = Currencies; type MaxMembers = ConstU32<10000>; type ProtocolTokenId = ProtocolTokenId; @@ -173,7 +170,7 @@ parameter_types! { } impl gamedao_flow::Config for Test { - type Event = Event; + type RuntimeEvent = RuntimeEvent; type Balance = Balance; type CurrencyId = CurrencyId; type WeightInfo = (); diff --git a/flow/src/tests.rs b/flow/src/tests.rs index bb7cfabd4..d417e52ce 100644 --- a/flow/src/tests.rs +++ b/flow/src/tests.rs @@ -4,14 +4,14 @@ use frame_support::traits::Hooks; use frame_support::{assert_noop, assert_ok}; use frame_system::RawOrigin; use sp_core::H256; -use sp_runtime::traits::{Hash, AccountIdConversion}; +use sp_runtime::traits::Hash; use gamedao_control::types::{AccessModel, FeeModel, OrgType, Org}; use super::{ types::{FlowProtocol, FlowGovernance}, mock::{ - BlockNumber, AccountId, Balance, Control, Event, Tokens, INIT_BALANCE, - Flow, Origin, System, Test, ALICE, BOB, DOLLARS, DAYS, new_test_ext, + BlockNumber, AccountId, Balance, Control, RuntimeEvent as Event, Tokens, INIT_BALANCE, + Flow, RuntimeOrigin as Origin, System, Test, ALICE, BOB, DOLLARS, DAYS, new_test_ext, PROTOCOL_TOKEN_ID, PAYMENT_TOKEN_ID, CampaignDurationLimits, MaxContributorsProcessing, }, * @@ -152,7 +152,7 @@ fn flow_create_errors() { ); // Ensure campaign expires before expiration limit // Error: OutOfBounds - let (min_duration, max_duration) = CampaignDurationLimits::get(); + let (_min_duration, max_duration) = CampaignDurationLimits::get(); let expiration_block = max_duration + now + 1; assert_noop!( Flow::create_campaign( diff --git a/flow/src/weights.rs b/flow/src/weights.rs index eff3a6e9a..f18793861 100644 --- a/flow/src/weights.rs +++ b/flow/src/weights.rs @@ -1,30 +1,15 @@ -// This file is part of Substrate. - -// Copyright (C) 2021 Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. //! Autogenerated weights for gamedao_flow //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-02-06, STEPS: `20`, REPEAT: 10, LOW RANGE: `[]`, HIGH RANGE: `[]` -//! EXECUTION: None, WASM-EXECUTION: Compiled, CHAIN: None, DB CACHE: 1024 +//! DATE: 2023-02-10, STEPS: `20`, REPEAT: 10, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: None, DB CACHE: 1024 // Executed Command: // ./target/release/subzero-dev // benchmark // pallet +// --execution=wasm // --pallet=gamedao_flow // --extrinsic=* // --steps=20 @@ -57,9 +42,10 @@ impl WeightInfo for SubstrateWeight { // Storage: Flow CampaignOf (r:0 w:1) // Storage: Flow CampaignStates (r:0 w:1) fn create_campaign() -> Weight { - (41_000_000 as Weight) - .saturating_add(T::DbWeight::get().reads(6 as Weight)) - .saturating_add(T::DbWeight::get().writes(6 as Weight)) + // Minimum execution time: 64_000 nanoseconds. + Weight::from_ref_time(67_000_000) + .saturating_add(T::DbWeight::get().reads(6)) + .saturating_add(T::DbWeight::get().writes(6)) } // Storage: Flow CampaignOf (r:1 w:0) // Storage: Flow CampaignStates (r:1 w:0) @@ -68,9 +54,10 @@ impl WeightInfo for SubstrateWeight { // Storage: Tokens Accounts (r:1 w:1) // Storage: Flow CampaignBalance (r:1 w:1) fn contribute() -> Weight { - (36_000_000 as Weight) - .saturating_add(T::DbWeight::get().reads(6 as Weight)) - .saturating_add(T::DbWeight::get().writes(4 as Weight)) + // Minimum execution time: 56_000 nanoseconds. + Weight::from_ref_time(58_000_000) + .saturating_add(T::DbWeight::get().reads(6)) + .saturating_add(T::DbWeight::get().writes(4)) } // Storage: Flow CampaignsByBlock (r:1 w:0) // Storage: Flow CampaignStates (r:10 w:11) @@ -79,18 +66,21 @@ impl WeightInfo for SubstrateWeight { // Storage: Flow CampaignContribution (r:5 w:0) // Storage: System Account (r:1 w:1) // Storage: Flow CampaignBalance (r:0 w:1) + /// The range of component `c` is `[0, 100]`. + /// The range of component `p` is `[0, 10]`. fn on_initialize(c: u32, p: u32, ) -> Weight { - (28_545_000 as Weight) - // Standard Error: 39_000 - .saturating_add((14_636_000 as Weight).saturating_mul(c as Weight)) - // Standard Error: 393_000 - .saturating_add((6_443_000 as Weight).saturating_mul(p as Weight)) - .saturating_add(T::DbWeight::get().reads(5 as Weight)) - .saturating_add(T::DbWeight::get().reads((2 as Weight).saturating_mul(c as Weight))) - .saturating_add(T::DbWeight::get().reads((1 as Weight).saturating_mul(p as Weight))) - .saturating_add(T::DbWeight::get().writes(5 as Weight)) - .saturating_add(T::DbWeight::get().writes((1 as Weight).saturating_mul(c as Weight))) - .saturating_add(T::DbWeight::get().writes((1 as Weight).saturating_mul(p as Weight))) + // Minimum execution time: 134_000 nanoseconds. + Weight::from_ref_time(68_040_945) + // Standard Error: 55_163 + .saturating_add(Weight::from_ref_time(25_455_935).saturating_mul(c.into())) + // Standard Error: 551_554 + .saturating_add(Weight::from_ref_time(9_852_261).saturating_mul(p.into())) + .saturating_add(T::DbWeight::get().reads(5)) + .saturating_add(T::DbWeight::get().reads((2_u64).saturating_mul(c.into()))) + .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(p.into()))) + .saturating_add(T::DbWeight::get().writes(5)) + .saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(c.into()))) + .saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(p.into()))) } } @@ -104,9 +94,10 @@ impl WeightInfo for () { // Storage: Flow CampaignOf (r:0 w:1) // Storage: Flow CampaignStates (r:0 w:1) fn create_campaign() -> Weight { - (41_000_000 as Weight) - .saturating_add(RocksDbWeight::get().reads(6 as Weight)) - .saturating_add(RocksDbWeight::get().writes(6 as Weight)) + // Minimum execution time: 64_000 nanoseconds. + Weight::from_ref_time(67_000_000) + .saturating_add(RocksDbWeight::get().reads(6)) + .saturating_add(RocksDbWeight::get().writes(6)) } // Storage: Flow CampaignOf (r:1 w:0) // Storage: Flow CampaignStates (r:1 w:0) @@ -115,9 +106,10 @@ impl WeightInfo for () { // Storage: Tokens Accounts (r:1 w:1) // Storage: Flow CampaignBalance (r:1 w:1) fn contribute() -> Weight { - (36_000_000 as Weight) - .saturating_add(RocksDbWeight::get().reads(6 as Weight)) - .saturating_add(RocksDbWeight::get().writes(4 as Weight)) + // Minimum execution time: 56_000 nanoseconds. + Weight::from_ref_time(58_000_000) + .saturating_add(RocksDbWeight::get().reads(6)) + .saturating_add(RocksDbWeight::get().writes(4)) } // Storage: Flow CampaignsByBlock (r:1 w:0) // Storage: Flow CampaignStates (r:10 w:11) @@ -126,17 +118,20 @@ impl WeightInfo for () { // Storage: Flow CampaignContribution (r:5 w:0) // Storage: System Account (r:1 w:1) // Storage: Flow CampaignBalance (r:0 w:1) + /// The range of component `c` is `[0, 100]`. + /// The range of component `p` is `[0, 10]`. fn on_initialize(c: u32, p: u32, ) -> Weight { - (28_545_000 as Weight) - // Standard Error: 39_000 - .saturating_add((14_636_000 as Weight).saturating_mul(c as Weight)) - // Standard Error: 393_000 - .saturating_add((6_443_000 as Weight).saturating_mul(p as Weight)) - .saturating_add(RocksDbWeight::get().reads(5 as Weight)) - .saturating_add(RocksDbWeight::get().reads((2 as Weight).saturating_mul(c as Weight))) - .saturating_add(RocksDbWeight::get().reads((1 as Weight).saturating_mul(p as Weight))) - .saturating_add(RocksDbWeight::get().writes(5 as Weight)) - .saturating_add(RocksDbWeight::get().writes((1 as Weight).saturating_mul(c as Weight))) - .saturating_add(RocksDbWeight::get().writes((1 as Weight).saturating_mul(p as Weight))) + // Minimum execution time: 134_000 nanoseconds. + Weight::from_ref_time(68_040_945) + // Standard Error: 55_163 + .saturating_add(Weight::from_ref_time(25_455_935).saturating_mul(c.into())) + // Standard Error: 551_554 + .saturating_add(Weight::from_ref_time(9_852_261).saturating_mul(p.into())) + .saturating_add(RocksDbWeight::get().reads(5)) + .saturating_add(RocksDbWeight::get().reads((2_u64).saturating_mul(c.into()))) + .saturating_add(RocksDbWeight::get().reads((1_u64).saturating_mul(p.into()))) + .saturating_add(RocksDbWeight::get().writes(5)) + .saturating_add(RocksDbWeight::get().writes((1_u64).saturating_mul(c.into()))) + .saturating_add(RocksDbWeight::get().writes((1_u64).saturating_mul(p.into()))) } -} +} \ No newline at end of file diff --git a/sense/Cargo.toml b/sense/Cargo.toml index b4321fab8..0da91af93 100755 --- a/sense/Cargo.toml +++ b/sense/Cargo.toml @@ -23,16 +23,16 @@ categories = [ serde = { version = "1.0.143", default-features = false } codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] } scale-info = { version = "2.1.1", default-features = false, features = ["derive"] } -sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.28", default-features = false } -sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.28", default-features = false } -frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.28", default-features = false } -frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.28", default-features = false } -frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.28", default-features = false, optional = true } +sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36", default-features = false } +sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36", default-features = false } +frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36", default-features = false } +frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36", default-features = false } +frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36", default-features = false, optional = true } [dev-dependencies] -sp-io = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.28" } -sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.28" } -sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.28" } +sp-io = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.36" } +sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.36" } +sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.36" } [features] default = ["std"] diff --git a/sense/src/benchmarking.rs b/sense/src/benchmarking.rs index cfe970ad0..dc3fedcba 100644 --- a/sense/src/benchmarking.rs +++ b/sense/src/benchmarking.rs @@ -12,7 +12,7 @@ benchmarks! { create_entity {}: _(RawOrigin::Root, account("1", 0, 0), BoundedVec::truncate_from(vec![1; 256])) update_property { - let caller_origin = ::Origin::from(RawOrigin::Root); + let caller_origin = ::RuntimeOrigin::from(RawOrigin::Root); let property_type = PropertyType::Experience; Sense::::create_entity(caller_origin, account("1", 0, 0), BoundedVec::truncate_from(vec![1; 1]))?; }: _(RawOrigin::Root, account("1", 0, 0), property_type, 255) diff --git a/sense/src/lib.rs b/sense/src/lib.rs index b7493416a..0c8458175 100644 --- a/sense/src/lib.rs +++ b/sense/src/lib.rs @@ -33,9 +33,9 @@ pub mod pallet { #[pallet::config] pub trait Config: frame_system::Config { - type Event: From> - + IsType<::Event> - + Into<::Event>; + type RuntimeEvent: From> + + IsType<::RuntimeEvent> + + Into<::RuntimeEvent>; type WeightInfo: WeightInfo; /// The maximum length of a name or symbol stored on-chain. @@ -122,6 +122,7 @@ pub mod pallet { /// Emits `EntityCreated` event when successful. /// /// Weight: `O(1)` + #[pallet::call_index(0)] #[pallet::weight(::WeightInfo::create_entity())] pub fn create_entity( origin: OriginFor, @@ -160,6 +161,7 @@ pub mod pallet { /// Emits `PropertyUpdated` event when successful. /// /// Weight: `O(1)` + #[pallet::call_index(1)] #[pallet::weight(::WeightInfo::update_property())] pub fn update_property( origin: OriginFor, diff --git a/sense/src/mock.rs b/sense/src/mock.rs index 06e65f05c..ce5881806 100644 --- a/sense/src/mock.rs +++ b/sense/src/mock.rs @@ -30,8 +30,6 @@ construct_runtime!( parameter_types! { pub const BlockHashCount: u64 = 250; pub const SS58Prefix: u8 = 42; - pub BlockWeights: frame_system::limits::BlockWeights = - frame_system::limits::BlockWeights::simple_max(1024); pub static ExistentialDeposit: u64 = 0; } @@ -40,8 +38,8 @@ impl system::Config for Test { type BlockWeights = (); type BlockLength = (); type DbWeight = (); - type Origin = Origin; - type Call = Call; + type RuntimeOrigin = RuntimeOrigin; + type RuntimeCall = RuntimeCall; type Index = u64; type BlockNumber = u64; type Hash = H256; @@ -49,7 +47,7 @@ impl system::Config for Test { type AccountId = u64; type Lookup = IdentityLookup; type Header = Header; - type Event = Event; + type RuntimeEvent = RuntimeEvent; type BlockHashCount = BlockHashCount; type Version = (); type PalletInfo = PalletInfo; @@ -67,7 +65,7 @@ parameter_types! { } impl pallet_sense::Config for Test { - type Event = Event; + type RuntimeEvent = RuntimeEvent; type WeightInfo = (); type StringLimit = StringLimit; } diff --git a/sense/src/tests.rs b/sense/src/tests.rs index 75b6c08f8..7ff6a026c 100644 --- a/sense/src/tests.rs +++ b/sense/src/tests.rs @@ -1,6 +1,6 @@ #![cfg(test)] use super::{Event as SenseEvent, Entity, EntityProperty, PropertyType, Error, Config, Entities, Properties}; -use crate::mock::*; +use crate::mock::{RuntimeEvent as Event, Sense, System, Test, RuntimeOrigin as Origin, new_test_ext}; use frame_support::{assert_noop, assert_ok, BoundedVec}; use frame_system::RawOrigin; use sp_runtime::traits::BadOrigin; diff --git a/sense/src/weights.rs b/sense/src/weights.rs index 27867f665..6cb9c27c3 100644 --- a/sense/src/weights.rs +++ b/sense/src/weights.rs @@ -1,30 +1,15 @@ -// This file is part of Substrate. - -// Copyright (C) 2021 Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. //! Autogenerated weights for gamedao_sense //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-02-06, STEPS: `20`, REPEAT: 10, LOW RANGE: `[]`, HIGH RANGE: `[]` -//! EXECUTION: None, WASM-EXECUTION: Compiled, CHAIN: None, DB CACHE: 1024 +//! DATE: 2023-02-10, STEPS: `20`, REPEAT: 10, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: None, DB CACHE: 1024 // Executed Command: // ./target/release/subzero-dev // benchmark // pallet +// --execution=wasm // --pallet=gamedao_sense // --extrinsic=* // --steps=20 @@ -52,16 +37,18 @@ impl WeightInfo for SubstrateWeight { // Storage: Sense EntityCount (r:1 w:1) // Storage: Sense Properties (r:0 w:3) fn create_entity() -> Weight { - (20_000_000 as Weight) - .saturating_add(T::DbWeight::get().reads(2 as Weight)) - .saturating_add(T::DbWeight::get().writes(5 as Weight)) + // Minimum execution time: 27_000 nanoseconds. + Weight::from_ref_time(29_000_000) + .saturating_add(T::DbWeight::get().reads(2)) + .saturating_add(T::DbWeight::get().writes(5)) } // Storage: Sense Entities (r:1 w:0) // Storage: Sense Properties (r:1 w:1) fn update_property() -> Weight { - (19_000_000 as Weight) - .saturating_add(T::DbWeight::get().reads(2 as Weight)) - .saturating_add(T::DbWeight::get().writes(1 as Weight)) + // Minimum execution time: 25_000 nanoseconds. + Weight::from_ref_time(26_000_000) + .saturating_add(T::DbWeight::get().reads(2)) + .saturating_add(T::DbWeight::get().writes(1)) } } @@ -71,15 +58,17 @@ impl WeightInfo for () { // Storage: Sense EntityCount (r:1 w:1) // Storage: Sense Properties (r:0 w:3) fn create_entity() -> Weight { - (20_000_000 as Weight) - .saturating_add(RocksDbWeight::get().reads(2 as Weight)) - .saturating_add(RocksDbWeight::get().writes(5 as Weight)) + // Minimum execution time: 27_000 nanoseconds. + Weight::from_ref_time(29_000_000) + .saturating_add(RocksDbWeight::get().reads(2)) + .saturating_add(RocksDbWeight::get().writes(5)) } // Storage: Sense Entities (r:1 w:0) // Storage: Sense Properties (r:1 w:1) fn update_property() -> Weight { - (19_000_000 as Weight) - .saturating_add(RocksDbWeight::get().reads(2 as Weight)) - .saturating_add(RocksDbWeight::get().writes(1 as Weight)) + // Minimum execution time: 25_000 nanoseconds. + Weight::from_ref_time(26_000_000) + .saturating_add(RocksDbWeight::get().reads(2)) + .saturating_add(RocksDbWeight::get().writes(1)) } -} +} \ No newline at end of file diff --git a/signal/Cargo.toml b/signal/Cargo.toml index cd103b6cd..08d0e594e 100644 --- a/signal/Cargo.toml +++ b/signal/Cargo.toml @@ -24,24 +24,24 @@ categories = [ serde = { version = "1.0.143", default-features = false } codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] } scale-info = { version = "2.1.1", default-features = false, features = ["derive"] } -sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.28", default-features = false } -sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.28", default-features = false } -frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.28", default-features = false } -frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.28", default-features = false } -frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.28", default-features = false, optional = true } -orml-traits = { git = 'https://github.com/open-web3-stack/open-runtime-module-library', branch= 'polkadot-v0.9.28', default-features = false } +sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36", default-features = false } +sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36", default-features = false } +frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36", default-features = false } +frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36", default-features = false } +frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36", default-features = false, optional = true } +orml-traits = { git = 'https://github.com/open-web3-stack/open-runtime-module-library', branch= 'polkadot-v0.9.36', default-features = false } gamedao-traits = { package = "gamedao-traits", path = "../traits", default-features = false } -sp-io = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.28", default-features=false } +sp-io = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.36", default-features=false } [dev-dependencies] -sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.28" } -sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.28" } +sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.36" } +sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.36" } -pallet-balances = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.28" } -pallet-timestamp = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.28" } +pallet-balances = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } +pallet-timestamp = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } -orml-currencies = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.28", default-features = false } -orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.28", default-features = false } +orml-currencies = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.36", default-features = false } +orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.36", default-features = false } gamedao-control = { path = "../control", default-features = true } gamedao-flow = { path = "../flow", default-features = true } diff --git a/signal/src/lib.rs b/signal/src/lib.rs index 943deee44..3085531c2 100644 --- a/signal/src/lib.rs +++ b/signal/src/lib.rs @@ -75,9 +75,9 @@ pub mod pallet { #[pallet::config] pub trait Config: frame_system::Config { - type Event: From> - + IsType<::Event> - + Into<::Event>; + type RuntimeEvent: From> + + IsType<::RuntimeEvent> + + Into<::RuntimeEvent>; /// The units in which we record balances. type Balance: Member @@ -417,6 +417,7 @@ pub mod pallet { ProposalStates::::insert(proposal_id, ProposalState::Active); Self::deposit_event(Event::::Activated { proposal_id: *proposal_id }); } + T::WeightInfo::on_initialize(proposals.len().saturated_into()) } diff --git a/signal/src/mock.rs b/signal/src/mock.rs index ea95b23ad..64f4b4f8d 100644 --- a/signal/src/mock.rs +++ b/signal/src/mock.rs @@ -15,7 +15,6 @@ use sp_runtime::{ Permill, }; use sp_std::convert::{TryFrom, TryInto}; -use gamedao_traits::FlowTrait; pub type AccountId = u64; pub type Amount = i128; @@ -24,7 +23,7 @@ pub type BlockNumber = u64; pub type CurrencyId = u32; pub type Hash = H256; pub type Moment = u64; -// pub type BoundedString = BoundedVec::StringLimit>; +pub type BoundedString = BoundedVec::StringLimit>; pub const MILLICENTS: Balance = 1_000_000_000; pub const CENTS: Balance = 1_000 * MILLICENTS; @@ -85,25 +84,23 @@ parameter_type_with_key! { }; } impl orml_tokens::Config for Test { - type Event = Event; + type RuntimeEvent = RuntimeEvent; type Balance = Balance; type Amount = Amount; type CurrencyId = CurrencyId; type WeightInfo = (); type ExistentialDeposits = ExistentialDeposits; - type OnDust = (); - type OnNewTokenAccount = (); - type OnKilledTokenAccount = (); + type CurrencyHooks = (); type MaxLocks = (); - type DustRemovalWhitelist = Nothing; - type ReserveIdentifier = ReserveIdentifier; type MaxReserves = MaxReserves; + type ReserveIdentifier = ReserveIdentifier; + type DustRemovalWhitelist = Nothing; } impl pallet_balances::Config for Test { type Balance = Balance; type DustRemoval = (); - type Event = Event; + type RuntimeEvent = RuntimeEvent; type ExistentialDeposit = ExistentialDeposit; type AccountStore = frame_system::Pallet; type MaxLocks = (); @@ -123,8 +120,8 @@ impl orml_currencies::Config for Test { parameter_types! { pub const BlockHashCount: u64 = 250; pub const SS58Prefix: u8 = 42; - pub BlockWeights: frame_system::limits::BlockWeights = - frame_system::limits::BlockWeights::simple_max(1024); + // pub BlockWeights: frame_system::limits::BlockWeights = + // frame_system::limits::BlockWeights::simple_max(1024); pub const ExistentialDeposit: Balance = 1; } impl frame_system::Config for Test { @@ -132,8 +129,8 @@ impl frame_system::Config for Test { type BlockWeights = (); type BlockLength = (); type DbWeight = (); - type Origin = Origin; - type Call = Call; + type RuntimeOrigin = RuntimeOrigin; + type RuntimeCall = RuntimeCall; type Index = u64; type BlockNumber = u64; type Hash = Hash; @@ -141,7 +138,7 @@ impl frame_system::Config for Test { type AccountId = AccountId; type Lookup = IdentityLookup; type Header = Header; - type Event = Event; + type RuntimeEvent = RuntimeEvent; type BlockHashCount = BlockHashCount; type Version = (); type PalletInfo = PalletInfo; @@ -175,7 +172,7 @@ impl gamedao_control::Config for Test { type Balance = Balance; type CurrencyId = CurrencyId; type WeightInfo = (); - type Event = Event; + type RuntimeEvent = RuntimeEvent; type Currency = Currencies; type MaxMembers = MaxMembers; type ProtocolTokenId = ProtocolTokenId; @@ -197,7 +194,7 @@ parameter_types! { } impl gamedao_flow::Config for Test { - type Event = Event; + type RuntimeEvent = RuntimeEvent; type Balance = Balance; type CurrencyId = CurrencyId; type WeightInfo = (); @@ -227,7 +224,7 @@ parameter_types! { pub const ProposalDurationLimits: (BlockNumber, BlockNumber) = (100, 864000); } impl gamedao_signal::Config for Test { - type Event = Event; + type RuntimeEvent = RuntimeEvent; type Balance = Balance; type CurrencyId = CurrencyId; type Currency = Currencies; @@ -250,112 +247,6 @@ impl gamedao_signal::Config for Test { type StringLimit = ConstU32<256>; } -use sp_runtime::traits::{Hash as HashTrait, AccountIdConversion}; -use gamedao_traits::ControlTrait; -use crate::ProposalCount; -use gamedao_control::types::{AccessModel, FeeModel, OrgType, Org}; -use gamedao_flow::{FlowGovernance, FlowProtocol}; -use super::types::{Proposal, ProposalType, SlashingRule}; -use frame_support::assert_ok; -use frame_system::RawOrigin; - -pub fn create_org(members: &Vec) -> (H256, AccountId) { - let bounded_str = BoundedVec::truncate_from(vec![1,2]); - let index = Control::org_count(); - let now = frame_system::Pallet::::block_number(); - let org = Org { - index, creator: ALICE, prime: ALICE, name: bounded_str.clone(), cid: bounded_str.clone(), - org_type: OrgType::Individual, fee_model: FeeModel::NoFees, membership_fee: Some(1 * DOLLARS), - gov_currency: PROTOCOL_TOKEN_ID, pay_currency: PAYMENT_TOKEN_ID, access_model: AccessModel::Open, - member_limit: ::MaxMembers::get(), created: now.clone(), mutated: now - }; - let org_id = ::Hashing::hash_of(&org); - assert_ok!( - Control::create_org( - Origin::signed(ALICE), org.name, org.cid, org.org_type, org.access_model, - org.fee_model, None, org.membership_fee, None, None, None - )); - let treasury_id = Control::org_treasury_account(&org_id).unwrap(); - let init_balance = 100 * DOLLARS; - assert_ok!(Tokens::set_balance(RawOrigin::Root.into(), treasury_id, PROTOCOL_TOKEN_ID, init_balance, 0)); - for x in members { - assert_ok!(Control::add_member(Origin::signed(x.clone()), org_id, *x)); - } - (org_id, treasury_id) -} - -pub fn set_balance(accounts: &Vec, amount: Balance) { - for x in accounts { - assert_ok!(Tokens::set_balance(RawOrigin::Root.into(), *x, PROTOCOL_TOKEN_ID, amount, 0)); - assert_ok!(Tokens::set_balance(RawOrigin::Root.into(), *x, PAYMENT_TOKEN_ID, amount, 0)); - } -} - -pub fn create_finalize_campaign( - current_block: BlockNumber, - org_id: H256, - contributors: &Vec, - contribution: Balance, - expiry: BlockNumber, - finalize: bool -) -> H256 { - let index = Flow::campaign_count(); - let bounded_str = BoundedVec::truncate_from(vec![1, 2, 3]); - let campaign = gamedao_flow::types::Campaign { - index, - org_id, - name: bounded_str.clone(), - owner: ALICE, - admin: ALICE, - deposit: 10 * DOLLARS, - start: current_block, - expiry, - cap: 40 * DOLLARS, - protocol: FlowProtocol::default(), - governance: FlowGovernance::default(), - cid: bounded_str.clone(), - token_symbol: None, - token_name: None, - created: current_block, - }; - assert_ok!(Flow::create_campaign( - Origin::signed(ALICE), - org_id, campaign.admin, campaign.name.clone(), campaign.cap, - campaign.deposit, campaign.expiry, campaign.protocol.clone(), - campaign.governance.clone(), campaign.cid.clone(), None, None, None - )); - let campaign_id = ::Hashing::hash_of(&campaign); - for x in contributors { - assert_ok!(Flow::contribute(Origin::signed(*x), campaign_id, contribution)); - } - // Finalize campaign - if finalize { - System::set_block_number(expiry); - Flow::on_finalize(expiry); - System::set_block_number(expiry + 1); - Flow::on_initialize(expiry + 1); - assert_eq!(Flow::is_campaign_succeeded(&campaign_id), true); - } - - campaign_id -} - -pub fn create_proposal( - proposal_type: ProposalType, org_id: H256, start: BlockNumber, expiry: BlockNumber, deposit: Balance, campaign_id: Option, - currency_id: Option, beneficiary: Option, amount: Option -) -> (H256, Proposal::StringLimit>>) { - let bounded_str = BoundedVec::truncate_from(vec![1, 2, 3]); - let proposal = Proposal { - index: >::get(), owner: ALICE, title: bounded_str.clone(), - cid: bounded_str, slashing_rule: SlashingRule::Automated, - start, expiry, org_id, deposit, campaign_id, - amount, beneficiary, proposal_type, currency_id, - }; - let proposal_id: H256 = ::Hashing::hash_of(&proposal); - (proposal_id, proposal) -} - - #[derive(Default)] pub struct ExtBuilder; impl ExtBuilder { diff --git a/signal/src/tests.rs b/signal/src/tests.rs index f7ac637c9..bbdb713ab 100644 --- a/signal/src/tests.rs +++ b/signal/src/tests.rs @@ -1,19 +1,118 @@ #[cfg(test)] use super::{ - mock::{ - BlockNumber, AccountId, Balance, Control, Event, ExtBuilder, - Origin, Signal, System, Test, ALICE, BOB, CHARLIE, DOLLARS, DAYS, - PROTOCOL_TOKEN_ID, PAYMENT_TOKEN_ID, create_proposal, create_finalize_campaign, create_org, set_balance, - ProposalDurationLimits - }, - types::{ProposalType, ProposalState, Majority}, + types::{Proposal, ProposalType, ProposalState, Majority}, *, }; +use crate::mock::{ + BlockNumber, AccountId, Balance, Control, RuntimeEvent as Event, ExtBuilder, Tokens, BoundedString, + RuntimeOrigin as Origin, Signal, System, Test, ALICE, BOB, CHARLIE, DOLLARS, DAYS, + PROTOCOL_TOKEN_ID, PAYMENT_TOKEN_ID, + ProposalDurationLimits, Flow, CurrencyId +}; use frame_system::RawOrigin; use frame_support::{ assert_noop, assert_ok, traits::Hooks }; +use sp_core::H256; +use gamedao_control::types::{AccessModel, FeeModel, OrgType, Org}; +use gamedao_flow::{FlowGovernance, FlowProtocol}; + +pub fn create_org(members: &Vec) -> (H256, AccountId) { + let bounded_str = BoundedVec::truncate_from(vec![1,2]); + let index = Control::org_count(); + let now = frame_system::Pallet::::block_number(); + let org = Org { + index, creator: ALICE, prime: ALICE, name: bounded_str.clone(), cid: bounded_str.clone(), + org_type: OrgType::Individual, fee_model: FeeModel::NoFees, membership_fee: Some(1 * DOLLARS), + gov_currency: PROTOCOL_TOKEN_ID, pay_currency: PAYMENT_TOKEN_ID, access_model: AccessModel::Open, + member_limit: ::MaxMembers::get(), created: now.clone(), mutated: now + }; + let org_id = ::Hashing::hash_of(&org); + assert_ok!( + Control::create_org( + Origin::signed(ALICE), org.name, org.cid, org.org_type, org.access_model, + org.fee_model, None, org.membership_fee, None, None, None + )); + let treasury_id = Control::org_treasury_account(&org_id).unwrap(); + let init_balance = 100 * DOLLARS; + assert_ok!(Tokens::set_balance(RawOrigin::Root.into(), treasury_id, PROTOCOL_TOKEN_ID, init_balance, 0)); + for x in members { + assert_ok!(Control::add_member(Origin::signed(x.clone()), org_id, *x)); + } + (org_id, treasury_id) +} + +pub fn set_balance(accounts: &Vec, amount: Balance) { + for x in accounts { + assert_ok!(Tokens::set_balance(RawOrigin::Root.into(), *x, PROTOCOL_TOKEN_ID, amount, 0)); + assert_ok!(Tokens::set_balance(RawOrigin::Root.into(), *x, PAYMENT_TOKEN_ID, amount, 0)); + } +} + +pub fn create_finalize_campaign( + current_block: BlockNumber, + org_id: H256, + contributors: &Vec, + contribution: Balance, + expiry: BlockNumber, + finalize: bool +) -> H256 { + let index = Flow::campaign_count(); + let bounded_str = BoundedVec::truncate_from(vec![1, 2, 3]); + let campaign = gamedao_flow::types::Campaign { + index, + org_id, + name: bounded_str.clone(), + owner: ALICE, + admin: ALICE, + deposit: 10 * DOLLARS, + start: current_block, + expiry, + cap: 40 * DOLLARS, + protocol: FlowProtocol::default(), + governance: FlowGovernance::default(), + cid: bounded_str.clone(), + token_symbol: None, + token_name: None, + created: current_block, + }; + assert_ok!(Flow::create_campaign( + Origin::signed(ALICE), + org_id, campaign.admin, campaign.name.clone(), campaign.cap, + campaign.deposit, campaign.expiry, campaign.protocol.clone(), + campaign.governance.clone(), campaign.cid.clone(), None, None, None + )); + let campaign_id = ::Hashing::hash_of(&campaign); + for x in contributors { + assert_ok!(Flow::contribute(Origin::signed(*x), campaign_id, contribution)); + } + // Finalize campaign + if finalize { + System::set_block_number(expiry); + Flow::on_finalize(expiry); + System::set_block_number(expiry + 1); + Flow::on_initialize(expiry + 1); + assert_eq!(Flow::is_campaign_succeeded(&campaign_id), true); + } + + campaign_id +} + +pub fn create_proposal( + proposal_type: ProposalType, org_id: H256, start: BlockNumber, expiry: BlockNumber, deposit: Balance, campaign_id: Option, + currency_id: Option, beneficiary: Option, amount: Option +) -> (H256, Proposal) { + let bounded_str = BoundedVec::truncate_from(vec![1, 2, 3]); + let proposal = Proposal { + index: >::get(), owner: ALICE, title: bounded_str.clone(), + cid: bounded_str, slashing_rule: SlashingRule::Automated, + start, expiry, org_id, deposit, campaign_id, + amount, beneficiary, proposal_type, currency_id, + }; + let proposal_id: H256 = ::Hashing::hash_of(&proposal); + (proposal_id, proposal) +} // TODO: more tests for token weighted voting diff --git a/signal/src/weights.rs b/signal/src/weights.rs index e56f4282b..77e1a232f 100644 --- a/signal/src/weights.rs +++ b/signal/src/weights.rs @@ -1,30 +1,15 @@ -// This file is part of Substrate. - -// Copyright (C) 2021 Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. //! Autogenerated weights for gamedao_signal //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-02-06, STEPS: `20`, REPEAT: 10, LOW RANGE: `[]`, HIGH RANGE: `[]` -//! EXECUTION: None, WASM-EXECUTION: Compiled, CHAIN: None, DB CACHE: 1024 +//! DATE: 2023-02-10, STEPS: `20`, REPEAT: 10, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: None, DB CACHE: 1024 // Executed Command: // ./target/release/subzero-dev // benchmark // pallet +// --execution=wasm // --pallet=gamedao_signal // --extrinsic=* // --steps=20 @@ -60,32 +45,37 @@ impl WeightInfo for SubstrateWeight { // Storage: Signal ProposalVoting (r:0 w:1) // Storage: Signal ProposalStates (r:0 w:1) fn proposal() -> Weight { - (65_000_000 as Weight) - .saturating_add(T::DbWeight::get().reads(10 as Weight)) - .saturating_add(T::DbWeight::get().writes(8 as Weight)) + // Minimum execution time: 90_000 nanoseconds. + Weight::from_ref_time(94_000_000) + .saturating_add(T::DbWeight::get().reads(10)) + .saturating_add(T::DbWeight::get().writes(8)) } // Storage: Signal ProposalVoting (r:1 w:1) // Storage: Signal ProposalOf (r:1 w:0) // Storage: Control MemberStates (r:1 w:0) // Storage: Signal ProposalStates (r:1 w:1) // Storage: Control OrgTreasury (r:1 w:0) - // Storage: Tokens Accounts (r:4 w:4) - // Storage: System Account (r:2 w:2) + // Storage: Tokens Accounts (r:3 w:3) + // Storage: System Account (r:1 w:1) + /// The range of component `m` is `[0, 1000]`. fn vote(m: u32, ) -> Weight { - (80_488_000 as Weight) - // Standard Error: 4_000 - .saturating_add((127_000 as Weight).saturating_mul(m as Weight)) - .saturating_add(T::DbWeight::get().reads(11 as Weight)) - .saturating_add(T::DbWeight::get().writes(8 as Weight)) + // Minimum execution time: 107_000 nanoseconds. + Weight::from_ref_time(113_880_549) + // Standard Error: 3_532 + .saturating_add(Weight::from_ref_time(148_088).saturating_mul(m.into())) + .saturating_add(T::DbWeight::get().reads(9)) + .saturating_add(T::DbWeight::get().writes(6)) } // Storage: Signal ProposalsByBlock (r:1 w:0) // Storage: Signal ProposalStates (r:5 w:0) + /// The range of component `p` is `[0, 100]`. fn on_initialize(p: u32, ) -> Weight { - (401_000 as Weight) - // Standard Error: 9_000 - .saturating_add((3_147_000 as Weight).saturating_mul(p as Weight)) - .saturating_add(T::DbWeight::get().reads(1 as Weight)) - .saturating_add(T::DbWeight::get().reads((1 as Weight).saturating_mul(p as Weight))) + // Minimum execution time: 5_000 nanoseconds. + Weight::from_ref_time(9_260_770) + // Standard Error: 7_634 + .saturating_add(Weight::from_ref_time(2_838_161).saturating_mul(p.into())) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(p.into()))) } } @@ -102,31 +92,36 @@ impl WeightInfo for () { // Storage: Signal ProposalVoting (r:0 w:1) // Storage: Signal ProposalStates (r:0 w:1) fn proposal() -> Weight { - (65_000_000 as Weight) - .saturating_add(RocksDbWeight::get().reads(10 as Weight)) - .saturating_add(RocksDbWeight::get().writes(8 as Weight)) + // Minimum execution time: 90_000 nanoseconds. + Weight::from_ref_time(94_000_000) + .saturating_add(RocksDbWeight::get().reads(10)) + .saturating_add(RocksDbWeight::get().writes(8)) } // Storage: Signal ProposalVoting (r:1 w:1) // Storage: Signal ProposalOf (r:1 w:0) // Storage: Control MemberStates (r:1 w:0) // Storage: Signal ProposalStates (r:1 w:1) // Storage: Control OrgTreasury (r:1 w:0) - // Storage: Tokens Accounts (r:4 w:4) - // Storage: System Account (r:2 w:2) + // Storage: Tokens Accounts (r:3 w:3) + // Storage: System Account (r:1 w:1) + /// The range of component `m` is `[0, 1000]`. fn vote(m: u32, ) -> Weight { - (80_488_000 as Weight) - // Standard Error: 4_000 - .saturating_add((127_000 as Weight).saturating_mul(m as Weight)) - .saturating_add(RocksDbWeight::get().reads(11 as Weight)) - .saturating_add(RocksDbWeight::get().writes(8 as Weight)) + // Minimum execution time: 107_000 nanoseconds. + Weight::from_ref_time(113_880_549) + // Standard Error: 3_532 + .saturating_add(Weight::from_ref_time(148_088).saturating_mul(m.into())) + .saturating_add(RocksDbWeight::get().reads(9)) + .saturating_add(RocksDbWeight::get().writes(6)) } // Storage: Signal ProposalsByBlock (r:1 w:0) // Storage: Signal ProposalStates (r:5 w:0) + /// The range of component `p` is `[0, 100]`. fn on_initialize(p: u32, ) -> Weight { - (401_000 as Weight) - // Standard Error: 9_000 - .saturating_add((3_147_000 as Weight).saturating_mul(p as Weight)) - .saturating_add(RocksDbWeight::get().reads(1 as Weight)) - .saturating_add(RocksDbWeight::get().reads((1 as Weight).saturating_mul(p as Weight))) + // Minimum execution time: 5_000 nanoseconds. + Weight::from_ref_time(9_260_770) + // Standard Error: 7_634 + .saturating_add(Weight::from_ref_time(2_838_161).saturating_mul(p.into())) + .saturating_add(RocksDbWeight::get().reads(1)) + .saturating_add(RocksDbWeight::get().reads((1_u64).saturating_mul(p.into()))) } -} +} \ No newline at end of file diff --git a/traits/Cargo.toml b/traits/Cargo.toml index c8b1c319e..ac03a6508 100644 --- a/traits/Cargo.toml +++ b/traits/Cargo.toml @@ -18,9 +18,9 @@ repository = "https://github.com/gamedaoco/gamedao-protocol" serde = { version = "1.0.124", default-features = false } codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] } scale-info = { version = "2.0.1", default-features = false, features = ["derive"] } -frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.28", default-features = false } -frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.28", default-features = false, optional = true } -sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.28", default-features = false } +frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36", default-features = false } +frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36", default-features = false, optional = true } +sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36", default-features = false } [features] default = ["std"] From c7754ebc4f40e80ebc2fcaed29124e3e3f6336de Mon Sep 17 00:00:00 2001 From: FiberMan Date: Wed, 15 Feb 2023 12:53:29 +0100 Subject: [PATCH 18/49] Add extrinsic descriptions for Battlepass. --- battlepass/src/lib.rs | 93 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 89 insertions(+), 4 deletions(-) diff --git a/battlepass/src/lib.rs b/battlepass/src/lib.rs index 60617274a..bfbd0e1f1 100644 --- a/battlepass/src/lib.rs +++ b/battlepass/src/lib.rs @@ -260,7 +260,7 @@ pub mod pallet { /// Claimed Battlepass-NFT by user and battlepass. /// - /// ClaimedBattlepasses: map (Hash, AccountId) => NftId + /// ClaimedBattlepasses: map (Hash, AccountId) => ItemId #[pallet::storage] #[pallet::getter(fn get_claimed_battlepass)] pub(super) type ClaimedBattlepasses = StorageDoubleMap<_, @@ -272,7 +272,7 @@ pub mod pallet { /// Total earned Points for users per each Battlepass. /// - /// Points: map (Hash, AccountId) => NftId + /// Points: map (Hash, AccountId) => u32 #[pallet::storage] #[pallet::getter(fn get_points)] pub(super) type Points = StorageDoubleMap<_, @@ -298,7 +298,7 @@ pub mod pallet { /// Claimed Reward-NFT by user. /// - /// ClaimedRewards: map (AccountId, Hash) => NftId + /// ClaimedRewards: map (Hash, AccountId) => ItemId #[pallet::storage] #[pallet::getter(fn get_claimed_rewards)] pub(super) type ClaimedRewards = StorageDoubleMap<_, @@ -320,6 +320,9 @@ pub mod pallet { OptionQuery >; + /// A counter for created collections + /// + /// CollectionIndex: u32 #[pallet::storage] #[pallet::getter(fn collection_index)] pub type CollectionIndex = StorageValue<_, u32, ValueQuery>; @@ -327,6 +330,15 @@ pub mod pallet { #[pallet::call] impl Pallet { + /// Creates a Battlepass. + /// May be called only by Organization owner. + /// Also creates a new collection to store claimed Battlepass NFTs. + /// + /// Parameters: + /// - `org_id`: ID of the Organization for which to create a Battlepass. + /// - `name`: Battlepass name. + /// - `cid`: IPFS content identifier. + /// - `price`: Price for the Battlepass subscription. #[pallet::call_index(0)] #[pallet::weight(::WeightInfo::create_battlepass())] #[transactional] @@ -356,6 +368,12 @@ pub mod pallet { Ok(()) } + /// Claims the Battlepass-NFT for user who joined the Battlepass. + /// This NFT may be used as a proof of a Battlepass membership. + /// + /// Parameters: + /// - `battlepass_id`: ID of the Battlepass for which to claim NFT. + /// - `for_who`: Account for which to claim NFT. #[pallet::call_index(1)] #[pallet::weight(::WeightInfo::claim_battlepass())] #[transactional] @@ -385,6 +403,12 @@ pub mod pallet { Ok(()) } + /// Activates the Battlepass. + /// Can activate only Battlepass in DRAFT state. + /// May be called only by Organization owner. + /// + /// Parameters: + /// - `battlepass_id`: ID of the Battlepass to activate. #[pallet::call_index(2)] #[pallet::weight(::WeightInfo::activate_battlepass())] #[transactional] @@ -409,6 +433,13 @@ pub mod pallet { Ok(()) } + /// Concludes the Battlepass. + /// Can conclude only Battlepass in ACTIVE state. + /// After calling this extrinsic Battlepass state can not be changed any more. + /// May be called only by Organization owner. + /// + /// Parameters: + /// - `battlepass_id`: ID of the Battlepass to conclude. #[pallet::call_index(3)] #[pallet::weight(::WeightInfo::conclude_battlepass())] #[transactional] @@ -431,6 +462,15 @@ pub mod pallet { Ok(()) } + /// Sets Battlepass Points for user. + /// So far no information about users' achievements is stored on chain. A separate trusted service (Bot) + /// should collect such info, process it, validate it and call this extrinsic if user's Points have been updated. + /// May be called only by Organization owner or by a specially dedicated for this purpose account. + /// + /// Parameters: + /// - `battlepass_id`: ID of the Battlepass. + /// - `account`: User's account for which to set Points. + /// - `amount`: Amount of Points to set. #[pallet::call_index(4)] #[pallet::weight(::WeightInfo::set_points())] pub fn set_points( @@ -458,6 +498,17 @@ pub mod pallet { Ok(()) } + /// Creates a Reward Type for the Battlepass. + /// Also creates a new collection to store claimed Reward NFTs. + /// May be called only by Organization owner. + /// + /// Parameters: + /// - `battlepass_id`: ID of the Battlepass to create a Reward for. + /// - `name`: Name of the Reward. + /// - `cid`: IPFS content identifier. + /// - `max`: Maximum number of claimed rewards this Reward Type may have. Unlimited if empty. + /// - `level`: Minimum Level user must reach to be able to claim this Reward Type. + /// - `transferable`: Specifies whether claimed Reward NFTs could be transferred (sold) to another account. #[pallet::call_index(5)] #[pallet::weight(::WeightInfo::create_reward())] #[transactional] @@ -488,6 +539,12 @@ pub mod pallet { Ok(()) } + /// Disables the Reward Type. + /// After calling this extrinsic Reward Type state can not be changed any more. + /// May be called only by Organization owner. + /// + /// Parameters: + /// - `reward_id`: ID of the Reward Type to be disabled. #[pallet::call_index(6)] #[pallet::weight(::WeightInfo::disable_reward())] pub fn disable_reward( @@ -513,6 +570,15 @@ pub mod pallet { Ok(()) } + /// Claims a reward for caller. + /// Mints a Reward NFT which may be used as a proof of a Reward posession. + /// Caller must be eligible for the Reward Type to be able to claim it. Eligibility criteria are: + /// - must be an Organization member. + /// - must be a Battlepass member (posess a valid Battlepass NFT). + /// - required achievement Level must be reached. + /// + /// Parameters: + /// - `reward_id`: ID of the Reward Type to claim. #[pallet::call_index(7)] #[pallet::weight(::WeightInfo::claim_reward())] #[transactional] @@ -544,7 +610,7 @@ pub mod pallet { // validate Battlepass NFT metadata let metadata: String = BoundedVec::truncate_from(reward.battlepass_id.encode()); ensure!(metadata == bp_nft.metadata, Error::::BattlepassNftInvalid); - // check if user has enough Points + // check if user has reached the required Level ensure!(Self::is_level_reached(&reward.battlepass_id, &claimer, reward.level), Error::::LevelNotReached); let nft_id = Self::do_claim_reward(claimer.clone(), reward_id, reward.collection_id, reward.transferable)?; @@ -554,6 +620,13 @@ pub mod pallet { Ok(()) } + /// Adds a new achievement Level. + /// May be called only by Organization owner. + /// + /// Parameters: + /// - `battlepass_id`: ID of the Battlepass to add a Level for. + /// - `level`: Achievement Level. + /// - `points`: Amount of Points needed to reach the Level. #[pallet::call_index(8)] #[pallet::weight(::WeightInfo::add_level())] pub fn add_level( @@ -579,6 +652,12 @@ pub mod pallet { Ok(()) } + /// Removes achievement Level. + /// May be called only by Organization owner. + /// + /// Parameters: + /// - `battlepass_id`: ID of the Battlepass to remove a Level for. + /// - `level`: Achievement Level. #[pallet::call_index(9)] #[pallet::weight(::WeightInfo::remove_level())] pub fn remove_level( @@ -605,6 +684,12 @@ pub mod pallet { Ok(()) } + /// Adds for a Battlepass a special trusted account (Bot) which will have a permission to update users' Points. + /// May be called only by Organization owner. + /// + /// Parameters: + /// - `battlepass_id`: ID of the Battlepass to add a Bot for. + /// - `bot`: Trusted Account ID. #[pallet::call_index(10)] #[pallet::weight(::WeightInfo::add_bot())] pub fn add_bot( From 59a6327eaff5d1512f16a0e6ea803132b91e8487 Mon Sep 17 00:00:00 2001 From: Yura Date: Thu, 16 Feb 2023 20:45:35 +0100 Subject: [PATCH 19/49] feat: Update Battlepass and Reward (#130) --- battlepass/src/lib.rs | 117 ++++++++++++++++++++++++++++++++++++++---- control/src/lib.rs | 14 ++--- 2 files changed, 114 insertions(+), 17 deletions(-) diff --git a/battlepass/src/lib.rs b/battlepass/src/lib.rs index bfbd0e1f1..35af3dc09 100644 --- a/battlepass/src/lib.rs +++ b/battlepass/src/lib.rs @@ -140,6 +140,14 @@ pub mod pallet { battlepass_id: T::Hash, season: u32 }, + + /// BattlePass updated + BattlepassUpdated { + battlepass_id: T::Hash, + name: Option>, + cid: Option>, + price: Option + }, /// BattlePass claimed BattlepassClaimed { @@ -179,6 +187,14 @@ pub mod pallet { level: u8 }, + /// Reward updated + RewardUpdated { + reward_id: T::Hash, + name: Option>, + cid: Option>, + transferable: Option + }, + /// Reward claimed by user RewardClaimed { reward_id: T::Hash, @@ -228,6 +244,7 @@ pub mod pallet { LevelNotReached, LevelUnknown, NoAvailableCollectionId, + NoChangesProvided, NotMember, NotOwnNft, OrgPrimeUnknown, @@ -368,13 +385,51 @@ pub mod pallet { Ok(()) } + + #[pallet::call_index(1)] + #[pallet::weight(10_000_000)] + pub fn update_battlepass( + origin: OriginFor, + battlepass_id: T::Hash, + name: Option>, + cid: Option>, + price: Option, + ) -> DispatchResult { + let creator = ensure_signed(origin)?; + // check if Battlepass exists + let mut battlepass = Self::get_battlepass(battlepass_id).ok_or(Error::::BattlepassUnknown)?; + // check if there is something to update + ensure!( + name.is_some() && name.clone().unwrap() != battlepass.name || + cid.is_some() && cid.clone().unwrap() != battlepass.cid || + price.is_some() && price.clone().unwrap() != battlepass.price, + Error::::NoChangesProvided + ); + // check if Battlepass state is not ENDED + ensure!(!Self::check_battlepass_state(battlepass_id, BattlepassState::ENDED)?, Error::::BattlepassStateWrong); + // check if Org is active + ensure!(T::Control::is_org_active(&battlepass.org_id), Error::::OrgUnknownOrInactive); + // check permissions (prime) + ensure!(Self::is_prime(&battlepass.org_id, creator.clone())?, Error::::AuthorizationError); + + battlepass.name = name.clone().unwrap(); + battlepass.cid = cid.clone().unwrap(); + battlepass.price = price.clone().unwrap(); + + Battlepasses::::insert(battlepass_id, battlepass); + + Self::deposit_event(Event::BattlepassUpdated { battlepass_id, name, cid, price }); + + Ok(()) + } + /// Claims the Battlepass-NFT for user who joined the Battlepass. /// This NFT may be used as a proof of a Battlepass membership. /// /// Parameters: /// - `battlepass_id`: ID of the Battlepass for which to claim NFT. /// - `for_who`: Account for which to claim NFT. - #[pallet::call_index(1)] + #[pallet::call_index(2)] #[pallet::weight(::WeightInfo::claim_battlepass())] #[transactional] pub fn claim_battlepass( @@ -409,7 +464,7 @@ pub mod pallet { /// /// Parameters: /// - `battlepass_id`: ID of the Battlepass to activate. - #[pallet::call_index(2)] + #[pallet::call_index(3)] #[pallet::weight(::WeightInfo::activate_battlepass())] #[transactional] pub fn activate_battlepass( @@ -440,7 +495,7 @@ pub mod pallet { /// /// Parameters: /// - `battlepass_id`: ID of the Battlepass to conclude. - #[pallet::call_index(3)] + #[pallet::call_index(4)] #[pallet::weight(::WeightInfo::conclude_battlepass())] #[transactional] pub fn conclude_battlepass( @@ -471,7 +526,7 @@ pub mod pallet { /// - `battlepass_id`: ID of the Battlepass. /// - `account`: User's account for which to set Points. /// - `amount`: Amount of Points to set. - #[pallet::call_index(4)] + #[pallet::call_index(5)] #[pallet::weight(::WeightInfo::set_points())] pub fn set_points( origin: OriginFor, @@ -509,7 +564,7 @@ pub mod pallet { /// - `max`: Maximum number of claimed rewards this Reward Type may have. Unlimited if empty. /// - `level`: Minimum Level user must reach to be able to claim this Reward Type. /// - `transferable`: Specifies whether claimed Reward NFTs could be transferred (sold) to another account. - #[pallet::call_index(5)] + #[pallet::call_index(6)] #[pallet::weight(::WeightInfo::create_reward())] #[transactional] pub fn create_reward( @@ -539,13 +594,55 @@ pub mod pallet { Ok(()) } + + #[pallet::call_index(7)] + #[pallet::weight(10_000_000)] + pub fn update_reward( + origin: OriginFor, + reward_id: T::Hash, + name: Option>, + cid: Option>, + transferable: Option, + ) -> DispatchResult { + let caller = ensure_signed(origin)?; + // check if Reward exists + let mut reward = Self::get_reward(reward_id).ok_or(Error::::RewardUnknown)?; + // check if there is something to update + ensure!( + name.is_some() && name.clone().unwrap() != reward.name || + cid.is_some() && cid.clone().unwrap() != reward.cid || + transferable.is_some() && transferable.clone().unwrap() != reward.transferable, + Error::::NoChangesProvided + ); + // check if Reward is active + ensure!(Self::check_reward_state(reward_id, RewardState::ACTIVE)?, Error::::RewardInactive); + // check if Battlepass exists + let battlepass = Self::get_battlepass(reward.battlepass_id).ok_or(Error::::BattlepassUnknown)?; + // check if Battlepass is not ended + ensure!(!Self::check_battlepass_state(reward.battlepass_id, BattlepassState::ENDED)?, Error::::BattlepassStateWrong); + // check if Org is active + ensure!(T::Control::is_org_active(&battlepass.org_id), Error::::OrgUnknownOrInactive); + // check permissions (prime) + ensure!(Self::is_prime(&battlepass.org_id, caller.clone())?, Error::::AuthorizationError); + + reward.name = name.clone().unwrap(); + reward.cid = cid.clone().unwrap(); + reward.transferable = transferable.clone().unwrap(); + + Rewards::::insert(reward_id, reward); + + Self::deposit_event(Event::RewardUpdated { reward_id, name, cid, transferable }); + + Ok(()) + } + /// Disables the Reward Type. /// After calling this extrinsic Reward Type state can not be changed any more. /// May be called only by Organization owner. /// /// Parameters: /// - `reward_id`: ID of the Reward Type to be disabled. - #[pallet::call_index(6)] + #[pallet::call_index(8)] #[pallet::weight(::WeightInfo::disable_reward())] pub fn disable_reward( origin: OriginFor, @@ -579,7 +676,7 @@ pub mod pallet { /// /// Parameters: /// - `reward_id`: ID of the Reward Type to claim. - #[pallet::call_index(7)] + #[pallet::call_index(9)] #[pallet::weight(::WeightInfo::claim_reward())] #[transactional] pub fn claim_reward( @@ -627,7 +724,7 @@ pub mod pallet { /// - `battlepass_id`: ID of the Battlepass to add a Level for. /// - `level`: Achievement Level. /// - `points`: Amount of Points needed to reach the Level. - #[pallet::call_index(8)] + #[pallet::call_index(10)] #[pallet::weight(::WeightInfo::add_level())] pub fn add_level( origin: OriginFor, @@ -658,7 +755,7 @@ pub mod pallet { /// Parameters: /// - `battlepass_id`: ID of the Battlepass to remove a Level for. /// - `level`: Achievement Level. - #[pallet::call_index(9)] + #[pallet::call_index(11)] #[pallet::weight(::WeightInfo::remove_level())] pub fn remove_level( origin: OriginFor, @@ -690,7 +787,7 @@ pub mod pallet { /// Parameters: /// - `battlepass_id`: ID of the Battlepass to add a Bot for. /// - `bot`: Trusted Account ID. - #[pallet::call_index(10)] + #[pallet::call_index(12)] #[pallet::weight(::WeightInfo::add_bot())] pub fn add_bot( origin: OriginFor, diff --git a/control/src/lib.rs b/control/src/lib.rs index e14cdeaf3..d7c79a784 100644 --- a/control/src/lib.rs +++ b/control/src/lib.rs @@ -701,13 +701,13 @@ impl Pallet { } } - fn ensure_root_or_governance(origin: T::RuntimeOrigin) -> Result<(), BadOrigin> { - match origin.into() { - Ok(RawOrigin::Root) => Ok(()), - // TODO: implement governance origin type - _ => Err(BadOrigin), - } - } + // fn ensure_root_or_governance(origin: T::RuntimeOrigin) -> Result<(), BadOrigin> { + // match origin.into() { + // Ok(RawOrigin::Root) => Ok(()), + // // TODO: implement governance origin type + // _ => Err(BadOrigin), + // } + // } fn ensure_root_or_self(origin: T::RuntimeOrigin, who: T::AccountId) -> Result<(), BadOrigin> { match origin.into() { From ee732d9fa85a7447a2e7c009d1ac62e5a59aab0e Mon Sep 17 00:00:00 2001 From: FiberMan Date: Thu, 16 Feb 2023 22:15:27 +0100 Subject: [PATCH 20/49] feat:tests for update_battlepass and update_reward --- battlepass/src/tests.rs | 221 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 203 insertions(+), 18 deletions(-) diff --git a/battlepass/src/tests.rs b/battlepass/src/tests.rs index d301924ff..e067915c5 100644 --- a/battlepass/src/tests.rs +++ b/battlepass/src/tests.rs @@ -98,7 +98,7 @@ fn add_member(org_id: H256, account: AccountId) { } fn string() -> BoundedVec{ - BoundedVec::truncate_from(vec![1,2]) + BoundedVec::truncate_from(b"string".to_vec()) } #[test] @@ -116,7 +116,6 @@ fn create_battlepass_test(){ new_test_ext().execute_with(|| { let org_id = create_org(); let wrong_org_id = ::Hashing::hash_of(&"123"); - let bounded_str = BoundedVec::truncate_from(vec![1,2]); let creator = ALICE; let not_creator = BOB; let not_member = EVA; @@ -125,7 +124,7 @@ fn create_battlepass_test(){ // Should not create for non existing Org assert_noop!( - Battlepass::create_battlepass(Origin::signed(creator), wrong_org_id, bounded_str.clone(), bounded_str.clone(), 10), + Battlepass::create_battlepass(Origin::signed(creator), wrong_org_id, string(), string(), 10), Error::::OrgUnknownOrInactive ); @@ -134,7 +133,7 @@ fn create_battlepass_test(){ Control::disable_org(Origin::signed(creator), org_id) ); assert_noop!( - Battlepass::create_battlepass(Origin::signed(creator), org_id, bounded_str.clone(), bounded_str.clone(), 10), + Battlepass::create_battlepass(Origin::signed(creator), org_id, string(), string(), 10), Error::::OrgUnknownOrInactive ); assert_ok!( @@ -146,17 +145,17 @@ fn create_battlepass_test(){ Control::add_member(Origin::signed(not_creator), org_id, not_creator) ); assert_noop!( - Battlepass::create_battlepass(Origin::signed(not_creator), org_id, bounded_str.clone(), bounded_str.clone(), 10), + Battlepass::create_battlepass(Origin::signed(not_creator), org_id, string(), string(), 10), Error::::AuthorizationError ); assert_noop!( - Battlepass::create_battlepass(Origin::signed(not_member), org_id, bounded_str.clone(), bounded_str.clone(), 10), + Battlepass::create_battlepass(Origin::signed(not_member), org_id, string(), string(), 10), Error::::AuthorizationError ); // Should create new Battlepass assert_ok!( - Battlepass::create_battlepass(Origin::signed(creator), org_id, bounded_str.clone(), bounded_str.clone(), 10) + Battlepass::create_battlepass(Origin::signed(creator), org_id, string(), string(), 10) ); // Check if NFT collection created assert_eq!(pallet_rmrk_core::Collections::::contains_key(0), true); @@ -175,7 +174,7 @@ fn create_battlepass_test(){ // Should create another Battlepass (may be multiple in DRAFT state) assert_ok!( - Battlepass::create_battlepass(Origin::signed(creator), org_id, bounded_str.clone(), bounded_str.clone(), 10) + Battlepass::create_battlepass(Origin::signed(creator), org_id, string(), string(), 10) ); // Check if NFT collection created assert_eq!(pallet_rmrk_core::Collections::::contains_key(1), true); @@ -199,6 +198,89 @@ fn create_battlepass_test(){ }) } +#[test] +fn update_battlepass_test() { + new_test_ext().execute_with(|| { + let org_id = create_org(); + let battlepass_id = create_battlepass(org_id); + let wrong_battlepass_id = ::Hashing::hash_of(&"123"); + let creator = ALICE; + let not_creator = BOB; + let not_member = EVA; + let new_name = BoundedVec::truncate_from(b"new name".to_vec()); + let new_cid = BoundedVec::truncate_from(b"new cid".to_vec()); + let new_price = 20; + + // Should not update unknown Battlepass + assert_noop!( + Battlepass::update_battlepass(Origin::signed(creator), wrong_battlepass_id, Some(string()), Some(string()), Some(10)), + Error::::BattlepassUnknown + ); + + // Should not update if no arguments provided + assert_noop!( + Battlepass::update_battlepass(Origin::signed(creator), battlepass_id, None, None, None), + Error::::NoChangesProvided + ); + + // Should not update if values are the same + assert_noop!( + Battlepass::update_battlepass(Origin::signed(creator), battlepass_id, Some(string()), Some(string()), Some(10)), + Error::::NoChangesProvided + ); + + // Should not update if Org is inactive + assert_ok!( + Control::disable_org(Origin::signed(creator), org_id) + ); + assert_noop!( + Battlepass::update_battlepass(Origin::signed(creator), battlepass_id, Some(new_name.clone()), Some(new_cid.clone()), Some(new_price.clone())), + Error::::OrgUnknownOrInactive + ); + assert_ok!( + Control::enable_org(Origin::signed(creator), org_id) + ); + + // Should not update if origin is not a Prime + assert_ok!( + Control::add_member(Origin::signed(not_creator), org_id, not_creator) + ); + assert_noop!( + Battlepass::update_battlepass(Origin::signed(not_creator), battlepass_id, Some(new_name.clone()), Some(new_cid.clone()), Some(new_price.clone())), + Error::::AuthorizationError + ); + assert_noop!( + Battlepass::update_battlepass(Origin::signed(not_member), battlepass_id, Some(new_name.clone()), Some(new_cid.clone()), Some(new_price.clone())), + Error::::AuthorizationError + ); + + // Should update battlepass + assert_ok!( + Battlepass::update_battlepass(Origin::signed(creator), battlepass_id, Some(new_name.clone()), Some(new_cid.clone()), Some(new_price.clone())), + ); + // Check if Battlepass updated + let updated = Battlepass::get_battlepass(battlepass_id).unwrap(); + assert_eq!(updated.name, new_name.clone()); + assert_eq!(updated.cid, new_cid.clone()); + assert_eq!(updated.price, new_price.clone()); + + + // Should not update if Battlepass state is ENDED + assert_ok!( + Battlepass::activate_battlepass(Origin::signed(creator), battlepass_id) + ); + assert_ok!( + Battlepass::conclude_battlepass(Origin::signed(creator), battlepass_id) + ); + assert_noop!( + Battlepass::update_battlepass(Origin::signed(creator), battlepass_id, Some(new_name), Some(new_cid), Some(30)), + Error::::BattlepassStateWrong + ); + + // Check events (battlepass updated) + }) +} + #[test] fn activate_battlepass_test() { new_test_ext().execute_with(|| { @@ -208,7 +290,6 @@ fn activate_battlepass_test() { let creator = ALICE; let not_creator = BOB; let not_member = EVA; - let bounded_str = BoundedVec::truncate_from(vec![1,2]); // Should not activate unknown Battlepass assert_noop!( @@ -262,7 +343,7 @@ fn activate_battlepass_test() { // Should not create if Org has an active battlepass assert_noop!( - Battlepass::create_battlepass(Origin::signed(creator), org_id, bounded_str.clone(), bounded_str.clone(), 10), + Battlepass::create_battlepass(Origin::signed(creator), org_id, string(), string(), 10), Error::::BattlepassExists ); @@ -537,7 +618,6 @@ fn create_reward_test() { let org_id = create_org(); let battlepass_id = create_battlepass(org_id); let wrong_battlepass_id = ::Hashing::hash_of(&"123"); - let bounded_str = BoundedVec::truncate_from(vec![1,2]); let creator = ALICE; let not_creator = BOB; let not_member = EVA; @@ -545,7 +625,7 @@ fn create_reward_test() { // Should not create if Battlepass unknown assert_noop!( - Battlepass::create_reward(Origin::signed(creator), wrong_battlepass_id, bounded_str.clone(), bounded_str.clone(), Some(1), 1, true), + Battlepass::create_reward(Origin::signed(creator), wrong_battlepass_id, string(), string(), Some(1), 1, true), Error::::BattlepassUnknown ); @@ -554,7 +634,7 @@ fn create_reward_test() { Control::disable_org(Origin::signed(creator), org_id) ); assert_noop!( - Battlepass::create_reward(Origin::signed(creator), battlepass_id, bounded_str.clone(), bounded_str.clone(), Some(1), 1, true), + Battlepass::create_reward(Origin::signed(creator), battlepass_id, string(), string(), Some(1), 1, true), Error::::OrgUnknownOrInactive ); assert_ok!( @@ -566,17 +646,17 @@ fn create_reward_test() { Control::add_member(Origin::signed(not_creator), org_id, not_creator) ); assert_noop!( - Battlepass::create_reward(Origin::signed(not_creator), battlepass_id, bounded_str.clone(), bounded_str.clone(), Some(1), 1, true), + Battlepass::create_reward(Origin::signed(not_creator), battlepass_id, string(), string(), Some(1), 1, true), Error::::AuthorizationError ); assert_noop!( - Battlepass::create_reward(Origin::signed(not_member), battlepass_id, bounded_str.clone(), bounded_str.clone(), Some(1), 1, true), + Battlepass::create_reward(Origin::signed(not_member), battlepass_id, string(), string(), Some(1), 1, true), Error::::AuthorizationError ); // Should create Reward if Battlepass state is DRAFT assert_ok!( - Battlepass::create_reward(Origin::signed(creator), battlepass_id, bounded_str.clone(), bounded_str.clone(), Some(1), 1, true) + Battlepass::create_reward(Origin::signed(creator), battlepass_id, string(), string(), Some(1), 1, true) ); // Check if NFT collection created assert_eq!(pallet_rmrk_core::Collections::::contains_key(1), true); @@ -593,7 +673,7 @@ fn create_reward_test() { Battlepass::activate_battlepass(Origin::signed(creator), battlepass_id) ); assert_ok!( - Battlepass::create_reward(Origin::signed(creator), battlepass_id, bounded_str.clone(), bounded_str.clone(), Some(1), 1, true) + Battlepass::create_reward(Origin::signed(creator), battlepass_id, string(), string(), Some(1), 1, true) ); // Check if NFT collection created assert_eq!(pallet_rmrk_core::Collections::::contains_key(2), true); @@ -611,7 +691,7 @@ fn create_reward_test() { Battlepass::conclude_battlepass(Origin::signed(creator), battlepass_id) ); assert_noop!( - Battlepass::create_reward(Origin::signed(creator), battlepass_id, bounded_str.clone(), bounded_str.clone(), Some(1), 1, true), + Battlepass::create_reward(Origin::signed(creator), battlepass_id, string(), string(), Some(1), 1, true), Error::::BattlepassStateWrong ); @@ -621,6 +701,111 @@ fn create_reward_test() { }) } +#[test] +fn update_reward_test() { + new_test_ext().execute_with(|| { + let org_id = create_org(); + let battlepass_id = create_battlepass(org_id); + let reward_id = create_reward(battlepass_id); + let reward_id_2 = create_reward(battlepass_id); + let wrong_id = ::Hashing::hash_of(&"123"); + let creator = ALICE; + let not_creator = BOB; + let not_member = EVA; + let new_name = BoundedVec::truncate_from(b"new name".to_vec()); + let new_cid = BoundedVec::truncate_from(b"new cid".to_vec()); + let new_transferable = false; + + // Should not update if Reward unknown + assert_noop!( + Battlepass::update_reward(Origin::signed(creator), wrong_id, Some(new_name.clone()), Some(new_cid.clone()), Some(new_transferable.clone())), + Error::::RewardUnknown + ); + + // Should not update if no arguments provided + assert_noop!( + Battlepass::update_reward(Origin::signed(creator), reward_id, None, None, None), + Error::::NoChangesProvided + ); + + // Should not update if values are the same + assert_noop!( + Battlepass::update_reward(Origin::signed(creator), reward_id, Some(string()), Some(string()), Some(true)), + Error::::NoChangesProvided + ); + + // Should not update if Battlepass unknown + Rewards::::mutate(reward_id_2, |reward| { + if let Some(r) = reward { + r.battlepass_id = wrong_id; + } + } ); + assert_noop!( + Battlepass::update_reward(Origin::signed(creator), reward_id_2, Some(new_name.clone()), Some(new_cid.clone()), Some(new_transferable.clone())), + Error::::BattlepassUnknown + ); + + // Should not update if Org is inactive + assert_ok!( + Control::disable_org(Origin::signed(creator), org_id) + ); + assert_noop!( + Battlepass::update_reward(Origin::signed(creator), reward_id, Some(new_name.clone()), Some(new_cid.clone()), Some(new_transferable.clone())), + Error::::OrgUnknownOrInactive + ); + assert_ok!( + Control::enable_org(Origin::signed(creator), org_id) + ); + + // Should not update if origin is not a Prime + assert_ok!( + Control::add_member(Origin::signed(not_creator), org_id, not_creator) + ); + assert_noop!( + Battlepass::update_reward(Origin::signed(not_creator), reward_id, Some(new_name.clone()), Some(new_cid.clone()), Some(new_transferable.clone())), + Error::::AuthorizationError + ); + assert_noop!( + Battlepass::update_reward(Origin::signed(not_member), reward_id, Some(new_name.clone()), Some(new_cid.clone()), Some(new_transferable.clone())), + Error::::AuthorizationError + ); + + // Should update Reward + assert_ok!( + Battlepass::update_reward(Origin::signed(creator), reward_id, Some(new_name.clone()), Some(new_cid.clone()), Some(new_transferable.clone())) + ); + // Check if Reward updated + let updated = Battlepass::get_reward(reward_id).unwrap(); + assert_eq!(updated.name, new_name.clone()); + assert_eq!(updated.cid, new_cid.clone()); + assert_eq!(updated.transferable, new_transferable.clone()); + + // Should not update if Battlepass state is ENDED + assert_ok!( + Battlepass::activate_battlepass(Origin::signed(creator), battlepass_id) + ); + assert_ok!( + Battlepass::conclude_battlepass(Origin::signed(creator), battlepass_id) + ); + assert_noop!( + Battlepass::update_reward(Origin::signed(creator), reward_id, Some(new_name.clone()), Some(new_cid.clone()), Some(true)), + Error::::BattlepassStateWrong + ); + + // Should not update if Reward inactive + assert_ok!( + Battlepass::disable_reward(Origin::signed(creator), reward_id) + ); + assert_noop!( + Battlepass::update_reward(Origin::signed(creator), reward_id, Some(new_name.clone()), Some(new_cid.clone()), Some(true)), + Error::::RewardInactive + ); + + // Check events + + }) +} + #[test] fn disable_reward_test() { new_test_ext().execute_with(|| { From 78c2a3c65ffed8600d965a1bcec328d14122b9ab Mon Sep 17 00:00:00 2001 From: FiberMan Date: Fri, 17 Feb 2023 10:10:31 +0100 Subject: [PATCH 21/49] feat: new benchmarks for battlepass. --- battlepass/src/benchmarking.rs | 31 +++++++++ battlepass/src/lib.rs | 4 +- battlepass/src/weights.rs | 120 +++++++++++++++++++++++---------- 3 files changed, 116 insertions(+), 39 deletions(-) diff --git a/battlepass/src/benchmarking.rs b/battlepass/src/benchmarking.rs index ee1a0eee3..7cc6e3560 100644 --- a/battlepass/src/benchmarking.rs +++ b/battlepass/src/benchmarking.rs @@ -96,6 +96,21 @@ benchmarks! { assert!(BattlepassInfoByOrg::::get(org_id).is_some()); } + update_battlepass { + let caller: T::AccountId = get_funded_caller::()?; + let org_id = get_org::(caller.clone()); + let battlepass_id = get_battlepass::(caller.clone(), org_id); + let new_name = BoundedVec::truncate_from(b"new name".to_vec()); + let new_cid = BoundedVec::truncate_from(b"new cid".to_vec()); + let new_price = 20; + }: _(RawOrigin::Signed(caller), battlepass_id, Some(new_name.clone()), Some(new_cid.clone()), Some(new_price.clone())) + verify { + let battlepass = Battlepasses::::get(battlepass_id).unwrap(); + assert!(battlepass.name == new_name); + assert!(battlepass.cid == new_cid); + assert!(battlepass.price == new_price); + } + claim_battlepass { let caller: T::AccountId = get_funded_caller::()?; let org_id = get_org::(caller.clone()); @@ -146,6 +161,22 @@ benchmarks! { assert!(Rewards::::iter_keys().count() == 1); } + update_reward { + let caller: T::AccountId = get_funded_caller::()?; + let org_id = get_org::(caller.clone()); + let battlepass_id = get_battlepass::(caller.clone(), org_id); + let reward_id = get_reward::(caller.clone(), battlepass_id); + let new_name = BoundedVec::truncate_from(b"new name".to_vec()); + let new_cid = BoundedVec::truncate_from(b"new cid".to_vec()); + let new_transferable = false; + }: _(RawOrigin::Signed(caller), reward_id, Some(new_name.clone()), Some(new_cid.clone()), Some(new_transferable.clone())) + verify { + let reward = Rewards::::get(reward_id).unwrap(); + assert!(reward.name == new_name); + assert!(reward.cid == new_cid); + assert!(reward.transferable == new_transferable); + } + disable_reward { let caller: T::AccountId = get_funded_caller::()?; let org_id = get_org::(caller.clone()); diff --git a/battlepass/src/lib.rs b/battlepass/src/lib.rs index 35af3dc09..137d4a113 100644 --- a/battlepass/src/lib.rs +++ b/battlepass/src/lib.rs @@ -387,7 +387,7 @@ pub mod pallet { #[pallet::call_index(1)] - #[pallet::weight(10_000_000)] + #[pallet::weight(::WeightInfo::update_battlepass())] pub fn update_battlepass( origin: OriginFor, battlepass_id: T::Hash, @@ -596,7 +596,7 @@ pub mod pallet { #[pallet::call_index(7)] - #[pallet::weight(10_000_000)] + #[pallet::weight(::WeightInfo::update_reward())] pub fn update_reward( origin: OriginFor, reward_id: T::Hash, diff --git a/battlepass/src/weights.rs b/battlepass/src/weights.rs index 556cb6a55..3c210c79d 100644 --- a/battlepass/src/weights.rs +++ b/battlepass/src/weights.rs @@ -2,7 +2,7 @@ //! Autogenerated weights for gamedao_battlepass //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-02-10, STEPS: `20`, REPEAT: 10, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2023-02-17, STEPS: `20`, REPEAT: 10, LOW RANGE: `[]`, HIGH RANGE: `[]` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: None, DB CACHE: 1024 // Executed Command: @@ -27,11 +27,13 @@ use sp_std::marker::PhantomData; /// Weight functions needed for gamedao_battlepass. pub trait WeightInfo { fn create_battlepass() -> Weight; + fn update_battlepass() -> Weight; fn claim_battlepass() -> Weight; fn activate_battlepass() -> Weight; fn conclude_battlepass() -> Weight; fn set_points() -> Weight; fn create_reward() -> Weight; + fn update_reward() -> Weight; fn disable_reward() -> Weight; fn claim_reward() -> Weight; fn add_level() -> Weight; @@ -52,11 +54,21 @@ impl WeightInfo for SubstrateWeight { // Storage: Battlepass BattlepassStates (r:0 w:1) // Storage: Battlepass Battlepasses (r:0 w:1) fn create_battlepass() -> Weight { - // Minimum execution time: 68_000 nanoseconds. - Weight::from_ref_time(70_000_000) + // Minimum execution time: 69_000 nanoseconds. + Weight::from_ref_time(71_000_000) .saturating_add(T::DbWeight::get().reads(5)) .saturating_add(T::DbWeight::get().writes(7)) } + // Storage: Battlepass Battlepasses (r:1 w:1) + // Storage: Battlepass BattlepassStates (r:1 w:0) + // Storage: Control OrgStates (r:1 w:0) + // Storage: Control Orgs (r:1 w:0) + fn update_battlepass() -> Weight { + // Minimum execution time: 36_000 nanoseconds. + Weight::from_ref_time(37_000_000) + .saturating_add(T::DbWeight::get().reads(4)) + .saturating_add(T::DbWeight::get().writes(1)) + } // Storage: Battlepass Battlepasses (r:1 w:0) // Storage: Battlepass BattlepassStates (r:1 w:0) // Storage: Control OrgStates (r:1 w:0) @@ -69,8 +81,8 @@ impl WeightInfo for SubstrateWeight { // Storage: Uniques CollectionMaxSupply (r:1 w:0) // Storage: Uniques Account (r:0 w:1) fn claim_battlepass() -> Weight { - // Minimum execution time: 97_000 nanoseconds. - Weight::from_ref_time(99_000_000) + // Minimum execution time: 94_000 nanoseconds. + Weight::from_ref_time(98_000_000) .saturating_add(T::DbWeight::get().reads(11)) .saturating_add(T::DbWeight::get().writes(6)) } @@ -90,8 +102,8 @@ impl WeightInfo for SubstrateWeight { // Storage: Control Orgs (r:1 w:0) // Storage: Battlepass BattlepassInfoByOrg (r:1 w:1) fn conclude_battlepass() -> Weight { - // Minimum execution time: 39_000 nanoseconds. - Weight::from_ref_time(40_000_000) + // Minimum execution time: 37_000 nanoseconds. + Weight::from_ref_time(38_000_000) .saturating_add(T::DbWeight::get().reads(4)) .saturating_add(T::DbWeight::get().writes(2)) } @@ -103,7 +115,7 @@ impl WeightInfo for SubstrateWeight { // Storage: Battlepass Points (r:0 w:1) fn set_points() -> Weight { // Minimum execution time: 39_000 nanoseconds. - Weight::from_ref_time(40_000_000) + Weight::from_ref_time(39_000_000) .saturating_add(T::DbWeight::get().reads(5)) .saturating_add(T::DbWeight::get().writes(1)) } @@ -118,18 +130,30 @@ impl WeightInfo for SubstrateWeight { // Storage: Battlepass Rewards (r:0 w:1) // Storage: Battlepass RewardStates (r:0 w:1) fn create_reward() -> Weight { - // Minimum execution time: 73_000 nanoseconds. - Weight::from_ref_time(76_000_000) + // Minimum execution time: 72_000 nanoseconds. + Weight::from_ref_time(74_000_000) .saturating_add(T::DbWeight::get().reads(6)) .saturating_add(T::DbWeight::get().writes(6)) } + // Storage: Battlepass Rewards (r:1 w:1) + // Storage: Battlepass RewardStates (r:1 w:0) + // Storage: Battlepass Battlepasses (r:1 w:0) + // Storage: Battlepass BattlepassStates (r:1 w:0) + // Storage: Control OrgStates (r:1 w:0) + // Storage: Control Orgs (r:1 w:0) + fn update_reward() -> Weight { + // Minimum execution time: 43_000 nanoseconds. + Weight::from_ref_time(44_000_000) + .saturating_add(T::DbWeight::get().reads(6)) + .saturating_add(T::DbWeight::get().writes(1)) + } // Storage: Battlepass Rewards (r:1 w:0) // Storage: Battlepass RewardStates (r:1 w:1) // Storage: Battlepass Battlepasses (r:1 w:0) // Storage: Control Orgs (r:1 w:0) fn disable_reward() -> Weight { - // Minimum execution time: 37_000 nanoseconds. - Weight::from_ref_time(39_000_000) + // Minimum execution time: 36_000 nanoseconds. + Weight::from_ref_time(38_000_000) .saturating_add(T::DbWeight::get().reads(4)) .saturating_add(T::DbWeight::get().writes(1)) } @@ -150,8 +174,8 @@ impl WeightInfo for SubstrateWeight { // Storage: Uniques CollectionMaxSupply (r:1 w:0) // Storage: Uniques Account (r:0 w:1) fn claim_reward() -> Weight { - // Minimum execution time: 130_000 nanoseconds. - Weight::from_ref_time(132_000_000) + // Minimum execution time: 124_000 nanoseconds. + Weight::from_ref_time(126_000_000) .saturating_add(T::DbWeight::get().reads(18)) .saturating_add(T::DbWeight::get().writes(6)) } @@ -161,8 +185,8 @@ impl WeightInfo for SubstrateWeight { // Storage: Control Orgs (r:1 w:0) // Storage: Battlepass Levels (r:0 w:1) fn add_level() -> Weight { - // Minimum execution time: 35_000 nanoseconds. - Weight::from_ref_time(36_000_000) + // Minimum execution time: 37_000 nanoseconds. + Weight::from_ref_time(37_000_000) .saturating_add(T::DbWeight::get().reads(4)) .saturating_add(T::DbWeight::get().writes(1)) } @@ -172,8 +196,8 @@ impl WeightInfo for SubstrateWeight { // Storage: Control Orgs (r:1 w:0) // Storage: Battlepass Levels (r:1 w:1) fn remove_level() -> Weight { - // Minimum execution time: 39_000 nanoseconds. - Weight::from_ref_time(41_000_000) + // Minimum execution time: 40_000 nanoseconds. + Weight::from_ref_time(42_000_000) .saturating_add(T::DbWeight::get().reads(5)) .saturating_add(T::DbWeight::get().writes(1)) } @@ -184,7 +208,7 @@ impl WeightInfo for SubstrateWeight { // Storage: Battlepass BattlepassInfoByOrg (r:1 w:1) fn add_bot() -> Weight { // Minimum execution time: 38_000 nanoseconds. - Weight::from_ref_time(38_000_000) + Weight::from_ref_time(42_000_000) .saturating_add(T::DbWeight::get().reads(5)) .saturating_add(T::DbWeight::get().writes(1)) } @@ -202,11 +226,21 @@ impl WeightInfo for () { // Storage: Battlepass BattlepassStates (r:0 w:1) // Storage: Battlepass Battlepasses (r:0 w:1) fn create_battlepass() -> Weight { - // Minimum execution time: 68_000 nanoseconds. - Weight::from_ref_time(70_000_000) + // Minimum execution time: 69_000 nanoseconds. + Weight::from_ref_time(71_000_000) .saturating_add(RocksDbWeight::get().reads(5)) .saturating_add(RocksDbWeight::get().writes(7)) } + // Storage: Battlepass Battlepasses (r:1 w:1) + // Storage: Battlepass BattlepassStates (r:1 w:0) + // Storage: Control OrgStates (r:1 w:0) + // Storage: Control Orgs (r:1 w:0) + fn update_battlepass() -> Weight { + // Minimum execution time: 36_000 nanoseconds. + Weight::from_ref_time(37_000_000) + .saturating_add(RocksDbWeight::get().reads(4)) + .saturating_add(RocksDbWeight::get().writes(1)) + } // Storage: Battlepass Battlepasses (r:1 w:0) // Storage: Battlepass BattlepassStates (r:1 w:0) // Storage: Control OrgStates (r:1 w:0) @@ -219,8 +253,8 @@ impl WeightInfo for () { // Storage: Uniques CollectionMaxSupply (r:1 w:0) // Storage: Uniques Account (r:0 w:1) fn claim_battlepass() -> Weight { - // Minimum execution time: 97_000 nanoseconds. - Weight::from_ref_time(99_000_000) + // Minimum execution time: 94_000 nanoseconds. + Weight::from_ref_time(98_000_000) .saturating_add(RocksDbWeight::get().reads(11)) .saturating_add(RocksDbWeight::get().writes(6)) } @@ -240,8 +274,8 @@ impl WeightInfo for () { // Storage: Control Orgs (r:1 w:0) // Storage: Battlepass BattlepassInfoByOrg (r:1 w:1) fn conclude_battlepass() -> Weight { - // Minimum execution time: 39_000 nanoseconds. - Weight::from_ref_time(40_000_000) + // Minimum execution time: 37_000 nanoseconds. + Weight::from_ref_time(38_000_000) .saturating_add(RocksDbWeight::get().reads(4)) .saturating_add(RocksDbWeight::get().writes(2)) } @@ -253,7 +287,7 @@ impl WeightInfo for () { // Storage: Battlepass Points (r:0 w:1) fn set_points() -> Weight { // Minimum execution time: 39_000 nanoseconds. - Weight::from_ref_time(40_000_000) + Weight::from_ref_time(39_000_000) .saturating_add(RocksDbWeight::get().reads(5)) .saturating_add(RocksDbWeight::get().writes(1)) } @@ -268,18 +302,30 @@ impl WeightInfo for () { // Storage: Battlepass Rewards (r:0 w:1) // Storage: Battlepass RewardStates (r:0 w:1) fn create_reward() -> Weight { - // Minimum execution time: 73_000 nanoseconds. - Weight::from_ref_time(76_000_000) + // Minimum execution time: 72_000 nanoseconds. + Weight::from_ref_time(74_000_000) .saturating_add(RocksDbWeight::get().reads(6)) .saturating_add(RocksDbWeight::get().writes(6)) } + // Storage: Battlepass Rewards (r:1 w:1) + // Storage: Battlepass RewardStates (r:1 w:0) + // Storage: Battlepass Battlepasses (r:1 w:0) + // Storage: Battlepass BattlepassStates (r:1 w:0) + // Storage: Control OrgStates (r:1 w:0) + // Storage: Control Orgs (r:1 w:0) + fn update_reward() -> Weight { + // Minimum execution time: 43_000 nanoseconds. + Weight::from_ref_time(44_000_000) + .saturating_add(RocksDbWeight::get().reads(6)) + .saturating_add(RocksDbWeight::get().writes(1)) + } // Storage: Battlepass Rewards (r:1 w:0) // Storage: Battlepass RewardStates (r:1 w:1) // Storage: Battlepass Battlepasses (r:1 w:0) // Storage: Control Orgs (r:1 w:0) fn disable_reward() -> Weight { - // Minimum execution time: 37_000 nanoseconds. - Weight::from_ref_time(39_000_000) + // Minimum execution time: 36_000 nanoseconds. + Weight::from_ref_time(38_000_000) .saturating_add(RocksDbWeight::get().reads(4)) .saturating_add(RocksDbWeight::get().writes(1)) } @@ -300,8 +346,8 @@ impl WeightInfo for () { // Storage: Uniques CollectionMaxSupply (r:1 w:0) // Storage: Uniques Account (r:0 w:1) fn claim_reward() -> Weight { - // Minimum execution time: 130_000 nanoseconds. - Weight::from_ref_time(132_000_000) + // Minimum execution time: 124_000 nanoseconds. + Weight::from_ref_time(126_000_000) .saturating_add(RocksDbWeight::get().reads(18)) .saturating_add(RocksDbWeight::get().writes(6)) } @@ -311,8 +357,8 @@ impl WeightInfo for () { // Storage: Control Orgs (r:1 w:0) // Storage: Battlepass Levels (r:0 w:1) fn add_level() -> Weight { - // Minimum execution time: 35_000 nanoseconds. - Weight::from_ref_time(36_000_000) + // Minimum execution time: 37_000 nanoseconds. + Weight::from_ref_time(37_000_000) .saturating_add(RocksDbWeight::get().reads(4)) .saturating_add(RocksDbWeight::get().writes(1)) } @@ -322,8 +368,8 @@ impl WeightInfo for () { // Storage: Control Orgs (r:1 w:0) // Storage: Battlepass Levels (r:1 w:1) fn remove_level() -> Weight { - // Minimum execution time: 39_000 nanoseconds. - Weight::from_ref_time(41_000_000) + // Minimum execution time: 40_000 nanoseconds. + Weight::from_ref_time(42_000_000) .saturating_add(RocksDbWeight::get().reads(5)) .saturating_add(RocksDbWeight::get().writes(1)) } @@ -334,7 +380,7 @@ impl WeightInfo for () { // Storage: Battlepass BattlepassInfoByOrg (r:1 w:1) fn add_bot() -> Weight { // Minimum execution time: 38_000 nanoseconds. - Weight::from_ref_time(38_000_000) + Weight::from_ref_time(42_000_000) .saturating_add(RocksDbWeight::get().reads(5)) .saturating_add(RocksDbWeight::get().writes(1)) } From 7a0418793eba08f026b0fee1a8d391d3fd2db05e Mon Sep 17 00:00:00 2001 From: FiberMan Date: Mon, 20 Feb 2023 16:23:28 +0100 Subject: [PATCH 22/49] feat: extend bot privileges --- battlepass/src/benchmarking.rs | 2 +- battlepass/src/lib.rs | 68 ++++++++++------ battlepass/src/mock.rs | 2 + battlepass/src/tests.rs | 140 +++++++++++++++++++++++++++------ battlepass/src/weights.rs | 82 +++++++++---------- 5 files changed, 203 insertions(+), 91 deletions(-) diff --git a/battlepass/src/benchmarking.rs b/battlepass/src/benchmarking.rs index 7cc6e3560..13564bc45 100644 --- a/battlepass/src/benchmarking.rs +++ b/battlepass/src/benchmarking.rs @@ -196,7 +196,7 @@ benchmarks! { set_bpass_points::(caller.clone(), battlepass_id); set_bpass_level::(caller.clone(), battlepass_id); let reward_id = get_reward::(caller.clone(), battlepass_id); - }: _(RawOrigin::Signed(caller.clone()), reward_id) + }: _(RawOrigin::Signed(caller.clone()), reward_id, caller.clone()) verify { assert!(ClaimedRewards::::get(reward_id, caller).is_some()); } diff --git a/battlepass/src/lib.rs b/battlepass/src/lib.rs index 137d4a113..aa1f9aa70 100644 --- a/battlepass/src/lib.rs +++ b/battlepass/src/lib.rs @@ -348,8 +348,8 @@ pub mod pallet { impl Pallet { /// Creates a Battlepass. - /// May be called only by Organization owner. /// Also creates a new collection to store claimed Battlepass NFTs. + /// May be called only by Organization owner. /// /// Parameters: /// - `org_id`: ID of the Organization for which to create a Battlepass. @@ -385,7 +385,14 @@ pub mod pallet { Ok(()) } - + /// Updates Battlepass. + /// May be called only by Organization owner. + /// + /// Parameters: + /// - `battlepass_id`: ID of the Battlepass to update. + /// - `name`: Battlepass name. + /// - `cid`: IPFS content identifier. + /// - `price`: Price for the Battlepass subscription. #[pallet::call_index(1)] #[pallet::weight(::WeightInfo::update_battlepass())] pub fn update_battlepass( @@ -425,6 +432,7 @@ pub mod pallet { /// Claims the Battlepass-NFT for user who joined the Battlepass. /// This NFT may be used as a proof of a Battlepass membership. + /// May be called by user or by Organization owner. /// /// Parameters: /// - `battlepass_id`: ID of the Battlepass for which to claim NFT. @@ -444,10 +452,10 @@ pub mod pallet { ensure!(Self::check_battlepass_state(battlepass_id, BattlepassState::ACTIVE)?, Error::::BattlepassStateWrong); // check if Org is active ensure!(T::Control::is_org_active(&battlepass.org_id), Error::::OrgUnknownOrInactive); - // check permissions (prime, bot, self - temp) - ensure!(by_who == for_who || Self::is_prime(&battlepass.org_id, by_who.clone())?, Error::::AuthorizationError); // check if user is a member of organization ensure!(T::Control::is_org_member_active(&battlepass.org_id, &for_who), Error::::NotMember); + // check permissions (self, prime) + ensure!(by_who == for_who || Self::is_prime(&battlepass.org_id, by_who.clone())?, Error::::AuthorizationError); // check if Battlepass already claimed ensure!(!ClaimedBattlepasses::::contains_key(battlepass_id, for_who.clone()), Error::::BattlepassClaimed); @@ -520,7 +528,7 @@ pub mod pallet { /// Sets Battlepass Points for user. /// So far no information about users' achievements is stored on chain. A separate trusted service (Bot) /// should collect such info, process it, validate it and call this extrinsic if user's Points have been updated. - /// May be called only by Organization owner or by a specially dedicated for this purpose account. + /// May be called only by Organization owner or by a specially dedicated for this purpose account (Bot). /// /// Parameters: /// - `battlepass_id`: ID of the Battlepass. @@ -555,7 +563,7 @@ pub mod pallet { /// Creates a Reward Type for the Battlepass. /// Also creates a new collection to store claimed Reward NFTs. - /// May be called only by Organization owner. + /// May be called only by Organization owner or by a specially dedicated for this purpose account (Bot). /// /// Parameters: /// - `battlepass_id`: ID of the Battlepass to create a Reward for. @@ -576,7 +584,7 @@ pub mod pallet { level: u8, transferable: bool, ) -> DispatchResult { - let creator = ensure_signed(origin)?; + let caller = ensure_signed(origin)?; // check if Battlepass exists let battlepass = Self::get_battlepass(battlepass_id).ok_or(Error::::BattlepassUnknown)?; // check if Battlepass is not ended @@ -584,9 +592,10 @@ pub mod pallet { // check if Org is active ensure!(T::Control::is_org_active(&battlepass.org_id), Error::::OrgUnknownOrInactive); // check permissions (prime) - ensure!(Self::is_prime(&battlepass.org_id, creator.clone())?, Error::::AuthorizationError); + ensure!(Self::is_prime_or_bot(&battlepass.org_id, caller)?, Error::::AuthorizationError); - let collection_id = Self::create_collection(creator.clone(), max)?; + let prime = T::Control::org_prime_account(&battlepass.org_id).ok_or(Error::::OrgPrimeUnknown)?; + let collection_id = Self::create_collection(prime, max)?; let reward_id = Self::do_create_reward(battlepass_id, name, cid, level, transferable, collection_id)?; Self::deposit_event(Event::RewardCreated { reward_id, battlepass_id, level }); @@ -594,7 +603,14 @@ pub mod pallet { Ok(()) } - + /// Updates Reward type. + /// May be called only by Organization owner or by a specially dedicated for this purpose account (Bot). + /// + /// Parameters: + /// - `reward_id`: ID of the Reward Type to be updated. + /// - `name`: Name of the Reward. + /// - `cid`: IPFS content identifier. + /// - `transferable`: Specifies whether claimed Reward NFTs could be transferred (sold) to another account. #[pallet::call_index(7)] #[pallet::weight(::WeightInfo::update_reward())] pub fn update_reward( @@ -623,7 +639,7 @@ pub mod pallet { // check if Org is active ensure!(T::Control::is_org_active(&battlepass.org_id), Error::::OrgUnknownOrInactive); // check permissions (prime) - ensure!(Self::is_prime(&battlepass.org_id, caller.clone())?, Error::::AuthorizationError); + ensure!(Self::is_prime_or_bot(&battlepass.org_id, caller)?, Error::::AuthorizationError); reward.name = name.clone().unwrap(); reward.cid = cid.clone().unwrap(); @@ -638,7 +654,7 @@ pub mod pallet { /// Disables the Reward Type. /// After calling this extrinsic Reward Type state can not be changed any more. - /// May be called only by Organization owner. + /// May be called only by Organization owner or by a specially dedicated for this purpose account (Bot). /// /// Parameters: /// - `reward_id`: ID of the Reward Type to be disabled. @@ -648,7 +664,7 @@ pub mod pallet { origin: OriginFor, reward_id: T::Hash ) -> DispatchResult { - let creator = ensure_signed(origin)?; + let caller = ensure_signed(origin)?; // check if Reward exists let reward = Self::get_reward(reward_id).ok_or(Error::::RewardUnknown)?; // check if Reward is active @@ -656,7 +672,7 @@ pub mod pallet { // check if Battlepass exists let battlepass = Self::get_battlepass(reward.battlepass_id).ok_or(Error::::BattlepassUnknown)?; // check permissions (prime) - ensure!(Self::is_prime(&battlepass.org_id, creator.clone())?, Error::::AuthorizationError); + ensure!(Self::is_prime_or_bot(&battlepass.org_id, caller)?, Error::::AuthorizationError); let state = RewardState::INACTIVE; @@ -667,12 +683,13 @@ pub mod pallet { Ok(()) } - /// Claims a reward for caller. + /// Claims a reward for user. /// Mints a Reward NFT which may be used as a proof of a Reward posession. - /// Caller must be eligible for the Reward Type to be able to claim it. Eligibility criteria are: + /// User must be eligible for the Reward Type to be able to claim it. Eligibility criteria are: /// - must be an Organization member. /// - must be a Battlepass member (posess a valid Battlepass NFT). /// - required achievement Level must be reached. + /// May be called by user or by Organization owner or by a specially dedicated for this purpose account (Bot). /// /// Parameters: /// - `reward_id`: ID of the Reward Type to claim. @@ -682,14 +699,15 @@ pub mod pallet { pub fn claim_reward( origin: OriginFor, reward_id: T::Hash, + for_who: T::AccountId, ) -> DispatchResult { - let claimer = ensure_signed(origin)?; + let by_who = ensure_signed(origin)?; // check if Reward exists let reward = Self::get_reward(reward_id).ok_or(Error::::RewardUnknown)?; // check if Reward is active ensure!(Self::check_reward_state(reward_id, RewardState::ACTIVE)?, Error::::RewardInactive); // check if Reward has not been claimed yet - ensure!(!ClaimedRewards::::contains_key(&reward_id, &claimer), Error::::RewardClaimed); + ensure!(!ClaimedRewards::::contains_key(&reward_id, &for_who), Error::::RewardClaimed); // check if Battlepass exists let battlepass = Self::get_battlepass(&reward.battlepass_id).ok_or(Error::::BattlepassUnknown)?; // check if Battlepass in ACTIVE state @@ -697,22 +715,24 @@ pub mod pallet { // check if Org is active ensure!(T::Control::is_org_active(&battlepass.org_id), Error::::OrgUnknownOrInactive); // check if user is a member of organization - ensure!(T::Control::is_org_member_active(&battlepass.org_id, &claimer), Error::::NotMember); + ensure!(T::Control::is_org_member_active(&battlepass.org_id, &for_who), Error::::NotMember); + // check permissions (self, prime or bot) + ensure!(by_who == for_who || Self::is_prime_or_bot(&battlepass.org_id, by_who.clone())?, Error::::AuthorizationError); // check if user claimed Battlepass NFT - let bp_nft_id = Self::get_claimed_battlepass(reward.battlepass_id, &claimer).ok_or(Error::::BattlepassNotClaimed)?; + let bp_nft_id = Self::get_claimed_battlepass(reward.battlepass_id, &for_who).ok_or(Error::::BattlepassNotClaimed)?; // check if Battlepass NFT exists let bp_nft = pallet_rmrk_core::Pallet::::nfts(&battlepass.collection_id, bp_nft_id).ok_or(Error::::BattlepassNftUnknown)?; // validate Battlepass NFT ownership - ensure!(AccountIdOrCollectionNftTuple::AccountId(claimer.clone()) == bp_nft.owner, Error::::NotOwnNft); + ensure!(AccountIdOrCollectionNftTuple::AccountId(for_who.clone()) == bp_nft.owner, Error::::NotOwnNft); // validate Battlepass NFT metadata let metadata: String = BoundedVec::truncate_from(reward.battlepass_id.encode()); ensure!(metadata == bp_nft.metadata, Error::::BattlepassNftInvalid); // check if user has reached the required Level - ensure!(Self::is_level_reached(&reward.battlepass_id, &claimer, reward.level), Error::::LevelNotReached); + ensure!(Self::is_level_reached(&reward.battlepass_id, &for_who, reward.level), Error::::LevelNotReached); - let nft_id = Self::do_claim_reward(claimer.clone(), reward_id, reward.collection_id, reward.transferable)?; + let nft_id = Self::do_claim_reward(for_who.clone(), reward_id, reward.collection_id, reward.transferable)?; - Self::deposit_event(Event::RewardClaimed {reward_id, claimer, collection_id: reward.collection_id, nft_id} ); + Self::deposit_event(Event::RewardClaimed {reward_id, claimer: for_who, collection_id: reward.collection_id, nft_id} ); Ok(()) } diff --git a/battlepass/src/mock.rs b/battlepass/src/mock.rs index d01b8cbcd..96fc3ab7b 100644 --- a/battlepass/src/mock.rs +++ b/battlepass/src/mock.rs @@ -37,6 +37,8 @@ pub const PAYMENT_TOKEN_ID: CurrencyId = 2; // Org creator: pub const ALICE: AccountId = 11; +// Bot +pub const BOT: AccountId = 333; // Contributors: pub const BOB: AccountId = 12; pub const EVA: AccountId = 13; diff --git a/battlepass/src/tests.rs b/battlepass/src/tests.rs index e067915c5..043c55034 100644 --- a/battlepass/src/tests.rs +++ b/battlepass/src/tests.rs @@ -9,7 +9,7 @@ use crate::mock::{ new_test_ext, RuntimeOrigin as Origin, Test, //System, Battlepass, Control, RmrkCore, - ALICE, BOB, EVA, TOM, PROTOCOL_TOKEN_ID, PAYMENT_TOKEN_ID, DOLLARS, + ALICE, BOB, EVA, TOM, BOT, PROTOCOL_TOKEN_ID, PAYMENT_TOKEN_ID, DOLLARS, AccountId, StringLimit, //Event }; use gamedao_control::types::{AccessModel, FeeModel, OrgType, Org}; @@ -527,7 +527,6 @@ fn set_points_test() { let creator = ALICE; let not_creator = BOB; let not_member = EVA; - let bot = 333u32; // Should not set if Battlepass unknown assert_noop!( @@ -571,7 +570,7 @@ fn set_points_test() { // Should not set by Bot if Bot is not authorized assert_noop!( - Battlepass::set_points(Origin::signed(bot), battlepass_id, creator, 10), + Battlepass::set_points(Origin::signed(BOT), battlepass_id, creator, 10), Error::::AuthorizationError ); @@ -590,10 +589,10 @@ fn set_points_test() { // Should set points by Bot assert_ok!( - Battlepass::add_bot(Origin::signed(creator), battlepass_id, bot) + Battlepass::add_bot(Origin::signed(creator), battlepass_id, BOT) ); assert_ok!( - Battlepass::set_points(Origin::signed(bot), battlepass_id, not_creator, 20) + Battlepass::set_points(Origin::signed(BOT), battlepass_id, not_creator, 20) ); // Check if Points record updated assert_eq!(Points::::get(battlepass_id, not_creator) == 20, true); @@ -621,7 +620,6 @@ fn create_reward_test() { let creator = ALICE; let not_creator = BOB; let not_member = EVA; - // Should not create if Battlepass unknown assert_noop!( @@ -659,7 +657,10 @@ fn create_reward_test() { Battlepass::create_reward(Origin::signed(creator), battlepass_id, string(), string(), Some(1), 1, true) ); // Check if NFT collection created - assert_eq!(pallet_rmrk_core::Collections::::contains_key(1), true); + let collection = pallet_rmrk_core::Collections::::get(1); + assert_eq!(collection.is_some(), true); + // Check if collection owner is a Prime + assert_eq!(collection.unwrap().issuer, creator); // Check if Reward created let reward_id = get_reward_hash(battlepass_id, 1, true, 1); let reward = Rewards::::get(reward_id); @@ -676,7 +677,10 @@ fn create_reward_test() { Battlepass::create_reward(Origin::signed(creator), battlepass_id, string(), string(), Some(1), 1, true) ); // Check if NFT collection created - assert_eq!(pallet_rmrk_core::Collections::::contains_key(2), true); + let collection = pallet_rmrk_core::Collections::::get(2); + assert_eq!(collection.is_some(), true); + // Check if collection owner is a Prime + assert_eq!(collection.unwrap().issuer, creator); // Check if Reward created let reward_id = get_reward_hash(battlepass_id, 1, true, 2); let reward = Rewards::::get(reward_id); @@ -685,6 +689,32 @@ fn create_reward_test() { // Check if RewardState is ACTIVE assert_eq!(RewardStates::::get(reward_id), Some(RewardState::ACTIVE)); + // Should not create if Bot is not added + assert_noop!( + Battlepass::create_reward(Origin::signed(BOT), battlepass_id, string(), string(), Some(1), 1, true), + Error::::AuthorizationError + ); + + // Should create Reward by Bot + assert_ok!( + Battlepass::add_bot(Origin::signed(creator), battlepass_id, BOT) + ); + assert_ok!( + Battlepass::create_reward(Origin::signed(BOT), battlepass_id, string(), string(), Some(1), 1, true) + ); + // Check if NFT collection created + let collection = pallet_rmrk_core::Collections::::get(3); + assert_eq!(collection.is_some(), true); + // Check if collection owner is a Prime + assert_eq!(collection.unwrap().issuer, creator); + // Check if Reward created + let reward_id = get_reward_hash(battlepass_id, 1, true, 3); + let reward = Rewards::::get(reward_id); + assert_eq!(reward.is_some(), true); + assert_eq!(reward.unwrap().collection_id, 3); + // Check if RewardState is ACTIVE + assert_eq!(RewardStates::::get(reward_id), Some(RewardState::ACTIVE)); + // Should not create Reward if Battlepass state is ENDED assert_ok!( @@ -780,6 +810,25 @@ fn update_reward_test() { assert_eq!(updated.cid, new_cid.clone()); assert_eq!(updated.transferable, new_transferable.clone()); + // Should not update if Bot is not added + assert_noop!( + Battlepass::update_reward(Origin::signed(BOT), reward_id, Some(new_name.clone()), Some(new_cid.clone()), Some(true)), + Error::::AuthorizationError + ); + + // Should update Reward by Bot + assert_ok!( + Battlepass::add_bot(Origin::signed(creator), battlepass_id, BOT) + ); + assert_ok!( + Battlepass::update_reward(Origin::signed(BOT), reward_id, Some(new_name.clone()), Some(new_cid.clone()), Some(true)) + ); + // Check if Reward updated + let updated = Battlepass::get_reward(reward_id).unwrap(); + assert_eq!(updated.name, new_name.clone()); + assert_eq!(updated.cid, new_cid.clone()); + assert_eq!(updated.transferable, true); + // Should not update if Battlepass state is ENDED assert_ok!( Battlepass::activate_battlepass(Origin::signed(creator), battlepass_id) @@ -788,7 +837,7 @@ fn update_reward_test() { Battlepass::conclude_battlepass(Origin::signed(creator), battlepass_id) ); assert_noop!( - Battlepass::update_reward(Origin::signed(creator), reward_id, Some(new_name.clone()), Some(new_cid.clone()), Some(true)), + Battlepass::update_reward(Origin::signed(creator), reward_id, Some(new_name.clone()), Some(new_cid.clone()), Some(false)), Error::::BattlepassStateWrong ); @@ -797,7 +846,7 @@ fn update_reward_test() { Battlepass::disable_reward(Origin::signed(creator), reward_id) ); assert_noop!( - Battlepass::update_reward(Origin::signed(creator), reward_id, Some(new_name.clone()), Some(new_cid.clone()), Some(true)), + Battlepass::update_reward(Origin::signed(creator), reward_id, Some(new_name.clone()), Some(new_cid.clone()), Some(false)), Error::::RewardInactive ); @@ -813,6 +862,7 @@ fn disable_reward_test() { let battlepass_id = create_battlepass(org_id); let reward_id = create_reward(battlepass_id); let reward_id_2 = create_reward(battlepass_id); + let reward_id_3 = create_reward(battlepass_id); let wrong_id = ::Hashing::hash_of(&"123"); let creator = ALICE; let not_creator = BOB; @@ -861,6 +911,21 @@ fn disable_reward_test() { Error::::RewardInactive ); + // Should not disable if Bot is not added + assert_noop!( + Battlepass::disable_reward(Origin::signed(BOT), reward_id_3), + Error::::AuthorizationError + ); + + // Should disable Reward by Bot + assert_ok!( + Battlepass::add_bot(Origin::signed(creator), battlepass_id, BOT) + ); + assert_ok!( + Battlepass::disable_reward(Origin::signed(BOT), reward_id_3) + ); + // Check if RewardState is INACTIVE + assert_eq!(RewardStates::::get(reward_id_3), Some(RewardState::INACTIVE)); // Check events @@ -886,7 +951,7 @@ fn claim_reward_test() { // Should not claim if Reward unknown assert_noop!( - Battlepass::claim_reward(Origin::signed(creator), wrong_id), + Battlepass::claim_reward(Origin::signed(creator), wrong_id, creator), Error::::RewardUnknown ); @@ -896,7 +961,7 @@ fn claim_reward_test() { Battlepass::disable_reward(Origin::signed(creator), reward_id) ); assert_noop!( - Battlepass::claim_reward(Origin::signed(creator), reward_id), + Battlepass::claim_reward(Origin::signed(creator), reward_id, creator), Error::::RewardInactive ); @@ -908,14 +973,14 @@ fn claim_reward_test() { } } ); assert_noop!( - Battlepass::claim_reward(Origin::signed(creator), reward_id), + Battlepass::claim_reward(Origin::signed(creator), reward_id, creator), Error::::BattlepassUnknown ); // Should not claim if Battlepass state is DRAFT let reward_id = create_reward(battlepass_id); assert_noop!( - Battlepass::claim_reward(Origin::signed(creator), reward_id), + Battlepass::claim_reward(Origin::signed(creator), reward_id, creator), Error::::BattlepassStateWrong ); @@ -927,7 +992,7 @@ fn claim_reward_test() { Control::disable_org(Origin::signed(creator), org_id) ); assert_noop!( - Battlepass::claim_reward(Origin::signed(creator), reward_id), + Battlepass::claim_reward(Origin::signed(creator), reward_id, creator), Error::::OrgUnknownOrInactive ); assert_ok!( @@ -936,13 +1001,29 @@ fn claim_reward_test() { // Should not claim for non members assert_noop!( - Battlepass::claim_reward(Origin::signed(not_member), reward_id), + Battlepass::claim_reward(Origin::signed(creator), reward_id, not_member), Error::::NotMember ); + // Should not claim by Bot if Bot account was not added + assert_noop!( + Battlepass::claim_battlepass(Origin::signed(BOT), battlepass_id, creator), + Error::::AuthorizationError + ); + + // Should not claim for others if origin is not a Prime or Bot + assert_noop!( + Battlepass::claim_battlepass(Origin::signed(not_creator), battlepass_id, creator), + Error::::AuthorizationError + ); + assert_noop!( + Battlepass::claim_battlepass(Origin::signed(not_member), battlepass_id, creator), + Error::::AuthorizationError + ); + // Should not claim Reward if user didn't claim Battlepass assert_noop!( - Battlepass::claim_reward(Origin::signed(not_creator), reward_id), + Battlepass::claim_reward(Origin::signed(not_creator), reward_id, not_creator), Error::::BattlepassNotClaimed ); @@ -954,7 +1035,7 @@ fn claim_reward_test() { RmrkCore::burn_nft(Origin::signed(not_creator), 0, 0) ); assert_noop!( - Battlepass::claim_reward(Origin::signed(not_creator), reward_id), + Battlepass::claim_reward(Origin::signed(not_creator), reward_id, not_creator), Error::::BattlepassNftUnknown ); @@ -971,7 +1052,7 @@ fn claim_reward_test() { RmrkCore::send(Origin::signed(creator), 0, 1, AccountIdOrCollectionNftTuple::AccountId(not_member)) ); assert_noop!( - Battlepass::claim_reward(Origin::signed(creator), reward_id), + Battlepass::claim_reward(Origin::signed(creator), reward_id, creator), Error::::NotOwnNft ); @@ -985,7 +1066,7 @@ fn claim_reward_test() { } }); assert_noop!( - Battlepass::claim_reward(Origin::signed(not_creator_2), reward_id), + Battlepass::claim_reward(Origin::signed(not_creator_2), reward_id, not_creator_2), Error::::BattlepassNftInvalid ); @@ -994,7 +1075,7 @@ fn claim_reward_test() { Battlepass::claim_battlepass(Origin::signed(not_creator_3), battlepass_id, not_creator_3) ); assert_noop!( - Battlepass::claim_reward(Origin::signed(not_creator_3), reward_id), + Battlepass::claim_reward(Origin::signed(not_creator_3), reward_id, not_creator_3), Error::::LevelNotReached ); @@ -1006,14 +1087,14 @@ fn claim_reward_test() { Battlepass::add_level(Origin::signed(creator), battlepass_id, 1, 10) ); assert_ok!( - Battlepass::claim_reward(Origin::signed(not_creator_3), reward_id) + Battlepass::claim_reward(Origin::signed(not_creator_3), reward_id, not_creator_3) ); // Check if Reward claimed assert_eq!(ClaimedRewards::::contains_key(reward_id, not_creator_3), true); // Should not claim if Reward already claimed assert_noop!( - Battlepass::claim_reward(Origin::signed(not_creator_3), reward_id), + Battlepass::claim_reward(Origin::signed(not_creator_3), reward_id, not_creator_3), Error::::RewardClaimed ); @@ -1028,16 +1109,25 @@ fn claim_reward_test() { Battlepass::set_points(Origin::signed(creator), battlepass_id, not_creator_4, 10) ); assert_noop!( - Battlepass::claim_reward(Origin::signed(not_creator_4), reward_id), + Battlepass::claim_reward(Origin::signed(not_creator_4), reward_id, not_creator_4), pallet_rmrk_core::Error::::CollectionFullOrLocked ); + // Should claim Reward by Bot + let reward_id = create_reward(battlepass_id); + assert_ok!( + Battlepass::add_bot(Origin::signed(creator), battlepass_id, BOT) + ); + assert_ok!( + Battlepass::claim_reward(Origin::signed(BOT), reward_id, not_creator_4) + ); + // Should not claim if Battlepass state is ENDED assert_ok!( Battlepass::conclude_battlepass(Origin::signed(creator), battlepass_id) ); assert_noop!( - Battlepass::claim_reward(Origin::signed(not_creator_4), reward_id), + Battlepass::claim_reward(Origin::signed(not_creator_4), reward_id, not_creator_3), Error::::BattlepassStateWrong ); diff --git a/battlepass/src/weights.rs b/battlepass/src/weights.rs index 3c210c79d..9ba5d9f48 100644 --- a/battlepass/src/weights.rs +++ b/battlepass/src/weights.rs @@ -2,7 +2,7 @@ //! Autogenerated weights for gamedao_battlepass //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-02-17, STEPS: `20`, REPEAT: 10, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2023-02-20, STEPS: `20`, REPEAT: 10, LOW RANGE: `[]`, HIGH RANGE: `[]` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: None, DB CACHE: 1024 // Executed Command: @@ -54,8 +54,8 @@ impl WeightInfo for SubstrateWeight { // Storage: Battlepass BattlepassStates (r:0 w:1) // Storage: Battlepass Battlepasses (r:0 w:1) fn create_battlepass() -> Weight { - // Minimum execution time: 69_000 nanoseconds. - Weight::from_ref_time(71_000_000) + // Minimum execution time: 70_000 nanoseconds. + Weight::from_ref_time(72_000_000) .saturating_add(T::DbWeight::get().reads(5)) .saturating_add(T::DbWeight::get().writes(7)) } @@ -64,8 +64,8 @@ impl WeightInfo for SubstrateWeight { // Storage: Control OrgStates (r:1 w:0) // Storage: Control Orgs (r:1 w:0) fn update_battlepass() -> Weight { - // Minimum execution time: 36_000 nanoseconds. - Weight::from_ref_time(37_000_000) + // Minimum execution time: 35_000 nanoseconds. + Weight::from_ref_time(36_000_000) .saturating_add(T::DbWeight::get().reads(4)) .saturating_add(T::DbWeight::get().writes(1)) } @@ -82,7 +82,7 @@ impl WeightInfo for SubstrateWeight { // Storage: Uniques Account (r:0 w:1) fn claim_battlepass() -> Weight { // Minimum execution time: 94_000 nanoseconds. - Weight::from_ref_time(98_000_000) + Weight::from_ref_time(96_000_000) .saturating_add(T::DbWeight::get().reads(11)) .saturating_add(T::DbWeight::get().writes(6)) } @@ -92,8 +92,8 @@ impl WeightInfo for SubstrateWeight { // Storage: Control Orgs (r:1 w:0) // Storage: Battlepass BattlepassInfoByOrg (r:1 w:1) fn activate_battlepass() -> Weight { - // Minimum execution time: 41_000 nanoseconds. - Weight::from_ref_time(42_000_000) + // Minimum execution time: 40_000 nanoseconds. + Weight::from_ref_time(44_000_000) .saturating_add(T::DbWeight::get().reads(5)) .saturating_add(T::DbWeight::get().writes(2)) } @@ -115,7 +115,7 @@ impl WeightInfo for SubstrateWeight { // Storage: Battlepass Points (r:0 w:1) fn set_points() -> Weight { // Minimum execution time: 39_000 nanoseconds. - Weight::from_ref_time(39_000_000) + Weight::from_ref_time(41_000_000) .saturating_add(T::DbWeight::get().reads(5)) .saturating_add(T::DbWeight::get().writes(1)) } @@ -130,8 +130,8 @@ impl WeightInfo for SubstrateWeight { // Storage: Battlepass Rewards (r:0 w:1) // Storage: Battlepass RewardStates (r:0 w:1) fn create_reward() -> Weight { - // Minimum execution time: 72_000 nanoseconds. - Weight::from_ref_time(74_000_000) + // Minimum execution time: 74_000 nanoseconds. + Weight::from_ref_time(76_000_000) .saturating_add(T::DbWeight::get().reads(6)) .saturating_add(T::DbWeight::get().writes(6)) } @@ -142,7 +142,7 @@ impl WeightInfo for SubstrateWeight { // Storage: Control OrgStates (r:1 w:0) // Storage: Control Orgs (r:1 w:0) fn update_reward() -> Weight { - // Minimum execution time: 43_000 nanoseconds. + // Minimum execution time: 41_000 nanoseconds. Weight::from_ref_time(44_000_000) .saturating_add(T::DbWeight::get().reads(6)) .saturating_add(T::DbWeight::get().writes(1)) @@ -153,7 +153,7 @@ impl WeightInfo for SubstrateWeight { // Storage: Control Orgs (r:1 w:0) fn disable_reward() -> Weight { // Minimum execution time: 36_000 nanoseconds. - Weight::from_ref_time(38_000_000) + Weight::from_ref_time(37_000_000) .saturating_add(T::DbWeight::get().reads(4)) .saturating_add(T::DbWeight::get().writes(1)) } @@ -174,8 +174,8 @@ impl WeightInfo for SubstrateWeight { // Storage: Uniques CollectionMaxSupply (r:1 w:0) // Storage: Uniques Account (r:0 w:1) fn claim_reward() -> Weight { - // Minimum execution time: 124_000 nanoseconds. - Weight::from_ref_time(126_000_000) + // Minimum execution time: 126_000 nanoseconds. + Weight::from_ref_time(133_000_000) .saturating_add(T::DbWeight::get().reads(18)) .saturating_add(T::DbWeight::get().writes(6)) } @@ -185,8 +185,8 @@ impl WeightInfo for SubstrateWeight { // Storage: Control Orgs (r:1 w:0) // Storage: Battlepass Levels (r:0 w:1) fn add_level() -> Weight { - // Minimum execution time: 37_000 nanoseconds. - Weight::from_ref_time(37_000_000) + // Minimum execution time: 36_000 nanoseconds. + Weight::from_ref_time(36_000_000) .saturating_add(T::DbWeight::get().reads(4)) .saturating_add(T::DbWeight::get().writes(1)) } @@ -196,8 +196,8 @@ impl WeightInfo for SubstrateWeight { // Storage: Control Orgs (r:1 w:0) // Storage: Battlepass Levels (r:1 w:1) fn remove_level() -> Weight { - // Minimum execution time: 40_000 nanoseconds. - Weight::from_ref_time(42_000_000) + // Minimum execution time: 38_000 nanoseconds. + Weight::from_ref_time(39_000_000) .saturating_add(T::DbWeight::get().reads(5)) .saturating_add(T::DbWeight::get().writes(1)) } @@ -207,8 +207,8 @@ impl WeightInfo for SubstrateWeight { // Storage: Control Orgs (r:1 w:0) // Storage: Battlepass BattlepassInfoByOrg (r:1 w:1) fn add_bot() -> Weight { - // Minimum execution time: 38_000 nanoseconds. - Weight::from_ref_time(42_000_000) + // Minimum execution time: 35_000 nanoseconds. + Weight::from_ref_time(37_000_000) .saturating_add(T::DbWeight::get().reads(5)) .saturating_add(T::DbWeight::get().writes(1)) } @@ -226,8 +226,8 @@ impl WeightInfo for () { // Storage: Battlepass BattlepassStates (r:0 w:1) // Storage: Battlepass Battlepasses (r:0 w:1) fn create_battlepass() -> Weight { - // Minimum execution time: 69_000 nanoseconds. - Weight::from_ref_time(71_000_000) + // Minimum execution time: 70_000 nanoseconds. + Weight::from_ref_time(72_000_000) .saturating_add(RocksDbWeight::get().reads(5)) .saturating_add(RocksDbWeight::get().writes(7)) } @@ -236,8 +236,8 @@ impl WeightInfo for () { // Storage: Control OrgStates (r:1 w:0) // Storage: Control Orgs (r:1 w:0) fn update_battlepass() -> Weight { - // Minimum execution time: 36_000 nanoseconds. - Weight::from_ref_time(37_000_000) + // Minimum execution time: 35_000 nanoseconds. + Weight::from_ref_time(36_000_000) .saturating_add(RocksDbWeight::get().reads(4)) .saturating_add(RocksDbWeight::get().writes(1)) } @@ -254,7 +254,7 @@ impl WeightInfo for () { // Storage: Uniques Account (r:0 w:1) fn claim_battlepass() -> Weight { // Minimum execution time: 94_000 nanoseconds. - Weight::from_ref_time(98_000_000) + Weight::from_ref_time(96_000_000) .saturating_add(RocksDbWeight::get().reads(11)) .saturating_add(RocksDbWeight::get().writes(6)) } @@ -264,8 +264,8 @@ impl WeightInfo for () { // Storage: Control Orgs (r:1 w:0) // Storage: Battlepass BattlepassInfoByOrg (r:1 w:1) fn activate_battlepass() -> Weight { - // Minimum execution time: 41_000 nanoseconds. - Weight::from_ref_time(42_000_000) + // Minimum execution time: 40_000 nanoseconds. + Weight::from_ref_time(44_000_000) .saturating_add(RocksDbWeight::get().reads(5)) .saturating_add(RocksDbWeight::get().writes(2)) } @@ -287,7 +287,7 @@ impl WeightInfo for () { // Storage: Battlepass Points (r:0 w:1) fn set_points() -> Weight { // Minimum execution time: 39_000 nanoseconds. - Weight::from_ref_time(39_000_000) + Weight::from_ref_time(41_000_000) .saturating_add(RocksDbWeight::get().reads(5)) .saturating_add(RocksDbWeight::get().writes(1)) } @@ -302,8 +302,8 @@ impl WeightInfo for () { // Storage: Battlepass Rewards (r:0 w:1) // Storage: Battlepass RewardStates (r:0 w:1) fn create_reward() -> Weight { - // Minimum execution time: 72_000 nanoseconds. - Weight::from_ref_time(74_000_000) + // Minimum execution time: 74_000 nanoseconds. + Weight::from_ref_time(76_000_000) .saturating_add(RocksDbWeight::get().reads(6)) .saturating_add(RocksDbWeight::get().writes(6)) } @@ -314,7 +314,7 @@ impl WeightInfo for () { // Storage: Control OrgStates (r:1 w:0) // Storage: Control Orgs (r:1 w:0) fn update_reward() -> Weight { - // Minimum execution time: 43_000 nanoseconds. + // Minimum execution time: 41_000 nanoseconds. Weight::from_ref_time(44_000_000) .saturating_add(RocksDbWeight::get().reads(6)) .saturating_add(RocksDbWeight::get().writes(1)) @@ -325,7 +325,7 @@ impl WeightInfo for () { // Storage: Control Orgs (r:1 w:0) fn disable_reward() -> Weight { // Minimum execution time: 36_000 nanoseconds. - Weight::from_ref_time(38_000_000) + Weight::from_ref_time(37_000_000) .saturating_add(RocksDbWeight::get().reads(4)) .saturating_add(RocksDbWeight::get().writes(1)) } @@ -346,8 +346,8 @@ impl WeightInfo for () { // Storage: Uniques CollectionMaxSupply (r:1 w:0) // Storage: Uniques Account (r:0 w:1) fn claim_reward() -> Weight { - // Minimum execution time: 124_000 nanoseconds. - Weight::from_ref_time(126_000_000) + // Minimum execution time: 126_000 nanoseconds. + Weight::from_ref_time(133_000_000) .saturating_add(RocksDbWeight::get().reads(18)) .saturating_add(RocksDbWeight::get().writes(6)) } @@ -357,8 +357,8 @@ impl WeightInfo for () { // Storage: Control Orgs (r:1 w:0) // Storage: Battlepass Levels (r:0 w:1) fn add_level() -> Weight { - // Minimum execution time: 37_000 nanoseconds. - Weight::from_ref_time(37_000_000) + // Minimum execution time: 36_000 nanoseconds. + Weight::from_ref_time(36_000_000) .saturating_add(RocksDbWeight::get().reads(4)) .saturating_add(RocksDbWeight::get().writes(1)) } @@ -368,8 +368,8 @@ impl WeightInfo for () { // Storage: Control Orgs (r:1 w:0) // Storage: Battlepass Levels (r:1 w:1) fn remove_level() -> Weight { - // Minimum execution time: 40_000 nanoseconds. - Weight::from_ref_time(42_000_000) + // Minimum execution time: 38_000 nanoseconds. + Weight::from_ref_time(39_000_000) .saturating_add(RocksDbWeight::get().reads(5)) .saturating_add(RocksDbWeight::get().writes(1)) } @@ -379,8 +379,8 @@ impl WeightInfo for () { // Storage: Control Orgs (r:1 w:0) // Storage: Battlepass BattlepassInfoByOrg (r:1 w:1) fn add_bot() -> Weight { - // Minimum execution time: 38_000 nanoseconds. - Weight::from_ref_time(42_000_000) + // Minimum execution time: 35_000 nanoseconds. + Weight::from_ref_time(37_000_000) .saturating_add(RocksDbWeight::get().reads(5)) .saturating_add(RocksDbWeight::get().writes(1)) } From 4e320d8bef25a29378cadc3a10b03248bcf305cb Mon Sep 17 00:00:00 2001 From: FiberMan Date: Tue, 21 Feb 2023 12:30:01 +0100 Subject: [PATCH 23/49] feat: claim battlepass by bot --- battlepass/src/benchmarking.rs | 12 ++++++++++-- battlepass/src/lib.rs | 4 ++-- battlepass/src/tests.rs | 30 ++++++++++++++++++++++++++---- 3 files changed, 38 insertions(+), 8 deletions(-) diff --git a/battlepass/src/benchmarking.rs b/battlepass/src/benchmarking.rs index 13564bc45..1ac3d78e8 100644 --- a/battlepass/src/benchmarking.rs +++ b/battlepass/src/benchmarking.rs @@ -84,6 +84,10 @@ fn get_reward(caller: T::AccountId, battlepass_id: T::Hash) -> T::Has ::Hashing::hash_of(&reward) } +fn set_bot(creator: T::AccountId, battlepass_id: T::Hash, bot: T::AccountId) { + let _ = BPass::::add_bot(RawOrigin::Signed(creator.clone()).into(), battlepass_id, bot); +} + benchmarks! { @@ -113,10 +117,12 @@ benchmarks! { claim_battlepass { let caller: T::AccountId = get_funded_caller::()?; + let bot: T::AccountId = get_funded_caller::()?; let org_id = get_org::(caller.clone()); let battlepass_id = get_battlepass::(caller.clone(), org_id); activate_bpass::(caller.clone(), battlepass_id); - }: _(RawOrigin::Signed(caller.clone()), battlepass_id, caller.clone()) + set_bot::(caller.clone(), battlepass_id, bot.clone()); + }: _(RawOrigin::Signed(bot), battlepass_id, caller.clone()) verify { assert!(ClaimedBattlepasses::::get(battlepass_id, caller).is_some()); } @@ -189,14 +195,16 @@ benchmarks! { claim_reward { let caller: T::AccountId = get_funded_caller::()?; + let bot: T::AccountId = get_funded_caller::()?; let org_id = get_org::(caller.clone()); let battlepass_id = get_battlepass::(caller.clone(), org_id); activate_bpass::(caller.clone(), battlepass_id); claim_bpass::(caller.clone(), battlepass_id); set_bpass_points::(caller.clone(), battlepass_id); set_bpass_level::(caller.clone(), battlepass_id); + set_bot::(caller.clone(), battlepass_id, bot.clone()); let reward_id = get_reward::(caller.clone(), battlepass_id); - }: _(RawOrigin::Signed(caller.clone()), reward_id, caller.clone()) + }: _(RawOrigin::Signed(bot), reward_id, caller.clone()) verify { assert!(ClaimedRewards::::get(reward_id, caller).is_some()); } diff --git a/battlepass/src/lib.rs b/battlepass/src/lib.rs index aa1f9aa70..d10e637bd 100644 --- a/battlepass/src/lib.rs +++ b/battlepass/src/lib.rs @@ -432,7 +432,7 @@ pub mod pallet { /// Claims the Battlepass-NFT for user who joined the Battlepass. /// This NFT may be used as a proof of a Battlepass membership. - /// May be called by user or by Organization owner. + /// May be called by user or by Organization owner or by a specially dedicated for this purpose account (Bot). /// /// Parameters: /// - `battlepass_id`: ID of the Battlepass for which to claim NFT. @@ -455,7 +455,7 @@ pub mod pallet { // check if user is a member of organization ensure!(T::Control::is_org_member_active(&battlepass.org_id, &for_who), Error::::NotMember); // check permissions (self, prime) - ensure!(by_who == for_who || Self::is_prime(&battlepass.org_id, by_who.clone())?, Error::::AuthorizationError); + ensure!(by_who == for_who || Self::is_prime_or_bot(&battlepass.org_id, by_who.clone())?, Error::::AuthorizationError); // check if Battlepass already claimed ensure!(!ClaimedBattlepasses::::contains_key(battlepass_id, for_who.clone()), Error::::BattlepassClaimed); diff --git a/battlepass/src/tests.rs b/battlepass/src/tests.rs index 043c55034..0af3b3936 100644 --- a/battlepass/src/tests.rs +++ b/battlepass/src/tests.rs @@ -430,9 +430,11 @@ fn claim_battlepass_test() { let creator = ALICE; let not_creator = BOB; let not_creator_2 = TOM; + let not_creator_3 = 22u32; let not_member = EVA; add_member(org_id, not_creator); add_member(org_id, not_creator_2); + add_member(org_id, not_creator_3); // Should not claim unknown Battlepass assert_noop!( @@ -461,6 +463,12 @@ fn claim_battlepass_test() { Control::enable_org(Origin::signed(creator), org_id) ); + // Should not claim by Bot if Bot account was not added + assert_noop!( + Battlepass::claim_battlepass(Origin::signed(BOT), battlepass_id, creator), + Error::::AuthorizationError + ); + // Should not claim for others if origin is not a Prime assert_noop!( Battlepass::claim_battlepass(Origin::signed(not_creator), battlepass_id, creator), @@ -477,7 +485,7 @@ fn claim_battlepass_test() { Error::::NotMember ); - // Should claim for others if origin is a Prime + // Should claim for others by Prime assert_ok!( Battlepass::claim_battlepass(Origin::signed(creator), battlepass_id, not_creator) ); @@ -505,6 +513,20 @@ fn claim_battlepass_test() { Error::::BattlepassClaimed ); + // Should claim for others by Bot + assert_ok!( + Battlepass::add_bot(Origin::signed(creator), battlepass_id, BOT) + ); + assert_ok!( + Battlepass::claim_battlepass(Origin::signed(BOT), battlepass_id, not_creator_3) + ); + // Check if ClaimedBattlepasses record created + let nft_id = ClaimedBattlepasses::::get(battlepass_id, not_creator_3); + assert_eq!(nft_id.is_some(), true); + assert_eq!(nft_id.unwrap(), 2); + // Check if NFT minted + assert_eq!(pallet_rmrk_core::Nfts::::contains_key(0, 2), true); + // Should not claim Battlepass in ENDED state assert_ok!( Battlepass::conclude_battlepass(Origin::signed(creator), battlepass_id) @@ -1007,17 +1029,17 @@ fn claim_reward_test() { // Should not claim by Bot if Bot account was not added assert_noop!( - Battlepass::claim_battlepass(Origin::signed(BOT), battlepass_id, creator), + Battlepass::claim_reward(Origin::signed(BOT), reward_id, creator), Error::::AuthorizationError ); // Should not claim for others if origin is not a Prime or Bot assert_noop!( - Battlepass::claim_battlepass(Origin::signed(not_creator), battlepass_id, creator), + Battlepass::claim_reward(Origin::signed(not_creator), reward_id, creator), Error::::AuthorizationError ); assert_noop!( - Battlepass::claim_battlepass(Origin::signed(not_member), battlepass_id, creator), + Battlepass::claim_reward(Origin::signed(not_member), reward_id, creator), Error::::AuthorizationError ); From d5370b753a5209164056063587037906ab919640 Mon Sep 17 00:00:00 2001 From: FiberMan Date: Wed, 22 Feb 2023 14:19:19 +0100 Subject: [PATCH 24/49] feat: add, remove levels by bot --- battlepass/src/lib.rs | 8 ++++---- battlepass/src/tests.rs | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/battlepass/src/lib.rs b/battlepass/src/lib.rs index d10e637bd..25203d333 100644 --- a/battlepass/src/lib.rs +++ b/battlepass/src/lib.rs @@ -738,7 +738,7 @@ pub mod pallet { } /// Adds a new achievement Level. - /// May be called only by Organization owner. + /// May be called only by Organization owner or by a specially dedicated for this purpose account (Bot). /// /// Parameters: /// - `battlepass_id`: ID of the Battlepass to add a Level for. @@ -760,7 +760,7 @@ pub mod pallet { // check if Org is active ensure!(T::Control::is_org_active(&battlepass.org_id), Error::::OrgUnknownOrInactive); // check permissions (prime) - ensure!(Self::is_prime(&battlepass.org_id, sender.clone())?, Error::::AuthorizationError); + ensure!(Self::is_prime_or_bot(&battlepass.org_id, sender.clone())?, Error::::AuthorizationError); Levels::::insert(battlepass_id, level, points); @@ -770,7 +770,7 @@ pub mod pallet { } /// Removes achievement Level. - /// May be called only by Organization owner. + /// May be called only by Organization owner or by a specially dedicated for this purpose account (Bot). /// /// Parameters: /// - `battlepass_id`: ID of the Battlepass to remove a Level for. @@ -790,7 +790,7 @@ pub mod pallet { // check if Org is active ensure!(T::Control::is_org_active(&battlepass.org_id), Error::::OrgUnknownOrInactive); // check permissions (prime) - ensure!(Self::is_prime(&battlepass.org_id, sender.clone())?, Error::::AuthorizationError); + ensure!(Self::is_prime_or_bot(&battlepass.org_id, sender.clone())?, Error::::AuthorizationError); // check if Level exists ensure!(Levels::::contains_key(battlepass_id, level), Error::::LevelUnknown); diff --git a/battlepass/src/tests.rs b/battlepass/src/tests.rs index 0af3b3936..fdb6e7aa6 100644 --- a/battlepass/src/tests.rs +++ b/battlepass/src/tests.rs @@ -1214,6 +1214,22 @@ fn add_level_test() { // Check if Level added assert_eq!(Levels::::contains_key(battlepass_id, 2), true); + // Should not add Level by Bot if Bot account was not added + assert_noop!( + Battlepass::add_level(Origin::signed(BOT), battlepass_id, 3, 10), + Error::::AuthorizationError + ); + + // Should add Level by Bot + assert_ok!( + Battlepass::add_bot(Origin::signed(creator), battlepass_id, BOT) + ); + assert_ok!( + Battlepass::add_level(Origin::signed(BOT), battlepass_id, 3, 10) + ); + // Check if Level added + assert_eq!(Levels::::contains_key(battlepass_id, 3), true); + // Should not add if Battlepass in ENDED state assert_ok!( Battlepass::conclude_battlepass(Origin::signed(creator), battlepass_id) @@ -1298,6 +1314,28 @@ fn remove_level_test() { // Check if Level removed assert_eq!(Levels::::contains_key(battlepass_id, 2), false); + + // Should not remove Level by Bot if Bot account was not added + assert_noop!( + Battlepass::remove_level(Origin::signed(BOT), battlepass_id, 3), + Error::::AuthorizationError + ); + + // Should remove Level by Bot + assert_ok!( + Battlepass::add_bot(Origin::signed(creator), battlepass_id, BOT) + ); + assert_ok!( + Battlepass::add_level(Origin::signed(creator), battlepass_id, 3, 10) + ); + assert_eq!(Levels::::contains_key(battlepass_id, 3), true); + assert_ok!( + Battlepass::remove_level(Origin::signed(BOT), battlepass_id, 3) + ); + // Check if Level added + assert_eq!(Levels::::contains_key(battlepass_id, 3), false); + + // Should not remove if Battlepass in ENDED state assert_ok!( Battlepass::conclude_battlepass(Origin::signed(creator), battlepass_id) From a76d9966fae53b8947ac29d7888354281c79643d Mon Sep 17 00:00:00 2001 From: FiberMan Date: Wed, 22 Feb 2023 15:12:12 +0100 Subject: [PATCH 25/49] update benchmarks --- battlepass/src/benchmarking.rs | 30 ++++--- battlepass/src/weights.rs | 142 +++++++++++++++++++-------------- 2 files changed, 102 insertions(+), 70 deletions(-) diff --git a/battlepass/src/benchmarking.rs b/battlepass/src/benchmarking.rs index 1ac3d78e8..5fd040624 100644 --- a/battlepass/src/benchmarking.rs +++ b/battlepass/src/benchmarking.rs @@ -3,7 +3,7 @@ use super::*; use crate::Pallet as BPass; -use frame_benchmarking::{benchmarks, impl_benchmark_test_suite, whitelisted_caller}; +use frame_benchmarking::{benchmarks, impl_benchmark_test_suite, whitelisted_caller, account}; use frame_system::RawOrigin; use sp_runtime::{DispatchError, traits::SaturatedConversion}; use sp_std::vec; @@ -117,7 +117,7 @@ benchmarks! { claim_battlepass { let caller: T::AccountId = get_funded_caller::()?; - let bot: T::AccountId = get_funded_caller::()?; + let bot: T::AccountId = account("bot", 0, 0); let org_id = get_org::(caller.clone()); let battlepass_id = get_battlepass::(caller.clone(), org_id); activate_bpass::(caller.clone(), battlepass_id); @@ -148,34 +148,40 @@ benchmarks! { set_points { let caller: T::AccountId = get_funded_caller::()?; + let bot: T::AccountId = account("bot", 0, 0); let org_id = get_org::(caller.clone()); let battlepass_id = get_battlepass::(caller.clone(), org_id); activate_bpass::(caller.clone(), battlepass_id); - }: _(RawOrigin::Signed(caller.clone()), battlepass_id, caller.clone(), 10) + set_bot::(caller.clone(), battlepass_id, bot.clone()); + }: _(RawOrigin::Signed(bot), battlepass_id, caller.clone(), 10) verify { assert!(Points::::get(battlepass_id, caller) == 10); } create_reward { let caller: T::AccountId = get_funded_caller::()?; + let bot: T::AccountId = account("bot", 0, 0); let org_id = get_org::(caller.clone()); let battlepass_id = get_battlepass::(caller.clone(), org_id); let str = BoundedVec::truncate_from(vec![1,2]); activate_bpass::(caller.clone(), battlepass_id); - }: _(RawOrigin::Signed(caller), battlepass_id, str.clone(), str.clone(), Some(10), 1, false) + set_bot::(caller.clone(), battlepass_id, bot.clone()); + }: _(RawOrigin::Signed(bot), battlepass_id, str.clone(), str.clone(), Some(10), 1, false) verify { assert!(Rewards::::iter_keys().count() == 1); } update_reward { let caller: T::AccountId = get_funded_caller::()?; + let bot: T::AccountId = account("bot", 0, 0); let org_id = get_org::(caller.clone()); let battlepass_id = get_battlepass::(caller.clone(), org_id); let reward_id = get_reward::(caller.clone(), battlepass_id); let new_name = BoundedVec::truncate_from(b"new name".to_vec()); let new_cid = BoundedVec::truncate_from(b"new cid".to_vec()); let new_transferable = false; - }: _(RawOrigin::Signed(caller), reward_id, Some(new_name.clone()), Some(new_cid.clone()), Some(new_transferable.clone())) + set_bot::(caller.clone(), battlepass_id, bot.clone()); + }: _(RawOrigin::Signed(bot), reward_id, Some(new_name.clone()), Some(new_cid.clone()), Some(new_transferable.clone())) verify { let reward = Rewards::::get(reward_id).unwrap(); assert!(reward.name == new_name); @@ -185,17 +191,19 @@ benchmarks! { disable_reward { let caller: T::AccountId = get_funded_caller::()?; + let bot: T::AccountId = account("bot", 0, 0); let org_id = get_org::(caller.clone()); let battlepass_id = get_battlepass::(caller.clone(), org_id); let reward_id = get_reward::(caller.clone(), battlepass_id); - }: _(RawOrigin::Signed(caller), reward_id) + set_bot::(caller.clone(), battlepass_id, bot.clone()); + }: _(RawOrigin::Signed(bot), reward_id) verify { assert!(RewardStates::::get(reward_id) == Some(RewardState::INACTIVE)); } claim_reward { let caller: T::AccountId = get_funded_caller::()?; - let bot: T::AccountId = get_funded_caller::()?; + let bot: T::AccountId = account("bot", 0, 0); let org_id = get_org::(caller.clone()); let battlepass_id = get_battlepass::(caller.clone(), org_id); activate_bpass::(caller.clone(), battlepass_id); @@ -211,19 +219,23 @@ benchmarks! { add_level { let caller: T::AccountId = get_funded_caller::()?; + let bot: T::AccountId = account("bot", 0, 0); let org_id = get_org::(caller.clone()); let battlepass_id = get_battlepass::(caller.clone(), org_id); - }: _(RawOrigin::Signed(caller.clone()), battlepass_id, 1, 10) + set_bot::(caller.clone(), battlepass_id, bot.clone()); + }: _(RawOrigin::Signed(bot), battlepass_id, 1, 10) verify { assert!(Levels::::get(battlepass_id, 1) == Some(10)); } remove_level { let caller: T::AccountId = get_funded_caller::()?; + let bot: T::AccountId = account("bot", 0, 0); let org_id = get_org::(caller.clone()); let battlepass_id = get_battlepass::(caller.clone(), org_id); set_bpass_level::(caller.clone(), battlepass_id); - }: _(RawOrigin::Signed(caller.clone()), battlepass_id, 1) + set_bot::(caller.clone(), battlepass_id, bot.clone()); + }: _(RawOrigin::Signed(bot), battlepass_id, 1) verify { assert!(Levels::::get(battlepass_id, 1) == None); } diff --git a/battlepass/src/weights.rs b/battlepass/src/weights.rs index 9ba5d9f48..0ff0db9a9 100644 --- a/battlepass/src/weights.rs +++ b/battlepass/src/weights.rs @@ -2,7 +2,7 @@ //! Autogenerated weights for gamedao_battlepass //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-02-20, STEPS: `20`, REPEAT: 10, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2023-02-22, STEPS: `20`, REPEAT: 10, LOW RANGE: `[]`, HIGH RANGE: `[]` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: None, DB CACHE: 1024 // Executed Command: @@ -54,8 +54,8 @@ impl WeightInfo for SubstrateWeight { // Storage: Battlepass BattlepassStates (r:0 w:1) // Storage: Battlepass Battlepasses (r:0 w:1) fn create_battlepass() -> Weight { - // Minimum execution time: 70_000 nanoseconds. - Weight::from_ref_time(72_000_000) + // Minimum execution time: 69_000 nanoseconds. + Weight::from_ref_time(70_000_000) .saturating_add(T::DbWeight::get().reads(5)) .saturating_add(T::DbWeight::get().writes(7)) } @@ -64,8 +64,8 @@ impl WeightInfo for SubstrateWeight { // Storage: Control OrgStates (r:1 w:0) // Storage: Control Orgs (r:1 w:0) fn update_battlepass() -> Weight { - // Minimum execution time: 35_000 nanoseconds. - Weight::from_ref_time(36_000_000) + // Minimum execution time: 37_000 nanoseconds. + Weight::from_ref_time(38_000_000) .saturating_add(T::DbWeight::get().reads(4)) .saturating_add(T::DbWeight::get().writes(1)) } @@ -73,6 +73,8 @@ impl WeightInfo for SubstrateWeight { // Storage: Battlepass BattlepassStates (r:1 w:0) // Storage: Control OrgStates (r:1 w:0) // Storage: Control MemberStates (r:1 w:0) + // Storage: Control Orgs (r:1 w:0) + // Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) // Storage: Battlepass ClaimedBattlepasses (r:2 w:1) // Storage: RmrkCore Nfts (r:1 w:1) // Storage: RmrkCore Collections (r:1 w:1) @@ -81,9 +83,9 @@ impl WeightInfo for SubstrateWeight { // Storage: Uniques CollectionMaxSupply (r:1 w:0) // Storage: Uniques Account (r:0 w:1) fn claim_battlepass() -> Weight { - // Minimum execution time: 94_000 nanoseconds. - Weight::from_ref_time(96_000_000) - .saturating_add(T::DbWeight::get().reads(11)) + // Minimum execution time: 102_000 nanoseconds. + Weight::from_ref_time(105_000_000) + .saturating_add(T::DbWeight::get().reads(13)) .saturating_add(T::DbWeight::get().writes(6)) } // Storage: Battlepass Battlepasses (r:1 w:0) @@ -92,8 +94,8 @@ impl WeightInfo for SubstrateWeight { // Storage: Control Orgs (r:1 w:0) // Storage: Battlepass BattlepassInfoByOrg (r:1 w:1) fn activate_battlepass() -> Weight { - // Minimum execution time: 40_000 nanoseconds. - Weight::from_ref_time(44_000_000) + // Minimum execution time: 41_000 nanoseconds. + Weight::from_ref_time(42_000_000) .saturating_add(T::DbWeight::get().reads(5)) .saturating_add(T::DbWeight::get().writes(2)) } @@ -102,7 +104,7 @@ impl WeightInfo for SubstrateWeight { // Storage: Control Orgs (r:1 w:0) // Storage: Battlepass BattlepassInfoByOrg (r:1 w:1) fn conclude_battlepass() -> Weight { - // Minimum execution time: 37_000 nanoseconds. + // Minimum execution time: 38_000 nanoseconds. Weight::from_ref_time(38_000_000) .saturating_add(T::DbWeight::get().reads(4)) .saturating_add(T::DbWeight::get().writes(2)) @@ -111,18 +113,20 @@ impl WeightInfo for SubstrateWeight { // Storage: Battlepass BattlepassStates (r:1 w:0) // Storage: Control OrgStates (r:1 w:0) // Storage: Control Orgs (r:1 w:0) + // Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) // Storage: Control MemberStates (r:1 w:0) // Storage: Battlepass Points (r:0 w:1) fn set_points() -> Weight { - // Minimum execution time: 39_000 nanoseconds. - Weight::from_ref_time(41_000_000) - .saturating_add(T::DbWeight::get().reads(5)) + // Minimum execution time: 40_000 nanoseconds. + Weight::from_ref_time(42_000_000) + .saturating_add(T::DbWeight::get().reads(6)) .saturating_add(T::DbWeight::get().writes(1)) } // Storage: Battlepass Battlepasses (r:1 w:0) // Storage: Battlepass BattlepassStates (r:1 w:0) // Storage: Control OrgStates (r:1 w:0) // Storage: Control Orgs (r:1 w:0) + // Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) // Storage: Battlepass CollectionIndex (r:1 w:1) // Storage: Uniques Class (r:1 w:1) // Storage: RmrkCore Collections (r:0 w:1) @@ -130,9 +134,9 @@ impl WeightInfo for SubstrateWeight { // Storage: Battlepass Rewards (r:0 w:1) // Storage: Battlepass RewardStates (r:0 w:1) fn create_reward() -> Weight { - // Minimum execution time: 74_000 nanoseconds. - Weight::from_ref_time(76_000_000) - .saturating_add(T::DbWeight::get().reads(6)) + // Minimum execution time: 76_000 nanoseconds. + Weight::from_ref_time(85_000_000) + .saturating_add(T::DbWeight::get().reads(7)) .saturating_add(T::DbWeight::get().writes(6)) } // Storage: Battlepass Rewards (r:1 w:1) @@ -141,20 +145,22 @@ impl WeightInfo for SubstrateWeight { // Storage: Battlepass BattlepassStates (r:1 w:0) // Storage: Control OrgStates (r:1 w:0) // Storage: Control Orgs (r:1 w:0) + // Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) fn update_reward() -> Weight { - // Minimum execution time: 41_000 nanoseconds. - Weight::from_ref_time(44_000_000) - .saturating_add(T::DbWeight::get().reads(6)) + // Minimum execution time: 43_000 nanoseconds. + Weight::from_ref_time(45_000_000) + .saturating_add(T::DbWeight::get().reads(7)) .saturating_add(T::DbWeight::get().writes(1)) } // Storage: Battlepass Rewards (r:1 w:0) // Storage: Battlepass RewardStates (r:1 w:1) // Storage: Battlepass Battlepasses (r:1 w:0) // Storage: Control Orgs (r:1 w:0) + // Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) fn disable_reward() -> Weight { // Minimum execution time: 36_000 nanoseconds. Weight::from_ref_time(37_000_000) - .saturating_add(T::DbWeight::get().reads(4)) + .saturating_add(T::DbWeight::get().reads(5)) .saturating_add(T::DbWeight::get().writes(1)) } // Storage: Battlepass Rewards (r:1 w:0) @@ -164,6 +170,8 @@ impl WeightInfo for SubstrateWeight { // Storage: Battlepass BattlepassStates (r:1 w:0) // Storage: Control OrgStates (r:1 w:0) // Storage: Control MemberStates (r:1 w:0) + // Storage: Control Orgs (r:1 w:0) + // Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) // Storage: Battlepass ClaimedBattlepasses (r:1 w:0) // Storage: RmrkCore Nfts (r:2 w:1) // Storage: Battlepass Points (r:1 w:0) @@ -174,31 +182,33 @@ impl WeightInfo for SubstrateWeight { // Storage: Uniques CollectionMaxSupply (r:1 w:0) // Storage: Uniques Account (r:0 w:1) fn claim_reward() -> Weight { - // Minimum execution time: 126_000 nanoseconds. - Weight::from_ref_time(133_000_000) - .saturating_add(T::DbWeight::get().reads(18)) + // Minimum execution time: 133_000 nanoseconds. + Weight::from_ref_time(135_000_000) + .saturating_add(T::DbWeight::get().reads(20)) .saturating_add(T::DbWeight::get().writes(6)) } // Storage: Battlepass Battlepasses (r:1 w:0) // Storage: Battlepass BattlepassStates (r:1 w:0) // Storage: Control OrgStates (r:1 w:0) // Storage: Control Orgs (r:1 w:0) + // Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) // Storage: Battlepass Levels (r:0 w:1) fn add_level() -> Weight { - // Minimum execution time: 36_000 nanoseconds. - Weight::from_ref_time(36_000_000) - .saturating_add(T::DbWeight::get().reads(4)) + // Minimum execution time: 41_000 nanoseconds. + Weight::from_ref_time(42_000_000) + .saturating_add(T::DbWeight::get().reads(5)) .saturating_add(T::DbWeight::get().writes(1)) } // Storage: Battlepass Battlepasses (r:1 w:0) // Storage: Battlepass BattlepassStates (r:1 w:0) // Storage: Control OrgStates (r:1 w:0) // Storage: Control Orgs (r:1 w:0) + // Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) // Storage: Battlepass Levels (r:1 w:1) fn remove_level() -> Weight { - // Minimum execution time: 38_000 nanoseconds. - Weight::from_ref_time(39_000_000) - .saturating_add(T::DbWeight::get().reads(5)) + // Minimum execution time: 41_000 nanoseconds. + Weight::from_ref_time(44_000_000) + .saturating_add(T::DbWeight::get().reads(6)) .saturating_add(T::DbWeight::get().writes(1)) } // Storage: Battlepass Battlepasses (r:1 w:0) @@ -207,7 +217,7 @@ impl WeightInfo for SubstrateWeight { // Storage: Control Orgs (r:1 w:0) // Storage: Battlepass BattlepassInfoByOrg (r:1 w:1) fn add_bot() -> Weight { - // Minimum execution time: 35_000 nanoseconds. + // Minimum execution time: 36_000 nanoseconds. Weight::from_ref_time(37_000_000) .saturating_add(T::DbWeight::get().reads(5)) .saturating_add(T::DbWeight::get().writes(1)) @@ -226,8 +236,8 @@ impl WeightInfo for () { // Storage: Battlepass BattlepassStates (r:0 w:1) // Storage: Battlepass Battlepasses (r:0 w:1) fn create_battlepass() -> Weight { - // Minimum execution time: 70_000 nanoseconds. - Weight::from_ref_time(72_000_000) + // Minimum execution time: 69_000 nanoseconds. + Weight::from_ref_time(70_000_000) .saturating_add(RocksDbWeight::get().reads(5)) .saturating_add(RocksDbWeight::get().writes(7)) } @@ -236,8 +246,8 @@ impl WeightInfo for () { // Storage: Control OrgStates (r:1 w:0) // Storage: Control Orgs (r:1 w:0) fn update_battlepass() -> Weight { - // Minimum execution time: 35_000 nanoseconds. - Weight::from_ref_time(36_000_000) + // Minimum execution time: 37_000 nanoseconds. + Weight::from_ref_time(38_000_000) .saturating_add(RocksDbWeight::get().reads(4)) .saturating_add(RocksDbWeight::get().writes(1)) } @@ -245,6 +255,8 @@ impl WeightInfo for () { // Storage: Battlepass BattlepassStates (r:1 w:0) // Storage: Control OrgStates (r:1 w:0) // Storage: Control MemberStates (r:1 w:0) + // Storage: Control Orgs (r:1 w:0) + // Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) // Storage: Battlepass ClaimedBattlepasses (r:2 w:1) // Storage: RmrkCore Nfts (r:1 w:1) // Storage: RmrkCore Collections (r:1 w:1) @@ -253,9 +265,9 @@ impl WeightInfo for () { // Storage: Uniques CollectionMaxSupply (r:1 w:0) // Storage: Uniques Account (r:0 w:1) fn claim_battlepass() -> Weight { - // Minimum execution time: 94_000 nanoseconds. - Weight::from_ref_time(96_000_000) - .saturating_add(RocksDbWeight::get().reads(11)) + // Minimum execution time: 102_000 nanoseconds. + Weight::from_ref_time(105_000_000) + .saturating_add(RocksDbWeight::get().reads(13)) .saturating_add(RocksDbWeight::get().writes(6)) } // Storage: Battlepass Battlepasses (r:1 w:0) @@ -264,8 +276,8 @@ impl WeightInfo for () { // Storage: Control Orgs (r:1 w:0) // Storage: Battlepass BattlepassInfoByOrg (r:1 w:1) fn activate_battlepass() -> Weight { - // Minimum execution time: 40_000 nanoseconds. - Weight::from_ref_time(44_000_000) + // Minimum execution time: 41_000 nanoseconds. + Weight::from_ref_time(42_000_000) .saturating_add(RocksDbWeight::get().reads(5)) .saturating_add(RocksDbWeight::get().writes(2)) } @@ -274,7 +286,7 @@ impl WeightInfo for () { // Storage: Control Orgs (r:1 w:0) // Storage: Battlepass BattlepassInfoByOrg (r:1 w:1) fn conclude_battlepass() -> Weight { - // Minimum execution time: 37_000 nanoseconds. + // Minimum execution time: 38_000 nanoseconds. Weight::from_ref_time(38_000_000) .saturating_add(RocksDbWeight::get().reads(4)) .saturating_add(RocksDbWeight::get().writes(2)) @@ -283,18 +295,20 @@ impl WeightInfo for () { // Storage: Battlepass BattlepassStates (r:1 w:0) // Storage: Control OrgStates (r:1 w:0) // Storage: Control Orgs (r:1 w:0) + // Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) // Storage: Control MemberStates (r:1 w:0) // Storage: Battlepass Points (r:0 w:1) fn set_points() -> Weight { - // Minimum execution time: 39_000 nanoseconds. - Weight::from_ref_time(41_000_000) - .saturating_add(RocksDbWeight::get().reads(5)) + // Minimum execution time: 40_000 nanoseconds. + Weight::from_ref_time(42_000_000) + .saturating_add(RocksDbWeight::get().reads(6)) .saturating_add(RocksDbWeight::get().writes(1)) } // Storage: Battlepass Battlepasses (r:1 w:0) // Storage: Battlepass BattlepassStates (r:1 w:0) // Storage: Control OrgStates (r:1 w:0) // Storage: Control Orgs (r:1 w:0) + // Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) // Storage: Battlepass CollectionIndex (r:1 w:1) // Storage: Uniques Class (r:1 w:1) // Storage: RmrkCore Collections (r:0 w:1) @@ -302,9 +316,9 @@ impl WeightInfo for () { // Storage: Battlepass Rewards (r:0 w:1) // Storage: Battlepass RewardStates (r:0 w:1) fn create_reward() -> Weight { - // Minimum execution time: 74_000 nanoseconds. - Weight::from_ref_time(76_000_000) - .saturating_add(RocksDbWeight::get().reads(6)) + // Minimum execution time: 76_000 nanoseconds. + Weight::from_ref_time(85_000_000) + .saturating_add(RocksDbWeight::get().reads(7)) .saturating_add(RocksDbWeight::get().writes(6)) } // Storage: Battlepass Rewards (r:1 w:1) @@ -313,20 +327,22 @@ impl WeightInfo for () { // Storage: Battlepass BattlepassStates (r:1 w:0) // Storage: Control OrgStates (r:1 w:0) // Storage: Control Orgs (r:1 w:0) + // Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) fn update_reward() -> Weight { - // Minimum execution time: 41_000 nanoseconds. - Weight::from_ref_time(44_000_000) - .saturating_add(RocksDbWeight::get().reads(6)) + // Minimum execution time: 43_000 nanoseconds. + Weight::from_ref_time(45_000_000) + .saturating_add(RocksDbWeight::get().reads(7)) .saturating_add(RocksDbWeight::get().writes(1)) } // Storage: Battlepass Rewards (r:1 w:0) // Storage: Battlepass RewardStates (r:1 w:1) // Storage: Battlepass Battlepasses (r:1 w:0) // Storage: Control Orgs (r:1 w:0) + // Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) fn disable_reward() -> Weight { // Minimum execution time: 36_000 nanoseconds. Weight::from_ref_time(37_000_000) - .saturating_add(RocksDbWeight::get().reads(4)) + .saturating_add(RocksDbWeight::get().reads(5)) .saturating_add(RocksDbWeight::get().writes(1)) } // Storage: Battlepass Rewards (r:1 w:0) @@ -336,6 +352,8 @@ impl WeightInfo for () { // Storage: Battlepass BattlepassStates (r:1 w:0) // Storage: Control OrgStates (r:1 w:0) // Storage: Control MemberStates (r:1 w:0) + // Storage: Control Orgs (r:1 w:0) + // Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) // Storage: Battlepass ClaimedBattlepasses (r:1 w:0) // Storage: RmrkCore Nfts (r:2 w:1) // Storage: Battlepass Points (r:1 w:0) @@ -346,31 +364,33 @@ impl WeightInfo for () { // Storage: Uniques CollectionMaxSupply (r:1 w:0) // Storage: Uniques Account (r:0 w:1) fn claim_reward() -> Weight { - // Minimum execution time: 126_000 nanoseconds. - Weight::from_ref_time(133_000_000) - .saturating_add(RocksDbWeight::get().reads(18)) + // Minimum execution time: 133_000 nanoseconds. + Weight::from_ref_time(135_000_000) + .saturating_add(RocksDbWeight::get().reads(20)) .saturating_add(RocksDbWeight::get().writes(6)) } // Storage: Battlepass Battlepasses (r:1 w:0) // Storage: Battlepass BattlepassStates (r:1 w:0) // Storage: Control OrgStates (r:1 w:0) // Storage: Control Orgs (r:1 w:0) + // Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) // Storage: Battlepass Levels (r:0 w:1) fn add_level() -> Weight { - // Minimum execution time: 36_000 nanoseconds. - Weight::from_ref_time(36_000_000) - .saturating_add(RocksDbWeight::get().reads(4)) + // Minimum execution time: 41_000 nanoseconds. + Weight::from_ref_time(42_000_000) + .saturating_add(RocksDbWeight::get().reads(5)) .saturating_add(RocksDbWeight::get().writes(1)) } // Storage: Battlepass Battlepasses (r:1 w:0) // Storage: Battlepass BattlepassStates (r:1 w:0) // Storage: Control OrgStates (r:1 w:0) // Storage: Control Orgs (r:1 w:0) + // Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) // Storage: Battlepass Levels (r:1 w:1) fn remove_level() -> Weight { - // Minimum execution time: 38_000 nanoseconds. - Weight::from_ref_time(39_000_000) - .saturating_add(RocksDbWeight::get().reads(5)) + // Minimum execution time: 41_000 nanoseconds. + Weight::from_ref_time(44_000_000) + .saturating_add(RocksDbWeight::get().reads(6)) .saturating_add(RocksDbWeight::get().writes(1)) } // Storage: Battlepass Battlepasses (r:1 w:0) @@ -379,7 +399,7 @@ impl WeightInfo for () { // Storage: Control Orgs (r:1 w:0) // Storage: Battlepass BattlepassInfoByOrg (r:1 w:1) fn add_bot() -> Weight { - // Minimum execution time: 35_000 nanoseconds. + // Minimum execution time: 36_000 nanoseconds. Weight::from_ref_time(37_000_000) .saturating_add(RocksDbWeight::get().reads(5)) .saturating_add(RocksDbWeight::get().writes(1)) From a73a97feda7c7ab01bd88d52b949e948d8b6c235 Mon Sep 17 00:00:00 2001 From: FiberMan Date: Thu, 23 Feb 2023 01:07:56 +0100 Subject: [PATCH 26/49] feat: use unique NFT IDs --- battlepass/src/lib.rs | 43 ++++++++++++---- battlepass/src/weights.rs | 102 ++++++++++++++++++++------------------ 2 files changed, 85 insertions(+), 60 deletions(-) diff --git a/battlepass/src/lib.rs b/battlepass/src/lib.rs index 25203d333..2c58737cd 100644 --- a/battlepass/src/lib.rs +++ b/battlepass/src/lib.rs @@ -244,6 +244,7 @@ pub mod pallet { LevelNotReached, LevelUnknown, NoAvailableCollectionId, + NoAvailableNftId, NoChangesProvided, NotMember, NotOwnNft, @@ -341,9 +342,16 @@ pub mod pallet { /// /// CollectionIndex: u32 #[pallet::storage] - #[pallet::getter(fn collection_index)] + #[pallet::getter(fn get_collection_index)] pub type CollectionIndex = StorageValue<_, u32, ValueQuery>; + /// A counter for created NFTs + /// + /// NftIndex: u32 + #[pallet::storage] + #[pallet::getter(fn get_nft_index)] + pub type NftIndex = StorageValue<_, u32, ValueQuery>; + #[pallet::call] impl Pallet { @@ -866,15 +874,28 @@ impl Pallet { levels.count() == 1 } + fn bump_collection_index() -> Result { + CollectionIndex::::try_mutate(|n| -> Result { + let id = *n; + ensure!(id != u32::max_value(), Error::::NoAvailableCollectionId); + *n += 1; + Ok(id) + }) + } + + fn bump_nft_index() -> Result { + NftIndex::::try_mutate(|n| -> Result { + let id = *n; + ensure!(id != u32::max_value(), Error::::NoAvailableNftId); + *n += 1; + Ok(id) + }) + } + fn create_collection(owner: T::AccountId, max: Option) -> Result { let metadata = BoundedVec::truncate_from(b"meta".to_vec()); // TODO: what should be here? let symbol = BoundedVec::truncate_from(b"symbol".to_vec()); // TODO: what should be here? - let collection_index = CollectionIndex::::try_mutate(|n| -> Result { - let id = *n; - ensure!(id != u32::max_value(), Error::::NoAvailableCollectionId); - *n += 1; - Ok(id) - })?; + let collection_index = Self::bump_collection_index()?; let collection_id = T::BattlepassHelper::collection(collection_index); T::Rmrk::collection_create(owner, collection_id, metadata, max, symbol)?; @@ -922,8 +943,8 @@ impl Pallet { } fn do_claim_battlepass(by_who: T::AccountId, for_who: T::AccountId, battlepass_id: T::Hash, collection_id: T::CollectionId) -> Result { - let nft_count = ClaimedBattlepasses::::iter_key_prefix(battlepass_id).count() as u32; - let nft_id: T::ItemId = T::BattlepassHelper::item(nft_count); + let nft_index = Self::bump_nft_index()?; + let nft_id: T::ItemId = T::BattlepassHelper::item(nft_index); // Create Battlepass NFT let metadata = battlepass_id.encode(); @@ -978,8 +999,8 @@ impl Pallet { } fn do_claim_reward(claimer: T::AccountId, reward_id: T::Hash, collection_id: T::CollectionId, transferable: bool) -> Result { - let nft_count = ClaimedRewards::::iter_key_prefix(reward_id).count() as u32; - let nft_id = T::BattlepassHelper::item(nft_count); + let nft_index = Self::bump_nft_index()?; + let nft_id = T::BattlepassHelper::item(nft_index); // Create Battlepass NFT let metadata = reward_id.encode(); diff --git a/battlepass/src/weights.rs b/battlepass/src/weights.rs index 0ff0db9a9..b270bf6d8 100644 --- a/battlepass/src/weights.rs +++ b/battlepass/src/weights.rs @@ -2,7 +2,7 @@ //! Autogenerated weights for gamedao_battlepass //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-02-22, STEPS: `20`, REPEAT: 10, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2023-02-23, STEPS: `20`, REPEAT: 10, LOW RANGE: `[]`, HIGH RANGE: `[]` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: None, DB CACHE: 1024 // Executed Command: @@ -54,8 +54,8 @@ impl WeightInfo for SubstrateWeight { // Storage: Battlepass BattlepassStates (r:0 w:1) // Storage: Battlepass Battlepasses (r:0 w:1) fn create_battlepass() -> Weight { - // Minimum execution time: 69_000 nanoseconds. - Weight::from_ref_time(70_000_000) + // Minimum execution time: 68_000 nanoseconds. + Weight::from_ref_time(69_000_000) .saturating_add(T::DbWeight::get().reads(5)) .saturating_add(T::DbWeight::get().writes(7)) } @@ -64,8 +64,8 @@ impl WeightInfo for SubstrateWeight { // Storage: Control OrgStates (r:1 w:0) // Storage: Control Orgs (r:1 w:0) fn update_battlepass() -> Weight { - // Minimum execution time: 37_000 nanoseconds. - Weight::from_ref_time(38_000_000) + // Minimum execution time: 35_000 nanoseconds. + Weight::from_ref_time(36_000_000) .saturating_add(T::DbWeight::get().reads(4)) .saturating_add(T::DbWeight::get().writes(1)) } @@ -75,7 +75,8 @@ impl WeightInfo for SubstrateWeight { // Storage: Control MemberStates (r:1 w:0) // Storage: Control Orgs (r:1 w:0) // Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) - // Storage: Battlepass ClaimedBattlepasses (r:2 w:1) + // Storage: Battlepass ClaimedBattlepasses (r:1 w:1) + // Storage: Battlepass NftIndex (r:1 w:1) // Storage: RmrkCore Nfts (r:1 w:1) // Storage: RmrkCore Collections (r:1 w:1) // Storage: Uniques Asset (r:1 w:1) @@ -83,10 +84,10 @@ impl WeightInfo for SubstrateWeight { // Storage: Uniques CollectionMaxSupply (r:1 w:0) // Storage: Uniques Account (r:0 w:1) fn claim_battlepass() -> Weight { - // Minimum execution time: 102_000 nanoseconds. - Weight::from_ref_time(105_000_000) + // Minimum execution time: 97_000 nanoseconds. + Weight::from_ref_time(100_000_000) .saturating_add(T::DbWeight::get().reads(13)) - .saturating_add(T::DbWeight::get().writes(6)) + .saturating_add(T::DbWeight::get().writes(7)) } // Storage: Battlepass Battlepasses (r:1 w:0) // Storage: Battlepass BattlepassStates (r:1 w:1) @@ -94,8 +95,8 @@ impl WeightInfo for SubstrateWeight { // Storage: Control Orgs (r:1 w:0) // Storage: Battlepass BattlepassInfoByOrg (r:1 w:1) fn activate_battlepass() -> Weight { - // Minimum execution time: 41_000 nanoseconds. - Weight::from_ref_time(42_000_000) + // Minimum execution time: 40_000 nanoseconds. + Weight::from_ref_time(41_000_000) .saturating_add(T::DbWeight::get().reads(5)) .saturating_add(T::DbWeight::get().writes(2)) } @@ -105,7 +106,7 @@ impl WeightInfo for SubstrateWeight { // Storage: Battlepass BattlepassInfoByOrg (r:1 w:1) fn conclude_battlepass() -> Weight { // Minimum execution time: 38_000 nanoseconds. - Weight::from_ref_time(38_000_000) + Weight::from_ref_time(41_000_000) .saturating_add(T::DbWeight::get().reads(4)) .saturating_add(T::DbWeight::get().writes(2)) } @@ -134,8 +135,8 @@ impl WeightInfo for SubstrateWeight { // Storage: Battlepass Rewards (r:0 w:1) // Storage: Battlepass RewardStates (r:0 w:1) fn create_reward() -> Weight { - // Minimum execution time: 76_000 nanoseconds. - Weight::from_ref_time(85_000_000) + // Minimum execution time: 77_000 nanoseconds. + Weight::from_ref_time(79_000_000) .saturating_add(T::DbWeight::get().reads(7)) .saturating_add(T::DbWeight::get().writes(6)) } @@ -147,8 +148,8 @@ impl WeightInfo for SubstrateWeight { // Storage: Control Orgs (r:1 w:0) // Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) fn update_reward() -> Weight { - // Minimum execution time: 43_000 nanoseconds. - Weight::from_ref_time(45_000_000) + // Minimum execution time: 47_000 nanoseconds. + Weight::from_ref_time(50_000_000) .saturating_add(T::DbWeight::get().reads(7)) .saturating_add(T::DbWeight::get().writes(1)) } @@ -158,14 +159,14 @@ impl WeightInfo for SubstrateWeight { // Storage: Control Orgs (r:1 w:0) // Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) fn disable_reward() -> Weight { - // Minimum execution time: 36_000 nanoseconds. - Weight::from_ref_time(37_000_000) + // Minimum execution time: 39_000 nanoseconds. + Weight::from_ref_time(39_000_000) .saturating_add(T::DbWeight::get().reads(5)) .saturating_add(T::DbWeight::get().writes(1)) } // Storage: Battlepass Rewards (r:1 w:0) // Storage: Battlepass RewardStates (r:1 w:0) - // Storage: Battlepass ClaimedRewards (r:2 w:1) + // Storage: Battlepass ClaimedRewards (r:1 w:1) // Storage: Battlepass Battlepasses (r:1 w:0) // Storage: Battlepass BattlepassStates (r:1 w:0) // Storage: Control OrgStates (r:1 w:0) @@ -176,16 +177,17 @@ impl WeightInfo for SubstrateWeight { // Storage: RmrkCore Nfts (r:2 w:1) // Storage: Battlepass Points (r:1 w:0) // Storage: Battlepass Levels (r:2 w:0) + // Storage: Battlepass NftIndex (r:1 w:1) // Storage: RmrkCore Collections (r:1 w:1) // Storage: Uniques Asset (r:1 w:1) // Storage: Uniques Class (r:1 w:1) // Storage: Uniques CollectionMaxSupply (r:1 w:0) // Storage: Uniques Account (r:0 w:1) fn claim_reward() -> Weight { - // Minimum execution time: 133_000 nanoseconds. - Weight::from_ref_time(135_000_000) + // Minimum execution time: 130_000 nanoseconds. + Weight::from_ref_time(132_000_000) .saturating_add(T::DbWeight::get().reads(20)) - .saturating_add(T::DbWeight::get().writes(6)) + .saturating_add(T::DbWeight::get().writes(7)) } // Storage: Battlepass Battlepasses (r:1 w:0) // Storage: Battlepass BattlepassStates (r:1 w:0) @@ -194,8 +196,8 @@ impl WeightInfo for SubstrateWeight { // Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) // Storage: Battlepass Levels (r:0 w:1) fn add_level() -> Weight { - // Minimum execution time: 41_000 nanoseconds. - Weight::from_ref_time(42_000_000) + // Minimum execution time: 39_000 nanoseconds. + Weight::from_ref_time(39_000_000) .saturating_add(T::DbWeight::get().reads(5)) .saturating_add(T::DbWeight::get().writes(1)) } @@ -218,7 +220,7 @@ impl WeightInfo for SubstrateWeight { // Storage: Battlepass BattlepassInfoByOrg (r:1 w:1) fn add_bot() -> Weight { // Minimum execution time: 36_000 nanoseconds. - Weight::from_ref_time(37_000_000) + Weight::from_ref_time(38_000_000) .saturating_add(T::DbWeight::get().reads(5)) .saturating_add(T::DbWeight::get().writes(1)) } @@ -236,8 +238,8 @@ impl WeightInfo for () { // Storage: Battlepass BattlepassStates (r:0 w:1) // Storage: Battlepass Battlepasses (r:0 w:1) fn create_battlepass() -> Weight { - // Minimum execution time: 69_000 nanoseconds. - Weight::from_ref_time(70_000_000) + // Minimum execution time: 68_000 nanoseconds. + Weight::from_ref_time(69_000_000) .saturating_add(RocksDbWeight::get().reads(5)) .saturating_add(RocksDbWeight::get().writes(7)) } @@ -246,8 +248,8 @@ impl WeightInfo for () { // Storage: Control OrgStates (r:1 w:0) // Storage: Control Orgs (r:1 w:0) fn update_battlepass() -> Weight { - // Minimum execution time: 37_000 nanoseconds. - Weight::from_ref_time(38_000_000) + // Minimum execution time: 35_000 nanoseconds. + Weight::from_ref_time(36_000_000) .saturating_add(RocksDbWeight::get().reads(4)) .saturating_add(RocksDbWeight::get().writes(1)) } @@ -257,7 +259,8 @@ impl WeightInfo for () { // Storage: Control MemberStates (r:1 w:0) // Storage: Control Orgs (r:1 w:0) // Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) - // Storage: Battlepass ClaimedBattlepasses (r:2 w:1) + // Storage: Battlepass ClaimedBattlepasses (r:1 w:1) + // Storage: Battlepass NftIndex (r:1 w:1) // Storage: RmrkCore Nfts (r:1 w:1) // Storage: RmrkCore Collections (r:1 w:1) // Storage: Uniques Asset (r:1 w:1) @@ -265,10 +268,10 @@ impl WeightInfo for () { // Storage: Uniques CollectionMaxSupply (r:1 w:0) // Storage: Uniques Account (r:0 w:1) fn claim_battlepass() -> Weight { - // Minimum execution time: 102_000 nanoseconds. - Weight::from_ref_time(105_000_000) + // Minimum execution time: 97_000 nanoseconds. + Weight::from_ref_time(100_000_000) .saturating_add(RocksDbWeight::get().reads(13)) - .saturating_add(RocksDbWeight::get().writes(6)) + .saturating_add(RocksDbWeight::get().writes(7)) } // Storage: Battlepass Battlepasses (r:1 w:0) // Storage: Battlepass BattlepassStates (r:1 w:1) @@ -276,8 +279,8 @@ impl WeightInfo for () { // Storage: Control Orgs (r:1 w:0) // Storage: Battlepass BattlepassInfoByOrg (r:1 w:1) fn activate_battlepass() -> Weight { - // Minimum execution time: 41_000 nanoseconds. - Weight::from_ref_time(42_000_000) + // Minimum execution time: 40_000 nanoseconds. + Weight::from_ref_time(41_000_000) .saturating_add(RocksDbWeight::get().reads(5)) .saturating_add(RocksDbWeight::get().writes(2)) } @@ -287,7 +290,7 @@ impl WeightInfo for () { // Storage: Battlepass BattlepassInfoByOrg (r:1 w:1) fn conclude_battlepass() -> Weight { // Minimum execution time: 38_000 nanoseconds. - Weight::from_ref_time(38_000_000) + Weight::from_ref_time(41_000_000) .saturating_add(RocksDbWeight::get().reads(4)) .saturating_add(RocksDbWeight::get().writes(2)) } @@ -316,8 +319,8 @@ impl WeightInfo for () { // Storage: Battlepass Rewards (r:0 w:1) // Storage: Battlepass RewardStates (r:0 w:1) fn create_reward() -> Weight { - // Minimum execution time: 76_000 nanoseconds. - Weight::from_ref_time(85_000_000) + // Minimum execution time: 77_000 nanoseconds. + Weight::from_ref_time(79_000_000) .saturating_add(RocksDbWeight::get().reads(7)) .saturating_add(RocksDbWeight::get().writes(6)) } @@ -329,8 +332,8 @@ impl WeightInfo for () { // Storage: Control Orgs (r:1 w:0) // Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) fn update_reward() -> Weight { - // Minimum execution time: 43_000 nanoseconds. - Weight::from_ref_time(45_000_000) + // Minimum execution time: 47_000 nanoseconds. + Weight::from_ref_time(50_000_000) .saturating_add(RocksDbWeight::get().reads(7)) .saturating_add(RocksDbWeight::get().writes(1)) } @@ -340,14 +343,14 @@ impl WeightInfo for () { // Storage: Control Orgs (r:1 w:0) // Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) fn disable_reward() -> Weight { - // Minimum execution time: 36_000 nanoseconds. - Weight::from_ref_time(37_000_000) + // Minimum execution time: 39_000 nanoseconds. + Weight::from_ref_time(39_000_000) .saturating_add(RocksDbWeight::get().reads(5)) .saturating_add(RocksDbWeight::get().writes(1)) } // Storage: Battlepass Rewards (r:1 w:0) // Storage: Battlepass RewardStates (r:1 w:0) - // Storage: Battlepass ClaimedRewards (r:2 w:1) + // Storage: Battlepass ClaimedRewards (r:1 w:1) // Storage: Battlepass Battlepasses (r:1 w:0) // Storage: Battlepass BattlepassStates (r:1 w:0) // Storage: Control OrgStates (r:1 w:0) @@ -358,16 +361,17 @@ impl WeightInfo for () { // Storage: RmrkCore Nfts (r:2 w:1) // Storage: Battlepass Points (r:1 w:0) // Storage: Battlepass Levels (r:2 w:0) + // Storage: Battlepass NftIndex (r:1 w:1) // Storage: RmrkCore Collections (r:1 w:1) // Storage: Uniques Asset (r:1 w:1) // Storage: Uniques Class (r:1 w:1) // Storage: Uniques CollectionMaxSupply (r:1 w:0) // Storage: Uniques Account (r:0 w:1) fn claim_reward() -> Weight { - // Minimum execution time: 133_000 nanoseconds. - Weight::from_ref_time(135_000_000) + // Minimum execution time: 130_000 nanoseconds. + Weight::from_ref_time(132_000_000) .saturating_add(RocksDbWeight::get().reads(20)) - .saturating_add(RocksDbWeight::get().writes(6)) + .saturating_add(RocksDbWeight::get().writes(7)) } // Storage: Battlepass Battlepasses (r:1 w:0) // Storage: Battlepass BattlepassStates (r:1 w:0) @@ -376,8 +380,8 @@ impl WeightInfo for () { // Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) // Storage: Battlepass Levels (r:0 w:1) fn add_level() -> Weight { - // Minimum execution time: 41_000 nanoseconds. - Weight::from_ref_time(42_000_000) + // Minimum execution time: 39_000 nanoseconds. + Weight::from_ref_time(39_000_000) .saturating_add(RocksDbWeight::get().reads(5)) .saturating_add(RocksDbWeight::get().writes(1)) } @@ -400,7 +404,7 @@ impl WeightInfo for () { // Storage: Battlepass BattlepassInfoByOrg (r:1 w:1) fn add_bot() -> Weight { // Minimum execution time: 36_000 nanoseconds. - Weight::from_ref_time(37_000_000) + Weight::from_ref_time(38_000_000) .saturating_add(RocksDbWeight::get().reads(5)) .saturating_add(RocksDbWeight::get().writes(1)) } From b840d41713f0493ae3fd5327e0617192409dbe11 Mon Sep 17 00:00:00 2001 From: FiberMan Date: Thu, 23 Feb 2023 13:29:13 +0100 Subject: [PATCH 27/49] feat: remove ability to claim battlepass for self --- battlepass/src/lib.rs | 16 ++++++++-------- battlepass/src/tests.rs | 32 +++++++++++++------------------- 2 files changed, 21 insertions(+), 27 deletions(-) diff --git a/battlepass/src/lib.rs b/battlepass/src/lib.rs index 2c58737cd..a52bbbe49 100644 --- a/battlepass/src/lib.rs +++ b/battlepass/src/lib.rs @@ -440,7 +440,7 @@ pub mod pallet { /// Claims the Battlepass-NFT for user who joined the Battlepass. /// This NFT may be used as a proof of a Battlepass membership. - /// May be called by user or by Organization owner or by a specially dedicated for this purpose account (Bot). + /// May be called by Organization owner or by a specially dedicated for this purpose account (Bot). /// /// Parameters: /// - `battlepass_id`: ID of the Battlepass for which to claim NFT. @@ -462,8 +462,8 @@ pub mod pallet { ensure!(T::Control::is_org_active(&battlepass.org_id), Error::::OrgUnknownOrInactive); // check if user is a member of organization ensure!(T::Control::is_org_member_active(&battlepass.org_id, &for_who), Error::::NotMember); - // check permissions (self, prime) - ensure!(by_who == for_who || Self::is_prime_or_bot(&battlepass.org_id, by_who.clone())?, Error::::AuthorizationError); + // check permissions (prime, bot) + ensure!(Self::is_prime_or_bot(&battlepass.org_id, by_who.clone())?, Error::::AuthorizationError); // check if Battlepass already claimed ensure!(!ClaimedBattlepasses::::contains_key(battlepass_id, for_who.clone()), Error::::BattlepassClaimed); @@ -599,7 +599,7 @@ pub mod pallet { ensure!(!Self::check_battlepass_state(battlepass_id, BattlepassState::ENDED)?, Error::::BattlepassStateWrong); // check if Org is active ensure!(T::Control::is_org_active(&battlepass.org_id), Error::::OrgUnknownOrInactive); - // check permissions (prime) + // check permissions (prime, bot) ensure!(Self::is_prime_or_bot(&battlepass.org_id, caller)?, Error::::AuthorizationError); let prime = T::Control::org_prime_account(&battlepass.org_id).ok_or(Error::::OrgPrimeUnknown)?; @@ -646,7 +646,7 @@ pub mod pallet { ensure!(!Self::check_battlepass_state(reward.battlepass_id, BattlepassState::ENDED)?, Error::::BattlepassStateWrong); // check if Org is active ensure!(T::Control::is_org_active(&battlepass.org_id), Error::::OrgUnknownOrInactive); - // check permissions (prime) + // check permissions (prime, bot) ensure!(Self::is_prime_or_bot(&battlepass.org_id, caller)?, Error::::AuthorizationError); reward.name = name.clone().unwrap(); @@ -679,7 +679,7 @@ pub mod pallet { ensure!(Self::check_reward_state(reward_id, RewardState::ACTIVE)?, Error::::RewardInactive); // check if Battlepass exists let battlepass = Self::get_battlepass(reward.battlepass_id).ok_or(Error::::BattlepassUnknown)?; - // check permissions (prime) + // check permissions (prime, bot) ensure!(Self::is_prime_or_bot(&battlepass.org_id, caller)?, Error::::AuthorizationError); let state = RewardState::INACTIVE; @@ -767,7 +767,7 @@ pub mod pallet { ensure!(!Self::check_battlepass_state(battlepass_id, BattlepassState::ENDED)?, Error::::BattlepassStateWrong); // check if Org is active ensure!(T::Control::is_org_active(&battlepass.org_id), Error::::OrgUnknownOrInactive); - // check permissions (prime) + // check permissions (prime, bot) ensure!(Self::is_prime_or_bot(&battlepass.org_id, sender.clone())?, Error::::AuthorizationError); Levels::::insert(battlepass_id, level, points); @@ -797,7 +797,7 @@ pub mod pallet { ensure!(!Self::check_battlepass_state(battlepass_id, BattlepassState::ENDED)?, Error::::BattlepassStateWrong); // check if Org is active ensure!(T::Control::is_org_active(&battlepass.org_id), Error::::OrgUnknownOrInactive); - // check permissions (prime) + // check permissions (prime, bot) ensure!(Self::is_prime_or_bot(&battlepass.org_id, sender.clone())?, Error::::AuthorizationError); // check if Level exists ensure!(Levels::::contains_key(battlepass_id, level), Error::::LevelUnknown); diff --git a/battlepass/src/tests.rs b/battlepass/src/tests.rs index fdb6e7aa6..3db7362d7 100644 --- a/battlepass/src/tests.rs +++ b/battlepass/src/tests.rs @@ -478,6 +478,11 @@ fn claim_battlepass_test() { Battlepass::claim_battlepass(Origin::signed(not_member), battlepass_id, creator), Error::::AuthorizationError ); + // Should not claim for self + assert_noop!( + Battlepass::claim_battlepass(Origin::signed(not_creator), battlepass_id, not_creator), + Error::::AuthorizationError + ); // Should not claim for non members assert_noop!( @@ -495,21 +500,10 @@ fn claim_battlepass_test() { assert_eq!(nft_id.unwrap(), 0); // Check if NFT minted assert_eq!(pallet_rmrk_core::Nfts::::contains_key(0, 0), true); - - // Should claim for self - assert_ok!( - Battlepass::claim_battlepass(Origin::signed(not_creator_2), battlepass_id, not_creator_2) - ); - // Check if ClaimedBattlepasses record created - let nft_id = ClaimedBattlepasses::::get(battlepass_id, not_creator_2); - assert_eq!(nft_id.is_some(), true); - assert_eq!(nft_id.unwrap(), 1); - // Check if NFT minted - assert_eq!(pallet_rmrk_core::Nfts::::contains_key(0, 1), true); - + // Should not claim if it was already claimed assert_noop!( - Battlepass::claim_battlepass(Origin::signed(not_creator), battlepass_id, not_creator), + Battlepass::claim_battlepass(Origin::signed(creator), battlepass_id, not_creator), Error::::BattlepassClaimed ); @@ -523,9 +517,9 @@ fn claim_battlepass_test() { // Check if ClaimedBattlepasses record created let nft_id = ClaimedBattlepasses::::get(battlepass_id, not_creator_3); assert_eq!(nft_id.is_some(), true); - assert_eq!(nft_id.unwrap(), 2); + assert_eq!(nft_id.unwrap(), 1); // Check if NFT minted - assert_eq!(pallet_rmrk_core::Nfts::::contains_key(0, 2), true); + assert_eq!(pallet_rmrk_core::Nfts::::contains_key(0, 1), true); // Should not claim Battlepass in ENDED state assert_ok!( @@ -1051,7 +1045,7 @@ fn claim_reward_test() { // Should not claim Reward if no NFT for claimed Battlepass assert_ok!( - Battlepass::claim_battlepass(Origin::signed(not_creator), battlepass_id, not_creator) + Battlepass::claim_battlepass(Origin::signed(creator), battlepass_id, not_creator) ); assert_ok!( RmrkCore::burn_nft(Origin::signed(not_creator), 0, 0) @@ -1080,7 +1074,7 @@ fn claim_reward_test() { // Should not claim Reward if Battlepass NFT is not valid assert_ok!( - Battlepass::claim_battlepass(Origin::signed(not_creator_2), battlepass_id, not_creator_2) + Battlepass::claim_battlepass(Origin::signed(creator), battlepass_id, not_creator_2) ); Nfts::::mutate(0, 2, |nft| { if let Some(n) = nft { @@ -1094,7 +1088,7 @@ fn claim_reward_test() { // Should not claim if user's level is too low assert_ok!( - Battlepass::claim_battlepass(Origin::signed(not_creator_3), battlepass_id, not_creator_3) + Battlepass::claim_battlepass(Origin::signed(creator), battlepass_id, not_creator_3) ); assert_noop!( Battlepass::claim_reward(Origin::signed(not_creator_3), reward_id, not_creator_3), @@ -1125,7 +1119,7 @@ fn claim_reward_test() { // Should not claim if max limit reached assert_ok!( - Battlepass::claim_battlepass(Origin::signed(not_creator_4), battlepass_id, not_creator_4) + Battlepass::claim_battlepass(Origin::signed(creator), battlepass_id, not_creator_4) ); assert_ok!( Battlepass::set_points(Origin::signed(creator), battlepass_id, not_creator_4, 10) From fc13b31a351ecdc2afd888e6e3d0d6266b00f1f7 Mon Sep 17 00:00:00 2001 From: vasylenko-yevhen Date: Fri, 24 Feb 2023 00:23:45 +0200 Subject: [PATCH 28/49] allows non org members to participate in battlepass --- battlepass/src/lib.rs | 11 +++-------- battlepass/src/tests.rs | 17 ++++++++--------- 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/battlepass/src/lib.rs b/battlepass/src/lib.rs index a52bbbe49..055508f28 100644 --- a/battlepass/src/lib.rs +++ b/battlepass/src/lib.rs @@ -246,7 +246,6 @@ pub mod pallet { NoAvailableCollectionId, NoAvailableNftId, NoChangesProvided, - NotMember, NotOwnNft, OrgPrimeUnknown, OrgUnknownOrInactive, @@ -460,8 +459,6 @@ pub mod pallet { ensure!(Self::check_battlepass_state(battlepass_id, BattlepassState::ACTIVE)?, Error::::BattlepassStateWrong); // check if Org is active ensure!(T::Control::is_org_active(&battlepass.org_id), Error::::OrgUnknownOrInactive); - // check if user is a member of organization - ensure!(T::Control::is_org_member_active(&battlepass.org_id, &for_who), Error::::NotMember); // check permissions (prime, bot) ensure!(Self::is_prime_or_bot(&battlepass.org_id, by_who.clone())?, Error::::AuthorizationError); // check if Battlepass already claimed @@ -559,8 +556,8 @@ pub mod pallet { ensure!(T::Control::is_org_active(&battlepass.org_id), Error::::OrgUnknownOrInactive); // check permissions (prime, bot) ensure!(Self::is_prime_or_bot(&battlepass.org_id, sender.clone())?, Error::::AuthorizationError); - // check if user is a member of organization - ensure!(T::Control::is_org_member_active(&battlepass.org_id, &account), Error::::NotMember); + // check if user has access to Battlepass + ensure!(ClaimedBattlepasses::::contains_key(battlepass_id, account.clone()), Error::::BattlepassNotClaimed); Points::::insert(battlepass_id, &account, amount); @@ -722,8 +719,6 @@ pub mod pallet { ensure!(Self::check_battlepass_state(reward.battlepass_id, BattlepassState::ACTIVE)?, Error::::BattlepassStateWrong); // check if Org is active ensure!(T::Control::is_org_active(&battlepass.org_id), Error::::OrgUnknownOrInactive); - // check if user is a member of organization - ensure!(T::Control::is_org_member_active(&battlepass.org_id, &for_who), Error::::NotMember); // check permissions (self, prime or bot) ensure!(by_who == for_who || Self::is_prime_or_bot(&battlepass.org_id, by_who.clone())?, Error::::AuthorizationError); // check if user claimed Battlepass NFT @@ -1020,4 +1015,4 @@ impl Pallet { Ok(nft_id) } -} \ No newline at end of file +} diff --git a/battlepass/src/tests.rs b/battlepass/src/tests.rs index 3db7362d7..4fb5dae38 100644 --- a/battlepass/src/tests.rs +++ b/battlepass/src/tests.rs @@ -483,12 +483,6 @@ fn claim_battlepass_test() { Battlepass::claim_battlepass(Origin::signed(not_creator), battlepass_id, not_creator), Error::::AuthorizationError ); - - // Should not claim for non members - assert_noop!( - Battlepass::claim_battlepass(Origin::signed(creator), battlepass_id, not_member), - Error::::NotMember - ); // Should claim for others by Prime assert_ok!( @@ -521,6 +515,11 @@ fn claim_battlepass_test() { // Check if NFT minted assert_eq!(pallet_rmrk_core::Nfts::::contains_key(0, 1), true); + // Should claim for accounts outside of org + assert_ok!( + Battlepass::claim_battlepass(Origin::signed(creator), battlepass_id, not_member), + ); + // Should not claim Battlepass in ENDED state assert_ok!( Battlepass::conclude_battlepass(Origin::signed(creator), battlepass_id) @@ -593,7 +592,7 @@ fn set_points_test() { // Should not set for non members assert_noop!( Battlepass::set_points(Origin::signed(creator), battlepass_id, not_member, 10), - Error::::NotMember + Error::::BattlepassNotClaimed ); // Should set points by Prime @@ -1018,7 +1017,7 @@ fn claim_reward_test() { // Should not claim for non members assert_noop!( Battlepass::claim_reward(Origin::signed(creator), reward_id, not_member), - Error::::NotMember + Error::::BattlepassNotClaimed ); // Should not claim by Bot if Bot account was not added @@ -1422,4 +1421,4 @@ fn add_bot_test() { // Check events }) -} \ No newline at end of file +} From d0d85f285ca3c5216ff33c286e412aae644dafe6 Mon Sep 17 00:00:00 2001 From: FiberMan Date: Fri, 24 Feb 2023 01:14:59 +0100 Subject: [PATCH 29/49] finish tests, update weights --- battlepass/src/benchmarking.rs | 1 + battlepass/src/lib.rs | 28 ++++++--- battlepass/src/tests.rs | 27 ++++++--- battlepass/src/weights.rs | 108 ++++++++++++++++----------------- 4 files changed, 92 insertions(+), 72 deletions(-) diff --git a/battlepass/src/benchmarking.rs b/battlepass/src/benchmarking.rs index 5fd040624..27c34531f 100644 --- a/battlepass/src/benchmarking.rs +++ b/battlepass/src/benchmarking.rs @@ -152,6 +152,7 @@ benchmarks! { let org_id = get_org::(caller.clone()); let battlepass_id = get_battlepass::(caller.clone(), org_id); activate_bpass::(caller.clone(), battlepass_id); + claim_bpass::(caller.clone(), battlepass_id); set_bot::(caller.clone(), battlepass_id, bot.clone()); }: _(RawOrigin::Signed(bot), battlepass_id, caller.clone(), 10) verify { diff --git a/battlepass/src/lib.rs b/battlepass/src/lib.rs index 055508f28..0dadccdfe 100644 --- a/battlepass/src/lib.rs +++ b/battlepass/src/lib.rs @@ -557,7 +557,7 @@ pub mod pallet { // check permissions (prime, bot) ensure!(Self::is_prime_or_bot(&battlepass.org_id, sender.clone())?, Error::::AuthorizationError); // check if user has access to Battlepass - ensure!(ClaimedBattlepasses::::contains_key(battlepass_id, account.clone()), Error::::BattlepassNotClaimed); + Self::validate_battlepass_ownership(account.clone(), battlepass_id, battlepass)?; Points::::insert(battlepass_id, &account, amount); @@ -721,15 +721,9 @@ pub mod pallet { ensure!(T::Control::is_org_active(&battlepass.org_id), Error::::OrgUnknownOrInactive); // check permissions (self, prime or bot) ensure!(by_who == for_who || Self::is_prime_or_bot(&battlepass.org_id, by_who.clone())?, Error::::AuthorizationError); - // check if user claimed Battlepass NFT - let bp_nft_id = Self::get_claimed_battlepass(reward.battlepass_id, &for_who).ok_or(Error::::BattlepassNotClaimed)?; - // check if Battlepass NFT exists - let bp_nft = pallet_rmrk_core::Pallet::::nfts(&battlepass.collection_id, bp_nft_id).ok_or(Error::::BattlepassNftUnknown)?; - // validate Battlepass NFT ownership - ensure!(AccountIdOrCollectionNftTuple::AccountId(for_who.clone()) == bp_nft.owner, Error::::NotOwnNft); - // validate Battlepass NFT metadata - let metadata: String = BoundedVec::truncate_from(reward.battlepass_id.encode()); - ensure!(metadata == bp_nft.metadata, Error::::BattlepassNftInvalid); + // check if user has access to Battlepass + Self::validate_battlepass_ownership(for_who.clone(), reward.battlepass_id, battlepass)?; + // check if user has reached the required Level ensure!(Self::is_level_reached(&reward.battlepass_id, &for_who, reward.level), Error::::LevelNotReached); @@ -1015,4 +1009,18 @@ impl Pallet { Ok(nft_id) } + + fn validate_battlepass_ownership(account: T::AccountId, battlepass_id: T::Hash, battlepass: Battlepass, T::CollectionId>) -> DispatchResult { + // check if user claimed Battlepass NFT + let bp_nft_id = Self::get_claimed_battlepass(battlepass_id, &account).ok_or(Error::::BattlepassNotClaimed)?; + // check if Battlepass NFT exists + let bp_nft = pallet_rmrk_core::Pallet::::nfts(&battlepass.collection_id, bp_nft_id).ok_or(Error::::BattlepassNftUnknown)?; + // validate Battlepass NFT ownership + ensure!(AccountIdOrCollectionNftTuple::AccountId(account.clone()) == bp_nft.owner, Error::::NotOwnNft); + // validate Battlepass NFT metadata + let metadata: String = BoundedVec::truncate_from(battlepass_id.encode()); + ensure!(metadata == bp_nft.metadata, Error::::BattlepassNftInvalid); + + Ok(()) + } } diff --git a/battlepass/src/tests.rs b/battlepass/src/tests.rs index 4fb5dae38..0f0b6e07d 100644 --- a/battlepass/src/tests.rs +++ b/battlepass/src/tests.rs @@ -589,13 +589,16 @@ fn set_points_test() { Error::::AuthorizationError ); - // Should not set for non members + // Should not set if user does not have access to Battlepass assert_noop!( Battlepass::set_points(Origin::signed(creator), battlepass_id, not_member, 10), Error::::BattlepassNotClaimed ); // Should set points by Prime + assert_ok!( + Battlepass::claim_battlepass(Origin::signed(creator), battlepass_id, not_creator) + ); assert_ok!( Battlepass::set_points(Origin::signed(creator), battlepass_id, not_creator, 10) ); @@ -1014,12 +1017,6 @@ fn claim_reward_test() { Control::enable_org(Origin::signed(creator), org_id) ); - // Should not claim for non members - assert_noop!( - Battlepass::claim_reward(Origin::signed(creator), reward_id, not_member), - Error::::BattlepassNotClaimed - ); - // Should not claim by Bot if Bot account was not added assert_noop!( Battlepass::claim_reward(Origin::signed(BOT), reward_id, creator), @@ -1136,6 +1133,22 @@ fn claim_reward_test() { assert_ok!( Battlepass::claim_reward(Origin::signed(BOT), reward_id, not_creator_4) ); + // Check if Reward claimed + assert_eq!(ClaimedRewards::::contains_key(reward_id, not_creator_4), true); + + // Should claim Reward for non-member + let reward_id = create_reward(battlepass_id); + assert_ok!( + Battlepass::claim_battlepass(Origin::signed(creator), battlepass_id, not_member) + ); + assert_ok!( + Battlepass::set_points(Origin::signed(creator), battlepass_id, not_member, 10) + ); + assert_ok!( + Battlepass::claim_reward(Origin::signed(not_member), reward_id, not_member) + ); + // Check if Reward claimed + assert_eq!(ClaimedRewards::::contains_key(reward_id, not_member), true); // Should not claim if Battlepass state is ENDED assert_ok!( diff --git a/battlepass/src/weights.rs b/battlepass/src/weights.rs index b270bf6d8..b491ec7d8 100644 --- a/battlepass/src/weights.rs +++ b/battlepass/src/weights.rs @@ -2,7 +2,7 @@ //! Autogenerated weights for gamedao_battlepass //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-02-23, STEPS: `20`, REPEAT: 10, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2023-02-24, STEPS: `20`, REPEAT: 10, LOW RANGE: `[]`, HIGH RANGE: `[]` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: None, DB CACHE: 1024 // Executed Command: @@ -54,8 +54,8 @@ impl WeightInfo for SubstrateWeight { // Storage: Battlepass BattlepassStates (r:0 w:1) // Storage: Battlepass Battlepasses (r:0 w:1) fn create_battlepass() -> Weight { - // Minimum execution time: 68_000 nanoseconds. - Weight::from_ref_time(69_000_000) + // Minimum execution time: 69_000 nanoseconds. + Weight::from_ref_time(70_000_000) .saturating_add(T::DbWeight::get().reads(5)) .saturating_add(T::DbWeight::get().writes(7)) } @@ -64,15 +64,14 @@ impl WeightInfo for SubstrateWeight { // Storage: Control OrgStates (r:1 w:0) // Storage: Control Orgs (r:1 w:0) fn update_battlepass() -> Weight { - // Minimum execution time: 35_000 nanoseconds. - Weight::from_ref_time(36_000_000) + // Minimum execution time: 36_000 nanoseconds. + Weight::from_ref_time(37_000_000) .saturating_add(T::DbWeight::get().reads(4)) .saturating_add(T::DbWeight::get().writes(1)) } // Storage: Battlepass Battlepasses (r:1 w:0) // Storage: Battlepass BattlepassStates (r:1 w:0) // Storage: Control OrgStates (r:1 w:0) - // Storage: Control MemberStates (r:1 w:0) // Storage: Control Orgs (r:1 w:0) // Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) // Storage: Battlepass ClaimedBattlepasses (r:1 w:1) @@ -84,9 +83,9 @@ impl WeightInfo for SubstrateWeight { // Storage: Uniques CollectionMaxSupply (r:1 w:0) // Storage: Uniques Account (r:0 w:1) fn claim_battlepass() -> Weight { - // Minimum execution time: 97_000 nanoseconds. - Weight::from_ref_time(100_000_000) - .saturating_add(T::DbWeight::get().reads(13)) + // Minimum execution time: 93_000 nanoseconds. + Weight::from_ref_time(102_000_000) + .saturating_add(T::DbWeight::get().reads(12)) .saturating_add(T::DbWeight::get().writes(7)) } // Storage: Battlepass Battlepasses (r:1 w:0) @@ -106,7 +105,7 @@ impl WeightInfo for SubstrateWeight { // Storage: Battlepass BattlepassInfoByOrg (r:1 w:1) fn conclude_battlepass() -> Weight { // Minimum execution time: 38_000 nanoseconds. - Weight::from_ref_time(41_000_000) + Weight::from_ref_time(39_000_000) .saturating_add(T::DbWeight::get().reads(4)) .saturating_add(T::DbWeight::get().writes(2)) } @@ -115,12 +114,13 @@ impl WeightInfo for SubstrateWeight { // Storage: Control OrgStates (r:1 w:0) // Storage: Control Orgs (r:1 w:0) // Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) - // Storage: Control MemberStates (r:1 w:0) + // Storage: Battlepass ClaimedBattlepasses (r:1 w:0) + // Storage: RmrkCore Nfts (r:1 w:0) // Storage: Battlepass Points (r:0 w:1) fn set_points() -> Weight { - // Minimum execution time: 40_000 nanoseconds. - Weight::from_ref_time(42_000_000) - .saturating_add(T::DbWeight::get().reads(6)) + // Minimum execution time: 46_000 nanoseconds. + Weight::from_ref_time(47_000_000) + .saturating_add(T::DbWeight::get().reads(7)) .saturating_add(T::DbWeight::get().writes(1)) } // Storage: Battlepass Battlepasses (r:1 w:0) @@ -135,8 +135,8 @@ impl WeightInfo for SubstrateWeight { // Storage: Battlepass Rewards (r:0 w:1) // Storage: Battlepass RewardStates (r:0 w:1) fn create_reward() -> Weight { - // Minimum execution time: 77_000 nanoseconds. - Weight::from_ref_time(79_000_000) + // Minimum execution time: 78_000 nanoseconds. + Weight::from_ref_time(80_000_000) .saturating_add(T::DbWeight::get().reads(7)) .saturating_add(T::DbWeight::get().writes(6)) } @@ -148,8 +148,8 @@ impl WeightInfo for SubstrateWeight { // Storage: Control Orgs (r:1 w:0) // Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) fn update_reward() -> Weight { - // Minimum execution time: 47_000 nanoseconds. - Weight::from_ref_time(50_000_000) + // Minimum execution time: 45_000 nanoseconds. + Weight::from_ref_time(46_000_000) .saturating_add(T::DbWeight::get().reads(7)) .saturating_add(T::DbWeight::get().writes(1)) } @@ -159,8 +159,8 @@ impl WeightInfo for SubstrateWeight { // Storage: Control Orgs (r:1 w:0) // Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) fn disable_reward() -> Weight { - // Minimum execution time: 39_000 nanoseconds. - Weight::from_ref_time(39_000_000) + // Minimum execution time: 40_000 nanoseconds. + Weight::from_ref_time(43_000_000) .saturating_add(T::DbWeight::get().reads(5)) .saturating_add(T::DbWeight::get().writes(1)) } @@ -170,7 +170,6 @@ impl WeightInfo for SubstrateWeight { // Storage: Battlepass Battlepasses (r:1 w:0) // Storage: Battlepass BattlepassStates (r:1 w:0) // Storage: Control OrgStates (r:1 w:0) - // Storage: Control MemberStates (r:1 w:0) // Storage: Control Orgs (r:1 w:0) // Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) // Storage: Battlepass ClaimedBattlepasses (r:1 w:0) @@ -184,9 +183,9 @@ impl WeightInfo for SubstrateWeight { // Storage: Uniques CollectionMaxSupply (r:1 w:0) // Storage: Uniques Account (r:0 w:1) fn claim_reward() -> Weight { - // Minimum execution time: 130_000 nanoseconds. - Weight::from_ref_time(132_000_000) - .saturating_add(T::DbWeight::get().reads(20)) + // Minimum execution time: 126_000 nanoseconds. + Weight::from_ref_time(128_000_000) + .saturating_add(T::DbWeight::get().reads(19)) .saturating_add(T::DbWeight::get().writes(7)) } // Storage: Battlepass Battlepasses (r:1 w:0) @@ -196,7 +195,7 @@ impl WeightInfo for SubstrateWeight { // Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) // Storage: Battlepass Levels (r:0 w:1) fn add_level() -> Weight { - // Minimum execution time: 39_000 nanoseconds. + // Minimum execution time: 38_000 nanoseconds. Weight::from_ref_time(39_000_000) .saturating_add(T::DbWeight::get().reads(5)) .saturating_add(T::DbWeight::get().writes(1)) @@ -208,8 +207,8 @@ impl WeightInfo for SubstrateWeight { // Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) // Storage: Battlepass Levels (r:1 w:1) fn remove_level() -> Weight { - // Minimum execution time: 41_000 nanoseconds. - Weight::from_ref_time(44_000_000) + // Minimum execution time: 42_000 nanoseconds. + Weight::from_ref_time(43_000_000) .saturating_add(T::DbWeight::get().reads(6)) .saturating_add(T::DbWeight::get().writes(1)) } @@ -219,7 +218,7 @@ impl WeightInfo for SubstrateWeight { // Storage: Control Orgs (r:1 w:0) // Storage: Battlepass BattlepassInfoByOrg (r:1 w:1) fn add_bot() -> Weight { - // Minimum execution time: 36_000 nanoseconds. + // Minimum execution time: 37_000 nanoseconds. Weight::from_ref_time(38_000_000) .saturating_add(T::DbWeight::get().reads(5)) .saturating_add(T::DbWeight::get().writes(1)) @@ -238,8 +237,8 @@ impl WeightInfo for () { // Storage: Battlepass BattlepassStates (r:0 w:1) // Storage: Battlepass Battlepasses (r:0 w:1) fn create_battlepass() -> Weight { - // Minimum execution time: 68_000 nanoseconds. - Weight::from_ref_time(69_000_000) + // Minimum execution time: 69_000 nanoseconds. + Weight::from_ref_time(70_000_000) .saturating_add(RocksDbWeight::get().reads(5)) .saturating_add(RocksDbWeight::get().writes(7)) } @@ -248,15 +247,14 @@ impl WeightInfo for () { // Storage: Control OrgStates (r:1 w:0) // Storage: Control Orgs (r:1 w:0) fn update_battlepass() -> Weight { - // Minimum execution time: 35_000 nanoseconds. - Weight::from_ref_time(36_000_000) + // Minimum execution time: 36_000 nanoseconds. + Weight::from_ref_time(37_000_000) .saturating_add(RocksDbWeight::get().reads(4)) .saturating_add(RocksDbWeight::get().writes(1)) } // Storage: Battlepass Battlepasses (r:1 w:0) // Storage: Battlepass BattlepassStates (r:1 w:0) // Storage: Control OrgStates (r:1 w:0) - // Storage: Control MemberStates (r:1 w:0) // Storage: Control Orgs (r:1 w:0) // Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) // Storage: Battlepass ClaimedBattlepasses (r:1 w:1) @@ -268,9 +266,9 @@ impl WeightInfo for () { // Storage: Uniques CollectionMaxSupply (r:1 w:0) // Storage: Uniques Account (r:0 w:1) fn claim_battlepass() -> Weight { - // Minimum execution time: 97_000 nanoseconds. - Weight::from_ref_time(100_000_000) - .saturating_add(RocksDbWeight::get().reads(13)) + // Minimum execution time: 93_000 nanoseconds. + Weight::from_ref_time(102_000_000) + .saturating_add(RocksDbWeight::get().reads(12)) .saturating_add(RocksDbWeight::get().writes(7)) } // Storage: Battlepass Battlepasses (r:1 w:0) @@ -290,7 +288,7 @@ impl WeightInfo for () { // Storage: Battlepass BattlepassInfoByOrg (r:1 w:1) fn conclude_battlepass() -> Weight { // Minimum execution time: 38_000 nanoseconds. - Weight::from_ref_time(41_000_000) + Weight::from_ref_time(39_000_000) .saturating_add(RocksDbWeight::get().reads(4)) .saturating_add(RocksDbWeight::get().writes(2)) } @@ -299,12 +297,13 @@ impl WeightInfo for () { // Storage: Control OrgStates (r:1 w:0) // Storage: Control Orgs (r:1 w:0) // Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) - // Storage: Control MemberStates (r:1 w:0) + // Storage: Battlepass ClaimedBattlepasses (r:1 w:0) + // Storage: RmrkCore Nfts (r:1 w:0) // Storage: Battlepass Points (r:0 w:1) fn set_points() -> Weight { - // Minimum execution time: 40_000 nanoseconds. - Weight::from_ref_time(42_000_000) - .saturating_add(RocksDbWeight::get().reads(6)) + // Minimum execution time: 46_000 nanoseconds. + Weight::from_ref_time(47_000_000) + .saturating_add(RocksDbWeight::get().reads(7)) .saturating_add(RocksDbWeight::get().writes(1)) } // Storage: Battlepass Battlepasses (r:1 w:0) @@ -319,8 +318,8 @@ impl WeightInfo for () { // Storage: Battlepass Rewards (r:0 w:1) // Storage: Battlepass RewardStates (r:0 w:1) fn create_reward() -> Weight { - // Minimum execution time: 77_000 nanoseconds. - Weight::from_ref_time(79_000_000) + // Minimum execution time: 78_000 nanoseconds. + Weight::from_ref_time(80_000_000) .saturating_add(RocksDbWeight::get().reads(7)) .saturating_add(RocksDbWeight::get().writes(6)) } @@ -332,8 +331,8 @@ impl WeightInfo for () { // Storage: Control Orgs (r:1 w:0) // Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) fn update_reward() -> Weight { - // Minimum execution time: 47_000 nanoseconds. - Weight::from_ref_time(50_000_000) + // Minimum execution time: 45_000 nanoseconds. + Weight::from_ref_time(46_000_000) .saturating_add(RocksDbWeight::get().reads(7)) .saturating_add(RocksDbWeight::get().writes(1)) } @@ -343,8 +342,8 @@ impl WeightInfo for () { // Storage: Control Orgs (r:1 w:0) // Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) fn disable_reward() -> Weight { - // Minimum execution time: 39_000 nanoseconds. - Weight::from_ref_time(39_000_000) + // Minimum execution time: 40_000 nanoseconds. + Weight::from_ref_time(43_000_000) .saturating_add(RocksDbWeight::get().reads(5)) .saturating_add(RocksDbWeight::get().writes(1)) } @@ -354,7 +353,6 @@ impl WeightInfo for () { // Storage: Battlepass Battlepasses (r:1 w:0) // Storage: Battlepass BattlepassStates (r:1 w:0) // Storage: Control OrgStates (r:1 w:0) - // Storage: Control MemberStates (r:1 w:0) // Storage: Control Orgs (r:1 w:0) // Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) // Storage: Battlepass ClaimedBattlepasses (r:1 w:0) @@ -368,9 +366,9 @@ impl WeightInfo for () { // Storage: Uniques CollectionMaxSupply (r:1 w:0) // Storage: Uniques Account (r:0 w:1) fn claim_reward() -> Weight { - // Minimum execution time: 130_000 nanoseconds. - Weight::from_ref_time(132_000_000) - .saturating_add(RocksDbWeight::get().reads(20)) + // Minimum execution time: 126_000 nanoseconds. + Weight::from_ref_time(128_000_000) + .saturating_add(RocksDbWeight::get().reads(19)) .saturating_add(RocksDbWeight::get().writes(7)) } // Storage: Battlepass Battlepasses (r:1 w:0) @@ -380,7 +378,7 @@ impl WeightInfo for () { // Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) // Storage: Battlepass Levels (r:0 w:1) fn add_level() -> Weight { - // Minimum execution time: 39_000 nanoseconds. + // Minimum execution time: 38_000 nanoseconds. Weight::from_ref_time(39_000_000) .saturating_add(RocksDbWeight::get().reads(5)) .saturating_add(RocksDbWeight::get().writes(1)) @@ -392,8 +390,8 @@ impl WeightInfo for () { // Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) // Storage: Battlepass Levels (r:1 w:1) fn remove_level() -> Weight { - // Minimum execution time: 41_000 nanoseconds. - Weight::from_ref_time(44_000_000) + // Minimum execution time: 42_000 nanoseconds. + Weight::from_ref_time(43_000_000) .saturating_add(RocksDbWeight::get().reads(6)) .saturating_add(RocksDbWeight::get().writes(1)) } @@ -403,7 +401,7 @@ impl WeightInfo for () { // Storage: Control Orgs (r:1 w:0) // Storage: Battlepass BattlepassInfoByOrg (r:1 w:1) fn add_bot() -> Weight { - // Minimum execution time: 36_000 nanoseconds. + // Minimum execution time: 37_000 nanoseconds. Weight::from_ref_time(38_000_000) .saturating_add(RocksDbWeight::get().reads(5)) .saturating_add(RocksDbWeight::get().writes(1)) From 6dcd13daf121e3125d8f99eb28268a6903d62a5a Mon Sep 17 00:00:00 2001 From: vasylenko-yevhen Date: Fri, 24 Feb 2023 10:14:58 +0200 Subject: [PATCH 30/49] allows root account to add bot account to the battlepass --- battlepass/src/lib.rs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/battlepass/src/lib.rs b/battlepass/src/lib.rs index 0dadccdfe..4e574e33d 100644 --- a/battlepass/src/lib.rs +++ b/battlepass/src/lib.rs @@ -13,7 +13,7 @@ #![cfg_attr(not(feature = "std"), no_std)] pub use pallet::*; -use frame_support::{pallet_prelude::*, transactional}; +use frame_support::{pallet_prelude::*, transactional, dispatch::{RawOrigin}}; use frame_system::pallet_prelude::*; use sp_std::convert::TryInto; use sp_runtime::traits::{AtLeast32BitUnsigned, Hash}; @@ -811,15 +811,15 @@ pub mod pallet { battlepass_id: T::Hash, bot: T::AccountId ) -> DispatchResult { - let sender = ensure_signed(origin)?; + ensure_signed(origin.clone())?; // check if Battlepass exists let battlepass = Self::get_battlepass(battlepass_id).ok_or(Error::::BattlepassUnknown)?; // check if Battlepass is not ended ensure!(!Self::check_battlepass_state(battlepass_id, BattlepassState::ENDED)?, Error::::BattlepassStateWrong); // check if Org is active ensure!(T::Control::is_org_active(&battlepass.org_id), Error::::OrgUnknownOrInactive); - // check permissions (prime) - ensure!(Self::is_prime(&battlepass.org_id, sender.clone())?, Error::::AuthorizationError); + // check permissions (prime or root) + ensure!(Self::is_prime_or_root(&battlepass.org_id, origin)?, Error::::AuthorizationError); BattlepassInfoByOrg::::try_mutate(battlepass.org_id, |info| -> Result<(), DispatchError> { if let Some(inf) = info { @@ -853,6 +853,16 @@ impl Pallet { Ok(Self::is_prime(org_id, who.clone())? || Self::is_bot(org_id, who)?) } + fn is_prime_or_root(org_id: &T::Hash, who: T::RuntimeOrigin) -> Result { + match who.into() { + Ok(RawOrigin::Root) => Ok(true), + Ok(RawOrigin::Signed(t)) => { + Self::is_prime(org_id, t) + }, + _ => Ok(false) + } + } + fn is_level_reached(battlepass_id: &T::Hash, account: &T::AccountId, level: u8) -> bool { let user_points = Self::get_points(battlepass_id, account); let levels = Levels::::iter_prefix(battlepass_id) From ffbff312498e337aaa34db4c526e92281230f008 Mon Sep 17 00:00:00 2001 From: vasylenko-yevhen Date: Sat, 25 Feb 2023 19:29:09 +0200 Subject: [PATCH 31/49] Correctly validate `add_bot` caller --- battlepass/src/lib.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/battlepass/src/lib.rs b/battlepass/src/lib.rs index 4e574e33d..ae90603f3 100644 --- a/battlepass/src/lib.rs +++ b/battlepass/src/lib.rs @@ -811,7 +811,6 @@ pub mod pallet { battlepass_id: T::Hash, bot: T::AccountId ) -> DispatchResult { - ensure_signed(origin.clone())?; // check if Battlepass exists let battlepass = Self::get_battlepass(battlepass_id).ok_or(Error::::BattlepassUnknown)?; // check if Battlepass is not ended From b899affd216b0459729428404a19eb4fb4f48ff9 Mon Sep 17 00:00:00 2001 From: FiberMan Date: Sun, 26 Feb 2023 00:21:31 +0100 Subject: [PATCH 32/49] fix: update_battlepass should update any number of fields --- battlepass/src/lib.rs | 6 +++--- battlepass/src/tests.rs | 9 +++++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/battlepass/src/lib.rs b/battlepass/src/lib.rs index ae90603f3..b014c69a8 100644 --- a/battlepass/src/lib.rs +++ b/battlepass/src/lib.rs @@ -426,9 +426,9 @@ pub mod pallet { // check permissions (prime) ensure!(Self::is_prime(&battlepass.org_id, creator.clone())?, Error::::AuthorizationError); - battlepass.name = name.clone().unwrap(); - battlepass.cid = cid.clone().unwrap(); - battlepass.price = price.clone().unwrap(); + if name.is_some() { battlepass.name = name.clone().unwrap() }; + if cid.is_some() { battlepass.cid = cid.clone().unwrap() }; + if price.is_some() { battlepass.price = price.clone().unwrap() }; Battlepasses::::insert(battlepass_id, battlepass); diff --git a/battlepass/src/tests.rs b/battlepass/src/tests.rs index 0f0b6e07d..b6094cb32 100644 --- a/battlepass/src/tests.rs +++ b/battlepass/src/tests.rs @@ -264,6 +264,15 @@ fn update_battlepass_test() { assert_eq!(updated.cid, new_cid.clone()); assert_eq!(updated.price, new_price.clone()); + // Should update some fields in battlepass + assert_ok!( + Battlepass::update_battlepass(Origin::signed(creator), battlepass_id, None, None, Some(100)), + ); + // Check if Battlepass updated + let updated = Battlepass::get_battlepass(battlepass_id).unwrap(); + assert_eq!(updated.name, new_name.clone()); + assert_eq!(updated.cid, new_cid.clone()); + assert_eq!(updated.price, 100); // Should not update if Battlepass state is ENDED assert_ok!( From 47475494fbb98105b511eb16839ecac614b99b4d Mon Sep 17 00:00:00 2001 From: FiberMan Date: Tue, 28 Feb 2023 05:57:07 +0100 Subject: [PATCH 33/49] Remove RMRK --- battlepass/Cargo.toml | 4 - battlepass/src/lib.rs | 117 +++++++++++++--------------- battlepass/src/mock.rs | 32 +------- battlepass/src/tests.rs | 56 ++++++-------- battlepass/src/weights.rs | 158 +++++++++++++++++++------------------- 5 files changed, 155 insertions(+), 212 deletions(-) diff --git a/battlepass/Cargo.toml b/battlepass/Cargo.toml index 0a297b9c8..72d4322a0 100644 --- a/battlepass/Cargo.toml +++ b/battlepass/Cargo.toml @@ -26,8 +26,6 @@ frame-system = { git = "https://github.com/paritytech/substrate", branch = "polk frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36", default-features = false, optional = true } pallet-uniques = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } -pallet-rmrk-core = { git = "https://github.com/rmrk-team/rmrk-substrate", default-features = false, tag = "0.3.0" } -rmrk-traits = { git = "https://github.com/rmrk-team/rmrk-substrate", default-features = false, tag = "0.3.0" } orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.36", default-features = false } @@ -69,8 +67,6 @@ std = [ "orml-currencies/std", "pallet-uniques/std", - "pallet-rmrk-core/std", - "rmrk-traits/std", "gamedao-control/std", "gamedao-traits/std", diff --git a/battlepass/src/lib.rs b/battlepass/src/lib.rs index b014c69a8..fdf7f546b 100644 --- a/battlepass/src/lib.rs +++ b/battlepass/src/lib.rs @@ -13,7 +13,8 @@ #![cfg_attr(not(feature = "std"), no_std)] pub use pallet::*; -use frame_support::{pallet_prelude::*, transactional, dispatch::{RawOrigin}}; +use frame_support::{pallet_prelude::*, transactional, dispatch::RawOrigin}; +use frame_support::traits::tokens::nonfungibles::Inspect; use frame_system::pallet_prelude::*; use sp_std::convert::TryInto; use sp_runtime::traits::{AtLeast32BitUnsigned, Hash}; @@ -21,7 +22,6 @@ use gamedao_traits::ControlTrait; #[cfg(feature = "runtime-benchmarks")] use gamedao_traits::ControlBenchmarkingTrait; use orml_traits::{MultiCurrency, MultiReservableCurrency}; -use rmrk_traits::{primitives::PartId, Collection, Nft, ResourceInfoMin, AccountIdOrCollectionNftTuple}; pub mod types; pub use types::*; @@ -34,14 +34,6 @@ pub mod weights; pub use weights::WeightInfo; pub type String = BoundedVec::StringLimit>; -pub type Symbol = BoundedVec::SymbolLimit>; -pub type Resource = BoundedVec< - ResourceInfoMin< - BoundedVec::StringLimit>, - BoundedVec::PartsLimit>, - >, - ::MaxResourcesOnMint, ->; pub trait BattlepassHelper { fn collection(i: u32) -> CollectionId; @@ -68,7 +60,7 @@ pub mod pallet { pub struct Pallet(_); #[pallet::config] - pub trait Config: frame_system::Config + pallet_rmrk_core::Config { + pub trait Config: frame_system::Config + pallet_uniques::Config { type RuntimeEvent: From> + IsType<::RuntimeEvent> + Into<::RuntimeEvent>; @@ -100,25 +92,12 @@ pub mod pallet { #[cfg(feature = "runtime-benchmarks")] type ControlBenchmarkHelper: ControlBenchmarkingTrait; - type Rmrk: Collection, Symbol, Self::AccountId, Self::CollectionId> - + Nft, Resource, Self::CollectionId, Self::ItemId>; - type BattlepassHelper: BattlepassHelper; /// The maximum length of a name, cid or metadata strings stored on-chain. #[pallet::constant] type StringLimit: Get; - /// The maximum length of a Collection symbol. - #[pallet::constant] - type SymbolLimit: Get; - - /// The maximum number of parts each resource may have - #[pallet::constant] - type PartsLimit: Get; - - type MaxResourcesOnMint: Get; - /// The CurrencyId which is used as a native token. #[pallet::constant] type NativeTokenId: Get; @@ -452,7 +431,7 @@ pub mod pallet { battlepass_id: T::Hash, for_who: T::AccountId, ) -> DispatchResult { - let by_who = ensure_signed(origin)?; + let by_who = ensure_signed(origin.clone())?; // check if Battlepass exists let battlepass = Self::get_battlepass(battlepass_id).ok_or(Error::::BattlepassUnknown)?; // check if Battlepass in ACTIVE state @@ -464,7 +443,7 @@ pub mod pallet { // check if Battlepass already claimed ensure!(!ClaimedBattlepasses::::contains_key(battlepass_id, for_who.clone()), Error::::BattlepassClaimed); - let nft_id = Self::do_claim_battlepass(by_who.clone(), for_who.clone(), battlepass_id, battlepass.collection_id)?; + let nft_id = Self::do_claim_battlepass(battlepass.creator.clone(), for_who.clone(), battlepass_id, battlepass.collection_id)?; Self::deposit_event(Event::BattlepassClaimed { by_who, for_who, org_id: battlepass.org_id, battlepass_id, nft_id }); @@ -706,7 +685,7 @@ pub mod pallet { reward_id: T::Hash, for_who: T::AccountId, ) -> DispatchResult { - let by_who = ensure_signed(origin)?; + let by_who = ensure_signed(origin.clone())?; // check if Reward exists let reward = Self::get_reward(reward_id).ok_or(Error::::RewardUnknown)?; // check if Reward is active @@ -715,6 +694,7 @@ pub mod pallet { ensure!(!ClaimedRewards::::contains_key(&reward_id, &for_who), Error::::RewardClaimed); // check if Battlepass exists let battlepass = Self::get_battlepass(&reward.battlepass_id).ok_or(Error::::BattlepassUnknown)?; + let creator = battlepass.creator.clone(); // check if Battlepass in ACTIVE state ensure!(Self::check_battlepass_state(reward.battlepass_id, BattlepassState::ACTIVE)?, Error::::BattlepassStateWrong); // check if Org is active @@ -727,7 +707,7 @@ pub mod pallet { // check if user has reached the required Level ensure!(Self::is_level_reached(&reward.battlepass_id, &for_who, reward.level), Error::::LevelNotReached); - let nft_id = Self::do_claim_reward(for_who.clone(), reward_id, reward.collection_id, reward.transferable)?; + let nft_id = Self::do_claim_reward(creator, for_who.clone(), reward_id, reward.collection_id)?; Self::deposit_event(Event::RewardClaimed {reward_id, claimer: for_who, collection_id: reward.collection_id, nft_id} ); @@ -892,15 +872,42 @@ impl Pallet { fn create_collection(owner: T::AccountId, max: Option) -> Result { let metadata = BoundedVec::truncate_from(b"meta".to_vec()); // TODO: what should be here? - let symbol = BoundedVec::truncate_from(b"symbol".to_vec()); // TODO: what should be here? let collection_index = Self::bump_collection_index()?; let collection_id = T::BattlepassHelper::collection(collection_index); + let origin = OriginFor::::from(RawOrigin::Signed(owner.clone())); - T::Rmrk::collection_create(owner, collection_id, metadata, max, symbol)?; + pallet_uniques::Pallet::::do_create_collection( + collection_id, + owner.clone(), + owner.clone(), + T::CollectionDeposit::get(), + false, + pallet_uniques::Event::Created { + collection: collection_id, + creator: owner.clone(), + owner: owner.clone(), + }, + )?; + pallet_uniques::Pallet::::set_collection_metadata(origin.clone(), collection_id, metadata, false)?; + pallet_uniques::Pallet::::freeze_collection(origin.clone(), collection_id)?; + if max.is_some() { + pallet_uniques::Pallet::::set_collection_max_supply(origin, collection_id, max.unwrap())?; + } Ok(collection_id) } + fn create_nft(creator: T::AccountId, for_who: T::AccountId, collection_id: T::CollectionId, nft_id: T::ItemId, metadata: BoundedVec::StringLimit>) -> DispatchResult { + let creator = OriginFor::::from(RawOrigin::Signed(creator)); + + pallet_uniques::Pallet::::do_mint(collection_id, nft_id, for_who, |_details| { + Ok(()) + })?; + pallet_uniques::Pallet::::set_metadata(creator, collection_id, nft_id, metadata, false)?; + + Ok(()) + } + fn check_battlepass_state(battlepass_id: T::Hash, state: BattlepassState) -> Result { let current_state = Self::get_battlepass_state(battlepass_id).ok_or(Error::::BattlepassStateUnknown)?; @@ -940,24 +947,14 @@ impl Pallet { Ok(battlepass_id) } - fn do_claim_battlepass(by_who: T::AccountId, for_who: T::AccountId, battlepass_id: T::Hash, collection_id: T::CollectionId) -> Result { + fn do_claim_battlepass(creator: T::AccountId, for_who: T::AccountId, battlepass_id: T::Hash, collection_id: T::CollectionId) -> Result { let nft_index = Self::bump_nft_index()?; let nft_id: T::ItemId = T::BattlepassHelper::item(nft_index); - + let metadata = BoundedVec::truncate_from(battlepass_id.encode()); + // Create Battlepass NFT - let metadata = battlepass_id.encode(); - let _ = T::Rmrk::nft_mint( - by_who.clone(), // sender - for_who.clone(), // owner - nft_id, // nft_id - collection_id, // collection_id - None, // royalty_recipient - None, // royalty_amount - BoundedVec::truncate_from(metadata), // metadata TODO: what should be here? - false, // transferable - None // resources - )?; - + Self::create_nft(creator, for_who.clone(), collection_id, nft_id, metadata)?; + ClaimedBattlepasses::::insert(battlepass_id, &for_who, nft_id); Ok(nft_id) @@ -996,25 +993,15 @@ impl Pallet { Ok(reward_id) } - fn do_claim_reward(claimer: T::AccountId, reward_id: T::Hash, collection_id: T::CollectionId, transferable: bool) -> Result { + fn do_claim_reward(creator: T::AccountId, for_who: T::AccountId, reward_id: T::Hash, collection_id: T::CollectionId) -> Result { let nft_index = Self::bump_nft_index()?; let nft_id = T::BattlepassHelper::item(nft_index); + let metadata = BoundedVec::truncate_from(reward_id.encode()); - // Create Battlepass NFT - let metadata = reward_id.encode(); - let _ = T::Rmrk::nft_mint( - claimer.clone(), // sender - claimer.clone(), // owner - nft_id, // nft_id - collection_id, // collection_id - None, // royalty_recipient - None, // royalty_amount - BoundedVec::truncate_from(metadata), // metadata TODO: what should be here? - transferable, // transferable - None // resources - )?; + // Create Reward NFT + Self::create_nft(creator, for_who.clone(), collection_id, nft_id, metadata)?; - ClaimedRewards::::insert(&reward_id, &claimer, nft_id); + ClaimedRewards::::insert(&reward_id, &for_who, nft_id); Ok(nft_id) } @@ -1023,13 +1010,13 @@ impl Pallet { // check if user claimed Battlepass NFT let bp_nft_id = Self::get_claimed_battlepass(battlepass_id, &account).ok_or(Error::::BattlepassNotClaimed)?; // check if Battlepass NFT exists - let bp_nft = pallet_rmrk_core::Pallet::::nfts(&battlepass.collection_id, bp_nft_id).ok_or(Error::::BattlepassNftUnknown)?; + let bp_nft_owner = pallet_uniques::Pallet::::owner(battlepass.collection_id, bp_nft_id).ok_or(Error::::BattlepassNftUnknown)?; // validate Battlepass NFT ownership - ensure!(AccountIdOrCollectionNftTuple::AccountId(account.clone()) == bp_nft.owner, Error::::NotOwnNft); + ensure!(account.clone() == bp_nft_owner, Error::::NotOwnNft); // validate Battlepass NFT metadata - let metadata: String = BoundedVec::truncate_from(battlepass_id.encode()); - ensure!(metadata == bp_nft.metadata, Error::::BattlepassNftInvalid); - + let bp_nft_metadata = as Inspect>::attribute(&battlepass.collection_id, &bp_nft_id, &[]); + ensure!(Some(battlepass_id.encode()) == bp_nft_metadata, Error::::BattlepassNftInvalid); + Ok(()) } } diff --git a/battlepass/src/mock.rs b/battlepass/src/mock.rs index 96fc3ab7b..34e4fbb63 100644 --- a/battlepass/src/mock.rs +++ b/battlepass/src/mock.rs @@ -70,7 +70,6 @@ construct_runtime!( Tokens: orml_tokens::{Pallet, Storage, Event, Config}, Currencies: orml_currencies::{Pallet, Call}, Uniques: pallet_uniques::{Pallet, Call, Storage, Event}, - RmrkCore: pallet_rmrk_core::{Pallet, Call, Event, Storage}, Control: gamedao_control, Battlepass: gamedao_battlepass::{Pallet, Call, Event, Storage}, } @@ -164,7 +163,7 @@ parameter_types! { pub const ValueLimit: u32 = 64; // Max 64 bytes per value pub MetadataDepositBase: Balance = 0; pub MetadataDepositPerByte: Balance = 0; - + pub const StringLimit: u32 = 64; } impl pallet_uniques::Config for Test { @@ -174,7 +173,7 @@ impl pallet_uniques::Config for Test { type Currency = PalletBalances; type ForceOrigin = EnsureRoot; type CreateOrigin = AsEnsureOriginWithArg>; - type Locker = pallet_rmrk_core::Pallet; + type Locker = (); type CollectionDeposit = CollectionDeposit; type ItemDeposit = ItemDeposit; type MetadataDepositBase = MetadataDepositBase; @@ -186,29 +185,6 @@ impl pallet_uniques::Config for Test { type WeightInfo = (); } -parameter_types! { - pub const ResourceSymbolLimit: u32 = 10; - pub const PartsLimit: u32 = 25; - pub const CollectionSymbolLimit: u32 = 100; - pub const MaxPriorities: u32 = 25; - pub const NestingBudget: u32 = 3; - pub const MaxResourcesOnMint: u32 = 100; - pub const StringLimit: u32 = 64; -} - -impl pallet_rmrk_core::Config for Test { - type RuntimeEvent = RuntimeEvent; - type ProtocolOrigin = EnsureRoot; - type ResourceSymbolLimit = ResourceSymbolLimit; - type PartsLimit = PartsLimit; - type MaxPriorities = MaxPriorities; - type CollectionSymbolLimit = CollectionSymbolLimit; - type MaxResourcesOnMint = MaxResourcesOnMint; - type NestingBudget = NestingBudget; - type WeightInfo = pallet_rmrk_core::weights::SubstrateWeight; - type TransferHooks = (); -} - parameter_types! { pub const NativeTokenId: CurrencyId = NATIVE_TOKEN_ID; pub const ProtocolTokenId: CurrencyId = PROTOCOL_TOKEN_ID; @@ -239,12 +215,8 @@ impl gamedao_battlepass::Config for Test { type Control = Control; #[cfg(feature = "runtime-benchmarks")] type ControlBenchmarkHelper = Control; - type Rmrk = RmrkCore; type BattlepassHelper = gamedao_battlepass::BpHelper; type StringLimit = StringLimit; - type SymbolLimit = CollectionSymbolLimit; - type PartsLimit = PartsLimit; - type MaxResourcesOnMint = MaxResourcesOnMint; type NativeTokenId = NativeTokenId; type ProtocolTokenId = ProtocolTokenId; type WeightInfo = (); diff --git a/battlepass/src/tests.rs b/battlepass/src/tests.rs index b6094cb32..b49b2b872 100644 --- a/battlepass/src/tests.rs +++ b/battlepass/src/tests.rs @@ -1,14 +1,13 @@ #![cfg(test)] use frame_support::{assert_noop, assert_ok}; -use pallet_rmrk_core::Nfts; -use rmrk_traits::AccountIdOrCollectionNftTuple; +use frame_support::traits::tokens::nonfungibles::{InspectEnumerable, Mutate, Transfer}; use sp_core::H256; use crate::mock::{ new_test_ext, RuntimeOrigin as Origin, Test, //System, - Battlepass, Control, RmrkCore, + Battlepass, Control, Uniques, ALICE, BOB, EVA, TOM, BOT, PROTOCOL_TOKEN_ID, PAYMENT_TOKEN_ID, DOLLARS, AccountId, StringLimit, //Event }; @@ -158,7 +157,7 @@ fn create_battlepass_test(){ Battlepass::create_battlepass(Origin::signed(creator), org_id, string(), string(), 10) ); // Check if NFT collection created - assert_eq!(pallet_rmrk_core::Collections::::contains_key(0), true); + assert_eq!(>::collections().any(|x| x == 0), true); // Check if Battlepass created let battlepass = Battlepasses::::get(battlepass_id_1); assert_eq!(battlepass.is_some(), true); @@ -177,7 +176,7 @@ fn create_battlepass_test(){ Battlepass::create_battlepass(Origin::signed(creator), org_id, string(), string(), 10) ); // Check if NFT collection created - assert_eq!(pallet_rmrk_core::Collections::::contains_key(1), true); + assert_eq!(>::collections().any(|x| x == 1), true); // Check if Battlepass created let battlepass = Battlepasses::::get(battlepass_id_2); assert_eq!(battlepass.is_some(), true); @@ -190,11 +189,6 @@ fn create_battlepass_test(){ assert_eq!(bp_info.is_some(), true); assert_eq!(bp_info.clone().unwrap().count, 2); assert_eq!(bp_info.clone().unwrap().active, None); - - // Check events (collection created, battlepass created) - // println!("Events: {}", System::events().len()); - // System::assert_has_event(Event::Battlepass(crate::Event::BattlepassCreated { org_id, battlepass_id, season: 1 })); - // System::assert_has_event(mock::Event::RmrkCore(pallet_rmrk_core::Event::CollectionCreated { issuer: creator, collection_id: 0 })); }) } @@ -502,7 +496,7 @@ fn claim_battlepass_test() { assert_eq!(nft_id.is_some(), true); assert_eq!(nft_id.unwrap(), 0); // Check if NFT minted - assert_eq!(pallet_rmrk_core::Nfts::::contains_key(0, 0), true); + assert_eq!(>::items(&0).any(|x| x == 0) , true); // Should not claim if it was already claimed assert_noop!( @@ -522,7 +516,7 @@ fn claim_battlepass_test() { assert_eq!(nft_id.is_some(), true); assert_eq!(nft_id.unwrap(), 1); // Check if NFT minted - assert_eq!(pallet_rmrk_core::Nfts::::contains_key(0, 1), true); + assert_eq!(>::items(&0).any(|x| x == 1) , true); // Should claim for accounts outside of org assert_ok!( @@ -684,10 +678,9 @@ fn create_reward_test() { Battlepass::create_reward(Origin::signed(creator), battlepass_id, string(), string(), Some(1), 1, true) ); // Check if NFT collection created - let collection = pallet_rmrk_core::Collections::::get(1); - assert_eq!(collection.is_some(), true); + assert_eq!(>::collections().any(|x| x == 1) , true); // Check if collection owner is a Prime - assert_eq!(collection.unwrap().issuer, creator); + assert_eq!(>::collection_owner(&1).unwrap(), creator); // Check if Reward created let reward_id = get_reward_hash(battlepass_id, 1, true, 1); let reward = Rewards::::get(reward_id); @@ -704,10 +697,9 @@ fn create_reward_test() { Battlepass::create_reward(Origin::signed(creator), battlepass_id, string(), string(), Some(1), 1, true) ); // Check if NFT collection created - let collection = pallet_rmrk_core::Collections::::get(2); - assert_eq!(collection.is_some(), true); + assert_eq!(>::collections().any(|x| x == 2) , true); // Check if collection owner is a Prime - assert_eq!(collection.unwrap().issuer, creator); + assert_eq!(>::collection_owner(&2).unwrap(), creator); // Check if Reward created let reward_id = get_reward_hash(battlepass_id, 1, true, 2); let reward = Rewards::::get(reward_id); @@ -730,10 +722,9 @@ fn create_reward_test() { Battlepass::create_reward(Origin::signed(BOT), battlepass_id, string(), string(), Some(1), 1, true) ); // Check if NFT collection created - let collection = pallet_rmrk_core::Collections::::get(3); - assert_eq!(collection.is_some(), true); + assert_eq!(>::collections().any(|x| x == 3) , true); // Check if collection owner is a Prime - assert_eq!(collection.unwrap().issuer, creator); + assert_eq!(>::collection_owner(&3).unwrap(), creator); // Check if Reward created let reward_id = get_reward_hash(battlepass_id, 1, true, 3); let reward = Rewards::::get(reward_id); @@ -1053,7 +1044,7 @@ fn claim_reward_test() { Battlepass::claim_battlepass(Origin::signed(creator), battlepass_id, not_creator) ); assert_ok!( - RmrkCore::burn_nft(Origin::signed(not_creator), 0, 0) + >::burn(&0, &0, None) ); assert_noop!( Battlepass::claim_reward(Origin::signed(not_creator), reward_id, not_creator), @@ -1064,13 +1055,11 @@ fn claim_reward_test() { assert_ok!( Battlepass::claim_battlepass(Origin::signed(creator), battlepass_id, creator) ); - Nfts::::mutate(0, 1, |nft| { - if let Some(n) = nft { - n.transferable = true - } - }); assert_ok!( - RmrkCore::send(Origin::signed(creator), 0, 1, AccountIdOrCollectionNftTuple::AccountId(not_member)) + Uniques::thaw_collection(Origin::signed(creator), 0) + ); + assert_ok!( + >::transfer(&0, &1, ¬_member) ); assert_noop!( Battlepass::claim_reward(Origin::signed(creator), reward_id, creator), @@ -1081,11 +1070,10 @@ fn claim_reward_test() { assert_ok!( Battlepass::claim_battlepass(Origin::signed(creator), battlepass_id, not_creator_2) ); - Nfts::::mutate(0, 2, |nft| { - if let Some(n) = nft { - n.metadata = BoundedVec::truncate_from(b"crap".to_vec()) - } - }); + let new_metadata = BoundedVec::truncate_from(b"crap".to_vec()); + assert_ok!( + Uniques::set_metadata(Origin::signed(creator), 0, 2, new_metadata, false) + ); assert_noop!( Battlepass::claim_reward(Origin::signed(not_creator_2), reward_id, not_creator_2), Error::::BattlepassNftInvalid @@ -1131,7 +1119,7 @@ fn claim_reward_test() { ); assert_noop!( Battlepass::claim_reward(Origin::signed(not_creator_4), reward_id, not_creator_4), - pallet_rmrk_core::Error::::CollectionFullOrLocked + pallet_uniques::Error::::MaxSupplyReached ); // Should claim Reward by Bot diff --git a/battlepass/src/weights.rs b/battlepass/src/weights.rs index b491ec7d8..8cc9e404f 100644 --- a/battlepass/src/weights.rs +++ b/battlepass/src/weights.rs @@ -2,7 +2,7 @@ //! Autogenerated weights for gamedao_battlepass //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-02-24, STEPS: `20`, REPEAT: 10, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2023-02-28, STEPS: `20`, REPEAT: 10, LOW RANGE: `[]`, HIGH RANGE: `[]` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: None, DB CACHE: 1024 // Executed Command: @@ -49,14 +49,14 @@ impl WeightInfo for SubstrateWeight { // Storage: Battlepass BattlepassInfoByOrg (r:1 w:1) // Storage: Battlepass CollectionIndex (r:1 w:1) // Storage: Uniques Class (r:1 w:1) - // Storage: RmrkCore Collections (r:0 w:1) + // Storage: Uniques ClassMetadataOf (r:1 w:1) // Storage: Uniques ClassAccount (r:0 w:1) // Storage: Battlepass BattlepassStates (r:0 w:1) // Storage: Battlepass Battlepasses (r:0 w:1) fn create_battlepass() -> Weight { - // Minimum execution time: 69_000 nanoseconds. - Weight::from_ref_time(70_000_000) - .saturating_add(T::DbWeight::get().reads(5)) + // Minimum execution time: 95_000 nanoseconds. + Weight::from_ref_time(97_000_000) + .saturating_add(T::DbWeight::get().reads(6)) .saturating_add(T::DbWeight::get().writes(7)) } // Storage: Battlepass Battlepasses (r:1 w:1) @@ -64,7 +64,7 @@ impl WeightInfo for SubstrateWeight { // Storage: Control OrgStates (r:1 w:0) // Storage: Control Orgs (r:1 w:0) fn update_battlepass() -> Weight { - // Minimum execution time: 36_000 nanoseconds. + // Minimum execution time: 37_000 nanoseconds. Weight::from_ref_time(37_000_000) .saturating_add(T::DbWeight::get().reads(4)) .saturating_add(T::DbWeight::get().writes(1)) @@ -76,17 +76,16 @@ impl WeightInfo for SubstrateWeight { // Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) // Storage: Battlepass ClaimedBattlepasses (r:1 w:1) // Storage: Battlepass NftIndex (r:1 w:1) - // Storage: RmrkCore Nfts (r:1 w:1) - // Storage: RmrkCore Collections (r:1 w:1) // Storage: Uniques Asset (r:1 w:1) // Storage: Uniques Class (r:1 w:1) // Storage: Uniques CollectionMaxSupply (r:1 w:0) + // Storage: Uniques InstanceMetadataOf (r:1 w:1) // Storage: Uniques Account (r:0 w:1) fn claim_battlepass() -> Weight { - // Minimum execution time: 93_000 nanoseconds. - Weight::from_ref_time(102_000_000) - .saturating_add(T::DbWeight::get().reads(12)) - .saturating_add(T::DbWeight::get().writes(7)) + // Minimum execution time: 102_000 nanoseconds. + Weight::from_ref_time(103_000_000) + .saturating_add(T::DbWeight::get().reads(11)) + .saturating_add(T::DbWeight::get().writes(6)) } // Storage: Battlepass Battlepasses (r:1 w:0) // Storage: Battlepass BattlepassStates (r:1 w:1) @@ -94,8 +93,8 @@ impl WeightInfo for SubstrateWeight { // Storage: Control Orgs (r:1 w:0) // Storage: Battlepass BattlepassInfoByOrg (r:1 w:1) fn activate_battlepass() -> Weight { - // Minimum execution time: 40_000 nanoseconds. - Weight::from_ref_time(41_000_000) + // Minimum execution time: 41_000 nanoseconds. + Weight::from_ref_time(42_000_000) .saturating_add(T::DbWeight::get().reads(5)) .saturating_add(T::DbWeight::get().writes(2)) } @@ -104,8 +103,8 @@ impl WeightInfo for SubstrateWeight { // Storage: Control Orgs (r:1 w:0) // Storage: Battlepass BattlepassInfoByOrg (r:1 w:1) fn conclude_battlepass() -> Weight { - // Minimum execution time: 38_000 nanoseconds. - Weight::from_ref_time(39_000_000) + // Minimum execution time: 40_000 nanoseconds. + Weight::from_ref_time(41_000_000) .saturating_add(T::DbWeight::get().reads(4)) .saturating_add(T::DbWeight::get().writes(2)) } @@ -115,12 +114,13 @@ impl WeightInfo for SubstrateWeight { // Storage: Control Orgs (r:1 w:0) // Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) // Storage: Battlepass ClaimedBattlepasses (r:1 w:0) - // Storage: RmrkCore Nfts (r:1 w:0) + // Storage: Uniques Asset (r:1 w:0) + // Storage: Uniques InstanceMetadataOf (r:1 w:0) // Storage: Battlepass Points (r:0 w:1) fn set_points() -> Weight { - // Minimum execution time: 46_000 nanoseconds. - Weight::from_ref_time(47_000_000) - .saturating_add(T::DbWeight::get().reads(7)) + // Minimum execution time: 50_000 nanoseconds. + Weight::from_ref_time(55_000_000) + .saturating_add(T::DbWeight::get().reads(8)) .saturating_add(T::DbWeight::get().writes(1)) } // Storage: Battlepass Battlepasses (r:1 w:0) @@ -130,15 +130,16 @@ impl WeightInfo for SubstrateWeight { // Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) // Storage: Battlepass CollectionIndex (r:1 w:1) // Storage: Uniques Class (r:1 w:1) - // Storage: RmrkCore Collections (r:0 w:1) + // Storage: Uniques ClassMetadataOf (r:1 w:1) + // Storage: Uniques CollectionMaxSupply (r:1 w:1) // Storage: Uniques ClassAccount (r:0 w:1) // Storage: Battlepass Rewards (r:0 w:1) // Storage: Battlepass RewardStates (r:0 w:1) fn create_reward() -> Weight { - // Minimum execution time: 78_000 nanoseconds. - Weight::from_ref_time(80_000_000) - .saturating_add(T::DbWeight::get().reads(7)) - .saturating_add(T::DbWeight::get().writes(6)) + // Minimum execution time: 118_000 nanoseconds. + Weight::from_ref_time(122_000_000) + .saturating_add(T::DbWeight::get().reads(9)) + .saturating_add(T::DbWeight::get().writes(7)) } // Storage: Battlepass Rewards (r:1 w:1) // Storage: Battlepass RewardStates (r:1 w:0) @@ -149,7 +150,7 @@ impl WeightInfo for SubstrateWeight { // Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) fn update_reward() -> Weight { // Minimum execution time: 45_000 nanoseconds. - Weight::from_ref_time(46_000_000) + Weight::from_ref_time(47_000_000) .saturating_add(T::DbWeight::get().reads(7)) .saturating_add(T::DbWeight::get().writes(1)) } @@ -159,8 +160,8 @@ impl WeightInfo for SubstrateWeight { // Storage: Control Orgs (r:1 w:0) // Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) fn disable_reward() -> Weight { - // Minimum execution time: 40_000 nanoseconds. - Weight::from_ref_time(43_000_000) + // Minimum execution time: 39_000 nanoseconds. + Weight::from_ref_time(41_000_000) .saturating_add(T::DbWeight::get().reads(5)) .saturating_add(T::DbWeight::get().writes(1)) } @@ -173,20 +174,19 @@ impl WeightInfo for SubstrateWeight { // Storage: Control Orgs (r:1 w:0) // Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) // Storage: Battlepass ClaimedBattlepasses (r:1 w:0) - // Storage: RmrkCore Nfts (r:2 w:1) + // Storage: Uniques Asset (r:2 w:1) + // Storage: Uniques InstanceMetadataOf (r:2 w:1) // Storage: Battlepass Points (r:1 w:0) // Storage: Battlepass Levels (r:2 w:0) // Storage: Battlepass NftIndex (r:1 w:1) - // Storage: RmrkCore Collections (r:1 w:1) - // Storage: Uniques Asset (r:1 w:1) // Storage: Uniques Class (r:1 w:1) // Storage: Uniques CollectionMaxSupply (r:1 w:0) // Storage: Uniques Account (r:0 w:1) fn claim_reward() -> Weight { - // Minimum execution time: 126_000 nanoseconds. - Weight::from_ref_time(128_000_000) + // Minimum execution time: 141_000 nanoseconds. + Weight::from_ref_time(149_000_000) .saturating_add(T::DbWeight::get().reads(19)) - .saturating_add(T::DbWeight::get().writes(7)) + .saturating_add(T::DbWeight::get().writes(6)) } // Storage: Battlepass Battlepasses (r:1 w:0) // Storage: Battlepass BattlepassStates (r:1 w:0) @@ -195,8 +195,8 @@ impl WeightInfo for SubstrateWeight { // Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) // Storage: Battlepass Levels (r:0 w:1) fn add_level() -> Weight { - // Minimum execution time: 38_000 nanoseconds. - Weight::from_ref_time(39_000_000) + // Minimum execution time: 36_000 nanoseconds. + Weight::from_ref_time(37_000_000) .saturating_add(T::DbWeight::get().reads(5)) .saturating_add(T::DbWeight::get().writes(1)) } @@ -207,8 +207,8 @@ impl WeightInfo for SubstrateWeight { // Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) // Storage: Battlepass Levels (r:1 w:1) fn remove_level() -> Weight { - // Minimum execution time: 42_000 nanoseconds. - Weight::from_ref_time(43_000_000) + // Minimum execution time: 40_000 nanoseconds. + Weight::from_ref_time(42_000_000) .saturating_add(T::DbWeight::get().reads(6)) .saturating_add(T::DbWeight::get().writes(1)) } @@ -218,8 +218,8 @@ impl WeightInfo for SubstrateWeight { // Storage: Control Orgs (r:1 w:0) // Storage: Battlepass BattlepassInfoByOrg (r:1 w:1) fn add_bot() -> Weight { - // Minimum execution time: 37_000 nanoseconds. - Weight::from_ref_time(38_000_000) + // Minimum execution time: 38_000 nanoseconds. + Weight::from_ref_time(40_000_000) .saturating_add(T::DbWeight::get().reads(5)) .saturating_add(T::DbWeight::get().writes(1)) } @@ -232,14 +232,14 @@ impl WeightInfo for () { // Storage: Battlepass BattlepassInfoByOrg (r:1 w:1) // Storage: Battlepass CollectionIndex (r:1 w:1) // Storage: Uniques Class (r:1 w:1) - // Storage: RmrkCore Collections (r:0 w:1) + // Storage: Uniques ClassMetadataOf (r:1 w:1) // Storage: Uniques ClassAccount (r:0 w:1) // Storage: Battlepass BattlepassStates (r:0 w:1) // Storage: Battlepass Battlepasses (r:0 w:1) fn create_battlepass() -> Weight { - // Minimum execution time: 69_000 nanoseconds. - Weight::from_ref_time(70_000_000) - .saturating_add(RocksDbWeight::get().reads(5)) + // Minimum execution time: 95_000 nanoseconds. + Weight::from_ref_time(97_000_000) + .saturating_add(RocksDbWeight::get().reads(6)) .saturating_add(RocksDbWeight::get().writes(7)) } // Storage: Battlepass Battlepasses (r:1 w:1) @@ -247,7 +247,7 @@ impl WeightInfo for () { // Storage: Control OrgStates (r:1 w:0) // Storage: Control Orgs (r:1 w:0) fn update_battlepass() -> Weight { - // Minimum execution time: 36_000 nanoseconds. + // Minimum execution time: 37_000 nanoseconds. Weight::from_ref_time(37_000_000) .saturating_add(RocksDbWeight::get().reads(4)) .saturating_add(RocksDbWeight::get().writes(1)) @@ -259,17 +259,16 @@ impl WeightInfo for () { // Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) // Storage: Battlepass ClaimedBattlepasses (r:1 w:1) // Storage: Battlepass NftIndex (r:1 w:1) - // Storage: RmrkCore Nfts (r:1 w:1) - // Storage: RmrkCore Collections (r:1 w:1) // Storage: Uniques Asset (r:1 w:1) // Storage: Uniques Class (r:1 w:1) // Storage: Uniques CollectionMaxSupply (r:1 w:0) + // Storage: Uniques InstanceMetadataOf (r:1 w:1) // Storage: Uniques Account (r:0 w:1) fn claim_battlepass() -> Weight { - // Minimum execution time: 93_000 nanoseconds. - Weight::from_ref_time(102_000_000) - .saturating_add(RocksDbWeight::get().reads(12)) - .saturating_add(RocksDbWeight::get().writes(7)) + // Minimum execution time: 102_000 nanoseconds. + Weight::from_ref_time(103_000_000) + .saturating_add(RocksDbWeight::get().reads(11)) + .saturating_add(RocksDbWeight::get().writes(6)) } // Storage: Battlepass Battlepasses (r:1 w:0) // Storage: Battlepass BattlepassStates (r:1 w:1) @@ -277,8 +276,8 @@ impl WeightInfo for () { // Storage: Control Orgs (r:1 w:0) // Storage: Battlepass BattlepassInfoByOrg (r:1 w:1) fn activate_battlepass() -> Weight { - // Minimum execution time: 40_000 nanoseconds. - Weight::from_ref_time(41_000_000) + // Minimum execution time: 41_000 nanoseconds. + Weight::from_ref_time(42_000_000) .saturating_add(RocksDbWeight::get().reads(5)) .saturating_add(RocksDbWeight::get().writes(2)) } @@ -287,8 +286,8 @@ impl WeightInfo for () { // Storage: Control Orgs (r:1 w:0) // Storage: Battlepass BattlepassInfoByOrg (r:1 w:1) fn conclude_battlepass() -> Weight { - // Minimum execution time: 38_000 nanoseconds. - Weight::from_ref_time(39_000_000) + // Minimum execution time: 40_000 nanoseconds. + Weight::from_ref_time(41_000_000) .saturating_add(RocksDbWeight::get().reads(4)) .saturating_add(RocksDbWeight::get().writes(2)) } @@ -298,12 +297,13 @@ impl WeightInfo for () { // Storage: Control Orgs (r:1 w:0) // Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) // Storage: Battlepass ClaimedBattlepasses (r:1 w:0) - // Storage: RmrkCore Nfts (r:1 w:0) + // Storage: Uniques Asset (r:1 w:0) + // Storage: Uniques InstanceMetadataOf (r:1 w:0) // Storage: Battlepass Points (r:0 w:1) fn set_points() -> Weight { - // Minimum execution time: 46_000 nanoseconds. - Weight::from_ref_time(47_000_000) - .saturating_add(RocksDbWeight::get().reads(7)) + // Minimum execution time: 50_000 nanoseconds. + Weight::from_ref_time(55_000_000) + .saturating_add(RocksDbWeight::get().reads(8)) .saturating_add(RocksDbWeight::get().writes(1)) } // Storage: Battlepass Battlepasses (r:1 w:0) @@ -313,15 +313,16 @@ impl WeightInfo for () { // Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) // Storage: Battlepass CollectionIndex (r:1 w:1) // Storage: Uniques Class (r:1 w:1) - // Storage: RmrkCore Collections (r:0 w:1) + // Storage: Uniques ClassMetadataOf (r:1 w:1) + // Storage: Uniques CollectionMaxSupply (r:1 w:1) // Storage: Uniques ClassAccount (r:0 w:1) // Storage: Battlepass Rewards (r:0 w:1) // Storage: Battlepass RewardStates (r:0 w:1) fn create_reward() -> Weight { - // Minimum execution time: 78_000 nanoseconds. - Weight::from_ref_time(80_000_000) - .saturating_add(RocksDbWeight::get().reads(7)) - .saturating_add(RocksDbWeight::get().writes(6)) + // Minimum execution time: 118_000 nanoseconds. + Weight::from_ref_time(122_000_000) + .saturating_add(RocksDbWeight::get().reads(9)) + .saturating_add(RocksDbWeight::get().writes(7)) } // Storage: Battlepass Rewards (r:1 w:1) // Storage: Battlepass RewardStates (r:1 w:0) @@ -332,7 +333,7 @@ impl WeightInfo for () { // Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) fn update_reward() -> Weight { // Minimum execution time: 45_000 nanoseconds. - Weight::from_ref_time(46_000_000) + Weight::from_ref_time(47_000_000) .saturating_add(RocksDbWeight::get().reads(7)) .saturating_add(RocksDbWeight::get().writes(1)) } @@ -342,8 +343,8 @@ impl WeightInfo for () { // Storage: Control Orgs (r:1 w:0) // Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) fn disable_reward() -> Weight { - // Minimum execution time: 40_000 nanoseconds. - Weight::from_ref_time(43_000_000) + // Minimum execution time: 39_000 nanoseconds. + Weight::from_ref_time(41_000_000) .saturating_add(RocksDbWeight::get().reads(5)) .saturating_add(RocksDbWeight::get().writes(1)) } @@ -356,20 +357,19 @@ impl WeightInfo for () { // Storage: Control Orgs (r:1 w:0) // Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) // Storage: Battlepass ClaimedBattlepasses (r:1 w:0) - // Storage: RmrkCore Nfts (r:2 w:1) + // Storage: Uniques Asset (r:2 w:1) + // Storage: Uniques InstanceMetadataOf (r:2 w:1) // Storage: Battlepass Points (r:1 w:0) // Storage: Battlepass Levels (r:2 w:0) // Storage: Battlepass NftIndex (r:1 w:1) - // Storage: RmrkCore Collections (r:1 w:1) - // Storage: Uniques Asset (r:1 w:1) // Storage: Uniques Class (r:1 w:1) // Storage: Uniques CollectionMaxSupply (r:1 w:0) // Storage: Uniques Account (r:0 w:1) fn claim_reward() -> Weight { - // Minimum execution time: 126_000 nanoseconds. - Weight::from_ref_time(128_000_000) + // Minimum execution time: 141_000 nanoseconds. + Weight::from_ref_time(149_000_000) .saturating_add(RocksDbWeight::get().reads(19)) - .saturating_add(RocksDbWeight::get().writes(7)) + .saturating_add(RocksDbWeight::get().writes(6)) } // Storage: Battlepass Battlepasses (r:1 w:0) // Storage: Battlepass BattlepassStates (r:1 w:0) @@ -378,8 +378,8 @@ impl WeightInfo for () { // Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) // Storage: Battlepass Levels (r:0 w:1) fn add_level() -> Weight { - // Minimum execution time: 38_000 nanoseconds. - Weight::from_ref_time(39_000_000) + // Minimum execution time: 36_000 nanoseconds. + Weight::from_ref_time(37_000_000) .saturating_add(RocksDbWeight::get().reads(5)) .saturating_add(RocksDbWeight::get().writes(1)) } @@ -390,8 +390,8 @@ impl WeightInfo for () { // Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) // Storage: Battlepass Levels (r:1 w:1) fn remove_level() -> Weight { - // Minimum execution time: 42_000 nanoseconds. - Weight::from_ref_time(43_000_000) + // Minimum execution time: 40_000 nanoseconds. + Weight::from_ref_time(42_000_000) .saturating_add(RocksDbWeight::get().reads(6)) .saturating_add(RocksDbWeight::get().writes(1)) } @@ -401,8 +401,8 @@ impl WeightInfo for () { // Storage: Control Orgs (r:1 w:0) // Storage: Battlepass BattlepassInfoByOrg (r:1 w:1) fn add_bot() -> Weight { - // Minimum execution time: 37_000 nanoseconds. - Weight::from_ref_time(38_000_000) + // Minimum execution time: 38_000 nanoseconds. + Weight::from_ref_time(40_000_000) .saturating_add(RocksDbWeight::get().reads(5)) .saturating_add(RocksDbWeight::get().writes(1)) } From 96e6755a20d37ff6187ae02b7af014c1b26aa890 Mon Sep 17 00:00:00 2001 From: FiberMan Date: Tue, 28 Feb 2023 15:30:20 +0100 Subject: [PATCH 34/49] fix: should create battlepass if there is active one --- battlepass/src/lib.rs | 20 ++++++++-- battlepass/src/tests.rs | 34 ++++++++++++---- battlepass/src/weights.rs | 84 +++++++++++++++++++-------------------- 3 files changed, 85 insertions(+), 53 deletions(-) diff --git a/battlepass/src/lib.rs b/battlepass/src/lib.rs index fdf7f546b..454031870 100644 --- a/battlepass/src/lib.rs +++ b/battlepass/src/lib.rs @@ -357,9 +357,7 @@ pub mod pallet { ensure!(T::Control::is_org_active(&org_id), Error::::OrgUnknownOrInactive); // check permissions (prime) ensure!(Self::is_prime(&org_id, creator.clone())?, Error::::AuthorizationError); - let (battlepass_count, maybe_active, _) = Self::get_battlepass_info(&org_id); - // check if there is no active battlepass for the Org - ensure!(maybe_active.is_none(), Error::::BattlepassExists); + let (battlepass_count, _, _) = Self::get_battlepass_info(&org_id); let new_season = battlepass_count + 1; // Create a collection to store Battlepass NFTs @@ -472,6 +470,9 @@ pub mod pallet { ensure!(T::Control::is_org_active(&battlepass.org_id), Error::::OrgUnknownOrInactive); // check permissions (prime) ensure!(Self::is_prime(&battlepass.org_id, sender.clone())?, Error::::AuthorizationError); + // check if there is no active battlepass for the Org + let (_, maybe_active, _) = Self::get_battlepass_info(&battlepass.org_id); + ensure!(maybe_active.is_none(), Error::::BattlepassExists); Self::change_battlepass_state(battlepass.org_id, battlepass_id, BattlepassState::ACTIVE)?; @@ -942,7 +943,18 @@ impl Pallet { Battlepasses::::insert(&battlepass_id, battlepass); BattlepassStates::::insert(&battlepass_id, BattlepassState::DRAFT); - BattlepassInfoByOrg::::insert(org_id, BattlepassInfo{count: new_season, active: None, bot: None}); + if new_season == 1 { + BattlepassInfoByOrg::::insert(org_id, BattlepassInfo{count: new_season, active: None, bot: None}); + } else { + BattlepassInfoByOrg::::try_mutate(org_id, |info| -> Result<(), DispatchError> { + if let Some(inf) = info { + inf.count = new_season; + } else { + return Err(Error::::BattlepassInfoUnknown)?; + } + Ok(()) + })?; + } Ok(battlepass_id) } diff --git a/battlepass/src/tests.rs b/battlepass/src/tests.rs index b49b2b872..298a877d4 100644 --- a/battlepass/src/tests.rs +++ b/battlepass/src/tests.rs @@ -120,6 +120,7 @@ fn create_battlepass_test(){ let not_member = EVA; let battlepass_id_1 = get_battlepass_hash(creator, org_id, 1, 10, 0); let battlepass_id_2 = get_battlepass_hash(creator, org_id, 2, 10, 1); + let battlepass_id_3 = get_battlepass_hash(creator, org_id, 3, 10, 2); // Should not create for non existing Org assert_noop!( @@ -189,6 +190,28 @@ fn create_battlepass_test(){ assert_eq!(bp_info.is_some(), true); assert_eq!(bp_info.clone().unwrap().count, 2); assert_eq!(bp_info.clone().unwrap().active, None); + + // Should create another Battlepass (even if there is an ACTIVE one) + assert_ok!( + Battlepass::activate_battlepass(Origin::signed(creator), battlepass_id_1) + ); + assert_ok!( + Battlepass::create_battlepass(Origin::signed(creator), org_id, string(), string(), 10) + ); + // Check if NFT collection created + assert_eq!(>::collections().any(|x| x == 1), true); + // Check if Battlepass created + let battlepass = Battlepasses::::get(battlepass_id_3); + assert_eq!(battlepass.is_some(), true); + assert_eq!(battlepass.unwrap().season, 3); + assert_eq!(Battlepasses::::contains_key(battlepass_id_3), true); + // Check if BattlepassState is DRAFT + assert_eq!(Battlepass::get_battlepass_state(battlepass_id_3), Some(types::BattlepassState::DRAFT)); + // Check if BattlepassInfo created (count = 3, active = battlepass_id_1) + let bp_info = BattlepassInfoByOrg::::get(org_id); + assert_eq!(bp_info.is_some(), true); + assert_eq!(bp_info.clone().unwrap().count, 3); + assert_eq!(bp_info.clone().unwrap().active, Some(battlepass_id_1)); }) } @@ -289,6 +312,7 @@ fn activate_battlepass_test() { new_test_ext().execute_with(|| { let org_id = create_org(); let battlepass_id = create_battlepass(org_id); + let battlepass_id_2 = create_battlepass(org_id); let wrong_battlepass_id = ::Hashing::hash_of(&"123"); let creator = ALICE; let not_creator = BOB; @@ -334,7 +358,7 @@ fn activate_battlepass_test() { // Check if BattlepassInfo changed (count = 1, active = battlepass_id) let bp_info = BattlepassInfoByOrg::::get(org_id); assert_eq!(bp_info.is_some(), true); - assert_eq!(bp_info.clone().unwrap().count, 1); + assert_eq!(bp_info.clone().unwrap().count, 2); assert_eq!(bp_info.clone().unwrap().active, Some(battlepass_id)); @@ -344,16 +368,12 @@ fn activate_battlepass_test() { Error::::BattlepassStateWrong ); - // Should not create if Org has an active battlepass + // Should not activate if Org has an active battlepass assert_noop!( - Battlepass::create_battlepass(Origin::signed(creator), org_id, string(), string(), 10), + Battlepass::activate_battlepass(Origin::signed(creator), battlepass_id_2), Error::::BattlepassExists ); - // Check events (battlepass activated) - // println!("Events: {}", System::events().len()); - // System::assert_has_event(Event::Battlepass(crate::Event::BattlepassActivated { by_who: creator, org_id, battlepass_id } )); - }) } diff --git a/battlepass/src/weights.rs b/battlepass/src/weights.rs index 8cc9e404f..865bd335c 100644 --- a/battlepass/src/weights.rs +++ b/battlepass/src/weights.rs @@ -54,8 +54,8 @@ impl WeightInfo for SubstrateWeight { // Storage: Battlepass BattlepassStates (r:0 w:1) // Storage: Battlepass Battlepasses (r:0 w:1) fn create_battlepass() -> Weight { - // Minimum execution time: 95_000 nanoseconds. - Weight::from_ref_time(97_000_000) + // Minimum execution time: 93_000 nanoseconds. + Weight::from_ref_time(95_000_000) .saturating_add(T::DbWeight::get().reads(6)) .saturating_add(T::DbWeight::get().writes(7)) } @@ -64,8 +64,8 @@ impl WeightInfo for SubstrateWeight { // Storage: Control OrgStates (r:1 w:0) // Storage: Control Orgs (r:1 w:0) fn update_battlepass() -> Weight { - // Minimum execution time: 37_000 nanoseconds. - Weight::from_ref_time(37_000_000) + // Minimum execution time: 35_000 nanoseconds. + Weight::from_ref_time(36_000_000) .saturating_add(T::DbWeight::get().reads(4)) .saturating_add(T::DbWeight::get().writes(1)) } @@ -82,8 +82,8 @@ impl WeightInfo for SubstrateWeight { // Storage: Uniques InstanceMetadataOf (r:1 w:1) // Storage: Uniques Account (r:0 w:1) fn claim_battlepass() -> Weight { - // Minimum execution time: 102_000 nanoseconds. - Weight::from_ref_time(103_000_000) + // Minimum execution time: 101_000 nanoseconds. + Weight::from_ref_time(105_000_000) .saturating_add(T::DbWeight::get().reads(11)) .saturating_add(T::DbWeight::get().writes(6)) } @@ -93,8 +93,8 @@ impl WeightInfo for SubstrateWeight { // Storage: Control Orgs (r:1 w:0) // Storage: Battlepass BattlepassInfoByOrg (r:1 w:1) fn activate_battlepass() -> Weight { - // Minimum execution time: 41_000 nanoseconds. - Weight::from_ref_time(42_000_000) + // Minimum execution time: 43_000 nanoseconds. + Weight::from_ref_time(44_000_000) .saturating_add(T::DbWeight::get().reads(5)) .saturating_add(T::DbWeight::get().writes(2)) } @@ -103,8 +103,8 @@ impl WeightInfo for SubstrateWeight { // Storage: Control Orgs (r:1 w:0) // Storage: Battlepass BattlepassInfoByOrg (r:1 w:1) fn conclude_battlepass() -> Weight { - // Minimum execution time: 40_000 nanoseconds. - Weight::from_ref_time(41_000_000) + // Minimum execution time: 38_000 nanoseconds. + Weight::from_ref_time(40_000_000) .saturating_add(T::DbWeight::get().reads(4)) .saturating_add(T::DbWeight::get().writes(2)) } @@ -118,8 +118,8 @@ impl WeightInfo for SubstrateWeight { // Storage: Uniques InstanceMetadataOf (r:1 w:0) // Storage: Battlepass Points (r:0 w:1) fn set_points() -> Weight { - // Minimum execution time: 50_000 nanoseconds. - Weight::from_ref_time(55_000_000) + // Minimum execution time: 51_000 nanoseconds. + Weight::from_ref_time(53_000_000) .saturating_add(T::DbWeight::get().reads(8)) .saturating_add(T::DbWeight::get().writes(1)) } @@ -136,8 +136,8 @@ impl WeightInfo for SubstrateWeight { // Storage: Battlepass Rewards (r:0 w:1) // Storage: Battlepass RewardStates (r:0 w:1) fn create_reward() -> Weight { - // Minimum execution time: 118_000 nanoseconds. - Weight::from_ref_time(122_000_000) + // Minimum execution time: 116_000 nanoseconds. + Weight::from_ref_time(120_000_000) .saturating_add(T::DbWeight::get().reads(9)) .saturating_add(T::DbWeight::get().writes(7)) } @@ -149,7 +149,7 @@ impl WeightInfo for SubstrateWeight { // Storage: Control Orgs (r:1 w:0) // Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) fn update_reward() -> Weight { - // Minimum execution time: 45_000 nanoseconds. + // Minimum execution time: 46_000 nanoseconds. Weight::from_ref_time(47_000_000) .saturating_add(T::DbWeight::get().reads(7)) .saturating_add(T::DbWeight::get().writes(1)) @@ -183,8 +183,8 @@ impl WeightInfo for SubstrateWeight { // Storage: Uniques CollectionMaxSupply (r:1 w:0) // Storage: Uniques Account (r:0 w:1) fn claim_reward() -> Weight { - // Minimum execution time: 141_000 nanoseconds. - Weight::from_ref_time(149_000_000) + // Minimum execution time: 137_000 nanoseconds. + Weight::from_ref_time(141_000_000) .saturating_add(T::DbWeight::get().reads(19)) .saturating_add(T::DbWeight::get().writes(6)) } @@ -195,8 +195,8 @@ impl WeightInfo for SubstrateWeight { // Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) // Storage: Battlepass Levels (r:0 w:1) fn add_level() -> Weight { - // Minimum execution time: 36_000 nanoseconds. - Weight::from_ref_time(37_000_000) + // Minimum execution time: 39_000 nanoseconds. + Weight::from_ref_time(41_000_000) .saturating_add(T::DbWeight::get().reads(5)) .saturating_add(T::DbWeight::get().writes(1)) } @@ -218,8 +218,8 @@ impl WeightInfo for SubstrateWeight { // Storage: Control Orgs (r:1 w:0) // Storage: Battlepass BattlepassInfoByOrg (r:1 w:1) fn add_bot() -> Weight { - // Minimum execution time: 38_000 nanoseconds. - Weight::from_ref_time(40_000_000) + // Minimum execution time: 35_000 nanoseconds. + Weight::from_ref_time(35_000_000) .saturating_add(T::DbWeight::get().reads(5)) .saturating_add(T::DbWeight::get().writes(1)) } @@ -237,8 +237,8 @@ impl WeightInfo for () { // Storage: Battlepass BattlepassStates (r:0 w:1) // Storage: Battlepass Battlepasses (r:0 w:1) fn create_battlepass() -> Weight { - // Minimum execution time: 95_000 nanoseconds. - Weight::from_ref_time(97_000_000) + // Minimum execution time: 93_000 nanoseconds. + Weight::from_ref_time(95_000_000) .saturating_add(RocksDbWeight::get().reads(6)) .saturating_add(RocksDbWeight::get().writes(7)) } @@ -247,8 +247,8 @@ impl WeightInfo for () { // Storage: Control OrgStates (r:1 w:0) // Storage: Control Orgs (r:1 w:0) fn update_battlepass() -> Weight { - // Minimum execution time: 37_000 nanoseconds. - Weight::from_ref_time(37_000_000) + // Minimum execution time: 35_000 nanoseconds. + Weight::from_ref_time(36_000_000) .saturating_add(RocksDbWeight::get().reads(4)) .saturating_add(RocksDbWeight::get().writes(1)) } @@ -265,8 +265,8 @@ impl WeightInfo for () { // Storage: Uniques InstanceMetadataOf (r:1 w:1) // Storage: Uniques Account (r:0 w:1) fn claim_battlepass() -> Weight { - // Minimum execution time: 102_000 nanoseconds. - Weight::from_ref_time(103_000_000) + // Minimum execution time: 101_000 nanoseconds. + Weight::from_ref_time(105_000_000) .saturating_add(RocksDbWeight::get().reads(11)) .saturating_add(RocksDbWeight::get().writes(6)) } @@ -276,8 +276,8 @@ impl WeightInfo for () { // Storage: Control Orgs (r:1 w:0) // Storage: Battlepass BattlepassInfoByOrg (r:1 w:1) fn activate_battlepass() -> Weight { - // Minimum execution time: 41_000 nanoseconds. - Weight::from_ref_time(42_000_000) + // Minimum execution time: 43_000 nanoseconds. + Weight::from_ref_time(44_000_000) .saturating_add(RocksDbWeight::get().reads(5)) .saturating_add(RocksDbWeight::get().writes(2)) } @@ -286,8 +286,8 @@ impl WeightInfo for () { // Storage: Control Orgs (r:1 w:0) // Storage: Battlepass BattlepassInfoByOrg (r:1 w:1) fn conclude_battlepass() -> Weight { - // Minimum execution time: 40_000 nanoseconds. - Weight::from_ref_time(41_000_000) + // Minimum execution time: 38_000 nanoseconds. + Weight::from_ref_time(40_000_000) .saturating_add(RocksDbWeight::get().reads(4)) .saturating_add(RocksDbWeight::get().writes(2)) } @@ -301,8 +301,8 @@ impl WeightInfo for () { // Storage: Uniques InstanceMetadataOf (r:1 w:0) // Storage: Battlepass Points (r:0 w:1) fn set_points() -> Weight { - // Minimum execution time: 50_000 nanoseconds. - Weight::from_ref_time(55_000_000) + // Minimum execution time: 51_000 nanoseconds. + Weight::from_ref_time(53_000_000) .saturating_add(RocksDbWeight::get().reads(8)) .saturating_add(RocksDbWeight::get().writes(1)) } @@ -319,8 +319,8 @@ impl WeightInfo for () { // Storage: Battlepass Rewards (r:0 w:1) // Storage: Battlepass RewardStates (r:0 w:1) fn create_reward() -> Weight { - // Minimum execution time: 118_000 nanoseconds. - Weight::from_ref_time(122_000_000) + // Minimum execution time: 116_000 nanoseconds. + Weight::from_ref_time(120_000_000) .saturating_add(RocksDbWeight::get().reads(9)) .saturating_add(RocksDbWeight::get().writes(7)) } @@ -332,7 +332,7 @@ impl WeightInfo for () { // Storage: Control Orgs (r:1 w:0) // Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) fn update_reward() -> Weight { - // Minimum execution time: 45_000 nanoseconds. + // Minimum execution time: 46_000 nanoseconds. Weight::from_ref_time(47_000_000) .saturating_add(RocksDbWeight::get().reads(7)) .saturating_add(RocksDbWeight::get().writes(1)) @@ -366,8 +366,8 @@ impl WeightInfo for () { // Storage: Uniques CollectionMaxSupply (r:1 w:0) // Storage: Uniques Account (r:0 w:1) fn claim_reward() -> Weight { - // Minimum execution time: 141_000 nanoseconds. - Weight::from_ref_time(149_000_000) + // Minimum execution time: 137_000 nanoseconds. + Weight::from_ref_time(141_000_000) .saturating_add(RocksDbWeight::get().reads(19)) .saturating_add(RocksDbWeight::get().writes(6)) } @@ -378,8 +378,8 @@ impl WeightInfo for () { // Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) // Storage: Battlepass Levels (r:0 w:1) fn add_level() -> Weight { - // Minimum execution time: 36_000 nanoseconds. - Weight::from_ref_time(37_000_000) + // Minimum execution time: 39_000 nanoseconds. + Weight::from_ref_time(41_000_000) .saturating_add(RocksDbWeight::get().reads(5)) .saturating_add(RocksDbWeight::get().writes(1)) } @@ -401,8 +401,8 @@ impl WeightInfo for () { // Storage: Control Orgs (r:1 w:0) // Storage: Battlepass BattlepassInfoByOrg (r:1 w:1) fn add_bot() -> Weight { - // Minimum execution time: 38_000 nanoseconds. - Weight::from_ref_time(40_000_000) + // Minimum execution time: 35_000 nanoseconds. + Weight::from_ref_time(35_000_000) .saturating_add(RocksDbWeight::get().reads(5)) .saturating_add(RocksDbWeight::get().writes(1)) } From 68ca89c31424887f0d6b66dcce5c512f2f4319c8 Mon Sep 17 00:00:00 2001 From: 2075 <1140449+2075@users.noreply.github.com> Date: Mon, 6 Mar 2023 21:15:21 +0100 Subject: [PATCH 35/49] feat: add option for name and cid (#142) * feat: add option for name and cid * feat: update tests * feat: add mock, update test * feat: fix types * feat: rm unused * feat: update readme, benchmarking * Fix type --------- Co-authored-by: vasylenko-yevhen --- control/README.md | 16 +++++++++++----- control/src/benchmarking.rs | 9 ++++++--- control/src/lib.rs | 6 +++++- control/src/mock.rs | 1 + control/src/tests.rs | 25 +++++++++++++++++-------- 5 files changed, 40 insertions(+), 17 deletions(-) diff --git a/control/README.md b/control/README.md index a88cf03f3..f7f53109e 100755 --- a/control/README.md +++ b/control/README.md @@ -4,12 +4,14 @@ DAO core to create organizations with their segregated treasury and maintain mem ## Overview -Control is a wrapper for organizationsal bodies in the chain. +Control is a wrapper for organizations on chain. -Organizations consist of members as individual users/accounts. - -Every organization has attached treasury, which is managed collectively by its members with help of related modules. +Organizations consist of: + - members as individual users/accounts + - prime as the prime voter, allowed to call administrative extrinsics + - council as the organization's top voters and controllers +Every organization has a treasury attached, which is managed collectively by its members. ### Terminology @@ -28,7 +30,7 @@ Control is designed to make the following possible: * Allow users to create organizations with specified options. * Provide organizations with individual treasury account. -* Allow users to become a members of organizations. +* Allow users to become members of organizations. ## Interface @@ -56,6 +58,10 @@ The following example shows how to use the Control module in your runtime by exp * Use related module (flow) to raise funds via croudfunding. * Use related module (signal) to manage raised funds via proposals. +## Development + +Run tests in development: `cargo test -p gamedao-control` +Run benchmarking: `cargo test -p gamedao-control --features runtime-benchmarks` ## Related Modules diff --git a/control/src/benchmarking.rs b/control/src/benchmarking.rs index d9e72442d..eb4157ff4 100644 --- a/control/src/benchmarking.rs +++ b/control/src/benchmarking.rs @@ -48,8 +48,11 @@ benchmarks! { update_org { let caller: T::AccountId = whitelisted_caller(); fund_account::(&caller)?; + let text = BoundedVec::truncate_from((0..255).collect()); let org_id = as ControlBenchmarkingTrait>::create_org(caller.clone()).unwrap(); + let name = Some(text.clone()); + let cid = Some(text.clone()); let prime_id = Some(caller.clone()); let org_type = Some(OrgType::Individual); let access_model = Some(AccessModel::Voting); @@ -57,10 +60,10 @@ benchmarks! { let fee_model = Some(FeeModel::NoFees); let membership_fee: Option = Some(99_u32.saturated_into()); }: _( - RawOrigin::Signed(caller), org_id, prime_id, org_type, access_model.clone(), + RawOrigin::Signed(caller), org_id, name, cid, prime_id, org_type, access_model.clone(), member_limit, fee_model.clone(), membership_fee ) - + verify { let org = Orgs::::get(org_id).unwrap(); assert_eq!(org.membership_fee, membership_fee); @@ -161,7 +164,7 @@ benchmarks! { let currency_id = T::PaymentTokenId::get(); let amount: T::Balance = 300_000_000_000_00_u128.saturated_into(); fund_account::(&treasury_id)?; - + }: _(RawOrigin::Signed(caller), org_id, currency_id, beneficiary.clone(), amount) verify { diff --git a/control/src/lib.rs b/control/src/lib.rs index d7c79a784..022dcd7cf 100644 --- a/control/src/lib.rs +++ b/control/src/lib.rs @@ -372,6 +372,8 @@ pub mod pallet { pub fn update_org( origin: OriginFor, org_id: T::Hash, + name: Option>, + cid: Option>, prime_id: Option, org_type: Option, access_model: Option, @@ -383,10 +385,12 @@ pub mod pallet { // Create entity like a council Self::ensure_root_or_prime(origin, org.prime.clone(), org.org_type.clone())?; - let args = [prime_id.is_some(), fee_model.is_some(), membership_fee.is_some(), + let args = [ name.is_some(), cid.is_some(), prime_id.is_some(), fee_model.is_some(), membership_fee.is_some(), access_model.is_some(), member_limit.is_some(), org_type.is_some()]; ensure!(args.iter().any(|x| *x == true), Error::::NoChangesProvided); + if name.is_some() { org.name = name.clone().unwrap(); }; + if cid.is_some() { org.cid = cid.clone().unwrap(); }; if access_model.is_some() { org.access_model = access_model.clone().unwrap(); }; if org_type.is_some() { org.org_type = org_type.clone().unwrap(); }; if member_limit.is_some() { org.member_limit = member_limit.clone().unwrap(); }; diff --git a/control/src/mock.rs b/control/src/mock.rs index 4d85abc65..9b44bd460 100644 --- a/control/src/mock.rs +++ b/control/src/mock.rs @@ -143,6 +143,7 @@ frame_support::parameter_types! { pub const MinimumDeposit: Balance = 5 * DOLLARS; pub const ControlPalletId: PalletId = PalletId(*b"gd/cntrl"); pub const MaxMembers: u32 = 10000; + pub const StringLimit: u32 = 64; } impl pallet_control::Config for Test { type Balance = Balance; diff --git a/control/src/tests.rs b/control/src/tests.rs index d32748ae0..1963d4e26 100644 --- a/control/src/tests.rs +++ b/control/src/tests.rs @@ -2,7 +2,7 @@ use frame_support::{assert_noop, assert_ok}; use sp_runtime::traits::BadOrigin; -use sp_core::H256; +use sp_core::{H256, ConstU32}; use super::*; use mock::{new_test_ext, System, Test, RuntimeEvent as Event, Control, RuntimeOrigin as Origin, Tokens, CurrencyId, Balance, AccountId, ALICE, BOB, CHARLIE, PAYMENT_TOKEN_ID, PROTOCOL_TOKEN_ID, DOLLARS}; @@ -92,26 +92,31 @@ fn control_create_org() { #[test] fn control_update_org() { new_test_ext().execute_with(|| { + let current_block = 3; System::set_block_number(current_block); let org_id = create_org(AccessModel::Prime); + let bounded_str: BoundedVec> = BoundedVec::truncate_from(vec![1,2]); + let new_name: BoundedVec> = bounded_str.clone(); + let new_cid: BoundedVec> = bounded_str.clone(); + // Check if no changes were provided // Error: NoChangesProvided assert_noop!(Control::update_org( - Origin::signed(ALICE), org_id, None, None, None, None, None, None), + Origin::signed(ALICE), org_id, None, None, None, None, None, None, None, None), Error::::NoChangesProvided); // FeeModel::Transfer and no membership_fee provided // Error: NoChangesProvided assert_noop!(Control::update_org( - Origin::signed(ALICE), org_id, None, None, None, None, Some(FeeModel::Transfer), None), + Origin::signed(ALICE), org_id, None, None, None, None, None, None, Some(FeeModel::Transfer), None), Error::::MissingParameter); // Check if prime can be not a member // Error: NotMember assert_noop!(Control::update_org( - Origin::signed(ALICE), org_id, Some(BOB), None, None, None, None, None), + Origin::signed(ALICE), org_id, None, None, Some(BOB), None, None, None, None, None), Error::::NotMember); assert_ok!(Control::add_member(Origin::signed(ALICE), org_id, BOB)); @@ -119,14 +124,16 @@ fn control_update_org() { // Check if only prime can perform update_org // Error: BadOrigin assert_noop!(Control::update_org( - Origin::signed(BOB), org_id, None, Some(OrgType::Dao), None, None, None, None), + Origin::signed(BOB), org_id, None, None, None, Some(OrgType::Dao), None, None, None, None), BadOrigin); // Check if root can update - assert_ok!(Control::update_org(Origin::root(), org_id, None, None, None, None, None, Some(199 * DOLLARS))); + assert_ok!(Control::update_org(Origin::root(), org_id, None, None, None, None, None, None, None, Some(199 * DOLLARS))); // Check if update_org works as expected let prime_id = Some(BOB); + let name: Option>> = Some(new_name); + let cid: Option>> = Some(new_cid); let org_type = Some(OrgType::Dao); let access_model = Some(AccessModel::Voting); let member_limit = Some(100 as MemberLimit); @@ -134,11 +141,13 @@ fn control_update_org() { let membership_fee = Some(99 * DOLLARS); assert_ok!(Control::update_org( - Origin::signed(ALICE), org_id, prime_id, org_type.clone(), access_model.clone(), member_limit, + Origin::signed(ALICE), org_id, name.clone(), cid.clone(), prime_id, org_type.clone(), access_model.clone(), member_limit, fee_model.clone(), membership_fee)); let org = Orgs::::get(org_id).unwrap(); assert_eq!(org.prime, prime_id.clone().unwrap()); + assert_eq!(org.name, name.clone().unwrap()); + assert_eq!(org.cid, cid.clone().unwrap()); assert_eq!(org.org_type, org_type.clone().unwrap()); assert_eq!(org.access_model, access_model.clone().unwrap()); assert_eq!(org.member_limit, member_limit.unwrap()); @@ -157,7 +166,7 @@ fn control_update_org() { } #[test] -fn control_enable_deisable_org() { +fn control_enable_disable_org() { new_test_ext().execute_with(|| { let current_block = 3; System::set_block_number(current_block); From d084aca04b7af146c2b557bb8ab8a167507beec4 Mon Sep 17 00:00:00 2001 From: Yura Date: Thu, 9 Mar 2023 12:55:43 +0100 Subject: [PATCH 36/49] feat: bump substrate version from 0.9.36 to 0.9.38 (#141) * feat: bump substrate version from 0.9.36 to 0.9.38 * bump protocol to 1.3.0 * use CID as collection metadata --- battlepass/Cargo.toml | 38 +- battlepass/src/benchmarking.rs | 4 +- battlepass/src/lib.rs | 64 +-- battlepass/src/tests.rs | 72 +-- battlepass/src/weights.rs | 879 +++++++++++++++++++++------------ control/Cargo.toml | 34 +- control/src/weights.rs | 387 +++++++++------ flow/Cargo.toml | 28 +- flow/src/weights.rs | 209 +++++--- sense/Cargo.toml | 20 +- sense/src/weights.rs | 77 ++- signal/Cargo.toml | 30 +- signal/src/weights.rs | 197 +++++--- traits/Cargo.toml | 14 +- 14 files changed, 1279 insertions(+), 774 deletions(-) diff --git a/battlepass/Cargo.toml b/battlepass/Cargo.toml index 72d4322a0..123748318 100644 --- a/battlepass/Cargo.toml +++ b/battlepass/Cargo.toml @@ -5,7 +5,7 @@ # ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ [package] name = "gamedao-battlepass" -version = "1.2.0" +version = "1.3.0" authors = ["zero.io","gamedao.co"] repository = "https://github.com/gamedaoco/gamedao-protocol" edition = "2018" @@ -14,33 +14,33 @@ description = "BattlePass pallet provides functionality to create, manage and pa [dependencies] serde = { version = "1.0.143", default-features = false } -codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] } +codec = { package = "parity-scale-codec", version = "3.2.2", default-features = false, features = ["derive"] } scale-info = { version = "2.1.1", default-features = false, features = ["derive"] } -sp-core = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } -sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } -sp-std = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } -sp-storage = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } -sp-io = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.36", default-features=false } -frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36", default-features = false } -frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36", default-features = false } -frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36", default-features = false, optional = true } +sp-core = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } +sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } +sp-std = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } +sp-storage = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } +sp-io = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.38", default-features=false } +frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38", default-features = false } +frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38", default-features = false } +frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38", default-features = false, optional = true } -pallet-uniques = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } +pallet-uniques = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } -orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.36", default-features = false } +orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.38", default-features = false } gamedao-control = { package = "gamedao-control", path = "../control", default-features = false } gamedao-traits = { package = "gamedao-traits", path = "../traits", default-features = false } [dev-dependencies] -sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.36" } -codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] } +sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.38" } +codec = { package = "parity-scale-codec", version = "3.2.2", default-features = false, features = ["derive"] } -pallet-balances = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } -pallet-uniques = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } -orml-currencies = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.36", default-features = false } -orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.36", default-features = false } -orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.36", default-features = false } +pallet-balances = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } +pallet-uniques = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } +orml-currencies = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.38", default-features = false } +orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.38", default-features = false } +orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.38", default-features = false } [features] default = ['std'] diff --git a/battlepass/src/benchmarking.rs b/battlepass/src/benchmarking.rs index 27c34531f..1ad896b44 100644 --- a/battlepass/src/benchmarking.rs +++ b/battlepass/src/benchmarking.rs @@ -124,7 +124,9 @@ benchmarks! { set_bot::(caller.clone(), battlepass_id, bot.clone()); }: _(RawOrigin::Signed(bot), battlepass_id, caller.clone()) verify { - assert!(ClaimedBattlepasses::::get(battlepass_id, caller).is_some()); + let collection_id = T::BattlepassHelper::collection(0); + let item_id = T::BattlepassHelper::item(0); + assert!( as InspectEnumerable>::items(&collection_id).any(|x| x == item_id)); } activate_battlepass { diff --git a/battlepass/src/lib.rs b/battlepass/src/lib.rs index 454031870..34b9d5a73 100644 --- a/battlepass/src/lib.rs +++ b/battlepass/src/lib.rs @@ -14,7 +14,7 @@ pub use pallet::*; use frame_support::{pallet_prelude::*, transactional, dispatch::RawOrigin}; -use frame_support::traits::tokens::nonfungibles::Inspect; +use frame_support::traits::tokens::nonfungibles::InspectEnumerable; use frame_system::pallet_prelude::*; use sp_std::convert::TryInto; use sp_runtime::traits::{AtLeast32BitUnsigned, Hash}; @@ -94,7 +94,7 @@ pub mod pallet { type BattlepassHelper: BattlepassHelper; - /// The maximum length of a name, cid or metadata strings stored on-chain. + /// The maximum length of a name, cid strings stored on-chain. #[pallet::constant] type StringLimit: Get; @@ -212,20 +212,17 @@ pub mod pallet { AuthorizationError, CollectionUnknown, BattlepassExists, - BattlepassClaimed, - BattlepassNotClaimed, + BattlepassOwnershipExists, + BattlepassOwnershipDoesntExist, BattlepassUnknown, BattlepassStateUnknown, BattlepassStateWrong, BattlepassInfoUnknown, - BattlepassNftUnknown, - BattlepassNftInvalid, LevelNotReached, LevelUnknown, NoAvailableCollectionId, NoAvailableNftId, NoChangesProvided, - NotOwnNft, OrgPrimeUnknown, OrgUnknownOrInactive, RewardClaimed, @@ -254,18 +251,6 @@ pub mod pallet { #[pallet::storage] pub type BattlepassInfoByOrg = StorageMap<_, Blake2_128Concat, T::Hash, BattlepassInfo, OptionQuery>; - /// Claimed Battlepass-NFT by user and battlepass. - /// - /// ClaimedBattlepasses: map (Hash, AccountId) => ItemId - #[pallet::storage] - #[pallet::getter(fn get_claimed_battlepass)] - pub(super) type ClaimedBattlepasses = StorageDoubleMap<_, - Blake2_128Concat, T::Hash, - Blake2_128Concat, T::AccountId, - T::ItemId, - OptionQuery - >; - /// Total earned Points for users per each Battlepass. /// /// Points: map (Hash, AccountId) => u32 @@ -361,7 +346,7 @@ pub mod pallet { let new_season = battlepass_count + 1; // Create a collection to store Battlepass NFTs - let collection_id = Self::create_collection(creator.clone(), None)?; + let collection_id = Self::create_collection(creator.clone(), None, cid.clone())?; let battlepass_id = Self::do_create_battlepass(creator, org_id, name, cid, collection_id, price, new_season)?; Self::deposit_event(Event::BattlepassCreated { org_id, battlepass_id, season: new_season }); @@ -435,15 +420,17 @@ pub mod pallet { // check if Battlepass in ACTIVE state ensure!(Self::check_battlepass_state(battlepass_id, BattlepassState::ACTIVE)?, Error::::BattlepassStateWrong); // check if Org is active - ensure!(T::Control::is_org_active(&battlepass.org_id), Error::::OrgUnknownOrInactive); + let org_id = battlepass.org_id.clone(); + ensure!(T::Control::is_org_active(&org_id), Error::::OrgUnknownOrInactive); // check permissions (prime, bot) - ensure!(Self::is_prime_or_bot(&battlepass.org_id, by_who.clone())?, Error::::AuthorizationError); - // check if Battlepass already claimed - ensure!(!ClaimedBattlepasses::::contains_key(battlepass_id, for_who.clone()), Error::::BattlepassClaimed); + ensure!(Self::is_prime_or_bot(&org_id, by_who.clone())?, Error::::AuthorizationError); + // check if user has access to Battlepass + ensure!(!Self::has_battlepass_ownership(for_who.clone(), battlepass.collection_id), Error::::BattlepassOwnershipExists); + let nft_id = Self::do_claim_battlepass(battlepass.creator.clone(), for_who.clone(), battlepass_id, battlepass.collection_id)?; - Self::deposit_event(Event::BattlepassClaimed { by_who, for_who, org_id: battlepass.org_id, battlepass_id, nft_id }); + Self::deposit_event(Event::BattlepassClaimed { by_who, for_who, org_id, battlepass_id, nft_id }); Ok(()) } @@ -537,7 +524,7 @@ pub mod pallet { // check permissions (prime, bot) ensure!(Self::is_prime_or_bot(&battlepass.org_id, sender.clone())?, Error::::AuthorizationError); // check if user has access to Battlepass - Self::validate_battlepass_ownership(account.clone(), battlepass_id, battlepass)?; + ensure!(Self::has_battlepass_ownership(account.clone(), battlepass.collection_id), Error::::BattlepassOwnershipDoesntExist); Points::::insert(battlepass_id, &account, amount); @@ -580,7 +567,7 @@ pub mod pallet { ensure!(Self::is_prime_or_bot(&battlepass.org_id, caller)?, Error::::AuthorizationError); let prime = T::Control::org_prime_account(&battlepass.org_id).ok_or(Error::::OrgPrimeUnknown)?; - let collection_id = Self::create_collection(prime, max)?; + let collection_id = Self::create_collection(prime, max, cid.clone())?; let reward_id = Self::do_create_reward(battlepass_id, name, cid, level, transferable, collection_id)?; Self::deposit_event(Event::RewardCreated { reward_id, battlepass_id, level }); @@ -703,7 +690,7 @@ pub mod pallet { // check permissions (self, prime or bot) ensure!(by_who == for_who || Self::is_prime_or_bot(&battlepass.org_id, by_who.clone())?, Error::::AuthorizationError); // check if user has access to Battlepass - Self::validate_battlepass_ownership(for_who.clone(), reward.battlepass_id, battlepass)?; + ensure!(Self::has_battlepass_ownership(for_who.clone(), battlepass.collection_id), Error::::BattlepassOwnershipDoesntExist); // check if user has reached the required Level ensure!(Self::is_level_reached(&reward.battlepass_id, &for_who, reward.level), Error::::LevelNotReached); @@ -871,8 +858,8 @@ impl Pallet { }) } - fn create_collection(owner: T::AccountId, max: Option) -> Result { - let metadata = BoundedVec::truncate_from(b"meta".to_vec()); // TODO: what should be here? + fn create_collection(owner: T::AccountId, max: Option, cid: String) -> Result { + let metadata = BoundedVec::truncate_from(cid.into()); let collection_index = Self::bump_collection_index()?; let collection_id = T::BattlepassHelper::collection(collection_index); let origin = OriginFor::::from(RawOrigin::Signed(owner.clone())); @@ -966,8 +953,6 @@ impl Pallet { // Create Battlepass NFT Self::create_nft(creator, for_who.clone(), collection_id, nft_id, metadata)?; - - ClaimedBattlepasses::::insert(battlepass_id, &for_who, nft_id); Ok(nft_id) } @@ -1018,17 +1003,8 @@ impl Pallet { Ok(nft_id) } - fn validate_battlepass_ownership(account: T::AccountId, battlepass_id: T::Hash, battlepass: Battlepass, T::CollectionId>) -> DispatchResult { - // check if user claimed Battlepass NFT - let bp_nft_id = Self::get_claimed_battlepass(battlepass_id, &account).ok_or(Error::::BattlepassNotClaimed)?; - // check if Battlepass NFT exists - let bp_nft_owner = pallet_uniques::Pallet::::owner(battlepass.collection_id, bp_nft_id).ok_or(Error::::BattlepassNftUnknown)?; - // validate Battlepass NFT ownership - ensure!(account.clone() == bp_nft_owner, Error::::NotOwnNft); - // validate Battlepass NFT metadata - let bp_nft_metadata = as Inspect>::attribute(&battlepass.collection_id, &bp_nft_id, &[]); - ensure!(Some(battlepass_id.encode()) == bp_nft_metadata, Error::::BattlepassNftInvalid); - - Ok(()) + fn has_battlepass_ownership(account: T::AccountId, bp_collection_id: T::CollectionId) -> bool { + let bp_owned_count = as InspectEnumerable>::owned_in_collection(&bp_collection_id, &account).count(); + bp_owned_count > 0 } } diff --git a/battlepass/src/tests.rs b/battlepass/src/tests.rs index 298a877d4..59297b7f4 100644 --- a/battlepass/src/tests.rs +++ b/battlepass/src/tests.rs @@ -1,7 +1,7 @@ #![cfg(test)] use frame_support::{assert_noop, assert_ok}; -use frame_support::traits::tokens::nonfungibles::{InspectEnumerable, Mutate, Transfer}; +use frame_support::traits::tokens::nonfungibles::{Inspect, InspectEnumerable, Mutate, Transfer}; use sp_core::H256; use crate::mock::{ @@ -455,6 +455,7 @@ fn claim_battlepass_test() { let not_creator_2 = TOM; let not_creator_3 = 22u32; let not_member = EVA; + let not_member_2 = 40; add_member(org_id, not_creator); add_member(org_id, not_creator_2); add_member(org_id, not_creator_3); @@ -511,17 +512,32 @@ fn claim_battlepass_test() { assert_ok!( Battlepass::claim_battlepass(Origin::signed(creator), battlepass_id, not_creator) ); - // Check if ClaimedBattlepasses record created - let nft_id = ClaimedBattlepasses::::get(battlepass_id, not_creator); - assert_eq!(nft_id.is_some(), true); - assert_eq!(nft_id.unwrap(), 0); // Check if NFT minted assert_eq!(>::items(&0).any(|x| x == 0) , true); // Should not claim if it was already claimed assert_noop!( Battlepass::claim_battlepass(Origin::signed(creator), battlepass_id, not_creator), - Error::::BattlepassClaimed + Error::::BattlepassOwnershipExists + ); + + // Should claim again after transferring Battlepass NFT to someone else + assert_ok!( + Uniques::thaw_collection(Origin::signed(creator), 0) + ); + assert_ok!( + >::transfer(&0, &0, ¬_member_2) + ); + assert_ok!( + Battlepass::claim_battlepass(Origin::signed(creator), battlepass_id, not_creator) + ); + // Check if NFT minted + assert_eq!(>::items(&0).any(|x| x == 1) , true); + + // Should not claim if user received Battlepass NFT from someone else + assert_noop!( + Battlepass::claim_battlepass(Origin::signed(creator), battlepass_id, not_member_2), + Error::::BattlepassOwnershipExists ); // Should claim for others by Bot @@ -531,12 +547,8 @@ fn claim_battlepass_test() { assert_ok!( Battlepass::claim_battlepass(Origin::signed(BOT), battlepass_id, not_creator_3) ); - // Check if ClaimedBattlepasses record created - let nft_id = ClaimedBattlepasses::::get(battlepass_id, not_creator_3); - assert_eq!(nft_id.is_some(), true); - assert_eq!(nft_id.unwrap(), 1); // Check if NFT minted - assert_eq!(>::items(&0).any(|x| x == 1) , true); + assert_eq!(>::items(&0).any(|x| x == 2) , true); // Should claim for accounts outside of org assert_ok!( @@ -615,7 +627,7 @@ fn set_points_test() { // Should not set if user does not have access to Battlepass assert_noop!( Battlepass::set_points(Origin::signed(creator), battlepass_id, not_member, 10), - Error::::BattlepassNotClaimed + Error::::BattlepassOwnershipDoesntExist ); // Should set points by Prime @@ -982,6 +994,7 @@ fn claim_reward_test() { let not_creator_3 = 30; let not_creator_4 = 31; let not_member = EVA; + let not_member_2 = 40; add_member(org_id, not_creator); add_member(org_id, not_creator_2); add_member(org_id, not_creator_3); @@ -1056,7 +1069,7 @@ fn claim_reward_test() { // Should not claim Reward if user didn't claim Battlepass assert_noop!( Battlepass::claim_reward(Origin::signed(not_creator), reward_id, not_creator), - Error::::BattlepassNotClaimed + Error::::BattlepassOwnershipDoesntExist ); // Should not claim Reward if no NFT for claimed Battlepass @@ -1068,7 +1081,7 @@ fn claim_reward_test() { ); assert_noop!( Battlepass::claim_reward(Origin::signed(not_creator), reward_id, not_creator), - Error::::BattlepassNftUnknown + Error::::BattlepassOwnershipDoesntExist ); // Should not claim Reward if user lost ownership of Battlepass NFT @@ -1079,24 +1092,11 @@ fn claim_reward_test() { Uniques::thaw_collection(Origin::signed(creator), 0) ); assert_ok!( - >::transfer(&0, &1, ¬_member) + >::transfer(&0, &1, ¬_member_2) ); assert_noop!( Battlepass::claim_reward(Origin::signed(creator), reward_id, creator), - Error::::NotOwnNft - ); - - // Should not claim Reward if Battlepass NFT is not valid - assert_ok!( - Battlepass::claim_battlepass(Origin::signed(creator), battlepass_id, not_creator_2) - ); - let new_metadata = BoundedVec::truncate_from(b"crap".to_vec()); - assert_ok!( - Uniques::set_metadata(Origin::signed(creator), 0, 2, new_metadata, false) - ); - assert_noop!( - Battlepass::claim_reward(Origin::signed(not_creator_2), reward_id, not_creator_2), - Error::::BattlepassNftInvalid + Error::::BattlepassOwnershipDoesntExist ); // Should not claim if user's level is too low @@ -1127,9 +1127,6 @@ fn claim_reward_test() { Error::::RewardClaimed ); - // Should claim Reward after receiving Battlepass NFT from elsewhere - // TODO: need to 'apply' the received Battlepass NFT so it will appear in ClaimedBattlepasses - // Should not claim if max limit reached assert_ok!( Battlepass::claim_battlepass(Origin::signed(creator), battlepass_id, not_creator_4) @@ -1167,6 +1164,17 @@ fn claim_reward_test() { // Check if Reward claimed assert_eq!(ClaimedRewards::::contains_key(reward_id, not_member), true); + // Should claim Reward after receiving Battlepass NFT from elsewhere + let reward_id = create_reward(battlepass_id); + assert_ok!( + Battlepass::set_points(Origin::signed(creator), battlepass_id, not_member_2, 10) + ); + assert_ok!( + Battlepass::claim_reward(Origin::signed(not_member_2), reward_id, not_member_2) + ); + // Check if Reward claimed + assert_eq!(ClaimedRewards::::contains_key(reward_id, not_member_2), true); + // Should not claim if Battlepass state is ENDED assert_ok!( Battlepass::conclude_battlepass(Origin::signed(creator), battlepass_id) diff --git a/battlepass/src/weights.rs b/battlepass/src/weights.rs index 865bd335c..2504abe43 100644 --- a/battlepass/src/weights.rs +++ b/battlepass/src/weights.rs @@ -2,7 +2,8 @@ //! Autogenerated weights for gamedao_battlepass //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-02-28, STEPS: `20`, REPEAT: 10, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2023-03-06, STEPS: `20`, REPEAT: `10`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! WORST CASE MAP SIZE: `1000000` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: None, DB CACHE: 1024 // Executed Command: @@ -44,366 +45,630 @@ pub trait WeightInfo { /// Weights for gamedao_battlepass using the Substrate node and recommended hardware. pub struct SubstrateWeight(PhantomData); impl WeightInfo for SubstrateWeight { - // Storage: Control OrgStates (r:1 w:0) - // Storage: Control Orgs (r:1 w:0) - // Storage: Battlepass BattlepassInfoByOrg (r:1 w:1) - // Storage: Battlepass CollectionIndex (r:1 w:1) - // Storage: Uniques Class (r:1 w:1) - // Storage: Uniques ClassMetadataOf (r:1 w:1) - // Storage: Uniques ClassAccount (r:0 w:1) - // Storage: Battlepass BattlepassStates (r:0 w:1) - // Storage: Battlepass Battlepasses (r:0 w:1) + /// Storage: Control OrgStates (r:1 w:0) + /// Proof: Control OrgStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Control Orgs (r:1 w:0) + /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) + /// Storage: Battlepass BattlepassInfoByOrg (r:1 w:1) + /// Proof: Battlepass BattlepassInfoByOrg (max_values: None, max_size: Some(118), added: 2593, mode: MaxEncodedLen) + /// Storage: Battlepass CollectionIndex (r:1 w:1) + /// Proof: Battlepass CollectionIndex (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: Uniques ClassMetadataOf (r:1 w:1) + /// Proof: Uniques ClassMetadataOf (max_values: None, max_size: Some(167), added: 2642, mode: MaxEncodedLen) + /// Storage: Uniques ClassAccount (r:0 w:1) + /// Proof: Uniques ClassAccount (max_values: None, max_size: Some(68), added: 2543, mode: MaxEncodedLen) + /// Storage: Battlepass BattlepassStates (r:0 w:1) + /// Proof: Battlepass BattlepassStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Battlepass Battlepasses (r:0 w:1) + /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(382), added: 2857, mode: MaxEncodedLen) fn create_battlepass() -> Weight { - // Minimum execution time: 93_000 nanoseconds. - Weight::from_ref_time(95_000_000) - .saturating_add(T::DbWeight::get().reads(6)) - .saturating_add(T::DbWeight::get().writes(7)) + // Proof Size summary in bytes: + // Measured: `597` + // Estimated: `13676` + // Minimum execution time: 86_000 nanoseconds. + Weight::from_parts(86_000_000, 13676) + .saturating_add(T::DbWeight::get().reads(6_u64)) + .saturating_add(T::DbWeight::get().writes(7_u64)) } - // Storage: Battlepass Battlepasses (r:1 w:1) - // Storage: Battlepass BattlepassStates (r:1 w:0) - // Storage: Control OrgStates (r:1 w:0) - // Storage: Control Orgs (r:1 w:0) + /// Storage: Battlepass Battlepasses (r:1 w:1) + /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(382), added: 2857, mode: MaxEncodedLen) + /// Storage: Battlepass BattlepassStates (r:1 w:0) + /// Proof: Battlepass BattlepassStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Control OrgStates (r:1 w:0) + /// Proof: Control OrgStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Control Orgs (r:1 w:0) + /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) fn update_battlepass() -> Weight { - // Minimum execution time: 35_000 nanoseconds. - Weight::from_ref_time(36_000_000) - .saturating_add(T::DbWeight::get().reads(4)) - .saturating_add(T::DbWeight::get().writes(1)) + // Proof Size summary in bytes: + // Measured: `837` + // Estimated: `10670` + // Minimum execution time: 29_000 nanoseconds. + Weight::from_parts(30_000_000, 10670) + .saturating_add(T::DbWeight::get().reads(4_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) } - // Storage: Battlepass Battlepasses (r:1 w:0) - // Storage: Battlepass BattlepassStates (r:1 w:0) - // Storage: Control OrgStates (r:1 w:0) - // Storage: Control Orgs (r:1 w:0) - // Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) - // Storage: Battlepass ClaimedBattlepasses (r:1 w:1) - // Storage: Battlepass NftIndex (r:1 w:1) - // Storage: Uniques Asset (r:1 w:1) - // Storage: Uniques Class (r:1 w:1) - // Storage: Uniques CollectionMaxSupply (r:1 w:0) - // Storage: Uniques InstanceMetadataOf (r:1 w:1) - // Storage: Uniques Account (r:0 w:1) + /// Storage: Battlepass Battlepasses (r:1 w:0) + /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(382), added: 2857, mode: MaxEncodedLen) + /// Storage: Battlepass BattlepassStates (r:1 w:0) + /// Proof: Battlepass BattlepassStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Control OrgStates (r:1 w:0) + /// Proof: Control OrgStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Control Orgs (r:1 w:0) + /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) + /// Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) + /// Proof: Battlepass BattlepassInfoByOrg (max_values: None, max_size: Some(118), added: 2593, mode: MaxEncodedLen) + /// Storage: Uniques Account (r:1 w:1) + /// Proof: Uniques Account (max_values: None, max_size: Some(88), added: 2563, mode: MaxEncodedLen) + /// Storage: Battlepass NftIndex (r:1 w:1) + /// Proof: Battlepass NftIndex (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) + /// Storage: Uniques Asset (r:1 w:1) + /// Proof: Uniques Asset (max_values: None, max_size: Some(122), added: 2597, mode: MaxEncodedLen) + /// Storage: Uniques Class (r:1 w:1) + /// Proof: Uniques Class (max_values: None, max_size: Some(178), added: 2653, 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(187), added: 2662, mode: MaxEncodedLen) fn claim_battlepass() -> Weight { - // Minimum execution time: 101_000 nanoseconds. - Weight::from_ref_time(105_000_000) - .saturating_add(T::DbWeight::get().reads(11)) - .saturating_add(T::DbWeight::get().writes(6)) + // Proof Size summary in bytes: + // Measured: `1359` + // Estimated: `26736` + // Minimum execution time: 95_000 nanoseconds. + Weight::from_parts(98_000_000, 26736) + .saturating_add(T::DbWeight::get().reads(11_u64)) + .saturating_add(T::DbWeight::get().writes(5_u64)) } - // Storage: Battlepass Battlepasses (r:1 w:0) - // Storage: Battlepass BattlepassStates (r:1 w:1) - // Storage: Control OrgStates (r:1 w:0) - // Storage: Control Orgs (r:1 w:0) - // Storage: Battlepass BattlepassInfoByOrg (r:1 w:1) + /// Storage: Battlepass Battlepasses (r:1 w:0) + /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(382), added: 2857, mode: MaxEncodedLen) + /// Storage: Battlepass BattlepassStates (r:1 w:1) + /// Proof: Battlepass BattlepassStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Control OrgStates (r:1 w:0) + /// Proof: Control OrgStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Control Orgs (r:1 w:0) + /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) + /// Storage: Battlepass BattlepassInfoByOrg (r:1 w:1) + /// Proof: Battlepass BattlepassInfoByOrg (max_values: None, max_size: Some(118), added: 2593, mode: MaxEncodedLen) fn activate_battlepass() -> Weight { - // Minimum execution time: 43_000 nanoseconds. - Weight::from_ref_time(44_000_000) - .saturating_add(T::DbWeight::get().reads(5)) - .saturating_add(T::DbWeight::get().writes(2)) + // Proof Size summary in bytes: + // Measured: `880` + // Estimated: `13263` + // Minimum execution time: 36_000 nanoseconds. + Weight::from_parts(37_000_000, 13263) + .saturating_add(T::DbWeight::get().reads(5_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) } - // Storage: Battlepass Battlepasses (r:1 w:0) - // Storage: Battlepass BattlepassStates (r:1 w:1) - // Storage: Control Orgs (r:1 w:0) - // Storage: Battlepass BattlepassInfoByOrg (r:1 w:1) + /// Storage: Battlepass Battlepasses (r:1 w:0) + /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(382), added: 2857, mode: MaxEncodedLen) + /// Storage: Battlepass BattlepassStates (r:1 w:1) + /// Proof: Battlepass BattlepassStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Control Orgs (r:1 w:0) + /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) + /// Storage: Battlepass BattlepassInfoByOrg (r:1 w:1) + /// Proof: Battlepass BattlepassInfoByOrg (max_values: None, max_size: Some(118), added: 2593, mode: MaxEncodedLen) fn conclude_battlepass() -> Weight { - // Minimum execution time: 38_000 nanoseconds. - Weight::from_ref_time(40_000_000) - .saturating_add(T::DbWeight::get().reads(4)) - .saturating_add(T::DbWeight::get().writes(2)) + // Proof Size summary in bytes: + // Measured: `907` + // Estimated: `10739` + // Minimum execution time: 33_000 nanoseconds. + Weight::from_parts(34_000_000, 10739) + .saturating_add(T::DbWeight::get().reads(4_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) } - // Storage: Battlepass Battlepasses (r:1 w:0) - // Storage: Battlepass BattlepassStates (r:1 w:0) - // Storage: Control OrgStates (r:1 w:0) - // Storage: Control Orgs (r:1 w:0) - // Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) - // Storage: Battlepass ClaimedBattlepasses (r:1 w:0) - // Storage: Uniques Asset (r:1 w:0) - // Storage: Uniques InstanceMetadataOf (r:1 w:0) - // Storage: Battlepass Points (r:0 w:1) + /// Storage: Battlepass Battlepasses (r:1 w:0) + /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(382), added: 2857, mode: MaxEncodedLen) + /// Storage: Battlepass BattlepassStates (r:1 w:0) + /// Proof: Battlepass BattlepassStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Control OrgStates (r:1 w:0) + /// Proof: Control OrgStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Control Orgs (r:1 w:0) + /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) + /// Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) + /// Proof: Battlepass BattlepassInfoByOrg (max_values: None, max_size: Some(118), added: 2593, mode: MaxEncodedLen) + /// Storage: Uniques Account (r:2 w:0) + /// Proof: Uniques Account (max_values: None, max_size: Some(88), added: 2563, mode: MaxEncodedLen) + /// Storage: Battlepass Points (r:0 w:1) + /// Proof: Battlepass Points (max_values: None, max_size: Some(100), added: 2575, mode: MaxEncodedLen) fn set_points() -> Weight { - // Minimum execution time: 51_000 nanoseconds. - Weight::from_ref_time(53_000_000) - .saturating_add(T::DbWeight::get().reads(8)) - .saturating_add(T::DbWeight::get().writes(1)) + // Proof Size summary in bytes: + // Measured: `1417` + // Estimated: `18389` + // Minimum execution time: 44_000 nanoseconds. + Weight::from_parts(44_000_000, 18389) + .saturating_add(T::DbWeight::get().reads(7_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) } - // Storage: Battlepass Battlepasses (r:1 w:0) - // Storage: Battlepass BattlepassStates (r:1 w:0) - // Storage: Control OrgStates (r:1 w:0) - // Storage: Control Orgs (r:1 w:0) - // Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) - // Storage: Battlepass CollectionIndex (r:1 w:1) - // Storage: Uniques Class (r:1 w:1) - // Storage: Uniques ClassMetadataOf (r:1 w:1) - // Storage: Uniques CollectionMaxSupply (r:1 w:1) - // Storage: Uniques ClassAccount (r:0 w:1) - // Storage: Battlepass Rewards (r:0 w:1) - // Storage: Battlepass RewardStates (r:0 w:1) + /// Storage: Battlepass Battlepasses (r:1 w:0) + /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(382), added: 2857, mode: MaxEncodedLen) + /// Storage: Battlepass BattlepassStates (r:1 w:0) + /// Proof: Battlepass BattlepassStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Control OrgStates (r:1 w:0) + /// Proof: Control OrgStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Control Orgs (r:1 w:0) + /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) + /// Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) + /// Proof: Battlepass BattlepassInfoByOrg (max_values: None, max_size: Some(118), added: 2593, mode: MaxEncodedLen) + /// Storage: Battlepass CollectionIndex (r:1 w:1) + /// Proof: Battlepass CollectionIndex (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: Uniques ClassMetadataOf (r:1 w:1) + /// Proof: Uniques ClassMetadataOf (max_values: None, max_size: Some(167), added: 2642, mode: MaxEncodedLen) + /// Storage: Uniques CollectionMaxSupply (r:1 w:1) + /// Proof: Uniques CollectionMaxSupply (max_values: None, max_size: Some(24), added: 2499, mode: MaxEncodedLen) + /// Storage: Uniques ClassAccount (r:0 w:1) + /// Proof: Uniques ClassAccount (max_values: None, max_size: Some(68), added: 2543, mode: MaxEncodedLen) + /// Storage: Battlepass Rewards (r:0 w:1) + /// Proof: Battlepass Rewards (max_values: None, max_size: Some(346), added: 2821, mode: MaxEncodedLen) + /// Storage: Battlepass RewardStates (r:0 w:1) + /// Proof: Battlepass RewardStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) fn create_reward() -> Weight { - // Minimum execution time: 116_000 nanoseconds. - Weight::from_ref_time(120_000_000) - .saturating_add(T::DbWeight::get().reads(9)) - .saturating_add(T::DbWeight::get().writes(7)) + // Proof Size summary in bytes: + // Measured: `1226` + // Estimated: `21556` + // Minimum execution time: 110_000 nanoseconds. + Weight::from_parts(112_000_000, 21556) + .saturating_add(T::DbWeight::get().reads(9_u64)) + .saturating_add(T::DbWeight::get().writes(7_u64)) } - // Storage: Battlepass Rewards (r:1 w:1) - // Storage: Battlepass RewardStates (r:1 w:0) - // Storage: Battlepass Battlepasses (r:1 w:0) - // Storage: Battlepass BattlepassStates (r:1 w:0) - // Storage: Control OrgStates (r:1 w:0) - // Storage: Control Orgs (r:1 w:0) - // Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) + /// Storage: Battlepass Rewards (r:1 w:1) + /// Proof: Battlepass Rewards (max_values: None, max_size: Some(346), added: 2821, mode: MaxEncodedLen) + /// Storage: Battlepass RewardStates (r:1 w:0) + /// Proof: Battlepass RewardStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Battlepass Battlepasses (r:1 w:0) + /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(382), added: 2857, mode: MaxEncodedLen) + /// Storage: Battlepass BattlepassStates (r:1 w:0) + /// Proof: Battlepass BattlepassStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Control OrgStates (r:1 w:0) + /// Proof: Control OrgStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Control Orgs (r:1 w:0) + /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) + /// Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) + /// Proof: Battlepass BattlepassInfoByOrg (max_values: None, max_size: Some(118), added: 2593, mode: MaxEncodedLen) fn update_reward() -> Weight { - // Minimum execution time: 46_000 nanoseconds. - Weight::from_ref_time(47_000_000) - .saturating_add(T::DbWeight::get().reads(7)) - .saturating_add(T::DbWeight::get().writes(1)) + // Proof Size summary in bytes: + // Measured: `1169` + // Estimated: `18608` + // Minimum execution time: 41_000 nanoseconds. + Weight::from_parts(41_000_000, 18608) + .saturating_add(T::DbWeight::get().reads(7_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) } - // Storage: Battlepass Rewards (r:1 w:0) - // Storage: Battlepass RewardStates (r:1 w:1) - // Storage: Battlepass Battlepasses (r:1 w:0) - // Storage: Control Orgs (r:1 w:0) - // Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) + /// Storage: Battlepass Rewards (r:1 w:0) + /// Proof: Battlepass Rewards (max_values: None, max_size: Some(346), added: 2821, mode: MaxEncodedLen) + /// Storage: Battlepass RewardStates (r:1 w:1) + /// Proof: Battlepass RewardStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Battlepass Battlepasses (r:1 w:0) + /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(382), added: 2857, mode: MaxEncodedLen) + /// Storage: Control Orgs (r:1 w:0) + /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) + /// Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) + /// Proof: Battlepass BattlepassInfoByOrg (max_values: None, max_size: Some(118), added: 2593, mode: MaxEncodedLen) fn disable_reward() -> Weight { - // Minimum execution time: 39_000 nanoseconds. - Weight::from_ref_time(41_000_000) - .saturating_add(T::DbWeight::get().reads(5)) - .saturating_add(T::DbWeight::get().writes(1)) + // Proof Size summary in bytes: + // Measured: `1094` + // Estimated: `13560` + // Minimum execution time: 33_000 nanoseconds. + Weight::from_parts(33_000_000, 13560) + .saturating_add(T::DbWeight::get().reads(5_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) } - // Storage: Battlepass Rewards (r:1 w:0) - // Storage: Battlepass RewardStates (r:1 w:0) - // Storage: Battlepass ClaimedRewards (r:1 w:1) - // Storage: Battlepass Battlepasses (r:1 w:0) - // Storage: Battlepass BattlepassStates (r:1 w:0) - // Storage: Control OrgStates (r:1 w:0) - // Storage: Control Orgs (r:1 w:0) - // Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) - // Storage: Battlepass ClaimedBattlepasses (r:1 w:0) - // Storage: Uniques Asset (r:2 w:1) - // Storage: Uniques InstanceMetadataOf (r:2 w:1) - // Storage: Battlepass Points (r:1 w:0) - // Storage: Battlepass Levels (r:2 w:0) - // Storage: Battlepass NftIndex (r:1 w:1) - // Storage: Uniques Class (r:1 w:1) - // Storage: Uniques CollectionMaxSupply (r:1 w:0) - // Storage: Uniques Account (r:0 w:1) + /// Storage: Battlepass Rewards (r:1 w:0) + /// Proof: Battlepass Rewards (max_values: None, max_size: Some(346), added: 2821, mode: MaxEncodedLen) + /// Storage: Battlepass RewardStates (r:1 w:0) + /// Proof: Battlepass RewardStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Battlepass ClaimedRewards (r:1 w:1) + /// Proof: Battlepass ClaimedRewards (max_values: None, max_size: Some(100), added: 2575, mode: MaxEncodedLen) + /// Storage: Battlepass Battlepasses (r:1 w:0) + /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(382), added: 2857, mode: MaxEncodedLen) + /// Storage: Battlepass BattlepassStates (r:1 w:0) + /// Proof: Battlepass BattlepassStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Control OrgStates (r:1 w:0) + /// Proof: Control OrgStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Control Orgs (r:1 w:0) + /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) + /// Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) + /// Proof: Battlepass BattlepassInfoByOrg (max_values: None, max_size: Some(118), added: 2593, mode: MaxEncodedLen) + /// Storage: Uniques Account (r:2 w:1) + /// Proof: Uniques Account (max_values: None, max_size: Some(88), added: 2563, mode: MaxEncodedLen) + /// Storage: Battlepass Points (r:1 w:0) + /// Proof: Battlepass Points (max_values: None, max_size: Some(100), added: 2575, mode: MaxEncodedLen) + /// Storage: Battlepass Levels (r:2 w:0) + /// Proof: Battlepass Levels (max_values: None, max_size: Some(69), added: 2544, mode: MaxEncodedLen) + /// Storage: Battlepass NftIndex (r:1 w:1) + /// Proof: Battlepass NftIndex (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) + /// Storage: Uniques Asset (r:1 w:1) + /// Proof: Uniques Asset (max_values: None, max_size: Some(122), added: 2597, mode: MaxEncodedLen) + /// Storage: Uniques Class (r:1 w:1) + /// Proof: Uniques Class (max_values: None, max_size: Some(178), added: 2653, 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(187), added: 2662, mode: MaxEncodedLen) fn claim_reward() -> Weight { - // Minimum execution time: 137_000 nanoseconds. - Weight::from_ref_time(141_000_000) - .saturating_add(T::DbWeight::get().reads(19)) - .saturating_add(T::DbWeight::get().writes(6)) + // Proof Size summary in bytes: + // Measured: `2203` + // Estimated: `44882` + // Minimum execution time: 133_000 nanoseconds. + Weight::from_parts(135_000_000, 44882) + .saturating_add(T::DbWeight::get().reads(18_u64)) + .saturating_add(T::DbWeight::get().writes(6_u64)) } - // Storage: Battlepass Battlepasses (r:1 w:0) - // Storage: Battlepass BattlepassStates (r:1 w:0) - // Storage: Control OrgStates (r:1 w:0) - // Storage: Control Orgs (r:1 w:0) - // Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) - // Storage: Battlepass Levels (r:0 w:1) + /// Storage: Battlepass Battlepasses (r:1 w:0) + /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(382), added: 2857, mode: MaxEncodedLen) + /// Storage: Battlepass BattlepassStates (r:1 w:0) + /// Proof: Battlepass BattlepassStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Control OrgStates (r:1 w:0) + /// Proof: Control OrgStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Control Orgs (r:1 w:0) + /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) + /// Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) + /// Proof: Battlepass BattlepassInfoByOrg (max_values: None, max_size: Some(118), added: 2593, mode: MaxEncodedLen) + /// Storage: Battlepass Levels (r:0 w:1) + /// Proof: Battlepass Levels (max_values: None, max_size: Some(69), added: 2544, mode: MaxEncodedLen) fn add_level() -> Weight { - // Minimum execution time: 39_000 nanoseconds. - Weight::from_ref_time(41_000_000) - .saturating_add(T::DbWeight::get().reads(5)) - .saturating_add(T::DbWeight::get().writes(1)) + // Proof Size summary in bytes: + // Measured: `945` + // Estimated: `13263` + // Minimum execution time: 31_000 nanoseconds. + Weight::from_parts(32_000_000, 13263) + .saturating_add(T::DbWeight::get().reads(5_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) } - // Storage: Battlepass Battlepasses (r:1 w:0) - // Storage: Battlepass BattlepassStates (r:1 w:0) - // Storage: Control OrgStates (r:1 w:0) - // Storage: Control Orgs (r:1 w:0) - // Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) - // Storage: Battlepass Levels (r:1 w:1) + /// Storage: Battlepass Battlepasses (r:1 w:0) + /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(382), added: 2857, mode: MaxEncodedLen) + /// Storage: Battlepass BattlepassStates (r:1 w:0) + /// Proof: Battlepass BattlepassStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Control OrgStates (r:1 w:0) + /// Proof: Control OrgStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Control Orgs (r:1 w:0) + /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) + /// Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) + /// Proof: Battlepass BattlepassInfoByOrg (max_values: None, max_size: Some(118), added: 2593, mode: MaxEncodedLen) + /// Storage: Battlepass Levels (r:1 w:1) + /// Proof: Battlepass Levels (max_values: None, max_size: Some(69), added: 2544, mode: MaxEncodedLen) fn remove_level() -> Weight { - // Minimum execution time: 40_000 nanoseconds. - Weight::from_ref_time(42_000_000) - .saturating_add(T::DbWeight::get().reads(6)) - .saturating_add(T::DbWeight::get().writes(1)) + // Proof Size summary in bytes: + // Measured: `1038` + // Estimated: `15807` + // Minimum execution time: 36_000 nanoseconds. + Weight::from_parts(37_000_000, 15807) + .saturating_add(T::DbWeight::get().reads(6_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) } - // Storage: Battlepass Battlepasses (r:1 w:0) - // Storage: Battlepass BattlepassStates (r:1 w:0) - // Storage: Control OrgStates (r:1 w:0) - // Storage: Control Orgs (r:1 w:0) - // Storage: Battlepass BattlepassInfoByOrg (r:1 w:1) + /// Storage: Battlepass Battlepasses (r:1 w:0) + /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(382), added: 2857, mode: MaxEncodedLen) + /// Storage: Battlepass BattlepassStates (r:1 w:0) + /// Proof: Battlepass BattlepassStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Control OrgStates (r:1 w:0) + /// Proof: Control OrgStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Control Orgs (r:1 w:0) + /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) + /// Storage: Battlepass BattlepassInfoByOrg (r:1 w:1) + /// Proof: Battlepass BattlepassInfoByOrg (max_values: None, max_size: Some(118), added: 2593, mode: MaxEncodedLen) fn add_bot() -> Weight { - // Minimum execution time: 35_000 nanoseconds. - Weight::from_ref_time(35_000_000) - .saturating_add(T::DbWeight::get().reads(5)) - .saturating_add(T::DbWeight::get().writes(1)) + // Proof Size summary in bytes: + // Measured: `880` + // Estimated: `13263` + // Minimum execution time: 30_000 nanoseconds. + Weight::from_parts(31_000_000, 13263) + .saturating_add(T::DbWeight::get().reads(5_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) } } // For backwards compatibility and tests impl WeightInfo for () { - // Storage: Control OrgStates (r:1 w:0) - // Storage: Control Orgs (r:1 w:0) - // Storage: Battlepass BattlepassInfoByOrg (r:1 w:1) - // Storage: Battlepass CollectionIndex (r:1 w:1) - // Storage: Uniques Class (r:1 w:1) - // Storage: Uniques ClassMetadataOf (r:1 w:1) - // Storage: Uniques ClassAccount (r:0 w:1) - // Storage: Battlepass BattlepassStates (r:0 w:1) - // Storage: Battlepass Battlepasses (r:0 w:1) + /// Storage: Control OrgStates (r:1 w:0) + /// Proof: Control OrgStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Control Orgs (r:1 w:0) + /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) + /// Storage: Battlepass BattlepassInfoByOrg (r:1 w:1) + /// Proof: Battlepass BattlepassInfoByOrg (max_values: None, max_size: Some(118), added: 2593, mode: MaxEncodedLen) + /// Storage: Battlepass CollectionIndex (r:1 w:1) + /// Proof: Battlepass CollectionIndex (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: Uniques ClassMetadataOf (r:1 w:1) + /// Proof: Uniques ClassMetadataOf (max_values: None, max_size: Some(167), added: 2642, mode: MaxEncodedLen) + /// Storage: Uniques ClassAccount (r:0 w:1) + /// Proof: Uniques ClassAccount (max_values: None, max_size: Some(68), added: 2543, mode: MaxEncodedLen) + /// Storage: Battlepass BattlepassStates (r:0 w:1) + /// Proof: Battlepass BattlepassStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Battlepass Battlepasses (r:0 w:1) + /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(382), added: 2857, mode: MaxEncodedLen) fn create_battlepass() -> Weight { - // Minimum execution time: 93_000 nanoseconds. - Weight::from_ref_time(95_000_000) - .saturating_add(RocksDbWeight::get().reads(6)) - .saturating_add(RocksDbWeight::get().writes(7)) + // Proof Size summary in bytes: + // Measured: `597` + // Estimated: `13676` + // Minimum execution time: 86_000 nanoseconds. + Weight::from_parts(86_000_000, 13676) + .saturating_add(RocksDbWeight::get().reads(6_u64)) + .saturating_add(RocksDbWeight::get().writes(7_u64)) } - // Storage: Battlepass Battlepasses (r:1 w:1) - // Storage: Battlepass BattlepassStates (r:1 w:0) - // Storage: Control OrgStates (r:1 w:0) - // Storage: Control Orgs (r:1 w:0) + /// Storage: Battlepass Battlepasses (r:1 w:1) + /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(382), added: 2857, mode: MaxEncodedLen) + /// Storage: Battlepass BattlepassStates (r:1 w:0) + /// Proof: Battlepass BattlepassStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Control OrgStates (r:1 w:0) + /// Proof: Control OrgStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Control Orgs (r:1 w:0) + /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) fn update_battlepass() -> Weight { - // Minimum execution time: 35_000 nanoseconds. - Weight::from_ref_time(36_000_000) - .saturating_add(RocksDbWeight::get().reads(4)) - .saturating_add(RocksDbWeight::get().writes(1)) + // Proof Size summary in bytes: + // Measured: `837` + // Estimated: `10670` + // Minimum execution time: 29_000 nanoseconds. + Weight::from_parts(30_000_000, 10670) + .saturating_add(RocksDbWeight::get().reads(4_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) } - // Storage: Battlepass Battlepasses (r:1 w:0) - // Storage: Battlepass BattlepassStates (r:1 w:0) - // Storage: Control OrgStates (r:1 w:0) - // Storage: Control Orgs (r:1 w:0) - // Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) - // Storage: Battlepass ClaimedBattlepasses (r:1 w:1) - // Storage: Battlepass NftIndex (r:1 w:1) - // Storage: Uniques Asset (r:1 w:1) - // Storage: Uniques Class (r:1 w:1) - // Storage: Uniques CollectionMaxSupply (r:1 w:0) - // Storage: Uniques InstanceMetadataOf (r:1 w:1) - // Storage: Uniques Account (r:0 w:1) + /// Storage: Battlepass Battlepasses (r:1 w:0) + /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(382), added: 2857, mode: MaxEncodedLen) + /// Storage: Battlepass BattlepassStates (r:1 w:0) + /// Proof: Battlepass BattlepassStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Control OrgStates (r:1 w:0) + /// Proof: Control OrgStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Control Orgs (r:1 w:0) + /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) + /// Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) + /// Proof: Battlepass BattlepassInfoByOrg (max_values: None, max_size: Some(118), added: 2593, mode: MaxEncodedLen) + /// Storage: Uniques Account (r:1 w:1) + /// Proof: Uniques Account (max_values: None, max_size: Some(88), added: 2563, mode: MaxEncodedLen) + /// Storage: Battlepass NftIndex (r:1 w:1) + /// Proof: Battlepass NftIndex (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) + /// Storage: Uniques Asset (r:1 w:1) + /// Proof: Uniques Asset (max_values: None, max_size: Some(122), added: 2597, mode: MaxEncodedLen) + /// Storage: Uniques Class (r:1 w:1) + /// Proof: Uniques Class (max_values: None, max_size: Some(178), added: 2653, 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(187), added: 2662, mode: MaxEncodedLen) fn claim_battlepass() -> Weight { - // Minimum execution time: 101_000 nanoseconds. - Weight::from_ref_time(105_000_000) - .saturating_add(RocksDbWeight::get().reads(11)) - .saturating_add(RocksDbWeight::get().writes(6)) + // Proof Size summary in bytes: + // Measured: `1359` + // Estimated: `26736` + // Minimum execution time: 95_000 nanoseconds. + Weight::from_parts(98_000_000, 26736) + .saturating_add(RocksDbWeight::get().reads(11_u64)) + .saturating_add(RocksDbWeight::get().writes(5_u64)) } - // Storage: Battlepass Battlepasses (r:1 w:0) - // Storage: Battlepass BattlepassStates (r:1 w:1) - // Storage: Control OrgStates (r:1 w:0) - // Storage: Control Orgs (r:1 w:0) - // Storage: Battlepass BattlepassInfoByOrg (r:1 w:1) + /// Storage: Battlepass Battlepasses (r:1 w:0) + /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(382), added: 2857, mode: MaxEncodedLen) + /// Storage: Battlepass BattlepassStates (r:1 w:1) + /// Proof: Battlepass BattlepassStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Control OrgStates (r:1 w:0) + /// Proof: Control OrgStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Control Orgs (r:1 w:0) + /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) + /// Storage: Battlepass BattlepassInfoByOrg (r:1 w:1) + /// Proof: Battlepass BattlepassInfoByOrg (max_values: None, max_size: Some(118), added: 2593, mode: MaxEncodedLen) fn activate_battlepass() -> Weight { - // Minimum execution time: 43_000 nanoseconds. - Weight::from_ref_time(44_000_000) - .saturating_add(RocksDbWeight::get().reads(5)) - .saturating_add(RocksDbWeight::get().writes(2)) + // Proof Size summary in bytes: + // Measured: `880` + // Estimated: `13263` + // Minimum execution time: 36_000 nanoseconds. + Weight::from_parts(37_000_000, 13263) + .saturating_add(RocksDbWeight::get().reads(5_u64)) + .saturating_add(RocksDbWeight::get().writes(2_u64)) } - // Storage: Battlepass Battlepasses (r:1 w:0) - // Storage: Battlepass BattlepassStates (r:1 w:1) - // Storage: Control Orgs (r:1 w:0) - // Storage: Battlepass BattlepassInfoByOrg (r:1 w:1) + /// Storage: Battlepass Battlepasses (r:1 w:0) + /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(382), added: 2857, mode: MaxEncodedLen) + /// Storage: Battlepass BattlepassStates (r:1 w:1) + /// Proof: Battlepass BattlepassStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Control Orgs (r:1 w:0) + /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) + /// Storage: Battlepass BattlepassInfoByOrg (r:1 w:1) + /// Proof: Battlepass BattlepassInfoByOrg (max_values: None, max_size: Some(118), added: 2593, mode: MaxEncodedLen) fn conclude_battlepass() -> Weight { - // Minimum execution time: 38_000 nanoseconds. - Weight::from_ref_time(40_000_000) - .saturating_add(RocksDbWeight::get().reads(4)) - .saturating_add(RocksDbWeight::get().writes(2)) + // Proof Size summary in bytes: + // Measured: `907` + // Estimated: `10739` + // Minimum execution time: 33_000 nanoseconds. + Weight::from_parts(34_000_000, 10739) + .saturating_add(RocksDbWeight::get().reads(4_u64)) + .saturating_add(RocksDbWeight::get().writes(2_u64)) } - // Storage: Battlepass Battlepasses (r:1 w:0) - // Storage: Battlepass BattlepassStates (r:1 w:0) - // Storage: Control OrgStates (r:1 w:0) - // Storage: Control Orgs (r:1 w:0) - // Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) - // Storage: Battlepass ClaimedBattlepasses (r:1 w:0) - // Storage: Uniques Asset (r:1 w:0) - // Storage: Uniques InstanceMetadataOf (r:1 w:0) - // Storage: Battlepass Points (r:0 w:1) + /// Storage: Battlepass Battlepasses (r:1 w:0) + /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(382), added: 2857, mode: MaxEncodedLen) + /// Storage: Battlepass BattlepassStates (r:1 w:0) + /// Proof: Battlepass BattlepassStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Control OrgStates (r:1 w:0) + /// Proof: Control OrgStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Control Orgs (r:1 w:0) + /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) + /// Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) + /// Proof: Battlepass BattlepassInfoByOrg (max_values: None, max_size: Some(118), added: 2593, mode: MaxEncodedLen) + /// Storage: Uniques Account (r:2 w:0) + /// Proof: Uniques Account (max_values: None, max_size: Some(88), added: 2563, mode: MaxEncodedLen) + /// Storage: Battlepass Points (r:0 w:1) + /// Proof: Battlepass Points (max_values: None, max_size: Some(100), added: 2575, mode: MaxEncodedLen) fn set_points() -> Weight { - // Minimum execution time: 51_000 nanoseconds. - Weight::from_ref_time(53_000_000) - .saturating_add(RocksDbWeight::get().reads(8)) - .saturating_add(RocksDbWeight::get().writes(1)) + // Proof Size summary in bytes: + // Measured: `1417` + // Estimated: `18389` + // Minimum execution time: 44_000 nanoseconds. + Weight::from_parts(44_000_000, 18389) + .saturating_add(RocksDbWeight::get().reads(7_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) } - // Storage: Battlepass Battlepasses (r:1 w:0) - // Storage: Battlepass BattlepassStates (r:1 w:0) - // Storage: Control OrgStates (r:1 w:0) - // Storage: Control Orgs (r:1 w:0) - // Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) - // Storage: Battlepass CollectionIndex (r:1 w:1) - // Storage: Uniques Class (r:1 w:1) - // Storage: Uniques ClassMetadataOf (r:1 w:1) - // Storage: Uniques CollectionMaxSupply (r:1 w:1) - // Storage: Uniques ClassAccount (r:0 w:1) - // Storage: Battlepass Rewards (r:0 w:1) - // Storage: Battlepass RewardStates (r:0 w:1) + /// Storage: Battlepass Battlepasses (r:1 w:0) + /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(382), added: 2857, mode: MaxEncodedLen) + /// Storage: Battlepass BattlepassStates (r:1 w:0) + /// Proof: Battlepass BattlepassStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Control OrgStates (r:1 w:0) + /// Proof: Control OrgStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Control Orgs (r:1 w:0) + /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) + /// Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) + /// Proof: Battlepass BattlepassInfoByOrg (max_values: None, max_size: Some(118), added: 2593, mode: MaxEncodedLen) + /// Storage: Battlepass CollectionIndex (r:1 w:1) + /// Proof: Battlepass CollectionIndex (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: Uniques ClassMetadataOf (r:1 w:1) + /// Proof: Uniques ClassMetadataOf (max_values: None, max_size: Some(167), added: 2642, mode: MaxEncodedLen) + /// Storage: Uniques CollectionMaxSupply (r:1 w:1) + /// Proof: Uniques CollectionMaxSupply (max_values: None, max_size: Some(24), added: 2499, mode: MaxEncodedLen) + /// Storage: Uniques ClassAccount (r:0 w:1) + /// Proof: Uniques ClassAccount (max_values: None, max_size: Some(68), added: 2543, mode: MaxEncodedLen) + /// Storage: Battlepass Rewards (r:0 w:1) + /// Proof: Battlepass Rewards (max_values: None, max_size: Some(346), added: 2821, mode: MaxEncodedLen) + /// Storage: Battlepass RewardStates (r:0 w:1) + /// Proof: Battlepass RewardStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) fn create_reward() -> Weight { - // Minimum execution time: 116_000 nanoseconds. - Weight::from_ref_time(120_000_000) - .saturating_add(RocksDbWeight::get().reads(9)) - .saturating_add(RocksDbWeight::get().writes(7)) + // Proof Size summary in bytes: + // Measured: `1226` + // Estimated: `21556` + // Minimum execution time: 110_000 nanoseconds. + Weight::from_parts(112_000_000, 21556) + .saturating_add(RocksDbWeight::get().reads(9_u64)) + .saturating_add(RocksDbWeight::get().writes(7_u64)) } - // Storage: Battlepass Rewards (r:1 w:1) - // Storage: Battlepass RewardStates (r:1 w:0) - // Storage: Battlepass Battlepasses (r:1 w:0) - // Storage: Battlepass BattlepassStates (r:1 w:0) - // Storage: Control OrgStates (r:1 w:0) - // Storage: Control Orgs (r:1 w:0) - // Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) + /// Storage: Battlepass Rewards (r:1 w:1) + /// Proof: Battlepass Rewards (max_values: None, max_size: Some(346), added: 2821, mode: MaxEncodedLen) + /// Storage: Battlepass RewardStates (r:1 w:0) + /// Proof: Battlepass RewardStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Battlepass Battlepasses (r:1 w:0) + /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(382), added: 2857, mode: MaxEncodedLen) + /// Storage: Battlepass BattlepassStates (r:1 w:0) + /// Proof: Battlepass BattlepassStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Control OrgStates (r:1 w:0) + /// Proof: Control OrgStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Control Orgs (r:1 w:0) + /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) + /// Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) + /// Proof: Battlepass BattlepassInfoByOrg (max_values: None, max_size: Some(118), added: 2593, mode: MaxEncodedLen) fn update_reward() -> Weight { - // Minimum execution time: 46_000 nanoseconds. - Weight::from_ref_time(47_000_000) - .saturating_add(RocksDbWeight::get().reads(7)) - .saturating_add(RocksDbWeight::get().writes(1)) + // Proof Size summary in bytes: + // Measured: `1169` + // Estimated: `18608` + // Minimum execution time: 41_000 nanoseconds. + Weight::from_parts(41_000_000, 18608) + .saturating_add(RocksDbWeight::get().reads(7_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) } - // Storage: Battlepass Rewards (r:1 w:0) - // Storage: Battlepass RewardStates (r:1 w:1) - // Storage: Battlepass Battlepasses (r:1 w:0) - // Storage: Control Orgs (r:1 w:0) - // Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) + /// Storage: Battlepass Rewards (r:1 w:0) + /// Proof: Battlepass Rewards (max_values: None, max_size: Some(346), added: 2821, mode: MaxEncodedLen) + /// Storage: Battlepass RewardStates (r:1 w:1) + /// Proof: Battlepass RewardStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Battlepass Battlepasses (r:1 w:0) + /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(382), added: 2857, mode: MaxEncodedLen) + /// Storage: Control Orgs (r:1 w:0) + /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) + /// Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) + /// Proof: Battlepass BattlepassInfoByOrg (max_values: None, max_size: Some(118), added: 2593, mode: MaxEncodedLen) fn disable_reward() -> Weight { - // Minimum execution time: 39_000 nanoseconds. - Weight::from_ref_time(41_000_000) - .saturating_add(RocksDbWeight::get().reads(5)) - .saturating_add(RocksDbWeight::get().writes(1)) + // Proof Size summary in bytes: + // Measured: `1094` + // Estimated: `13560` + // Minimum execution time: 33_000 nanoseconds. + Weight::from_parts(33_000_000, 13560) + .saturating_add(RocksDbWeight::get().reads(5_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) } - // Storage: Battlepass Rewards (r:1 w:0) - // Storage: Battlepass RewardStates (r:1 w:0) - // Storage: Battlepass ClaimedRewards (r:1 w:1) - // Storage: Battlepass Battlepasses (r:1 w:0) - // Storage: Battlepass BattlepassStates (r:1 w:0) - // Storage: Control OrgStates (r:1 w:0) - // Storage: Control Orgs (r:1 w:0) - // Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) - // Storage: Battlepass ClaimedBattlepasses (r:1 w:0) - // Storage: Uniques Asset (r:2 w:1) - // Storage: Uniques InstanceMetadataOf (r:2 w:1) - // Storage: Battlepass Points (r:1 w:0) - // Storage: Battlepass Levels (r:2 w:0) - // Storage: Battlepass NftIndex (r:1 w:1) - // Storage: Uniques Class (r:1 w:1) - // Storage: Uniques CollectionMaxSupply (r:1 w:0) - // Storage: Uniques Account (r:0 w:1) + /// Storage: Battlepass Rewards (r:1 w:0) + /// Proof: Battlepass Rewards (max_values: None, max_size: Some(346), added: 2821, mode: MaxEncodedLen) + /// Storage: Battlepass RewardStates (r:1 w:0) + /// Proof: Battlepass RewardStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Battlepass ClaimedRewards (r:1 w:1) + /// Proof: Battlepass ClaimedRewards (max_values: None, max_size: Some(100), added: 2575, mode: MaxEncodedLen) + /// Storage: Battlepass Battlepasses (r:1 w:0) + /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(382), added: 2857, mode: MaxEncodedLen) + /// Storage: Battlepass BattlepassStates (r:1 w:0) + /// Proof: Battlepass BattlepassStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Control OrgStates (r:1 w:0) + /// Proof: Control OrgStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Control Orgs (r:1 w:0) + /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) + /// Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) + /// Proof: Battlepass BattlepassInfoByOrg (max_values: None, max_size: Some(118), added: 2593, mode: MaxEncodedLen) + /// Storage: Uniques Account (r:2 w:1) + /// Proof: Uniques Account (max_values: None, max_size: Some(88), added: 2563, mode: MaxEncodedLen) + /// Storage: Battlepass Points (r:1 w:0) + /// Proof: Battlepass Points (max_values: None, max_size: Some(100), added: 2575, mode: MaxEncodedLen) + /// Storage: Battlepass Levels (r:2 w:0) + /// Proof: Battlepass Levels (max_values: None, max_size: Some(69), added: 2544, mode: MaxEncodedLen) + /// Storage: Battlepass NftIndex (r:1 w:1) + /// Proof: Battlepass NftIndex (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) + /// Storage: Uniques Asset (r:1 w:1) + /// Proof: Uniques Asset (max_values: None, max_size: Some(122), added: 2597, mode: MaxEncodedLen) + /// Storage: Uniques Class (r:1 w:1) + /// Proof: Uniques Class (max_values: None, max_size: Some(178), added: 2653, 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(187), added: 2662, mode: MaxEncodedLen) fn claim_reward() -> Weight { - // Minimum execution time: 137_000 nanoseconds. - Weight::from_ref_time(141_000_000) - .saturating_add(RocksDbWeight::get().reads(19)) - .saturating_add(RocksDbWeight::get().writes(6)) + // Proof Size summary in bytes: + // Measured: `2203` + // Estimated: `44882` + // Minimum execution time: 133_000 nanoseconds. + Weight::from_parts(135_000_000, 44882) + .saturating_add(RocksDbWeight::get().reads(18_u64)) + .saturating_add(RocksDbWeight::get().writes(6_u64)) } - // Storage: Battlepass Battlepasses (r:1 w:0) - // Storage: Battlepass BattlepassStates (r:1 w:0) - // Storage: Control OrgStates (r:1 w:0) - // Storage: Control Orgs (r:1 w:0) - // Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) - // Storage: Battlepass Levels (r:0 w:1) + /// Storage: Battlepass Battlepasses (r:1 w:0) + /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(382), added: 2857, mode: MaxEncodedLen) + /// Storage: Battlepass BattlepassStates (r:1 w:0) + /// Proof: Battlepass BattlepassStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Control OrgStates (r:1 w:0) + /// Proof: Control OrgStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Control Orgs (r:1 w:0) + /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) + /// Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) + /// Proof: Battlepass BattlepassInfoByOrg (max_values: None, max_size: Some(118), added: 2593, mode: MaxEncodedLen) + /// Storage: Battlepass Levels (r:0 w:1) + /// Proof: Battlepass Levels (max_values: None, max_size: Some(69), added: 2544, mode: MaxEncodedLen) fn add_level() -> Weight { - // Minimum execution time: 39_000 nanoseconds. - Weight::from_ref_time(41_000_000) - .saturating_add(RocksDbWeight::get().reads(5)) - .saturating_add(RocksDbWeight::get().writes(1)) + // Proof Size summary in bytes: + // Measured: `945` + // Estimated: `13263` + // Minimum execution time: 31_000 nanoseconds. + Weight::from_parts(32_000_000, 13263) + .saturating_add(RocksDbWeight::get().reads(5_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) } - // Storage: Battlepass Battlepasses (r:1 w:0) - // Storage: Battlepass BattlepassStates (r:1 w:0) - // Storage: Control OrgStates (r:1 w:0) - // Storage: Control Orgs (r:1 w:0) - // Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) - // Storage: Battlepass Levels (r:1 w:1) + /// Storage: Battlepass Battlepasses (r:1 w:0) + /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(382), added: 2857, mode: MaxEncodedLen) + /// Storage: Battlepass BattlepassStates (r:1 w:0) + /// Proof: Battlepass BattlepassStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Control OrgStates (r:1 w:0) + /// Proof: Control OrgStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Control Orgs (r:1 w:0) + /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) + /// Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) + /// Proof: Battlepass BattlepassInfoByOrg (max_values: None, max_size: Some(118), added: 2593, mode: MaxEncodedLen) + /// Storage: Battlepass Levels (r:1 w:1) + /// Proof: Battlepass Levels (max_values: None, max_size: Some(69), added: 2544, mode: MaxEncodedLen) fn remove_level() -> Weight { - // Minimum execution time: 40_000 nanoseconds. - Weight::from_ref_time(42_000_000) - .saturating_add(RocksDbWeight::get().reads(6)) - .saturating_add(RocksDbWeight::get().writes(1)) + // Proof Size summary in bytes: + // Measured: `1038` + // Estimated: `15807` + // Minimum execution time: 36_000 nanoseconds. + Weight::from_parts(37_000_000, 15807) + .saturating_add(RocksDbWeight::get().reads(6_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) } - // Storage: Battlepass Battlepasses (r:1 w:0) - // Storage: Battlepass BattlepassStates (r:1 w:0) - // Storage: Control OrgStates (r:1 w:0) - // Storage: Control Orgs (r:1 w:0) - // Storage: Battlepass BattlepassInfoByOrg (r:1 w:1) + /// Storage: Battlepass Battlepasses (r:1 w:0) + /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(382), added: 2857, mode: MaxEncodedLen) + /// Storage: Battlepass BattlepassStates (r:1 w:0) + /// Proof: Battlepass BattlepassStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Control OrgStates (r:1 w:0) + /// Proof: Control OrgStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Control Orgs (r:1 w:0) + /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) + /// Storage: Battlepass BattlepassInfoByOrg (r:1 w:1) + /// Proof: Battlepass BattlepassInfoByOrg (max_values: None, max_size: Some(118), added: 2593, mode: MaxEncodedLen) fn add_bot() -> Weight { - // Minimum execution time: 35_000 nanoseconds. - Weight::from_ref_time(35_000_000) - .saturating_add(RocksDbWeight::get().reads(5)) - .saturating_add(RocksDbWeight::get().writes(1)) + // Proof Size summary in bytes: + // Measured: `880` + // Estimated: `13263` + // Minimum execution time: 30_000 nanoseconds. + Weight::from_parts(31_000_000, 13263) + .saturating_add(RocksDbWeight::get().reads(5_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) } } \ No newline at end of file diff --git a/control/Cargo.toml b/control/Cargo.toml index b3132c03b..b1aa751a6 100755 --- a/control/Cargo.toml +++ b/control/Cargo.toml @@ -5,7 +5,7 @@ # ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ [package] name = "gamedao-control" -version = "1.2.0" +version = "1.3.0" authors = ["zero.io","gamedao.co"] repository = "https://github.com/gamedaoco/gamedao-protocol" edition = "2018" @@ -17,32 +17,32 @@ hex-literal = "0.3.4" num_enum = { version = "0.5.1", default-features = false } serde = { version = "1.0.143", default-features = false } -codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] } +codec = { package = "parity-scale-codec", version = "3.2.2", default-features = false, features = ["derive"] } scale-info = { version = "2.1.1", default-features = false, features = ["derive"] } -sp-core = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } -sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } -sp-std = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } -sp-storage = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } +sp-core = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } +sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } +sp-std = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } +sp-storage = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } -frame-support = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } -frame-system = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } -frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36", default-features = false, optional = true } -sp-io = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.36", default-features=false } +frame-support = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } +frame-system = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } +frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38", default-features = false, optional = true } +sp-io = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.38", default-features=false } -pallet-balances = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } +pallet-balances = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } -orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.36", default-features = false } +orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.38", default-features = false } gamedao-traits = { package = "gamedao-traits", path = "../traits", default-features = false } # tangram = { package = "module-tangram", path = "../../zero/tangram", default-features = false } [dev-dependencies] -sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.36" } -sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.36" } -pallet-balances = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } -orml-currencies = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.36", default-features = false } -orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.36", default-features = false } +sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.38" } +sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.38" } +pallet-balances = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } +orml-currencies = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.38", default-features = false } +orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.38", default-features = false } [features] default = ["std"] diff --git a/control/src/weights.rs b/control/src/weights.rs index c92926dea..6583e7cd7 100644 --- a/control/src/weights.rs +++ b/control/src/weights.rs @@ -2,7 +2,8 @@ //! Autogenerated weights for gamedao_control //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-02-10, STEPS: `20`, REPEAT: 10, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2023-03-04, STEPS: `20`, REPEAT: `10`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! WORST CASE MAP SIZE: `1000000` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: None, DB CACHE: 1024 // Executed Command: @@ -39,174 +40,282 @@ pub trait WeightInfo { /// Weights for gamedao_control using the Substrate node and recommended hardware. pub struct SubstrateWeight(PhantomData); impl WeightInfo for SubstrateWeight { - // Storage: Control OrgCount (r:1 w:1) - // Storage: System Account (r:1 w:1) - // Storage: Control Orgs (r:1 w:1) - // Storage: Tokens Accounts (r:2 w:2) - // Storage: Control Members (r:1 w:1) - // Storage: Control OrgMemberCount (r:0 w:1) - // Storage: Control OrgTreasury (r:0 w:1) - // Storage: Control MemberStates (r:0 w:1) - // Storage: Control OrgStates (r:0 w:1) + /// Storage: Control OrgCount (r:1 w:1) + /// Proof: Control OrgCount (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) + /// Storage: System Account (r:1 w:1) + /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) + /// Storage: Control Orgs (r:1 w:1) + /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) + /// Storage: Tokens Accounts (r:2 w:2) + /// Proof: Tokens Accounts (max_values: None, max_size: Some(109), added: 2584, mode: MaxEncodedLen) + /// Storage: Control Members (r:1 w:1) + /// Proof: Control Members (max_values: None, max_size: Some(32050), added: 34525, mode: MaxEncodedLen) + /// Storage: Control OrgMemberCount (r:0 w:1) + /// Proof: Control OrgMemberCount (max_values: None, max_size: Some(52), added: 2527, mode: MaxEncodedLen) + /// Storage: Control OrgTreasury (r:0 w:1) + /// Proof: Control OrgTreasury (max_values: None, max_size: Some(80), added: 2555, mode: MaxEncodedLen) + /// Storage: Control MemberStates (r:0 w:1) + /// Proof: Control MemberStates (max_values: None, max_size: Some(97), added: 2572, mode: MaxEncodedLen) + /// Storage: Control OrgStates (r:0 w:1) + /// Proof: Control OrgStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) fn create_org() -> Weight { - // Minimum execution time: 79_000 nanoseconds. - Weight::from_ref_time(81_000_000) - .saturating_add(T::DbWeight::get().reads(6)) - .saturating_add(T::DbWeight::get().writes(10)) + // Proof Size summary in bytes: + // Measured: `408` + // Estimated: `45560` + // Minimum execution time: 70_000 nanoseconds. + Weight::from_parts(71_000_000, 45560) + .saturating_add(T::DbWeight::get().reads(6_u64)) + .saturating_add(T::DbWeight::get().writes(10_u64)) } - // Storage: Control Orgs (r:1 w:1) - // Storage: Control MemberStates (r:1 w:0) + /// Storage: Control Orgs (r:1 w:1) + /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) + /// Storage: Control MemberStates (r:1 w:0) + /// Proof: Control MemberStates (max_values: None, max_size: Some(97), added: 2572, mode: MaxEncodedLen) fn update_org() -> Weight { - // Minimum execution time: 28_000 nanoseconds. - Weight::from_ref_time(29_000_000) - .saturating_add(T::DbWeight::get().reads(2)) - .saturating_add(T::DbWeight::get().writes(1)) + // Proof Size summary in bytes: + // Measured: `565` + // Estimated: `5337` + // Minimum execution time: 21_000 nanoseconds. + Weight::from_parts(22_000_000, 5337) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) } - // Storage: Control Orgs (r:1 w:0) - // Storage: Control OrgStates (r:0 w:1) + /// Storage: Control Orgs (r:1 w:0) + /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) + /// Storage: Control OrgStates (r:0 w:1) + /// Proof: Control OrgStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) fn disable_org() -> Weight { - // Minimum execution time: 23_000 nanoseconds. - Weight::from_ref_time(24_000_000) - .saturating_add(T::DbWeight::get().reads(1)) - .saturating_add(T::DbWeight::get().writes(1)) + // Proof Size summary in bytes: + // Measured: `480` + // Estimated: `2765` + // Minimum execution time: 17_000 nanoseconds. + Weight::from_parts(18_000_000, 2765) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) } - // Storage: Control Orgs (r:1 w:0) - // Storage: Control OrgStates (r:0 w:1) + /// Storage: Control Orgs (r:1 w:0) + /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) + /// Storage: Control OrgStates (r:0 w:1) + /// Proof: Control OrgStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) fn enable_org() -> Weight { - // Minimum execution time: 24_000 nanoseconds. - Weight::from_ref_time(25_000_000) - .saturating_add(T::DbWeight::get().reads(1)) - .saturating_add(T::DbWeight::get().writes(1)) - } - // Storage: Control Orgs (r:1 w:0) - // Storage: Control OrgTreasury (r:1 w:0) - // Storage: Control Members (r:1 w:1) - // Storage: Control OrgMemberCount (r:0 w:1) - // Storage: Control MemberStates (r:0 w:1) + // Proof Size summary in bytes: + // Measured: `480` + // Estimated: `2765` + // Minimum execution time: 17_000 nanoseconds. + Weight::from_parts(17_000_000, 2765) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: Control Orgs (r:1 w:0) + /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) + /// Storage: Control OrgTreasury (r:1 w:0) + /// Proof: Control OrgTreasury (max_values: None, max_size: Some(80), added: 2555, mode: MaxEncodedLen) + /// Storage: Control Members (r:1 w:1) + /// Proof: Control Members (max_values: None, max_size: Some(32050), added: 34525, mode: MaxEncodedLen) + /// Storage: Control OrgMemberCount (r:0 w:1) + /// Proof: Control OrgMemberCount (max_values: None, max_size: Some(52), added: 2527, mode: MaxEncodedLen) + /// Storage: Control MemberStates (r:0 w:1) + /// Proof: Control MemberStates (max_values: None, max_size: Some(97), added: 2572, mode: MaxEncodedLen) /// The range of component `r` is `[1, 999]`. fn add_member(r: u32, ) -> Weight { - // Minimum execution time: 36_000 nanoseconds. - Weight::from_ref_time(34_091_687) - // Standard Error: 1_851 - .saturating_add(Weight::from_ref_time(65_158).saturating_mul(r.into())) - .saturating_add(T::DbWeight::get().reads(3)) - .saturating_add(T::DbWeight::get().writes(3)) - } - // Storage: Control Orgs (r:1 w:0) - // Storage: Control MemberStates (r:1 w:0) + // Proof Size summary in bytes: + // Measured: `659 + r * (32 ±0)` + // Estimated: `39845` + // Minimum execution time: 29_000 nanoseconds. + Weight::from_parts(27_804_864, 39845) + // Standard Error: 897 + .saturating_add(Weight::from_ref_time(34_905).saturating_mul(r.into())) + .saturating_add(T::DbWeight::get().reads(3_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) + } + /// Storage: Control Orgs (r:1 w:0) + /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) + /// Storage: Control MemberStates (r:1 w:0) + /// Proof: Control MemberStates (max_values: None, max_size: Some(97), added: 2572, mode: MaxEncodedLen) fn update_member_state() -> Weight { - // Minimum execution time: 15_000 nanoseconds. - Weight::from_ref_time(16_000_000) - .saturating_add(T::DbWeight::get().reads(2)) - } - // Storage: Control Orgs (r:1 w:0) - // Storage: Control Members (r:1 w:1) - // Storage: Control OrgMemberCount (r:0 w:1) - // Storage: Control MemberStates (r:0 w:1) + // Proof Size summary in bytes: + // Measured: `604` + // Estimated: `5337` + // Minimum execution time: 14_000 nanoseconds. + Weight::from_parts(15_000_000, 5337) + .saturating_add(T::DbWeight::get().reads(2_u64)) + } + /// Storage: Control Orgs (r:1 w:0) + /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) + /// Storage: Control Members (r:1 w:1) + /// Proof: Control Members (max_values: None, max_size: Some(32050), added: 34525, mode: MaxEncodedLen) + /// Storage: Control OrgMemberCount (r:0 w:1) + /// Proof: Control OrgMemberCount (max_values: None, max_size: Some(52), added: 2527, mode: MaxEncodedLen) + /// Storage: Control MemberStates (r:0 w:1) + /// Proof: Control MemberStates (max_values: None, max_size: Some(97), added: 2572, mode: MaxEncodedLen) /// The range of component `r` is `[1, 999]`. fn remove_member(r: u32, ) -> Weight { - // Minimum execution time: 30_000 nanoseconds. - Weight::from_ref_time(37_544_684) - // Standard Error: 2_351 - .saturating_add(Weight::from_ref_time(43_383).saturating_mul(r.into())) - .saturating_add(T::DbWeight::get().reads(2)) - .saturating_add(T::DbWeight::get().writes(3)) - } - // Storage: Control Orgs (r:1 w:0) - // Storage: Control OrgTreasury (r:1 w:0) - // Storage: Tokens Accounts (r:2 w:2) - // Storage: System Account (r:2 w:1) + // Proof Size summary in bytes: + // Measured: `584 + r * (32 ±0)` + // Estimated: `37290` + // Minimum execution time: 25_000 nanoseconds. + Weight::from_parts(23_223_981, 37290) + // Standard Error: 874 + .saturating_add(Weight::from_ref_time(33_949).saturating_mul(r.into())) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) + } + /// Storage: Control Orgs (r:1 w:0) + /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) + /// Storage: Control OrgTreasury (r:1 w:0) + /// Proof: Control OrgTreasury (max_values: None, max_size: Some(80), added: 2555, mode: MaxEncodedLen) + /// Storage: Tokens Accounts (r:2 w:2) + /// Proof: Tokens Accounts (max_values: None, max_size: Some(109), added: 2584, mode: MaxEncodedLen) + /// Storage: System Account (r:2 w:1) + /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) fn spend_funds() -> Weight { - // Minimum execution time: 63_000 nanoseconds. - Weight::from_ref_time(64_000_000) - .saturating_add(T::DbWeight::get().reads(6)) - .saturating_add(T::DbWeight::get().writes(3)) + // Proof Size summary in bytes: + // Measured: `1040` + // Estimated: `15694` + // Minimum execution time: 58_000 nanoseconds. + Weight::from_parts(59_000_000, 15694) + .saturating_add(T::DbWeight::get().reads(6_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) } } // For backwards compatibility and tests impl WeightInfo for () { - // Storage: Control OrgCount (r:1 w:1) - // Storage: System Account (r:1 w:1) - // Storage: Control Orgs (r:1 w:1) - // Storage: Tokens Accounts (r:2 w:2) - // Storage: Control Members (r:1 w:1) - // Storage: Control OrgMemberCount (r:0 w:1) - // Storage: Control OrgTreasury (r:0 w:1) - // Storage: Control MemberStates (r:0 w:1) - // Storage: Control OrgStates (r:0 w:1) + /// Storage: Control OrgCount (r:1 w:1) + /// Proof: Control OrgCount (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) + /// Storage: System Account (r:1 w:1) + /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) + /// Storage: Control Orgs (r:1 w:1) + /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) + /// Storage: Tokens Accounts (r:2 w:2) + /// Proof: Tokens Accounts (max_values: None, max_size: Some(109), added: 2584, mode: MaxEncodedLen) + /// Storage: Control Members (r:1 w:1) + /// Proof: Control Members (max_values: None, max_size: Some(32050), added: 34525, mode: MaxEncodedLen) + /// Storage: Control OrgMemberCount (r:0 w:1) + /// Proof: Control OrgMemberCount (max_values: None, max_size: Some(52), added: 2527, mode: MaxEncodedLen) + /// Storage: Control OrgTreasury (r:0 w:1) + /// Proof: Control OrgTreasury (max_values: None, max_size: Some(80), added: 2555, mode: MaxEncodedLen) + /// Storage: Control MemberStates (r:0 w:1) + /// Proof: Control MemberStates (max_values: None, max_size: Some(97), added: 2572, mode: MaxEncodedLen) + /// Storage: Control OrgStates (r:0 w:1) + /// Proof: Control OrgStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) fn create_org() -> Weight { - // Minimum execution time: 79_000 nanoseconds. - Weight::from_ref_time(81_000_000) - .saturating_add(RocksDbWeight::get().reads(6)) - .saturating_add(RocksDbWeight::get().writes(10)) + // Proof Size summary in bytes: + // Measured: `408` + // Estimated: `45560` + // Minimum execution time: 70_000 nanoseconds. + Weight::from_parts(71_000_000, 45560) + .saturating_add(RocksDbWeight::get().reads(6_u64)) + .saturating_add(RocksDbWeight::get().writes(10_u64)) } - // Storage: Control Orgs (r:1 w:1) - // Storage: Control MemberStates (r:1 w:0) + /// Storage: Control Orgs (r:1 w:1) + /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) + /// Storage: Control MemberStates (r:1 w:0) + /// Proof: Control MemberStates (max_values: None, max_size: Some(97), added: 2572, mode: MaxEncodedLen) fn update_org() -> Weight { - // Minimum execution time: 28_000 nanoseconds. - Weight::from_ref_time(29_000_000) - .saturating_add(RocksDbWeight::get().reads(2)) - .saturating_add(RocksDbWeight::get().writes(1)) + // Proof Size summary in bytes: + // Measured: `565` + // Estimated: `5337` + // Minimum execution time: 21_000 nanoseconds. + Weight::from_parts(22_000_000, 5337) + .saturating_add(RocksDbWeight::get().reads(2_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) } - // Storage: Control Orgs (r:1 w:0) - // Storage: Control OrgStates (r:0 w:1) + /// Storage: Control Orgs (r:1 w:0) + /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) + /// Storage: Control OrgStates (r:0 w:1) + /// Proof: Control OrgStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) fn disable_org() -> Weight { - // Minimum execution time: 23_000 nanoseconds. - Weight::from_ref_time(24_000_000) - .saturating_add(RocksDbWeight::get().reads(1)) - .saturating_add(RocksDbWeight::get().writes(1)) + // Proof Size summary in bytes: + // Measured: `480` + // Estimated: `2765` + // Minimum execution time: 17_000 nanoseconds. + Weight::from_parts(18_000_000, 2765) + .saturating_add(RocksDbWeight::get().reads(1_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) } - // Storage: Control Orgs (r:1 w:0) - // Storage: Control OrgStates (r:0 w:1) + /// Storage: Control Orgs (r:1 w:0) + /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) + /// Storage: Control OrgStates (r:0 w:1) + /// Proof: Control OrgStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) fn enable_org() -> Weight { - // Minimum execution time: 24_000 nanoseconds. - Weight::from_ref_time(25_000_000) - .saturating_add(RocksDbWeight::get().reads(1)) - .saturating_add(RocksDbWeight::get().writes(1)) - } - // Storage: Control Orgs (r:1 w:0) - // Storage: Control OrgTreasury (r:1 w:0) - // Storage: Control Members (r:1 w:1) - // Storage: Control OrgMemberCount (r:0 w:1) - // Storage: Control MemberStates (r:0 w:1) + // Proof Size summary in bytes: + // Measured: `480` + // Estimated: `2765` + // Minimum execution time: 17_000 nanoseconds. + Weight::from_parts(17_000_000, 2765) + .saturating_add(RocksDbWeight::get().reads(1_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) + } + /// Storage: Control Orgs (r:1 w:0) + /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) + /// Storage: Control OrgTreasury (r:1 w:0) + /// Proof: Control OrgTreasury (max_values: None, max_size: Some(80), added: 2555, mode: MaxEncodedLen) + /// Storage: Control Members (r:1 w:1) + /// Proof: Control Members (max_values: None, max_size: Some(32050), added: 34525, mode: MaxEncodedLen) + /// Storage: Control OrgMemberCount (r:0 w:1) + /// Proof: Control OrgMemberCount (max_values: None, max_size: Some(52), added: 2527, mode: MaxEncodedLen) + /// Storage: Control MemberStates (r:0 w:1) + /// Proof: Control MemberStates (max_values: None, max_size: Some(97), added: 2572, mode: MaxEncodedLen) /// The range of component `r` is `[1, 999]`. fn add_member(r: u32, ) -> Weight { - // Minimum execution time: 36_000 nanoseconds. - Weight::from_ref_time(34_091_687) - // Standard Error: 1_851 - .saturating_add(Weight::from_ref_time(65_158).saturating_mul(r.into())) - .saturating_add(RocksDbWeight::get().reads(3)) - .saturating_add(RocksDbWeight::get().writes(3)) - } - // Storage: Control Orgs (r:1 w:0) - // Storage: Control MemberStates (r:1 w:0) + // Proof Size summary in bytes: + // Measured: `659 + r * (32 ±0)` + // Estimated: `39845` + // Minimum execution time: 29_000 nanoseconds. + Weight::from_parts(27_804_864, 39845) + // Standard Error: 897 + .saturating_add(Weight::from_ref_time(34_905).saturating_mul(r.into())) + .saturating_add(RocksDbWeight::get().reads(3_u64)) + .saturating_add(RocksDbWeight::get().writes(3_u64)) + } + /// Storage: Control Orgs (r:1 w:0) + /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) + /// Storage: Control MemberStates (r:1 w:0) + /// Proof: Control MemberStates (max_values: None, max_size: Some(97), added: 2572, mode: MaxEncodedLen) fn update_member_state() -> Weight { - // Minimum execution time: 15_000 nanoseconds. - Weight::from_ref_time(16_000_000) - .saturating_add(RocksDbWeight::get().reads(2)) - } - // Storage: Control Orgs (r:1 w:0) - // Storage: Control Members (r:1 w:1) - // Storage: Control OrgMemberCount (r:0 w:1) - // Storage: Control MemberStates (r:0 w:1) + // Proof Size summary in bytes: + // Measured: `604` + // Estimated: `5337` + // Minimum execution time: 14_000 nanoseconds. + Weight::from_parts(15_000_000, 5337) + .saturating_add(RocksDbWeight::get().reads(2_u64)) + } + /// Storage: Control Orgs (r:1 w:0) + /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) + /// Storage: Control Members (r:1 w:1) + /// Proof: Control Members (max_values: None, max_size: Some(32050), added: 34525, mode: MaxEncodedLen) + /// Storage: Control OrgMemberCount (r:0 w:1) + /// Proof: Control OrgMemberCount (max_values: None, max_size: Some(52), added: 2527, mode: MaxEncodedLen) + /// Storage: Control MemberStates (r:0 w:1) + /// Proof: Control MemberStates (max_values: None, max_size: Some(97), added: 2572, mode: MaxEncodedLen) /// The range of component `r` is `[1, 999]`. fn remove_member(r: u32, ) -> Weight { - // Minimum execution time: 30_000 nanoseconds. - Weight::from_ref_time(37_544_684) - // Standard Error: 2_351 - .saturating_add(Weight::from_ref_time(43_383).saturating_mul(r.into())) - .saturating_add(RocksDbWeight::get().reads(2)) - .saturating_add(RocksDbWeight::get().writes(3)) - } - // Storage: Control Orgs (r:1 w:0) - // Storage: Control OrgTreasury (r:1 w:0) - // Storage: Tokens Accounts (r:2 w:2) - // Storage: System Account (r:2 w:1) + // Proof Size summary in bytes: + // Measured: `584 + r * (32 ±0)` + // Estimated: `37290` + // Minimum execution time: 25_000 nanoseconds. + Weight::from_parts(23_223_981, 37290) + // Standard Error: 874 + .saturating_add(Weight::from_ref_time(33_949).saturating_mul(r.into())) + .saturating_add(RocksDbWeight::get().reads(2_u64)) + .saturating_add(RocksDbWeight::get().writes(3_u64)) + } + /// Storage: Control Orgs (r:1 w:0) + /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) + /// Storage: Control OrgTreasury (r:1 w:0) + /// Proof: Control OrgTreasury (max_values: None, max_size: Some(80), added: 2555, mode: MaxEncodedLen) + /// Storage: Tokens Accounts (r:2 w:2) + /// Proof: Tokens Accounts (max_values: None, max_size: Some(109), added: 2584, mode: MaxEncodedLen) + /// Storage: System Account (r:2 w:1) + /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) fn spend_funds() -> Weight { - // Minimum execution time: 63_000 nanoseconds. - Weight::from_ref_time(64_000_000) - .saturating_add(RocksDbWeight::get().reads(6)) - .saturating_add(RocksDbWeight::get().writes(3)) + // Proof Size summary in bytes: + // Measured: `1040` + // Estimated: `15694` + // Minimum execution time: 58_000 nanoseconds. + Weight::from_parts(59_000_000, 15694) + .saturating_add(RocksDbWeight::get().reads(6_u64)) + .saturating_add(RocksDbWeight::get().writes(3_u64)) } } \ No newline at end of file diff --git a/flow/Cargo.toml b/flow/Cargo.toml index bb918ccc0..cfb515e01 100644 --- a/flow/Cargo.toml +++ b/flow/Cargo.toml @@ -6,7 +6,7 @@ [package] name = "gamedao-flow" -version = "1.2.0" +version = "1.3.0" authors = ["zero.io","gamedao.co"] edition = "2018" license = "GPL-3.0-or-later" @@ -15,27 +15,27 @@ repository = "https://github.com/gamedaoco/gamedao-protocol" [dependencies] serde = { version = "1.0.143", default-features = false } -codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] } +codec = { package = "parity-scale-codec", version = "3.2.2", default-features = false, features = ["derive"] } scale-info = { version = "2.1.1", default-features = false, features = ["derive"] } -sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36", default-features = false } -sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36", default-features = false } -frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36", default-features = false } -frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36", default-features = false } -frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36", default-features = false, optional = true } -sp-io = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.36", default-features=false } +sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38", default-features = false } +sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38", default-features = false } +frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38", default-features = false } +frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38", default-features = false } +frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38", default-features = false, optional = true } +sp-io = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.38", default-features=false } -orml-currencies = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.36", default-features = false } -orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.36", default-features = false } -orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.36", default-features = false } +orml-currencies = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.38", default-features = false } +orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.38", default-features = false } +orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.38", default-features = false } gamedao-traits = { package = "gamedao-traits", path = "../traits", default-features = false } gamedao-control = { package = "gamedao-control", path = "../control", default-features = false } [dev-dependencies] -sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.36" } +sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.38" } -pallet-timestamp = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } -pallet-balances = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } +pallet-timestamp = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } +pallet-balances = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } gamedao-control = { package = "gamedao-control", path = "../control", default-features = true } diff --git a/flow/src/weights.rs b/flow/src/weights.rs index f18793861..6f7abf2d2 100644 --- a/flow/src/weights.rs +++ b/flow/src/weights.rs @@ -2,7 +2,8 @@ //! Autogenerated weights for gamedao_flow //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-02-10, STEPS: `20`, REPEAT: 10, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2023-03-04, STEPS: `20`, REPEAT: `10`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! WORST CASE MAP SIZE: `1000000` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: None, DB CACHE: 1024 // Executed Command: @@ -34,104 +35,166 @@ pub trait WeightInfo { /// Weights for gamedao_flow using the Substrate node and recommended hardware. pub struct SubstrateWeight(PhantomData); impl WeightInfo for SubstrateWeight { - // Storage: Control Orgs (r:1 w:0) - // Storage: Flow CampaignCount (r:1 w:1) - // Storage: Flow CampaignsByBlock (r:2 w:2) - // Storage: Control OrgTreasury (r:1 w:0) - // Storage: Tokens Accounts (r:1 w:1) - // Storage: Flow CampaignOf (r:0 w:1) - // Storage: Flow CampaignStates (r:0 w:1) + /// Storage: Control Orgs (r:1 w:0) + /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) + /// Storage: Flow CampaignCount (r:1 w:1) + /// Proof: Flow CampaignCount (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) + /// Storage: Flow CampaignsByBlock (r:2 w:2) + /// Proof: Flow CampaignsByBlock (max_values: None, max_size: Some(358), added: 2833, mode: MaxEncodedLen) + /// Storage: Control OrgTreasury (r:1 w:0) + /// Proof: Control OrgTreasury (max_values: None, max_size: Some(80), added: 2555, mode: MaxEncodedLen) + /// Storage: Tokens Accounts (r:1 w:1) + /// Proof: Tokens Accounts (max_values: None, max_size: Some(109), added: 2584, mode: MaxEncodedLen) + /// Storage: Flow CampaignOf (r:0 w:1) + /// Proof: Flow CampaignOf (max_values: None, max_size: Some(460), added: 2935, mode: MaxEncodedLen) + /// Storage: Flow CampaignStates (r:0 w:1) + /// Proof: Flow CampaignStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) fn create_campaign() -> Weight { - // Minimum execution time: 64_000 nanoseconds. - Weight::from_ref_time(67_000_000) - .saturating_add(T::DbWeight::get().reads(6)) - .saturating_add(T::DbWeight::get().writes(6)) + // Proof Size summary in bytes: + // Measured: `1009` + // Estimated: `14069` + // Minimum execution time: 57_000 nanoseconds. + Weight::from_parts(58_000_000, 14069) + .saturating_add(T::DbWeight::get().reads(6_u64)) + .saturating_add(T::DbWeight::get().writes(6_u64)) } - // Storage: Flow CampaignOf (r:1 w:0) - // Storage: Flow CampaignStates (r:1 w:0) - // Storage: Flow CampaignContribution (r:1 w:1) - // Storage: Flow CampaignContributorsCount (r:1 w:1) - // Storage: Tokens Accounts (r:1 w:1) - // Storage: Flow CampaignBalance (r:1 w:1) + /// Storage: Flow CampaignOf (r:1 w:0) + /// Proof: Flow CampaignOf (max_values: None, max_size: Some(460), added: 2935, mode: MaxEncodedLen) + /// Storage: Flow CampaignStates (r:1 w:0) + /// Proof: Flow CampaignStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Flow CampaignContribution (r:1 w:1) + /// Proof: Flow CampaignContribution (max_values: None, max_size: Some(112), added: 2587, mode: MaxEncodedLen) + /// Storage: Flow CampaignContributorsCount (r:1 w:1) + /// Proof: Flow CampaignContributorsCount (max_values: None, max_size: Some(56), added: 2531, mode: MaxEncodedLen) + /// Storage: Tokens Accounts (r:1 w:1) + /// Proof: Tokens Accounts (max_values: None, max_size: Some(109), added: 2584, mode: MaxEncodedLen) + /// Storage: Flow CampaignBalance (r:1 w:1) + /// Proof: Flow CampaignBalance (max_values: None, max_size: Some(64), added: 2539, mode: MaxEncodedLen) fn contribute() -> Weight { - // Minimum execution time: 56_000 nanoseconds. - Weight::from_ref_time(58_000_000) - .saturating_add(T::DbWeight::get().reads(6)) - .saturating_add(T::DbWeight::get().writes(4)) + // Proof Size summary in bytes: + // Measured: `1104` + // Estimated: `15700` + // Minimum execution time: 48_000 nanoseconds. + Weight::from_parts(51_000_000, 15700) + .saturating_add(T::DbWeight::get().reads(6_u64)) + .saturating_add(T::DbWeight::get().writes(4_u64)) } - // Storage: Flow CampaignsByBlock (r:1 w:0) - // Storage: Flow CampaignStates (r:10 w:11) - // Storage: Flow CampaignFinalizationQueue (r:2 w:1) - // Storage: Tokens Accounts (r:1 w:1) - // Storage: Flow CampaignContribution (r:5 w:0) - // Storage: System Account (r:1 w:1) - // Storage: Flow CampaignBalance (r:0 w:1) + /// Storage: Flow CampaignsByBlock (r:1 w:0) + /// Proof: Flow CampaignsByBlock (max_values: None, max_size: Some(358), added: 2833, mode: MaxEncodedLen) + /// Storage: Flow CampaignStates (r:10 w:11) + /// Proof: Flow CampaignStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Flow CampaignFinalizationQueue (r:2 w:1) + /// Proof: Flow CampaignFinalizationQueue (max_values: None, max_size: Some(320511), added: 322986, mode: MaxEncodedLen) + /// Storage: Flow CampaignContribution (r:100 w:0) + /// Proof: Flow CampaignContribution (max_values: None, max_size: Some(112), added: 2587, mode: MaxEncodedLen) + /// Storage: Tokens Accounts (r:102 w:102) + /// Proof: Tokens Accounts (max_values: None, max_size: Some(109), added: 2584, mode: MaxEncodedLen) + /// Storage: System Account (r:1 w:1) + /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) + /// Storage: Flow CampaignBalance (r:0 w:1) + /// Proof: Flow CampaignBalance (max_values: None, max_size: Some(64), added: 2539, mode: MaxEncodedLen) /// The range of component `c` is `[0, 100]`. /// The range of component `p` is `[0, 10]`. fn on_initialize(c: u32, p: u32, ) -> Weight { - // Minimum execution time: 134_000 nanoseconds. - Weight::from_ref_time(68_040_945) - // Standard Error: 55_163 - .saturating_add(Weight::from_ref_time(25_455_935).saturating_mul(c.into())) - // Standard Error: 551_554 - .saturating_add(Weight::from_ref_time(9_852_261).saturating_mul(p.into())) - .saturating_add(T::DbWeight::get().reads(5)) + // Proof Size summary in bytes: + // Measured: `1615 + c * (288 ±0) + p * (87 ±0)` + // Estimated: `655398 + c * (5182 ±0) + p * (2558 ±12)` + // Minimum execution time: 136_000 nanoseconds. + Weight::from_parts(62_296_021, 655398) + // Standard Error: 59_341 + .saturating_add(Weight::from_ref_time(25_969_615).saturating_mul(c.into())) + // Standard Error: 593_322 + .saturating_add(Weight::from_ref_time(10_250_535).saturating_mul(p.into())) + .saturating_add(T::DbWeight::get().reads(5_u64)) .saturating_add(T::DbWeight::get().reads((2_u64).saturating_mul(c.into()))) .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(p.into()))) - .saturating_add(T::DbWeight::get().writes(5)) + .saturating_add(T::DbWeight::get().writes(5_u64)) .saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(c.into()))) .saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(p.into()))) + .saturating_add(Weight::from_proof_size(5182).saturating_mul(c.into())) + .saturating_add(Weight::from_proof_size(2558).saturating_mul(p.into())) } } // For backwards compatibility and tests impl WeightInfo for () { - // Storage: Control Orgs (r:1 w:0) - // Storage: Flow CampaignCount (r:1 w:1) - // Storage: Flow CampaignsByBlock (r:2 w:2) - // Storage: Control OrgTreasury (r:1 w:0) - // Storage: Tokens Accounts (r:1 w:1) - // Storage: Flow CampaignOf (r:0 w:1) - // Storage: Flow CampaignStates (r:0 w:1) + /// Storage: Control Orgs (r:1 w:0) + /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) + /// Storage: Flow CampaignCount (r:1 w:1) + /// Proof: Flow CampaignCount (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) + /// Storage: Flow CampaignsByBlock (r:2 w:2) + /// Proof: Flow CampaignsByBlock (max_values: None, max_size: Some(358), added: 2833, mode: MaxEncodedLen) + /// Storage: Control OrgTreasury (r:1 w:0) + /// Proof: Control OrgTreasury (max_values: None, max_size: Some(80), added: 2555, mode: MaxEncodedLen) + /// Storage: Tokens Accounts (r:1 w:1) + /// Proof: Tokens Accounts (max_values: None, max_size: Some(109), added: 2584, mode: MaxEncodedLen) + /// Storage: Flow CampaignOf (r:0 w:1) + /// Proof: Flow CampaignOf (max_values: None, max_size: Some(460), added: 2935, mode: MaxEncodedLen) + /// Storage: Flow CampaignStates (r:0 w:1) + /// Proof: Flow CampaignStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) fn create_campaign() -> Weight { - // Minimum execution time: 64_000 nanoseconds. - Weight::from_ref_time(67_000_000) - .saturating_add(RocksDbWeight::get().reads(6)) - .saturating_add(RocksDbWeight::get().writes(6)) + // Proof Size summary in bytes: + // Measured: `1009` + // Estimated: `14069` + // Minimum execution time: 57_000 nanoseconds. + Weight::from_parts(58_000_000, 14069) + .saturating_add(RocksDbWeight::get().reads(6_u64)) + .saturating_add(RocksDbWeight::get().writes(6_u64)) } - // Storage: Flow CampaignOf (r:1 w:0) - // Storage: Flow CampaignStates (r:1 w:0) - // Storage: Flow CampaignContribution (r:1 w:1) - // Storage: Flow CampaignContributorsCount (r:1 w:1) - // Storage: Tokens Accounts (r:1 w:1) - // Storage: Flow CampaignBalance (r:1 w:1) + /// Storage: Flow CampaignOf (r:1 w:0) + /// Proof: Flow CampaignOf (max_values: None, max_size: Some(460), added: 2935, mode: MaxEncodedLen) + /// Storage: Flow CampaignStates (r:1 w:0) + /// Proof: Flow CampaignStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Flow CampaignContribution (r:1 w:1) + /// Proof: Flow CampaignContribution (max_values: None, max_size: Some(112), added: 2587, mode: MaxEncodedLen) + /// Storage: Flow CampaignContributorsCount (r:1 w:1) + /// Proof: Flow CampaignContributorsCount (max_values: None, max_size: Some(56), added: 2531, mode: MaxEncodedLen) + /// Storage: Tokens Accounts (r:1 w:1) + /// Proof: Tokens Accounts (max_values: None, max_size: Some(109), added: 2584, mode: MaxEncodedLen) + /// Storage: Flow CampaignBalance (r:1 w:1) + /// Proof: Flow CampaignBalance (max_values: None, max_size: Some(64), added: 2539, mode: MaxEncodedLen) fn contribute() -> Weight { - // Minimum execution time: 56_000 nanoseconds. - Weight::from_ref_time(58_000_000) - .saturating_add(RocksDbWeight::get().reads(6)) - .saturating_add(RocksDbWeight::get().writes(4)) + // Proof Size summary in bytes: + // Measured: `1104` + // Estimated: `15700` + // Minimum execution time: 48_000 nanoseconds. + Weight::from_parts(51_000_000, 15700) + .saturating_add(RocksDbWeight::get().reads(6_u64)) + .saturating_add(RocksDbWeight::get().writes(4_u64)) } - // Storage: Flow CampaignsByBlock (r:1 w:0) - // Storage: Flow CampaignStates (r:10 w:11) - // Storage: Flow CampaignFinalizationQueue (r:2 w:1) - // Storage: Tokens Accounts (r:1 w:1) - // Storage: Flow CampaignContribution (r:5 w:0) - // Storage: System Account (r:1 w:1) - // Storage: Flow CampaignBalance (r:0 w:1) + /// Storage: Flow CampaignsByBlock (r:1 w:0) + /// Proof: Flow CampaignsByBlock (max_values: None, max_size: Some(358), added: 2833, mode: MaxEncodedLen) + /// Storage: Flow CampaignStates (r:10 w:11) + /// Proof: Flow CampaignStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Flow CampaignFinalizationQueue (r:2 w:1) + /// Proof: Flow CampaignFinalizationQueue (max_values: None, max_size: Some(320511), added: 322986, mode: MaxEncodedLen) + /// Storage: Flow CampaignContribution (r:100 w:0) + /// Proof: Flow CampaignContribution (max_values: None, max_size: Some(112), added: 2587, mode: MaxEncodedLen) + /// Storage: Tokens Accounts (r:102 w:102) + /// Proof: Tokens Accounts (max_values: None, max_size: Some(109), added: 2584, mode: MaxEncodedLen) + /// Storage: System Account (r:1 w:1) + /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) + /// Storage: Flow CampaignBalance (r:0 w:1) + /// Proof: Flow CampaignBalance (max_values: None, max_size: Some(64), added: 2539, mode: MaxEncodedLen) /// The range of component `c` is `[0, 100]`. /// The range of component `p` is `[0, 10]`. fn on_initialize(c: u32, p: u32, ) -> Weight { - // Minimum execution time: 134_000 nanoseconds. - Weight::from_ref_time(68_040_945) - // Standard Error: 55_163 - .saturating_add(Weight::from_ref_time(25_455_935).saturating_mul(c.into())) - // Standard Error: 551_554 - .saturating_add(Weight::from_ref_time(9_852_261).saturating_mul(p.into())) - .saturating_add(RocksDbWeight::get().reads(5)) + // Proof Size summary in bytes: + // Measured: `1615 + c * (288 ±0) + p * (87 ±0)` + // Estimated: `655398 + c * (5182 ±0) + p * (2558 ±12)` + // Minimum execution time: 136_000 nanoseconds. + Weight::from_parts(62_296_021, 655398) + // Standard Error: 59_341 + .saturating_add(Weight::from_ref_time(25_969_615).saturating_mul(c.into())) + // Standard Error: 593_322 + .saturating_add(Weight::from_ref_time(10_250_535).saturating_mul(p.into())) + .saturating_add(RocksDbWeight::get().reads(5_u64)) .saturating_add(RocksDbWeight::get().reads((2_u64).saturating_mul(c.into()))) .saturating_add(RocksDbWeight::get().reads((1_u64).saturating_mul(p.into()))) - .saturating_add(RocksDbWeight::get().writes(5)) + .saturating_add(RocksDbWeight::get().writes(5_u64)) .saturating_add(RocksDbWeight::get().writes((1_u64).saturating_mul(c.into()))) .saturating_add(RocksDbWeight::get().writes((1_u64).saturating_mul(p.into()))) + .saturating_add(Weight::from_proof_size(5182).saturating_mul(c.into())) + .saturating_add(Weight::from_proof_size(2558).saturating_mul(p.into())) } } \ No newline at end of file diff --git a/sense/Cargo.toml b/sense/Cargo.toml index 0da91af93..4d408d69c 100755 --- a/sense/Cargo.toml +++ b/sense/Cargo.toml @@ -6,7 +6,7 @@ [package] name = "gamedao-sense" -version = "1.2.0" +version = "1.3.0" authors = ["zero.io","gamedao.co"] edition = "2018" license = "GPL-3.0-or-later" @@ -21,18 +21,18 @@ categories = [ [dependencies] serde = { version = "1.0.143", default-features = false } -codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] } +codec = { package = "parity-scale-codec", version = "3.2.2", default-features = false, features = ["derive"] } scale-info = { version = "2.1.1", default-features = false, features = ["derive"] } -sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36", default-features = false } -sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36", default-features = false } -frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36", default-features = false } -frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36", default-features = false } -frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36", default-features = false, optional = true } +sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38", default-features = false } +sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38", default-features = false } +frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38", default-features = false } +frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38", default-features = false } +frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38", default-features = false, optional = true } [dev-dependencies] -sp-io = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.36" } -sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.36" } -sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.36" } +sp-io = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.38" } +sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.38" } +sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.38" } [features] default = ["std"] diff --git a/sense/src/weights.rs b/sense/src/weights.rs index 6cb9c27c3..6e53933e1 100644 --- a/sense/src/weights.rs +++ b/sense/src/weights.rs @@ -2,7 +2,8 @@ //! Autogenerated weights for gamedao_sense //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-02-10, STEPS: `20`, REPEAT: 10, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2023-03-04, STEPS: `20`, REPEAT: `10`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! WORST CASE MAP SIZE: `1000000` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: None, DB CACHE: 1024 // Executed Command: @@ -33,42 +34,64 @@ pub trait WeightInfo { /// Weights for gamedao_sense using the Substrate node and recommended hardware. pub struct SubstrateWeight(PhantomData); impl WeightInfo for SubstrateWeight { - // Storage: Sense Entities (r:1 w:1) - // Storage: Sense EntityCount (r:1 w:1) - // Storage: Sense Properties (r:0 w:3) + /// Storage: Sense Entities (r:1 w:1) + /// Proof: Sense Entities (max_values: None, max_size: Some(170), added: 2645, mode: MaxEncodedLen) + /// Storage: Sense EntityCount (r:1 w:1) + /// Proof: Sense EntityCount (max_values: Some(1), max_size: Some(16), added: 511, mode: MaxEncodedLen) + /// Storage: Sense Properties (r:0 w:3) + /// Proof: Sense Properties (max_values: None, max_size: Some(77), added: 2552, mode: MaxEncodedLen) fn create_entity() -> Weight { - // Minimum execution time: 27_000 nanoseconds. - Weight::from_ref_time(29_000_000) - .saturating_add(T::DbWeight::get().reads(2)) - .saturating_add(T::DbWeight::get().writes(5)) + // Proof Size summary in bytes: + // Measured: `142` + // Estimated: `3156` + // Minimum execution time: 21_000 nanoseconds. + Weight::from_parts(22_000_000, 3156) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(5_u64)) } - // Storage: Sense Entities (r:1 w:0) - // Storage: Sense Properties (r:1 w:1) + /// Storage: Sense Entities (r:1 w:0) + /// Proof: Sense Entities (max_values: None, max_size: Some(170), added: 2645, mode: MaxEncodedLen) + /// Storage: Sense Properties (r:1 w:1) + /// Proof: Sense Properties (max_values: None, max_size: Some(77), added: 2552, mode: MaxEncodedLen) fn update_property() -> Weight { - // Minimum execution time: 25_000 nanoseconds. - Weight::from_ref_time(26_000_000) - .saturating_add(T::DbWeight::get().reads(2)) - .saturating_add(T::DbWeight::get().writes(1)) + // Proof Size summary in bytes: + // Measured: `452` + // Estimated: `5197` + // Minimum execution time: 20_000 nanoseconds. + Weight::from_parts(21_000_000, 5197) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) } } // For backwards compatibility and tests impl WeightInfo for () { - // Storage: Sense Entities (r:1 w:1) - // Storage: Sense EntityCount (r:1 w:1) - // Storage: Sense Properties (r:0 w:3) + /// Storage: Sense Entities (r:1 w:1) + /// Proof: Sense Entities (max_values: None, max_size: Some(170), added: 2645, mode: MaxEncodedLen) + /// Storage: Sense EntityCount (r:1 w:1) + /// Proof: Sense EntityCount (max_values: Some(1), max_size: Some(16), added: 511, mode: MaxEncodedLen) + /// Storage: Sense Properties (r:0 w:3) + /// Proof: Sense Properties (max_values: None, max_size: Some(77), added: 2552, mode: MaxEncodedLen) fn create_entity() -> Weight { - // Minimum execution time: 27_000 nanoseconds. - Weight::from_ref_time(29_000_000) - .saturating_add(RocksDbWeight::get().reads(2)) - .saturating_add(RocksDbWeight::get().writes(5)) + // Proof Size summary in bytes: + // Measured: `142` + // Estimated: `3156` + // Minimum execution time: 21_000 nanoseconds. + Weight::from_parts(22_000_000, 3156) + .saturating_add(RocksDbWeight::get().reads(2_u64)) + .saturating_add(RocksDbWeight::get().writes(5_u64)) } - // Storage: Sense Entities (r:1 w:0) - // Storage: Sense Properties (r:1 w:1) + /// Storage: Sense Entities (r:1 w:0) + /// Proof: Sense Entities (max_values: None, max_size: Some(170), added: 2645, mode: MaxEncodedLen) + /// Storage: Sense Properties (r:1 w:1) + /// Proof: Sense Properties (max_values: None, max_size: Some(77), added: 2552, mode: MaxEncodedLen) fn update_property() -> Weight { - // Minimum execution time: 25_000 nanoseconds. - Weight::from_ref_time(26_000_000) - .saturating_add(RocksDbWeight::get().reads(2)) - .saturating_add(RocksDbWeight::get().writes(1)) + // Proof Size summary in bytes: + // Measured: `452` + // Estimated: `5197` + // Minimum execution time: 20_000 nanoseconds. + Weight::from_parts(21_000_000, 5197) + .saturating_add(RocksDbWeight::get().reads(2_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) } } \ No newline at end of file diff --git a/signal/Cargo.toml b/signal/Cargo.toml index 08d0e594e..d5e1264c5 100644 --- a/signal/Cargo.toml +++ b/signal/Cargo.toml @@ -6,7 +6,7 @@ [package] name = "gamedao-signal" -version = "1.2.0" +version = "1.3.0" authors = ["zero.io","gamedao.co"] repository = "https://github.com/gamedaoco/gamedao-protocol" edition = "2018" @@ -22,26 +22,26 @@ categories = [ [dependencies] serde = { version = "1.0.143", default-features = false } -codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] } +codec = { package = "parity-scale-codec", version = "3.2.2", default-features = false, features = ["derive"] } scale-info = { version = "2.1.1", default-features = false, features = ["derive"] } -sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36", default-features = false } -sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36", default-features = false } -frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36", default-features = false } -frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36", default-features = false } -frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36", default-features = false, optional = true } -orml-traits = { git = 'https://github.com/open-web3-stack/open-runtime-module-library', branch= 'polkadot-v0.9.36', default-features = false } +sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38", default-features = false } +sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38", default-features = false } +frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38", default-features = false } +frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38", default-features = false } +frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38", default-features = false, optional = true } +orml-traits = { git = 'https://github.com/open-web3-stack/open-runtime-module-library', branch= "polkadot-v0.9.38", default-features = false } gamedao-traits = { package = "gamedao-traits", path = "../traits", default-features = false } -sp-io = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.36", default-features=false } +sp-io = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.38", default-features=false } [dev-dependencies] -sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.36" } -sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.36" } +sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.38" } +sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.38" } -pallet-balances = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } -pallet-timestamp = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } +pallet-balances = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } +pallet-timestamp = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } -orml-currencies = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.36", default-features = false } -orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.36", default-features = false } +orml-currencies = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.38", default-features = false } +orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.38", default-features = false } gamedao-control = { path = "../control", default-features = true } gamedao-flow = { path = "../flow", default-features = true } diff --git a/signal/src/weights.rs b/signal/src/weights.rs index 77e1a232f..03dd2aba9 100644 --- a/signal/src/weights.rs +++ b/signal/src/weights.rs @@ -2,7 +2,8 @@ //! Autogenerated weights for gamedao_signal //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-02-10, STEPS: `20`, REPEAT: 10, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2023-03-04, STEPS: `20`, REPEAT: `10`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! WORST CASE MAP SIZE: `1000000` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: None, DB CACHE: 1024 // Executed Command: @@ -34,94 +35,152 @@ pub trait WeightInfo { /// Weights for gamedao_signal using the Substrate node and recommended hardware. pub struct SubstrateWeight(PhantomData); impl WeightInfo for SubstrateWeight { - // Storage: Control OrgStates (r:1 w:0) - // Storage: Control MemberStates (r:1 w:0) - // Storage: Signal ProposalCount (r:1 w:1) - // Storage: Signal ProposalOf (r:1 w:1) - // Storage: Tokens Accounts (r:2 w:2) - // Storage: Control OrgTreasury (r:1 w:0) - // Storage: Signal ProposalsByBlock (r:2 w:2) - // Storage: Control OrgMemberCount (r:1 w:0) - // Storage: Signal ProposalVoting (r:0 w:1) - // Storage: Signal ProposalStates (r:0 w:1) + /// Storage: Control OrgStates (r:1 w:0) + /// Proof: Control OrgStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Control MemberStates (r:1 w:0) + /// Proof: Control MemberStates (max_values: None, max_size: Some(97), added: 2572, mode: MaxEncodedLen) + /// Storage: Signal ProposalCount (r:1 w:1) + /// Proof: Signal ProposalCount (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) + /// Storage: Signal ProposalOf (r:1 w:1) + /// Proof: Signal ProposalOf (max_values: None, max_size: Some(363), added: 2838, mode: MaxEncodedLen) + /// Storage: Tokens Accounts (r:2 w:2) + /// Proof: Tokens Accounts (max_values: None, max_size: Some(109), added: 2584, mode: MaxEncodedLen) + /// Storage: Control OrgTreasury (r:1 w:0) + /// Proof: Control OrgTreasury (max_values: None, max_size: Some(80), added: 2555, mode: MaxEncodedLen) + /// Storage: Signal ProposalsByBlock (r:2 w:2) + /// Proof: Signal ProposalsByBlock (max_values: None, max_size: Some(3239), added: 5714, mode: MaxEncodedLen) + /// Storage: Control OrgMemberCount (r:1 w:0) + /// Proof: Control OrgMemberCount (max_values: None, max_size: Some(52), added: 2527, mode: MaxEncodedLen) + /// Storage: Signal ProposalVoting (r:0 w:1) + /// Proof: Signal ProposalVoting (max_values: None, max_size: Some(130112), added: 132587, mode: MaxEncodedLen) + /// Storage: Signal ProposalStates (r:0 w:1) + /// Proof: Signal ProposalStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) fn proposal() -> Weight { - // Minimum execution time: 90_000 nanoseconds. - Weight::from_ref_time(94_000_000) - .saturating_add(T::DbWeight::get().reads(10)) - .saturating_add(T::DbWeight::get().writes(8)) + // Proof Size summary in bytes: + // Measured: `1390` + // Estimated: `30111` + // Minimum execution time: 82_000 nanoseconds. + Weight::from_parts(82_000_000, 30111) + .saturating_add(T::DbWeight::get().reads(10_u64)) + .saturating_add(T::DbWeight::get().writes(8_u64)) } - // Storage: Signal ProposalVoting (r:1 w:1) - // Storage: Signal ProposalOf (r:1 w:0) - // Storage: Control MemberStates (r:1 w:0) - // Storage: Signal ProposalStates (r:1 w:1) - // Storage: Control OrgTreasury (r:1 w:0) - // Storage: Tokens Accounts (r:3 w:3) - // Storage: System Account (r:1 w:1) + /// Storage: Signal ProposalVoting (r:1 w:1) + /// Proof: Signal ProposalVoting (max_values: None, max_size: Some(130112), added: 132587, mode: MaxEncodedLen) + /// Storage: Signal ProposalOf (r:1 w:0) + /// Proof: Signal ProposalOf (max_values: None, max_size: Some(363), added: 2838, mode: MaxEncodedLen) + /// Storage: Control MemberStates (r:1 w:0) + /// Proof: Control MemberStates (max_values: None, max_size: Some(97), added: 2572, mode: MaxEncodedLen) + /// Storage: Signal ProposalStates (r:1 w:1) + /// Proof: Signal ProposalStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Control OrgTreasury (r:1 w:0) + /// Proof: Control OrgTreasury (max_values: None, max_size: Some(80), added: 2555, mode: MaxEncodedLen) + /// Storage: Tokens Accounts (r:3 w:3) + /// Proof: Tokens Accounts (max_values: None, max_size: Some(109), added: 2584, mode: MaxEncodedLen) + /// Storage: System Account (r:1 w:1) + /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) /// The range of component `m` is `[0, 1000]`. fn vote(m: u32, ) -> Weight { - // Minimum execution time: 107_000 nanoseconds. - Weight::from_ref_time(113_880_549) - // Standard Error: 3_532 - .saturating_add(Weight::from_ref_time(148_088).saturating_mul(m.into())) - .saturating_add(T::DbWeight::get().reads(9)) - .saturating_add(T::DbWeight::get().writes(6)) + // Proof Size summary in bytes: + // Measured: `3941 + m * (51 ±0)` + // Estimated: `153431` + // Minimum execution time: 99_000 nanoseconds. + Weight::from_parts(94_755_596, 153431) + // Standard Error: 2_268 + .saturating_add(Weight::from_ref_time(112_356).saturating_mul(m.into())) + .saturating_add(T::DbWeight::get().reads(9_u64)) + .saturating_add(T::DbWeight::get().writes(6_u64)) } - // Storage: Signal ProposalsByBlock (r:1 w:0) - // Storage: Signal ProposalStates (r:5 w:0) + /// Storage: Signal ProposalsByBlock (r:1 w:0) + /// Proof: Signal ProposalsByBlock (max_values: None, max_size: Some(3239), added: 5714, mode: MaxEncodedLen) + /// Storage: Signal ProposalStates (r:100 w:0) + /// Proof: Signal ProposalStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) /// The range of component `p` is `[0, 100]`. fn on_initialize(p: u32, ) -> Weight { - // Minimum execution time: 5_000 nanoseconds. - Weight::from_ref_time(9_260_770) - // Standard Error: 7_634 - .saturating_add(Weight::from_ref_time(2_838_161).saturating_mul(p.into())) - .saturating_add(T::DbWeight::get().reads(1)) + // Proof Size summary in bytes: + // Measured: `394 + p * (86 ±0)` + // Estimated: `5714 + p * (2524 ±0)` + // Minimum execution time: 3_000 nanoseconds. + Weight::from_parts(3_033_538, 5714) + // Standard Error: 21_933 + .saturating_add(Weight::from_ref_time(3_051_963).saturating_mul(p.into())) + .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(p.into()))) + .saturating_add(Weight::from_proof_size(2524).saturating_mul(p.into())) } } // For backwards compatibility and tests impl WeightInfo for () { - // Storage: Control OrgStates (r:1 w:0) - // Storage: Control MemberStates (r:1 w:0) - // Storage: Signal ProposalCount (r:1 w:1) - // Storage: Signal ProposalOf (r:1 w:1) - // Storage: Tokens Accounts (r:2 w:2) - // Storage: Control OrgTreasury (r:1 w:0) - // Storage: Signal ProposalsByBlock (r:2 w:2) - // Storage: Control OrgMemberCount (r:1 w:0) - // Storage: Signal ProposalVoting (r:0 w:1) - // Storage: Signal ProposalStates (r:0 w:1) + /// Storage: Control OrgStates (r:1 w:0) + /// Proof: Control OrgStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Control MemberStates (r:1 w:0) + /// Proof: Control MemberStates (max_values: None, max_size: Some(97), added: 2572, mode: MaxEncodedLen) + /// Storage: Signal ProposalCount (r:1 w:1) + /// Proof: Signal ProposalCount (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) + /// Storage: Signal ProposalOf (r:1 w:1) + /// Proof: Signal ProposalOf (max_values: None, max_size: Some(363), added: 2838, mode: MaxEncodedLen) + /// Storage: Tokens Accounts (r:2 w:2) + /// Proof: Tokens Accounts (max_values: None, max_size: Some(109), added: 2584, mode: MaxEncodedLen) + /// Storage: Control OrgTreasury (r:1 w:0) + /// Proof: Control OrgTreasury (max_values: None, max_size: Some(80), added: 2555, mode: MaxEncodedLen) + /// Storage: Signal ProposalsByBlock (r:2 w:2) + /// Proof: Signal ProposalsByBlock (max_values: None, max_size: Some(3239), added: 5714, mode: MaxEncodedLen) + /// Storage: Control OrgMemberCount (r:1 w:0) + /// Proof: Control OrgMemberCount (max_values: None, max_size: Some(52), added: 2527, mode: MaxEncodedLen) + /// Storage: Signal ProposalVoting (r:0 w:1) + /// Proof: Signal ProposalVoting (max_values: None, max_size: Some(130112), added: 132587, mode: MaxEncodedLen) + /// Storage: Signal ProposalStates (r:0 w:1) + /// Proof: Signal ProposalStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) fn proposal() -> Weight { - // Minimum execution time: 90_000 nanoseconds. - Weight::from_ref_time(94_000_000) - .saturating_add(RocksDbWeight::get().reads(10)) - .saturating_add(RocksDbWeight::get().writes(8)) + // Proof Size summary in bytes: + // Measured: `1390` + // Estimated: `30111` + // Minimum execution time: 82_000 nanoseconds. + Weight::from_parts(82_000_000, 30111) + .saturating_add(RocksDbWeight::get().reads(10_u64)) + .saturating_add(RocksDbWeight::get().writes(8_u64)) } - // Storage: Signal ProposalVoting (r:1 w:1) - // Storage: Signal ProposalOf (r:1 w:0) - // Storage: Control MemberStates (r:1 w:0) - // Storage: Signal ProposalStates (r:1 w:1) - // Storage: Control OrgTreasury (r:1 w:0) - // Storage: Tokens Accounts (r:3 w:3) - // Storage: System Account (r:1 w:1) + /// Storage: Signal ProposalVoting (r:1 w:1) + /// Proof: Signal ProposalVoting (max_values: None, max_size: Some(130112), added: 132587, mode: MaxEncodedLen) + /// Storage: Signal ProposalOf (r:1 w:0) + /// Proof: Signal ProposalOf (max_values: None, max_size: Some(363), added: 2838, mode: MaxEncodedLen) + /// Storage: Control MemberStates (r:1 w:0) + /// Proof: Control MemberStates (max_values: None, max_size: Some(97), added: 2572, mode: MaxEncodedLen) + /// Storage: Signal ProposalStates (r:1 w:1) + /// Proof: Signal ProposalStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Control OrgTreasury (r:1 w:0) + /// Proof: Control OrgTreasury (max_values: None, max_size: Some(80), added: 2555, mode: MaxEncodedLen) + /// Storage: Tokens Accounts (r:3 w:3) + /// Proof: Tokens Accounts (max_values: None, max_size: Some(109), added: 2584, mode: MaxEncodedLen) + /// Storage: System Account (r:1 w:1) + /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) /// The range of component `m` is `[0, 1000]`. fn vote(m: u32, ) -> Weight { - // Minimum execution time: 107_000 nanoseconds. - Weight::from_ref_time(113_880_549) - // Standard Error: 3_532 - .saturating_add(Weight::from_ref_time(148_088).saturating_mul(m.into())) - .saturating_add(RocksDbWeight::get().reads(9)) - .saturating_add(RocksDbWeight::get().writes(6)) + // Proof Size summary in bytes: + // Measured: `3941 + m * (51 ±0)` + // Estimated: `153431` + // Minimum execution time: 99_000 nanoseconds. + Weight::from_parts(94_755_596, 153431) + // Standard Error: 2_268 + .saturating_add(Weight::from_ref_time(112_356).saturating_mul(m.into())) + .saturating_add(RocksDbWeight::get().reads(9_u64)) + .saturating_add(RocksDbWeight::get().writes(6_u64)) } - // Storage: Signal ProposalsByBlock (r:1 w:0) - // Storage: Signal ProposalStates (r:5 w:0) + /// Storage: Signal ProposalsByBlock (r:1 w:0) + /// Proof: Signal ProposalsByBlock (max_values: None, max_size: Some(3239), added: 5714, mode: MaxEncodedLen) + /// Storage: Signal ProposalStates (r:100 w:0) + /// Proof: Signal ProposalStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) /// The range of component `p` is `[0, 100]`. fn on_initialize(p: u32, ) -> Weight { - // Minimum execution time: 5_000 nanoseconds. - Weight::from_ref_time(9_260_770) - // Standard Error: 7_634 - .saturating_add(Weight::from_ref_time(2_838_161).saturating_mul(p.into())) - .saturating_add(RocksDbWeight::get().reads(1)) + // Proof Size summary in bytes: + // Measured: `394 + p * (86 ±0)` + // Estimated: `5714 + p * (2524 ±0)` + // Minimum execution time: 3_000 nanoseconds. + Weight::from_parts(3_033_538, 5714) + // Standard Error: 21_933 + .saturating_add(Weight::from_ref_time(3_051_963).saturating_mul(p.into())) + .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().reads((1_u64).saturating_mul(p.into()))) + .saturating_add(Weight::from_proof_size(2524).saturating_mul(p.into())) } } \ No newline at end of file diff --git a/traits/Cargo.toml b/traits/Cargo.toml index ac03a6508..819182e95 100644 --- a/traits/Cargo.toml +++ b/traits/Cargo.toml @@ -6,7 +6,7 @@ [package] name = "gamedao-traits" -version = "1.2.0" +version = "1.3.0" authors = ["zero.io","gamedao.co"] edition = "2018" license = "GPL-3.0-or-later" @@ -15,12 +15,12 @@ repository = "https://github.com/gamedaoco/gamedao-protocol" [dependencies] -serde = { version = "1.0.124", default-features = false } -codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] } -scale-info = { version = "2.0.1", default-features = false, features = ["derive"] } -frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36", default-features = false } -frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36", default-features = false, optional = true } -sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36", default-features = false } +serde = { version = "1.0.143", default-features = false } +codec = { package = "parity-scale-codec", version = "3.2.2", default-features = false, features = ["derive"] } +scale-info = { version = "2.1.1", default-features = false, features = ["derive"] } +frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38", default-features = false } +frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38", default-features = false, optional = true } +sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38", default-features = false } [features] default = ["std"] From ac9e413b28065ac398d051f5907224b858d60739 Mon Sep 17 00:00:00 2001 From: Vasylenko Yevhen Date: Thu, 9 Mar 2023 14:11:06 +0200 Subject: [PATCH 37/49] Revert "feat: bump substrate version from 0.9.36 to 0.9.38 (#141)" (#144) This reverts commit d084aca04b7af146c2b557bb8ab8a167507beec4. --- battlepass/Cargo.toml | 38 +- battlepass/src/benchmarking.rs | 4 +- battlepass/src/lib.rs | 64 ++- battlepass/src/tests.rs | 72 ++- battlepass/src/weights.rs | 879 ++++++++++++--------------------- control/Cargo.toml | 34 +- control/src/weights.rs | 387 ++++++--------- flow/Cargo.toml | 28 +- flow/src/weights.rs | 209 +++----- sense/Cargo.toml | 20 +- sense/src/weights.rs | 77 +-- signal/Cargo.toml | 30 +- signal/src/weights.rs | 197 +++----- traits/Cargo.toml | 14 +- 14 files changed, 774 insertions(+), 1279 deletions(-) diff --git a/battlepass/Cargo.toml b/battlepass/Cargo.toml index 123748318..72d4322a0 100644 --- a/battlepass/Cargo.toml +++ b/battlepass/Cargo.toml @@ -5,7 +5,7 @@ # ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ [package] name = "gamedao-battlepass" -version = "1.3.0" +version = "1.2.0" authors = ["zero.io","gamedao.co"] repository = "https://github.com/gamedaoco/gamedao-protocol" edition = "2018" @@ -14,33 +14,33 @@ description = "BattlePass pallet provides functionality to create, manage and pa [dependencies] serde = { version = "1.0.143", default-features = false } -codec = { package = "parity-scale-codec", version = "3.2.2", default-features = false, features = ["derive"] } +codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] } scale-info = { version = "2.1.1", default-features = false, features = ["derive"] } -sp-core = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } -sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } -sp-std = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } -sp-storage = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } -sp-io = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.38", default-features=false } -frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38", default-features = false } -frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38", default-features = false } -frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38", default-features = false, optional = true } +sp-core = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } +sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } +sp-std = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } +sp-storage = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } +sp-io = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.36", default-features=false } +frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36", default-features = false } +frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36", default-features = false } +frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36", default-features = false, optional = true } -pallet-uniques = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } +pallet-uniques = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } -orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.38", default-features = false } +orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.36", default-features = false } gamedao-control = { package = "gamedao-control", path = "../control", default-features = false } gamedao-traits = { package = "gamedao-traits", path = "../traits", default-features = false } [dev-dependencies] -sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.38" } -codec = { package = "parity-scale-codec", version = "3.2.2", default-features = false, features = ["derive"] } +sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.36" } +codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] } -pallet-balances = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } -pallet-uniques = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } -orml-currencies = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.38", default-features = false } -orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.38", default-features = false } -orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.38", default-features = false } +pallet-balances = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } +pallet-uniques = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } +orml-currencies = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.36", default-features = false } +orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.36", default-features = false } +orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.36", default-features = false } [features] default = ['std'] diff --git a/battlepass/src/benchmarking.rs b/battlepass/src/benchmarking.rs index 1ad896b44..27c34531f 100644 --- a/battlepass/src/benchmarking.rs +++ b/battlepass/src/benchmarking.rs @@ -124,9 +124,7 @@ benchmarks! { set_bot::(caller.clone(), battlepass_id, bot.clone()); }: _(RawOrigin::Signed(bot), battlepass_id, caller.clone()) verify { - let collection_id = T::BattlepassHelper::collection(0); - let item_id = T::BattlepassHelper::item(0); - assert!( as InspectEnumerable>::items(&collection_id).any(|x| x == item_id)); + assert!(ClaimedBattlepasses::::get(battlepass_id, caller).is_some()); } activate_battlepass { diff --git a/battlepass/src/lib.rs b/battlepass/src/lib.rs index 34b9d5a73..454031870 100644 --- a/battlepass/src/lib.rs +++ b/battlepass/src/lib.rs @@ -14,7 +14,7 @@ pub use pallet::*; use frame_support::{pallet_prelude::*, transactional, dispatch::RawOrigin}; -use frame_support::traits::tokens::nonfungibles::InspectEnumerable; +use frame_support::traits::tokens::nonfungibles::Inspect; use frame_system::pallet_prelude::*; use sp_std::convert::TryInto; use sp_runtime::traits::{AtLeast32BitUnsigned, Hash}; @@ -94,7 +94,7 @@ pub mod pallet { type BattlepassHelper: BattlepassHelper; - /// The maximum length of a name, cid strings stored on-chain. + /// The maximum length of a name, cid or metadata strings stored on-chain. #[pallet::constant] type StringLimit: Get; @@ -212,17 +212,20 @@ pub mod pallet { AuthorizationError, CollectionUnknown, BattlepassExists, - BattlepassOwnershipExists, - BattlepassOwnershipDoesntExist, + BattlepassClaimed, + BattlepassNotClaimed, BattlepassUnknown, BattlepassStateUnknown, BattlepassStateWrong, BattlepassInfoUnknown, + BattlepassNftUnknown, + BattlepassNftInvalid, LevelNotReached, LevelUnknown, NoAvailableCollectionId, NoAvailableNftId, NoChangesProvided, + NotOwnNft, OrgPrimeUnknown, OrgUnknownOrInactive, RewardClaimed, @@ -251,6 +254,18 @@ pub mod pallet { #[pallet::storage] pub type BattlepassInfoByOrg = StorageMap<_, Blake2_128Concat, T::Hash, BattlepassInfo, OptionQuery>; + /// Claimed Battlepass-NFT by user and battlepass. + /// + /// ClaimedBattlepasses: map (Hash, AccountId) => ItemId + #[pallet::storage] + #[pallet::getter(fn get_claimed_battlepass)] + pub(super) type ClaimedBattlepasses = StorageDoubleMap<_, + Blake2_128Concat, T::Hash, + Blake2_128Concat, T::AccountId, + T::ItemId, + OptionQuery + >; + /// Total earned Points for users per each Battlepass. /// /// Points: map (Hash, AccountId) => u32 @@ -346,7 +361,7 @@ pub mod pallet { let new_season = battlepass_count + 1; // Create a collection to store Battlepass NFTs - let collection_id = Self::create_collection(creator.clone(), None, cid.clone())?; + let collection_id = Self::create_collection(creator.clone(), None)?; let battlepass_id = Self::do_create_battlepass(creator, org_id, name, cid, collection_id, price, new_season)?; Self::deposit_event(Event::BattlepassCreated { org_id, battlepass_id, season: new_season }); @@ -420,17 +435,15 @@ pub mod pallet { // check if Battlepass in ACTIVE state ensure!(Self::check_battlepass_state(battlepass_id, BattlepassState::ACTIVE)?, Error::::BattlepassStateWrong); // check if Org is active - let org_id = battlepass.org_id.clone(); - ensure!(T::Control::is_org_active(&org_id), Error::::OrgUnknownOrInactive); + ensure!(T::Control::is_org_active(&battlepass.org_id), Error::::OrgUnknownOrInactive); // check permissions (prime, bot) - ensure!(Self::is_prime_or_bot(&org_id, by_who.clone())?, Error::::AuthorizationError); - // check if user has access to Battlepass - ensure!(!Self::has_battlepass_ownership(for_who.clone(), battlepass.collection_id), Error::::BattlepassOwnershipExists); - + ensure!(Self::is_prime_or_bot(&battlepass.org_id, by_who.clone())?, Error::::AuthorizationError); + // check if Battlepass already claimed + ensure!(!ClaimedBattlepasses::::contains_key(battlepass_id, for_who.clone()), Error::::BattlepassClaimed); let nft_id = Self::do_claim_battlepass(battlepass.creator.clone(), for_who.clone(), battlepass_id, battlepass.collection_id)?; - Self::deposit_event(Event::BattlepassClaimed { by_who, for_who, org_id, battlepass_id, nft_id }); + Self::deposit_event(Event::BattlepassClaimed { by_who, for_who, org_id: battlepass.org_id, battlepass_id, nft_id }); Ok(()) } @@ -524,7 +537,7 @@ pub mod pallet { // check permissions (prime, bot) ensure!(Self::is_prime_or_bot(&battlepass.org_id, sender.clone())?, Error::::AuthorizationError); // check if user has access to Battlepass - ensure!(Self::has_battlepass_ownership(account.clone(), battlepass.collection_id), Error::::BattlepassOwnershipDoesntExist); + Self::validate_battlepass_ownership(account.clone(), battlepass_id, battlepass)?; Points::::insert(battlepass_id, &account, amount); @@ -567,7 +580,7 @@ pub mod pallet { ensure!(Self::is_prime_or_bot(&battlepass.org_id, caller)?, Error::::AuthorizationError); let prime = T::Control::org_prime_account(&battlepass.org_id).ok_or(Error::::OrgPrimeUnknown)?; - let collection_id = Self::create_collection(prime, max, cid.clone())?; + let collection_id = Self::create_collection(prime, max)?; let reward_id = Self::do_create_reward(battlepass_id, name, cid, level, transferable, collection_id)?; Self::deposit_event(Event::RewardCreated { reward_id, battlepass_id, level }); @@ -690,7 +703,7 @@ pub mod pallet { // check permissions (self, prime or bot) ensure!(by_who == for_who || Self::is_prime_or_bot(&battlepass.org_id, by_who.clone())?, Error::::AuthorizationError); // check if user has access to Battlepass - ensure!(Self::has_battlepass_ownership(for_who.clone(), battlepass.collection_id), Error::::BattlepassOwnershipDoesntExist); + Self::validate_battlepass_ownership(for_who.clone(), reward.battlepass_id, battlepass)?; // check if user has reached the required Level ensure!(Self::is_level_reached(&reward.battlepass_id, &for_who, reward.level), Error::::LevelNotReached); @@ -858,8 +871,8 @@ impl Pallet { }) } - fn create_collection(owner: T::AccountId, max: Option, cid: String) -> Result { - let metadata = BoundedVec::truncate_from(cid.into()); + fn create_collection(owner: T::AccountId, max: Option) -> Result { + let metadata = BoundedVec::truncate_from(b"meta".to_vec()); // TODO: what should be here? let collection_index = Self::bump_collection_index()?; let collection_id = T::BattlepassHelper::collection(collection_index); let origin = OriginFor::::from(RawOrigin::Signed(owner.clone())); @@ -953,6 +966,8 @@ impl Pallet { // Create Battlepass NFT Self::create_nft(creator, for_who.clone(), collection_id, nft_id, metadata)?; + + ClaimedBattlepasses::::insert(battlepass_id, &for_who, nft_id); Ok(nft_id) } @@ -1003,8 +1018,17 @@ impl Pallet { Ok(nft_id) } - fn has_battlepass_ownership(account: T::AccountId, bp_collection_id: T::CollectionId) -> bool { - let bp_owned_count = as InspectEnumerable>::owned_in_collection(&bp_collection_id, &account).count(); - bp_owned_count > 0 + fn validate_battlepass_ownership(account: T::AccountId, battlepass_id: T::Hash, battlepass: Battlepass, T::CollectionId>) -> DispatchResult { + // check if user claimed Battlepass NFT + let bp_nft_id = Self::get_claimed_battlepass(battlepass_id, &account).ok_or(Error::::BattlepassNotClaimed)?; + // check if Battlepass NFT exists + let bp_nft_owner = pallet_uniques::Pallet::::owner(battlepass.collection_id, bp_nft_id).ok_or(Error::::BattlepassNftUnknown)?; + // validate Battlepass NFT ownership + ensure!(account.clone() == bp_nft_owner, Error::::NotOwnNft); + // validate Battlepass NFT metadata + let bp_nft_metadata = as Inspect>::attribute(&battlepass.collection_id, &bp_nft_id, &[]); + ensure!(Some(battlepass_id.encode()) == bp_nft_metadata, Error::::BattlepassNftInvalid); + + Ok(()) } } diff --git a/battlepass/src/tests.rs b/battlepass/src/tests.rs index 59297b7f4..298a877d4 100644 --- a/battlepass/src/tests.rs +++ b/battlepass/src/tests.rs @@ -1,7 +1,7 @@ #![cfg(test)] use frame_support::{assert_noop, assert_ok}; -use frame_support::traits::tokens::nonfungibles::{Inspect, InspectEnumerable, Mutate, Transfer}; +use frame_support::traits::tokens::nonfungibles::{InspectEnumerable, Mutate, Transfer}; use sp_core::H256; use crate::mock::{ @@ -455,7 +455,6 @@ fn claim_battlepass_test() { let not_creator_2 = TOM; let not_creator_3 = 22u32; let not_member = EVA; - let not_member_2 = 40; add_member(org_id, not_creator); add_member(org_id, not_creator_2); add_member(org_id, not_creator_3); @@ -512,32 +511,17 @@ fn claim_battlepass_test() { assert_ok!( Battlepass::claim_battlepass(Origin::signed(creator), battlepass_id, not_creator) ); + // Check if ClaimedBattlepasses record created + let nft_id = ClaimedBattlepasses::::get(battlepass_id, not_creator); + assert_eq!(nft_id.is_some(), true); + assert_eq!(nft_id.unwrap(), 0); // Check if NFT minted assert_eq!(>::items(&0).any(|x| x == 0) , true); // Should not claim if it was already claimed assert_noop!( Battlepass::claim_battlepass(Origin::signed(creator), battlepass_id, not_creator), - Error::::BattlepassOwnershipExists - ); - - // Should claim again after transferring Battlepass NFT to someone else - assert_ok!( - Uniques::thaw_collection(Origin::signed(creator), 0) - ); - assert_ok!( - >::transfer(&0, &0, ¬_member_2) - ); - assert_ok!( - Battlepass::claim_battlepass(Origin::signed(creator), battlepass_id, not_creator) - ); - // Check if NFT minted - assert_eq!(>::items(&0).any(|x| x == 1) , true); - - // Should not claim if user received Battlepass NFT from someone else - assert_noop!( - Battlepass::claim_battlepass(Origin::signed(creator), battlepass_id, not_member_2), - Error::::BattlepassOwnershipExists + Error::::BattlepassClaimed ); // Should claim for others by Bot @@ -547,8 +531,12 @@ fn claim_battlepass_test() { assert_ok!( Battlepass::claim_battlepass(Origin::signed(BOT), battlepass_id, not_creator_3) ); + // Check if ClaimedBattlepasses record created + let nft_id = ClaimedBattlepasses::::get(battlepass_id, not_creator_3); + assert_eq!(nft_id.is_some(), true); + assert_eq!(nft_id.unwrap(), 1); // Check if NFT minted - assert_eq!(>::items(&0).any(|x| x == 2) , true); + assert_eq!(>::items(&0).any(|x| x == 1) , true); // Should claim for accounts outside of org assert_ok!( @@ -627,7 +615,7 @@ fn set_points_test() { // Should not set if user does not have access to Battlepass assert_noop!( Battlepass::set_points(Origin::signed(creator), battlepass_id, not_member, 10), - Error::::BattlepassOwnershipDoesntExist + Error::::BattlepassNotClaimed ); // Should set points by Prime @@ -994,7 +982,6 @@ fn claim_reward_test() { let not_creator_3 = 30; let not_creator_4 = 31; let not_member = EVA; - let not_member_2 = 40; add_member(org_id, not_creator); add_member(org_id, not_creator_2); add_member(org_id, not_creator_3); @@ -1069,7 +1056,7 @@ fn claim_reward_test() { // Should not claim Reward if user didn't claim Battlepass assert_noop!( Battlepass::claim_reward(Origin::signed(not_creator), reward_id, not_creator), - Error::::BattlepassOwnershipDoesntExist + Error::::BattlepassNotClaimed ); // Should not claim Reward if no NFT for claimed Battlepass @@ -1081,7 +1068,7 @@ fn claim_reward_test() { ); assert_noop!( Battlepass::claim_reward(Origin::signed(not_creator), reward_id, not_creator), - Error::::BattlepassOwnershipDoesntExist + Error::::BattlepassNftUnknown ); // Should not claim Reward if user lost ownership of Battlepass NFT @@ -1092,11 +1079,24 @@ fn claim_reward_test() { Uniques::thaw_collection(Origin::signed(creator), 0) ); assert_ok!( - >::transfer(&0, &1, ¬_member_2) + >::transfer(&0, &1, ¬_member) ); assert_noop!( Battlepass::claim_reward(Origin::signed(creator), reward_id, creator), - Error::::BattlepassOwnershipDoesntExist + Error::::NotOwnNft + ); + + // Should not claim Reward if Battlepass NFT is not valid + assert_ok!( + Battlepass::claim_battlepass(Origin::signed(creator), battlepass_id, not_creator_2) + ); + let new_metadata = BoundedVec::truncate_from(b"crap".to_vec()); + assert_ok!( + Uniques::set_metadata(Origin::signed(creator), 0, 2, new_metadata, false) + ); + assert_noop!( + Battlepass::claim_reward(Origin::signed(not_creator_2), reward_id, not_creator_2), + Error::::BattlepassNftInvalid ); // Should not claim if user's level is too low @@ -1127,6 +1127,9 @@ fn claim_reward_test() { Error::::RewardClaimed ); + // Should claim Reward after receiving Battlepass NFT from elsewhere + // TODO: need to 'apply' the received Battlepass NFT so it will appear in ClaimedBattlepasses + // Should not claim if max limit reached assert_ok!( Battlepass::claim_battlepass(Origin::signed(creator), battlepass_id, not_creator_4) @@ -1164,17 +1167,6 @@ fn claim_reward_test() { // Check if Reward claimed assert_eq!(ClaimedRewards::::contains_key(reward_id, not_member), true); - // Should claim Reward after receiving Battlepass NFT from elsewhere - let reward_id = create_reward(battlepass_id); - assert_ok!( - Battlepass::set_points(Origin::signed(creator), battlepass_id, not_member_2, 10) - ); - assert_ok!( - Battlepass::claim_reward(Origin::signed(not_member_2), reward_id, not_member_2) - ); - // Check if Reward claimed - assert_eq!(ClaimedRewards::::contains_key(reward_id, not_member_2), true); - // Should not claim if Battlepass state is ENDED assert_ok!( Battlepass::conclude_battlepass(Origin::signed(creator), battlepass_id) diff --git a/battlepass/src/weights.rs b/battlepass/src/weights.rs index 2504abe43..865bd335c 100644 --- a/battlepass/src/weights.rs +++ b/battlepass/src/weights.rs @@ -2,8 +2,7 @@ //! Autogenerated weights for gamedao_battlepass //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-03-06, STEPS: `20`, REPEAT: `10`, LOW RANGE: `[]`, HIGH RANGE: `[]` -//! WORST CASE MAP SIZE: `1000000` +//! DATE: 2023-02-28, STEPS: `20`, REPEAT: 10, LOW RANGE: `[]`, HIGH RANGE: `[]` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: None, DB CACHE: 1024 // Executed Command: @@ -45,630 +44,366 @@ pub trait WeightInfo { /// Weights for gamedao_battlepass using the Substrate node and recommended hardware. pub struct SubstrateWeight(PhantomData); impl WeightInfo for SubstrateWeight { - /// Storage: Control OrgStates (r:1 w:0) - /// Proof: Control OrgStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) - /// Storage: Control Orgs (r:1 w:0) - /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) - /// Storage: Battlepass BattlepassInfoByOrg (r:1 w:1) - /// Proof: Battlepass BattlepassInfoByOrg (max_values: None, max_size: Some(118), added: 2593, mode: MaxEncodedLen) - /// Storage: Battlepass CollectionIndex (r:1 w:1) - /// Proof: Battlepass CollectionIndex (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: Uniques ClassMetadataOf (r:1 w:1) - /// Proof: Uniques ClassMetadataOf (max_values: None, max_size: Some(167), added: 2642, mode: MaxEncodedLen) - /// Storage: Uniques ClassAccount (r:0 w:1) - /// Proof: Uniques ClassAccount (max_values: None, max_size: Some(68), added: 2543, mode: MaxEncodedLen) - /// Storage: Battlepass BattlepassStates (r:0 w:1) - /// Proof: Battlepass BattlepassStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) - /// Storage: Battlepass Battlepasses (r:0 w:1) - /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(382), added: 2857, mode: MaxEncodedLen) + // Storage: Control OrgStates (r:1 w:0) + // Storage: Control Orgs (r:1 w:0) + // Storage: Battlepass BattlepassInfoByOrg (r:1 w:1) + // Storage: Battlepass CollectionIndex (r:1 w:1) + // Storage: Uniques Class (r:1 w:1) + // Storage: Uniques ClassMetadataOf (r:1 w:1) + // Storage: Uniques ClassAccount (r:0 w:1) + // Storage: Battlepass BattlepassStates (r:0 w:1) + // Storage: Battlepass Battlepasses (r:0 w:1) fn create_battlepass() -> Weight { - // Proof Size summary in bytes: - // Measured: `597` - // Estimated: `13676` - // Minimum execution time: 86_000 nanoseconds. - Weight::from_parts(86_000_000, 13676) - .saturating_add(T::DbWeight::get().reads(6_u64)) - .saturating_add(T::DbWeight::get().writes(7_u64)) + // Minimum execution time: 93_000 nanoseconds. + Weight::from_ref_time(95_000_000) + .saturating_add(T::DbWeight::get().reads(6)) + .saturating_add(T::DbWeight::get().writes(7)) } - /// Storage: Battlepass Battlepasses (r:1 w:1) - /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(382), added: 2857, mode: MaxEncodedLen) - /// Storage: Battlepass BattlepassStates (r:1 w:0) - /// Proof: Battlepass BattlepassStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) - /// Storage: Control OrgStates (r:1 w:0) - /// Proof: Control OrgStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) - /// Storage: Control Orgs (r:1 w:0) - /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) + // Storage: Battlepass Battlepasses (r:1 w:1) + // Storage: Battlepass BattlepassStates (r:1 w:0) + // Storage: Control OrgStates (r:1 w:0) + // Storage: Control Orgs (r:1 w:0) fn update_battlepass() -> Weight { - // Proof Size summary in bytes: - // Measured: `837` - // Estimated: `10670` - // Minimum execution time: 29_000 nanoseconds. - Weight::from_parts(30_000_000, 10670) - .saturating_add(T::DbWeight::get().reads(4_u64)) - .saturating_add(T::DbWeight::get().writes(1_u64)) + // Minimum execution time: 35_000 nanoseconds. + Weight::from_ref_time(36_000_000) + .saturating_add(T::DbWeight::get().reads(4)) + .saturating_add(T::DbWeight::get().writes(1)) } - /// Storage: Battlepass Battlepasses (r:1 w:0) - /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(382), added: 2857, mode: MaxEncodedLen) - /// Storage: Battlepass BattlepassStates (r:1 w:0) - /// Proof: Battlepass BattlepassStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) - /// Storage: Control OrgStates (r:1 w:0) - /// Proof: Control OrgStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) - /// Storage: Control Orgs (r:1 w:0) - /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) - /// Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) - /// Proof: Battlepass BattlepassInfoByOrg (max_values: None, max_size: Some(118), added: 2593, mode: MaxEncodedLen) - /// Storage: Uniques Account (r:1 w:1) - /// Proof: Uniques Account (max_values: None, max_size: Some(88), added: 2563, mode: MaxEncodedLen) - /// Storage: Battlepass NftIndex (r:1 w:1) - /// Proof: Battlepass NftIndex (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: Uniques Asset (r:1 w:1) - /// Proof: Uniques Asset (max_values: None, max_size: Some(122), added: 2597, mode: MaxEncodedLen) - /// Storage: Uniques Class (r:1 w:1) - /// Proof: Uniques Class (max_values: None, max_size: Some(178), added: 2653, 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(187), added: 2662, mode: MaxEncodedLen) + // Storage: Battlepass Battlepasses (r:1 w:0) + // Storage: Battlepass BattlepassStates (r:1 w:0) + // Storage: Control OrgStates (r:1 w:0) + // Storage: Control Orgs (r:1 w:0) + // Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) + // Storage: Battlepass ClaimedBattlepasses (r:1 w:1) + // Storage: Battlepass NftIndex (r:1 w:1) + // Storage: Uniques Asset (r:1 w:1) + // Storage: Uniques Class (r:1 w:1) + // Storage: Uniques CollectionMaxSupply (r:1 w:0) + // Storage: Uniques InstanceMetadataOf (r:1 w:1) + // Storage: Uniques Account (r:0 w:1) fn claim_battlepass() -> Weight { - // Proof Size summary in bytes: - // Measured: `1359` - // Estimated: `26736` - // Minimum execution time: 95_000 nanoseconds. - Weight::from_parts(98_000_000, 26736) - .saturating_add(T::DbWeight::get().reads(11_u64)) - .saturating_add(T::DbWeight::get().writes(5_u64)) + // Minimum execution time: 101_000 nanoseconds. + Weight::from_ref_time(105_000_000) + .saturating_add(T::DbWeight::get().reads(11)) + .saturating_add(T::DbWeight::get().writes(6)) } - /// Storage: Battlepass Battlepasses (r:1 w:0) - /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(382), added: 2857, mode: MaxEncodedLen) - /// Storage: Battlepass BattlepassStates (r:1 w:1) - /// Proof: Battlepass BattlepassStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) - /// Storage: Control OrgStates (r:1 w:0) - /// Proof: Control OrgStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) - /// Storage: Control Orgs (r:1 w:0) - /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) - /// Storage: Battlepass BattlepassInfoByOrg (r:1 w:1) - /// Proof: Battlepass BattlepassInfoByOrg (max_values: None, max_size: Some(118), added: 2593, mode: MaxEncodedLen) + // Storage: Battlepass Battlepasses (r:1 w:0) + // Storage: Battlepass BattlepassStates (r:1 w:1) + // Storage: Control OrgStates (r:1 w:0) + // Storage: Control Orgs (r:1 w:0) + // Storage: Battlepass BattlepassInfoByOrg (r:1 w:1) fn activate_battlepass() -> Weight { - // Proof Size summary in bytes: - // Measured: `880` - // Estimated: `13263` - // Minimum execution time: 36_000 nanoseconds. - Weight::from_parts(37_000_000, 13263) - .saturating_add(T::DbWeight::get().reads(5_u64)) - .saturating_add(T::DbWeight::get().writes(2_u64)) + // Minimum execution time: 43_000 nanoseconds. + Weight::from_ref_time(44_000_000) + .saturating_add(T::DbWeight::get().reads(5)) + .saturating_add(T::DbWeight::get().writes(2)) } - /// Storage: Battlepass Battlepasses (r:1 w:0) - /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(382), added: 2857, mode: MaxEncodedLen) - /// Storage: Battlepass BattlepassStates (r:1 w:1) - /// Proof: Battlepass BattlepassStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) - /// Storage: Control Orgs (r:1 w:0) - /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) - /// Storage: Battlepass BattlepassInfoByOrg (r:1 w:1) - /// Proof: Battlepass BattlepassInfoByOrg (max_values: None, max_size: Some(118), added: 2593, mode: MaxEncodedLen) + // Storage: Battlepass Battlepasses (r:1 w:0) + // Storage: Battlepass BattlepassStates (r:1 w:1) + // Storage: Control Orgs (r:1 w:0) + // Storage: Battlepass BattlepassInfoByOrg (r:1 w:1) fn conclude_battlepass() -> Weight { - // Proof Size summary in bytes: - // Measured: `907` - // Estimated: `10739` - // Minimum execution time: 33_000 nanoseconds. - Weight::from_parts(34_000_000, 10739) - .saturating_add(T::DbWeight::get().reads(4_u64)) - .saturating_add(T::DbWeight::get().writes(2_u64)) + // Minimum execution time: 38_000 nanoseconds. + Weight::from_ref_time(40_000_000) + .saturating_add(T::DbWeight::get().reads(4)) + .saturating_add(T::DbWeight::get().writes(2)) } - /// Storage: Battlepass Battlepasses (r:1 w:0) - /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(382), added: 2857, mode: MaxEncodedLen) - /// Storage: Battlepass BattlepassStates (r:1 w:0) - /// Proof: Battlepass BattlepassStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) - /// Storage: Control OrgStates (r:1 w:0) - /// Proof: Control OrgStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) - /// Storage: Control Orgs (r:1 w:0) - /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) - /// Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) - /// Proof: Battlepass BattlepassInfoByOrg (max_values: None, max_size: Some(118), added: 2593, mode: MaxEncodedLen) - /// Storage: Uniques Account (r:2 w:0) - /// Proof: Uniques Account (max_values: None, max_size: Some(88), added: 2563, mode: MaxEncodedLen) - /// Storage: Battlepass Points (r:0 w:1) - /// Proof: Battlepass Points (max_values: None, max_size: Some(100), added: 2575, mode: MaxEncodedLen) + // Storage: Battlepass Battlepasses (r:1 w:0) + // Storage: Battlepass BattlepassStates (r:1 w:0) + // Storage: Control OrgStates (r:1 w:0) + // Storage: Control Orgs (r:1 w:0) + // Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) + // Storage: Battlepass ClaimedBattlepasses (r:1 w:0) + // Storage: Uniques Asset (r:1 w:0) + // Storage: Uniques InstanceMetadataOf (r:1 w:0) + // Storage: Battlepass Points (r:0 w:1) fn set_points() -> Weight { - // Proof Size summary in bytes: - // Measured: `1417` - // Estimated: `18389` - // Minimum execution time: 44_000 nanoseconds. - Weight::from_parts(44_000_000, 18389) - .saturating_add(T::DbWeight::get().reads(7_u64)) - .saturating_add(T::DbWeight::get().writes(1_u64)) + // Minimum execution time: 51_000 nanoseconds. + Weight::from_ref_time(53_000_000) + .saturating_add(T::DbWeight::get().reads(8)) + .saturating_add(T::DbWeight::get().writes(1)) } - /// Storage: Battlepass Battlepasses (r:1 w:0) - /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(382), added: 2857, mode: MaxEncodedLen) - /// Storage: Battlepass BattlepassStates (r:1 w:0) - /// Proof: Battlepass BattlepassStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) - /// Storage: Control OrgStates (r:1 w:0) - /// Proof: Control OrgStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) - /// Storage: Control Orgs (r:1 w:0) - /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) - /// Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) - /// Proof: Battlepass BattlepassInfoByOrg (max_values: None, max_size: Some(118), added: 2593, mode: MaxEncodedLen) - /// Storage: Battlepass CollectionIndex (r:1 w:1) - /// Proof: Battlepass CollectionIndex (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: Uniques ClassMetadataOf (r:1 w:1) - /// Proof: Uniques ClassMetadataOf (max_values: None, max_size: Some(167), added: 2642, mode: MaxEncodedLen) - /// Storage: Uniques CollectionMaxSupply (r:1 w:1) - /// Proof: Uniques CollectionMaxSupply (max_values: None, max_size: Some(24), added: 2499, mode: MaxEncodedLen) - /// Storage: Uniques ClassAccount (r:0 w:1) - /// Proof: Uniques ClassAccount (max_values: None, max_size: Some(68), added: 2543, mode: MaxEncodedLen) - /// Storage: Battlepass Rewards (r:0 w:1) - /// Proof: Battlepass Rewards (max_values: None, max_size: Some(346), added: 2821, mode: MaxEncodedLen) - /// Storage: Battlepass RewardStates (r:0 w:1) - /// Proof: Battlepass RewardStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + // Storage: Battlepass Battlepasses (r:1 w:0) + // Storage: Battlepass BattlepassStates (r:1 w:0) + // Storage: Control OrgStates (r:1 w:0) + // Storage: Control Orgs (r:1 w:0) + // Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) + // Storage: Battlepass CollectionIndex (r:1 w:1) + // Storage: Uniques Class (r:1 w:1) + // Storage: Uniques ClassMetadataOf (r:1 w:1) + // Storage: Uniques CollectionMaxSupply (r:1 w:1) + // Storage: Uniques ClassAccount (r:0 w:1) + // Storage: Battlepass Rewards (r:0 w:1) + // Storage: Battlepass RewardStates (r:0 w:1) fn create_reward() -> Weight { - // Proof Size summary in bytes: - // Measured: `1226` - // Estimated: `21556` - // Minimum execution time: 110_000 nanoseconds. - Weight::from_parts(112_000_000, 21556) - .saturating_add(T::DbWeight::get().reads(9_u64)) - .saturating_add(T::DbWeight::get().writes(7_u64)) + // Minimum execution time: 116_000 nanoseconds. + Weight::from_ref_time(120_000_000) + .saturating_add(T::DbWeight::get().reads(9)) + .saturating_add(T::DbWeight::get().writes(7)) } - /// Storage: Battlepass Rewards (r:1 w:1) - /// Proof: Battlepass Rewards (max_values: None, max_size: Some(346), added: 2821, mode: MaxEncodedLen) - /// Storage: Battlepass RewardStates (r:1 w:0) - /// Proof: Battlepass RewardStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) - /// Storage: Battlepass Battlepasses (r:1 w:0) - /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(382), added: 2857, mode: MaxEncodedLen) - /// Storage: Battlepass BattlepassStates (r:1 w:0) - /// Proof: Battlepass BattlepassStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) - /// Storage: Control OrgStates (r:1 w:0) - /// Proof: Control OrgStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) - /// Storage: Control Orgs (r:1 w:0) - /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) - /// Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) - /// Proof: Battlepass BattlepassInfoByOrg (max_values: None, max_size: Some(118), added: 2593, mode: MaxEncodedLen) + // Storage: Battlepass Rewards (r:1 w:1) + // Storage: Battlepass RewardStates (r:1 w:0) + // Storage: Battlepass Battlepasses (r:1 w:0) + // Storage: Battlepass BattlepassStates (r:1 w:0) + // Storage: Control OrgStates (r:1 w:0) + // Storage: Control Orgs (r:1 w:0) + // Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) fn update_reward() -> Weight { - // Proof Size summary in bytes: - // Measured: `1169` - // Estimated: `18608` - // Minimum execution time: 41_000 nanoseconds. - Weight::from_parts(41_000_000, 18608) - .saturating_add(T::DbWeight::get().reads(7_u64)) - .saturating_add(T::DbWeight::get().writes(1_u64)) + // Minimum execution time: 46_000 nanoseconds. + Weight::from_ref_time(47_000_000) + .saturating_add(T::DbWeight::get().reads(7)) + .saturating_add(T::DbWeight::get().writes(1)) } - /// Storage: Battlepass Rewards (r:1 w:0) - /// Proof: Battlepass Rewards (max_values: None, max_size: Some(346), added: 2821, mode: MaxEncodedLen) - /// Storage: Battlepass RewardStates (r:1 w:1) - /// Proof: Battlepass RewardStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) - /// Storage: Battlepass Battlepasses (r:1 w:0) - /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(382), added: 2857, mode: MaxEncodedLen) - /// Storage: Control Orgs (r:1 w:0) - /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) - /// Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) - /// Proof: Battlepass BattlepassInfoByOrg (max_values: None, max_size: Some(118), added: 2593, mode: MaxEncodedLen) + // Storage: Battlepass Rewards (r:1 w:0) + // Storage: Battlepass RewardStates (r:1 w:1) + // Storage: Battlepass Battlepasses (r:1 w:0) + // Storage: Control Orgs (r:1 w:0) + // Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) fn disable_reward() -> Weight { - // Proof Size summary in bytes: - // Measured: `1094` - // Estimated: `13560` - // Minimum execution time: 33_000 nanoseconds. - Weight::from_parts(33_000_000, 13560) - .saturating_add(T::DbWeight::get().reads(5_u64)) - .saturating_add(T::DbWeight::get().writes(1_u64)) + // Minimum execution time: 39_000 nanoseconds. + Weight::from_ref_time(41_000_000) + .saturating_add(T::DbWeight::get().reads(5)) + .saturating_add(T::DbWeight::get().writes(1)) } - /// Storage: Battlepass Rewards (r:1 w:0) - /// Proof: Battlepass Rewards (max_values: None, max_size: Some(346), added: 2821, mode: MaxEncodedLen) - /// Storage: Battlepass RewardStates (r:1 w:0) - /// Proof: Battlepass RewardStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) - /// Storage: Battlepass ClaimedRewards (r:1 w:1) - /// Proof: Battlepass ClaimedRewards (max_values: None, max_size: Some(100), added: 2575, mode: MaxEncodedLen) - /// Storage: Battlepass Battlepasses (r:1 w:0) - /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(382), added: 2857, mode: MaxEncodedLen) - /// Storage: Battlepass BattlepassStates (r:1 w:0) - /// Proof: Battlepass BattlepassStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) - /// Storage: Control OrgStates (r:1 w:0) - /// Proof: Control OrgStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) - /// Storage: Control Orgs (r:1 w:0) - /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) - /// Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) - /// Proof: Battlepass BattlepassInfoByOrg (max_values: None, max_size: Some(118), added: 2593, mode: MaxEncodedLen) - /// Storage: Uniques Account (r:2 w:1) - /// Proof: Uniques Account (max_values: None, max_size: Some(88), added: 2563, mode: MaxEncodedLen) - /// Storage: Battlepass Points (r:1 w:0) - /// Proof: Battlepass Points (max_values: None, max_size: Some(100), added: 2575, mode: MaxEncodedLen) - /// Storage: Battlepass Levels (r:2 w:0) - /// Proof: Battlepass Levels (max_values: None, max_size: Some(69), added: 2544, mode: MaxEncodedLen) - /// Storage: Battlepass NftIndex (r:1 w:1) - /// Proof: Battlepass NftIndex (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: Uniques Asset (r:1 w:1) - /// Proof: Uniques Asset (max_values: None, max_size: Some(122), added: 2597, mode: MaxEncodedLen) - /// Storage: Uniques Class (r:1 w:1) - /// Proof: Uniques Class (max_values: None, max_size: Some(178), added: 2653, 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(187), added: 2662, mode: MaxEncodedLen) + // Storage: Battlepass Rewards (r:1 w:0) + // Storage: Battlepass RewardStates (r:1 w:0) + // Storage: Battlepass ClaimedRewards (r:1 w:1) + // Storage: Battlepass Battlepasses (r:1 w:0) + // Storage: Battlepass BattlepassStates (r:1 w:0) + // Storage: Control OrgStates (r:1 w:0) + // Storage: Control Orgs (r:1 w:0) + // Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) + // Storage: Battlepass ClaimedBattlepasses (r:1 w:0) + // Storage: Uniques Asset (r:2 w:1) + // Storage: Uniques InstanceMetadataOf (r:2 w:1) + // Storage: Battlepass Points (r:1 w:0) + // Storage: Battlepass Levels (r:2 w:0) + // Storage: Battlepass NftIndex (r:1 w:1) + // Storage: Uniques Class (r:1 w:1) + // Storage: Uniques CollectionMaxSupply (r:1 w:0) + // Storage: Uniques Account (r:0 w:1) fn claim_reward() -> Weight { - // Proof Size summary in bytes: - // Measured: `2203` - // Estimated: `44882` - // Minimum execution time: 133_000 nanoseconds. - Weight::from_parts(135_000_000, 44882) - .saturating_add(T::DbWeight::get().reads(18_u64)) - .saturating_add(T::DbWeight::get().writes(6_u64)) + // Minimum execution time: 137_000 nanoseconds. + Weight::from_ref_time(141_000_000) + .saturating_add(T::DbWeight::get().reads(19)) + .saturating_add(T::DbWeight::get().writes(6)) } - /// Storage: Battlepass Battlepasses (r:1 w:0) - /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(382), added: 2857, mode: MaxEncodedLen) - /// Storage: Battlepass BattlepassStates (r:1 w:0) - /// Proof: Battlepass BattlepassStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) - /// Storage: Control OrgStates (r:1 w:0) - /// Proof: Control OrgStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) - /// Storage: Control Orgs (r:1 w:0) - /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) - /// Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) - /// Proof: Battlepass BattlepassInfoByOrg (max_values: None, max_size: Some(118), added: 2593, mode: MaxEncodedLen) - /// Storage: Battlepass Levels (r:0 w:1) - /// Proof: Battlepass Levels (max_values: None, max_size: Some(69), added: 2544, mode: MaxEncodedLen) + // Storage: Battlepass Battlepasses (r:1 w:0) + // Storage: Battlepass BattlepassStates (r:1 w:0) + // Storage: Control OrgStates (r:1 w:0) + // Storage: Control Orgs (r:1 w:0) + // Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) + // Storage: Battlepass Levels (r:0 w:1) fn add_level() -> Weight { - // Proof Size summary in bytes: - // Measured: `945` - // Estimated: `13263` - // Minimum execution time: 31_000 nanoseconds. - Weight::from_parts(32_000_000, 13263) - .saturating_add(T::DbWeight::get().reads(5_u64)) - .saturating_add(T::DbWeight::get().writes(1_u64)) + // Minimum execution time: 39_000 nanoseconds. + Weight::from_ref_time(41_000_000) + .saturating_add(T::DbWeight::get().reads(5)) + .saturating_add(T::DbWeight::get().writes(1)) } - /// Storage: Battlepass Battlepasses (r:1 w:0) - /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(382), added: 2857, mode: MaxEncodedLen) - /// Storage: Battlepass BattlepassStates (r:1 w:0) - /// Proof: Battlepass BattlepassStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) - /// Storage: Control OrgStates (r:1 w:0) - /// Proof: Control OrgStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) - /// Storage: Control Orgs (r:1 w:0) - /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) - /// Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) - /// Proof: Battlepass BattlepassInfoByOrg (max_values: None, max_size: Some(118), added: 2593, mode: MaxEncodedLen) - /// Storage: Battlepass Levels (r:1 w:1) - /// Proof: Battlepass Levels (max_values: None, max_size: Some(69), added: 2544, mode: MaxEncodedLen) + // Storage: Battlepass Battlepasses (r:1 w:0) + // Storage: Battlepass BattlepassStates (r:1 w:0) + // Storage: Control OrgStates (r:1 w:0) + // Storage: Control Orgs (r:1 w:0) + // Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) + // Storage: Battlepass Levels (r:1 w:1) fn remove_level() -> Weight { - // Proof Size summary in bytes: - // Measured: `1038` - // Estimated: `15807` - // Minimum execution time: 36_000 nanoseconds. - Weight::from_parts(37_000_000, 15807) - .saturating_add(T::DbWeight::get().reads(6_u64)) - .saturating_add(T::DbWeight::get().writes(1_u64)) + // Minimum execution time: 40_000 nanoseconds. + Weight::from_ref_time(42_000_000) + .saturating_add(T::DbWeight::get().reads(6)) + .saturating_add(T::DbWeight::get().writes(1)) } - /// Storage: Battlepass Battlepasses (r:1 w:0) - /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(382), added: 2857, mode: MaxEncodedLen) - /// Storage: Battlepass BattlepassStates (r:1 w:0) - /// Proof: Battlepass BattlepassStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) - /// Storage: Control OrgStates (r:1 w:0) - /// Proof: Control OrgStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) - /// Storage: Control Orgs (r:1 w:0) - /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) - /// Storage: Battlepass BattlepassInfoByOrg (r:1 w:1) - /// Proof: Battlepass BattlepassInfoByOrg (max_values: None, max_size: Some(118), added: 2593, mode: MaxEncodedLen) + // Storage: Battlepass Battlepasses (r:1 w:0) + // Storage: Battlepass BattlepassStates (r:1 w:0) + // Storage: Control OrgStates (r:1 w:0) + // Storage: Control Orgs (r:1 w:0) + // Storage: Battlepass BattlepassInfoByOrg (r:1 w:1) fn add_bot() -> Weight { - // Proof Size summary in bytes: - // Measured: `880` - // Estimated: `13263` - // Minimum execution time: 30_000 nanoseconds. - Weight::from_parts(31_000_000, 13263) - .saturating_add(T::DbWeight::get().reads(5_u64)) - .saturating_add(T::DbWeight::get().writes(1_u64)) + // Minimum execution time: 35_000 nanoseconds. + Weight::from_ref_time(35_000_000) + .saturating_add(T::DbWeight::get().reads(5)) + .saturating_add(T::DbWeight::get().writes(1)) } } // For backwards compatibility and tests impl WeightInfo for () { - /// Storage: Control OrgStates (r:1 w:0) - /// Proof: Control OrgStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) - /// Storage: Control Orgs (r:1 w:0) - /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) - /// Storage: Battlepass BattlepassInfoByOrg (r:1 w:1) - /// Proof: Battlepass BattlepassInfoByOrg (max_values: None, max_size: Some(118), added: 2593, mode: MaxEncodedLen) - /// Storage: Battlepass CollectionIndex (r:1 w:1) - /// Proof: Battlepass CollectionIndex (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: Uniques ClassMetadataOf (r:1 w:1) - /// Proof: Uniques ClassMetadataOf (max_values: None, max_size: Some(167), added: 2642, mode: MaxEncodedLen) - /// Storage: Uniques ClassAccount (r:0 w:1) - /// Proof: Uniques ClassAccount (max_values: None, max_size: Some(68), added: 2543, mode: MaxEncodedLen) - /// Storage: Battlepass BattlepassStates (r:0 w:1) - /// Proof: Battlepass BattlepassStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) - /// Storage: Battlepass Battlepasses (r:0 w:1) - /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(382), added: 2857, mode: MaxEncodedLen) + // Storage: Control OrgStates (r:1 w:0) + // Storage: Control Orgs (r:1 w:0) + // Storage: Battlepass BattlepassInfoByOrg (r:1 w:1) + // Storage: Battlepass CollectionIndex (r:1 w:1) + // Storage: Uniques Class (r:1 w:1) + // Storage: Uniques ClassMetadataOf (r:1 w:1) + // Storage: Uniques ClassAccount (r:0 w:1) + // Storage: Battlepass BattlepassStates (r:0 w:1) + // Storage: Battlepass Battlepasses (r:0 w:1) fn create_battlepass() -> Weight { - // Proof Size summary in bytes: - // Measured: `597` - // Estimated: `13676` - // Minimum execution time: 86_000 nanoseconds. - Weight::from_parts(86_000_000, 13676) - .saturating_add(RocksDbWeight::get().reads(6_u64)) - .saturating_add(RocksDbWeight::get().writes(7_u64)) + // Minimum execution time: 93_000 nanoseconds. + Weight::from_ref_time(95_000_000) + .saturating_add(RocksDbWeight::get().reads(6)) + .saturating_add(RocksDbWeight::get().writes(7)) } - /// Storage: Battlepass Battlepasses (r:1 w:1) - /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(382), added: 2857, mode: MaxEncodedLen) - /// Storage: Battlepass BattlepassStates (r:1 w:0) - /// Proof: Battlepass BattlepassStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) - /// Storage: Control OrgStates (r:1 w:0) - /// Proof: Control OrgStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) - /// Storage: Control Orgs (r:1 w:0) - /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) + // Storage: Battlepass Battlepasses (r:1 w:1) + // Storage: Battlepass BattlepassStates (r:1 w:0) + // Storage: Control OrgStates (r:1 w:0) + // Storage: Control Orgs (r:1 w:0) fn update_battlepass() -> Weight { - // Proof Size summary in bytes: - // Measured: `837` - // Estimated: `10670` - // Minimum execution time: 29_000 nanoseconds. - Weight::from_parts(30_000_000, 10670) - .saturating_add(RocksDbWeight::get().reads(4_u64)) - .saturating_add(RocksDbWeight::get().writes(1_u64)) + // Minimum execution time: 35_000 nanoseconds. + Weight::from_ref_time(36_000_000) + .saturating_add(RocksDbWeight::get().reads(4)) + .saturating_add(RocksDbWeight::get().writes(1)) } - /// Storage: Battlepass Battlepasses (r:1 w:0) - /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(382), added: 2857, mode: MaxEncodedLen) - /// Storage: Battlepass BattlepassStates (r:1 w:0) - /// Proof: Battlepass BattlepassStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) - /// Storage: Control OrgStates (r:1 w:0) - /// Proof: Control OrgStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) - /// Storage: Control Orgs (r:1 w:0) - /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) - /// Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) - /// Proof: Battlepass BattlepassInfoByOrg (max_values: None, max_size: Some(118), added: 2593, mode: MaxEncodedLen) - /// Storage: Uniques Account (r:1 w:1) - /// Proof: Uniques Account (max_values: None, max_size: Some(88), added: 2563, mode: MaxEncodedLen) - /// Storage: Battlepass NftIndex (r:1 w:1) - /// Proof: Battlepass NftIndex (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: Uniques Asset (r:1 w:1) - /// Proof: Uniques Asset (max_values: None, max_size: Some(122), added: 2597, mode: MaxEncodedLen) - /// Storage: Uniques Class (r:1 w:1) - /// Proof: Uniques Class (max_values: None, max_size: Some(178), added: 2653, 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(187), added: 2662, mode: MaxEncodedLen) + // Storage: Battlepass Battlepasses (r:1 w:0) + // Storage: Battlepass BattlepassStates (r:1 w:0) + // Storage: Control OrgStates (r:1 w:0) + // Storage: Control Orgs (r:1 w:0) + // Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) + // Storage: Battlepass ClaimedBattlepasses (r:1 w:1) + // Storage: Battlepass NftIndex (r:1 w:1) + // Storage: Uniques Asset (r:1 w:1) + // Storage: Uniques Class (r:1 w:1) + // Storage: Uniques CollectionMaxSupply (r:1 w:0) + // Storage: Uniques InstanceMetadataOf (r:1 w:1) + // Storage: Uniques Account (r:0 w:1) fn claim_battlepass() -> Weight { - // Proof Size summary in bytes: - // Measured: `1359` - // Estimated: `26736` - // Minimum execution time: 95_000 nanoseconds. - Weight::from_parts(98_000_000, 26736) - .saturating_add(RocksDbWeight::get().reads(11_u64)) - .saturating_add(RocksDbWeight::get().writes(5_u64)) + // Minimum execution time: 101_000 nanoseconds. + Weight::from_ref_time(105_000_000) + .saturating_add(RocksDbWeight::get().reads(11)) + .saturating_add(RocksDbWeight::get().writes(6)) } - /// Storage: Battlepass Battlepasses (r:1 w:0) - /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(382), added: 2857, mode: MaxEncodedLen) - /// Storage: Battlepass BattlepassStates (r:1 w:1) - /// Proof: Battlepass BattlepassStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) - /// Storage: Control OrgStates (r:1 w:0) - /// Proof: Control OrgStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) - /// Storage: Control Orgs (r:1 w:0) - /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) - /// Storage: Battlepass BattlepassInfoByOrg (r:1 w:1) - /// Proof: Battlepass BattlepassInfoByOrg (max_values: None, max_size: Some(118), added: 2593, mode: MaxEncodedLen) + // Storage: Battlepass Battlepasses (r:1 w:0) + // Storage: Battlepass BattlepassStates (r:1 w:1) + // Storage: Control OrgStates (r:1 w:0) + // Storage: Control Orgs (r:1 w:0) + // Storage: Battlepass BattlepassInfoByOrg (r:1 w:1) fn activate_battlepass() -> Weight { - // Proof Size summary in bytes: - // Measured: `880` - // Estimated: `13263` - // Minimum execution time: 36_000 nanoseconds. - Weight::from_parts(37_000_000, 13263) - .saturating_add(RocksDbWeight::get().reads(5_u64)) - .saturating_add(RocksDbWeight::get().writes(2_u64)) + // Minimum execution time: 43_000 nanoseconds. + Weight::from_ref_time(44_000_000) + .saturating_add(RocksDbWeight::get().reads(5)) + .saturating_add(RocksDbWeight::get().writes(2)) } - /// Storage: Battlepass Battlepasses (r:1 w:0) - /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(382), added: 2857, mode: MaxEncodedLen) - /// Storage: Battlepass BattlepassStates (r:1 w:1) - /// Proof: Battlepass BattlepassStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) - /// Storage: Control Orgs (r:1 w:0) - /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) - /// Storage: Battlepass BattlepassInfoByOrg (r:1 w:1) - /// Proof: Battlepass BattlepassInfoByOrg (max_values: None, max_size: Some(118), added: 2593, mode: MaxEncodedLen) + // Storage: Battlepass Battlepasses (r:1 w:0) + // Storage: Battlepass BattlepassStates (r:1 w:1) + // Storage: Control Orgs (r:1 w:0) + // Storage: Battlepass BattlepassInfoByOrg (r:1 w:1) fn conclude_battlepass() -> Weight { - // Proof Size summary in bytes: - // Measured: `907` - // Estimated: `10739` - // Minimum execution time: 33_000 nanoseconds. - Weight::from_parts(34_000_000, 10739) - .saturating_add(RocksDbWeight::get().reads(4_u64)) - .saturating_add(RocksDbWeight::get().writes(2_u64)) + // Minimum execution time: 38_000 nanoseconds. + Weight::from_ref_time(40_000_000) + .saturating_add(RocksDbWeight::get().reads(4)) + .saturating_add(RocksDbWeight::get().writes(2)) } - /// Storage: Battlepass Battlepasses (r:1 w:0) - /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(382), added: 2857, mode: MaxEncodedLen) - /// Storage: Battlepass BattlepassStates (r:1 w:0) - /// Proof: Battlepass BattlepassStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) - /// Storage: Control OrgStates (r:1 w:0) - /// Proof: Control OrgStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) - /// Storage: Control Orgs (r:1 w:0) - /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) - /// Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) - /// Proof: Battlepass BattlepassInfoByOrg (max_values: None, max_size: Some(118), added: 2593, mode: MaxEncodedLen) - /// Storage: Uniques Account (r:2 w:0) - /// Proof: Uniques Account (max_values: None, max_size: Some(88), added: 2563, mode: MaxEncodedLen) - /// Storage: Battlepass Points (r:0 w:1) - /// Proof: Battlepass Points (max_values: None, max_size: Some(100), added: 2575, mode: MaxEncodedLen) + // Storage: Battlepass Battlepasses (r:1 w:0) + // Storage: Battlepass BattlepassStates (r:1 w:0) + // Storage: Control OrgStates (r:1 w:0) + // Storage: Control Orgs (r:1 w:0) + // Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) + // Storage: Battlepass ClaimedBattlepasses (r:1 w:0) + // Storage: Uniques Asset (r:1 w:0) + // Storage: Uniques InstanceMetadataOf (r:1 w:0) + // Storage: Battlepass Points (r:0 w:1) fn set_points() -> Weight { - // Proof Size summary in bytes: - // Measured: `1417` - // Estimated: `18389` - // Minimum execution time: 44_000 nanoseconds. - Weight::from_parts(44_000_000, 18389) - .saturating_add(RocksDbWeight::get().reads(7_u64)) - .saturating_add(RocksDbWeight::get().writes(1_u64)) + // Minimum execution time: 51_000 nanoseconds. + Weight::from_ref_time(53_000_000) + .saturating_add(RocksDbWeight::get().reads(8)) + .saturating_add(RocksDbWeight::get().writes(1)) } - /// Storage: Battlepass Battlepasses (r:1 w:0) - /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(382), added: 2857, mode: MaxEncodedLen) - /// Storage: Battlepass BattlepassStates (r:1 w:0) - /// Proof: Battlepass BattlepassStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) - /// Storage: Control OrgStates (r:1 w:0) - /// Proof: Control OrgStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) - /// Storage: Control Orgs (r:1 w:0) - /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) - /// Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) - /// Proof: Battlepass BattlepassInfoByOrg (max_values: None, max_size: Some(118), added: 2593, mode: MaxEncodedLen) - /// Storage: Battlepass CollectionIndex (r:1 w:1) - /// Proof: Battlepass CollectionIndex (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: Uniques ClassMetadataOf (r:1 w:1) - /// Proof: Uniques ClassMetadataOf (max_values: None, max_size: Some(167), added: 2642, mode: MaxEncodedLen) - /// Storage: Uniques CollectionMaxSupply (r:1 w:1) - /// Proof: Uniques CollectionMaxSupply (max_values: None, max_size: Some(24), added: 2499, mode: MaxEncodedLen) - /// Storage: Uniques ClassAccount (r:0 w:1) - /// Proof: Uniques ClassAccount (max_values: None, max_size: Some(68), added: 2543, mode: MaxEncodedLen) - /// Storage: Battlepass Rewards (r:0 w:1) - /// Proof: Battlepass Rewards (max_values: None, max_size: Some(346), added: 2821, mode: MaxEncodedLen) - /// Storage: Battlepass RewardStates (r:0 w:1) - /// Proof: Battlepass RewardStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + // Storage: Battlepass Battlepasses (r:1 w:0) + // Storage: Battlepass BattlepassStates (r:1 w:0) + // Storage: Control OrgStates (r:1 w:0) + // Storage: Control Orgs (r:1 w:0) + // Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) + // Storage: Battlepass CollectionIndex (r:1 w:1) + // Storage: Uniques Class (r:1 w:1) + // Storage: Uniques ClassMetadataOf (r:1 w:1) + // Storage: Uniques CollectionMaxSupply (r:1 w:1) + // Storage: Uniques ClassAccount (r:0 w:1) + // Storage: Battlepass Rewards (r:0 w:1) + // Storage: Battlepass RewardStates (r:0 w:1) fn create_reward() -> Weight { - // Proof Size summary in bytes: - // Measured: `1226` - // Estimated: `21556` - // Minimum execution time: 110_000 nanoseconds. - Weight::from_parts(112_000_000, 21556) - .saturating_add(RocksDbWeight::get().reads(9_u64)) - .saturating_add(RocksDbWeight::get().writes(7_u64)) + // Minimum execution time: 116_000 nanoseconds. + Weight::from_ref_time(120_000_000) + .saturating_add(RocksDbWeight::get().reads(9)) + .saturating_add(RocksDbWeight::get().writes(7)) } - /// Storage: Battlepass Rewards (r:1 w:1) - /// Proof: Battlepass Rewards (max_values: None, max_size: Some(346), added: 2821, mode: MaxEncodedLen) - /// Storage: Battlepass RewardStates (r:1 w:0) - /// Proof: Battlepass RewardStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) - /// Storage: Battlepass Battlepasses (r:1 w:0) - /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(382), added: 2857, mode: MaxEncodedLen) - /// Storage: Battlepass BattlepassStates (r:1 w:0) - /// Proof: Battlepass BattlepassStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) - /// Storage: Control OrgStates (r:1 w:0) - /// Proof: Control OrgStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) - /// Storage: Control Orgs (r:1 w:0) - /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) - /// Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) - /// Proof: Battlepass BattlepassInfoByOrg (max_values: None, max_size: Some(118), added: 2593, mode: MaxEncodedLen) + // Storage: Battlepass Rewards (r:1 w:1) + // Storage: Battlepass RewardStates (r:1 w:0) + // Storage: Battlepass Battlepasses (r:1 w:0) + // Storage: Battlepass BattlepassStates (r:1 w:0) + // Storage: Control OrgStates (r:1 w:0) + // Storage: Control Orgs (r:1 w:0) + // Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) fn update_reward() -> Weight { - // Proof Size summary in bytes: - // Measured: `1169` - // Estimated: `18608` - // Minimum execution time: 41_000 nanoseconds. - Weight::from_parts(41_000_000, 18608) - .saturating_add(RocksDbWeight::get().reads(7_u64)) - .saturating_add(RocksDbWeight::get().writes(1_u64)) + // Minimum execution time: 46_000 nanoseconds. + Weight::from_ref_time(47_000_000) + .saturating_add(RocksDbWeight::get().reads(7)) + .saturating_add(RocksDbWeight::get().writes(1)) } - /// Storage: Battlepass Rewards (r:1 w:0) - /// Proof: Battlepass Rewards (max_values: None, max_size: Some(346), added: 2821, mode: MaxEncodedLen) - /// Storage: Battlepass RewardStates (r:1 w:1) - /// Proof: Battlepass RewardStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) - /// Storage: Battlepass Battlepasses (r:1 w:0) - /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(382), added: 2857, mode: MaxEncodedLen) - /// Storage: Control Orgs (r:1 w:0) - /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) - /// Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) - /// Proof: Battlepass BattlepassInfoByOrg (max_values: None, max_size: Some(118), added: 2593, mode: MaxEncodedLen) + // Storage: Battlepass Rewards (r:1 w:0) + // Storage: Battlepass RewardStates (r:1 w:1) + // Storage: Battlepass Battlepasses (r:1 w:0) + // Storage: Control Orgs (r:1 w:0) + // Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) fn disable_reward() -> Weight { - // Proof Size summary in bytes: - // Measured: `1094` - // Estimated: `13560` - // Minimum execution time: 33_000 nanoseconds. - Weight::from_parts(33_000_000, 13560) - .saturating_add(RocksDbWeight::get().reads(5_u64)) - .saturating_add(RocksDbWeight::get().writes(1_u64)) + // Minimum execution time: 39_000 nanoseconds. + Weight::from_ref_time(41_000_000) + .saturating_add(RocksDbWeight::get().reads(5)) + .saturating_add(RocksDbWeight::get().writes(1)) } - /// Storage: Battlepass Rewards (r:1 w:0) - /// Proof: Battlepass Rewards (max_values: None, max_size: Some(346), added: 2821, mode: MaxEncodedLen) - /// Storage: Battlepass RewardStates (r:1 w:0) - /// Proof: Battlepass RewardStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) - /// Storage: Battlepass ClaimedRewards (r:1 w:1) - /// Proof: Battlepass ClaimedRewards (max_values: None, max_size: Some(100), added: 2575, mode: MaxEncodedLen) - /// Storage: Battlepass Battlepasses (r:1 w:0) - /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(382), added: 2857, mode: MaxEncodedLen) - /// Storage: Battlepass BattlepassStates (r:1 w:0) - /// Proof: Battlepass BattlepassStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) - /// Storage: Control OrgStates (r:1 w:0) - /// Proof: Control OrgStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) - /// Storage: Control Orgs (r:1 w:0) - /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) - /// Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) - /// Proof: Battlepass BattlepassInfoByOrg (max_values: None, max_size: Some(118), added: 2593, mode: MaxEncodedLen) - /// Storage: Uniques Account (r:2 w:1) - /// Proof: Uniques Account (max_values: None, max_size: Some(88), added: 2563, mode: MaxEncodedLen) - /// Storage: Battlepass Points (r:1 w:0) - /// Proof: Battlepass Points (max_values: None, max_size: Some(100), added: 2575, mode: MaxEncodedLen) - /// Storage: Battlepass Levels (r:2 w:0) - /// Proof: Battlepass Levels (max_values: None, max_size: Some(69), added: 2544, mode: MaxEncodedLen) - /// Storage: Battlepass NftIndex (r:1 w:1) - /// Proof: Battlepass NftIndex (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: Uniques Asset (r:1 w:1) - /// Proof: Uniques Asset (max_values: None, max_size: Some(122), added: 2597, mode: MaxEncodedLen) - /// Storage: Uniques Class (r:1 w:1) - /// Proof: Uniques Class (max_values: None, max_size: Some(178), added: 2653, 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(187), added: 2662, mode: MaxEncodedLen) + // Storage: Battlepass Rewards (r:1 w:0) + // Storage: Battlepass RewardStates (r:1 w:0) + // Storage: Battlepass ClaimedRewards (r:1 w:1) + // Storage: Battlepass Battlepasses (r:1 w:0) + // Storage: Battlepass BattlepassStates (r:1 w:0) + // Storage: Control OrgStates (r:1 w:0) + // Storage: Control Orgs (r:1 w:0) + // Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) + // Storage: Battlepass ClaimedBattlepasses (r:1 w:0) + // Storage: Uniques Asset (r:2 w:1) + // Storage: Uniques InstanceMetadataOf (r:2 w:1) + // Storage: Battlepass Points (r:1 w:0) + // Storage: Battlepass Levels (r:2 w:0) + // Storage: Battlepass NftIndex (r:1 w:1) + // Storage: Uniques Class (r:1 w:1) + // Storage: Uniques CollectionMaxSupply (r:1 w:0) + // Storage: Uniques Account (r:0 w:1) fn claim_reward() -> Weight { - // Proof Size summary in bytes: - // Measured: `2203` - // Estimated: `44882` - // Minimum execution time: 133_000 nanoseconds. - Weight::from_parts(135_000_000, 44882) - .saturating_add(RocksDbWeight::get().reads(18_u64)) - .saturating_add(RocksDbWeight::get().writes(6_u64)) + // Minimum execution time: 137_000 nanoseconds. + Weight::from_ref_time(141_000_000) + .saturating_add(RocksDbWeight::get().reads(19)) + .saturating_add(RocksDbWeight::get().writes(6)) } - /// Storage: Battlepass Battlepasses (r:1 w:0) - /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(382), added: 2857, mode: MaxEncodedLen) - /// Storage: Battlepass BattlepassStates (r:1 w:0) - /// Proof: Battlepass BattlepassStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) - /// Storage: Control OrgStates (r:1 w:0) - /// Proof: Control OrgStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) - /// Storage: Control Orgs (r:1 w:0) - /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) - /// Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) - /// Proof: Battlepass BattlepassInfoByOrg (max_values: None, max_size: Some(118), added: 2593, mode: MaxEncodedLen) - /// Storage: Battlepass Levels (r:0 w:1) - /// Proof: Battlepass Levels (max_values: None, max_size: Some(69), added: 2544, mode: MaxEncodedLen) + // Storage: Battlepass Battlepasses (r:1 w:0) + // Storage: Battlepass BattlepassStates (r:1 w:0) + // Storage: Control OrgStates (r:1 w:0) + // Storage: Control Orgs (r:1 w:0) + // Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) + // Storage: Battlepass Levels (r:0 w:1) fn add_level() -> Weight { - // Proof Size summary in bytes: - // Measured: `945` - // Estimated: `13263` - // Minimum execution time: 31_000 nanoseconds. - Weight::from_parts(32_000_000, 13263) - .saturating_add(RocksDbWeight::get().reads(5_u64)) - .saturating_add(RocksDbWeight::get().writes(1_u64)) + // Minimum execution time: 39_000 nanoseconds. + Weight::from_ref_time(41_000_000) + .saturating_add(RocksDbWeight::get().reads(5)) + .saturating_add(RocksDbWeight::get().writes(1)) } - /// Storage: Battlepass Battlepasses (r:1 w:0) - /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(382), added: 2857, mode: MaxEncodedLen) - /// Storage: Battlepass BattlepassStates (r:1 w:0) - /// Proof: Battlepass BattlepassStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) - /// Storage: Control OrgStates (r:1 w:0) - /// Proof: Control OrgStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) - /// Storage: Control Orgs (r:1 w:0) - /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) - /// Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) - /// Proof: Battlepass BattlepassInfoByOrg (max_values: None, max_size: Some(118), added: 2593, mode: MaxEncodedLen) - /// Storage: Battlepass Levels (r:1 w:1) - /// Proof: Battlepass Levels (max_values: None, max_size: Some(69), added: 2544, mode: MaxEncodedLen) + // Storage: Battlepass Battlepasses (r:1 w:0) + // Storage: Battlepass BattlepassStates (r:1 w:0) + // Storage: Control OrgStates (r:1 w:0) + // Storage: Control Orgs (r:1 w:0) + // Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) + // Storage: Battlepass Levels (r:1 w:1) fn remove_level() -> Weight { - // Proof Size summary in bytes: - // Measured: `1038` - // Estimated: `15807` - // Minimum execution time: 36_000 nanoseconds. - Weight::from_parts(37_000_000, 15807) - .saturating_add(RocksDbWeight::get().reads(6_u64)) - .saturating_add(RocksDbWeight::get().writes(1_u64)) + // Minimum execution time: 40_000 nanoseconds. + Weight::from_ref_time(42_000_000) + .saturating_add(RocksDbWeight::get().reads(6)) + .saturating_add(RocksDbWeight::get().writes(1)) } - /// Storage: Battlepass Battlepasses (r:1 w:0) - /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(382), added: 2857, mode: MaxEncodedLen) - /// Storage: Battlepass BattlepassStates (r:1 w:0) - /// Proof: Battlepass BattlepassStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) - /// Storage: Control OrgStates (r:1 w:0) - /// Proof: Control OrgStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) - /// Storage: Control Orgs (r:1 w:0) - /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) - /// Storage: Battlepass BattlepassInfoByOrg (r:1 w:1) - /// Proof: Battlepass BattlepassInfoByOrg (max_values: None, max_size: Some(118), added: 2593, mode: MaxEncodedLen) + // Storage: Battlepass Battlepasses (r:1 w:0) + // Storage: Battlepass BattlepassStates (r:1 w:0) + // Storage: Control OrgStates (r:1 w:0) + // Storage: Control Orgs (r:1 w:0) + // Storage: Battlepass BattlepassInfoByOrg (r:1 w:1) fn add_bot() -> Weight { - // Proof Size summary in bytes: - // Measured: `880` - // Estimated: `13263` - // Minimum execution time: 30_000 nanoseconds. - Weight::from_parts(31_000_000, 13263) - .saturating_add(RocksDbWeight::get().reads(5_u64)) - .saturating_add(RocksDbWeight::get().writes(1_u64)) + // Minimum execution time: 35_000 nanoseconds. + Weight::from_ref_time(35_000_000) + .saturating_add(RocksDbWeight::get().reads(5)) + .saturating_add(RocksDbWeight::get().writes(1)) } } \ No newline at end of file diff --git a/control/Cargo.toml b/control/Cargo.toml index b1aa751a6..b3132c03b 100755 --- a/control/Cargo.toml +++ b/control/Cargo.toml @@ -5,7 +5,7 @@ # ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ [package] name = "gamedao-control" -version = "1.3.0" +version = "1.2.0" authors = ["zero.io","gamedao.co"] repository = "https://github.com/gamedaoco/gamedao-protocol" edition = "2018" @@ -17,32 +17,32 @@ hex-literal = "0.3.4" num_enum = { version = "0.5.1", default-features = false } serde = { version = "1.0.143", default-features = false } -codec = { package = "parity-scale-codec", version = "3.2.2", default-features = false, features = ["derive"] } +codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] } scale-info = { version = "2.1.1", default-features = false, features = ["derive"] } -sp-core = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } -sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } -sp-std = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } -sp-storage = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } +sp-core = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } +sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } +sp-std = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } +sp-storage = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } -frame-support = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } -frame-system = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } -frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38", default-features = false, optional = true } -sp-io = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.38", default-features=false } +frame-support = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } +frame-system = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } +frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36", default-features = false, optional = true } +sp-io = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.36", default-features=false } -pallet-balances = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } +pallet-balances = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } -orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.38", default-features = false } +orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.36", default-features = false } gamedao-traits = { package = "gamedao-traits", path = "../traits", default-features = false } # tangram = { package = "module-tangram", path = "../../zero/tangram", default-features = false } [dev-dependencies] -sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.38" } -sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.38" } -pallet-balances = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } -orml-currencies = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.38", default-features = false } -orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.38", default-features = false } +sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.36" } +sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.36" } +pallet-balances = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } +orml-currencies = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.36", default-features = false } +orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.36", default-features = false } [features] default = ["std"] diff --git a/control/src/weights.rs b/control/src/weights.rs index 6583e7cd7..c92926dea 100644 --- a/control/src/weights.rs +++ b/control/src/weights.rs @@ -2,8 +2,7 @@ //! Autogenerated weights for gamedao_control //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-03-04, STEPS: `20`, REPEAT: `10`, LOW RANGE: `[]`, HIGH RANGE: `[]` -//! WORST CASE MAP SIZE: `1000000` +//! DATE: 2023-02-10, STEPS: `20`, REPEAT: 10, LOW RANGE: `[]`, HIGH RANGE: `[]` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: None, DB CACHE: 1024 // Executed Command: @@ -40,282 +39,174 @@ pub trait WeightInfo { /// Weights for gamedao_control using the Substrate node and recommended hardware. pub struct SubstrateWeight(PhantomData); impl WeightInfo for SubstrateWeight { - /// Storage: Control OrgCount (r:1 w:1) - /// Proof: Control OrgCount (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: System Account (r:1 w:1) - /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) - /// Storage: Control Orgs (r:1 w:1) - /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) - /// Storage: Tokens Accounts (r:2 w:2) - /// Proof: Tokens Accounts (max_values: None, max_size: Some(109), added: 2584, mode: MaxEncodedLen) - /// Storage: Control Members (r:1 w:1) - /// Proof: Control Members (max_values: None, max_size: Some(32050), added: 34525, mode: MaxEncodedLen) - /// Storage: Control OrgMemberCount (r:0 w:1) - /// Proof: Control OrgMemberCount (max_values: None, max_size: Some(52), added: 2527, mode: MaxEncodedLen) - /// Storage: Control OrgTreasury (r:0 w:1) - /// Proof: Control OrgTreasury (max_values: None, max_size: Some(80), added: 2555, mode: MaxEncodedLen) - /// Storage: Control MemberStates (r:0 w:1) - /// Proof: Control MemberStates (max_values: None, max_size: Some(97), added: 2572, mode: MaxEncodedLen) - /// Storage: Control OrgStates (r:0 w:1) - /// Proof: Control OrgStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + // Storage: Control OrgCount (r:1 w:1) + // Storage: System Account (r:1 w:1) + // Storage: Control Orgs (r:1 w:1) + // Storage: Tokens Accounts (r:2 w:2) + // Storage: Control Members (r:1 w:1) + // Storage: Control OrgMemberCount (r:0 w:1) + // Storage: Control OrgTreasury (r:0 w:1) + // Storage: Control MemberStates (r:0 w:1) + // Storage: Control OrgStates (r:0 w:1) fn create_org() -> Weight { - // Proof Size summary in bytes: - // Measured: `408` - // Estimated: `45560` - // Minimum execution time: 70_000 nanoseconds. - Weight::from_parts(71_000_000, 45560) - .saturating_add(T::DbWeight::get().reads(6_u64)) - .saturating_add(T::DbWeight::get().writes(10_u64)) + // Minimum execution time: 79_000 nanoseconds. + Weight::from_ref_time(81_000_000) + .saturating_add(T::DbWeight::get().reads(6)) + .saturating_add(T::DbWeight::get().writes(10)) } - /// Storage: Control Orgs (r:1 w:1) - /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) - /// Storage: Control MemberStates (r:1 w:0) - /// Proof: Control MemberStates (max_values: None, max_size: Some(97), added: 2572, mode: MaxEncodedLen) + // Storage: Control Orgs (r:1 w:1) + // Storage: Control MemberStates (r:1 w:0) fn update_org() -> Weight { - // Proof Size summary in bytes: - // Measured: `565` - // Estimated: `5337` - // Minimum execution time: 21_000 nanoseconds. - Weight::from_parts(22_000_000, 5337) - .saturating_add(T::DbWeight::get().reads(2_u64)) - .saturating_add(T::DbWeight::get().writes(1_u64)) + // Minimum execution time: 28_000 nanoseconds. + Weight::from_ref_time(29_000_000) + .saturating_add(T::DbWeight::get().reads(2)) + .saturating_add(T::DbWeight::get().writes(1)) } - /// Storage: Control Orgs (r:1 w:0) - /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) - /// Storage: Control OrgStates (r:0 w:1) - /// Proof: Control OrgStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + // Storage: Control Orgs (r:1 w:0) + // Storage: Control OrgStates (r:0 w:1) fn disable_org() -> Weight { - // Proof Size summary in bytes: - // Measured: `480` - // Estimated: `2765` - // Minimum execution time: 17_000 nanoseconds. - Weight::from_parts(18_000_000, 2765) - .saturating_add(T::DbWeight::get().reads(1_u64)) - .saturating_add(T::DbWeight::get().writes(1_u64)) + // Minimum execution time: 23_000 nanoseconds. + Weight::from_ref_time(24_000_000) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)) } - /// Storage: Control Orgs (r:1 w:0) - /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) - /// Storage: Control OrgStates (r:0 w:1) - /// Proof: Control OrgStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + // Storage: Control Orgs (r:1 w:0) + // Storage: Control OrgStates (r:0 w:1) fn enable_org() -> Weight { - // Proof Size summary in bytes: - // Measured: `480` - // Estimated: `2765` - // Minimum execution time: 17_000 nanoseconds. - Weight::from_parts(17_000_000, 2765) - .saturating_add(T::DbWeight::get().reads(1_u64)) - .saturating_add(T::DbWeight::get().writes(1_u64)) - } - /// Storage: Control Orgs (r:1 w:0) - /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) - /// Storage: Control OrgTreasury (r:1 w:0) - /// Proof: Control OrgTreasury (max_values: None, max_size: Some(80), added: 2555, mode: MaxEncodedLen) - /// Storage: Control Members (r:1 w:1) - /// Proof: Control Members (max_values: None, max_size: Some(32050), added: 34525, mode: MaxEncodedLen) - /// Storage: Control OrgMemberCount (r:0 w:1) - /// Proof: Control OrgMemberCount (max_values: None, max_size: Some(52), added: 2527, mode: MaxEncodedLen) - /// Storage: Control MemberStates (r:0 w:1) - /// Proof: Control MemberStates (max_values: None, max_size: Some(97), added: 2572, mode: MaxEncodedLen) + // Minimum execution time: 24_000 nanoseconds. + Weight::from_ref_time(25_000_000) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)) + } + // Storage: Control Orgs (r:1 w:0) + // Storage: Control OrgTreasury (r:1 w:0) + // Storage: Control Members (r:1 w:1) + // Storage: Control OrgMemberCount (r:0 w:1) + // Storage: Control MemberStates (r:0 w:1) /// The range of component `r` is `[1, 999]`. fn add_member(r: u32, ) -> Weight { - // Proof Size summary in bytes: - // Measured: `659 + r * (32 ±0)` - // Estimated: `39845` - // Minimum execution time: 29_000 nanoseconds. - Weight::from_parts(27_804_864, 39845) - // Standard Error: 897 - .saturating_add(Weight::from_ref_time(34_905).saturating_mul(r.into())) - .saturating_add(T::DbWeight::get().reads(3_u64)) - .saturating_add(T::DbWeight::get().writes(3_u64)) - } - /// Storage: Control Orgs (r:1 w:0) - /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) - /// Storage: Control MemberStates (r:1 w:0) - /// Proof: Control MemberStates (max_values: None, max_size: Some(97), added: 2572, mode: MaxEncodedLen) + // Minimum execution time: 36_000 nanoseconds. + Weight::from_ref_time(34_091_687) + // Standard Error: 1_851 + .saturating_add(Weight::from_ref_time(65_158).saturating_mul(r.into())) + .saturating_add(T::DbWeight::get().reads(3)) + .saturating_add(T::DbWeight::get().writes(3)) + } + // Storage: Control Orgs (r:1 w:0) + // Storage: Control MemberStates (r:1 w:0) fn update_member_state() -> Weight { - // Proof Size summary in bytes: - // Measured: `604` - // Estimated: `5337` - // Minimum execution time: 14_000 nanoseconds. - Weight::from_parts(15_000_000, 5337) - .saturating_add(T::DbWeight::get().reads(2_u64)) - } - /// Storage: Control Orgs (r:1 w:0) - /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) - /// Storage: Control Members (r:1 w:1) - /// Proof: Control Members (max_values: None, max_size: Some(32050), added: 34525, mode: MaxEncodedLen) - /// Storage: Control OrgMemberCount (r:0 w:1) - /// Proof: Control OrgMemberCount (max_values: None, max_size: Some(52), added: 2527, mode: MaxEncodedLen) - /// Storage: Control MemberStates (r:0 w:1) - /// Proof: Control MemberStates (max_values: None, max_size: Some(97), added: 2572, mode: MaxEncodedLen) + // Minimum execution time: 15_000 nanoseconds. + Weight::from_ref_time(16_000_000) + .saturating_add(T::DbWeight::get().reads(2)) + } + // Storage: Control Orgs (r:1 w:0) + // Storage: Control Members (r:1 w:1) + // Storage: Control OrgMemberCount (r:0 w:1) + // Storage: Control MemberStates (r:0 w:1) /// The range of component `r` is `[1, 999]`. fn remove_member(r: u32, ) -> Weight { - // Proof Size summary in bytes: - // Measured: `584 + r * (32 ±0)` - // Estimated: `37290` - // Minimum execution time: 25_000 nanoseconds. - Weight::from_parts(23_223_981, 37290) - // Standard Error: 874 - .saturating_add(Weight::from_ref_time(33_949).saturating_mul(r.into())) - .saturating_add(T::DbWeight::get().reads(2_u64)) - .saturating_add(T::DbWeight::get().writes(3_u64)) - } - /// Storage: Control Orgs (r:1 w:0) - /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) - /// Storage: Control OrgTreasury (r:1 w:0) - /// Proof: Control OrgTreasury (max_values: None, max_size: Some(80), added: 2555, mode: MaxEncodedLen) - /// Storage: Tokens Accounts (r:2 w:2) - /// Proof: Tokens Accounts (max_values: None, max_size: Some(109), added: 2584, mode: MaxEncodedLen) - /// Storage: System Account (r:2 w:1) - /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) + // Minimum execution time: 30_000 nanoseconds. + Weight::from_ref_time(37_544_684) + // Standard Error: 2_351 + .saturating_add(Weight::from_ref_time(43_383).saturating_mul(r.into())) + .saturating_add(T::DbWeight::get().reads(2)) + .saturating_add(T::DbWeight::get().writes(3)) + } + // Storage: Control Orgs (r:1 w:0) + // Storage: Control OrgTreasury (r:1 w:0) + // Storage: Tokens Accounts (r:2 w:2) + // Storage: System Account (r:2 w:1) fn spend_funds() -> Weight { - // Proof Size summary in bytes: - // Measured: `1040` - // Estimated: `15694` - // Minimum execution time: 58_000 nanoseconds. - Weight::from_parts(59_000_000, 15694) - .saturating_add(T::DbWeight::get().reads(6_u64)) - .saturating_add(T::DbWeight::get().writes(3_u64)) + // Minimum execution time: 63_000 nanoseconds. + Weight::from_ref_time(64_000_000) + .saturating_add(T::DbWeight::get().reads(6)) + .saturating_add(T::DbWeight::get().writes(3)) } } // For backwards compatibility and tests impl WeightInfo for () { - /// Storage: Control OrgCount (r:1 w:1) - /// Proof: Control OrgCount (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: System Account (r:1 w:1) - /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) - /// Storage: Control Orgs (r:1 w:1) - /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) - /// Storage: Tokens Accounts (r:2 w:2) - /// Proof: Tokens Accounts (max_values: None, max_size: Some(109), added: 2584, mode: MaxEncodedLen) - /// Storage: Control Members (r:1 w:1) - /// Proof: Control Members (max_values: None, max_size: Some(32050), added: 34525, mode: MaxEncodedLen) - /// Storage: Control OrgMemberCount (r:0 w:1) - /// Proof: Control OrgMemberCount (max_values: None, max_size: Some(52), added: 2527, mode: MaxEncodedLen) - /// Storage: Control OrgTreasury (r:0 w:1) - /// Proof: Control OrgTreasury (max_values: None, max_size: Some(80), added: 2555, mode: MaxEncodedLen) - /// Storage: Control MemberStates (r:0 w:1) - /// Proof: Control MemberStates (max_values: None, max_size: Some(97), added: 2572, mode: MaxEncodedLen) - /// Storage: Control OrgStates (r:0 w:1) - /// Proof: Control OrgStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + // Storage: Control OrgCount (r:1 w:1) + // Storage: System Account (r:1 w:1) + // Storage: Control Orgs (r:1 w:1) + // Storage: Tokens Accounts (r:2 w:2) + // Storage: Control Members (r:1 w:1) + // Storage: Control OrgMemberCount (r:0 w:1) + // Storage: Control OrgTreasury (r:0 w:1) + // Storage: Control MemberStates (r:0 w:1) + // Storage: Control OrgStates (r:0 w:1) fn create_org() -> Weight { - // Proof Size summary in bytes: - // Measured: `408` - // Estimated: `45560` - // Minimum execution time: 70_000 nanoseconds. - Weight::from_parts(71_000_000, 45560) - .saturating_add(RocksDbWeight::get().reads(6_u64)) - .saturating_add(RocksDbWeight::get().writes(10_u64)) + // Minimum execution time: 79_000 nanoseconds. + Weight::from_ref_time(81_000_000) + .saturating_add(RocksDbWeight::get().reads(6)) + .saturating_add(RocksDbWeight::get().writes(10)) } - /// Storage: Control Orgs (r:1 w:1) - /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) - /// Storage: Control MemberStates (r:1 w:0) - /// Proof: Control MemberStates (max_values: None, max_size: Some(97), added: 2572, mode: MaxEncodedLen) + // Storage: Control Orgs (r:1 w:1) + // Storage: Control MemberStates (r:1 w:0) fn update_org() -> Weight { - // Proof Size summary in bytes: - // Measured: `565` - // Estimated: `5337` - // Minimum execution time: 21_000 nanoseconds. - Weight::from_parts(22_000_000, 5337) - .saturating_add(RocksDbWeight::get().reads(2_u64)) - .saturating_add(RocksDbWeight::get().writes(1_u64)) + // Minimum execution time: 28_000 nanoseconds. + Weight::from_ref_time(29_000_000) + .saturating_add(RocksDbWeight::get().reads(2)) + .saturating_add(RocksDbWeight::get().writes(1)) } - /// Storage: Control Orgs (r:1 w:0) - /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) - /// Storage: Control OrgStates (r:0 w:1) - /// Proof: Control OrgStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + // Storage: Control Orgs (r:1 w:0) + // Storage: Control OrgStates (r:0 w:1) fn disable_org() -> Weight { - // Proof Size summary in bytes: - // Measured: `480` - // Estimated: `2765` - // Minimum execution time: 17_000 nanoseconds. - Weight::from_parts(18_000_000, 2765) - .saturating_add(RocksDbWeight::get().reads(1_u64)) - .saturating_add(RocksDbWeight::get().writes(1_u64)) + // Minimum execution time: 23_000 nanoseconds. + Weight::from_ref_time(24_000_000) + .saturating_add(RocksDbWeight::get().reads(1)) + .saturating_add(RocksDbWeight::get().writes(1)) } - /// Storage: Control Orgs (r:1 w:0) - /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) - /// Storage: Control OrgStates (r:0 w:1) - /// Proof: Control OrgStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + // Storage: Control Orgs (r:1 w:0) + // Storage: Control OrgStates (r:0 w:1) fn enable_org() -> Weight { - // Proof Size summary in bytes: - // Measured: `480` - // Estimated: `2765` - // Minimum execution time: 17_000 nanoseconds. - Weight::from_parts(17_000_000, 2765) - .saturating_add(RocksDbWeight::get().reads(1_u64)) - .saturating_add(RocksDbWeight::get().writes(1_u64)) - } - /// Storage: Control Orgs (r:1 w:0) - /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) - /// Storage: Control OrgTreasury (r:1 w:0) - /// Proof: Control OrgTreasury (max_values: None, max_size: Some(80), added: 2555, mode: MaxEncodedLen) - /// Storage: Control Members (r:1 w:1) - /// Proof: Control Members (max_values: None, max_size: Some(32050), added: 34525, mode: MaxEncodedLen) - /// Storage: Control OrgMemberCount (r:0 w:1) - /// Proof: Control OrgMemberCount (max_values: None, max_size: Some(52), added: 2527, mode: MaxEncodedLen) - /// Storage: Control MemberStates (r:0 w:1) - /// Proof: Control MemberStates (max_values: None, max_size: Some(97), added: 2572, mode: MaxEncodedLen) + // Minimum execution time: 24_000 nanoseconds. + Weight::from_ref_time(25_000_000) + .saturating_add(RocksDbWeight::get().reads(1)) + .saturating_add(RocksDbWeight::get().writes(1)) + } + // Storage: Control Orgs (r:1 w:0) + // Storage: Control OrgTreasury (r:1 w:0) + // Storage: Control Members (r:1 w:1) + // Storage: Control OrgMemberCount (r:0 w:1) + // Storage: Control MemberStates (r:0 w:1) /// The range of component `r` is `[1, 999]`. fn add_member(r: u32, ) -> Weight { - // Proof Size summary in bytes: - // Measured: `659 + r * (32 ±0)` - // Estimated: `39845` - // Minimum execution time: 29_000 nanoseconds. - Weight::from_parts(27_804_864, 39845) - // Standard Error: 897 - .saturating_add(Weight::from_ref_time(34_905).saturating_mul(r.into())) - .saturating_add(RocksDbWeight::get().reads(3_u64)) - .saturating_add(RocksDbWeight::get().writes(3_u64)) - } - /// Storage: Control Orgs (r:1 w:0) - /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) - /// Storage: Control MemberStates (r:1 w:0) - /// Proof: Control MemberStates (max_values: None, max_size: Some(97), added: 2572, mode: MaxEncodedLen) + // Minimum execution time: 36_000 nanoseconds. + Weight::from_ref_time(34_091_687) + // Standard Error: 1_851 + .saturating_add(Weight::from_ref_time(65_158).saturating_mul(r.into())) + .saturating_add(RocksDbWeight::get().reads(3)) + .saturating_add(RocksDbWeight::get().writes(3)) + } + // Storage: Control Orgs (r:1 w:0) + // Storage: Control MemberStates (r:1 w:0) fn update_member_state() -> Weight { - // Proof Size summary in bytes: - // Measured: `604` - // Estimated: `5337` - // Minimum execution time: 14_000 nanoseconds. - Weight::from_parts(15_000_000, 5337) - .saturating_add(RocksDbWeight::get().reads(2_u64)) - } - /// Storage: Control Orgs (r:1 w:0) - /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) - /// Storage: Control Members (r:1 w:1) - /// Proof: Control Members (max_values: None, max_size: Some(32050), added: 34525, mode: MaxEncodedLen) - /// Storage: Control OrgMemberCount (r:0 w:1) - /// Proof: Control OrgMemberCount (max_values: None, max_size: Some(52), added: 2527, mode: MaxEncodedLen) - /// Storage: Control MemberStates (r:0 w:1) - /// Proof: Control MemberStates (max_values: None, max_size: Some(97), added: 2572, mode: MaxEncodedLen) + // Minimum execution time: 15_000 nanoseconds. + Weight::from_ref_time(16_000_000) + .saturating_add(RocksDbWeight::get().reads(2)) + } + // Storage: Control Orgs (r:1 w:0) + // Storage: Control Members (r:1 w:1) + // Storage: Control OrgMemberCount (r:0 w:1) + // Storage: Control MemberStates (r:0 w:1) /// The range of component `r` is `[1, 999]`. fn remove_member(r: u32, ) -> Weight { - // Proof Size summary in bytes: - // Measured: `584 + r * (32 ±0)` - // Estimated: `37290` - // Minimum execution time: 25_000 nanoseconds. - Weight::from_parts(23_223_981, 37290) - // Standard Error: 874 - .saturating_add(Weight::from_ref_time(33_949).saturating_mul(r.into())) - .saturating_add(RocksDbWeight::get().reads(2_u64)) - .saturating_add(RocksDbWeight::get().writes(3_u64)) - } - /// Storage: Control Orgs (r:1 w:0) - /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) - /// Storage: Control OrgTreasury (r:1 w:0) - /// Proof: Control OrgTreasury (max_values: None, max_size: Some(80), added: 2555, mode: MaxEncodedLen) - /// Storage: Tokens Accounts (r:2 w:2) - /// Proof: Tokens Accounts (max_values: None, max_size: Some(109), added: 2584, mode: MaxEncodedLen) - /// Storage: System Account (r:2 w:1) - /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) + // Minimum execution time: 30_000 nanoseconds. + Weight::from_ref_time(37_544_684) + // Standard Error: 2_351 + .saturating_add(Weight::from_ref_time(43_383).saturating_mul(r.into())) + .saturating_add(RocksDbWeight::get().reads(2)) + .saturating_add(RocksDbWeight::get().writes(3)) + } + // Storage: Control Orgs (r:1 w:0) + // Storage: Control OrgTreasury (r:1 w:0) + // Storage: Tokens Accounts (r:2 w:2) + // Storage: System Account (r:2 w:1) fn spend_funds() -> Weight { - // Proof Size summary in bytes: - // Measured: `1040` - // Estimated: `15694` - // Minimum execution time: 58_000 nanoseconds. - Weight::from_parts(59_000_000, 15694) - .saturating_add(RocksDbWeight::get().reads(6_u64)) - .saturating_add(RocksDbWeight::get().writes(3_u64)) + // Minimum execution time: 63_000 nanoseconds. + Weight::from_ref_time(64_000_000) + .saturating_add(RocksDbWeight::get().reads(6)) + .saturating_add(RocksDbWeight::get().writes(3)) } } \ No newline at end of file diff --git a/flow/Cargo.toml b/flow/Cargo.toml index cfb515e01..bb918ccc0 100644 --- a/flow/Cargo.toml +++ b/flow/Cargo.toml @@ -6,7 +6,7 @@ [package] name = "gamedao-flow" -version = "1.3.0" +version = "1.2.0" authors = ["zero.io","gamedao.co"] edition = "2018" license = "GPL-3.0-or-later" @@ -15,27 +15,27 @@ repository = "https://github.com/gamedaoco/gamedao-protocol" [dependencies] serde = { version = "1.0.143", default-features = false } -codec = { package = "parity-scale-codec", version = "3.2.2", default-features = false, features = ["derive"] } +codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] } scale-info = { version = "2.1.1", default-features = false, features = ["derive"] } -sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38", default-features = false } -sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38", default-features = false } -frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38", default-features = false } -frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38", default-features = false } -frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38", default-features = false, optional = true } -sp-io = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.38", default-features=false } +sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36", default-features = false } +sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36", default-features = false } +frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36", default-features = false } +frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36", default-features = false } +frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36", default-features = false, optional = true } +sp-io = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.36", default-features=false } -orml-currencies = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.38", default-features = false } -orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.38", default-features = false } -orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.38", default-features = false } +orml-currencies = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.36", default-features = false } +orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.36", default-features = false } +orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.36", default-features = false } gamedao-traits = { package = "gamedao-traits", path = "../traits", default-features = false } gamedao-control = { package = "gamedao-control", path = "../control", default-features = false } [dev-dependencies] -sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.38" } +sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.36" } -pallet-timestamp = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } -pallet-balances = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } +pallet-timestamp = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } +pallet-balances = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } gamedao-control = { package = "gamedao-control", path = "../control", default-features = true } diff --git a/flow/src/weights.rs b/flow/src/weights.rs index 6f7abf2d2..f18793861 100644 --- a/flow/src/weights.rs +++ b/flow/src/weights.rs @@ -2,8 +2,7 @@ //! Autogenerated weights for gamedao_flow //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-03-04, STEPS: `20`, REPEAT: `10`, LOW RANGE: `[]`, HIGH RANGE: `[]` -//! WORST CASE MAP SIZE: `1000000` +//! DATE: 2023-02-10, STEPS: `20`, REPEAT: 10, LOW RANGE: `[]`, HIGH RANGE: `[]` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: None, DB CACHE: 1024 // Executed Command: @@ -35,166 +34,104 @@ pub trait WeightInfo { /// Weights for gamedao_flow using the Substrate node and recommended hardware. pub struct SubstrateWeight(PhantomData); impl WeightInfo for SubstrateWeight { - /// Storage: Control Orgs (r:1 w:0) - /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) - /// Storage: Flow CampaignCount (r:1 w:1) - /// Proof: Flow CampaignCount (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: Flow CampaignsByBlock (r:2 w:2) - /// Proof: Flow CampaignsByBlock (max_values: None, max_size: Some(358), added: 2833, mode: MaxEncodedLen) - /// Storage: Control OrgTreasury (r:1 w:0) - /// Proof: Control OrgTreasury (max_values: None, max_size: Some(80), added: 2555, mode: MaxEncodedLen) - /// Storage: Tokens Accounts (r:1 w:1) - /// Proof: Tokens Accounts (max_values: None, max_size: Some(109), added: 2584, mode: MaxEncodedLen) - /// Storage: Flow CampaignOf (r:0 w:1) - /// Proof: Flow CampaignOf (max_values: None, max_size: Some(460), added: 2935, mode: MaxEncodedLen) - /// Storage: Flow CampaignStates (r:0 w:1) - /// Proof: Flow CampaignStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + // Storage: Control Orgs (r:1 w:0) + // Storage: Flow CampaignCount (r:1 w:1) + // Storage: Flow CampaignsByBlock (r:2 w:2) + // Storage: Control OrgTreasury (r:1 w:0) + // Storage: Tokens Accounts (r:1 w:1) + // Storage: Flow CampaignOf (r:0 w:1) + // Storage: Flow CampaignStates (r:0 w:1) fn create_campaign() -> Weight { - // Proof Size summary in bytes: - // Measured: `1009` - // Estimated: `14069` - // Minimum execution time: 57_000 nanoseconds. - Weight::from_parts(58_000_000, 14069) - .saturating_add(T::DbWeight::get().reads(6_u64)) - .saturating_add(T::DbWeight::get().writes(6_u64)) + // Minimum execution time: 64_000 nanoseconds. + Weight::from_ref_time(67_000_000) + .saturating_add(T::DbWeight::get().reads(6)) + .saturating_add(T::DbWeight::get().writes(6)) } - /// Storage: Flow CampaignOf (r:1 w:0) - /// Proof: Flow CampaignOf (max_values: None, max_size: Some(460), added: 2935, mode: MaxEncodedLen) - /// Storage: Flow CampaignStates (r:1 w:0) - /// Proof: Flow CampaignStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) - /// Storage: Flow CampaignContribution (r:1 w:1) - /// Proof: Flow CampaignContribution (max_values: None, max_size: Some(112), added: 2587, mode: MaxEncodedLen) - /// Storage: Flow CampaignContributorsCount (r:1 w:1) - /// Proof: Flow CampaignContributorsCount (max_values: None, max_size: Some(56), added: 2531, mode: MaxEncodedLen) - /// Storage: Tokens Accounts (r:1 w:1) - /// Proof: Tokens Accounts (max_values: None, max_size: Some(109), added: 2584, mode: MaxEncodedLen) - /// Storage: Flow CampaignBalance (r:1 w:1) - /// Proof: Flow CampaignBalance (max_values: None, max_size: Some(64), added: 2539, mode: MaxEncodedLen) + // Storage: Flow CampaignOf (r:1 w:0) + // Storage: Flow CampaignStates (r:1 w:0) + // Storage: Flow CampaignContribution (r:1 w:1) + // Storage: Flow CampaignContributorsCount (r:1 w:1) + // Storage: Tokens Accounts (r:1 w:1) + // Storage: Flow CampaignBalance (r:1 w:1) fn contribute() -> Weight { - // Proof Size summary in bytes: - // Measured: `1104` - // Estimated: `15700` - // Minimum execution time: 48_000 nanoseconds. - Weight::from_parts(51_000_000, 15700) - .saturating_add(T::DbWeight::get().reads(6_u64)) - .saturating_add(T::DbWeight::get().writes(4_u64)) + // Minimum execution time: 56_000 nanoseconds. + Weight::from_ref_time(58_000_000) + .saturating_add(T::DbWeight::get().reads(6)) + .saturating_add(T::DbWeight::get().writes(4)) } - /// Storage: Flow CampaignsByBlock (r:1 w:0) - /// Proof: Flow CampaignsByBlock (max_values: None, max_size: Some(358), added: 2833, mode: MaxEncodedLen) - /// Storage: Flow CampaignStates (r:10 w:11) - /// Proof: Flow CampaignStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) - /// Storage: Flow CampaignFinalizationQueue (r:2 w:1) - /// Proof: Flow CampaignFinalizationQueue (max_values: None, max_size: Some(320511), added: 322986, mode: MaxEncodedLen) - /// Storage: Flow CampaignContribution (r:100 w:0) - /// Proof: Flow CampaignContribution (max_values: None, max_size: Some(112), added: 2587, mode: MaxEncodedLen) - /// Storage: Tokens Accounts (r:102 w:102) - /// Proof: Tokens Accounts (max_values: None, max_size: Some(109), added: 2584, mode: MaxEncodedLen) - /// Storage: System Account (r:1 w:1) - /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) - /// Storage: Flow CampaignBalance (r:0 w:1) - /// Proof: Flow CampaignBalance (max_values: None, max_size: Some(64), added: 2539, mode: MaxEncodedLen) + // Storage: Flow CampaignsByBlock (r:1 w:0) + // Storage: Flow CampaignStates (r:10 w:11) + // Storage: Flow CampaignFinalizationQueue (r:2 w:1) + // Storage: Tokens Accounts (r:1 w:1) + // Storage: Flow CampaignContribution (r:5 w:0) + // Storage: System Account (r:1 w:1) + // Storage: Flow CampaignBalance (r:0 w:1) /// The range of component `c` is `[0, 100]`. /// The range of component `p` is `[0, 10]`. fn on_initialize(c: u32, p: u32, ) -> Weight { - // Proof Size summary in bytes: - // Measured: `1615 + c * (288 ±0) + p * (87 ±0)` - // Estimated: `655398 + c * (5182 ±0) + p * (2558 ±12)` - // Minimum execution time: 136_000 nanoseconds. - Weight::from_parts(62_296_021, 655398) - // Standard Error: 59_341 - .saturating_add(Weight::from_ref_time(25_969_615).saturating_mul(c.into())) - // Standard Error: 593_322 - .saturating_add(Weight::from_ref_time(10_250_535).saturating_mul(p.into())) - .saturating_add(T::DbWeight::get().reads(5_u64)) + // Minimum execution time: 134_000 nanoseconds. + Weight::from_ref_time(68_040_945) + // Standard Error: 55_163 + .saturating_add(Weight::from_ref_time(25_455_935).saturating_mul(c.into())) + // Standard Error: 551_554 + .saturating_add(Weight::from_ref_time(9_852_261).saturating_mul(p.into())) + .saturating_add(T::DbWeight::get().reads(5)) .saturating_add(T::DbWeight::get().reads((2_u64).saturating_mul(c.into()))) .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(p.into()))) - .saturating_add(T::DbWeight::get().writes(5_u64)) + .saturating_add(T::DbWeight::get().writes(5)) .saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(c.into()))) .saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(p.into()))) - .saturating_add(Weight::from_proof_size(5182).saturating_mul(c.into())) - .saturating_add(Weight::from_proof_size(2558).saturating_mul(p.into())) } } // For backwards compatibility and tests impl WeightInfo for () { - /// Storage: Control Orgs (r:1 w:0) - /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) - /// Storage: Flow CampaignCount (r:1 w:1) - /// Proof: Flow CampaignCount (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: Flow CampaignsByBlock (r:2 w:2) - /// Proof: Flow CampaignsByBlock (max_values: None, max_size: Some(358), added: 2833, mode: MaxEncodedLen) - /// Storage: Control OrgTreasury (r:1 w:0) - /// Proof: Control OrgTreasury (max_values: None, max_size: Some(80), added: 2555, mode: MaxEncodedLen) - /// Storage: Tokens Accounts (r:1 w:1) - /// Proof: Tokens Accounts (max_values: None, max_size: Some(109), added: 2584, mode: MaxEncodedLen) - /// Storage: Flow CampaignOf (r:0 w:1) - /// Proof: Flow CampaignOf (max_values: None, max_size: Some(460), added: 2935, mode: MaxEncodedLen) - /// Storage: Flow CampaignStates (r:0 w:1) - /// Proof: Flow CampaignStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + // Storage: Control Orgs (r:1 w:0) + // Storage: Flow CampaignCount (r:1 w:1) + // Storage: Flow CampaignsByBlock (r:2 w:2) + // Storage: Control OrgTreasury (r:1 w:0) + // Storage: Tokens Accounts (r:1 w:1) + // Storage: Flow CampaignOf (r:0 w:1) + // Storage: Flow CampaignStates (r:0 w:1) fn create_campaign() -> Weight { - // Proof Size summary in bytes: - // Measured: `1009` - // Estimated: `14069` - // Minimum execution time: 57_000 nanoseconds. - Weight::from_parts(58_000_000, 14069) - .saturating_add(RocksDbWeight::get().reads(6_u64)) - .saturating_add(RocksDbWeight::get().writes(6_u64)) + // Minimum execution time: 64_000 nanoseconds. + Weight::from_ref_time(67_000_000) + .saturating_add(RocksDbWeight::get().reads(6)) + .saturating_add(RocksDbWeight::get().writes(6)) } - /// Storage: Flow CampaignOf (r:1 w:0) - /// Proof: Flow CampaignOf (max_values: None, max_size: Some(460), added: 2935, mode: MaxEncodedLen) - /// Storage: Flow CampaignStates (r:1 w:0) - /// Proof: Flow CampaignStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) - /// Storage: Flow CampaignContribution (r:1 w:1) - /// Proof: Flow CampaignContribution (max_values: None, max_size: Some(112), added: 2587, mode: MaxEncodedLen) - /// Storage: Flow CampaignContributorsCount (r:1 w:1) - /// Proof: Flow CampaignContributorsCount (max_values: None, max_size: Some(56), added: 2531, mode: MaxEncodedLen) - /// Storage: Tokens Accounts (r:1 w:1) - /// Proof: Tokens Accounts (max_values: None, max_size: Some(109), added: 2584, mode: MaxEncodedLen) - /// Storage: Flow CampaignBalance (r:1 w:1) - /// Proof: Flow CampaignBalance (max_values: None, max_size: Some(64), added: 2539, mode: MaxEncodedLen) + // Storage: Flow CampaignOf (r:1 w:0) + // Storage: Flow CampaignStates (r:1 w:0) + // Storage: Flow CampaignContribution (r:1 w:1) + // Storage: Flow CampaignContributorsCount (r:1 w:1) + // Storage: Tokens Accounts (r:1 w:1) + // Storage: Flow CampaignBalance (r:1 w:1) fn contribute() -> Weight { - // Proof Size summary in bytes: - // Measured: `1104` - // Estimated: `15700` - // Minimum execution time: 48_000 nanoseconds. - Weight::from_parts(51_000_000, 15700) - .saturating_add(RocksDbWeight::get().reads(6_u64)) - .saturating_add(RocksDbWeight::get().writes(4_u64)) + // Minimum execution time: 56_000 nanoseconds. + Weight::from_ref_time(58_000_000) + .saturating_add(RocksDbWeight::get().reads(6)) + .saturating_add(RocksDbWeight::get().writes(4)) } - /// Storage: Flow CampaignsByBlock (r:1 w:0) - /// Proof: Flow CampaignsByBlock (max_values: None, max_size: Some(358), added: 2833, mode: MaxEncodedLen) - /// Storage: Flow CampaignStates (r:10 w:11) - /// Proof: Flow CampaignStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) - /// Storage: Flow CampaignFinalizationQueue (r:2 w:1) - /// Proof: Flow CampaignFinalizationQueue (max_values: None, max_size: Some(320511), added: 322986, mode: MaxEncodedLen) - /// Storage: Flow CampaignContribution (r:100 w:0) - /// Proof: Flow CampaignContribution (max_values: None, max_size: Some(112), added: 2587, mode: MaxEncodedLen) - /// Storage: Tokens Accounts (r:102 w:102) - /// Proof: Tokens Accounts (max_values: None, max_size: Some(109), added: 2584, mode: MaxEncodedLen) - /// Storage: System Account (r:1 w:1) - /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) - /// Storage: Flow CampaignBalance (r:0 w:1) - /// Proof: Flow CampaignBalance (max_values: None, max_size: Some(64), added: 2539, mode: MaxEncodedLen) + // Storage: Flow CampaignsByBlock (r:1 w:0) + // Storage: Flow CampaignStates (r:10 w:11) + // Storage: Flow CampaignFinalizationQueue (r:2 w:1) + // Storage: Tokens Accounts (r:1 w:1) + // Storage: Flow CampaignContribution (r:5 w:0) + // Storage: System Account (r:1 w:1) + // Storage: Flow CampaignBalance (r:0 w:1) /// The range of component `c` is `[0, 100]`. /// The range of component `p` is `[0, 10]`. fn on_initialize(c: u32, p: u32, ) -> Weight { - // Proof Size summary in bytes: - // Measured: `1615 + c * (288 ±0) + p * (87 ±0)` - // Estimated: `655398 + c * (5182 ±0) + p * (2558 ±12)` - // Minimum execution time: 136_000 nanoseconds. - Weight::from_parts(62_296_021, 655398) - // Standard Error: 59_341 - .saturating_add(Weight::from_ref_time(25_969_615).saturating_mul(c.into())) - // Standard Error: 593_322 - .saturating_add(Weight::from_ref_time(10_250_535).saturating_mul(p.into())) - .saturating_add(RocksDbWeight::get().reads(5_u64)) + // Minimum execution time: 134_000 nanoseconds. + Weight::from_ref_time(68_040_945) + // Standard Error: 55_163 + .saturating_add(Weight::from_ref_time(25_455_935).saturating_mul(c.into())) + // Standard Error: 551_554 + .saturating_add(Weight::from_ref_time(9_852_261).saturating_mul(p.into())) + .saturating_add(RocksDbWeight::get().reads(5)) .saturating_add(RocksDbWeight::get().reads((2_u64).saturating_mul(c.into()))) .saturating_add(RocksDbWeight::get().reads((1_u64).saturating_mul(p.into()))) - .saturating_add(RocksDbWeight::get().writes(5_u64)) + .saturating_add(RocksDbWeight::get().writes(5)) .saturating_add(RocksDbWeight::get().writes((1_u64).saturating_mul(c.into()))) .saturating_add(RocksDbWeight::get().writes((1_u64).saturating_mul(p.into()))) - .saturating_add(Weight::from_proof_size(5182).saturating_mul(c.into())) - .saturating_add(Weight::from_proof_size(2558).saturating_mul(p.into())) } } \ No newline at end of file diff --git a/sense/Cargo.toml b/sense/Cargo.toml index 4d408d69c..0da91af93 100755 --- a/sense/Cargo.toml +++ b/sense/Cargo.toml @@ -6,7 +6,7 @@ [package] name = "gamedao-sense" -version = "1.3.0" +version = "1.2.0" authors = ["zero.io","gamedao.co"] edition = "2018" license = "GPL-3.0-or-later" @@ -21,18 +21,18 @@ categories = [ [dependencies] serde = { version = "1.0.143", default-features = false } -codec = { package = "parity-scale-codec", version = "3.2.2", default-features = false, features = ["derive"] } +codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] } scale-info = { version = "2.1.1", default-features = false, features = ["derive"] } -sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38", default-features = false } -sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38", default-features = false } -frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38", default-features = false } -frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38", default-features = false } -frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38", default-features = false, optional = true } +sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36", default-features = false } +sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36", default-features = false } +frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36", default-features = false } +frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36", default-features = false } +frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36", default-features = false, optional = true } [dev-dependencies] -sp-io = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.38" } -sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.38" } -sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.38" } +sp-io = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.36" } +sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.36" } +sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.36" } [features] default = ["std"] diff --git a/sense/src/weights.rs b/sense/src/weights.rs index 6e53933e1..6cb9c27c3 100644 --- a/sense/src/weights.rs +++ b/sense/src/weights.rs @@ -2,8 +2,7 @@ //! Autogenerated weights for gamedao_sense //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-03-04, STEPS: `20`, REPEAT: `10`, LOW RANGE: `[]`, HIGH RANGE: `[]` -//! WORST CASE MAP SIZE: `1000000` +//! DATE: 2023-02-10, STEPS: `20`, REPEAT: 10, LOW RANGE: `[]`, HIGH RANGE: `[]` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: None, DB CACHE: 1024 // Executed Command: @@ -34,64 +33,42 @@ pub trait WeightInfo { /// Weights for gamedao_sense using the Substrate node and recommended hardware. pub struct SubstrateWeight(PhantomData); impl WeightInfo for SubstrateWeight { - /// Storage: Sense Entities (r:1 w:1) - /// Proof: Sense Entities (max_values: None, max_size: Some(170), added: 2645, mode: MaxEncodedLen) - /// Storage: Sense EntityCount (r:1 w:1) - /// Proof: Sense EntityCount (max_values: Some(1), max_size: Some(16), added: 511, mode: MaxEncodedLen) - /// Storage: Sense Properties (r:0 w:3) - /// Proof: Sense Properties (max_values: None, max_size: Some(77), added: 2552, mode: MaxEncodedLen) + // Storage: Sense Entities (r:1 w:1) + // Storage: Sense EntityCount (r:1 w:1) + // Storage: Sense Properties (r:0 w:3) fn create_entity() -> Weight { - // Proof Size summary in bytes: - // Measured: `142` - // Estimated: `3156` - // Minimum execution time: 21_000 nanoseconds. - Weight::from_parts(22_000_000, 3156) - .saturating_add(T::DbWeight::get().reads(2_u64)) - .saturating_add(T::DbWeight::get().writes(5_u64)) + // Minimum execution time: 27_000 nanoseconds. + Weight::from_ref_time(29_000_000) + .saturating_add(T::DbWeight::get().reads(2)) + .saturating_add(T::DbWeight::get().writes(5)) } - /// Storage: Sense Entities (r:1 w:0) - /// Proof: Sense Entities (max_values: None, max_size: Some(170), added: 2645, mode: MaxEncodedLen) - /// Storage: Sense Properties (r:1 w:1) - /// Proof: Sense Properties (max_values: None, max_size: Some(77), added: 2552, mode: MaxEncodedLen) + // Storage: Sense Entities (r:1 w:0) + // Storage: Sense Properties (r:1 w:1) fn update_property() -> Weight { - // Proof Size summary in bytes: - // Measured: `452` - // Estimated: `5197` - // Minimum execution time: 20_000 nanoseconds. - Weight::from_parts(21_000_000, 5197) - .saturating_add(T::DbWeight::get().reads(2_u64)) - .saturating_add(T::DbWeight::get().writes(1_u64)) + // Minimum execution time: 25_000 nanoseconds. + Weight::from_ref_time(26_000_000) + .saturating_add(T::DbWeight::get().reads(2)) + .saturating_add(T::DbWeight::get().writes(1)) } } // For backwards compatibility and tests impl WeightInfo for () { - /// Storage: Sense Entities (r:1 w:1) - /// Proof: Sense Entities (max_values: None, max_size: Some(170), added: 2645, mode: MaxEncodedLen) - /// Storage: Sense EntityCount (r:1 w:1) - /// Proof: Sense EntityCount (max_values: Some(1), max_size: Some(16), added: 511, mode: MaxEncodedLen) - /// Storage: Sense Properties (r:0 w:3) - /// Proof: Sense Properties (max_values: None, max_size: Some(77), added: 2552, mode: MaxEncodedLen) + // Storage: Sense Entities (r:1 w:1) + // Storage: Sense EntityCount (r:1 w:1) + // Storage: Sense Properties (r:0 w:3) fn create_entity() -> Weight { - // Proof Size summary in bytes: - // Measured: `142` - // Estimated: `3156` - // Minimum execution time: 21_000 nanoseconds. - Weight::from_parts(22_000_000, 3156) - .saturating_add(RocksDbWeight::get().reads(2_u64)) - .saturating_add(RocksDbWeight::get().writes(5_u64)) + // Minimum execution time: 27_000 nanoseconds. + Weight::from_ref_time(29_000_000) + .saturating_add(RocksDbWeight::get().reads(2)) + .saturating_add(RocksDbWeight::get().writes(5)) } - /// Storage: Sense Entities (r:1 w:0) - /// Proof: Sense Entities (max_values: None, max_size: Some(170), added: 2645, mode: MaxEncodedLen) - /// Storage: Sense Properties (r:1 w:1) - /// Proof: Sense Properties (max_values: None, max_size: Some(77), added: 2552, mode: MaxEncodedLen) + // Storage: Sense Entities (r:1 w:0) + // Storage: Sense Properties (r:1 w:1) fn update_property() -> Weight { - // Proof Size summary in bytes: - // Measured: `452` - // Estimated: `5197` - // Minimum execution time: 20_000 nanoseconds. - Weight::from_parts(21_000_000, 5197) - .saturating_add(RocksDbWeight::get().reads(2_u64)) - .saturating_add(RocksDbWeight::get().writes(1_u64)) + // Minimum execution time: 25_000 nanoseconds. + Weight::from_ref_time(26_000_000) + .saturating_add(RocksDbWeight::get().reads(2)) + .saturating_add(RocksDbWeight::get().writes(1)) } } \ No newline at end of file diff --git a/signal/Cargo.toml b/signal/Cargo.toml index d5e1264c5..08d0e594e 100644 --- a/signal/Cargo.toml +++ b/signal/Cargo.toml @@ -6,7 +6,7 @@ [package] name = "gamedao-signal" -version = "1.3.0" +version = "1.2.0" authors = ["zero.io","gamedao.co"] repository = "https://github.com/gamedaoco/gamedao-protocol" edition = "2018" @@ -22,26 +22,26 @@ categories = [ [dependencies] serde = { version = "1.0.143", default-features = false } -codec = { package = "parity-scale-codec", version = "3.2.2", default-features = false, features = ["derive"] } +codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] } scale-info = { version = "2.1.1", default-features = false, features = ["derive"] } -sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38", default-features = false } -sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38", default-features = false } -frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38", default-features = false } -frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38", default-features = false } -frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38", default-features = false, optional = true } -orml-traits = { git = 'https://github.com/open-web3-stack/open-runtime-module-library', branch= "polkadot-v0.9.38", default-features = false } +sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36", default-features = false } +sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36", default-features = false } +frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36", default-features = false } +frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36", default-features = false } +frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36", default-features = false, optional = true } +orml-traits = { git = 'https://github.com/open-web3-stack/open-runtime-module-library', branch= 'polkadot-v0.9.36', default-features = false } gamedao-traits = { package = "gamedao-traits", path = "../traits", default-features = false } -sp-io = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.38", default-features=false } +sp-io = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.36", default-features=false } [dev-dependencies] -sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.38" } -sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.38" } +sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.36" } +sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.36" } -pallet-balances = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } -pallet-timestamp = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } +pallet-balances = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } +pallet-timestamp = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } -orml-currencies = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.38", default-features = false } -orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.38", default-features = false } +orml-currencies = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.36", default-features = false } +orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.36", default-features = false } gamedao-control = { path = "../control", default-features = true } gamedao-flow = { path = "../flow", default-features = true } diff --git a/signal/src/weights.rs b/signal/src/weights.rs index 03dd2aba9..77e1a232f 100644 --- a/signal/src/weights.rs +++ b/signal/src/weights.rs @@ -2,8 +2,7 @@ //! Autogenerated weights for gamedao_signal //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-03-04, STEPS: `20`, REPEAT: `10`, LOW RANGE: `[]`, HIGH RANGE: `[]` -//! WORST CASE MAP SIZE: `1000000` +//! DATE: 2023-02-10, STEPS: `20`, REPEAT: 10, LOW RANGE: `[]`, HIGH RANGE: `[]` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: None, DB CACHE: 1024 // Executed Command: @@ -35,152 +34,94 @@ pub trait WeightInfo { /// Weights for gamedao_signal using the Substrate node and recommended hardware. pub struct SubstrateWeight(PhantomData); impl WeightInfo for SubstrateWeight { - /// Storage: Control OrgStates (r:1 w:0) - /// Proof: Control OrgStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) - /// Storage: Control MemberStates (r:1 w:0) - /// Proof: Control MemberStates (max_values: None, max_size: Some(97), added: 2572, mode: MaxEncodedLen) - /// Storage: Signal ProposalCount (r:1 w:1) - /// Proof: Signal ProposalCount (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: Signal ProposalOf (r:1 w:1) - /// Proof: Signal ProposalOf (max_values: None, max_size: Some(363), added: 2838, mode: MaxEncodedLen) - /// Storage: Tokens Accounts (r:2 w:2) - /// Proof: Tokens Accounts (max_values: None, max_size: Some(109), added: 2584, mode: MaxEncodedLen) - /// Storage: Control OrgTreasury (r:1 w:0) - /// Proof: Control OrgTreasury (max_values: None, max_size: Some(80), added: 2555, mode: MaxEncodedLen) - /// Storage: Signal ProposalsByBlock (r:2 w:2) - /// Proof: Signal ProposalsByBlock (max_values: None, max_size: Some(3239), added: 5714, mode: MaxEncodedLen) - /// Storage: Control OrgMemberCount (r:1 w:0) - /// Proof: Control OrgMemberCount (max_values: None, max_size: Some(52), added: 2527, mode: MaxEncodedLen) - /// Storage: Signal ProposalVoting (r:0 w:1) - /// Proof: Signal ProposalVoting (max_values: None, max_size: Some(130112), added: 132587, mode: MaxEncodedLen) - /// Storage: Signal ProposalStates (r:0 w:1) - /// Proof: Signal ProposalStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + // Storage: Control OrgStates (r:1 w:0) + // Storage: Control MemberStates (r:1 w:0) + // Storage: Signal ProposalCount (r:1 w:1) + // Storage: Signal ProposalOf (r:1 w:1) + // Storage: Tokens Accounts (r:2 w:2) + // Storage: Control OrgTreasury (r:1 w:0) + // Storage: Signal ProposalsByBlock (r:2 w:2) + // Storage: Control OrgMemberCount (r:1 w:0) + // Storage: Signal ProposalVoting (r:0 w:1) + // Storage: Signal ProposalStates (r:0 w:1) fn proposal() -> Weight { - // Proof Size summary in bytes: - // Measured: `1390` - // Estimated: `30111` - // Minimum execution time: 82_000 nanoseconds. - Weight::from_parts(82_000_000, 30111) - .saturating_add(T::DbWeight::get().reads(10_u64)) - .saturating_add(T::DbWeight::get().writes(8_u64)) + // Minimum execution time: 90_000 nanoseconds. + Weight::from_ref_time(94_000_000) + .saturating_add(T::DbWeight::get().reads(10)) + .saturating_add(T::DbWeight::get().writes(8)) } - /// Storage: Signal ProposalVoting (r:1 w:1) - /// Proof: Signal ProposalVoting (max_values: None, max_size: Some(130112), added: 132587, mode: MaxEncodedLen) - /// Storage: Signal ProposalOf (r:1 w:0) - /// Proof: Signal ProposalOf (max_values: None, max_size: Some(363), added: 2838, mode: MaxEncodedLen) - /// Storage: Control MemberStates (r:1 w:0) - /// Proof: Control MemberStates (max_values: None, max_size: Some(97), added: 2572, mode: MaxEncodedLen) - /// Storage: Signal ProposalStates (r:1 w:1) - /// Proof: Signal ProposalStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) - /// Storage: Control OrgTreasury (r:1 w:0) - /// Proof: Control OrgTreasury (max_values: None, max_size: Some(80), added: 2555, mode: MaxEncodedLen) - /// Storage: Tokens Accounts (r:3 w:3) - /// Proof: Tokens Accounts (max_values: None, max_size: Some(109), added: 2584, mode: MaxEncodedLen) - /// Storage: System Account (r:1 w:1) - /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) + // Storage: Signal ProposalVoting (r:1 w:1) + // Storage: Signal ProposalOf (r:1 w:0) + // Storage: Control MemberStates (r:1 w:0) + // Storage: Signal ProposalStates (r:1 w:1) + // Storage: Control OrgTreasury (r:1 w:0) + // Storage: Tokens Accounts (r:3 w:3) + // Storage: System Account (r:1 w:1) /// The range of component `m` is `[0, 1000]`. fn vote(m: u32, ) -> Weight { - // Proof Size summary in bytes: - // Measured: `3941 + m * (51 ±0)` - // Estimated: `153431` - // Minimum execution time: 99_000 nanoseconds. - Weight::from_parts(94_755_596, 153431) - // Standard Error: 2_268 - .saturating_add(Weight::from_ref_time(112_356).saturating_mul(m.into())) - .saturating_add(T::DbWeight::get().reads(9_u64)) - .saturating_add(T::DbWeight::get().writes(6_u64)) + // Minimum execution time: 107_000 nanoseconds. + Weight::from_ref_time(113_880_549) + // Standard Error: 3_532 + .saturating_add(Weight::from_ref_time(148_088).saturating_mul(m.into())) + .saturating_add(T::DbWeight::get().reads(9)) + .saturating_add(T::DbWeight::get().writes(6)) } - /// Storage: Signal ProposalsByBlock (r:1 w:0) - /// Proof: Signal ProposalsByBlock (max_values: None, max_size: Some(3239), added: 5714, mode: MaxEncodedLen) - /// Storage: Signal ProposalStates (r:100 w:0) - /// Proof: Signal ProposalStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + // Storage: Signal ProposalsByBlock (r:1 w:0) + // Storage: Signal ProposalStates (r:5 w:0) /// The range of component `p` is `[0, 100]`. fn on_initialize(p: u32, ) -> Weight { - // Proof Size summary in bytes: - // Measured: `394 + p * (86 ±0)` - // Estimated: `5714 + p * (2524 ±0)` - // Minimum execution time: 3_000 nanoseconds. - Weight::from_parts(3_033_538, 5714) - // Standard Error: 21_933 - .saturating_add(Weight::from_ref_time(3_051_963).saturating_mul(p.into())) - .saturating_add(T::DbWeight::get().reads(1_u64)) + // Minimum execution time: 5_000 nanoseconds. + Weight::from_ref_time(9_260_770) + // Standard Error: 7_634 + .saturating_add(Weight::from_ref_time(2_838_161).saturating_mul(p.into())) + .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(p.into()))) - .saturating_add(Weight::from_proof_size(2524).saturating_mul(p.into())) } } // For backwards compatibility and tests impl WeightInfo for () { - /// Storage: Control OrgStates (r:1 w:0) - /// Proof: Control OrgStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) - /// Storage: Control MemberStates (r:1 w:0) - /// Proof: Control MemberStates (max_values: None, max_size: Some(97), added: 2572, mode: MaxEncodedLen) - /// Storage: Signal ProposalCount (r:1 w:1) - /// Proof: Signal ProposalCount (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: Signal ProposalOf (r:1 w:1) - /// Proof: Signal ProposalOf (max_values: None, max_size: Some(363), added: 2838, mode: MaxEncodedLen) - /// Storage: Tokens Accounts (r:2 w:2) - /// Proof: Tokens Accounts (max_values: None, max_size: Some(109), added: 2584, mode: MaxEncodedLen) - /// Storage: Control OrgTreasury (r:1 w:0) - /// Proof: Control OrgTreasury (max_values: None, max_size: Some(80), added: 2555, mode: MaxEncodedLen) - /// Storage: Signal ProposalsByBlock (r:2 w:2) - /// Proof: Signal ProposalsByBlock (max_values: None, max_size: Some(3239), added: 5714, mode: MaxEncodedLen) - /// Storage: Control OrgMemberCount (r:1 w:0) - /// Proof: Control OrgMemberCount (max_values: None, max_size: Some(52), added: 2527, mode: MaxEncodedLen) - /// Storage: Signal ProposalVoting (r:0 w:1) - /// Proof: Signal ProposalVoting (max_values: None, max_size: Some(130112), added: 132587, mode: MaxEncodedLen) - /// Storage: Signal ProposalStates (r:0 w:1) - /// Proof: Signal ProposalStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + // Storage: Control OrgStates (r:1 w:0) + // Storage: Control MemberStates (r:1 w:0) + // Storage: Signal ProposalCount (r:1 w:1) + // Storage: Signal ProposalOf (r:1 w:1) + // Storage: Tokens Accounts (r:2 w:2) + // Storage: Control OrgTreasury (r:1 w:0) + // Storage: Signal ProposalsByBlock (r:2 w:2) + // Storage: Control OrgMemberCount (r:1 w:0) + // Storage: Signal ProposalVoting (r:0 w:1) + // Storage: Signal ProposalStates (r:0 w:1) fn proposal() -> Weight { - // Proof Size summary in bytes: - // Measured: `1390` - // Estimated: `30111` - // Minimum execution time: 82_000 nanoseconds. - Weight::from_parts(82_000_000, 30111) - .saturating_add(RocksDbWeight::get().reads(10_u64)) - .saturating_add(RocksDbWeight::get().writes(8_u64)) + // Minimum execution time: 90_000 nanoseconds. + Weight::from_ref_time(94_000_000) + .saturating_add(RocksDbWeight::get().reads(10)) + .saturating_add(RocksDbWeight::get().writes(8)) } - /// Storage: Signal ProposalVoting (r:1 w:1) - /// Proof: Signal ProposalVoting (max_values: None, max_size: Some(130112), added: 132587, mode: MaxEncodedLen) - /// Storage: Signal ProposalOf (r:1 w:0) - /// Proof: Signal ProposalOf (max_values: None, max_size: Some(363), added: 2838, mode: MaxEncodedLen) - /// Storage: Control MemberStates (r:1 w:0) - /// Proof: Control MemberStates (max_values: None, max_size: Some(97), added: 2572, mode: MaxEncodedLen) - /// Storage: Signal ProposalStates (r:1 w:1) - /// Proof: Signal ProposalStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) - /// Storage: Control OrgTreasury (r:1 w:0) - /// Proof: Control OrgTreasury (max_values: None, max_size: Some(80), added: 2555, mode: MaxEncodedLen) - /// Storage: Tokens Accounts (r:3 w:3) - /// Proof: Tokens Accounts (max_values: None, max_size: Some(109), added: 2584, mode: MaxEncodedLen) - /// Storage: System Account (r:1 w:1) - /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) + // Storage: Signal ProposalVoting (r:1 w:1) + // Storage: Signal ProposalOf (r:1 w:0) + // Storage: Control MemberStates (r:1 w:0) + // Storage: Signal ProposalStates (r:1 w:1) + // Storage: Control OrgTreasury (r:1 w:0) + // Storage: Tokens Accounts (r:3 w:3) + // Storage: System Account (r:1 w:1) /// The range of component `m` is `[0, 1000]`. fn vote(m: u32, ) -> Weight { - // Proof Size summary in bytes: - // Measured: `3941 + m * (51 ±0)` - // Estimated: `153431` - // Minimum execution time: 99_000 nanoseconds. - Weight::from_parts(94_755_596, 153431) - // Standard Error: 2_268 - .saturating_add(Weight::from_ref_time(112_356).saturating_mul(m.into())) - .saturating_add(RocksDbWeight::get().reads(9_u64)) - .saturating_add(RocksDbWeight::get().writes(6_u64)) + // Minimum execution time: 107_000 nanoseconds. + Weight::from_ref_time(113_880_549) + // Standard Error: 3_532 + .saturating_add(Weight::from_ref_time(148_088).saturating_mul(m.into())) + .saturating_add(RocksDbWeight::get().reads(9)) + .saturating_add(RocksDbWeight::get().writes(6)) } - /// Storage: Signal ProposalsByBlock (r:1 w:0) - /// Proof: Signal ProposalsByBlock (max_values: None, max_size: Some(3239), added: 5714, mode: MaxEncodedLen) - /// Storage: Signal ProposalStates (r:100 w:0) - /// Proof: Signal ProposalStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + // Storage: Signal ProposalsByBlock (r:1 w:0) + // Storage: Signal ProposalStates (r:5 w:0) /// The range of component `p` is `[0, 100]`. fn on_initialize(p: u32, ) -> Weight { - // Proof Size summary in bytes: - // Measured: `394 + p * (86 ±0)` - // Estimated: `5714 + p * (2524 ±0)` - // Minimum execution time: 3_000 nanoseconds. - Weight::from_parts(3_033_538, 5714) - // Standard Error: 21_933 - .saturating_add(Weight::from_ref_time(3_051_963).saturating_mul(p.into())) - .saturating_add(RocksDbWeight::get().reads(1_u64)) + // Minimum execution time: 5_000 nanoseconds. + Weight::from_ref_time(9_260_770) + // Standard Error: 7_634 + .saturating_add(Weight::from_ref_time(2_838_161).saturating_mul(p.into())) + .saturating_add(RocksDbWeight::get().reads(1)) .saturating_add(RocksDbWeight::get().reads((1_u64).saturating_mul(p.into()))) - .saturating_add(Weight::from_proof_size(2524).saturating_mul(p.into())) } } \ No newline at end of file diff --git a/traits/Cargo.toml b/traits/Cargo.toml index 819182e95..ac03a6508 100644 --- a/traits/Cargo.toml +++ b/traits/Cargo.toml @@ -6,7 +6,7 @@ [package] name = "gamedao-traits" -version = "1.3.0" +version = "1.2.0" authors = ["zero.io","gamedao.co"] edition = "2018" license = "GPL-3.0-or-later" @@ -15,12 +15,12 @@ repository = "https://github.com/gamedaoco/gamedao-protocol" [dependencies] -serde = { version = "1.0.143", default-features = false } -codec = { package = "parity-scale-codec", version = "3.2.2", default-features = false, features = ["derive"] } -scale-info = { version = "2.1.1", default-features = false, features = ["derive"] } -frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38", default-features = false } -frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38", default-features = false, optional = true } -sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38", default-features = false } +serde = { version = "1.0.124", default-features = false } +codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] } +scale-info = { version = "2.0.1", default-features = false, features = ["derive"] } +frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36", default-features = false } +frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36", default-features = false, optional = true } +sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36", default-features = false } [features] default = ["std"] From 09f91654fd7a18b07b9a9dcb7d11f9debd1a7bfc Mon Sep 17 00:00:00 2001 From: Vasylenko Yevhen Date: Thu, 9 Mar 2023 14:13:22 +0200 Subject: [PATCH 38/49] Update substrate v36 to v38 (#145) * feat: bump substrate version from 0.9.36 to 0.9.38 * bump protocol to 1.3.0 * use CID as collection metadata --------- Co-authored-by: FiberMan --- battlepass/Cargo.toml | 38 +- battlepass/src/benchmarking.rs | 4 +- battlepass/src/lib.rs | 64 +-- battlepass/src/tests.rs | 72 +-- battlepass/src/weights.rs | 879 +++++++++++++++++++++------------ control/Cargo.toml | 34 +- control/src/weights.rs | 387 +++++++++------ flow/Cargo.toml | 28 +- flow/src/weights.rs | 209 +++++--- sense/Cargo.toml | 20 +- sense/src/weights.rs | 77 ++- signal/Cargo.toml | 30 +- signal/src/weights.rs | 197 +++++--- traits/Cargo.toml | 14 +- 14 files changed, 1279 insertions(+), 774 deletions(-) diff --git a/battlepass/Cargo.toml b/battlepass/Cargo.toml index 72d4322a0..123748318 100644 --- a/battlepass/Cargo.toml +++ b/battlepass/Cargo.toml @@ -5,7 +5,7 @@ # ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ [package] name = "gamedao-battlepass" -version = "1.2.0" +version = "1.3.0" authors = ["zero.io","gamedao.co"] repository = "https://github.com/gamedaoco/gamedao-protocol" edition = "2018" @@ -14,33 +14,33 @@ description = "BattlePass pallet provides functionality to create, manage and pa [dependencies] serde = { version = "1.0.143", default-features = false } -codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] } +codec = { package = "parity-scale-codec", version = "3.2.2", default-features = false, features = ["derive"] } scale-info = { version = "2.1.1", default-features = false, features = ["derive"] } -sp-core = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } -sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } -sp-std = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } -sp-storage = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } -sp-io = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.36", default-features=false } -frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36", default-features = false } -frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36", default-features = false } -frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36", default-features = false, optional = true } +sp-core = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } +sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } +sp-std = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } +sp-storage = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } +sp-io = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.38", default-features=false } +frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38", default-features = false } +frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38", default-features = false } +frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38", default-features = false, optional = true } -pallet-uniques = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } +pallet-uniques = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } -orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.36", default-features = false } +orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.38", default-features = false } gamedao-control = { package = "gamedao-control", path = "../control", default-features = false } gamedao-traits = { package = "gamedao-traits", path = "../traits", default-features = false } [dev-dependencies] -sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.36" } -codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] } +sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.38" } +codec = { package = "parity-scale-codec", version = "3.2.2", default-features = false, features = ["derive"] } -pallet-balances = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } -pallet-uniques = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } -orml-currencies = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.36", default-features = false } -orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.36", default-features = false } -orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.36", default-features = false } +pallet-balances = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } +pallet-uniques = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } +orml-currencies = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.38", default-features = false } +orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.38", default-features = false } +orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.38", default-features = false } [features] default = ['std'] diff --git a/battlepass/src/benchmarking.rs b/battlepass/src/benchmarking.rs index 27c34531f..1ad896b44 100644 --- a/battlepass/src/benchmarking.rs +++ b/battlepass/src/benchmarking.rs @@ -124,7 +124,9 @@ benchmarks! { set_bot::(caller.clone(), battlepass_id, bot.clone()); }: _(RawOrigin::Signed(bot), battlepass_id, caller.clone()) verify { - assert!(ClaimedBattlepasses::::get(battlepass_id, caller).is_some()); + let collection_id = T::BattlepassHelper::collection(0); + let item_id = T::BattlepassHelper::item(0); + assert!( as InspectEnumerable>::items(&collection_id).any(|x| x == item_id)); } activate_battlepass { diff --git a/battlepass/src/lib.rs b/battlepass/src/lib.rs index 454031870..34b9d5a73 100644 --- a/battlepass/src/lib.rs +++ b/battlepass/src/lib.rs @@ -14,7 +14,7 @@ pub use pallet::*; use frame_support::{pallet_prelude::*, transactional, dispatch::RawOrigin}; -use frame_support::traits::tokens::nonfungibles::Inspect; +use frame_support::traits::tokens::nonfungibles::InspectEnumerable; use frame_system::pallet_prelude::*; use sp_std::convert::TryInto; use sp_runtime::traits::{AtLeast32BitUnsigned, Hash}; @@ -94,7 +94,7 @@ pub mod pallet { type BattlepassHelper: BattlepassHelper; - /// The maximum length of a name, cid or metadata strings stored on-chain. + /// The maximum length of a name, cid strings stored on-chain. #[pallet::constant] type StringLimit: Get; @@ -212,20 +212,17 @@ pub mod pallet { AuthorizationError, CollectionUnknown, BattlepassExists, - BattlepassClaimed, - BattlepassNotClaimed, + BattlepassOwnershipExists, + BattlepassOwnershipDoesntExist, BattlepassUnknown, BattlepassStateUnknown, BattlepassStateWrong, BattlepassInfoUnknown, - BattlepassNftUnknown, - BattlepassNftInvalid, LevelNotReached, LevelUnknown, NoAvailableCollectionId, NoAvailableNftId, NoChangesProvided, - NotOwnNft, OrgPrimeUnknown, OrgUnknownOrInactive, RewardClaimed, @@ -254,18 +251,6 @@ pub mod pallet { #[pallet::storage] pub type BattlepassInfoByOrg = StorageMap<_, Blake2_128Concat, T::Hash, BattlepassInfo, OptionQuery>; - /// Claimed Battlepass-NFT by user and battlepass. - /// - /// ClaimedBattlepasses: map (Hash, AccountId) => ItemId - #[pallet::storage] - #[pallet::getter(fn get_claimed_battlepass)] - pub(super) type ClaimedBattlepasses = StorageDoubleMap<_, - Blake2_128Concat, T::Hash, - Blake2_128Concat, T::AccountId, - T::ItemId, - OptionQuery - >; - /// Total earned Points for users per each Battlepass. /// /// Points: map (Hash, AccountId) => u32 @@ -361,7 +346,7 @@ pub mod pallet { let new_season = battlepass_count + 1; // Create a collection to store Battlepass NFTs - let collection_id = Self::create_collection(creator.clone(), None)?; + let collection_id = Self::create_collection(creator.clone(), None, cid.clone())?; let battlepass_id = Self::do_create_battlepass(creator, org_id, name, cid, collection_id, price, new_season)?; Self::deposit_event(Event::BattlepassCreated { org_id, battlepass_id, season: new_season }); @@ -435,15 +420,17 @@ pub mod pallet { // check if Battlepass in ACTIVE state ensure!(Self::check_battlepass_state(battlepass_id, BattlepassState::ACTIVE)?, Error::::BattlepassStateWrong); // check if Org is active - ensure!(T::Control::is_org_active(&battlepass.org_id), Error::::OrgUnknownOrInactive); + let org_id = battlepass.org_id.clone(); + ensure!(T::Control::is_org_active(&org_id), Error::::OrgUnknownOrInactive); // check permissions (prime, bot) - ensure!(Self::is_prime_or_bot(&battlepass.org_id, by_who.clone())?, Error::::AuthorizationError); - // check if Battlepass already claimed - ensure!(!ClaimedBattlepasses::::contains_key(battlepass_id, for_who.clone()), Error::::BattlepassClaimed); + ensure!(Self::is_prime_or_bot(&org_id, by_who.clone())?, Error::::AuthorizationError); + // check if user has access to Battlepass + ensure!(!Self::has_battlepass_ownership(for_who.clone(), battlepass.collection_id), Error::::BattlepassOwnershipExists); + let nft_id = Self::do_claim_battlepass(battlepass.creator.clone(), for_who.clone(), battlepass_id, battlepass.collection_id)?; - Self::deposit_event(Event::BattlepassClaimed { by_who, for_who, org_id: battlepass.org_id, battlepass_id, nft_id }); + Self::deposit_event(Event::BattlepassClaimed { by_who, for_who, org_id, battlepass_id, nft_id }); Ok(()) } @@ -537,7 +524,7 @@ pub mod pallet { // check permissions (prime, bot) ensure!(Self::is_prime_or_bot(&battlepass.org_id, sender.clone())?, Error::::AuthorizationError); // check if user has access to Battlepass - Self::validate_battlepass_ownership(account.clone(), battlepass_id, battlepass)?; + ensure!(Self::has_battlepass_ownership(account.clone(), battlepass.collection_id), Error::::BattlepassOwnershipDoesntExist); Points::::insert(battlepass_id, &account, amount); @@ -580,7 +567,7 @@ pub mod pallet { ensure!(Self::is_prime_or_bot(&battlepass.org_id, caller)?, Error::::AuthorizationError); let prime = T::Control::org_prime_account(&battlepass.org_id).ok_or(Error::::OrgPrimeUnknown)?; - let collection_id = Self::create_collection(prime, max)?; + let collection_id = Self::create_collection(prime, max, cid.clone())?; let reward_id = Self::do_create_reward(battlepass_id, name, cid, level, transferable, collection_id)?; Self::deposit_event(Event::RewardCreated { reward_id, battlepass_id, level }); @@ -703,7 +690,7 @@ pub mod pallet { // check permissions (self, prime or bot) ensure!(by_who == for_who || Self::is_prime_or_bot(&battlepass.org_id, by_who.clone())?, Error::::AuthorizationError); // check if user has access to Battlepass - Self::validate_battlepass_ownership(for_who.clone(), reward.battlepass_id, battlepass)?; + ensure!(Self::has_battlepass_ownership(for_who.clone(), battlepass.collection_id), Error::::BattlepassOwnershipDoesntExist); // check if user has reached the required Level ensure!(Self::is_level_reached(&reward.battlepass_id, &for_who, reward.level), Error::::LevelNotReached); @@ -871,8 +858,8 @@ impl Pallet { }) } - fn create_collection(owner: T::AccountId, max: Option) -> Result { - let metadata = BoundedVec::truncate_from(b"meta".to_vec()); // TODO: what should be here? + fn create_collection(owner: T::AccountId, max: Option, cid: String) -> Result { + let metadata = BoundedVec::truncate_from(cid.into()); let collection_index = Self::bump_collection_index()?; let collection_id = T::BattlepassHelper::collection(collection_index); let origin = OriginFor::::from(RawOrigin::Signed(owner.clone())); @@ -966,8 +953,6 @@ impl Pallet { // Create Battlepass NFT Self::create_nft(creator, for_who.clone(), collection_id, nft_id, metadata)?; - - ClaimedBattlepasses::::insert(battlepass_id, &for_who, nft_id); Ok(nft_id) } @@ -1018,17 +1003,8 @@ impl Pallet { Ok(nft_id) } - fn validate_battlepass_ownership(account: T::AccountId, battlepass_id: T::Hash, battlepass: Battlepass, T::CollectionId>) -> DispatchResult { - // check if user claimed Battlepass NFT - let bp_nft_id = Self::get_claimed_battlepass(battlepass_id, &account).ok_or(Error::::BattlepassNotClaimed)?; - // check if Battlepass NFT exists - let bp_nft_owner = pallet_uniques::Pallet::::owner(battlepass.collection_id, bp_nft_id).ok_or(Error::::BattlepassNftUnknown)?; - // validate Battlepass NFT ownership - ensure!(account.clone() == bp_nft_owner, Error::::NotOwnNft); - // validate Battlepass NFT metadata - let bp_nft_metadata = as Inspect>::attribute(&battlepass.collection_id, &bp_nft_id, &[]); - ensure!(Some(battlepass_id.encode()) == bp_nft_metadata, Error::::BattlepassNftInvalid); - - Ok(()) + fn has_battlepass_ownership(account: T::AccountId, bp_collection_id: T::CollectionId) -> bool { + let bp_owned_count = as InspectEnumerable>::owned_in_collection(&bp_collection_id, &account).count(); + bp_owned_count > 0 } } diff --git a/battlepass/src/tests.rs b/battlepass/src/tests.rs index 298a877d4..59297b7f4 100644 --- a/battlepass/src/tests.rs +++ b/battlepass/src/tests.rs @@ -1,7 +1,7 @@ #![cfg(test)] use frame_support::{assert_noop, assert_ok}; -use frame_support::traits::tokens::nonfungibles::{InspectEnumerable, Mutate, Transfer}; +use frame_support::traits::tokens::nonfungibles::{Inspect, InspectEnumerable, Mutate, Transfer}; use sp_core::H256; use crate::mock::{ @@ -455,6 +455,7 @@ fn claim_battlepass_test() { let not_creator_2 = TOM; let not_creator_3 = 22u32; let not_member = EVA; + let not_member_2 = 40; add_member(org_id, not_creator); add_member(org_id, not_creator_2); add_member(org_id, not_creator_3); @@ -511,17 +512,32 @@ fn claim_battlepass_test() { assert_ok!( Battlepass::claim_battlepass(Origin::signed(creator), battlepass_id, not_creator) ); - // Check if ClaimedBattlepasses record created - let nft_id = ClaimedBattlepasses::::get(battlepass_id, not_creator); - assert_eq!(nft_id.is_some(), true); - assert_eq!(nft_id.unwrap(), 0); // Check if NFT minted assert_eq!(>::items(&0).any(|x| x == 0) , true); // Should not claim if it was already claimed assert_noop!( Battlepass::claim_battlepass(Origin::signed(creator), battlepass_id, not_creator), - Error::::BattlepassClaimed + Error::::BattlepassOwnershipExists + ); + + // Should claim again after transferring Battlepass NFT to someone else + assert_ok!( + Uniques::thaw_collection(Origin::signed(creator), 0) + ); + assert_ok!( + >::transfer(&0, &0, ¬_member_2) + ); + assert_ok!( + Battlepass::claim_battlepass(Origin::signed(creator), battlepass_id, not_creator) + ); + // Check if NFT minted + assert_eq!(>::items(&0).any(|x| x == 1) , true); + + // Should not claim if user received Battlepass NFT from someone else + assert_noop!( + Battlepass::claim_battlepass(Origin::signed(creator), battlepass_id, not_member_2), + Error::::BattlepassOwnershipExists ); // Should claim for others by Bot @@ -531,12 +547,8 @@ fn claim_battlepass_test() { assert_ok!( Battlepass::claim_battlepass(Origin::signed(BOT), battlepass_id, not_creator_3) ); - // Check if ClaimedBattlepasses record created - let nft_id = ClaimedBattlepasses::::get(battlepass_id, not_creator_3); - assert_eq!(nft_id.is_some(), true); - assert_eq!(nft_id.unwrap(), 1); // Check if NFT minted - assert_eq!(>::items(&0).any(|x| x == 1) , true); + assert_eq!(>::items(&0).any(|x| x == 2) , true); // Should claim for accounts outside of org assert_ok!( @@ -615,7 +627,7 @@ fn set_points_test() { // Should not set if user does not have access to Battlepass assert_noop!( Battlepass::set_points(Origin::signed(creator), battlepass_id, not_member, 10), - Error::::BattlepassNotClaimed + Error::::BattlepassOwnershipDoesntExist ); // Should set points by Prime @@ -982,6 +994,7 @@ fn claim_reward_test() { let not_creator_3 = 30; let not_creator_4 = 31; let not_member = EVA; + let not_member_2 = 40; add_member(org_id, not_creator); add_member(org_id, not_creator_2); add_member(org_id, not_creator_3); @@ -1056,7 +1069,7 @@ fn claim_reward_test() { // Should not claim Reward if user didn't claim Battlepass assert_noop!( Battlepass::claim_reward(Origin::signed(not_creator), reward_id, not_creator), - Error::::BattlepassNotClaimed + Error::::BattlepassOwnershipDoesntExist ); // Should not claim Reward if no NFT for claimed Battlepass @@ -1068,7 +1081,7 @@ fn claim_reward_test() { ); assert_noop!( Battlepass::claim_reward(Origin::signed(not_creator), reward_id, not_creator), - Error::::BattlepassNftUnknown + Error::::BattlepassOwnershipDoesntExist ); // Should not claim Reward if user lost ownership of Battlepass NFT @@ -1079,24 +1092,11 @@ fn claim_reward_test() { Uniques::thaw_collection(Origin::signed(creator), 0) ); assert_ok!( - >::transfer(&0, &1, ¬_member) + >::transfer(&0, &1, ¬_member_2) ); assert_noop!( Battlepass::claim_reward(Origin::signed(creator), reward_id, creator), - Error::::NotOwnNft - ); - - // Should not claim Reward if Battlepass NFT is not valid - assert_ok!( - Battlepass::claim_battlepass(Origin::signed(creator), battlepass_id, not_creator_2) - ); - let new_metadata = BoundedVec::truncate_from(b"crap".to_vec()); - assert_ok!( - Uniques::set_metadata(Origin::signed(creator), 0, 2, new_metadata, false) - ); - assert_noop!( - Battlepass::claim_reward(Origin::signed(not_creator_2), reward_id, not_creator_2), - Error::::BattlepassNftInvalid + Error::::BattlepassOwnershipDoesntExist ); // Should not claim if user's level is too low @@ -1127,9 +1127,6 @@ fn claim_reward_test() { Error::::RewardClaimed ); - // Should claim Reward after receiving Battlepass NFT from elsewhere - // TODO: need to 'apply' the received Battlepass NFT so it will appear in ClaimedBattlepasses - // Should not claim if max limit reached assert_ok!( Battlepass::claim_battlepass(Origin::signed(creator), battlepass_id, not_creator_4) @@ -1167,6 +1164,17 @@ fn claim_reward_test() { // Check if Reward claimed assert_eq!(ClaimedRewards::::contains_key(reward_id, not_member), true); + // Should claim Reward after receiving Battlepass NFT from elsewhere + let reward_id = create_reward(battlepass_id); + assert_ok!( + Battlepass::set_points(Origin::signed(creator), battlepass_id, not_member_2, 10) + ); + assert_ok!( + Battlepass::claim_reward(Origin::signed(not_member_2), reward_id, not_member_2) + ); + // Check if Reward claimed + assert_eq!(ClaimedRewards::::contains_key(reward_id, not_member_2), true); + // Should not claim if Battlepass state is ENDED assert_ok!( Battlepass::conclude_battlepass(Origin::signed(creator), battlepass_id) diff --git a/battlepass/src/weights.rs b/battlepass/src/weights.rs index 865bd335c..2504abe43 100644 --- a/battlepass/src/weights.rs +++ b/battlepass/src/weights.rs @@ -2,7 +2,8 @@ //! Autogenerated weights for gamedao_battlepass //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-02-28, STEPS: `20`, REPEAT: 10, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2023-03-06, STEPS: `20`, REPEAT: `10`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! WORST CASE MAP SIZE: `1000000` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: None, DB CACHE: 1024 // Executed Command: @@ -44,366 +45,630 @@ pub trait WeightInfo { /// Weights for gamedao_battlepass using the Substrate node and recommended hardware. pub struct SubstrateWeight(PhantomData); impl WeightInfo for SubstrateWeight { - // Storage: Control OrgStates (r:1 w:0) - // Storage: Control Orgs (r:1 w:0) - // Storage: Battlepass BattlepassInfoByOrg (r:1 w:1) - // Storage: Battlepass CollectionIndex (r:1 w:1) - // Storage: Uniques Class (r:1 w:1) - // Storage: Uniques ClassMetadataOf (r:1 w:1) - // Storage: Uniques ClassAccount (r:0 w:1) - // Storage: Battlepass BattlepassStates (r:0 w:1) - // Storage: Battlepass Battlepasses (r:0 w:1) + /// Storage: Control OrgStates (r:1 w:0) + /// Proof: Control OrgStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Control Orgs (r:1 w:0) + /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) + /// Storage: Battlepass BattlepassInfoByOrg (r:1 w:1) + /// Proof: Battlepass BattlepassInfoByOrg (max_values: None, max_size: Some(118), added: 2593, mode: MaxEncodedLen) + /// Storage: Battlepass CollectionIndex (r:1 w:1) + /// Proof: Battlepass CollectionIndex (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: Uniques ClassMetadataOf (r:1 w:1) + /// Proof: Uniques ClassMetadataOf (max_values: None, max_size: Some(167), added: 2642, mode: MaxEncodedLen) + /// Storage: Uniques ClassAccount (r:0 w:1) + /// Proof: Uniques ClassAccount (max_values: None, max_size: Some(68), added: 2543, mode: MaxEncodedLen) + /// Storage: Battlepass BattlepassStates (r:0 w:1) + /// Proof: Battlepass BattlepassStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Battlepass Battlepasses (r:0 w:1) + /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(382), added: 2857, mode: MaxEncodedLen) fn create_battlepass() -> Weight { - // Minimum execution time: 93_000 nanoseconds. - Weight::from_ref_time(95_000_000) - .saturating_add(T::DbWeight::get().reads(6)) - .saturating_add(T::DbWeight::get().writes(7)) + // Proof Size summary in bytes: + // Measured: `597` + // Estimated: `13676` + // Minimum execution time: 86_000 nanoseconds. + Weight::from_parts(86_000_000, 13676) + .saturating_add(T::DbWeight::get().reads(6_u64)) + .saturating_add(T::DbWeight::get().writes(7_u64)) } - // Storage: Battlepass Battlepasses (r:1 w:1) - // Storage: Battlepass BattlepassStates (r:1 w:0) - // Storage: Control OrgStates (r:1 w:0) - // Storage: Control Orgs (r:1 w:0) + /// Storage: Battlepass Battlepasses (r:1 w:1) + /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(382), added: 2857, mode: MaxEncodedLen) + /// Storage: Battlepass BattlepassStates (r:1 w:0) + /// Proof: Battlepass BattlepassStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Control OrgStates (r:1 w:0) + /// Proof: Control OrgStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Control Orgs (r:1 w:0) + /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) fn update_battlepass() -> Weight { - // Minimum execution time: 35_000 nanoseconds. - Weight::from_ref_time(36_000_000) - .saturating_add(T::DbWeight::get().reads(4)) - .saturating_add(T::DbWeight::get().writes(1)) + // Proof Size summary in bytes: + // Measured: `837` + // Estimated: `10670` + // Minimum execution time: 29_000 nanoseconds. + Weight::from_parts(30_000_000, 10670) + .saturating_add(T::DbWeight::get().reads(4_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) } - // Storage: Battlepass Battlepasses (r:1 w:0) - // Storage: Battlepass BattlepassStates (r:1 w:0) - // Storage: Control OrgStates (r:1 w:0) - // Storage: Control Orgs (r:1 w:0) - // Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) - // Storage: Battlepass ClaimedBattlepasses (r:1 w:1) - // Storage: Battlepass NftIndex (r:1 w:1) - // Storage: Uniques Asset (r:1 w:1) - // Storage: Uniques Class (r:1 w:1) - // Storage: Uniques CollectionMaxSupply (r:1 w:0) - // Storage: Uniques InstanceMetadataOf (r:1 w:1) - // Storage: Uniques Account (r:0 w:1) + /// Storage: Battlepass Battlepasses (r:1 w:0) + /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(382), added: 2857, mode: MaxEncodedLen) + /// Storage: Battlepass BattlepassStates (r:1 w:0) + /// Proof: Battlepass BattlepassStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Control OrgStates (r:1 w:0) + /// Proof: Control OrgStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Control Orgs (r:1 w:0) + /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) + /// Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) + /// Proof: Battlepass BattlepassInfoByOrg (max_values: None, max_size: Some(118), added: 2593, mode: MaxEncodedLen) + /// Storage: Uniques Account (r:1 w:1) + /// Proof: Uniques Account (max_values: None, max_size: Some(88), added: 2563, mode: MaxEncodedLen) + /// Storage: Battlepass NftIndex (r:1 w:1) + /// Proof: Battlepass NftIndex (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) + /// Storage: Uniques Asset (r:1 w:1) + /// Proof: Uniques Asset (max_values: None, max_size: Some(122), added: 2597, mode: MaxEncodedLen) + /// Storage: Uniques Class (r:1 w:1) + /// Proof: Uniques Class (max_values: None, max_size: Some(178), added: 2653, 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(187), added: 2662, mode: MaxEncodedLen) fn claim_battlepass() -> Weight { - // Minimum execution time: 101_000 nanoseconds. - Weight::from_ref_time(105_000_000) - .saturating_add(T::DbWeight::get().reads(11)) - .saturating_add(T::DbWeight::get().writes(6)) + // Proof Size summary in bytes: + // Measured: `1359` + // Estimated: `26736` + // Minimum execution time: 95_000 nanoseconds. + Weight::from_parts(98_000_000, 26736) + .saturating_add(T::DbWeight::get().reads(11_u64)) + .saturating_add(T::DbWeight::get().writes(5_u64)) } - // Storage: Battlepass Battlepasses (r:1 w:0) - // Storage: Battlepass BattlepassStates (r:1 w:1) - // Storage: Control OrgStates (r:1 w:0) - // Storage: Control Orgs (r:1 w:0) - // Storage: Battlepass BattlepassInfoByOrg (r:1 w:1) + /// Storage: Battlepass Battlepasses (r:1 w:0) + /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(382), added: 2857, mode: MaxEncodedLen) + /// Storage: Battlepass BattlepassStates (r:1 w:1) + /// Proof: Battlepass BattlepassStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Control OrgStates (r:1 w:0) + /// Proof: Control OrgStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Control Orgs (r:1 w:0) + /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) + /// Storage: Battlepass BattlepassInfoByOrg (r:1 w:1) + /// Proof: Battlepass BattlepassInfoByOrg (max_values: None, max_size: Some(118), added: 2593, mode: MaxEncodedLen) fn activate_battlepass() -> Weight { - // Minimum execution time: 43_000 nanoseconds. - Weight::from_ref_time(44_000_000) - .saturating_add(T::DbWeight::get().reads(5)) - .saturating_add(T::DbWeight::get().writes(2)) + // Proof Size summary in bytes: + // Measured: `880` + // Estimated: `13263` + // Minimum execution time: 36_000 nanoseconds. + Weight::from_parts(37_000_000, 13263) + .saturating_add(T::DbWeight::get().reads(5_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) } - // Storage: Battlepass Battlepasses (r:1 w:0) - // Storage: Battlepass BattlepassStates (r:1 w:1) - // Storage: Control Orgs (r:1 w:0) - // Storage: Battlepass BattlepassInfoByOrg (r:1 w:1) + /// Storage: Battlepass Battlepasses (r:1 w:0) + /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(382), added: 2857, mode: MaxEncodedLen) + /// Storage: Battlepass BattlepassStates (r:1 w:1) + /// Proof: Battlepass BattlepassStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Control Orgs (r:1 w:0) + /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) + /// Storage: Battlepass BattlepassInfoByOrg (r:1 w:1) + /// Proof: Battlepass BattlepassInfoByOrg (max_values: None, max_size: Some(118), added: 2593, mode: MaxEncodedLen) fn conclude_battlepass() -> Weight { - // Minimum execution time: 38_000 nanoseconds. - Weight::from_ref_time(40_000_000) - .saturating_add(T::DbWeight::get().reads(4)) - .saturating_add(T::DbWeight::get().writes(2)) + // Proof Size summary in bytes: + // Measured: `907` + // Estimated: `10739` + // Minimum execution time: 33_000 nanoseconds. + Weight::from_parts(34_000_000, 10739) + .saturating_add(T::DbWeight::get().reads(4_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) } - // Storage: Battlepass Battlepasses (r:1 w:0) - // Storage: Battlepass BattlepassStates (r:1 w:0) - // Storage: Control OrgStates (r:1 w:0) - // Storage: Control Orgs (r:1 w:0) - // Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) - // Storage: Battlepass ClaimedBattlepasses (r:1 w:0) - // Storage: Uniques Asset (r:1 w:0) - // Storage: Uniques InstanceMetadataOf (r:1 w:0) - // Storage: Battlepass Points (r:0 w:1) + /// Storage: Battlepass Battlepasses (r:1 w:0) + /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(382), added: 2857, mode: MaxEncodedLen) + /// Storage: Battlepass BattlepassStates (r:1 w:0) + /// Proof: Battlepass BattlepassStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Control OrgStates (r:1 w:0) + /// Proof: Control OrgStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Control Orgs (r:1 w:0) + /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) + /// Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) + /// Proof: Battlepass BattlepassInfoByOrg (max_values: None, max_size: Some(118), added: 2593, mode: MaxEncodedLen) + /// Storage: Uniques Account (r:2 w:0) + /// Proof: Uniques Account (max_values: None, max_size: Some(88), added: 2563, mode: MaxEncodedLen) + /// Storage: Battlepass Points (r:0 w:1) + /// Proof: Battlepass Points (max_values: None, max_size: Some(100), added: 2575, mode: MaxEncodedLen) fn set_points() -> Weight { - // Minimum execution time: 51_000 nanoseconds. - Weight::from_ref_time(53_000_000) - .saturating_add(T::DbWeight::get().reads(8)) - .saturating_add(T::DbWeight::get().writes(1)) + // Proof Size summary in bytes: + // Measured: `1417` + // Estimated: `18389` + // Minimum execution time: 44_000 nanoseconds. + Weight::from_parts(44_000_000, 18389) + .saturating_add(T::DbWeight::get().reads(7_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) } - // Storage: Battlepass Battlepasses (r:1 w:0) - // Storage: Battlepass BattlepassStates (r:1 w:0) - // Storage: Control OrgStates (r:1 w:0) - // Storage: Control Orgs (r:1 w:0) - // Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) - // Storage: Battlepass CollectionIndex (r:1 w:1) - // Storage: Uniques Class (r:1 w:1) - // Storage: Uniques ClassMetadataOf (r:1 w:1) - // Storage: Uniques CollectionMaxSupply (r:1 w:1) - // Storage: Uniques ClassAccount (r:0 w:1) - // Storage: Battlepass Rewards (r:0 w:1) - // Storage: Battlepass RewardStates (r:0 w:1) + /// Storage: Battlepass Battlepasses (r:1 w:0) + /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(382), added: 2857, mode: MaxEncodedLen) + /// Storage: Battlepass BattlepassStates (r:1 w:0) + /// Proof: Battlepass BattlepassStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Control OrgStates (r:1 w:0) + /// Proof: Control OrgStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Control Orgs (r:1 w:0) + /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) + /// Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) + /// Proof: Battlepass BattlepassInfoByOrg (max_values: None, max_size: Some(118), added: 2593, mode: MaxEncodedLen) + /// Storage: Battlepass CollectionIndex (r:1 w:1) + /// Proof: Battlepass CollectionIndex (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: Uniques ClassMetadataOf (r:1 w:1) + /// Proof: Uniques ClassMetadataOf (max_values: None, max_size: Some(167), added: 2642, mode: MaxEncodedLen) + /// Storage: Uniques CollectionMaxSupply (r:1 w:1) + /// Proof: Uniques CollectionMaxSupply (max_values: None, max_size: Some(24), added: 2499, mode: MaxEncodedLen) + /// Storage: Uniques ClassAccount (r:0 w:1) + /// Proof: Uniques ClassAccount (max_values: None, max_size: Some(68), added: 2543, mode: MaxEncodedLen) + /// Storage: Battlepass Rewards (r:0 w:1) + /// Proof: Battlepass Rewards (max_values: None, max_size: Some(346), added: 2821, mode: MaxEncodedLen) + /// Storage: Battlepass RewardStates (r:0 w:1) + /// Proof: Battlepass RewardStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) fn create_reward() -> Weight { - // Minimum execution time: 116_000 nanoseconds. - Weight::from_ref_time(120_000_000) - .saturating_add(T::DbWeight::get().reads(9)) - .saturating_add(T::DbWeight::get().writes(7)) + // Proof Size summary in bytes: + // Measured: `1226` + // Estimated: `21556` + // Minimum execution time: 110_000 nanoseconds. + Weight::from_parts(112_000_000, 21556) + .saturating_add(T::DbWeight::get().reads(9_u64)) + .saturating_add(T::DbWeight::get().writes(7_u64)) } - // Storage: Battlepass Rewards (r:1 w:1) - // Storage: Battlepass RewardStates (r:1 w:0) - // Storage: Battlepass Battlepasses (r:1 w:0) - // Storage: Battlepass BattlepassStates (r:1 w:0) - // Storage: Control OrgStates (r:1 w:0) - // Storage: Control Orgs (r:1 w:0) - // Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) + /// Storage: Battlepass Rewards (r:1 w:1) + /// Proof: Battlepass Rewards (max_values: None, max_size: Some(346), added: 2821, mode: MaxEncodedLen) + /// Storage: Battlepass RewardStates (r:1 w:0) + /// Proof: Battlepass RewardStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Battlepass Battlepasses (r:1 w:0) + /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(382), added: 2857, mode: MaxEncodedLen) + /// Storage: Battlepass BattlepassStates (r:1 w:0) + /// Proof: Battlepass BattlepassStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Control OrgStates (r:1 w:0) + /// Proof: Control OrgStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Control Orgs (r:1 w:0) + /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) + /// Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) + /// Proof: Battlepass BattlepassInfoByOrg (max_values: None, max_size: Some(118), added: 2593, mode: MaxEncodedLen) fn update_reward() -> Weight { - // Minimum execution time: 46_000 nanoseconds. - Weight::from_ref_time(47_000_000) - .saturating_add(T::DbWeight::get().reads(7)) - .saturating_add(T::DbWeight::get().writes(1)) + // Proof Size summary in bytes: + // Measured: `1169` + // Estimated: `18608` + // Minimum execution time: 41_000 nanoseconds. + Weight::from_parts(41_000_000, 18608) + .saturating_add(T::DbWeight::get().reads(7_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) } - // Storage: Battlepass Rewards (r:1 w:0) - // Storage: Battlepass RewardStates (r:1 w:1) - // Storage: Battlepass Battlepasses (r:1 w:0) - // Storage: Control Orgs (r:1 w:0) - // Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) + /// Storage: Battlepass Rewards (r:1 w:0) + /// Proof: Battlepass Rewards (max_values: None, max_size: Some(346), added: 2821, mode: MaxEncodedLen) + /// Storage: Battlepass RewardStates (r:1 w:1) + /// Proof: Battlepass RewardStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Battlepass Battlepasses (r:1 w:0) + /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(382), added: 2857, mode: MaxEncodedLen) + /// Storage: Control Orgs (r:1 w:0) + /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) + /// Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) + /// Proof: Battlepass BattlepassInfoByOrg (max_values: None, max_size: Some(118), added: 2593, mode: MaxEncodedLen) fn disable_reward() -> Weight { - // Minimum execution time: 39_000 nanoseconds. - Weight::from_ref_time(41_000_000) - .saturating_add(T::DbWeight::get().reads(5)) - .saturating_add(T::DbWeight::get().writes(1)) + // Proof Size summary in bytes: + // Measured: `1094` + // Estimated: `13560` + // Minimum execution time: 33_000 nanoseconds. + Weight::from_parts(33_000_000, 13560) + .saturating_add(T::DbWeight::get().reads(5_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) } - // Storage: Battlepass Rewards (r:1 w:0) - // Storage: Battlepass RewardStates (r:1 w:0) - // Storage: Battlepass ClaimedRewards (r:1 w:1) - // Storage: Battlepass Battlepasses (r:1 w:0) - // Storage: Battlepass BattlepassStates (r:1 w:0) - // Storage: Control OrgStates (r:1 w:0) - // Storage: Control Orgs (r:1 w:0) - // Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) - // Storage: Battlepass ClaimedBattlepasses (r:1 w:0) - // Storage: Uniques Asset (r:2 w:1) - // Storage: Uniques InstanceMetadataOf (r:2 w:1) - // Storage: Battlepass Points (r:1 w:0) - // Storage: Battlepass Levels (r:2 w:0) - // Storage: Battlepass NftIndex (r:1 w:1) - // Storage: Uniques Class (r:1 w:1) - // Storage: Uniques CollectionMaxSupply (r:1 w:0) - // Storage: Uniques Account (r:0 w:1) + /// Storage: Battlepass Rewards (r:1 w:0) + /// Proof: Battlepass Rewards (max_values: None, max_size: Some(346), added: 2821, mode: MaxEncodedLen) + /// Storage: Battlepass RewardStates (r:1 w:0) + /// Proof: Battlepass RewardStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Battlepass ClaimedRewards (r:1 w:1) + /// Proof: Battlepass ClaimedRewards (max_values: None, max_size: Some(100), added: 2575, mode: MaxEncodedLen) + /// Storage: Battlepass Battlepasses (r:1 w:0) + /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(382), added: 2857, mode: MaxEncodedLen) + /// Storage: Battlepass BattlepassStates (r:1 w:0) + /// Proof: Battlepass BattlepassStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Control OrgStates (r:1 w:0) + /// Proof: Control OrgStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Control Orgs (r:1 w:0) + /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) + /// Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) + /// Proof: Battlepass BattlepassInfoByOrg (max_values: None, max_size: Some(118), added: 2593, mode: MaxEncodedLen) + /// Storage: Uniques Account (r:2 w:1) + /// Proof: Uniques Account (max_values: None, max_size: Some(88), added: 2563, mode: MaxEncodedLen) + /// Storage: Battlepass Points (r:1 w:0) + /// Proof: Battlepass Points (max_values: None, max_size: Some(100), added: 2575, mode: MaxEncodedLen) + /// Storage: Battlepass Levels (r:2 w:0) + /// Proof: Battlepass Levels (max_values: None, max_size: Some(69), added: 2544, mode: MaxEncodedLen) + /// Storage: Battlepass NftIndex (r:1 w:1) + /// Proof: Battlepass NftIndex (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) + /// Storage: Uniques Asset (r:1 w:1) + /// Proof: Uniques Asset (max_values: None, max_size: Some(122), added: 2597, mode: MaxEncodedLen) + /// Storage: Uniques Class (r:1 w:1) + /// Proof: Uniques Class (max_values: None, max_size: Some(178), added: 2653, 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(187), added: 2662, mode: MaxEncodedLen) fn claim_reward() -> Weight { - // Minimum execution time: 137_000 nanoseconds. - Weight::from_ref_time(141_000_000) - .saturating_add(T::DbWeight::get().reads(19)) - .saturating_add(T::DbWeight::get().writes(6)) + // Proof Size summary in bytes: + // Measured: `2203` + // Estimated: `44882` + // Minimum execution time: 133_000 nanoseconds. + Weight::from_parts(135_000_000, 44882) + .saturating_add(T::DbWeight::get().reads(18_u64)) + .saturating_add(T::DbWeight::get().writes(6_u64)) } - // Storage: Battlepass Battlepasses (r:1 w:0) - // Storage: Battlepass BattlepassStates (r:1 w:0) - // Storage: Control OrgStates (r:1 w:0) - // Storage: Control Orgs (r:1 w:0) - // Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) - // Storage: Battlepass Levels (r:0 w:1) + /// Storage: Battlepass Battlepasses (r:1 w:0) + /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(382), added: 2857, mode: MaxEncodedLen) + /// Storage: Battlepass BattlepassStates (r:1 w:0) + /// Proof: Battlepass BattlepassStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Control OrgStates (r:1 w:0) + /// Proof: Control OrgStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Control Orgs (r:1 w:0) + /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) + /// Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) + /// Proof: Battlepass BattlepassInfoByOrg (max_values: None, max_size: Some(118), added: 2593, mode: MaxEncodedLen) + /// Storage: Battlepass Levels (r:0 w:1) + /// Proof: Battlepass Levels (max_values: None, max_size: Some(69), added: 2544, mode: MaxEncodedLen) fn add_level() -> Weight { - // Minimum execution time: 39_000 nanoseconds. - Weight::from_ref_time(41_000_000) - .saturating_add(T::DbWeight::get().reads(5)) - .saturating_add(T::DbWeight::get().writes(1)) + // Proof Size summary in bytes: + // Measured: `945` + // Estimated: `13263` + // Minimum execution time: 31_000 nanoseconds. + Weight::from_parts(32_000_000, 13263) + .saturating_add(T::DbWeight::get().reads(5_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) } - // Storage: Battlepass Battlepasses (r:1 w:0) - // Storage: Battlepass BattlepassStates (r:1 w:0) - // Storage: Control OrgStates (r:1 w:0) - // Storage: Control Orgs (r:1 w:0) - // Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) - // Storage: Battlepass Levels (r:1 w:1) + /// Storage: Battlepass Battlepasses (r:1 w:0) + /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(382), added: 2857, mode: MaxEncodedLen) + /// Storage: Battlepass BattlepassStates (r:1 w:0) + /// Proof: Battlepass BattlepassStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Control OrgStates (r:1 w:0) + /// Proof: Control OrgStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Control Orgs (r:1 w:0) + /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) + /// Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) + /// Proof: Battlepass BattlepassInfoByOrg (max_values: None, max_size: Some(118), added: 2593, mode: MaxEncodedLen) + /// Storage: Battlepass Levels (r:1 w:1) + /// Proof: Battlepass Levels (max_values: None, max_size: Some(69), added: 2544, mode: MaxEncodedLen) fn remove_level() -> Weight { - // Minimum execution time: 40_000 nanoseconds. - Weight::from_ref_time(42_000_000) - .saturating_add(T::DbWeight::get().reads(6)) - .saturating_add(T::DbWeight::get().writes(1)) + // Proof Size summary in bytes: + // Measured: `1038` + // Estimated: `15807` + // Minimum execution time: 36_000 nanoseconds. + Weight::from_parts(37_000_000, 15807) + .saturating_add(T::DbWeight::get().reads(6_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) } - // Storage: Battlepass Battlepasses (r:1 w:0) - // Storage: Battlepass BattlepassStates (r:1 w:0) - // Storage: Control OrgStates (r:1 w:0) - // Storage: Control Orgs (r:1 w:0) - // Storage: Battlepass BattlepassInfoByOrg (r:1 w:1) + /// Storage: Battlepass Battlepasses (r:1 w:0) + /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(382), added: 2857, mode: MaxEncodedLen) + /// Storage: Battlepass BattlepassStates (r:1 w:0) + /// Proof: Battlepass BattlepassStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Control OrgStates (r:1 w:0) + /// Proof: Control OrgStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Control Orgs (r:1 w:0) + /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) + /// Storage: Battlepass BattlepassInfoByOrg (r:1 w:1) + /// Proof: Battlepass BattlepassInfoByOrg (max_values: None, max_size: Some(118), added: 2593, mode: MaxEncodedLen) fn add_bot() -> Weight { - // Minimum execution time: 35_000 nanoseconds. - Weight::from_ref_time(35_000_000) - .saturating_add(T::DbWeight::get().reads(5)) - .saturating_add(T::DbWeight::get().writes(1)) + // Proof Size summary in bytes: + // Measured: `880` + // Estimated: `13263` + // Minimum execution time: 30_000 nanoseconds. + Weight::from_parts(31_000_000, 13263) + .saturating_add(T::DbWeight::get().reads(5_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) } } // For backwards compatibility and tests impl WeightInfo for () { - // Storage: Control OrgStates (r:1 w:0) - // Storage: Control Orgs (r:1 w:0) - // Storage: Battlepass BattlepassInfoByOrg (r:1 w:1) - // Storage: Battlepass CollectionIndex (r:1 w:1) - // Storage: Uniques Class (r:1 w:1) - // Storage: Uniques ClassMetadataOf (r:1 w:1) - // Storage: Uniques ClassAccount (r:0 w:1) - // Storage: Battlepass BattlepassStates (r:0 w:1) - // Storage: Battlepass Battlepasses (r:0 w:1) + /// Storage: Control OrgStates (r:1 w:0) + /// Proof: Control OrgStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Control Orgs (r:1 w:0) + /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) + /// Storage: Battlepass BattlepassInfoByOrg (r:1 w:1) + /// Proof: Battlepass BattlepassInfoByOrg (max_values: None, max_size: Some(118), added: 2593, mode: MaxEncodedLen) + /// Storage: Battlepass CollectionIndex (r:1 w:1) + /// Proof: Battlepass CollectionIndex (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: Uniques ClassMetadataOf (r:1 w:1) + /// Proof: Uniques ClassMetadataOf (max_values: None, max_size: Some(167), added: 2642, mode: MaxEncodedLen) + /// Storage: Uniques ClassAccount (r:0 w:1) + /// Proof: Uniques ClassAccount (max_values: None, max_size: Some(68), added: 2543, mode: MaxEncodedLen) + /// Storage: Battlepass BattlepassStates (r:0 w:1) + /// Proof: Battlepass BattlepassStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Battlepass Battlepasses (r:0 w:1) + /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(382), added: 2857, mode: MaxEncodedLen) fn create_battlepass() -> Weight { - // Minimum execution time: 93_000 nanoseconds. - Weight::from_ref_time(95_000_000) - .saturating_add(RocksDbWeight::get().reads(6)) - .saturating_add(RocksDbWeight::get().writes(7)) + // Proof Size summary in bytes: + // Measured: `597` + // Estimated: `13676` + // Minimum execution time: 86_000 nanoseconds. + Weight::from_parts(86_000_000, 13676) + .saturating_add(RocksDbWeight::get().reads(6_u64)) + .saturating_add(RocksDbWeight::get().writes(7_u64)) } - // Storage: Battlepass Battlepasses (r:1 w:1) - // Storage: Battlepass BattlepassStates (r:1 w:0) - // Storage: Control OrgStates (r:1 w:0) - // Storage: Control Orgs (r:1 w:0) + /// Storage: Battlepass Battlepasses (r:1 w:1) + /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(382), added: 2857, mode: MaxEncodedLen) + /// Storage: Battlepass BattlepassStates (r:1 w:0) + /// Proof: Battlepass BattlepassStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Control OrgStates (r:1 w:0) + /// Proof: Control OrgStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Control Orgs (r:1 w:0) + /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) fn update_battlepass() -> Weight { - // Minimum execution time: 35_000 nanoseconds. - Weight::from_ref_time(36_000_000) - .saturating_add(RocksDbWeight::get().reads(4)) - .saturating_add(RocksDbWeight::get().writes(1)) + // Proof Size summary in bytes: + // Measured: `837` + // Estimated: `10670` + // Minimum execution time: 29_000 nanoseconds. + Weight::from_parts(30_000_000, 10670) + .saturating_add(RocksDbWeight::get().reads(4_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) } - // Storage: Battlepass Battlepasses (r:1 w:0) - // Storage: Battlepass BattlepassStates (r:1 w:0) - // Storage: Control OrgStates (r:1 w:0) - // Storage: Control Orgs (r:1 w:0) - // Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) - // Storage: Battlepass ClaimedBattlepasses (r:1 w:1) - // Storage: Battlepass NftIndex (r:1 w:1) - // Storage: Uniques Asset (r:1 w:1) - // Storage: Uniques Class (r:1 w:1) - // Storage: Uniques CollectionMaxSupply (r:1 w:0) - // Storage: Uniques InstanceMetadataOf (r:1 w:1) - // Storage: Uniques Account (r:0 w:1) + /// Storage: Battlepass Battlepasses (r:1 w:0) + /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(382), added: 2857, mode: MaxEncodedLen) + /// Storage: Battlepass BattlepassStates (r:1 w:0) + /// Proof: Battlepass BattlepassStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Control OrgStates (r:1 w:0) + /// Proof: Control OrgStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Control Orgs (r:1 w:0) + /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) + /// Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) + /// Proof: Battlepass BattlepassInfoByOrg (max_values: None, max_size: Some(118), added: 2593, mode: MaxEncodedLen) + /// Storage: Uniques Account (r:1 w:1) + /// Proof: Uniques Account (max_values: None, max_size: Some(88), added: 2563, mode: MaxEncodedLen) + /// Storage: Battlepass NftIndex (r:1 w:1) + /// Proof: Battlepass NftIndex (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) + /// Storage: Uniques Asset (r:1 w:1) + /// Proof: Uniques Asset (max_values: None, max_size: Some(122), added: 2597, mode: MaxEncodedLen) + /// Storage: Uniques Class (r:1 w:1) + /// Proof: Uniques Class (max_values: None, max_size: Some(178), added: 2653, 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(187), added: 2662, mode: MaxEncodedLen) fn claim_battlepass() -> Weight { - // Minimum execution time: 101_000 nanoseconds. - Weight::from_ref_time(105_000_000) - .saturating_add(RocksDbWeight::get().reads(11)) - .saturating_add(RocksDbWeight::get().writes(6)) + // Proof Size summary in bytes: + // Measured: `1359` + // Estimated: `26736` + // Minimum execution time: 95_000 nanoseconds. + Weight::from_parts(98_000_000, 26736) + .saturating_add(RocksDbWeight::get().reads(11_u64)) + .saturating_add(RocksDbWeight::get().writes(5_u64)) } - // Storage: Battlepass Battlepasses (r:1 w:0) - // Storage: Battlepass BattlepassStates (r:1 w:1) - // Storage: Control OrgStates (r:1 w:0) - // Storage: Control Orgs (r:1 w:0) - // Storage: Battlepass BattlepassInfoByOrg (r:1 w:1) + /// Storage: Battlepass Battlepasses (r:1 w:0) + /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(382), added: 2857, mode: MaxEncodedLen) + /// Storage: Battlepass BattlepassStates (r:1 w:1) + /// Proof: Battlepass BattlepassStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Control OrgStates (r:1 w:0) + /// Proof: Control OrgStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Control Orgs (r:1 w:0) + /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) + /// Storage: Battlepass BattlepassInfoByOrg (r:1 w:1) + /// Proof: Battlepass BattlepassInfoByOrg (max_values: None, max_size: Some(118), added: 2593, mode: MaxEncodedLen) fn activate_battlepass() -> Weight { - // Minimum execution time: 43_000 nanoseconds. - Weight::from_ref_time(44_000_000) - .saturating_add(RocksDbWeight::get().reads(5)) - .saturating_add(RocksDbWeight::get().writes(2)) + // Proof Size summary in bytes: + // Measured: `880` + // Estimated: `13263` + // Minimum execution time: 36_000 nanoseconds. + Weight::from_parts(37_000_000, 13263) + .saturating_add(RocksDbWeight::get().reads(5_u64)) + .saturating_add(RocksDbWeight::get().writes(2_u64)) } - // Storage: Battlepass Battlepasses (r:1 w:0) - // Storage: Battlepass BattlepassStates (r:1 w:1) - // Storage: Control Orgs (r:1 w:0) - // Storage: Battlepass BattlepassInfoByOrg (r:1 w:1) + /// Storage: Battlepass Battlepasses (r:1 w:0) + /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(382), added: 2857, mode: MaxEncodedLen) + /// Storage: Battlepass BattlepassStates (r:1 w:1) + /// Proof: Battlepass BattlepassStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Control Orgs (r:1 w:0) + /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) + /// Storage: Battlepass BattlepassInfoByOrg (r:1 w:1) + /// Proof: Battlepass BattlepassInfoByOrg (max_values: None, max_size: Some(118), added: 2593, mode: MaxEncodedLen) fn conclude_battlepass() -> Weight { - // Minimum execution time: 38_000 nanoseconds. - Weight::from_ref_time(40_000_000) - .saturating_add(RocksDbWeight::get().reads(4)) - .saturating_add(RocksDbWeight::get().writes(2)) + // Proof Size summary in bytes: + // Measured: `907` + // Estimated: `10739` + // Minimum execution time: 33_000 nanoseconds. + Weight::from_parts(34_000_000, 10739) + .saturating_add(RocksDbWeight::get().reads(4_u64)) + .saturating_add(RocksDbWeight::get().writes(2_u64)) } - // Storage: Battlepass Battlepasses (r:1 w:0) - // Storage: Battlepass BattlepassStates (r:1 w:0) - // Storage: Control OrgStates (r:1 w:0) - // Storage: Control Orgs (r:1 w:0) - // Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) - // Storage: Battlepass ClaimedBattlepasses (r:1 w:0) - // Storage: Uniques Asset (r:1 w:0) - // Storage: Uniques InstanceMetadataOf (r:1 w:0) - // Storage: Battlepass Points (r:0 w:1) + /// Storage: Battlepass Battlepasses (r:1 w:0) + /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(382), added: 2857, mode: MaxEncodedLen) + /// Storage: Battlepass BattlepassStates (r:1 w:0) + /// Proof: Battlepass BattlepassStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Control OrgStates (r:1 w:0) + /// Proof: Control OrgStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Control Orgs (r:1 w:0) + /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) + /// Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) + /// Proof: Battlepass BattlepassInfoByOrg (max_values: None, max_size: Some(118), added: 2593, mode: MaxEncodedLen) + /// Storage: Uniques Account (r:2 w:0) + /// Proof: Uniques Account (max_values: None, max_size: Some(88), added: 2563, mode: MaxEncodedLen) + /// Storage: Battlepass Points (r:0 w:1) + /// Proof: Battlepass Points (max_values: None, max_size: Some(100), added: 2575, mode: MaxEncodedLen) fn set_points() -> Weight { - // Minimum execution time: 51_000 nanoseconds. - Weight::from_ref_time(53_000_000) - .saturating_add(RocksDbWeight::get().reads(8)) - .saturating_add(RocksDbWeight::get().writes(1)) + // Proof Size summary in bytes: + // Measured: `1417` + // Estimated: `18389` + // Minimum execution time: 44_000 nanoseconds. + Weight::from_parts(44_000_000, 18389) + .saturating_add(RocksDbWeight::get().reads(7_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) } - // Storage: Battlepass Battlepasses (r:1 w:0) - // Storage: Battlepass BattlepassStates (r:1 w:0) - // Storage: Control OrgStates (r:1 w:0) - // Storage: Control Orgs (r:1 w:0) - // Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) - // Storage: Battlepass CollectionIndex (r:1 w:1) - // Storage: Uniques Class (r:1 w:1) - // Storage: Uniques ClassMetadataOf (r:1 w:1) - // Storage: Uniques CollectionMaxSupply (r:1 w:1) - // Storage: Uniques ClassAccount (r:0 w:1) - // Storage: Battlepass Rewards (r:0 w:1) - // Storage: Battlepass RewardStates (r:0 w:1) + /// Storage: Battlepass Battlepasses (r:1 w:0) + /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(382), added: 2857, mode: MaxEncodedLen) + /// Storage: Battlepass BattlepassStates (r:1 w:0) + /// Proof: Battlepass BattlepassStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Control OrgStates (r:1 w:0) + /// Proof: Control OrgStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Control Orgs (r:1 w:0) + /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) + /// Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) + /// Proof: Battlepass BattlepassInfoByOrg (max_values: None, max_size: Some(118), added: 2593, mode: MaxEncodedLen) + /// Storage: Battlepass CollectionIndex (r:1 w:1) + /// Proof: Battlepass CollectionIndex (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: Uniques ClassMetadataOf (r:1 w:1) + /// Proof: Uniques ClassMetadataOf (max_values: None, max_size: Some(167), added: 2642, mode: MaxEncodedLen) + /// Storage: Uniques CollectionMaxSupply (r:1 w:1) + /// Proof: Uniques CollectionMaxSupply (max_values: None, max_size: Some(24), added: 2499, mode: MaxEncodedLen) + /// Storage: Uniques ClassAccount (r:0 w:1) + /// Proof: Uniques ClassAccount (max_values: None, max_size: Some(68), added: 2543, mode: MaxEncodedLen) + /// Storage: Battlepass Rewards (r:0 w:1) + /// Proof: Battlepass Rewards (max_values: None, max_size: Some(346), added: 2821, mode: MaxEncodedLen) + /// Storage: Battlepass RewardStates (r:0 w:1) + /// Proof: Battlepass RewardStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) fn create_reward() -> Weight { - // Minimum execution time: 116_000 nanoseconds. - Weight::from_ref_time(120_000_000) - .saturating_add(RocksDbWeight::get().reads(9)) - .saturating_add(RocksDbWeight::get().writes(7)) + // Proof Size summary in bytes: + // Measured: `1226` + // Estimated: `21556` + // Minimum execution time: 110_000 nanoseconds. + Weight::from_parts(112_000_000, 21556) + .saturating_add(RocksDbWeight::get().reads(9_u64)) + .saturating_add(RocksDbWeight::get().writes(7_u64)) } - // Storage: Battlepass Rewards (r:1 w:1) - // Storage: Battlepass RewardStates (r:1 w:0) - // Storage: Battlepass Battlepasses (r:1 w:0) - // Storage: Battlepass BattlepassStates (r:1 w:0) - // Storage: Control OrgStates (r:1 w:0) - // Storage: Control Orgs (r:1 w:0) - // Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) + /// Storage: Battlepass Rewards (r:1 w:1) + /// Proof: Battlepass Rewards (max_values: None, max_size: Some(346), added: 2821, mode: MaxEncodedLen) + /// Storage: Battlepass RewardStates (r:1 w:0) + /// Proof: Battlepass RewardStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Battlepass Battlepasses (r:1 w:0) + /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(382), added: 2857, mode: MaxEncodedLen) + /// Storage: Battlepass BattlepassStates (r:1 w:0) + /// Proof: Battlepass BattlepassStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Control OrgStates (r:1 w:0) + /// Proof: Control OrgStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Control Orgs (r:1 w:0) + /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) + /// Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) + /// Proof: Battlepass BattlepassInfoByOrg (max_values: None, max_size: Some(118), added: 2593, mode: MaxEncodedLen) fn update_reward() -> Weight { - // Minimum execution time: 46_000 nanoseconds. - Weight::from_ref_time(47_000_000) - .saturating_add(RocksDbWeight::get().reads(7)) - .saturating_add(RocksDbWeight::get().writes(1)) + // Proof Size summary in bytes: + // Measured: `1169` + // Estimated: `18608` + // Minimum execution time: 41_000 nanoseconds. + Weight::from_parts(41_000_000, 18608) + .saturating_add(RocksDbWeight::get().reads(7_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) } - // Storage: Battlepass Rewards (r:1 w:0) - // Storage: Battlepass RewardStates (r:1 w:1) - // Storage: Battlepass Battlepasses (r:1 w:0) - // Storage: Control Orgs (r:1 w:0) - // Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) + /// Storage: Battlepass Rewards (r:1 w:0) + /// Proof: Battlepass Rewards (max_values: None, max_size: Some(346), added: 2821, mode: MaxEncodedLen) + /// Storage: Battlepass RewardStates (r:1 w:1) + /// Proof: Battlepass RewardStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Battlepass Battlepasses (r:1 w:0) + /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(382), added: 2857, mode: MaxEncodedLen) + /// Storage: Control Orgs (r:1 w:0) + /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) + /// Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) + /// Proof: Battlepass BattlepassInfoByOrg (max_values: None, max_size: Some(118), added: 2593, mode: MaxEncodedLen) fn disable_reward() -> Weight { - // Minimum execution time: 39_000 nanoseconds. - Weight::from_ref_time(41_000_000) - .saturating_add(RocksDbWeight::get().reads(5)) - .saturating_add(RocksDbWeight::get().writes(1)) + // Proof Size summary in bytes: + // Measured: `1094` + // Estimated: `13560` + // Minimum execution time: 33_000 nanoseconds. + Weight::from_parts(33_000_000, 13560) + .saturating_add(RocksDbWeight::get().reads(5_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) } - // Storage: Battlepass Rewards (r:1 w:0) - // Storage: Battlepass RewardStates (r:1 w:0) - // Storage: Battlepass ClaimedRewards (r:1 w:1) - // Storage: Battlepass Battlepasses (r:1 w:0) - // Storage: Battlepass BattlepassStates (r:1 w:0) - // Storage: Control OrgStates (r:1 w:0) - // Storage: Control Orgs (r:1 w:0) - // Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) - // Storage: Battlepass ClaimedBattlepasses (r:1 w:0) - // Storage: Uniques Asset (r:2 w:1) - // Storage: Uniques InstanceMetadataOf (r:2 w:1) - // Storage: Battlepass Points (r:1 w:0) - // Storage: Battlepass Levels (r:2 w:0) - // Storage: Battlepass NftIndex (r:1 w:1) - // Storage: Uniques Class (r:1 w:1) - // Storage: Uniques CollectionMaxSupply (r:1 w:0) - // Storage: Uniques Account (r:0 w:1) + /// Storage: Battlepass Rewards (r:1 w:0) + /// Proof: Battlepass Rewards (max_values: None, max_size: Some(346), added: 2821, mode: MaxEncodedLen) + /// Storage: Battlepass RewardStates (r:1 w:0) + /// Proof: Battlepass RewardStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Battlepass ClaimedRewards (r:1 w:1) + /// Proof: Battlepass ClaimedRewards (max_values: None, max_size: Some(100), added: 2575, mode: MaxEncodedLen) + /// Storage: Battlepass Battlepasses (r:1 w:0) + /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(382), added: 2857, mode: MaxEncodedLen) + /// Storage: Battlepass BattlepassStates (r:1 w:0) + /// Proof: Battlepass BattlepassStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Control OrgStates (r:1 w:0) + /// Proof: Control OrgStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Control Orgs (r:1 w:0) + /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) + /// Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) + /// Proof: Battlepass BattlepassInfoByOrg (max_values: None, max_size: Some(118), added: 2593, mode: MaxEncodedLen) + /// Storage: Uniques Account (r:2 w:1) + /// Proof: Uniques Account (max_values: None, max_size: Some(88), added: 2563, mode: MaxEncodedLen) + /// Storage: Battlepass Points (r:1 w:0) + /// Proof: Battlepass Points (max_values: None, max_size: Some(100), added: 2575, mode: MaxEncodedLen) + /// Storage: Battlepass Levels (r:2 w:0) + /// Proof: Battlepass Levels (max_values: None, max_size: Some(69), added: 2544, mode: MaxEncodedLen) + /// Storage: Battlepass NftIndex (r:1 w:1) + /// Proof: Battlepass NftIndex (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) + /// Storage: Uniques Asset (r:1 w:1) + /// Proof: Uniques Asset (max_values: None, max_size: Some(122), added: 2597, mode: MaxEncodedLen) + /// Storage: Uniques Class (r:1 w:1) + /// Proof: Uniques Class (max_values: None, max_size: Some(178), added: 2653, 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(187), added: 2662, mode: MaxEncodedLen) fn claim_reward() -> Weight { - // Minimum execution time: 137_000 nanoseconds. - Weight::from_ref_time(141_000_000) - .saturating_add(RocksDbWeight::get().reads(19)) - .saturating_add(RocksDbWeight::get().writes(6)) + // Proof Size summary in bytes: + // Measured: `2203` + // Estimated: `44882` + // Minimum execution time: 133_000 nanoseconds. + Weight::from_parts(135_000_000, 44882) + .saturating_add(RocksDbWeight::get().reads(18_u64)) + .saturating_add(RocksDbWeight::get().writes(6_u64)) } - // Storage: Battlepass Battlepasses (r:1 w:0) - // Storage: Battlepass BattlepassStates (r:1 w:0) - // Storage: Control OrgStates (r:1 w:0) - // Storage: Control Orgs (r:1 w:0) - // Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) - // Storage: Battlepass Levels (r:0 w:1) + /// Storage: Battlepass Battlepasses (r:1 w:0) + /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(382), added: 2857, mode: MaxEncodedLen) + /// Storage: Battlepass BattlepassStates (r:1 w:0) + /// Proof: Battlepass BattlepassStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Control OrgStates (r:1 w:0) + /// Proof: Control OrgStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Control Orgs (r:1 w:0) + /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) + /// Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) + /// Proof: Battlepass BattlepassInfoByOrg (max_values: None, max_size: Some(118), added: 2593, mode: MaxEncodedLen) + /// Storage: Battlepass Levels (r:0 w:1) + /// Proof: Battlepass Levels (max_values: None, max_size: Some(69), added: 2544, mode: MaxEncodedLen) fn add_level() -> Weight { - // Minimum execution time: 39_000 nanoseconds. - Weight::from_ref_time(41_000_000) - .saturating_add(RocksDbWeight::get().reads(5)) - .saturating_add(RocksDbWeight::get().writes(1)) + // Proof Size summary in bytes: + // Measured: `945` + // Estimated: `13263` + // Minimum execution time: 31_000 nanoseconds. + Weight::from_parts(32_000_000, 13263) + .saturating_add(RocksDbWeight::get().reads(5_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) } - // Storage: Battlepass Battlepasses (r:1 w:0) - // Storage: Battlepass BattlepassStates (r:1 w:0) - // Storage: Control OrgStates (r:1 w:0) - // Storage: Control Orgs (r:1 w:0) - // Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) - // Storage: Battlepass Levels (r:1 w:1) + /// Storage: Battlepass Battlepasses (r:1 w:0) + /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(382), added: 2857, mode: MaxEncodedLen) + /// Storage: Battlepass BattlepassStates (r:1 w:0) + /// Proof: Battlepass BattlepassStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Control OrgStates (r:1 w:0) + /// Proof: Control OrgStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Control Orgs (r:1 w:0) + /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) + /// Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) + /// Proof: Battlepass BattlepassInfoByOrg (max_values: None, max_size: Some(118), added: 2593, mode: MaxEncodedLen) + /// Storage: Battlepass Levels (r:1 w:1) + /// Proof: Battlepass Levels (max_values: None, max_size: Some(69), added: 2544, mode: MaxEncodedLen) fn remove_level() -> Weight { - // Minimum execution time: 40_000 nanoseconds. - Weight::from_ref_time(42_000_000) - .saturating_add(RocksDbWeight::get().reads(6)) - .saturating_add(RocksDbWeight::get().writes(1)) + // Proof Size summary in bytes: + // Measured: `1038` + // Estimated: `15807` + // Minimum execution time: 36_000 nanoseconds. + Weight::from_parts(37_000_000, 15807) + .saturating_add(RocksDbWeight::get().reads(6_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) } - // Storage: Battlepass Battlepasses (r:1 w:0) - // Storage: Battlepass BattlepassStates (r:1 w:0) - // Storage: Control OrgStates (r:1 w:0) - // Storage: Control Orgs (r:1 w:0) - // Storage: Battlepass BattlepassInfoByOrg (r:1 w:1) + /// Storage: Battlepass Battlepasses (r:1 w:0) + /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(382), added: 2857, mode: MaxEncodedLen) + /// Storage: Battlepass BattlepassStates (r:1 w:0) + /// Proof: Battlepass BattlepassStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Control OrgStates (r:1 w:0) + /// Proof: Control OrgStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Control Orgs (r:1 w:0) + /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) + /// Storage: Battlepass BattlepassInfoByOrg (r:1 w:1) + /// Proof: Battlepass BattlepassInfoByOrg (max_values: None, max_size: Some(118), added: 2593, mode: MaxEncodedLen) fn add_bot() -> Weight { - // Minimum execution time: 35_000 nanoseconds. - Weight::from_ref_time(35_000_000) - .saturating_add(RocksDbWeight::get().reads(5)) - .saturating_add(RocksDbWeight::get().writes(1)) + // Proof Size summary in bytes: + // Measured: `880` + // Estimated: `13263` + // Minimum execution time: 30_000 nanoseconds. + Weight::from_parts(31_000_000, 13263) + .saturating_add(RocksDbWeight::get().reads(5_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) } } \ No newline at end of file diff --git a/control/Cargo.toml b/control/Cargo.toml index b3132c03b..b1aa751a6 100755 --- a/control/Cargo.toml +++ b/control/Cargo.toml @@ -5,7 +5,7 @@ # ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ [package] name = "gamedao-control" -version = "1.2.0" +version = "1.3.0" authors = ["zero.io","gamedao.co"] repository = "https://github.com/gamedaoco/gamedao-protocol" edition = "2018" @@ -17,32 +17,32 @@ hex-literal = "0.3.4" num_enum = { version = "0.5.1", default-features = false } serde = { version = "1.0.143", default-features = false } -codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] } +codec = { package = "parity-scale-codec", version = "3.2.2", default-features = false, features = ["derive"] } scale-info = { version = "2.1.1", default-features = false, features = ["derive"] } -sp-core = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } -sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } -sp-std = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } -sp-storage = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } +sp-core = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } +sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } +sp-std = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } +sp-storage = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } -frame-support = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } -frame-system = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } -frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36", default-features = false, optional = true } -sp-io = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.36", default-features=false } +frame-support = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } +frame-system = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } +frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38", default-features = false, optional = true } +sp-io = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.38", default-features=false } -pallet-balances = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } +pallet-balances = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } -orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.36", default-features = false } +orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.38", default-features = false } gamedao-traits = { package = "gamedao-traits", path = "../traits", default-features = false } # tangram = { package = "module-tangram", path = "../../zero/tangram", default-features = false } [dev-dependencies] -sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.36" } -sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.36" } -pallet-balances = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } -orml-currencies = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.36", default-features = false } -orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.36", default-features = false } +sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.38" } +sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.38" } +pallet-balances = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } +orml-currencies = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.38", default-features = false } +orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.38", default-features = false } [features] default = ["std"] diff --git a/control/src/weights.rs b/control/src/weights.rs index c92926dea..6583e7cd7 100644 --- a/control/src/weights.rs +++ b/control/src/weights.rs @@ -2,7 +2,8 @@ //! Autogenerated weights for gamedao_control //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-02-10, STEPS: `20`, REPEAT: 10, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2023-03-04, STEPS: `20`, REPEAT: `10`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! WORST CASE MAP SIZE: `1000000` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: None, DB CACHE: 1024 // Executed Command: @@ -39,174 +40,282 @@ pub trait WeightInfo { /// Weights for gamedao_control using the Substrate node and recommended hardware. pub struct SubstrateWeight(PhantomData); impl WeightInfo for SubstrateWeight { - // Storage: Control OrgCount (r:1 w:1) - // Storage: System Account (r:1 w:1) - // Storage: Control Orgs (r:1 w:1) - // Storage: Tokens Accounts (r:2 w:2) - // Storage: Control Members (r:1 w:1) - // Storage: Control OrgMemberCount (r:0 w:1) - // Storage: Control OrgTreasury (r:0 w:1) - // Storage: Control MemberStates (r:0 w:1) - // Storage: Control OrgStates (r:0 w:1) + /// Storage: Control OrgCount (r:1 w:1) + /// Proof: Control OrgCount (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) + /// Storage: System Account (r:1 w:1) + /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) + /// Storage: Control Orgs (r:1 w:1) + /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) + /// Storage: Tokens Accounts (r:2 w:2) + /// Proof: Tokens Accounts (max_values: None, max_size: Some(109), added: 2584, mode: MaxEncodedLen) + /// Storage: Control Members (r:1 w:1) + /// Proof: Control Members (max_values: None, max_size: Some(32050), added: 34525, mode: MaxEncodedLen) + /// Storage: Control OrgMemberCount (r:0 w:1) + /// Proof: Control OrgMemberCount (max_values: None, max_size: Some(52), added: 2527, mode: MaxEncodedLen) + /// Storage: Control OrgTreasury (r:0 w:1) + /// Proof: Control OrgTreasury (max_values: None, max_size: Some(80), added: 2555, mode: MaxEncodedLen) + /// Storage: Control MemberStates (r:0 w:1) + /// Proof: Control MemberStates (max_values: None, max_size: Some(97), added: 2572, mode: MaxEncodedLen) + /// Storage: Control OrgStates (r:0 w:1) + /// Proof: Control OrgStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) fn create_org() -> Weight { - // Minimum execution time: 79_000 nanoseconds. - Weight::from_ref_time(81_000_000) - .saturating_add(T::DbWeight::get().reads(6)) - .saturating_add(T::DbWeight::get().writes(10)) + // Proof Size summary in bytes: + // Measured: `408` + // Estimated: `45560` + // Minimum execution time: 70_000 nanoseconds. + Weight::from_parts(71_000_000, 45560) + .saturating_add(T::DbWeight::get().reads(6_u64)) + .saturating_add(T::DbWeight::get().writes(10_u64)) } - // Storage: Control Orgs (r:1 w:1) - // Storage: Control MemberStates (r:1 w:0) + /// Storage: Control Orgs (r:1 w:1) + /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) + /// Storage: Control MemberStates (r:1 w:0) + /// Proof: Control MemberStates (max_values: None, max_size: Some(97), added: 2572, mode: MaxEncodedLen) fn update_org() -> Weight { - // Minimum execution time: 28_000 nanoseconds. - Weight::from_ref_time(29_000_000) - .saturating_add(T::DbWeight::get().reads(2)) - .saturating_add(T::DbWeight::get().writes(1)) + // Proof Size summary in bytes: + // Measured: `565` + // Estimated: `5337` + // Minimum execution time: 21_000 nanoseconds. + Weight::from_parts(22_000_000, 5337) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) } - // Storage: Control Orgs (r:1 w:0) - // Storage: Control OrgStates (r:0 w:1) + /// Storage: Control Orgs (r:1 w:0) + /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) + /// Storage: Control OrgStates (r:0 w:1) + /// Proof: Control OrgStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) fn disable_org() -> Weight { - // Minimum execution time: 23_000 nanoseconds. - Weight::from_ref_time(24_000_000) - .saturating_add(T::DbWeight::get().reads(1)) - .saturating_add(T::DbWeight::get().writes(1)) + // Proof Size summary in bytes: + // Measured: `480` + // Estimated: `2765` + // Minimum execution time: 17_000 nanoseconds. + Weight::from_parts(18_000_000, 2765) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) } - // Storage: Control Orgs (r:1 w:0) - // Storage: Control OrgStates (r:0 w:1) + /// Storage: Control Orgs (r:1 w:0) + /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) + /// Storage: Control OrgStates (r:0 w:1) + /// Proof: Control OrgStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) fn enable_org() -> Weight { - // Minimum execution time: 24_000 nanoseconds. - Weight::from_ref_time(25_000_000) - .saturating_add(T::DbWeight::get().reads(1)) - .saturating_add(T::DbWeight::get().writes(1)) - } - // Storage: Control Orgs (r:1 w:0) - // Storage: Control OrgTreasury (r:1 w:0) - // Storage: Control Members (r:1 w:1) - // Storage: Control OrgMemberCount (r:0 w:1) - // Storage: Control MemberStates (r:0 w:1) + // Proof Size summary in bytes: + // Measured: `480` + // Estimated: `2765` + // Minimum execution time: 17_000 nanoseconds. + Weight::from_parts(17_000_000, 2765) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: Control Orgs (r:1 w:0) + /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) + /// Storage: Control OrgTreasury (r:1 w:0) + /// Proof: Control OrgTreasury (max_values: None, max_size: Some(80), added: 2555, mode: MaxEncodedLen) + /// Storage: Control Members (r:1 w:1) + /// Proof: Control Members (max_values: None, max_size: Some(32050), added: 34525, mode: MaxEncodedLen) + /// Storage: Control OrgMemberCount (r:0 w:1) + /// Proof: Control OrgMemberCount (max_values: None, max_size: Some(52), added: 2527, mode: MaxEncodedLen) + /// Storage: Control MemberStates (r:0 w:1) + /// Proof: Control MemberStates (max_values: None, max_size: Some(97), added: 2572, mode: MaxEncodedLen) /// The range of component `r` is `[1, 999]`. fn add_member(r: u32, ) -> Weight { - // Minimum execution time: 36_000 nanoseconds. - Weight::from_ref_time(34_091_687) - // Standard Error: 1_851 - .saturating_add(Weight::from_ref_time(65_158).saturating_mul(r.into())) - .saturating_add(T::DbWeight::get().reads(3)) - .saturating_add(T::DbWeight::get().writes(3)) - } - // Storage: Control Orgs (r:1 w:0) - // Storage: Control MemberStates (r:1 w:0) + // Proof Size summary in bytes: + // Measured: `659 + r * (32 ±0)` + // Estimated: `39845` + // Minimum execution time: 29_000 nanoseconds. + Weight::from_parts(27_804_864, 39845) + // Standard Error: 897 + .saturating_add(Weight::from_ref_time(34_905).saturating_mul(r.into())) + .saturating_add(T::DbWeight::get().reads(3_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) + } + /// Storage: Control Orgs (r:1 w:0) + /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) + /// Storage: Control MemberStates (r:1 w:0) + /// Proof: Control MemberStates (max_values: None, max_size: Some(97), added: 2572, mode: MaxEncodedLen) fn update_member_state() -> Weight { - // Minimum execution time: 15_000 nanoseconds. - Weight::from_ref_time(16_000_000) - .saturating_add(T::DbWeight::get().reads(2)) - } - // Storage: Control Orgs (r:1 w:0) - // Storage: Control Members (r:1 w:1) - // Storage: Control OrgMemberCount (r:0 w:1) - // Storage: Control MemberStates (r:0 w:1) + // Proof Size summary in bytes: + // Measured: `604` + // Estimated: `5337` + // Minimum execution time: 14_000 nanoseconds. + Weight::from_parts(15_000_000, 5337) + .saturating_add(T::DbWeight::get().reads(2_u64)) + } + /// Storage: Control Orgs (r:1 w:0) + /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) + /// Storage: Control Members (r:1 w:1) + /// Proof: Control Members (max_values: None, max_size: Some(32050), added: 34525, mode: MaxEncodedLen) + /// Storage: Control OrgMemberCount (r:0 w:1) + /// Proof: Control OrgMemberCount (max_values: None, max_size: Some(52), added: 2527, mode: MaxEncodedLen) + /// Storage: Control MemberStates (r:0 w:1) + /// Proof: Control MemberStates (max_values: None, max_size: Some(97), added: 2572, mode: MaxEncodedLen) /// The range of component `r` is `[1, 999]`. fn remove_member(r: u32, ) -> Weight { - // Minimum execution time: 30_000 nanoseconds. - Weight::from_ref_time(37_544_684) - // Standard Error: 2_351 - .saturating_add(Weight::from_ref_time(43_383).saturating_mul(r.into())) - .saturating_add(T::DbWeight::get().reads(2)) - .saturating_add(T::DbWeight::get().writes(3)) - } - // Storage: Control Orgs (r:1 w:0) - // Storage: Control OrgTreasury (r:1 w:0) - // Storage: Tokens Accounts (r:2 w:2) - // Storage: System Account (r:2 w:1) + // Proof Size summary in bytes: + // Measured: `584 + r * (32 ±0)` + // Estimated: `37290` + // Minimum execution time: 25_000 nanoseconds. + Weight::from_parts(23_223_981, 37290) + // Standard Error: 874 + .saturating_add(Weight::from_ref_time(33_949).saturating_mul(r.into())) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) + } + /// Storage: Control Orgs (r:1 w:0) + /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) + /// Storage: Control OrgTreasury (r:1 w:0) + /// Proof: Control OrgTreasury (max_values: None, max_size: Some(80), added: 2555, mode: MaxEncodedLen) + /// Storage: Tokens Accounts (r:2 w:2) + /// Proof: Tokens Accounts (max_values: None, max_size: Some(109), added: 2584, mode: MaxEncodedLen) + /// Storage: System Account (r:2 w:1) + /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) fn spend_funds() -> Weight { - // Minimum execution time: 63_000 nanoseconds. - Weight::from_ref_time(64_000_000) - .saturating_add(T::DbWeight::get().reads(6)) - .saturating_add(T::DbWeight::get().writes(3)) + // Proof Size summary in bytes: + // Measured: `1040` + // Estimated: `15694` + // Minimum execution time: 58_000 nanoseconds. + Weight::from_parts(59_000_000, 15694) + .saturating_add(T::DbWeight::get().reads(6_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) } } // For backwards compatibility and tests impl WeightInfo for () { - // Storage: Control OrgCount (r:1 w:1) - // Storage: System Account (r:1 w:1) - // Storage: Control Orgs (r:1 w:1) - // Storage: Tokens Accounts (r:2 w:2) - // Storage: Control Members (r:1 w:1) - // Storage: Control OrgMemberCount (r:0 w:1) - // Storage: Control OrgTreasury (r:0 w:1) - // Storage: Control MemberStates (r:0 w:1) - // Storage: Control OrgStates (r:0 w:1) + /// Storage: Control OrgCount (r:1 w:1) + /// Proof: Control OrgCount (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) + /// Storage: System Account (r:1 w:1) + /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) + /// Storage: Control Orgs (r:1 w:1) + /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) + /// Storage: Tokens Accounts (r:2 w:2) + /// Proof: Tokens Accounts (max_values: None, max_size: Some(109), added: 2584, mode: MaxEncodedLen) + /// Storage: Control Members (r:1 w:1) + /// Proof: Control Members (max_values: None, max_size: Some(32050), added: 34525, mode: MaxEncodedLen) + /// Storage: Control OrgMemberCount (r:0 w:1) + /// Proof: Control OrgMemberCount (max_values: None, max_size: Some(52), added: 2527, mode: MaxEncodedLen) + /// Storage: Control OrgTreasury (r:0 w:1) + /// Proof: Control OrgTreasury (max_values: None, max_size: Some(80), added: 2555, mode: MaxEncodedLen) + /// Storage: Control MemberStates (r:0 w:1) + /// Proof: Control MemberStates (max_values: None, max_size: Some(97), added: 2572, mode: MaxEncodedLen) + /// Storage: Control OrgStates (r:0 w:1) + /// Proof: Control OrgStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) fn create_org() -> Weight { - // Minimum execution time: 79_000 nanoseconds. - Weight::from_ref_time(81_000_000) - .saturating_add(RocksDbWeight::get().reads(6)) - .saturating_add(RocksDbWeight::get().writes(10)) + // Proof Size summary in bytes: + // Measured: `408` + // Estimated: `45560` + // Minimum execution time: 70_000 nanoseconds. + Weight::from_parts(71_000_000, 45560) + .saturating_add(RocksDbWeight::get().reads(6_u64)) + .saturating_add(RocksDbWeight::get().writes(10_u64)) } - // Storage: Control Orgs (r:1 w:1) - // Storage: Control MemberStates (r:1 w:0) + /// Storage: Control Orgs (r:1 w:1) + /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) + /// Storage: Control MemberStates (r:1 w:0) + /// Proof: Control MemberStates (max_values: None, max_size: Some(97), added: 2572, mode: MaxEncodedLen) fn update_org() -> Weight { - // Minimum execution time: 28_000 nanoseconds. - Weight::from_ref_time(29_000_000) - .saturating_add(RocksDbWeight::get().reads(2)) - .saturating_add(RocksDbWeight::get().writes(1)) + // Proof Size summary in bytes: + // Measured: `565` + // Estimated: `5337` + // Minimum execution time: 21_000 nanoseconds. + Weight::from_parts(22_000_000, 5337) + .saturating_add(RocksDbWeight::get().reads(2_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) } - // Storage: Control Orgs (r:1 w:0) - // Storage: Control OrgStates (r:0 w:1) + /// Storage: Control Orgs (r:1 w:0) + /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) + /// Storage: Control OrgStates (r:0 w:1) + /// Proof: Control OrgStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) fn disable_org() -> Weight { - // Minimum execution time: 23_000 nanoseconds. - Weight::from_ref_time(24_000_000) - .saturating_add(RocksDbWeight::get().reads(1)) - .saturating_add(RocksDbWeight::get().writes(1)) + // Proof Size summary in bytes: + // Measured: `480` + // Estimated: `2765` + // Minimum execution time: 17_000 nanoseconds. + Weight::from_parts(18_000_000, 2765) + .saturating_add(RocksDbWeight::get().reads(1_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) } - // Storage: Control Orgs (r:1 w:0) - // Storage: Control OrgStates (r:0 w:1) + /// Storage: Control Orgs (r:1 w:0) + /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) + /// Storage: Control OrgStates (r:0 w:1) + /// Proof: Control OrgStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) fn enable_org() -> Weight { - // Minimum execution time: 24_000 nanoseconds. - Weight::from_ref_time(25_000_000) - .saturating_add(RocksDbWeight::get().reads(1)) - .saturating_add(RocksDbWeight::get().writes(1)) - } - // Storage: Control Orgs (r:1 w:0) - // Storage: Control OrgTreasury (r:1 w:0) - // Storage: Control Members (r:1 w:1) - // Storage: Control OrgMemberCount (r:0 w:1) - // Storage: Control MemberStates (r:0 w:1) + // Proof Size summary in bytes: + // Measured: `480` + // Estimated: `2765` + // Minimum execution time: 17_000 nanoseconds. + Weight::from_parts(17_000_000, 2765) + .saturating_add(RocksDbWeight::get().reads(1_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) + } + /// Storage: Control Orgs (r:1 w:0) + /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) + /// Storage: Control OrgTreasury (r:1 w:0) + /// Proof: Control OrgTreasury (max_values: None, max_size: Some(80), added: 2555, mode: MaxEncodedLen) + /// Storage: Control Members (r:1 w:1) + /// Proof: Control Members (max_values: None, max_size: Some(32050), added: 34525, mode: MaxEncodedLen) + /// Storage: Control OrgMemberCount (r:0 w:1) + /// Proof: Control OrgMemberCount (max_values: None, max_size: Some(52), added: 2527, mode: MaxEncodedLen) + /// Storage: Control MemberStates (r:0 w:1) + /// Proof: Control MemberStates (max_values: None, max_size: Some(97), added: 2572, mode: MaxEncodedLen) /// The range of component `r` is `[1, 999]`. fn add_member(r: u32, ) -> Weight { - // Minimum execution time: 36_000 nanoseconds. - Weight::from_ref_time(34_091_687) - // Standard Error: 1_851 - .saturating_add(Weight::from_ref_time(65_158).saturating_mul(r.into())) - .saturating_add(RocksDbWeight::get().reads(3)) - .saturating_add(RocksDbWeight::get().writes(3)) - } - // Storage: Control Orgs (r:1 w:0) - // Storage: Control MemberStates (r:1 w:0) + // Proof Size summary in bytes: + // Measured: `659 + r * (32 ±0)` + // Estimated: `39845` + // Minimum execution time: 29_000 nanoseconds. + Weight::from_parts(27_804_864, 39845) + // Standard Error: 897 + .saturating_add(Weight::from_ref_time(34_905).saturating_mul(r.into())) + .saturating_add(RocksDbWeight::get().reads(3_u64)) + .saturating_add(RocksDbWeight::get().writes(3_u64)) + } + /// Storage: Control Orgs (r:1 w:0) + /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) + /// Storage: Control MemberStates (r:1 w:0) + /// Proof: Control MemberStates (max_values: None, max_size: Some(97), added: 2572, mode: MaxEncodedLen) fn update_member_state() -> Weight { - // Minimum execution time: 15_000 nanoseconds. - Weight::from_ref_time(16_000_000) - .saturating_add(RocksDbWeight::get().reads(2)) - } - // Storage: Control Orgs (r:1 w:0) - // Storage: Control Members (r:1 w:1) - // Storage: Control OrgMemberCount (r:0 w:1) - // Storage: Control MemberStates (r:0 w:1) + // Proof Size summary in bytes: + // Measured: `604` + // Estimated: `5337` + // Minimum execution time: 14_000 nanoseconds. + Weight::from_parts(15_000_000, 5337) + .saturating_add(RocksDbWeight::get().reads(2_u64)) + } + /// Storage: Control Orgs (r:1 w:0) + /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) + /// Storage: Control Members (r:1 w:1) + /// Proof: Control Members (max_values: None, max_size: Some(32050), added: 34525, mode: MaxEncodedLen) + /// Storage: Control OrgMemberCount (r:0 w:1) + /// Proof: Control OrgMemberCount (max_values: None, max_size: Some(52), added: 2527, mode: MaxEncodedLen) + /// Storage: Control MemberStates (r:0 w:1) + /// Proof: Control MemberStates (max_values: None, max_size: Some(97), added: 2572, mode: MaxEncodedLen) /// The range of component `r` is `[1, 999]`. fn remove_member(r: u32, ) -> Weight { - // Minimum execution time: 30_000 nanoseconds. - Weight::from_ref_time(37_544_684) - // Standard Error: 2_351 - .saturating_add(Weight::from_ref_time(43_383).saturating_mul(r.into())) - .saturating_add(RocksDbWeight::get().reads(2)) - .saturating_add(RocksDbWeight::get().writes(3)) - } - // Storage: Control Orgs (r:1 w:0) - // Storage: Control OrgTreasury (r:1 w:0) - // Storage: Tokens Accounts (r:2 w:2) - // Storage: System Account (r:2 w:1) + // Proof Size summary in bytes: + // Measured: `584 + r * (32 ±0)` + // Estimated: `37290` + // Minimum execution time: 25_000 nanoseconds. + Weight::from_parts(23_223_981, 37290) + // Standard Error: 874 + .saturating_add(Weight::from_ref_time(33_949).saturating_mul(r.into())) + .saturating_add(RocksDbWeight::get().reads(2_u64)) + .saturating_add(RocksDbWeight::get().writes(3_u64)) + } + /// Storage: Control Orgs (r:1 w:0) + /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) + /// Storage: Control OrgTreasury (r:1 w:0) + /// Proof: Control OrgTreasury (max_values: None, max_size: Some(80), added: 2555, mode: MaxEncodedLen) + /// Storage: Tokens Accounts (r:2 w:2) + /// Proof: Tokens Accounts (max_values: None, max_size: Some(109), added: 2584, mode: MaxEncodedLen) + /// Storage: System Account (r:2 w:1) + /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) fn spend_funds() -> Weight { - // Minimum execution time: 63_000 nanoseconds. - Weight::from_ref_time(64_000_000) - .saturating_add(RocksDbWeight::get().reads(6)) - .saturating_add(RocksDbWeight::get().writes(3)) + // Proof Size summary in bytes: + // Measured: `1040` + // Estimated: `15694` + // Minimum execution time: 58_000 nanoseconds. + Weight::from_parts(59_000_000, 15694) + .saturating_add(RocksDbWeight::get().reads(6_u64)) + .saturating_add(RocksDbWeight::get().writes(3_u64)) } } \ No newline at end of file diff --git a/flow/Cargo.toml b/flow/Cargo.toml index bb918ccc0..cfb515e01 100644 --- a/flow/Cargo.toml +++ b/flow/Cargo.toml @@ -6,7 +6,7 @@ [package] name = "gamedao-flow" -version = "1.2.0" +version = "1.3.0" authors = ["zero.io","gamedao.co"] edition = "2018" license = "GPL-3.0-or-later" @@ -15,27 +15,27 @@ repository = "https://github.com/gamedaoco/gamedao-protocol" [dependencies] serde = { version = "1.0.143", default-features = false } -codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] } +codec = { package = "parity-scale-codec", version = "3.2.2", default-features = false, features = ["derive"] } scale-info = { version = "2.1.1", default-features = false, features = ["derive"] } -sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36", default-features = false } -sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36", default-features = false } -frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36", default-features = false } -frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36", default-features = false } -frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36", default-features = false, optional = true } -sp-io = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.36", default-features=false } +sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38", default-features = false } +sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38", default-features = false } +frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38", default-features = false } +frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38", default-features = false } +frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38", default-features = false, optional = true } +sp-io = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.38", default-features=false } -orml-currencies = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.36", default-features = false } -orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.36", default-features = false } -orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.36", default-features = false } +orml-currencies = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.38", default-features = false } +orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.38", default-features = false } +orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.38", default-features = false } gamedao-traits = { package = "gamedao-traits", path = "../traits", default-features = false } gamedao-control = { package = "gamedao-control", path = "../control", default-features = false } [dev-dependencies] -sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.36" } +sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.38" } -pallet-timestamp = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } -pallet-balances = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } +pallet-timestamp = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } +pallet-balances = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } gamedao-control = { package = "gamedao-control", path = "../control", default-features = true } diff --git a/flow/src/weights.rs b/flow/src/weights.rs index f18793861..6f7abf2d2 100644 --- a/flow/src/weights.rs +++ b/flow/src/weights.rs @@ -2,7 +2,8 @@ //! Autogenerated weights for gamedao_flow //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-02-10, STEPS: `20`, REPEAT: 10, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2023-03-04, STEPS: `20`, REPEAT: `10`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! WORST CASE MAP SIZE: `1000000` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: None, DB CACHE: 1024 // Executed Command: @@ -34,104 +35,166 @@ pub trait WeightInfo { /// Weights for gamedao_flow using the Substrate node and recommended hardware. pub struct SubstrateWeight(PhantomData); impl WeightInfo for SubstrateWeight { - // Storage: Control Orgs (r:1 w:0) - // Storage: Flow CampaignCount (r:1 w:1) - // Storage: Flow CampaignsByBlock (r:2 w:2) - // Storage: Control OrgTreasury (r:1 w:0) - // Storage: Tokens Accounts (r:1 w:1) - // Storage: Flow CampaignOf (r:0 w:1) - // Storage: Flow CampaignStates (r:0 w:1) + /// Storage: Control Orgs (r:1 w:0) + /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) + /// Storage: Flow CampaignCount (r:1 w:1) + /// Proof: Flow CampaignCount (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) + /// Storage: Flow CampaignsByBlock (r:2 w:2) + /// Proof: Flow CampaignsByBlock (max_values: None, max_size: Some(358), added: 2833, mode: MaxEncodedLen) + /// Storage: Control OrgTreasury (r:1 w:0) + /// Proof: Control OrgTreasury (max_values: None, max_size: Some(80), added: 2555, mode: MaxEncodedLen) + /// Storage: Tokens Accounts (r:1 w:1) + /// Proof: Tokens Accounts (max_values: None, max_size: Some(109), added: 2584, mode: MaxEncodedLen) + /// Storage: Flow CampaignOf (r:0 w:1) + /// Proof: Flow CampaignOf (max_values: None, max_size: Some(460), added: 2935, mode: MaxEncodedLen) + /// Storage: Flow CampaignStates (r:0 w:1) + /// Proof: Flow CampaignStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) fn create_campaign() -> Weight { - // Minimum execution time: 64_000 nanoseconds. - Weight::from_ref_time(67_000_000) - .saturating_add(T::DbWeight::get().reads(6)) - .saturating_add(T::DbWeight::get().writes(6)) + // Proof Size summary in bytes: + // Measured: `1009` + // Estimated: `14069` + // Minimum execution time: 57_000 nanoseconds. + Weight::from_parts(58_000_000, 14069) + .saturating_add(T::DbWeight::get().reads(6_u64)) + .saturating_add(T::DbWeight::get().writes(6_u64)) } - // Storage: Flow CampaignOf (r:1 w:0) - // Storage: Flow CampaignStates (r:1 w:0) - // Storage: Flow CampaignContribution (r:1 w:1) - // Storage: Flow CampaignContributorsCount (r:1 w:1) - // Storage: Tokens Accounts (r:1 w:1) - // Storage: Flow CampaignBalance (r:1 w:1) + /// Storage: Flow CampaignOf (r:1 w:0) + /// Proof: Flow CampaignOf (max_values: None, max_size: Some(460), added: 2935, mode: MaxEncodedLen) + /// Storage: Flow CampaignStates (r:1 w:0) + /// Proof: Flow CampaignStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Flow CampaignContribution (r:1 w:1) + /// Proof: Flow CampaignContribution (max_values: None, max_size: Some(112), added: 2587, mode: MaxEncodedLen) + /// Storage: Flow CampaignContributorsCount (r:1 w:1) + /// Proof: Flow CampaignContributorsCount (max_values: None, max_size: Some(56), added: 2531, mode: MaxEncodedLen) + /// Storage: Tokens Accounts (r:1 w:1) + /// Proof: Tokens Accounts (max_values: None, max_size: Some(109), added: 2584, mode: MaxEncodedLen) + /// Storage: Flow CampaignBalance (r:1 w:1) + /// Proof: Flow CampaignBalance (max_values: None, max_size: Some(64), added: 2539, mode: MaxEncodedLen) fn contribute() -> Weight { - // Minimum execution time: 56_000 nanoseconds. - Weight::from_ref_time(58_000_000) - .saturating_add(T::DbWeight::get().reads(6)) - .saturating_add(T::DbWeight::get().writes(4)) + // Proof Size summary in bytes: + // Measured: `1104` + // Estimated: `15700` + // Minimum execution time: 48_000 nanoseconds. + Weight::from_parts(51_000_000, 15700) + .saturating_add(T::DbWeight::get().reads(6_u64)) + .saturating_add(T::DbWeight::get().writes(4_u64)) } - // Storage: Flow CampaignsByBlock (r:1 w:0) - // Storage: Flow CampaignStates (r:10 w:11) - // Storage: Flow CampaignFinalizationQueue (r:2 w:1) - // Storage: Tokens Accounts (r:1 w:1) - // Storage: Flow CampaignContribution (r:5 w:0) - // Storage: System Account (r:1 w:1) - // Storage: Flow CampaignBalance (r:0 w:1) + /// Storage: Flow CampaignsByBlock (r:1 w:0) + /// Proof: Flow CampaignsByBlock (max_values: None, max_size: Some(358), added: 2833, mode: MaxEncodedLen) + /// Storage: Flow CampaignStates (r:10 w:11) + /// Proof: Flow CampaignStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Flow CampaignFinalizationQueue (r:2 w:1) + /// Proof: Flow CampaignFinalizationQueue (max_values: None, max_size: Some(320511), added: 322986, mode: MaxEncodedLen) + /// Storage: Flow CampaignContribution (r:100 w:0) + /// Proof: Flow CampaignContribution (max_values: None, max_size: Some(112), added: 2587, mode: MaxEncodedLen) + /// Storage: Tokens Accounts (r:102 w:102) + /// Proof: Tokens Accounts (max_values: None, max_size: Some(109), added: 2584, mode: MaxEncodedLen) + /// Storage: System Account (r:1 w:1) + /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) + /// Storage: Flow CampaignBalance (r:0 w:1) + /// Proof: Flow CampaignBalance (max_values: None, max_size: Some(64), added: 2539, mode: MaxEncodedLen) /// The range of component `c` is `[0, 100]`. /// The range of component `p` is `[0, 10]`. fn on_initialize(c: u32, p: u32, ) -> Weight { - // Minimum execution time: 134_000 nanoseconds. - Weight::from_ref_time(68_040_945) - // Standard Error: 55_163 - .saturating_add(Weight::from_ref_time(25_455_935).saturating_mul(c.into())) - // Standard Error: 551_554 - .saturating_add(Weight::from_ref_time(9_852_261).saturating_mul(p.into())) - .saturating_add(T::DbWeight::get().reads(5)) + // Proof Size summary in bytes: + // Measured: `1615 + c * (288 ±0) + p * (87 ±0)` + // Estimated: `655398 + c * (5182 ±0) + p * (2558 ±12)` + // Minimum execution time: 136_000 nanoseconds. + Weight::from_parts(62_296_021, 655398) + // Standard Error: 59_341 + .saturating_add(Weight::from_ref_time(25_969_615).saturating_mul(c.into())) + // Standard Error: 593_322 + .saturating_add(Weight::from_ref_time(10_250_535).saturating_mul(p.into())) + .saturating_add(T::DbWeight::get().reads(5_u64)) .saturating_add(T::DbWeight::get().reads((2_u64).saturating_mul(c.into()))) .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(p.into()))) - .saturating_add(T::DbWeight::get().writes(5)) + .saturating_add(T::DbWeight::get().writes(5_u64)) .saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(c.into()))) .saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(p.into()))) + .saturating_add(Weight::from_proof_size(5182).saturating_mul(c.into())) + .saturating_add(Weight::from_proof_size(2558).saturating_mul(p.into())) } } // For backwards compatibility and tests impl WeightInfo for () { - // Storage: Control Orgs (r:1 w:0) - // Storage: Flow CampaignCount (r:1 w:1) - // Storage: Flow CampaignsByBlock (r:2 w:2) - // Storage: Control OrgTreasury (r:1 w:0) - // Storage: Tokens Accounts (r:1 w:1) - // Storage: Flow CampaignOf (r:0 w:1) - // Storage: Flow CampaignStates (r:0 w:1) + /// Storage: Control Orgs (r:1 w:0) + /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) + /// Storage: Flow CampaignCount (r:1 w:1) + /// Proof: Flow CampaignCount (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) + /// Storage: Flow CampaignsByBlock (r:2 w:2) + /// Proof: Flow CampaignsByBlock (max_values: None, max_size: Some(358), added: 2833, mode: MaxEncodedLen) + /// Storage: Control OrgTreasury (r:1 w:0) + /// Proof: Control OrgTreasury (max_values: None, max_size: Some(80), added: 2555, mode: MaxEncodedLen) + /// Storage: Tokens Accounts (r:1 w:1) + /// Proof: Tokens Accounts (max_values: None, max_size: Some(109), added: 2584, mode: MaxEncodedLen) + /// Storage: Flow CampaignOf (r:0 w:1) + /// Proof: Flow CampaignOf (max_values: None, max_size: Some(460), added: 2935, mode: MaxEncodedLen) + /// Storage: Flow CampaignStates (r:0 w:1) + /// Proof: Flow CampaignStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) fn create_campaign() -> Weight { - // Minimum execution time: 64_000 nanoseconds. - Weight::from_ref_time(67_000_000) - .saturating_add(RocksDbWeight::get().reads(6)) - .saturating_add(RocksDbWeight::get().writes(6)) + // Proof Size summary in bytes: + // Measured: `1009` + // Estimated: `14069` + // Minimum execution time: 57_000 nanoseconds. + Weight::from_parts(58_000_000, 14069) + .saturating_add(RocksDbWeight::get().reads(6_u64)) + .saturating_add(RocksDbWeight::get().writes(6_u64)) } - // Storage: Flow CampaignOf (r:1 w:0) - // Storage: Flow CampaignStates (r:1 w:0) - // Storage: Flow CampaignContribution (r:1 w:1) - // Storage: Flow CampaignContributorsCount (r:1 w:1) - // Storage: Tokens Accounts (r:1 w:1) - // Storage: Flow CampaignBalance (r:1 w:1) + /// Storage: Flow CampaignOf (r:1 w:0) + /// Proof: Flow CampaignOf (max_values: None, max_size: Some(460), added: 2935, mode: MaxEncodedLen) + /// Storage: Flow CampaignStates (r:1 w:0) + /// Proof: Flow CampaignStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Flow CampaignContribution (r:1 w:1) + /// Proof: Flow CampaignContribution (max_values: None, max_size: Some(112), added: 2587, mode: MaxEncodedLen) + /// Storage: Flow CampaignContributorsCount (r:1 w:1) + /// Proof: Flow CampaignContributorsCount (max_values: None, max_size: Some(56), added: 2531, mode: MaxEncodedLen) + /// Storage: Tokens Accounts (r:1 w:1) + /// Proof: Tokens Accounts (max_values: None, max_size: Some(109), added: 2584, mode: MaxEncodedLen) + /// Storage: Flow CampaignBalance (r:1 w:1) + /// Proof: Flow CampaignBalance (max_values: None, max_size: Some(64), added: 2539, mode: MaxEncodedLen) fn contribute() -> Weight { - // Minimum execution time: 56_000 nanoseconds. - Weight::from_ref_time(58_000_000) - .saturating_add(RocksDbWeight::get().reads(6)) - .saturating_add(RocksDbWeight::get().writes(4)) + // Proof Size summary in bytes: + // Measured: `1104` + // Estimated: `15700` + // Minimum execution time: 48_000 nanoseconds. + Weight::from_parts(51_000_000, 15700) + .saturating_add(RocksDbWeight::get().reads(6_u64)) + .saturating_add(RocksDbWeight::get().writes(4_u64)) } - // Storage: Flow CampaignsByBlock (r:1 w:0) - // Storage: Flow CampaignStates (r:10 w:11) - // Storage: Flow CampaignFinalizationQueue (r:2 w:1) - // Storage: Tokens Accounts (r:1 w:1) - // Storage: Flow CampaignContribution (r:5 w:0) - // Storage: System Account (r:1 w:1) - // Storage: Flow CampaignBalance (r:0 w:1) + /// Storage: Flow CampaignsByBlock (r:1 w:0) + /// Proof: Flow CampaignsByBlock (max_values: None, max_size: Some(358), added: 2833, mode: MaxEncodedLen) + /// Storage: Flow CampaignStates (r:10 w:11) + /// Proof: Flow CampaignStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Flow CampaignFinalizationQueue (r:2 w:1) + /// Proof: Flow CampaignFinalizationQueue (max_values: None, max_size: Some(320511), added: 322986, mode: MaxEncodedLen) + /// Storage: Flow CampaignContribution (r:100 w:0) + /// Proof: Flow CampaignContribution (max_values: None, max_size: Some(112), added: 2587, mode: MaxEncodedLen) + /// Storage: Tokens Accounts (r:102 w:102) + /// Proof: Tokens Accounts (max_values: None, max_size: Some(109), added: 2584, mode: MaxEncodedLen) + /// Storage: System Account (r:1 w:1) + /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) + /// Storage: Flow CampaignBalance (r:0 w:1) + /// Proof: Flow CampaignBalance (max_values: None, max_size: Some(64), added: 2539, mode: MaxEncodedLen) /// The range of component `c` is `[0, 100]`. /// The range of component `p` is `[0, 10]`. fn on_initialize(c: u32, p: u32, ) -> Weight { - // Minimum execution time: 134_000 nanoseconds. - Weight::from_ref_time(68_040_945) - // Standard Error: 55_163 - .saturating_add(Weight::from_ref_time(25_455_935).saturating_mul(c.into())) - // Standard Error: 551_554 - .saturating_add(Weight::from_ref_time(9_852_261).saturating_mul(p.into())) - .saturating_add(RocksDbWeight::get().reads(5)) + // Proof Size summary in bytes: + // Measured: `1615 + c * (288 ±0) + p * (87 ±0)` + // Estimated: `655398 + c * (5182 ±0) + p * (2558 ±12)` + // Minimum execution time: 136_000 nanoseconds. + Weight::from_parts(62_296_021, 655398) + // Standard Error: 59_341 + .saturating_add(Weight::from_ref_time(25_969_615).saturating_mul(c.into())) + // Standard Error: 593_322 + .saturating_add(Weight::from_ref_time(10_250_535).saturating_mul(p.into())) + .saturating_add(RocksDbWeight::get().reads(5_u64)) .saturating_add(RocksDbWeight::get().reads((2_u64).saturating_mul(c.into()))) .saturating_add(RocksDbWeight::get().reads((1_u64).saturating_mul(p.into()))) - .saturating_add(RocksDbWeight::get().writes(5)) + .saturating_add(RocksDbWeight::get().writes(5_u64)) .saturating_add(RocksDbWeight::get().writes((1_u64).saturating_mul(c.into()))) .saturating_add(RocksDbWeight::get().writes((1_u64).saturating_mul(p.into()))) + .saturating_add(Weight::from_proof_size(5182).saturating_mul(c.into())) + .saturating_add(Weight::from_proof_size(2558).saturating_mul(p.into())) } } \ No newline at end of file diff --git a/sense/Cargo.toml b/sense/Cargo.toml index 0da91af93..4d408d69c 100755 --- a/sense/Cargo.toml +++ b/sense/Cargo.toml @@ -6,7 +6,7 @@ [package] name = "gamedao-sense" -version = "1.2.0" +version = "1.3.0" authors = ["zero.io","gamedao.co"] edition = "2018" license = "GPL-3.0-or-later" @@ -21,18 +21,18 @@ categories = [ [dependencies] serde = { version = "1.0.143", default-features = false } -codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] } +codec = { package = "parity-scale-codec", version = "3.2.2", default-features = false, features = ["derive"] } scale-info = { version = "2.1.1", default-features = false, features = ["derive"] } -sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36", default-features = false } -sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36", default-features = false } -frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36", default-features = false } -frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36", default-features = false } -frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36", default-features = false, optional = true } +sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38", default-features = false } +sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38", default-features = false } +frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38", default-features = false } +frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38", default-features = false } +frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38", default-features = false, optional = true } [dev-dependencies] -sp-io = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.36" } -sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.36" } -sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.36" } +sp-io = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.38" } +sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.38" } +sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.38" } [features] default = ["std"] diff --git a/sense/src/weights.rs b/sense/src/weights.rs index 6cb9c27c3..6e53933e1 100644 --- a/sense/src/weights.rs +++ b/sense/src/weights.rs @@ -2,7 +2,8 @@ //! Autogenerated weights for gamedao_sense //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-02-10, STEPS: `20`, REPEAT: 10, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2023-03-04, STEPS: `20`, REPEAT: `10`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! WORST CASE MAP SIZE: `1000000` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: None, DB CACHE: 1024 // Executed Command: @@ -33,42 +34,64 @@ pub trait WeightInfo { /// Weights for gamedao_sense using the Substrate node and recommended hardware. pub struct SubstrateWeight(PhantomData); impl WeightInfo for SubstrateWeight { - // Storage: Sense Entities (r:1 w:1) - // Storage: Sense EntityCount (r:1 w:1) - // Storage: Sense Properties (r:0 w:3) + /// Storage: Sense Entities (r:1 w:1) + /// Proof: Sense Entities (max_values: None, max_size: Some(170), added: 2645, mode: MaxEncodedLen) + /// Storage: Sense EntityCount (r:1 w:1) + /// Proof: Sense EntityCount (max_values: Some(1), max_size: Some(16), added: 511, mode: MaxEncodedLen) + /// Storage: Sense Properties (r:0 w:3) + /// Proof: Sense Properties (max_values: None, max_size: Some(77), added: 2552, mode: MaxEncodedLen) fn create_entity() -> Weight { - // Minimum execution time: 27_000 nanoseconds. - Weight::from_ref_time(29_000_000) - .saturating_add(T::DbWeight::get().reads(2)) - .saturating_add(T::DbWeight::get().writes(5)) + // Proof Size summary in bytes: + // Measured: `142` + // Estimated: `3156` + // Minimum execution time: 21_000 nanoseconds. + Weight::from_parts(22_000_000, 3156) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(5_u64)) } - // Storage: Sense Entities (r:1 w:0) - // Storage: Sense Properties (r:1 w:1) + /// Storage: Sense Entities (r:1 w:0) + /// Proof: Sense Entities (max_values: None, max_size: Some(170), added: 2645, mode: MaxEncodedLen) + /// Storage: Sense Properties (r:1 w:1) + /// Proof: Sense Properties (max_values: None, max_size: Some(77), added: 2552, mode: MaxEncodedLen) fn update_property() -> Weight { - // Minimum execution time: 25_000 nanoseconds. - Weight::from_ref_time(26_000_000) - .saturating_add(T::DbWeight::get().reads(2)) - .saturating_add(T::DbWeight::get().writes(1)) + // Proof Size summary in bytes: + // Measured: `452` + // Estimated: `5197` + // Minimum execution time: 20_000 nanoseconds. + Weight::from_parts(21_000_000, 5197) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) } } // For backwards compatibility and tests impl WeightInfo for () { - // Storage: Sense Entities (r:1 w:1) - // Storage: Sense EntityCount (r:1 w:1) - // Storage: Sense Properties (r:0 w:3) + /// Storage: Sense Entities (r:1 w:1) + /// Proof: Sense Entities (max_values: None, max_size: Some(170), added: 2645, mode: MaxEncodedLen) + /// Storage: Sense EntityCount (r:1 w:1) + /// Proof: Sense EntityCount (max_values: Some(1), max_size: Some(16), added: 511, mode: MaxEncodedLen) + /// Storage: Sense Properties (r:0 w:3) + /// Proof: Sense Properties (max_values: None, max_size: Some(77), added: 2552, mode: MaxEncodedLen) fn create_entity() -> Weight { - // Minimum execution time: 27_000 nanoseconds. - Weight::from_ref_time(29_000_000) - .saturating_add(RocksDbWeight::get().reads(2)) - .saturating_add(RocksDbWeight::get().writes(5)) + // Proof Size summary in bytes: + // Measured: `142` + // Estimated: `3156` + // Minimum execution time: 21_000 nanoseconds. + Weight::from_parts(22_000_000, 3156) + .saturating_add(RocksDbWeight::get().reads(2_u64)) + .saturating_add(RocksDbWeight::get().writes(5_u64)) } - // Storage: Sense Entities (r:1 w:0) - // Storage: Sense Properties (r:1 w:1) + /// Storage: Sense Entities (r:1 w:0) + /// Proof: Sense Entities (max_values: None, max_size: Some(170), added: 2645, mode: MaxEncodedLen) + /// Storage: Sense Properties (r:1 w:1) + /// Proof: Sense Properties (max_values: None, max_size: Some(77), added: 2552, mode: MaxEncodedLen) fn update_property() -> Weight { - // Minimum execution time: 25_000 nanoseconds. - Weight::from_ref_time(26_000_000) - .saturating_add(RocksDbWeight::get().reads(2)) - .saturating_add(RocksDbWeight::get().writes(1)) + // Proof Size summary in bytes: + // Measured: `452` + // Estimated: `5197` + // Minimum execution time: 20_000 nanoseconds. + Weight::from_parts(21_000_000, 5197) + .saturating_add(RocksDbWeight::get().reads(2_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) } } \ No newline at end of file diff --git a/signal/Cargo.toml b/signal/Cargo.toml index 08d0e594e..d5e1264c5 100644 --- a/signal/Cargo.toml +++ b/signal/Cargo.toml @@ -6,7 +6,7 @@ [package] name = "gamedao-signal" -version = "1.2.0" +version = "1.3.0" authors = ["zero.io","gamedao.co"] repository = "https://github.com/gamedaoco/gamedao-protocol" edition = "2018" @@ -22,26 +22,26 @@ categories = [ [dependencies] serde = { version = "1.0.143", default-features = false } -codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] } +codec = { package = "parity-scale-codec", version = "3.2.2", default-features = false, features = ["derive"] } scale-info = { version = "2.1.1", default-features = false, features = ["derive"] } -sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36", default-features = false } -sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36", default-features = false } -frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36", default-features = false } -frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36", default-features = false } -frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36", default-features = false, optional = true } -orml-traits = { git = 'https://github.com/open-web3-stack/open-runtime-module-library', branch= 'polkadot-v0.9.36', default-features = false } +sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38", default-features = false } +sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38", default-features = false } +frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38", default-features = false } +frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38", default-features = false } +frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38", default-features = false, optional = true } +orml-traits = { git = 'https://github.com/open-web3-stack/open-runtime-module-library', branch= "polkadot-v0.9.38", default-features = false } gamedao-traits = { package = "gamedao-traits", path = "../traits", default-features = false } -sp-io = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.36", default-features=false } +sp-io = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.38", default-features=false } [dev-dependencies] -sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.36" } -sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.36" } +sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.38" } +sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.38" } -pallet-balances = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } -pallet-timestamp = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } +pallet-balances = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } +pallet-timestamp = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } -orml-currencies = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.36", default-features = false } -orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.36", default-features = false } +orml-currencies = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.38", default-features = false } +orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.38", default-features = false } gamedao-control = { path = "../control", default-features = true } gamedao-flow = { path = "../flow", default-features = true } diff --git a/signal/src/weights.rs b/signal/src/weights.rs index 77e1a232f..03dd2aba9 100644 --- a/signal/src/weights.rs +++ b/signal/src/weights.rs @@ -2,7 +2,8 @@ //! Autogenerated weights for gamedao_signal //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-02-10, STEPS: `20`, REPEAT: 10, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2023-03-04, STEPS: `20`, REPEAT: `10`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! WORST CASE MAP SIZE: `1000000` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: None, DB CACHE: 1024 // Executed Command: @@ -34,94 +35,152 @@ pub trait WeightInfo { /// Weights for gamedao_signal using the Substrate node and recommended hardware. pub struct SubstrateWeight(PhantomData); impl WeightInfo for SubstrateWeight { - // Storage: Control OrgStates (r:1 w:0) - // Storage: Control MemberStates (r:1 w:0) - // Storage: Signal ProposalCount (r:1 w:1) - // Storage: Signal ProposalOf (r:1 w:1) - // Storage: Tokens Accounts (r:2 w:2) - // Storage: Control OrgTreasury (r:1 w:0) - // Storage: Signal ProposalsByBlock (r:2 w:2) - // Storage: Control OrgMemberCount (r:1 w:0) - // Storage: Signal ProposalVoting (r:0 w:1) - // Storage: Signal ProposalStates (r:0 w:1) + /// Storage: Control OrgStates (r:1 w:0) + /// Proof: Control OrgStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Control MemberStates (r:1 w:0) + /// Proof: Control MemberStates (max_values: None, max_size: Some(97), added: 2572, mode: MaxEncodedLen) + /// Storage: Signal ProposalCount (r:1 w:1) + /// Proof: Signal ProposalCount (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) + /// Storage: Signal ProposalOf (r:1 w:1) + /// Proof: Signal ProposalOf (max_values: None, max_size: Some(363), added: 2838, mode: MaxEncodedLen) + /// Storage: Tokens Accounts (r:2 w:2) + /// Proof: Tokens Accounts (max_values: None, max_size: Some(109), added: 2584, mode: MaxEncodedLen) + /// Storage: Control OrgTreasury (r:1 w:0) + /// Proof: Control OrgTreasury (max_values: None, max_size: Some(80), added: 2555, mode: MaxEncodedLen) + /// Storage: Signal ProposalsByBlock (r:2 w:2) + /// Proof: Signal ProposalsByBlock (max_values: None, max_size: Some(3239), added: 5714, mode: MaxEncodedLen) + /// Storage: Control OrgMemberCount (r:1 w:0) + /// Proof: Control OrgMemberCount (max_values: None, max_size: Some(52), added: 2527, mode: MaxEncodedLen) + /// Storage: Signal ProposalVoting (r:0 w:1) + /// Proof: Signal ProposalVoting (max_values: None, max_size: Some(130112), added: 132587, mode: MaxEncodedLen) + /// Storage: Signal ProposalStates (r:0 w:1) + /// Proof: Signal ProposalStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) fn proposal() -> Weight { - // Minimum execution time: 90_000 nanoseconds. - Weight::from_ref_time(94_000_000) - .saturating_add(T::DbWeight::get().reads(10)) - .saturating_add(T::DbWeight::get().writes(8)) + // Proof Size summary in bytes: + // Measured: `1390` + // Estimated: `30111` + // Minimum execution time: 82_000 nanoseconds. + Weight::from_parts(82_000_000, 30111) + .saturating_add(T::DbWeight::get().reads(10_u64)) + .saturating_add(T::DbWeight::get().writes(8_u64)) } - // Storage: Signal ProposalVoting (r:1 w:1) - // Storage: Signal ProposalOf (r:1 w:0) - // Storage: Control MemberStates (r:1 w:0) - // Storage: Signal ProposalStates (r:1 w:1) - // Storage: Control OrgTreasury (r:1 w:0) - // Storage: Tokens Accounts (r:3 w:3) - // Storage: System Account (r:1 w:1) + /// Storage: Signal ProposalVoting (r:1 w:1) + /// Proof: Signal ProposalVoting (max_values: None, max_size: Some(130112), added: 132587, mode: MaxEncodedLen) + /// Storage: Signal ProposalOf (r:1 w:0) + /// Proof: Signal ProposalOf (max_values: None, max_size: Some(363), added: 2838, mode: MaxEncodedLen) + /// Storage: Control MemberStates (r:1 w:0) + /// Proof: Control MemberStates (max_values: None, max_size: Some(97), added: 2572, mode: MaxEncodedLen) + /// Storage: Signal ProposalStates (r:1 w:1) + /// Proof: Signal ProposalStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Control OrgTreasury (r:1 w:0) + /// Proof: Control OrgTreasury (max_values: None, max_size: Some(80), added: 2555, mode: MaxEncodedLen) + /// Storage: Tokens Accounts (r:3 w:3) + /// Proof: Tokens Accounts (max_values: None, max_size: Some(109), added: 2584, mode: MaxEncodedLen) + /// Storage: System Account (r:1 w:1) + /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) /// The range of component `m` is `[0, 1000]`. fn vote(m: u32, ) -> Weight { - // Minimum execution time: 107_000 nanoseconds. - Weight::from_ref_time(113_880_549) - // Standard Error: 3_532 - .saturating_add(Weight::from_ref_time(148_088).saturating_mul(m.into())) - .saturating_add(T::DbWeight::get().reads(9)) - .saturating_add(T::DbWeight::get().writes(6)) + // Proof Size summary in bytes: + // Measured: `3941 + m * (51 ±0)` + // Estimated: `153431` + // Minimum execution time: 99_000 nanoseconds. + Weight::from_parts(94_755_596, 153431) + // Standard Error: 2_268 + .saturating_add(Weight::from_ref_time(112_356).saturating_mul(m.into())) + .saturating_add(T::DbWeight::get().reads(9_u64)) + .saturating_add(T::DbWeight::get().writes(6_u64)) } - // Storage: Signal ProposalsByBlock (r:1 w:0) - // Storage: Signal ProposalStates (r:5 w:0) + /// Storage: Signal ProposalsByBlock (r:1 w:0) + /// Proof: Signal ProposalsByBlock (max_values: None, max_size: Some(3239), added: 5714, mode: MaxEncodedLen) + /// Storage: Signal ProposalStates (r:100 w:0) + /// Proof: Signal ProposalStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) /// The range of component `p` is `[0, 100]`. fn on_initialize(p: u32, ) -> Weight { - // Minimum execution time: 5_000 nanoseconds. - Weight::from_ref_time(9_260_770) - // Standard Error: 7_634 - .saturating_add(Weight::from_ref_time(2_838_161).saturating_mul(p.into())) - .saturating_add(T::DbWeight::get().reads(1)) + // Proof Size summary in bytes: + // Measured: `394 + p * (86 ±0)` + // Estimated: `5714 + p * (2524 ±0)` + // Minimum execution time: 3_000 nanoseconds. + Weight::from_parts(3_033_538, 5714) + // Standard Error: 21_933 + .saturating_add(Weight::from_ref_time(3_051_963).saturating_mul(p.into())) + .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(p.into()))) + .saturating_add(Weight::from_proof_size(2524).saturating_mul(p.into())) } } // For backwards compatibility and tests impl WeightInfo for () { - // Storage: Control OrgStates (r:1 w:0) - // Storage: Control MemberStates (r:1 w:0) - // Storage: Signal ProposalCount (r:1 w:1) - // Storage: Signal ProposalOf (r:1 w:1) - // Storage: Tokens Accounts (r:2 w:2) - // Storage: Control OrgTreasury (r:1 w:0) - // Storage: Signal ProposalsByBlock (r:2 w:2) - // Storage: Control OrgMemberCount (r:1 w:0) - // Storage: Signal ProposalVoting (r:0 w:1) - // Storage: Signal ProposalStates (r:0 w:1) + /// Storage: Control OrgStates (r:1 w:0) + /// Proof: Control OrgStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Control MemberStates (r:1 w:0) + /// Proof: Control MemberStates (max_values: None, max_size: Some(97), added: 2572, mode: MaxEncodedLen) + /// Storage: Signal ProposalCount (r:1 w:1) + /// Proof: Signal ProposalCount (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) + /// Storage: Signal ProposalOf (r:1 w:1) + /// Proof: Signal ProposalOf (max_values: None, max_size: Some(363), added: 2838, mode: MaxEncodedLen) + /// Storage: Tokens Accounts (r:2 w:2) + /// Proof: Tokens Accounts (max_values: None, max_size: Some(109), added: 2584, mode: MaxEncodedLen) + /// Storage: Control OrgTreasury (r:1 w:0) + /// Proof: Control OrgTreasury (max_values: None, max_size: Some(80), added: 2555, mode: MaxEncodedLen) + /// Storage: Signal ProposalsByBlock (r:2 w:2) + /// Proof: Signal ProposalsByBlock (max_values: None, max_size: Some(3239), added: 5714, mode: MaxEncodedLen) + /// Storage: Control OrgMemberCount (r:1 w:0) + /// Proof: Control OrgMemberCount (max_values: None, max_size: Some(52), added: 2527, mode: MaxEncodedLen) + /// Storage: Signal ProposalVoting (r:0 w:1) + /// Proof: Signal ProposalVoting (max_values: None, max_size: Some(130112), added: 132587, mode: MaxEncodedLen) + /// Storage: Signal ProposalStates (r:0 w:1) + /// Proof: Signal ProposalStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) fn proposal() -> Weight { - // Minimum execution time: 90_000 nanoseconds. - Weight::from_ref_time(94_000_000) - .saturating_add(RocksDbWeight::get().reads(10)) - .saturating_add(RocksDbWeight::get().writes(8)) + // Proof Size summary in bytes: + // Measured: `1390` + // Estimated: `30111` + // Minimum execution time: 82_000 nanoseconds. + Weight::from_parts(82_000_000, 30111) + .saturating_add(RocksDbWeight::get().reads(10_u64)) + .saturating_add(RocksDbWeight::get().writes(8_u64)) } - // Storage: Signal ProposalVoting (r:1 w:1) - // Storage: Signal ProposalOf (r:1 w:0) - // Storage: Control MemberStates (r:1 w:0) - // Storage: Signal ProposalStates (r:1 w:1) - // Storage: Control OrgTreasury (r:1 w:0) - // Storage: Tokens Accounts (r:3 w:3) - // Storage: System Account (r:1 w:1) + /// Storage: Signal ProposalVoting (r:1 w:1) + /// Proof: Signal ProposalVoting (max_values: None, max_size: Some(130112), added: 132587, mode: MaxEncodedLen) + /// Storage: Signal ProposalOf (r:1 w:0) + /// Proof: Signal ProposalOf (max_values: None, max_size: Some(363), added: 2838, mode: MaxEncodedLen) + /// Storage: Control MemberStates (r:1 w:0) + /// Proof: Control MemberStates (max_values: None, max_size: Some(97), added: 2572, mode: MaxEncodedLen) + /// Storage: Signal ProposalStates (r:1 w:1) + /// Proof: Signal ProposalStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Control OrgTreasury (r:1 w:0) + /// Proof: Control OrgTreasury (max_values: None, max_size: Some(80), added: 2555, mode: MaxEncodedLen) + /// Storage: Tokens Accounts (r:3 w:3) + /// Proof: Tokens Accounts (max_values: None, max_size: Some(109), added: 2584, mode: MaxEncodedLen) + /// Storage: System Account (r:1 w:1) + /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) /// The range of component `m` is `[0, 1000]`. fn vote(m: u32, ) -> Weight { - // Minimum execution time: 107_000 nanoseconds. - Weight::from_ref_time(113_880_549) - // Standard Error: 3_532 - .saturating_add(Weight::from_ref_time(148_088).saturating_mul(m.into())) - .saturating_add(RocksDbWeight::get().reads(9)) - .saturating_add(RocksDbWeight::get().writes(6)) + // Proof Size summary in bytes: + // Measured: `3941 + m * (51 ±0)` + // Estimated: `153431` + // Minimum execution time: 99_000 nanoseconds. + Weight::from_parts(94_755_596, 153431) + // Standard Error: 2_268 + .saturating_add(Weight::from_ref_time(112_356).saturating_mul(m.into())) + .saturating_add(RocksDbWeight::get().reads(9_u64)) + .saturating_add(RocksDbWeight::get().writes(6_u64)) } - // Storage: Signal ProposalsByBlock (r:1 w:0) - // Storage: Signal ProposalStates (r:5 w:0) + /// Storage: Signal ProposalsByBlock (r:1 w:0) + /// Proof: Signal ProposalsByBlock (max_values: None, max_size: Some(3239), added: 5714, mode: MaxEncodedLen) + /// Storage: Signal ProposalStates (r:100 w:0) + /// Proof: Signal ProposalStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) /// The range of component `p` is `[0, 100]`. fn on_initialize(p: u32, ) -> Weight { - // Minimum execution time: 5_000 nanoseconds. - Weight::from_ref_time(9_260_770) - // Standard Error: 7_634 - .saturating_add(Weight::from_ref_time(2_838_161).saturating_mul(p.into())) - .saturating_add(RocksDbWeight::get().reads(1)) + // Proof Size summary in bytes: + // Measured: `394 + p * (86 ±0)` + // Estimated: `5714 + p * (2524 ±0)` + // Minimum execution time: 3_000 nanoseconds. + Weight::from_parts(3_033_538, 5714) + // Standard Error: 21_933 + .saturating_add(Weight::from_ref_time(3_051_963).saturating_mul(p.into())) + .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().reads((1_u64).saturating_mul(p.into()))) + .saturating_add(Weight::from_proof_size(2524).saturating_mul(p.into())) } } \ No newline at end of file diff --git a/traits/Cargo.toml b/traits/Cargo.toml index ac03a6508..819182e95 100644 --- a/traits/Cargo.toml +++ b/traits/Cargo.toml @@ -6,7 +6,7 @@ [package] name = "gamedao-traits" -version = "1.2.0" +version = "1.3.0" authors = ["zero.io","gamedao.co"] edition = "2018" license = "GPL-3.0-or-later" @@ -15,12 +15,12 @@ repository = "https://github.com/gamedaoco/gamedao-protocol" [dependencies] -serde = { version = "1.0.124", default-features = false } -codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] } -scale-info = { version = "2.0.1", default-features = false, features = ["derive"] } -frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36", default-features = false } -frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36", default-features = false, optional = true } -sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36", default-features = false } +serde = { version = "1.0.143", default-features = false } +codec = { package = "parity-scale-codec", version = "3.2.2", default-features = false, features = ["derive"] } +scale-info = { version = "2.1.1", default-features = false, features = ["derive"] } +frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38", default-features = false } +frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38", default-features = false, optional = true } +sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38", default-features = false } [features] default = ["std"] From 0e8b48d9bb13ba0a6b2961ff3b5a89cc8ef869df Mon Sep 17 00:00:00 2001 From: Yura Date: Mon, 13 Mar 2023 16:20:12 +0100 Subject: [PATCH 39/49] fix: update_reward should update any number of fields (#146) --- battlepass/src/lib.rs | 6 +++--- battlepass/src/tests.rs | 10 ++++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/battlepass/src/lib.rs b/battlepass/src/lib.rs index 34b9d5a73..ed14d640f 100644 --- a/battlepass/src/lib.rs +++ b/battlepass/src/lib.rs @@ -613,9 +613,9 @@ pub mod pallet { // check permissions (prime, bot) ensure!(Self::is_prime_or_bot(&battlepass.org_id, caller)?, Error::::AuthorizationError); - reward.name = name.clone().unwrap(); - reward.cid = cid.clone().unwrap(); - reward.transferable = transferable.clone().unwrap(); + if name.is_some() { reward.name = name.clone().unwrap() }; + if cid.is_some() { reward.cid = cid.clone().unwrap() }; + if transferable.is_some() { reward.transferable = transferable.clone().unwrap() }; Rewards::::insert(reward_id, reward); diff --git a/battlepass/src/tests.rs b/battlepass/src/tests.rs index 59297b7f4..c475f29b5 100644 --- a/battlepass/src/tests.rs +++ b/battlepass/src/tests.rs @@ -860,6 +860,16 @@ fn update_reward_test() { assert_eq!(updated.cid, new_cid.clone()); assert_eq!(updated.transferable, new_transferable.clone()); + // Should update some fields in Reward + assert_ok!( + Battlepass::update_reward(Origin::signed(creator), reward_id, None, Some(new_name.clone()), None) + ); + // Check if Reward updated + let updated = Battlepass::get_reward(reward_id).unwrap(); + assert_eq!(updated.name, new_name.clone()); + assert_eq!(updated.cid, new_name.clone()); + assert_eq!(updated.transferable, new_transferable.clone()); + // Should not update if Bot is not added assert_noop!( Battlepass::update_reward(Origin::signed(BOT), reward_id, Some(new_name.clone()), Some(new_cid.clone()), Some(true)), From a58aba0c3b093357bea84815b2edebcc888137f0 Mon Sep 17 00:00:00 2001 From: FiberMan Date: Tue, 14 Mar 2023 17:09:36 +0100 Subject: [PATCH 40/49] feat: allow bot to update the battlepass --- battlepass/src/benchmarking.rs | 4 +- battlepass/src/lib.rs | 2 +- battlepass/src/tests.rs | 19 +++++++++ battlepass/src/weights.rs | 78 ++++++++++++++++++---------------- 4 files changed, 64 insertions(+), 39 deletions(-) diff --git a/battlepass/src/benchmarking.rs b/battlepass/src/benchmarking.rs index 1ad896b44..ecde8076a 100644 --- a/battlepass/src/benchmarking.rs +++ b/battlepass/src/benchmarking.rs @@ -102,12 +102,14 @@ benchmarks! { update_battlepass { let caller: T::AccountId = get_funded_caller::()?; + let bot: T::AccountId = account("bot", 0, 0); let org_id = get_org::(caller.clone()); let battlepass_id = get_battlepass::(caller.clone(), org_id); let new_name = BoundedVec::truncate_from(b"new name".to_vec()); let new_cid = BoundedVec::truncate_from(b"new cid".to_vec()); let new_price = 20; - }: _(RawOrigin::Signed(caller), battlepass_id, Some(new_name.clone()), Some(new_cid.clone()), Some(new_price.clone())) + set_bot::(caller.clone(), battlepass_id, bot.clone()); + }: _(RawOrigin::Signed(bot), battlepass_id, Some(new_name.clone()), Some(new_cid.clone()), Some(new_price.clone())) verify { let battlepass = Battlepasses::::get(battlepass_id).unwrap(); assert!(battlepass.name == new_name); diff --git a/battlepass/src/lib.rs b/battlepass/src/lib.rs index ed14d640f..e07ea8e05 100644 --- a/battlepass/src/lib.rs +++ b/battlepass/src/lib.rs @@ -386,7 +386,7 @@ pub mod pallet { // check if Org is active ensure!(T::Control::is_org_active(&battlepass.org_id), Error::::OrgUnknownOrInactive); // check permissions (prime) - ensure!(Self::is_prime(&battlepass.org_id, creator.clone())?, Error::::AuthorizationError); + ensure!(Self::is_prime_or_bot(&battlepass.org_id, creator.clone())?, Error::::AuthorizationError); if name.is_some() { battlepass.name = name.clone().unwrap() }; if cid.is_some() { battlepass.cid = cid.clone().unwrap() }; diff --git a/battlepass/src/tests.rs b/battlepass/src/tests.rs index c475f29b5..66b3db4d0 100644 --- a/battlepass/src/tests.rs +++ b/battlepass/src/tests.rs @@ -291,6 +291,25 @@ fn update_battlepass_test() { assert_eq!(updated.cid, new_cid.clone()); assert_eq!(updated.price, 100); + // Should not update if Bot is not added + assert_noop!( + Battlepass::update_battlepass(Origin::signed(BOT), battlepass_id, None, None, Some(200)), + Error::::AuthorizationError + ); + + // Should update Reward by Bot + assert_ok!( + Battlepass::add_bot(Origin::signed(creator), battlepass_id, BOT) + ); + assert_ok!( + Battlepass::update_battlepass(Origin::signed(BOT), battlepass_id, None, None, Some(200)), + ); + // Check if Battlepass updated + let updated = Battlepass::get_battlepass(battlepass_id).unwrap(); + assert_eq!(updated.name, new_name.clone()); + assert_eq!(updated.cid, new_cid.clone()); + assert_eq!(updated.price, 200); + // Should not update if Battlepass state is ENDED assert_ok!( Battlepass::activate_battlepass(Origin::signed(creator), battlepass_id) diff --git a/battlepass/src/weights.rs b/battlepass/src/weights.rs index 2504abe43..0078faa59 100644 --- a/battlepass/src/weights.rs +++ b/battlepass/src/weights.rs @@ -2,7 +2,7 @@ //! Autogenerated weights for gamedao_battlepass //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-03-06, STEPS: `20`, REPEAT: `10`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2023-03-14, STEPS: `20`, REPEAT: `10`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: None, DB CACHE: 1024 @@ -67,8 +67,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `597` // Estimated: `13676` - // Minimum execution time: 86_000 nanoseconds. - Weight::from_parts(86_000_000, 13676) + // Minimum execution time: 87_000 nanoseconds. + Weight::from_parts(88_000_000, 13676) .saturating_add(T::DbWeight::get().reads(6_u64)) .saturating_add(T::DbWeight::get().writes(7_u64)) } @@ -80,13 +80,15 @@ impl WeightInfo for SubstrateWeight { /// Proof: Control OrgStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) /// Storage: Control Orgs (r:1 w:0) /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) + /// Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) + /// Proof: Battlepass BattlepassInfoByOrg (max_values: None, max_size: Some(118), added: 2593, mode: MaxEncodedLen) fn update_battlepass() -> Weight { // Proof Size summary in bytes: - // Measured: `837` - // Estimated: `10670` - // Minimum execution time: 29_000 nanoseconds. - Weight::from_parts(30_000_000, 10670) - .saturating_add(T::DbWeight::get().reads(4_u64)) + // Measured: `945` + // Estimated: `13263` + // Minimum execution time: 33_000 nanoseconds. + Weight::from_parts(34_000_000, 13263) + .saturating_add(T::DbWeight::get().reads(5_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } /// Storage: Battlepass Battlepasses (r:1 w:0) @@ -115,7 +117,7 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `1359` // Estimated: `26736` - // Minimum execution time: 95_000 nanoseconds. + // Minimum execution time: 97_000 nanoseconds. Weight::from_parts(98_000_000, 26736) .saturating_add(T::DbWeight::get().reads(11_u64)) .saturating_add(T::DbWeight::get().writes(5_u64)) @@ -151,8 +153,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `907` // Estimated: `10739` - // Minimum execution time: 33_000 nanoseconds. - Weight::from_parts(34_000_000, 10739) + // Minimum execution time: 30_000 nanoseconds. + Weight::from_parts(32_000_000, 10739) .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } @@ -174,8 +176,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `1417` // Estimated: `18389` - // Minimum execution time: 44_000 nanoseconds. - Weight::from_parts(44_000_000, 18389) + // Minimum execution time: 41_000 nanoseconds. + Weight::from_parts(43_000_000, 18389) .saturating_add(T::DbWeight::get().reads(7_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -231,7 +233,7 @@ impl WeightInfo for SubstrateWeight { // Measured: `1169` // Estimated: `18608` // Minimum execution time: 41_000 nanoseconds. - Weight::from_parts(41_000_000, 18608) + Weight::from_parts(42_000_000, 18608) .saturating_add(T::DbWeight::get().reads(7_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -250,7 +252,7 @@ impl WeightInfo for SubstrateWeight { // Measured: `1094` // Estimated: `13560` // Minimum execution time: 33_000 nanoseconds. - Weight::from_parts(33_000_000, 13560) + Weight::from_parts(36_000_000, 13560) .saturating_add(T::DbWeight::get().reads(5_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -290,7 +292,7 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `2203` // Estimated: `44882` - // Minimum execution time: 133_000 nanoseconds. + // Minimum execution time: 134_000 nanoseconds. Weight::from_parts(135_000_000, 44882) .saturating_add(T::DbWeight::get().reads(18_u64)) .saturating_add(T::DbWeight::get().writes(6_u64)) @@ -332,8 +334,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `1038` // Estimated: `15807` - // Minimum execution time: 36_000 nanoseconds. - Weight::from_parts(37_000_000, 15807) + // Minimum execution time: 37_000 nanoseconds. + Weight::from_parts(38_000_000, 15807) .saturating_add(T::DbWeight::get().reads(6_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -352,7 +354,7 @@ impl WeightInfo for SubstrateWeight { // Measured: `880` // Estimated: `13263` // Minimum execution time: 30_000 nanoseconds. - Weight::from_parts(31_000_000, 13263) + Weight::from_parts(33_000_000, 13263) .saturating_add(T::DbWeight::get().reads(5_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -382,8 +384,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `597` // Estimated: `13676` - // Minimum execution time: 86_000 nanoseconds. - Weight::from_parts(86_000_000, 13676) + // Minimum execution time: 87_000 nanoseconds. + Weight::from_parts(88_000_000, 13676) .saturating_add(RocksDbWeight::get().reads(6_u64)) .saturating_add(RocksDbWeight::get().writes(7_u64)) } @@ -395,13 +397,15 @@ impl WeightInfo for () { /// Proof: Control OrgStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) /// Storage: Control Orgs (r:1 w:0) /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) + /// Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) + /// Proof: Battlepass BattlepassInfoByOrg (max_values: None, max_size: Some(118), added: 2593, mode: MaxEncodedLen) fn update_battlepass() -> Weight { // Proof Size summary in bytes: - // Measured: `837` - // Estimated: `10670` - // Minimum execution time: 29_000 nanoseconds. - Weight::from_parts(30_000_000, 10670) - .saturating_add(RocksDbWeight::get().reads(4_u64)) + // Measured: `945` + // Estimated: `13263` + // Minimum execution time: 33_000 nanoseconds. + Weight::from_parts(34_000_000, 13263) + .saturating_add(RocksDbWeight::get().reads(5_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } /// Storage: Battlepass Battlepasses (r:1 w:0) @@ -430,7 +434,7 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `1359` // Estimated: `26736` - // Minimum execution time: 95_000 nanoseconds. + // Minimum execution time: 97_000 nanoseconds. Weight::from_parts(98_000_000, 26736) .saturating_add(RocksDbWeight::get().reads(11_u64)) .saturating_add(RocksDbWeight::get().writes(5_u64)) @@ -466,8 +470,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `907` // Estimated: `10739` - // Minimum execution time: 33_000 nanoseconds. - Weight::from_parts(34_000_000, 10739) + // Minimum execution time: 30_000 nanoseconds. + Weight::from_parts(32_000_000, 10739) .saturating_add(RocksDbWeight::get().reads(4_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) } @@ -489,8 +493,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `1417` // Estimated: `18389` - // Minimum execution time: 44_000 nanoseconds. - Weight::from_parts(44_000_000, 18389) + // Minimum execution time: 41_000 nanoseconds. + Weight::from_parts(43_000_000, 18389) .saturating_add(RocksDbWeight::get().reads(7_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -546,7 +550,7 @@ impl WeightInfo for () { // Measured: `1169` // Estimated: `18608` // Minimum execution time: 41_000 nanoseconds. - Weight::from_parts(41_000_000, 18608) + Weight::from_parts(42_000_000, 18608) .saturating_add(RocksDbWeight::get().reads(7_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -565,7 +569,7 @@ impl WeightInfo for () { // Measured: `1094` // Estimated: `13560` // Minimum execution time: 33_000 nanoseconds. - Weight::from_parts(33_000_000, 13560) + Weight::from_parts(36_000_000, 13560) .saturating_add(RocksDbWeight::get().reads(5_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -605,7 +609,7 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `2203` // Estimated: `44882` - // Minimum execution time: 133_000 nanoseconds. + // Minimum execution time: 134_000 nanoseconds. Weight::from_parts(135_000_000, 44882) .saturating_add(RocksDbWeight::get().reads(18_u64)) .saturating_add(RocksDbWeight::get().writes(6_u64)) @@ -647,8 +651,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `1038` // Estimated: `15807` - // Minimum execution time: 36_000 nanoseconds. - Weight::from_parts(37_000_000, 15807) + // Minimum execution time: 37_000 nanoseconds. + Weight::from_parts(38_000_000, 15807) .saturating_add(RocksDbWeight::get().reads(6_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -667,7 +671,7 @@ impl WeightInfo for () { // Measured: `880` // Estimated: `13263` // Minimum execution time: 30_000 nanoseconds. - Weight::from_parts(31_000_000, 13263) + Weight::from_parts(33_000_000, 13263) .saturating_add(RocksDbWeight::get().reads(5_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } From 2cc4c035af40301a72cea420e4bac2adcc433434 Mon Sep 17 00:00:00 2001 From: FiberMan Date: Thu, 16 Mar 2023 17:14:03 +0100 Subject: [PATCH 41/49] feat: use provided CID as a metadata for NFT. --- battlepass/src/benchmarking.rs | 6 +- battlepass/src/lib.rs | 100 +++++++++++++++--------- battlepass/src/tests.rs | 111 ++++++++++++++++---------- battlepass/src/weights.rs | 138 ++++++++++++++++++--------------- control/src/lib.rs | 2 +- 5 files changed, 217 insertions(+), 140 deletions(-) diff --git a/battlepass/src/benchmarking.rs b/battlepass/src/benchmarking.rs index ecde8076a..356a17817 100644 --- a/battlepass/src/benchmarking.rs +++ b/battlepass/src/benchmarking.rs @@ -57,7 +57,7 @@ fn activate_bpass(caller: T::AccountId, battlepass_id: T::Hash) { } fn claim_bpass(caller: T::AccountId, battlepass_id: T::Hash) { - let _ = BPass::::claim_battlepass(RawOrigin::Signed(caller.clone()).into(), battlepass_id, caller); + let _ = BPass::::claim_battlepass(RawOrigin::Signed(caller.clone()).into(), battlepass_id, caller, None); } fn set_bpass_points(caller: T::AccountId, battlepass_id: T::Hash) { @@ -124,7 +124,7 @@ benchmarks! { let battlepass_id = get_battlepass::(caller.clone(), org_id); activate_bpass::(caller.clone(), battlepass_id); set_bot::(caller.clone(), battlepass_id, bot.clone()); - }: _(RawOrigin::Signed(bot), battlepass_id, caller.clone()) + }: _(RawOrigin::Signed(bot), battlepass_id, caller.clone(), None) verify { let collection_id = T::BattlepassHelper::collection(0); let item_id = T::BattlepassHelper::item(0); @@ -217,7 +217,7 @@ benchmarks! { set_bpass_level::(caller.clone(), battlepass_id); set_bot::(caller.clone(), battlepass_id, bot.clone()); let reward_id = get_reward::(caller.clone(), battlepass_id); - }: _(RawOrigin::Signed(bot), reward_id, caller.clone()) + }: _(RawOrigin::Signed(bot), reward_id, caller.clone(), None) verify { assert!(ClaimedRewards::::get(reward_id, caller).is_some()); } diff --git a/battlepass/src/lib.rs b/battlepass/src/lib.rs index e07ea8e05..59b68d636 100644 --- a/battlepass/src/lib.rs +++ b/battlepass/src/lib.rs @@ -355,6 +355,7 @@ pub mod pallet { } /// Updates Battlepass. + /// Also updates Collection's metadata if Battlepass CID has changed. /// May be called only by Organization owner. /// /// Parameters: @@ -364,6 +365,7 @@ pub mod pallet { /// - `price`: Price for the Battlepass subscription. #[pallet::call_index(1)] #[pallet::weight(::WeightInfo::update_battlepass())] + #[transactional] pub fn update_battlepass( origin: OriginFor, battlepass_id: T::Hash, @@ -375,10 +377,11 @@ pub mod pallet { // check if Battlepass exists let mut battlepass = Self::get_battlepass(battlepass_id).ok_or(Error::::BattlepassUnknown)?; // check if there is something to update + let name_changed = name.is_some() && name.clone().unwrap() != battlepass.name; + let cid_changed = cid.is_some() && cid.clone().unwrap() != battlepass.cid; + let price_changed = price.is_some() && price.clone().unwrap() != battlepass.price; ensure!( - name.is_some() && name.clone().unwrap() != battlepass.name || - cid.is_some() && cid.clone().unwrap() != battlepass.cid || - price.is_some() && price.clone().unwrap() != battlepass.price, + name_changed || cid_changed || price_changed, Error::::NoChangesProvided ); // check if Battlepass state is not ENDED @@ -388,9 +391,14 @@ pub mod pallet { // check permissions (prime) ensure!(Self::is_prime_or_bot(&battlepass.org_id, creator.clone())?, Error::::AuthorizationError); - if name.is_some() { battlepass.name = name.clone().unwrap() }; - if cid.is_some() { battlepass.cid = cid.clone().unwrap() }; - if price.is_some() { battlepass.price = price.clone().unwrap() }; + if name_changed { battlepass.name = name.clone().unwrap() } + if price_changed { battlepass.price = price.clone().unwrap() } + if cid_changed { + battlepass.cid = cid.clone().unwrap(); + + let prime = T::Control::org_prime_account(&battlepass.org_id).ok_or(Error::::OrgPrimeUnknown)?; + Self::update_collection_metadata(prime, battlepass.collection_id, cid.clone().unwrap())?; + } Battlepasses::::insert(battlepass_id, battlepass); @@ -405,16 +413,18 @@ pub mod pallet { /// /// Parameters: /// - `battlepass_id`: ID of the Battlepass for which to claim NFT. - /// - `for_who`: Account for which to claim NFT. + /// - `claimer`: Account for which to claim NFT. + /// - `cid`: If provided, store it in NFT's metadata. Otherwise, Battlepass CID will be stored there. #[pallet::call_index(2)] #[pallet::weight(::WeightInfo::claim_battlepass())] #[transactional] pub fn claim_battlepass( origin: OriginFor, battlepass_id: T::Hash, - for_who: T::AccountId, + claimer: T::AccountId, + cid: Option> ) -> DispatchResult { - let by_who = ensure_signed(origin.clone())?; + let caller = ensure_signed(origin)?; // check if Battlepass exists let battlepass = Self::get_battlepass(battlepass_id).ok_or(Error::::BattlepassUnknown)?; // check if Battlepass in ACTIVE state @@ -423,14 +433,13 @@ pub mod pallet { let org_id = battlepass.org_id.clone(); ensure!(T::Control::is_org_active(&org_id), Error::::OrgUnknownOrInactive); // check permissions (prime, bot) - ensure!(Self::is_prime_or_bot(&org_id, by_who.clone())?, Error::::AuthorizationError); + ensure!(Self::is_prime_or_bot(&org_id, caller.clone())?, Error::::AuthorizationError); // check if user has access to Battlepass - ensure!(!Self::has_battlepass_ownership(for_who.clone(), battlepass.collection_id), Error::::BattlepassOwnershipExists); + ensure!(!Self::is_battlepass_member(claimer.clone(), battlepass.collection_id), Error::::BattlepassOwnershipExists); + let nft_id = Self::do_claim_battlepass(battlepass.creator.clone(), claimer.clone(), battlepass.collection_id, cid.unwrap_or(battlepass.cid))?; - let nft_id = Self::do_claim_battlepass(battlepass.creator.clone(), for_who.clone(), battlepass_id, battlepass.collection_id)?; - - Self::deposit_event(Event::BattlepassClaimed { by_who, for_who, org_id, battlepass_id, nft_id }); + Self::deposit_event(Event::BattlepassClaimed { by_who: caller, for_who: claimer, org_id, battlepass_id, nft_id }); Ok(()) } @@ -524,7 +533,7 @@ pub mod pallet { // check permissions (prime, bot) ensure!(Self::is_prime_or_bot(&battlepass.org_id, sender.clone())?, Error::::AuthorizationError); // check if user has access to Battlepass - ensure!(Self::has_battlepass_ownership(account.clone(), battlepass.collection_id), Error::::BattlepassOwnershipDoesntExist); + ensure!(Self::is_battlepass_member(account.clone(), battlepass.collection_id), Error::::BattlepassOwnershipDoesntExist); Points::::insert(battlepass_id, &account, amount); @@ -576,6 +585,7 @@ pub mod pallet { } /// Updates Reward type. + /// Also updates Collection's metadata if Reward's CID has changed. /// May be called only by Organization owner or by a specially dedicated for this purpose account (Bot). /// /// Parameters: @@ -596,10 +606,11 @@ pub mod pallet { // check if Reward exists let mut reward = Self::get_reward(reward_id).ok_or(Error::::RewardUnknown)?; // check if there is something to update + let name_changed = name.is_some() && name.clone().unwrap() != reward.name; + let cid_changed = cid.is_some() && cid.clone().unwrap() != reward.cid; + let transferable_changed = transferable.is_some() && transferable.clone().unwrap() != reward.transferable; ensure!( - name.is_some() && name.clone().unwrap() != reward.name || - cid.is_some() && cid.clone().unwrap() != reward.cid || - transferable.is_some() && transferable.clone().unwrap() != reward.transferable, + name_changed || cid_changed || transferable_changed, Error::::NoChangesProvided ); // check if Reward is active @@ -613,9 +624,14 @@ pub mod pallet { // check permissions (prime, bot) ensure!(Self::is_prime_or_bot(&battlepass.org_id, caller)?, Error::::AuthorizationError); - if name.is_some() { reward.name = name.clone().unwrap() }; - if cid.is_some() { reward.cid = cid.clone().unwrap() }; - if transferable.is_some() { reward.transferable = transferable.clone().unwrap() }; + if name_changed { reward.name = name.clone().unwrap() }; + if transferable_changed { reward.transferable = transferable.clone().unwrap() }; + if cid_changed { + reward.cid = cid.clone().unwrap(); + + let prime = T::Control::org_prime_account(&battlepass.org_id).ok_or(Error::::OrgPrimeUnknown)?; + Self::update_collection_metadata(prime, reward.collection_id, cid.clone().unwrap())?; + } Rewards::::insert(reward_id, reward); @@ -661,25 +677,28 @@ pub mod pallet { /// - must be an Organization member. /// - must be a Battlepass member (posess a valid Battlepass NFT). /// - required achievement Level must be reached. - /// May be called by user or by Organization owner or by a specially dedicated for this purpose account (Bot). + /// May be called by Organization owner or by a specially dedicated for this purpose account (Bot). /// /// Parameters: /// - `reward_id`: ID of the Reward Type to claim. + /// - `claimer`: User account for who to claim the reward. + /// - `cid`: If provided, store it in NFT's metadata. Otherwise, Reward CID will be stored there. #[pallet::call_index(9)] #[pallet::weight(::WeightInfo::claim_reward())] #[transactional] pub fn claim_reward( origin: OriginFor, reward_id: T::Hash, - for_who: T::AccountId, + claimer: T::AccountId, + cid: Option> ) -> DispatchResult { - let by_who = ensure_signed(origin.clone())?; + let caller = ensure_signed(origin)?; // check if Reward exists let reward = Self::get_reward(reward_id).ok_or(Error::::RewardUnknown)?; // check if Reward is active ensure!(Self::check_reward_state(reward_id, RewardState::ACTIVE)?, Error::::RewardInactive); // check if Reward has not been claimed yet - ensure!(!ClaimedRewards::::contains_key(&reward_id, &for_who), Error::::RewardClaimed); + ensure!(!ClaimedRewards::::contains_key(&reward_id, &claimer), Error::::RewardClaimed); // check if Battlepass exists let battlepass = Self::get_battlepass(&reward.battlepass_id).ok_or(Error::::BattlepassUnknown)?; let creator = battlepass.creator.clone(); @@ -687,17 +706,17 @@ pub mod pallet { ensure!(Self::check_battlepass_state(reward.battlepass_id, BattlepassState::ACTIVE)?, Error::::BattlepassStateWrong); // check if Org is active ensure!(T::Control::is_org_active(&battlepass.org_id), Error::::OrgUnknownOrInactive); - // check permissions (self, prime or bot) - ensure!(by_who == for_who || Self::is_prime_or_bot(&battlepass.org_id, by_who.clone())?, Error::::AuthorizationError); + // check permissions (prime or bot) + ensure!(Self::is_prime_or_bot(&battlepass.org_id, caller.clone())?, Error::::AuthorizationError); // check if user has access to Battlepass - ensure!(Self::has_battlepass_ownership(for_who.clone(), battlepass.collection_id), Error::::BattlepassOwnershipDoesntExist); + ensure!(Self::is_battlepass_member(claimer.clone(), battlepass.collection_id), Error::::BattlepassOwnershipDoesntExist); // check if user has reached the required Level - ensure!(Self::is_level_reached(&reward.battlepass_id, &for_who, reward.level), Error::::LevelNotReached); + ensure!(Self::is_level_reached(&reward.battlepass_id, &claimer, reward.level), Error::::LevelNotReached); - let nft_id = Self::do_claim_reward(creator, for_who.clone(), reward_id, reward.collection_id)?; + let nft_id = Self::do_claim_reward(creator, claimer.clone(), reward_id, reward.collection_id, cid.unwrap_or(reward.cid))?; - Self::deposit_event(Event::RewardClaimed {reward_id, claimer: for_who, collection_id: reward.collection_id, nft_id} ); + Self::deposit_event(Event::RewardClaimed {reward_id, claimer, collection_id: reward.collection_id, nft_id} ); Ok(()) } @@ -895,6 +914,15 @@ impl Pallet { Ok(()) } + + fn update_collection_metadata(owner: T::AccountId, collection_id: T::CollectionId, cid: String) -> DispatchResult { + let origin = OriginFor::::from(RawOrigin::Signed(owner.clone())); + let metadata = BoundedVec::truncate_from(cid.into()); + + pallet_uniques::Pallet::::set_collection_metadata(origin, collection_id, metadata, false)?; + + Ok(()) + } fn check_battlepass_state(battlepass_id: T::Hash, state: BattlepassState) -> Result { let current_state = Self::get_battlepass_state(battlepass_id).ok_or(Error::::BattlepassStateUnknown)?; @@ -946,10 +974,10 @@ impl Pallet { Ok(battlepass_id) } - fn do_claim_battlepass(creator: T::AccountId, for_who: T::AccountId, battlepass_id: T::Hash, collection_id: T::CollectionId) -> Result { + fn do_claim_battlepass(creator: T::AccountId, for_who: T::AccountId, collection_id: T::CollectionId, cid: String) -> Result { let nft_index = Self::bump_nft_index()?; let nft_id: T::ItemId = T::BattlepassHelper::item(nft_index); - let metadata = BoundedVec::truncate_from(battlepass_id.encode()); + let metadata = BoundedVec::truncate_from(cid.into()); // Create Battlepass NFT Self::create_nft(creator, for_who.clone(), collection_id, nft_id, metadata)?; @@ -990,10 +1018,10 @@ impl Pallet { Ok(reward_id) } - fn do_claim_reward(creator: T::AccountId, for_who: T::AccountId, reward_id: T::Hash, collection_id: T::CollectionId) -> Result { + fn do_claim_reward(creator: T::AccountId, for_who: T::AccountId, reward_id: T::Hash, collection_id: T::CollectionId, cid: String) -> Result { let nft_index = Self::bump_nft_index()?; let nft_id = T::BattlepassHelper::item(nft_index); - let metadata = BoundedVec::truncate_from(reward_id.encode()); + let metadata = BoundedVec::truncate_from(cid.into()); // Create Reward NFT Self::create_nft(creator, for_who.clone(), collection_id, nft_id, metadata)?; @@ -1003,7 +1031,7 @@ impl Pallet { Ok(nft_id) } - fn has_battlepass_ownership(account: T::AccountId, bp_collection_id: T::CollectionId) -> bool { + fn is_battlepass_member(account: T::AccountId, bp_collection_id: T::CollectionId) -> bool { let bp_owned_count = as InspectEnumerable>::owned_in_collection(&bp_collection_id, &account).count(); bp_owned_count > 0 } diff --git a/battlepass/src/tests.rs b/battlepass/src/tests.rs index 66b3db4d0..a49f1669d 100644 --- a/battlepass/src/tests.rs +++ b/battlepass/src/tests.rs @@ -280,6 +280,8 @@ fn update_battlepass_test() { assert_eq!(updated.name, new_name.clone()); assert_eq!(updated.cid, new_cid.clone()); assert_eq!(updated.price, new_price.clone()); + // Check if Collection metadata updated + assert_eq!(>::collection_attribute(&0, &[]), Some(new_cid.clone().into())); // Should update some fields in battlepass assert_ok!( @@ -469,6 +471,7 @@ fn claim_battlepass_test() { let org_id = create_org(); let battlepass_id = create_battlepass(org_id); let wrong_battlepass_id = ::Hashing::hash_of(&"123"); + let cid = BoundedVec::truncate_from(b"new cid".to_vec()); let creator = ALICE; let not_creator = BOB; let not_creator_2 = TOM; @@ -481,13 +484,13 @@ fn claim_battlepass_test() { // Should not claim unknown Battlepass assert_noop!( - Battlepass::claim_battlepass(Origin::signed(creator), wrong_battlepass_id, creator), + Battlepass::claim_battlepass(Origin::signed(creator), wrong_battlepass_id, creator, None), Error::::BattlepassUnknown ); // Should not claim Battlepass in DRAFT state assert_noop!( - Battlepass::claim_battlepass(Origin::signed(creator), battlepass_id, creator), + Battlepass::claim_battlepass(Origin::signed(creator), battlepass_id, creator, None), Error::::BattlepassStateWrong ); @@ -499,7 +502,7 @@ fn claim_battlepass_test() { Control::disable_org(Origin::signed(creator), org_id) ); assert_noop!( - Battlepass::claim_battlepass(Origin::signed(creator), battlepass_id, creator), + Battlepass::claim_battlepass(Origin::signed(creator), battlepass_id, creator, None), Error::::OrgUnknownOrInactive ); assert_ok!( @@ -508,35 +511,37 @@ fn claim_battlepass_test() { // Should not claim by Bot if Bot account was not added assert_noop!( - Battlepass::claim_battlepass(Origin::signed(BOT), battlepass_id, creator), + Battlepass::claim_battlepass(Origin::signed(BOT), battlepass_id, creator, None), Error::::AuthorizationError ); // Should not claim for others if origin is not a Prime assert_noop!( - Battlepass::claim_battlepass(Origin::signed(not_creator), battlepass_id, creator), + Battlepass::claim_battlepass(Origin::signed(not_creator), battlepass_id, creator, None), Error::::AuthorizationError ); assert_noop!( - Battlepass::claim_battlepass(Origin::signed(not_member), battlepass_id, creator), + Battlepass::claim_battlepass(Origin::signed(not_member), battlepass_id, creator, None), Error::::AuthorizationError ); // Should not claim for self assert_noop!( - Battlepass::claim_battlepass(Origin::signed(not_creator), battlepass_id, not_creator), + Battlepass::claim_battlepass(Origin::signed(not_creator), battlepass_id, not_creator, None), Error::::AuthorizationError ); // Should claim for others by Prime assert_ok!( - Battlepass::claim_battlepass(Origin::signed(creator), battlepass_id, not_creator) + Battlepass::claim_battlepass(Origin::signed(creator), battlepass_id, not_creator, None) ); // Check if NFT minted assert_eq!(>::items(&0).any(|x| x == 0) , true); + // Check NFT metadata + assert_eq!(>::attribute(&0, &0, &[]), Some(string().into())); // Should not claim if it was already claimed assert_noop!( - Battlepass::claim_battlepass(Origin::signed(creator), battlepass_id, not_creator), + Battlepass::claim_battlepass(Origin::signed(creator), battlepass_id, not_creator, None), Error::::BattlepassOwnershipExists ); @@ -548,14 +553,14 @@ fn claim_battlepass_test() { >::transfer(&0, &0, ¬_member_2) ); assert_ok!( - Battlepass::claim_battlepass(Origin::signed(creator), battlepass_id, not_creator) + Battlepass::claim_battlepass(Origin::signed(creator), battlepass_id, not_creator, None) ); // Check if NFT minted assert_eq!(>::items(&0).any(|x| x == 1) , true); // Should not claim if user received Battlepass NFT from someone else assert_noop!( - Battlepass::claim_battlepass(Origin::signed(creator), battlepass_id, not_member_2), + Battlepass::claim_battlepass(Origin::signed(creator), battlepass_id, not_member_2, None), Error::::BattlepassOwnershipExists ); @@ -564,22 +569,26 @@ fn claim_battlepass_test() { Battlepass::add_bot(Origin::signed(creator), battlepass_id, BOT) ); assert_ok!( - Battlepass::claim_battlepass(Origin::signed(BOT), battlepass_id, not_creator_3) + Battlepass::claim_battlepass(Origin::signed(BOT), battlepass_id, not_creator_3, None) ); // Check if NFT minted assert_eq!(>::items(&0).any(|x| x == 2) , true); // Should claim for accounts outside of org assert_ok!( - Battlepass::claim_battlepass(Origin::signed(creator), battlepass_id, not_member), + Battlepass::claim_battlepass(Origin::signed(creator), battlepass_id, not_member, Some(cid.clone())), ); + // Check if NFT minted + assert_eq!(>::items(&0).any(|x| x == 3) , true); + // Check NFT metadata + assert_eq!(>::attribute(&0, &3, &[]), Some(cid.into())); // Should not claim Battlepass in ENDED state assert_ok!( Battlepass::conclude_battlepass(Origin::signed(creator), battlepass_id) ); assert_noop!( - Battlepass::claim_battlepass(Origin::signed(creator), battlepass_id, creator), + Battlepass::claim_battlepass(Origin::signed(creator), battlepass_id, creator, None), Error::::BattlepassStateWrong ); // Check events @@ -651,7 +660,7 @@ fn set_points_test() { // Should set points by Prime assert_ok!( - Battlepass::claim_battlepass(Origin::signed(creator), battlepass_id, not_creator) + Battlepass::claim_battlepass(Origin::signed(creator), battlepass_id, not_creator, None) ); assert_ok!( Battlepass::set_points(Origin::signed(creator), battlepass_id, not_creator, 10) @@ -878,6 +887,8 @@ fn update_reward_test() { assert_eq!(updated.name, new_name.clone()); assert_eq!(updated.cid, new_cid.clone()); assert_eq!(updated.transferable, new_transferable.clone()); + // Check if Collection metadata updated + assert_eq!(>::collection_attribute(&1, &[]), Some(new_cid.clone().into())); // Should update some fields in Reward assert_ok!( @@ -1017,6 +1028,7 @@ fn claim_reward_test() { let org_id = create_org(); let battlepass_id = create_battlepass(org_id); let wrong_id = ::Hashing::hash_of(&"123"); + let cid = BoundedVec::truncate_from(b"new cid".to_vec()); let creator = ALICE; let not_creator = BOB; let not_creator_2 = TOM; @@ -1031,7 +1043,7 @@ fn claim_reward_test() { // Should not claim if Reward unknown assert_noop!( - Battlepass::claim_reward(Origin::signed(creator), wrong_id, creator), + Battlepass::claim_reward(Origin::signed(creator), wrong_id, creator, None), Error::::RewardUnknown ); @@ -1041,7 +1053,7 @@ fn claim_reward_test() { Battlepass::disable_reward(Origin::signed(creator), reward_id) ); assert_noop!( - Battlepass::claim_reward(Origin::signed(creator), reward_id, creator), + Battlepass::claim_reward(Origin::signed(creator), reward_id, creator, None), Error::::RewardInactive ); @@ -1053,14 +1065,14 @@ fn claim_reward_test() { } } ); assert_noop!( - Battlepass::claim_reward(Origin::signed(creator), reward_id, creator), + Battlepass::claim_reward(Origin::signed(creator), reward_id, creator, None), Error::::BattlepassUnknown ); // Should not claim if Battlepass state is DRAFT let reward_id = create_reward(battlepass_id); assert_noop!( - Battlepass::claim_reward(Origin::signed(creator), reward_id, creator), + Battlepass::claim_reward(Origin::signed(creator), reward_id, creator, None), Error::::BattlepassStateWrong ); @@ -1072,7 +1084,7 @@ fn claim_reward_test() { Control::disable_org(Origin::signed(creator), org_id) ); assert_noop!( - Battlepass::claim_reward(Origin::signed(creator), reward_id, creator), + Battlepass::claim_reward(Origin::signed(creator), reward_id, creator, None), Error::::OrgUnknownOrInactive ); assert_ok!( @@ -1081,41 +1093,46 @@ fn claim_reward_test() { // Should not claim by Bot if Bot account was not added assert_noop!( - Battlepass::claim_reward(Origin::signed(BOT), reward_id, creator), + Battlepass::claim_reward(Origin::signed(BOT), reward_id, creator, None), Error::::AuthorizationError ); // Should not claim for others if origin is not a Prime or Bot assert_noop!( - Battlepass::claim_reward(Origin::signed(not_creator), reward_id, creator), + Battlepass::claim_reward(Origin::signed(not_creator), reward_id, creator, None), Error::::AuthorizationError ); assert_noop!( - Battlepass::claim_reward(Origin::signed(not_member), reward_id, creator), + Battlepass::claim_reward(Origin::signed(not_member), reward_id, creator, None), + Error::::AuthorizationError + ); + // Should not claim for self + assert_noop!( + Battlepass::claim_reward(Origin::signed(not_member), reward_id, not_member, None), Error::::AuthorizationError ); // Should not claim Reward if user didn't claim Battlepass assert_noop!( - Battlepass::claim_reward(Origin::signed(not_creator), reward_id, not_creator), + Battlepass::claim_reward(Origin::signed(creator), reward_id, not_creator, None), Error::::BattlepassOwnershipDoesntExist ); // Should not claim Reward if no NFT for claimed Battlepass assert_ok!( - Battlepass::claim_battlepass(Origin::signed(creator), battlepass_id, not_creator) + Battlepass::claim_battlepass(Origin::signed(creator), battlepass_id, not_creator, None) ); assert_ok!( >::burn(&0, &0, None) ); assert_noop!( - Battlepass::claim_reward(Origin::signed(not_creator), reward_id, not_creator), + Battlepass::claim_reward(Origin::signed(creator), reward_id, not_creator, None), Error::::BattlepassOwnershipDoesntExist ); // Should not claim Reward if user lost ownership of Battlepass NFT assert_ok!( - Battlepass::claim_battlepass(Origin::signed(creator), battlepass_id, creator) + Battlepass::claim_battlepass(Origin::signed(creator), battlepass_id, creator, None) ); assert_ok!( Uniques::thaw_collection(Origin::signed(creator), 0) @@ -1124,16 +1141,16 @@ fn claim_reward_test() { >::transfer(&0, &1, ¬_member_2) ); assert_noop!( - Battlepass::claim_reward(Origin::signed(creator), reward_id, creator), + Battlepass::claim_reward(Origin::signed(creator), reward_id, creator, None), Error::::BattlepassOwnershipDoesntExist ); // Should not claim if user's level is too low assert_ok!( - Battlepass::claim_battlepass(Origin::signed(creator), battlepass_id, not_creator_3) + Battlepass::claim_battlepass(Origin::signed(creator), battlepass_id, not_creator_3, None) ); assert_noop!( - Battlepass::claim_reward(Origin::signed(not_creator_3), reward_id, not_creator_3), + Battlepass::claim_reward(Origin::signed(creator), reward_id, not_creator_3, None), Error::::LevelNotReached ); @@ -1145,26 +1162,30 @@ fn claim_reward_test() { Battlepass::add_level(Origin::signed(creator), battlepass_id, 1, 10) ); assert_ok!( - Battlepass::claim_reward(Origin::signed(not_creator_3), reward_id, not_creator_3) + Battlepass::claim_reward(Origin::signed(creator), reward_id, not_creator_3, None) ); // Check if Reward claimed assert_eq!(ClaimedRewards::::contains_key(reward_id, not_creator_3), true); + // Check if NFT minted + assert_eq!(>::items(&3).any(|x| x == 3) , true); + // Check NFT metadata + assert_eq!(>::attribute(&3, &3, &[]), Some(string().into())); // Should not claim if Reward already claimed assert_noop!( - Battlepass::claim_reward(Origin::signed(not_creator_3), reward_id, not_creator_3), + Battlepass::claim_reward(Origin::signed(creator), reward_id, not_creator_3, None), Error::::RewardClaimed ); // Should not claim if max limit reached assert_ok!( - Battlepass::claim_battlepass(Origin::signed(creator), battlepass_id, not_creator_4) + Battlepass::claim_battlepass(Origin::signed(creator), battlepass_id, not_creator_4, None) ); assert_ok!( Battlepass::set_points(Origin::signed(creator), battlepass_id, not_creator_4, 10) ); assert_noop!( - Battlepass::claim_reward(Origin::signed(not_creator_4), reward_id, not_creator_4), + Battlepass::claim_reward(Origin::signed(creator), reward_id, not_creator_4, None), pallet_uniques::Error::::MaxSupplyReached ); @@ -1174,24 +1195,32 @@ fn claim_reward_test() { Battlepass::add_bot(Origin::signed(creator), battlepass_id, BOT) ); assert_ok!( - Battlepass::claim_reward(Origin::signed(BOT), reward_id, not_creator_4) + Battlepass::claim_reward(Origin::signed(BOT), reward_id, not_creator_4, None) ); // Check if Reward claimed assert_eq!(ClaimedRewards::::contains_key(reward_id, not_creator_4), true); + // Check if NFT minted + assert_eq!(>::items(&4).any(|x| x == 5) , true); + // Check NFT metadata + assert_eq!(>::attribute(&4, &5, &[]), Some(string().into())); // Should claim Reward for non-member let reward_id = create_reward(battlepass_id); assert_ok!( - Battlepass::claim_battlepass(Origin::signed(creator), battlepass_id, not_member) + Battlepass::claim_battlepass(Origin::signed(creator), battlepass_id, not_member, None) ); assert_ok!( Battlepass::set_points(Origin::signed(creator), battlepass_id, not_member, 10) ); assert_ok!( - Battlepass::claim_reward(Origin::signed(not_member), reward_id, not_member) + Battlepass::claim_reward(Origin::signed(creator), reward_id, not_member, Some(cid.clone())) ); // Check if Reward claimed assert_eq!(ClaimedRewards::::contains_key(reward_id, not_member), true); + // Check if NFT minted + assert_eq!(>::items(&5).any(|x| x == 7) , true); + // Check NFT metadata + assert_eq!(>::attribute(&5, &7, &[]), Some(cid.into())); // Should claim Reward after receiving Battlepass NFT from elsewhere let reward_id = create_reward(battlepass_id); @@ -1199,17 +1228,21 @@ fn claim_reward_test() { Battlepass::set_points(Origin::signed(creator), battlepass_id, not_member_2, 10) ); assert_ok!( - Battlepass::claim_reward(Origin::signed(not_member_2), reward_id, not_member_2) + Battlepass::claim_reward(Origin::signed(creator), reward_id, not_member_2, None) ); // Check if Reward claimed assert_eq!(ClaimedRewards::::contains_key(reward_id, not_member_2), true); + // Check if NFT minted + assert_eq!(>::items(&6).any(|x| x == 8) , true); + // Check NFT metadata + assert_eq!(>::attribute(&6, &8, &[]), Some(string().into())); // Should not claim if Battlepass state is ENDED assert_ok!( Battlepass::conclude_battlepass(Origin::signed(creator), battlepass_id) ); assert_noop!( - Battlepass::claim_reward(Origin::signed(not_creator_4), reward_id, not_creator_3), + Battlepass::claim_reward(Origin::signed(creator), reward_id, not_creator_3, None), Error::::BattlepassStateWrong ); diff --git a/battlepass/src/weights.rs b/battlepass/src/weights.rs index 0078faa59..ab3d4e8a3 100644 --- a/battlepass/src/weights.rs +++ b/battlepass/src/weights.rs @@ -2,7 +2,7 @@ //! Autogenerated weights for gamedao_battlepass //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-03-14, STEPS: `20`, REPEAT: `10`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2023-03-16, STEPS: `20`, REPEAT: `10`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: None, DB CACHE: 1024 @@ -67,7 +67,7 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `597` // Estimated: `13676` - // Minimum execution time: 87_000 nanoseconds. + // Minimum execution time: 86_000 nanoseconds. Weight::from_parts(88_000_000, 13676) .saturating_add(T::DbWeight::get().reads(6_u64)) .saturating_add(T::DbWeight::get().writes(7_u64)) @@ -82,14 +82,18 @@ impl WeightInfo for SubstrateWeight { /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) /// Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) /// Proof: Battlepass BattlepassInfoByOrg (max_values: None, max_size: Some(118), added: 2593, mode: MaxEncodedLen) + /// Storage: Uniques Class (r:1 w:1) + /// Proof: Uniques Class (max_values: None, max_size: Some(178), added: 2653, mode: MaxEncodedLen) + /// Storage: Uniques ClassMetadataOf (r:1 w:1) + /// Proof: Uniques ClassMetadataOf (max_values: None, max_size: Some(167), added: 2642, mode: MaxEncodedLen) fn update_battlepass() -> Weight { // Proof Size summary in bytes: - // Measured: `945` - // Estimated: `13263` - // Minimum execution time: 33_000 nanoseconds. - Weight::from_parts(34_000_000, 13263) - .saturating_add(T::DbWeight::get().reads(5_u64)) - .saturating_add(T::DbWeight::get().writes(1_u64)) + // Measured: `1354` + // Estimated: `18558` + // Minimum execution time: 67_000 nanoseconds. + Weight::from_parts(71_000_000, 18558) + .saturating_add(T::DbWeight::get().reads(7_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) } /// Storage: Battlepass Battlepasses (r:1 w:0) /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(382), added: 2857, mode: MaxEncodedLen) @@ -117,8 +121,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `1359` // Estimated: `26736` - // Minimum execution time: 97_000 nanoseconds. - Weight::from_parts(98_000_000, 26736) + // Minimum execution time: 98_000 nanoseconds. + Weight::from_parts(99_000_000, 26736) .saturating_add(T::DbWeight::get().reads(11_u64)) .saturating_add(T::DbWeight::get().writes(5_u64)) } @@ -136,8 +140,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `880` // Estimated: `13263` - // Minimum execution time: 36_000 nanoseconds. - Weight::from_parts(37_000_000, 13263) + // Minimum execution time: 35_000 nanoseconds. + Weight::from_parts(36_000_000, 13263) .saturating_add(T::DbWeight::get().reads(5_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } @@ -153,7 +157,7 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `907` // Estimated: `10739` - // Minimum execution time: 30_000 nanoseconds. + // Minimum execution time: 31_000 nanoseconds. Weight::from_parts(32_000_000, 10739) .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) @@ -176,8 +180,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `1417` // Estimated: `18389` - // Minimum execution time: 41_000 nanoseconds. - Weight::from_parts(43_000_000, 18389) + // Minimum execution time: 43_000 nanoseconds. + Weight::from_parts(45_000_000, 18389) .saturating_add(T::DbWeight::get().reads(7_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -210,7 +214,7 @@ impl WeightInfo for SubstrateWeight { // Measured: `1226` // Estimated: `21556` // Minimum execution time: 110_000 nanoseconds. - Weight::from_parts(112_000_000, 21556) + Weight::from_parts(111_000_000, 21556) .saturating_add(T::DbWeight::get().reads(9_u64)) .saturating_add(T::DbWeight::get().writes(7_u64)) } @@ -228,14 +232,18 @@ impl WeightInfo for SubstrateWeight { /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) /// Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) /// Proof: Battlepass BattlepassInfoByOrg (max_values: None, max_size: Some(118), added: 2593, mode: MaxEncodedLen) + /// Storage: Uniques Class (r:1 w:1) + /// Proof: Uniques Class (max_values: None, max_size: Some(178), added: 2653, mode: MaxEncodedLen) + /// Storage: Uniques ClassMetadataOf (r:1 w:1) + /// Proof: Uniques ClassMetadataOf (max_values: None, max_size: Some(167), added: 2642, mode: MaxEncodedLen) fn update_reward() -> Weight { // Proof Size summary in bytes: - // Measured: `1169` - // Estimated: `18608` - // Minimum execution time: 41_000 nanoseconds. - Weight::from_parts(42_000_000, 18608) - .saturating_add(T::DbWeight::get().reads(7_u64)) - .saturating_add(T::DbWeight::get().writes(1_u64)) + // Measured: `1685` + // Estimated: `23903` + // Minimum execution time: 73_000 nanoseconds. + Weight::from_parts(75_000_000, 23903) + .saturating_add(T::DbWeight::get().reads(9_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) } /// Storage: Battlepass Rewards (r:1 w:0) /// Proof: Battlepass Rewards (max_values: None, max_size: Some(346), added: 2821, mode: MaxEncodedLen) @@ -252,7 +260,7 @@ impl WeightInfo for SubstrateWeight { // Measured: `1094` // Estimated: `13560` // Minimum execution time: 33_000 nanoseconds. - Weight::from_parts(36_000_000, 13560) + Weight::from_parts(37_000_000, 13560) .saturating_add(T::DbWeight::get().reads(5_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -290,10 +298,10 @@ impl WeightInfo for SubstrateWeight { /// Proof: Uniques InstanceMetadataOf (max_values: None, max_size: Some(187), added: 2662, mode: MaxEncodedLen) fn claim_reward() -> Weight { // Proof Size summary in bytes: - // Measured: `2203` + // Measured: `2192` // Estimated: `44882` - // Minimum execution time: 134_000 nanoseconds. - Weight::from_parts(135_000_000, 44882) + // Minimum execution time: 135_000 nanoseconds. + Weight::from_parts(145_000_000, 44882) .saturating_add(T::DbWeight::get().reads(18_u64)) .saturating_add(T::DbWeight::get().writes(6_u64)) } @@ -313,7 +321,7 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `945` // Estimated: `13263` - // Minimum execution time: 31_000 nanoseconds. + // Minimum execution time: 32_000 nanoseconds. Weight::from_parts(32_000_000, 13263) .saturating_add(T::DbWeight::get().reads(5_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) @@ -334,8 +342,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `1038` // Estimated: `15807` - // Minimum execution time: 37_000 nanoseconds. - Weight::from_parts(38_000_000, 15807) + // Minimum execution time: 36_000 nanoseconds. + Weight::from_parts(37_000_000, 15807) .saturating_add(T::DbWeight::get().reads(6_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -353,8 +361,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `880` // Estimated: `13263` - // Minimum execution time: 30_000 nanoseconds. - Weight::from_parts(33_000_000, 13263) + // Minimum execution time: 31_000 nanoseconds. + Weight::from_parts(32_000_000, 13263) .saturating_add(T::DbWeight::get().reads(5_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -384,7 +392,7 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `597` // Estimated: `13676` - // Minimum execution time: 87_000 nanoseconds. + // Minimum execution time: 86_000 nanoseconds. Weight::from_parts(88_000_000, 13676) .saturating_add(RocksDbWeight::get().reads(6_u64)) .saturating_add(RocksDbWeight::get().writes(7_u64)) @@ -399,14 +407,18 @@ impl WeightInfo for () { /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) /// Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) /// Proof: Battlepass BattlepassInfoByOrg (max_values: None, max_size: Some(118), added: 2593, mode: MaxEncodedLen) + /// Storage: Uniques Class (r:1 w:1) + /// Proof: Uniques Class (max_values: None, max_size: Some(178), added: 2653, mode: MaxEncodedLen) + /// Storage: Uniques ClassMetadataOf (r:1 w:1) + /// Proof: Uniques ClassMetadataOf (max_values: None, max_size: Some(167), added: 2642, mode: MaxEncodedLen) fn update_battlepass() -> Weight { // Proof Size summary in bytes: - // Measured: `945` - // Estimated: `13263` - // Minimum execution time: 33_000 nanoseconds. - Weight::from_parts(34_000_000, 13263) - .saturating_add(RocksDbWeight::get().reads(5_u64)) - .saturating_add(RocksDbWeight::get().writes(1_u64)) + // Measured: `1354` + // Estimated: `18558` + // Minimum execution time: 67_000 nanoseconds. + Weight::from_parts(71_000_000, 18558) + .saturating_add(RocksDbWeight::get().reads(7_u64)) + .saturating_add(RocksDbWeight::get().writes(3_u64)) } /// Storage: Battlepass Battlepasses (r:1 w:0) /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(382), added: 2857, mode: MaxEncodedLen) @@ -434,8 +446,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `1359` // Estimated: `26736` - // Minimum execution time: 97_000 nanoseconds. - Weight::from_parts(98_000_000, 26736) + // Minimum execution time: 98_000 nanoseconds. + Weight::from_parts(99_000_000, 26736) .saturating_add(RocksDbWeight::get().reads(11_u64)) .saturating_add(RocksDbWeight::get().writes(5_u64)) } @@ -453,8 +465,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `880` // Estimated: `13263` - // Minimum execution time: 36_000 nanoseconds. - Weight::from_parts(37_000_000, 13263) + // Minimum execution time: 35_000 nanoseconds. + Weight::from_parts(36_000_000, 13263) .saturating_add(RocksDbWeight::get().reads(5_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) } @@ -470,7 +482,7 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `907` // Estimated: `10739` - // Minimum execution time: 30_000 nanoseconds. + // Minimum execution time: 31_000 nanoseconds. Weight::from_parts(32_000_000, 10739) .saturating_add(RocksDbWeight::get().reads(4_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) @@ -493,8 +505,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `1417` // Estimated: `18389` - // Minimum execution time: 41_000 nanoseconds. - Weight::from_parts(43_000_000, 18389) + // Minimum execution time: 43_000 nanoseconds. + Weight::from_parts(45_000_000, 18389) .saturating_add(RocksDbWeight::get().reads(7_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -527,7 +539,7 @@ impl WeightInfo for () { // Measured: `1226` // Estimated: `21556` // Minimum execution time: 110_000 nanoseconds. - Weight::from_parts(112_000_000, 21556) + Weight::from_parts(111_000_000, 21556) .saturating_add(RocksDbWeight::get().reads(9_u64)) .saturating_add(RocksDbWeight::get().writes(7_u64)) } @@ -545,14 +557,18 @@ impl WeightInfo for () { /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) /// Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) /// Proof: Battlepass BattlepassInfoByOrg (max_values: None, max_size: Some(118), added: 2593, mode: MaxEncodedLen) + /// Storage: Uniques Class (r:1 w:1) + /// Proof: Uniques Class (max_values: None, max_size: Some(178), added: 2653, mode: MaxEncodedLen) + /// Storage: Uniques ClassMetadataOf (r:1 w:1) + /// Proof: Uniques ClassMetadataOf (max_values: None, max_size: Some(167), added: 2642, mode: MaxEncodedLen) fn update_reward() -> Weight { // Proof Size summary in bytes: - // Measured: `1169` - // Estimated: `18608` - // Minimum execution time: 41_000 nanoseconds. - Weight::from_parts(42_000_000, 18608) - .saturating_add(RocksDbWeight::get().reads(7_u64)) - .saturating_add(RocksDbWeight::get().writes(1_u64)) + // Measured: `1685` + // Estimated: `23903` + // Minimum execution time: 73_000 nanoseconds. + Weight::from_parts(75_000_000, 23903) + .saturating_add(RocksDbWeight::get().reads(9_u64)) + .saturating_add(RocksDbWeight::get().writes(3_u64)) } /// Storage: Battlepass Rewards (r:1 w:0) /// Proof: Battlepass Rewards (max_values: None, max_size: Some(346), added: 2821, mode: MaxEncodedLen) @@ -569,7 +585,7 @@ impl WeightInfo for () { // Measured: `1094` // Estimated: `13560` // Minimum execution time: 33_000 nanoseconds. - Weight::from_parts(36_000_000, 13560) + Weight::from_parts(37_000_000, 13560) .saturating_add(RocksDbWeight::get().reads(5_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -607,10 +623,10 @@ impl WeightInfo for () { /// Proof: Uniques InstanceMetadataOf (max_values: None, max_size: Some(187), added: 2662, mode: MaxEncodedLen) fn claim_reward() -> Weight { // Proof Size summary in bytes: - // Measured: `2203` + // Measured: `2192` // Estimated: `44882` - // Minimum execution time: 134_000 nanoseconds. - Weight::from_parts(135_000_000, 44882) + // Minimum execution time: 135_000 nanoseconds. + Weight::from_parts(145_000_000, 44882) .saturating_add(RocksDbWeight::get().reads(18_u64)) .saturating_add(RocksDbWeight::get().writes(6_u64)) } @@ -630,7 +646,7 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `945` // Estimated: `13263` - // Minimum execution time: 31_000 nanoseconds. + // Minimum execution time: 32_000 nanoseconds. Weight::from_parts(32_000_000, 13263) .saturating_add(RocksDbWeight::get().reads(5_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) @@ -651,8 +667,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `1038` // Estimated: `15807` - // Minimum execution time: 37_000 nanoseconds. - Weight::from_parts(38_000_000, 15807) + // Minimum execution time: 36_000 nanoseconds. + Weight::from_parts(37_000_000, 15807) .saturating_add(RocksDbWeight::get().reads(6_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -670,8 +686,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `880` // Estimated: `13263` - // Minimum execution time: 30_000 nanoseconds. - Weight::from_parts(33_000_000, 13263) + // Minimum execution time: 31_000 nanoseconds. + Weight::from_parts(32_000_000, 13263) .saturating_add(RocksDbWeight::get().reads(5_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } diff --git a/control/src/lib.rs b/control/src/lib.rs index 022dcd7cf..fa13dd9f5 100644 --- a/control/src/lib.rs +++ b/control/src/lib.rs @@ -316,7 +316,7 @@ pub mod pallet { pay_currency: Option, deposit: Option, ) -> DispatchResult { - let sender = ensure_signed(origin.clone())?; + let sender = ensure_signed(origin)?; // Provide default values for optional parameters: let member_limit = member_limit.unwrap_or(T::MaxMembers::get()); From dcab08a38cb59c846110ad49a839854c1778bafe Mon Sep 17 00:00:00 2001 From: FiberMan Date: Wed, 22 Mar 2023 16:51:08 +0100 Subject: [PATCH 42/49] address comments from SBP3 review --- battlepass/src/lib.rs | 71 +++++++++++++++-------------- battlepass/src/mock.rs | 1 - battlepass/src/tests.rs | 27 +----------- control/src/lib.rs | 94 ++++++++++++++++++++------------------- flow/src/lib.rs | 89 +++++++++++++++++++------------------ flow/src/mock.rs | 2 +- flow/src/tests.rs | 44 ++++++++++-------- signal/src/lib.rs | 98 ++++++++++++++++++++--------------------- 8 files changed, 204 insertions(+), 222 deletions(-) diff --git a/battlepass/src/lib.rs b/battlepass/src/lib.rs index 59b68d636..107d48b4f 100644 --- a/battlepass/src/lib.rs +++ b/battlepass/src/lib.rs @@ -43,11 +43,11 @@ pub trait BattlepassHelper { pub struct BpHelper; impl, ItemId: From> BattlepassHelper for BpHelper { - fn collection(i: u32) -> CollectionId { - i.into() + fn collection(id: u32) -> CollectionId { + id.into() } - fn item(i: u32) -> ItemId { - i.into() + fn item(id: u32) -> ItemId { + id.into() } } @@ -210,7 +210,6 @@ pub mod pallet { #[pallet::error] pub enum Error { AuthorizationError, - CollectionUnknown, BattlepassExists, BattlepassOwnershipExists, BattlepassOwnershipDoesntExist, @@ -243,13 +242,13 @@ pub mod pallet { /// BattlepassStates: map Hash => BattlepassState #[pallet::storage] #[pallet::getter(fn get_battlepass_state)] - pub type BattlepassStates = StorageMap<_, Blake2_128Concat, T::Hash, BattlepassState, OptionQuery>; + pub(super) type BattlepassStates = StorageMap<_, Blake2_128Concat, T::Hash, BattlepassState, OptionQuery>; /// Battlepass info by organization. /// /// BattlepassInfoByOrg: map Hash => BattlepassInfo #[pallet::storage] - pub type BattlepassInfoByOrg = StorageMap<_, Blake2_128Concat, T::Hash, BattlepassInfo, OptionQuery>; + pub(super) type BattlepassInfoByOrg = StorageMap<_, Blake2_128Concat, T::Hash, BattlepassInfo, OptionQuery>; /// Total earned Points for users per each Battlepass. /// @@ -306,14 +305,14 @@ pub mod pallet { /// CollectionIndex: u32 #[pallet::storage] #[pallet::getter(fn get_collection_index)] - pub type CollectionIndex = StorageValue<_, u32, ValueQuery>; + pub(super) type CollectionIndex = StorageValue<_, u32, ValueQuery>; /// A counter for created NFTs /// /// NftIndex: u32 #[pallet::storage] #[pallet::getter(fn get_nft_index)] - pub type NftIndex = StorageValue<_, u32, ValueQuery>; + pub(super) type NftIndex = StorageValue<_, u32, ValueQuery>; #[pallet::call] impl Pallet { @@ -379,7 +378,7 @@ pub mod pallet { // check if there is something to update let name_changed = name.is_some() && name.clone().unwrap() != battlepass.name; let cid_changed = cid.is_some() && cid.clone().unwrap() != battlepass.cid; - let price_changed = price.is_some() && price.clone().unwrap() != battlepass.price; + let price_changed = price.is_some() && price.unwrap() != battlepass.price; ensure!( name_changed || cid_changed || price_changed, Error::::NoChangesProvided @@ -389,10 +388,10 @@ pub mod pallet { // check if Org is active ensure!(T::Control::is_org_active(&battlepass.org_id), Error::::OrgUnknownOrInactive); // check permissions (prime) - ensure!(Self::is_prime_or_bot(&battlepass.org_id, creator.clone())?, Error::::AuthorizationError); + ensure!(Self::is_prime_or_bot(&battlepass.org_id, creator)?, Error::::AuthorizationError); if name_changed { battlepass.name = name.clone().unwrap() } - if price_changed { battlepass.price = price.clone().unwrap() } + if price_changed { battlepass.price = price.unwrap() } if cid_changed { battlepass.cid = cid.clone().unwrap(); @@ -430,7 +429,7 @@ pub mod pallet { // check if Battlepass in ACTIVE state ensure!(Self::check_battlepass_state(battlepass_id, BattlepassState::ACTIVE)?, Error::::BattlepassStateWrong); // check if Org is active - let org_id = battlepass.org_id.clone(); + let org_id = battlepass.org_id; ensure!(T::Control::is_org_active(&org_id), Error::::OrgUnknownOrInactive); // check permissions (prime, bot) ensure!(Self::is_prime_or_bot(&org_id, caller.clone())?, Error::::AuthorizationError); @@ -608,7 +607,7 @@ pub mod pallet { // check if there is something to update let name_changed = name.is_some() && name.clone().unwrap() != reward.name; let cid_changed = cid.is_some() && cid.clone().unwrap() != reward.cid; - let transferable_changed = transferable.is_some() && transferable.clone().unwrap() != reward.transferable; + let transferable_changed = transferable.is_some() && transferable.unwrap() != reward.transferable; ensure!( name_changed || cid_changed || transferable_changed, Error::::NoChangesProvided @@ -625,7 +624,7 @@ pub mod pallet { ensure!(Self::is_prime_or_bot(&battlepass.org_id, caller)?, Error::::AuthorizationError); if name_changed { reward.name = name.clone().unwrap() }; - if transferable_changed { reward.transferable = transferable.clone().unwrap() }; + if transferable_changed { reward.transferable = transferable.unwrap() }; if cid_changed { reward.cid = cid.clone().unwrap(); @@ -698,16 +697,16 @@ pub mod pallet { // check if Reward is active ensure!(Self::check_reward_state(reward_id, RewardState::ACTIVE)?, Error::::RewardInactive); // check if Reward has not been claimed yet - ensure!(!ClaimedRewards::::contains_key(&reward_id, &claimer), Error::::RewardClaimed); + ensure!(!ClaimedRewards::::contains_key(reward_id, &claimer), Error::::RewardClaimed); // check if Battlepass exists - let battlepass = Self::get_battlepass(&reward.battlepass_id).ok_or(Error::::BattlepassUnknown)?; + let battlepass = Self::get_battlepass(reward.battlepass_id).ok_or(Error::::BattlepassUnknown)?; let creator = battlepass.creator.clone(); // check if Battlepass in ACTIVE state ensure!(Self::check_battlepass_state(reward.battlepass_id, BattlepassState::ACTIVE)?, Error::::BattlepassStateWrong); // check if Org is active ensure!(T::Control::is_org_active(&battlepass.org_id), Error::::OrgUnknownOrInactive); // check permissions (prime or bot) - ensure!(Self::is_prime_or_bot(&battlepass.org_id, caller.clone())?, Error::::AuthorizationError); + ensure!(Self::is_prime_or_bot(&battlepass.org_id, caller)?, Error::::AuthorizationError); // check if user has access to Battlepass ensure!(Self::is_battlepass_member(claimer.clone(), battlepass.collection_id), Error::::BattlepassOwnershipDoesntExist); @@ -744,7 +743,7 @@ pub mod pallet { // check if Org is active ensure!(T::Control::is_org_active(&battlepass.org_id), Error::::OrgUnknownOrInactive); // check permissions (prime, bot) - ensure!(Self::is_prime_or_bot(&battlepass.org_id, sender.clone())?, Error::::AuthorizationError); + ensure!(Self::is_prime_or_bot(&battlepass.org_id, sender)?, Error::::AuthorizationError); Levels::::insert(battlepass_id, level, points); @@ -774,7 +773,7 @@ pub mod pallet { // check if Org is active ensure!(T::Control::is_org_active(&battlepass.org_id), Error::::OrgUnknownOrInactive); // check permissions (prime, bot) - ensure!(Self::is_prime_or_bot(&battlepass.org_id, sender.clone())?, Error::::AuthorizationError); + ensure!(Self::is_prime_or_bot(&battlepass.org_id, sender)?, Error::::AuthorizationError); // check if Level exists ensure!(Levels::::contains_key(battlepass_id, level), Error::::LevelUnknown); @@ -812,7 +811,7 @@ pub mod pallet { inf.bot = Some(bot.clone()); Ok(()) } else { - return Err(Error::::BattlepassInfoUnknown)?; + Err(Error::::BattlepassInfoUnknown)? } })?; @@ -892,7 +891,7 @@ impl Pallet { pallet_uniques::Event::Created { collection: collection_id, creator: owner.clone(), - owner: owner.clone(), + owner, }, )?; pallet_uniques::Pallet::::set_collection_metadata(origin.clone(), collection_id, metadata, false)?; @@ -916,7 +915,7 @@ impl Pallet { } fn update_collection_metadata(owner: T::AccountId, collection_id: T::CollectionId, cid: String) -> DispatchResult { - let origin = OriginFor::::from(RawOrigin::Signed(owner.clone())); + let origin = OriginFor::::from(RawOrigin::Signed(owner)); let metadata = BoundedVec::truncate_from(cid.into()); pallet_uniques::Pallet::::set_collection_metadata(origin, collection_id, metadata, false)?; @@ -938,32 +937,32 @@ impl Pallet { fn get_battlepass_info(org_id: &T::Hash) -> (u32, Option, Option) { if let Some(bp_info) = BattlepassInfoByOrg::::get(org_id) { - return (bp_info.count, bp_info.active, bp_info.bot); + (bp_info.count, bp_info.active, bp_info.bot) } else { - return (0, None, None); + (0, None, None) } } - fn do_create_battlepass(creator: T::AccountId, org_id: T::Hash, name: String, cid: String, collection_id: T::CollectionId, price: u16, new_season:u32) -> Result { + fn do_create_battlepass(creator: T::AccountId, org_id: T::Hash, name: String, cid: String, collection_id: T::CollectionId, price: u16, season:u32) -> Result { let battlepass: Battlepass, T::CollectionId> = Battlepass { creator, org_id, name, cid, - season: new_season, + season, collection_id, price }; let battlepass_id = ::Hashing::hash_of(&battlepass); - Battlepasses::::insert(&battlepass_id, battlepass); - BattlepassStates::::insert(&battlepass_id, BattlepassState::DRAFT); - if new_season == 1 { - BattlepassInfoByOrg::::insert(org_id, BattlepassInfo{count: new_season, active: None, bot: None}); + Battlepasses::::insert(battlepass_id, battlepass); + BattlepassStates::::insert(battlepass_id, BattlepassState::DRAFT); + if season == 1 { + BattlepassInfoByOrg::::insert(org_id, BattlepassInfo{count: season, active: None, bot: None}); } else { BattlepassInfoByOrg::::try_mutate(org_id, |info| -> Result<(), DispatchError> { if let Some(inf) = info { - inf.count = new_season; + inf.count = season; } else { return Err(Error::::BattlepassInfoUnknown)?; } @@ -980,7 +979,7 @@ impl Pallet { let metadata = BoundedVec::truncate_from(cid.into()); // Create Battlepass NFT - Self::create_nft(creator, for_who.clone(), collection_id, nft_id, metadata)?; + Self::create_nft(creator, for_who, collection_id, nft_id, metadata)?; Ok(nft_id) } @@ -988,13 +987,13 @@ impl Pallet { fn change_battlepass_state(org_id: T::Hash, battlepass_id: T::Hash, state: BattlepassState) -> DispatchResult { let active_battlepass = if state == BattlepassState::ACTIVE { Some(battlepass_id) } else { None }; - BattlepassStates::::insert(&battlepass_id, state); + BattlepassStates::::insert(battlepass_id, state); BattlepassInfoByOrg::::try_mutate(org_id, |info| -> Result<(), DispatchError> { if let Some(inf) = info { inf.active = active_battlepass; Ok(()) } else { - return Err(Error::::BattlepassInfoUnknown)?; + Err(Error::::BattlepassInfoUnknown)? } })?; @@ -1026,7 +1025,7 @@ impl Pallet { // Create Reward NFT Self::create_nft(creator, for_who.clone(), collection_id, nft_id, metadata)?; - ClaimedRewards::::insert(&reward_id, &for_who, nft_id); + ClaimedRewards::::insert(reward_id, &for_who, nft_id); Ok(nft_id) } diff --git a/battlepass/src/mock.rs b/battlepass/src/mock.rs index 34e4fbb63..c4e7402b3 100644 --- a/battlepass/src/mock.rs +++ b/battlepass/src/mock.rs @@ -1,7 +1,6 @@ #![cfg(test)] use crate as gamedao_battlepass; -// use frame_support::traits::{ConstU16, ConstU64}; use frame_support::{construct_runtime, parameter_types, PalletId, traits::{AsEnsureOriginWithArg, Nothing, GenesisBuild}, pallet_prelude::*, diff --git a/battlepass/src/tests.rs b/battlepass/src/tests.rs index a49f1669d..92be2e59a 100644 --- a/battlepass/src/tests.rs +++ b/battlepass/src/tests.rs @@ -6,10 +6,9 @@ use sp_core::H256; use crate::mock::{ new_test_ext, RuntimeOrigin as Origin, Test, - //System, Battlepass, Control, Uniques, ALICE, BOB, EVA, TOM, BOT, PROTOCOL_TOKEN_ID, PAYMENT_TOKEN_ID, DOLLARS, - AccountId, StringLimit, //Event + AccountId, StringLimit, }; use gamedao_control::types::{AccessModel, FeeModel, OrgType, Org}; @@ -323,8 +322,6 @@ fn update_battlepass_test() { Battlepass::update_battlepass(Origin::signed(creator), battlepass_id, Some(new_name), Some(new_cid), Some(30)), Error::::BattlepassStateWrong ); - - // Check events (battlepass updated) }) } @@ -459,8 +456,6 @@ fn deactivate_battlepass_test() { Battlepass::conclude_battlepass(Origin::signed(creator), battlepass_id), Error::::BattlepassStateWrong ); - - // Check events }) } @@ -591,7 +586,6 @@ fn claim_battlepass_test() { Battlepass::claim_battlepass(Origin::signed(creator), battlepass_id, creator, None), Error::::BattlepassStateWrong ); - // Check events }) } @@ -686,8 +680,6 @@ fn set_points_test() { Battlepass::set_points(Origin::signed(creator), battlepass_id, creator, 10), Error::::BattlepassStateWrong ); - - // Check events }) } @@ -803,9 +795,6 @@ fn create_reward_test() { Error::::BattlepassStateWrong ); - - // Check events - }) } @@ -939,8 +928,6 @@ fn update_reward_test() { Battlepass::update_reward(Origin::signed(creator), reward_id, Some(new_name.clone()), Some(new_cid.clone()), Some(false)), Error::::RewardInactive ); - - // Check events }) } @@ -1017,8 +1004,6 @@ fn disable_reward_test() { // Check if RewardState is INACTIVE assert_eq!(RewardStates::::get(reward_id_3), Some(RewardState::INACTIVE)); - // Check events - }) } @@ -1245,8 +1230,6 @@ fn claim_reward_test() { Battlepass::claim_reward(Origin::signed(creator), reward_id, not_creator_3, None), Error::::BattlepassStateWrong ); - - // Check events }) } @@ -1331,8 +1314,6 @@ fn add_level_test() { Battlepass::add_level(Origin::signed(creator), battlepass_id, 1, 10), Error::::BattlepassStateWrong ); - - // Check events }) } @@ -1438,9 +1419,6 @@ fn remove_level_test() { Error::::BattlepassStateWrong ); - - // Check events - }) } @@ -1517,8 +1495,5 @@ fn add_bot_test() { Error::::BattlepassStateWrong ); - - // Check events - }) } diff --git a/control/src/lib.rs b/control/src/lib.rs index fa13dd9f5..950e2d4bc 100644 --- a/control/src/lib.rs +++ b/control/src/lib.rs @@ -22,7 +22,7 @@ pub mod weights; use codec::Codec; use frame_support::{dispatch::{DispatchResult, DispatchError, RawOrigin}, - ensure, PalletId, traits::Get, BoundedVec, transactional, log + ensure, PalletId, traits::Get, BoundedVec, transactional, }; use frame_system::ensure_root; #[cfg(feature = "runtime-benchmarks")] @@ -185,14 +185,14 @@ pub mod pallet { let org: Org = types::Org { index, creator: creator.clone(), prime: prime.clone(), name: name.clone(), cid: cid.clone(), org_type: org_type.clone(), fee_model: fee_model.clone(), membership_fee: Some(*membership_fee), - gov_currency: gov_currency.clone(), pay_currency: *pay_currency, member_limit: *member_limit, - access_model: access_model.clone(), created: now.clone(), mutated: now + gov_currency: *gov_currency, pay_currency: *pay_currency, member_limit: *member_limit, + access_model: access_model.clone(), created: now, mutated: now }; let org_id = ::Hashing::hash_of(&org); - if Pallet::::do_create_org(org_id.clone(), &org, treasury_id.clone(), *deposit).is_err() { log::error!("Error creating organization in genesis.") }; - if Pallet::::do_add_member(org_id, creator.clone(), MemberState::Active).is_err() { log::error!("Error adding member in genesis.") }; - if Pallet::::pay_membership_fee(&creator, &treasury_id, &org).is_err() { log::error!("Error paying membership fee in genesis.") }; + Pallet::::do_create_org(org_id, &org, treasury_id.clone(), *deposit).expect("Error creating organization in genesis."); + Pallet::::do_add_member(org_id, creator.clone(), MemberState::Active).expect("Error adding member in genesis."); + Pallet::::pay_membership_fee(creator, treasury_id, &org).expect("Error paying membership fee in genesis."); }); } } @@ -338,11 +338,11 @@ pub mod pallet { let now = frame_system::Pallet::::block_number(); let org = types::Org { index, creator: sender.clone(), prime: sender.clone(), name, cid, org_type, - fee_model: fee_model.clone(), membership_fee: membership_fee.clone(), gov_currency, - pay_currency, member_limit, access_model, created: now.clone(), mutated: now, + fee_model: fee_model.clone(), membership_fee, gov_currency, + pay_currency, member_limit, access_model, created: now, mutated: now, }; let org_id = T::Hashing::hash_of(&org); - ensure!(!Orgs::::contains_key(&org_id), Error::::OrganizationExists); + ensure!(!Orgs::::contains_key(org_id), Error::::OrganizationExists); Self::do_create_org(org_id, &org, treasury_id.clone(), deposit)?; Self::do_add_member(org_id, sender.clone(), MemberState::Active)?; @@ -381,7 +381,7 @@ pub mod pallet { fee_model: Option, membership_fee: Option, ) -> DispatchResult { - let mut org = Orgs::::get(&org_id).ok_or(Error::::OrganizationUnknown)?; + let mut org = Orgs::::get(org_id).ok_or(Error::::OrganizationUnknown)?; // Create entity like a council Self::ensure_root_or_prime(origin, org.prime.clone(), org.org_type.clone())?; @@ -393,11 +393,11 @@ pub mod pallet { if cid.is_some() { org.cid = cid.clone().unwrap(); }; if access_model.is_some() { org.access_model = access_model.clone().unwrap(); }; if org_type.is_some() { org.org_type = org_type.clone().unwrap(); }; - if member_limit.is_some() { org.member_limit = member_limit.clone().unwrap(); }; - if membership_fee.is_some() { org.membership_fee = membership_fee.clone(); }; + if member_limit.is_some() { org.member_limit = member_limit.unwrap(); }; + if membership_fee.is_some() { org.membership_fee = membership_fee; }; if prime_id.is_some() { let prime_id = prime_id.clone().unwrap(); - ensure!(MemberStates::::contains_key(&org_id, &prime_id), Error::::NotMember); + ensure!(MemberStates::::contains_key(org_id, &prime_id), Error::::NotMember); org.prime = prime_id; }; if fee_model.is_some() { @@ -408,7 +408,7 @@ pub mod pallet { org.fee_model = fee_model; }; - Orgs::::insert(&org_id, org); + Orgs::::insert(org_id, org); let block_number = frame_system::Pallet::::block_number(); Self::deposit_event(Event::OrgUpdated { @@ -432,10 +432,10 @@ pub mod pallet { /// Weight: `O(1)` #[pallet::weight(T::WeightInfo::enable_org())] pub fn enable_org(origin: OriginFor, org_id: T::Hash) -> DispatchResult { - let org = Orgs::::get(&org_id).ok_or(Error::::OrganizationUnknown)?; + let org = Orgs::::get(org_id).ok_or(Error::::OrganizationUnknown)?; Self::ensure_root_or_prime(origin, org.prime, org.org_type)?; - OrgStates::::insert(org_id.clone(), OrgState::Active); + OrgStates::::insert(org_id, OrgState::Active); Self::deposit_event(Event::OrgEnabled(org_id)); Ok(()) } @@ -453,10 +453,10 @@ pub mod pallet { /// Weight: `O(1)` #[pallet::weight(T::WeightInfo::disable_org())] pub fn disable_org(origin: OriginFor, org_id: T::Hash) -> DispatchResult { - let org = Orgs::::get(&org_id).ok_or(Error::::OrganizationUnknown)?; + let org = Orgs::::get(org_id).ok_or(Error::::OrganizationUnknown)?; Self::ensure_root_or_prime(origin, org.prime, org.org_type)?; - OrgStates::::insert(org_id.clone(), OrgState::Inactive); + OrgStates::::insert(org_id, OrgState::Inactive); Self::deposit_event(Event::OrgDisabled(org_id)); Ok(()) } @@ -476,10 +476,10 @@ pub mod pallet { org_id: T::Hash, who: T::AccountId ) -> DispatchResultWithPostInfo { - let org = Orgs::::get(&org_id).ok_or(Error::::OrganizationUnknown)?; + let org = Orgs::::get(org_id).ok_or(Error::::OrganizationUnknown)?; if let Ok(sender) = ensure_signed(origin.clone()) { ensure!( - sender == who || (org.access_model == AccessModel::Prime && sender == org.prime.clone()), + sender == who || (org.access_model == AccessModel::Prime && sender == org.prime), BadOrigin ); } @@ -514,10 +514,10 @@ pub mod pallet { who: T::AccountId, state: MemberState ) -> DispatchResult { - let org = Orgs::::get(&org_id).ok_or(Error::::OrganizationUnknown)?; - Self::ensure_membership_permissions(origin, who.clone(), org.prime.clone(), org.org_type.clone(), org.access_model.clone())?; + let org = Orgs::::get(org_id).ok_or(Error::::OrganizationUnknown)?; + Self::ensure_membership_permissions(origin, who.clone(), org.prime.clone(), org.org_type.clone(), org.access_model)?; - let current_member_state = MemberStates::::get(org_id.clone(), who.clone()); + let current_member_state = MemberStates::::get(org_id, who.clone()); if current_member_state == MemberState::Pending { Self::do_update_member(org_id, who.clone(), state)?; } @@ -535,9 +535,9 @@ pub mod pallet { /// Weight: `O(log n)` #[pallet::weight(T::WeightInfo::remove_member(T::MaxMembers::get()))] pub fn remove_member(origin: OriginFor, org_id: T::Hash, who: T::AccountId) -> DispatchResultWithPostInfo { - let org = Orgs::::get(&org_id).ok_or(Error::::OrganizationUnknown)?; + let org = Orgs::::get(org_id).ok_or(Error::::OrganizationUnknown)?; Self::ensure_membership_permissions(origin, who.clone(), org.prime.clone(), org.org_type.clone(), org.access_model.clone())?; - let member_count = Self::do_remove_member(org_id.clone(), who.clone())?; + let member_count = Self::do_remove_member(org_id, who.clone())?; if org.fee_model == FeeModel::Reserve { T::Currency::unreserve(org.gov_currency, &who, org.membership_fee.ok_or(Error::::MissingParameter)?); } @@ -567,7 +567,7 @@ pub mod pallet { beneficiary: T::AccountId, amount: T::Balance ) -> DispatchResult { - let org = Orgs::::get(&org_id).ok_or(Error::::OrganizationUnknown)?; + let org = Orgs::::get(org_id).ok_or(Error::::OrganizationUnknown)?; let treasury_id = OrgTreasury::::get(org_id).ok_or(Error::::TreasuryUnknown)?; Self::ensure_root_or_prime(origin, org.prime, org.org_type)?; @@ -587,17 +587,17 @@ impl Pallet { fn do_create_org(org_id: T::Hash, org: &Org, treasury_id: T::AccountId, deposit: T::Balance, ) -> Result<(), DispatchError> { let creator = org.creator.clone(); - let created_at = org.created.clone(); + let created_at = org.created; - OrgTreasury::::insert(&org_id, &treasury_id); - OrgStates::::insert(&org_id, OrgState::Active); + OrgTreasury::::insert(org_id, &treasury_id); + OrgStates::::insert(org_id, OrgState::Active); OrgCount::::set(org.index.checked_add(1).ok_or(Overflow)?); T::Currency::transfer( org.gov_currency, &creator, &treasury_id, deposit, ).map_err(|_| Error::::BalanceLow)?; - Orgs::::insert(&org_id, org); + Orgs::::insert(org_id, org); Self::deposit_event(Event::OrgCreated { org_id, creator, treasury_id, created_at, realm_index: 0 }); Ok(()) @@ -605,7 +605,7 @@ impl Pallet { fn do_add_member(org_id: T::Hash, who: T::AccountId, member_state: MemberState ) -> Result { - let mut members = Members::::get(&org_id); + let mut members = Members::::get(org_id); let location = members.binary_search(&who).err().ok_or(Error::::AlreadyMember)?; members .try_insert(location, who.clone()) @@ -613,9 +613,9 @@ impl Pallet { let members_count = members.len() as u32; // TODO: flatten Members and MemberStates - Members::::insert(&org_id, &members); - OrgMemberCount::::insert(&org_id, members_count); - MemberStates::::insert(&org_id, &who, member_state); + Members::::insert(org_id, &members); + OrgMemberCount::::insert(org_id, members_count); + MemberStates::::insert(org_id, &who, member_state); let block_number = frame_system::Pallet::::block_number(); Self::deposit_event(Event::MemberAdded { org_id, who, block_number }); @@ -628,21 +628,21 @@ impl Pallet { who: T::AccountId, state: MemberState ) -> Result<(), DispatchError> { - MemberStates::::set(&org_id, &who, state.clone()); + MemberStates::::set(org_id, &who, state.clone()); let block_number = frame_system::Pallet::::block_number(); Self::deposit_event(Event::MemberUpdated { org_id, who, state, block_number }); Ok(()) } fn do_remove_member(org_id: T::Hash, who: T::AccountId) -> Result { - let mut members = Members::::get(&org_id); + let mut members = Members::::get(org_id); let location = members.binary_search(&who).ok().ok_or(Error::::NotMember)?; members.remove(location); let members_count = members.len() as u32; - Members::::insert(&org_id, &members); - OrgMemberCount::::insert(&org_id, members_count); - MemberStates::::remove(&org_id, &who); + Members::::insert(org_id, &members); + OrgMemberCount::::insert(org_id, members_count); + MemberStates::::remove(org_id, &who); let block_number = frame_system::Pallet::::block_number(); Self::deposit_event(Event::MemberRemoved { org_id, who, block_number }); @@ -658,12 +658,12 @@ impl Pallet { match org.fee_model { FeeModel::NoFees => {}, FeeModel::Reserve => { - T::Currency::reserve(org.gov_currency, &who, org.membership_fee.unwrap() + T::Currency::reserve(org.gov_currency, who, org.membership_fee.unwrap() ).map_err(|_| Error::::BalanceLow)?; }, FeeModel::Transfer => { T::Currency::transfer( - org.gov_currency, &who, &treasury_id, org.membership_fee.unwrap() + org.gov_currency, who, treasury_id, org.membership_fee.unwrap() ).map_err(|_| Error::::BalanceLow)?; } }; @@ -679,13 +679,13 @@ impl Pallet { ) -> Result<(), BadOrigin> { match access_model { AccessModel::Open => { - return Ok(Self::ensure_root_or_self(origin, who.clone())?); + Self::ensure_root_or_self(origin, who) }, AccessModel::Prime => { - return Ok(Self::ensure_root_or_prime(origin, prime, org_type)?); + Self::ensure_root_or_prime(origin, prime, org_type) }, AccessModel::Voting => { - return Ok(Self::ensure_root_or_prime(origin, prime, org_type)?); + Self::ensure_root_or_prime(origin, prime, org_type) // TODO: add voting when membership voting is available // return Ok(Self::ensure_root_or_governance(origin)?); }, @@ -733,8 +733,10 @@ impl ControlTrait for Pallet { fn org_prime_account(org_id: &T::Hash) -> Option { if let Some(org) = Orgs::::get(org_id) { - return Some(org.prime) - } else { return None } + Some(org.prime) + } else { + None + } } fn org_treasury_account(org_id: &T::Hash) -> Option { OrgTreasury::::get(org_id) diff --git a/flow/src/lib.rs b/flow/src/lib.rs index 731428ee5..1c03512aa 100644 --- a/flow/src/lib.rs +++ b/flow/src/lib.rs @@ -291,13 +291,13 @@ pub mod pallet { fn on_initialize(block_number: T::BlockNumber) -> Weight { // Activate campaigns - let campaigns = CampaignsByBlock::::get(BlockType::Start, &block_number); + let campaigns = CampaignsByBlock::::get(BlockType::Start, block_number); for campaign_id in &campaigns { - let campaign_state = CampaignStates::::get(&campaign_id); + let campaign_state = CampaignStates::::get(campaign_id); if campaign_state != CampaignState::Created { continue; // Just a safety check, never should happen }; - CampaignStates::::insert(&campaign_id, CampaignState::Active); + CampaignStates::::insert(campaign_id, CampaignState::Active); Self::deposit_event(Event::::Activated { campaign_id: *campaign_id }); } @@ -314,7 +314,7 @@ pub mod pallet { for (i, c) in contributors.clone().into_iter().enumerate() { if processed >= T::MaxContributorsProcessing::get() { let not_finalized = BoundedVec::truncate_from(contributors[i..].into()); - CampaignFinalizationQueue::::insert(&campaign_id, + CampaignFinalizationQueue::::insert(campaign_id, (&campaign, &campaign_balance, &campaign_state, &treasury_id, not_finalized)); contributors_finalized = false; break @@ -324,7 +324,7 @@ pub mod pallet { } if contributors_finalized { Self::finalize_campaign(&campaign_state, campaign_id, &campaign, campaign_balance, treasury_id, block_number); - CampaignFinalizationQueue::::remove(&campaign_id); + CampaignFinalizationQueue::::remove(campaign_id); } } T::WeightInfo::on_initialize(processed, campaigns.len() as u32) @@ -346,13 +346,13 @@ pub mod pallet { } let treasury_id = maybe_treasury_id.unwrap(); let campaign_balance = CampaignBalance::::get(campaign_id); - let contributors = CampaignContribution::::iter_key_prefix(&campaign_id).collect::>(); - let state: CampaignState; - if campaign_balance >= campaign.cap { - state = CampaignState::Succeeded; - } else { - state = CampaignState::Failed; - } + let contributors = CampaignContribution::::iter_key_prefix(campaign_id).collect::>(); + let state = + if campaign_balance >= campaign.cap { + CampaignState::Succeeded + } else { + CampaignState::Failed + }; if contributors.len() as u32 > T::MaxCampaignContributors::get() { log::error!( target: "runtime::gamedao_flow", "MaxCampaignContributors exceeds limits {}, @@ -455,7 +455,7 @@ pub mod pallet { #[transactional] pub fn contribute(origin: OriginFor, campaign_id: T::Hash, contribution: T::Balance) -> DispatchResult { let sender = ensure_signed(origin)?; - let campaign = CampaignOf::::get(&campaign_id).ok_or(Error::::CampaignUnknown)?; + let campaign = CampaignOf::::get(campaign_id).ok_or(Error::::CampaignUnknown)?; let block_number = >::block_number(); ensure!(block_number < campaign.expiry, Error::::CampaignExpired); @@ -480,52 +480,52 @@ pub mod pallet { impl Pallet { fn mint_campaign(campaign_id: &T::Hash, campaign: Campaign) -> DispatchResult { - let campaign_state; - if campaign.start > >::block_number() { - campaign_state = CampaignState::Created; - } else { - campaign_state = CampaignState::Active; - } - CampaignStates::::insert(&campaign_id, campaign_state); + let campaign_state = + if campaign.start > >::block_number() { + CampaignState::Created + } else { + CampaignState::Active + }; + CampaignStates::::insert(campaign_id, campaign_state); CampaignsByBlock::::try_mutate( BlockType::Start, campaign.start, |campaigns| -> Result<(), DispatchError> { - campaigns.try_push(campaign_id.clone()).map_err(|_| Error::::CampaignsPerBlockExceeded)?; + campaigns.try_push(*campaign_id).map_err(|_| Error::::CampaignsPerBlockExceeded)?; Ok(()) } )?; CampaignsByBlock::::try_mutate( BlockType::Expiry, campaign.expiry, |campaigns| -> Result<(), DispatchError> { - campaigns.try_push(campaign_id.clone()).map_err(|_| Error::::CampaignsPerBlockExceeded)?; + campaigns.try_push(*campaign_id).map_err(|_| Error::::CampaignsPerBlockExceeded)?; Ok(()) } )?; - CampaignOf::::insert(&campaign_id, campaign.clone()); + CampaignOf::::insert(campaign_id, campaign.clone()); CampaignCount::::set(campaign.index.checked_add(1).ok_or(Overflow)?); let treasury_id = T::Control::org_treasury_account(&campaign.org_id).ok_or(Error::::TreasuryNotExist)?; T::Currency::reserve( - T::ProtocolTokenId::get(), &treasury_id, campaign.deposit.clone() + T::ProtocolTokenId::get(), &treasury_id, campaign.deposit ).map_err(|_| Error::::TreasuryBalanceLow)?; Ok(()) } fn create_contribution(sender: T::AccountId, campaign_id: T::Hash, contribution: T::Balance) -> DispatchResult { - let is_returning_contributor = CampaignContribution::::contains_key(&campaign_id, &sender); + let is_returning_contributor = CampaignContribution::::contains_key(campaign_id, &sender); if !is_returning_contributor { - let contributors = CampaignContributorsCount::::get(&campaign_id); - CampaignContributorsCount::::insert(campaign_id.clone(), contributors.checked_add(1).ok_or(Overflow)?); + let contributors = CampaignContributorsCount::::get(campaign_id); + CampaignContributorsCount::::insert(campaign_id, contributors.checked_add(1).ok_or(Overflow)?); } // Reserve contributed amount T::Currency::reserve(T::PaymentTokenId::get(), &sender, contribution).map_err(|_| Error::::BalanceLow)?; // Update contributor balance for campaign - let total_contribution = CampaignContribution::::get(&campaign_id, &sender); - CampaignContribution::::insert(&campaign_id, &sender, total_contribution + contribution); + let total_contribution = CampaignContribution::::get(campaign_id, &sender); + CampaignContribution::::insert(campaign_id, &sender, total_contribution + contribution); // Update campaign balance - let total_campaign_balance = CampaignBalance::::get(&campaign_id); - CampaignBalance::::insert(&campaign_id, total_campaign_balance + contribution); + let total_campaign_balance = CampaignBalance::::get(campaign_id); + CampaignBalance::::insert(campaign_id, total_campaign_balance + contribution); Ok(()) } @@ -536,19 +536,19 @@ impl Pallet { campaign_id: T::Hash, org_treasury: &T::AccountId, ) { - match campaign_state { - &CampaignState::Succeeded => { + match *campaign_state { + CampaignState::Succeeded => { let contributor_balance = CampaignContribution::::get(campaign_id, &contributor); let _transfer_amount = T::Currency::repatriate_reserved( T::PaymentTokenId::get(), &contributor, - &org_treasury, - contributor_balance.clone(), + org_treasury, + contributor_balance, BalanceStatus::Reserved ); }, - &CampaignState::Failed => { + CampaignState::Failed => { let contribution = CampaignContribution::::get(campaign_id, contributor.clone()); T::Currency::unreserve(T::PaymentTokenId::get(), &contributor, contribution); }, @@ -565,9 +565,9 @@ impl Pallet { org_treasury: T::AccountId, block_number: T::BlockNumber, ) { - match campaign_state { - &CampaignState::Succeeded => { - let commission = T::CampaignFee::get().mul_floor(campaign_balance.clone()); + match *campaign_state { + CampaignState::Succeeded => { + let commission = T::CampaignFee::get().mul_floor(campaign_balance); let _transfer_commission = T::Currency::repatriate_reserved( T::PaymentTokenId::get(), &org_treasury, @@ -578,12 +578,12 @@ impl Pallet { // Update campaign balance let updated_balance = campaign_balance - commission; CampaignBalance::::insert(campaign_id, updated_balance); - CampaignStates::::insert(&campaign_id, CampaignState::Succeeded); + CampaignStates::::insert(campaign_id, CampaignState::Succeeded); Self::deposit_event(Event::Succeeded { campaign_id, campaign_balance: updated_balance, block_number }); }, - &CampaignState::Failed => { + CampaignState::Failed => { // Unreserve Initial deposit T::Currency::unreserve(T::ProtocolTokenId::get(), &org_treasury, campaign.deposit); CampaignStates::::insert(campaign_id, CampaignState::Failed); @@ -607,9 +607,10 @@ impl FlowTrait for Pallet { fn campaign_owner(campaign_id: &T::Hash) -> Option { let campaign = CampaignOf::::get(campaign_id); if let Some(campaign) = campaign { - return Some(campaign.owner); - }; - return None; + Some(campaign.owner) + } else { + None + } } fn is_campaign_succeeded(campaign_id: &T::Hash) -> bool { CampaignStates::::get(campaign_id) == CampaignState::Succeeded diff --git a/flow/src/mock.rs b/flow/src/mock.rs index 0ab186cc7..560d9a1f0 100644 --- a/flow/src/mock.rs +++ b/flow/src/mock.rs @@ -163,7 +163,7 @@ parameter_types! { pub const MaxCampaignsPerBlock: u32 = 2; pub const MaxContributorsProcessing: u32 = 4; pub const MinContribution: Balance = 1 * DOLLARS; - pub CampaignFee: Permill = Permill::from_rational(1u32, 10u32); // 10% + pub CampaignFee: Permill = Permill::from_rational(1u32, 15u32); // 15% pub const GameDAOTreasury: AccountId = GAMEDAO_TREASURY; pub const CampaignDurationLimits: (BlockNumber, BlockNumber) = (1 * DAYS, 100 * DAYS); pub MinCampaignDeposit: Permill = Permill::from_rational(1u32, 10u32); // 10% diff --git a/flow/src/tests.rs b/flow/src/tests.rs index d417e52ce..049b77f0a 100644 --- a/flow/src/tests.rs +++ b/flow/src/tests.rs @@ -301,7 +301,7 @@ fn flow_contribute_success() { } /// Tests queue when two campaigns created -// #[test] +#[test] fn flow_on_finalize_campaign_succeess() { new_test_ext().execute_with(|| { let (org_id, treasury_id, tbalance) = create_org_treasury(); @@ -362,40 +362,41 @@ fn flow_on_finalize_campaign_succeess() { let batch_size: u128 = 4; assert_eq!(MaxContributorsProcessing::get(), batch_size as u32); - // --------- Block 1: process first 4 contributors --------- + // --------- Block 1: process 1 contributor from Campaign1 and revert Campaign1, process 3 contributors from Campaign2 --------- System::set_block_number(expiry + 1); Flow::on_initialize(expiry + 1); + // Campaign1 failed with 1 contributor, so we don't count his contribution assert_eq!( ::Currency::total_balance(PAYMENT_TOKEN_ID, &treasury_id), - batch_size * contribution + batch_size * contribution - contribution ); assert_eq!( ::Currency::free_balance(PAYMENT_TOKEN_ID, &treasury_id), 0 ); - // --------- Block 2: process next 4 contributors --------- + // --------- Block 2: process next 4 contributors from Campaign2 --------- System::set_block_number(expiry + 2); Flow::on_initialize(expiry + 2); assert_eq!( ::Currency::total_balance(PAYMENT_TOKEN_ID, &treasury_id), - 2 * batch_size * contribution + 2 * batch_size * contribution - contribution ); assert_eq!( ::Currency::free_balance(PAYMENT_TOKEN_ID, &treasury_id), 0 ); assert_eq!(CampaignStates::::get(&campaign_id), CampaignState::Active); - assert_eq!(CampaignStates::::get(&campaign_id_rev), CampaignState::Active); + assert_eq!(CampaignStates::::get(&campaign_id_rev), CampaignState::Failed); - // --------- Block 3: process last 2 contributors and finalize Campaign1, process 1 contributor and revert Campaign2 --------- + // --------- Block 3: process last 3 contributors from Campaign2 and finalize Campaign2 --------- System::set_block_number(expiry + 3); Flow::on_initialize(expiry + 3); // Campaign finalized: - let commission = ::CampaignFee::get().mul_floor(contribution * 10); + let commission = ::CampaignFee::get().mul_floor(contribution * total_contributors); // The balance was transfered and locked in the org treasury assert_eq!( ::Currency::total_balance(PAYMENT_TOKEN_ID, &treasury_id), @@ -420,22 +421,27 @@ fn flow_on_finalize_campaign_succeess() { assert_eq!(CampaignStates::::get(&campaign_id_rev), CampaignState::Failed); // Last event: - let events = System::events().into_iter().map(|evt| evt.event).collect::>(); + let events = System::events() + .into_iter() + .map(|evt| evt.event) + .filter_map(|e| if let Event::Flow(inner) = e { Some(inner) } else { None }) + .collect::>(); + assert_eq!( - events[events.len() - 4], - Event::Flow(crate::Event::Succeeded { - campaign_id, - campaign_balance: CampaignBalance::::get(campaign_id), - block_number: expiry + 3, - }) + events[events.len() - 2], + crate::Event::Failed { + campaign_id: campaign_id_rev, + campaign_balance: CampaignBalance::::get(campaign_id_rev), + block_number: expiry + 1, + } ); assert_eq!( events[events.len() - 1], - Event::Flow(crate::Event::Failed { - campaign_id: campaign_id_rev, - campaign_balance: CampaignBalance::::get(campaign_id_rev), + crate::Event::Succeeded { + campaign_id, + campaign_balance: CampaignBalance::::get(campaign_id), block_number: expiry + 3, - }) + } ); }); diff --git a/signal/src/lib.rs b/signal/src/lib.rs index 3085531c2..68f742e76 100644 --- a/signal/src/lib.rs +++ b/signal/src/lib.rs @@ -316,7 +316,7 @@ pub mod pallet { ensure!(proposer == campaign_owner, Error::::AuthorizationError); ensure!(T::Flow::is_campaign_succeeded(&c_id), Error::::CampaignUnsucceeded); - let used_balance = CampaignBalanceUsed::::get(&c_id); + let used_balance = CampaignBalanceUsed::::get(c_id); let total_balance = T::Flow::campaign_balance(&c_id); let remaining_balance = total_balance .checked_sub(&used_balance) @@ -334,12 +334,12 @@ pub mod pallet { // Create Proposal let index = ProposalCount::::get(); let proposal = types::Proposal { - index: index.clone(), title, cid, org_id, campaign_id, amount, deposit: proposal_deposit, + index, title, cid, org_id, campaign_id, amount, deposit: proposal_deposit, currency_id, beneficiary, proposal_type: proposal_type.clone(), start: starts, expiry, owner: proposer.clone(), slashing_rule: SlashingRule::Automated }; let proposal_hash = T::Hashing::hash_of(&proposal); - ensure!(!ProposalOf::::contains_key(&proposal_hash), Error::::ProposalExists); + ensure!(!ProposalOf::::contains_key(proposal_hash), Error::::ProposalExists); Self::create_proposal(&proposal_hash, proposal)?; Self::create_voting(&proposal_hash, &proposal_type, &index, &org_id, &campaign_id, quorum, majority, unit, scale); @@ -365,7 +365,7 @@ pub mod pallet { deposit: Option, ) -> DispatchResultWithPostInfo { let who = ensure_signed(origin)?; - let voting = ProposalVoting::::get(&proposal_id).ok_or(Error::::ProposalUnknown)?; + let voting = ProposalVoting::::get(proposal_id).ok_or(Error::::ProposalUnknown)?; // Deposit is required for token weighted voting only if voting.unit == Unit::Token && deposit.is_none() { @@ -374,7 +374,7 @@ pub mod pallet { return Err(Error::::WrongParameter)?; } - let proposal = ProposalOf::::get(&proposal_id).ok_or(Error::::ProposalUnknown)?; + let proposal = ProposalOf::::get(proposal_id).ok_or(Error::::ProposalUnknown)?; match proposal.proposal_type { ProposalType::General | ProposalType::Spending => { ensure!( @@ -394,7 +394,7 @@ pub mod pallet { // Ensure the Proposal is Active ensure!( - ProposalStates::::get(&proposal_id) == ProposalState::Active, + ProposalStates::::get(proposal_id) == ProposalState::Active, Error::::ProposalNotActive ); @@ -408,9 +408,9 @@ pub mod pallet { fn on_initialize(block_number: T::BlockNumber) -> Weight { - let proposals = ProposalsByBlock::::get(BlockType::Start, &block_number); + let proposals = ProposalsByBlock::::get(BlockType::Start, block_number); for proposal_id in &proposals { - let proposal_state = ProposalStates::::get(&proposal_id); + let proposal_state = ProposalStates::::get(proposal_id); if proposal_state != ProposalState::Created { continue; // Just a safety check, never should happen }; @@ -422,14 +422,14 @@ pub mod pallet { } fn on_finalize(block_number: T::BlockNumber) { - for proposal_id in &ProposalsByBlock::::get(BlockType::Expiry, &block_number) { + for proposal_id in &ProposalsByBlock::::get(BlockType::Expiry, block_number) { // Skip already finalized proposals (ex. if absolute majority was achieved) - let mut proposal_state = ProposalStates::::get(&proposal_id); + let mut proposal_state = ProposalStates::::get(proposal_id); if proposal_state != ProposalState::Active { continue; }; - let maybe_voting = ProposalVoting::::get(&proposal_id); - let proposal_exists = ProposalOf::::contains_key(&proposal_id); + let maybe_voting = ProposalVoting::::get(proposal_id); + let proposal_exists = ProposalOf::::contains_key(proposal_id); if maybe_voting.is_none() || !proposal_exists { log::error!(target: "runtime::gamedao_signal", "Proposal [{:?}] or voting [{:?}] is missing for proposal id: {:?}.", proposal_exists, maybe_voting.is_some(), proposal_id); @@ -440,7 +440,7 @@ pub mod pallet { // Get the final state based on Voting participation, quorum, majority proposal_state = Self::get_final_proposal_state(&voting); - if Self::finalize_proposal(&proposal_id, proposal_state, &voting).is_err() { + if Self::finalize_proposal(proposal_id, proposal_state, &voting).is_err() { log::error!(target: "runtime::gamedao_signal", "Failed to finalize a proposal {:?}.", proposal_id); }; } @@ -486,12 +486,12 @@ pub mod pallet { return Ok(()); }; if let Some(amount) = old_deposit { - let _ = T::Currency::unreserve(T::ProtocolTokenId::get(), &who, *amount); + let _ = T::Currency::unreserve(T::ProtocolTokenId::get(), who, *amount); } if let Some(amount) = deposit { - T::Currency::reserve(T::ProtocolTokenId::get(), &who, *amount).map_err(|_| Error::::BalanceLow)?; + T::Currency::reserve(T::ProtocolTokenId::get(), who, *amount).map_err(|_| Error::::BalanceLow)?; } - return Ok(()); + Ok(()) } pub fn try_finalize_proposal(voting: &Voting) -> Option { @@ -509,9 +509,9 @@ pub mod pallet { } // Everyone voted if voting.eligible == voting.participating { - return Some(Self::get_final_proposal_state(&voting)); + return Some(Self::get_final_proposal_state(voting)); } - return None; + None } pub fn do_vote( @@ -532,7 +532,7 @@ pub mod pallet { voting.nays.swap_remove(pos); } if position_yes.is_none() { - voting.ayes.try_push((who.clone(), power.clone(), deposit.clone())).map_err(|_| Error::::VoteLimitReached)?; + voting.ayes.try_push((who.clone(), power, deposit)).map_err(|_| Error::::VoteLimitReached)?; } else { return Err(Error::::DuplicateVote.into()) } @@ -542,7 +542,7 @@ pub mod pallet { voting.ayes.swap_remove(pos); } if position_no.is_none() { - voting.nays.try_push((who.clone(), power.clone(), deposit.clone())).map_err(|_| Error::::VoteLimitReached)?; + voting.nays.try_push((who.clone(), power, deposit)).map_err(|_| Error::::VoteLimitReached)?; } else { return Err(Error::::DuplicateVote.into()) } @@ -563,7 +563,7 @@ pub mod pallet { no: voting.no, }); - ProposalVoting::::insert(&proposal_id, &voting); + ProposalVoting::::insert(proposal_id, &voting); // For Absolute majority if more then 50% of members vote for one option, the proposal period ends earlier. if let Some(final_proposal_state) = Self::try_finalize_proposal(&voting) { @@ -577,12 +577,12 @@ pub mod pallet { proposal_id: &T::Hash, proposal: Proposal ) -> Result<(), DispatchError> { - let proposal_state; - if proposal.start > >::block_number() { - proposal_state = ProposalState::Created; - } else { - proposal_state = ProposalState::Active; - } + let proposal_state = + if proposal.start > >::block_number() { + ProposalState::Created + } else { + ProposalState::Active + }; T::Currency::reserve( T::ProtocolTokenId::get(), &proposal.owner, proposal.deposit ).map_err(|_| Error::::BalanceLow)?; @@ -596,13 +596,13 @@ pub mod pallet { ProposalsByBlock::::try_mutate( BlockType::Start, proposal.start, |proposals| -> Result<(), DispatchError> { - proposals.try_push(proposal_id.clone()).map_err(|_| Error::::TooManyProposals)?; + proposals.try_push(*proposal_id).map_err(|_| Error::::TooManyProposals)?; Ok(()) } )?; ProposalsByBlock::::try_mutate( BlockType::Expiry, proposal.expiry, |proposals| -> Result<(), DispatchError> { - proposals.try_push(proposal_id.clone()).map_err(|_| Error::::TooManyProposals)?; + proposals.try_push(*proposal_id).map_err(|_| Error::::TooManyProposals)?; Ok(()) } )?; @@ -634,7 +634,7 @@ pub mod pallet { eligible = T::Flow::campaign_contributors_count(&campaign_id.unwrap()).into(); } _ => { - eligible = T::Control::org_member_count(&org_id).into(); + eligible = T::Control::org_member_count(org_id).into(); } } } @@ -670,17 +670,17 @@ pub mod pallet { // Simple majority should be implemented for multiple options voting Majority::Relative | Majority::Simple => { if voting.yes > voting.no { - return ProposalState::Accepted; + ProposalState::Accepted } else { - return ProposalState::Rejected; + ProposalState::Rejected } } Majority::Absolute => { let majority_quorum = Permill::from_rational(1u32, 2u32); if voting.yes >= majority_quorum.mul_floor(voting.eligible) { - return ProposalState::Accepted; + ProposalState::Accepted } else { - return ProposalState::Rejected; + ProposalState::Rejected } } } @@ -694,9 +694,9 @@ pub mod pallet { let currency_id = proposal.currency_id.ok_or(Error::::ProposalInvalid)?; let treasury = T::Control::org_treasury_account(&proposal.org_id).ok_or(Error::::TreasuryUnknown)?; T::Currency::unreserve(currency_id, &treasury, amount); - let used_balance = CampaignBalanceUsed::::get(&campaign_id); - CampaignBalanceUsed::::insert(&campaign_id, used_balance + amount); - return Ok(ProposalState::Finalized); + let used_balance = CampaignBalanceUsed::::get(campaign_id); + CampaignBalanceUsed::::insert(campaign_id, used_balance + amount); + Ok(ProposalState::Finalized) } ProposalType::Spending => { let amount = proposal.amount.ok_or(Error::::ProposalInvalid)?; @@ -706,12 +706,12 @@ pub mod pallet { T::Currency::repatriate_reserved( currency_id, &treasury, - &beneficiary, + beneficiary, amount, BalanceStatus::Free)?; - return Ok(ProposalState::Finalized); + Ok(ProposalState::Finalized) } - _ => { return Ok(proposal_state) } + _ => { Ok(proposal_state) } } } @@ -747,23 +747,23 @@ pub mod pallet { fn emit_event(proposal_state: &ProposalState, proposal_id: &T::Hash) { match proposal_state { ProposalState::Accepted => { - Self::deposit_event(Event::::Accepted { proposal_id: proposal_id.clone() }); + Self::deposit_event(Event::::Accepted { proposal_id: *proposal_id }); } ProposalState::Rejected => { - Self::deposit_event(Event::::Rejected { proposal_id: proposal_id.clone() }); + Self::deposit_event(Event::::Rejected { proposal_id: *proposal_id }); } ProposalState::Expired => { - Self::deposit_event(Event::::Expired { proposal_id: proposal_id.clone() }); + Self::deposit_event(Event::::Expired { proposal_id: *proposal_id }); } ProposalState::Finalized => { - Self::deposit_event(Event::::Finalized { proposal_id: proposal_id.clone() }); + Self::deposit_event(Event::::Finalized { proposal_id: *proposal_id }); } _ => { } } } fn finalize_proposal(proposal_id: &T::Hash, mut proposal_state: ProposalState, voting: &Voting) -> DispatchResult { - let proposal = ProposalOf::::get(&proposal_id).ok_or(Error::::ProposalUnknown)?; + let proposal = ProposalOf::::get(proposal_id).ok_or(Error::::ProposalUnknown)?; match proposal_state { ProposalState::Accepted => { @@ -786,16 +786,16 @@ pub mod pallet { let currency_id = T::ProtocolTokenId::get(); // TODO: chain - &voting.ayes.iter().chain(&voting.nays.iter()) for (who, _, deposit) in &voting.ayes { - let _ = T::Currency::unreserve(currency_id, &who, deposit.ok_or(Error::::VotingInvalid)?); + let _ = T::Currency::unreserve(currency_id, who, deposit.ok_or(Error::::VotingInvalid)?); }; for (who, _, deposit) in &voting.nays { - let _ = T::Currency::unreserve(currency_id, &who, deposit.ok_or(Error::::VotingInvalid)?); + let _ = T::Currency::unreserve(currency_id, who, deposit.ok_or(Error::::VotingInvalid)?); }; } // Refund or slash proposal's deposit based on proposal state and majority of rejection - Self::process_proposal_deposit(&proposal, &voting, &proposal_state)?; + Self::process_proposal_deposit(&proposal, voting, &proposal_state)?; - Self::emit_event(&proposal_state, &proposal_id); + Self::emit_event(&proposal_state, proposal_id); ProposalStates::::insert(proposal_id, proposal_state); Ok(()) From 95fd935210eb1d7313babc27032c8519ff3ee1f7 Mon Sep 17 00:00:00 2001 From: FiberMan Date: Fri, 14 Apr 2023 12:23:29 +0200 Subject: [PATCH 43/49] Substrate upgrade 0.9.38 to 0.9.39 --- battlepass/Cargo.toml | 32 ++++++++++++++++---------------- control/Cargo.toml | 30 +++++++++++++++--------------- flow/Cargo.toml | 24 ++++++++++++------------ sense/Cargo.toml | 16 ++++++++-------- signal/Cargo.toml | 26 +++++++++++++------------- traits/Cargo.toml | 6 +++--- 6 files changed, 67 insertions(+), 67 deletions(-) diff --git a/battlepass/Cargo.toml b/battlepass/Cargo.toml index 123748318..d9f774823 100644 --- a/battlepass/Cargo.toml +++ b/battlepass/Cargo.toml @@ -16,31 +16,31 @@ description = "BattlePass pallet provides functionality to create, manage and pa serde = { version = "1.0.143", default-features = false } codec = { package = "parity-scale-codec", version = "3.2.2", default-features = false, features = ["derive"] } scale-info = { version = "2.1.1", default-features = false, features = ["derive"] } -sp-core = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } -sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } -sp-std = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } -sp-storage = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } -sp-io = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.38", default-features=false } -frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38", default-features = false } -frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38", default-features = false } -frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38", default-features = false, optional = true } +sp-core = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.39" } +sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.39" } +sp-std = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.39" } +sp-storage = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.39" } +sp-io = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39", default-features=false } +frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.39", default-features = false } +frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.39", default-features = false } +frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.39", default-features = false, optional = true } -pallet-uniques = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } +pallet-uniques = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.39" } -orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.38", default-features = false } +orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.39", default-features = false } gamedao-control = { package = "gamedao-control", path = "../control", default-features = false } gamedao-traits = { package = "gamedao-traits", path = "../traits", default-features = false } [dev-dependencies] -sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.38" } +sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.39" } codec = { package = "parity-scale-codec", version = "3.2.2", default-features = false, features = ["derive"] } -pallet-balances = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } -pallet-uniques = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } -orml-currencies = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.38", default-features = false } -orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.38", default-features = false } -orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.38", default-features = false } +pallet-balances = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.39" } +pallet-uniques = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.39" } +orml-currencies = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.39", default-features = false } +orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.39", default-features = false } +orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.39", default-features = false } [features] default = ['std'] diff --git a/control/Cargo.toml b/control/Cargo.toml index b1aa751a6..63d739f0b 100755 --- a/control/Cargo.toml +++ b/control/Cargo.toml @@ -20,29 +20,29 @@ serde = { version = "1.0.143", default-features = false } codec = { package = "parity-scale-codec", version = "3.2.2", default-features = false, features = ["derive"] } scale-info = { version = "2.1.1", default-features = false, features = ["derive"] } -sp-core = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } -sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } -sp-std = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } -sp-storage = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } +sp-core = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.39" } +sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.39" } +sp-std = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.39" } +sp-storage = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.39" } -frame-support = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } -frame-system = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } -frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38", default-features = false, optional = true } -sp-io = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.38", default-features=false } +frame-support = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.39" } +frame-system = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.39" } +frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.39", default-features = false, optional = true } +sp-io = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39", default-features=false } -pallet-balances = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } +pallet-balances = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.39" } -orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.38", default-features = false } +orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.39", default-features = false } gamedao-traits = { package = "gamedao-traits", path = "../traits", default-features = false } # tangram = { package = "module-tangram", path = "../../zero/tangram", default-features = false } [dev-dependencies] -sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.38" } -sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.38" } -pallet-balances = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } -orml-currencies = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.38", default-features = false } -orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.38", default-features = false } +sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.39" } +sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.39" } +pallet-balances = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.39" } +orml-currencies = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.39", default-features = false } +orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.39", default-features = false } [features] default = ["std"] diff --git a/flow/Cargo.toml b/flow/Cargo.toml index cfb515e01..ebb06b89b 100644 --- a/flow/Cargo.toml +++ b/flow/Cargo.toml @@ -17,25 +17,25 @@ repository = "https://github.com/gamedaoco/gamedao-protocol" serde = { version = "1.0.143", default-features = false } codec = { package = "parity-scale-codec", version = "3.2.2", default-features = false, features = ["derive"] } scale-info = { version = "2.1.1", default-features = false, features = ["derive"] } -sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38", default-features = false } -sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38", default-features = false } -frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38", default-features = false } -frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38", default-features = false } -frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38", default-features = false, optional = true } -sp-io = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.38", default-features=false } +sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.39", default-features = false } +sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.39", default-features = false } +frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.39", default-features = false } +frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.39", default-features = false } +frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.39", default-features = false, optional = true } +sp-io = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39", default-features=false } -orml-currencies = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.38", default-features = false } -orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.38", default-features = false } -orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.38", default-features = false } +orml-currencies = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.39", default-features = false } +orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.39", default-features = false } +orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.39", default-features = false } gamedao-traits = { package = "gamedao-traits", path = "../traits", default-features = false } gamedao-control = { package = "gamedao-control", path = "../control", default-features = false } [dev-dependencies] -sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.38" } +sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.39" } -pallet-timestamp = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } -pallet-balances = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } +pallet-timestamp = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.39" } +pallet-balances = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.39" } gamedao-control = { package = "gamedao-control", path = "../control", default-features = true } diff --git a/sense/Cargo.toml b/sense/Cargo.toml index 4d408d69c..020fc2849 100755 --- a/sense/Cargo.toml +++ b/sense/Cargo.toml @@ -23,16 +23,16 @@ categories = [ serde = { version = "1.0.143", default-features = false } codec = { package = "parity-scale-codec", version = "3.2.2", default-features = false, features = ["derive"] } scale-info = { version = "2.1.1", default-features = false, features = ["derive"] } -sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38", default-features = false } -sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38", default-features = false } -frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38", default-features = false } -frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38", default-features = false } -frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38", default-features = false, optional = true } +sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.39", default-features = false } +sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.39", default-features = false } +frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.39", default-features = false } +frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.39", default-features = false } +frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.39", default-features = false, optional = true } [dev-dependencies] -sp-io = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.38" } -sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.38" } -sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.38" } +sp-io = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.39" } +sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.39" } +sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.39" } [features] default = ["std"] diff --git a/signal/Cargo.toml b/signal/Cargo.toml index d5e1264c5..c560903ce 100644 --- a/signal/Cargo.toml +++ b/signal/Cargo.toml @@ -24,24 +24,24 @@ categories = [ serde = { version = "1.0.143", default-features = false } codec = { package = "parity-scale-codec", version = "3.2.2", default-features = false, features = ["derive"] } scale-info = { version = "2.1.1", default-features = false, features = ["derive"] } -sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38", default-features = false } -sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38", default-features = false } -frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38", default-features = false } -frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38", default-features = false } -frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38", default-features = false, optional = true } -orml-traits = { git = 'https://github.com/open-web3-stack/open-runtime-module-library', branch= "polkadot-v0.9.38", default-features = false } +sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.39", default-features = false } +sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.39", default-features = false } +frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.39", default-features = false } +frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.39", default-features = false } +frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.39", default-features = false, optional = true } +orml-traits = { git = 'https://github.com/open-web3-stack/open-runtime-module-library', branch= "polkadot-v0.9.39", default-features = false } gamedao-traits = { package = "gamedao-traits", path = "../traits", default-features = false } -sp-io = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.38", default-features=false } +sp-io = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39", default-features=false } [dev-dependencies] -sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.38" } -sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.38" } +sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.39" } +sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.39" } -pallet-balances = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } -pallet-timestamp = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } +pallet-balances = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.39" } +pallet-timestamp = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.39" } -orml-currencies = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.38", default-features = false } -orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.38", default-features = false } +orml-currencies = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.39", default-features = false } +orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.39", default-features = false } gamedao-control = { path = "../control", default-features = true } gamedao-flow = { path = "../flow", default-features = true } diff --git a/traits/Cargo.toml b/traits/Cargo.toml index 819182e95..e97967141 100644 --- a/traits/Cargo.toml +++ b/traits/Cargo.toml @@ -18,9 +18,9 @@ repository = "https://github.com/gamedaoco/gamedao-protocol" serde = { version = "1.0.143", default-features = false } codec = { package = "parity-scale-codec", version = "3.2.2", default-features = false, features = ["derive"] } scale-info = { version = "2.1.1", default-features = false, features = ["derive"] } -frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38", default-features = false } -frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38", default-features = false, optional = true } -sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38", default-features = false } +frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.39", default-features = false } +frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.39", default-features = false, optional = true } +sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.39", default-features = false } [features] default = ["std"] From e0d0bf2b8eee8eb7302d4230c6a67923be2c16c0 Mon Sep 17 00:00:00 2001 From: FiberMan Date: Fri, 14 Apr 2023 14:40:23 +0200 Subject: [PATCH 44/49] Substrate upgrade 0.9.39 to 0.9.40 --- battlepass/Cargo.toml | 32 ++++++++++++++++---------------- control/Cargo.toml | 30 +++++++++++++++--------------- flow/Cargo.toml | 24 ++++++++++++------------ sense/Cargo.toml | 16 ++++++++-------- signal/Cargo.toml | 26 +++++++++++++------------- traits/Cargo.toml | 6 +++--- 6 files changed, 67 insertions(+), 67 deletions(-) diff --git a/battlepass/Cargo.toml b/battlepass/Cargo.toml index d9f774823..0651ba995 100644 --- a/battlepass/Cargo.toml +++ b/battlepass/Cargo.toml @@ -16,31 +16,31 @@ description = "BattlePass pallet provides functionality to create, manage and pa serde = { version = "1.0.143", default-features = false } codec = { package = "parity-scale-codec", version = "3.2.2", default-features = false, features = ["derive"] } scale-info = { version = "2.1.1", default-features = false, features = ["derive"] } -sp-core = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.39" } -sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.39" } -sp-std = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.39" } -sp-storage = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.39" } -sp-io = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39", default-features=false } -frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.39", default-features = false } -frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.39", default-features = false } -frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.39", default-features = false, optional = true } +sp-core = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" } +sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" } +sp-std = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" } +sp-storage = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" } +sp-io = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.40", default-features=false } +frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40", default-features = false } +frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40", default-features = false } +frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40", default-features = false, optional = true } -pallet-uniques = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.39" } +pallet-uniques = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" } -orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.39", default-features = false } +orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.40", default-features = false } gamedao-control = { package = "gamedao-control", path = "../control", default-features = false } gamedao-traits = { package = "gamedao-traits", path = "../traits", default-features = false } [dev-dependencies] -sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.39" } +sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.40" } codec = { package = "parity-scale-codec", version = "3.2.2", default-features = false, features = ["derive"] } -pallet-balances = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.39" } -pallet-uniques = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.39" } -orml-currencies = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.39", default-features = false } -orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.39", default-features = false } -orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.39", default-features = false } +pallet-balances = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" } +pallet-uniques = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" } +orml-currencies = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.40", default-features = false } +orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.40", default-features = false } +orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.40", default-features = false } [features] default = ['std'] diff --git a/control/Cargo.toml b/control/Cargo.toml index 63d739f0b..1d298b978 100755 --- a/control/Cargo.toml +++ b/control/Cargo.toml @@ -20,29 +20,29 @@ serde = { version = "1.0.143", default-features = false } codec = { package = "parity-scale-codec", version = "3.2.2", default-features = false, features = ["derive"] } scale-info = { version = "2.1.1", default-features = false, features = ["derive"] } -sp-core = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.39" } -sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.39" } -sp-std = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.39" } -sp-storage = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.39" } +sp-core = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" } +sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" } +sp-std = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" } +sp-storage = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" } -frame-support = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.39" } -frame-system = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.39" } -frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.39", default-features = false, optional = true } -sp-io = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39", default-features=false } +frame-support = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" } +frame-system = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" } +frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40", default-features = false, optional = true } +sp-io = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.40", default-features=false } -pallet-balances = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.39" } +pallet-balances = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" } -orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.39", default-features = false } +orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.40", default-features = false } gamedao-traits = { package = "gamedao-traits", path = "../traits", default-features = false } # tangram = { package = "module-tangram", path = "../../zero/tangram", default-features = false } [dev-dependencies] -sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.39" } -sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.39" } -pallet-balances = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.39" } -orml-currencies = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.39", default-features = false } -orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.39", default-features = false } +sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.40" } +sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.40" } +pallet-balances = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" } +orml-currencies = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.40", default-features = false } +orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.40", default-features = false } [features] default = ["std"] diff --git a/flow/Cargo.toml b/flow/Cargo.toml index ebb06b89b..207f761fd 100644 --- a/flow/Cargo.toml +++ b/flow/Cargo.toml @@ -17,25 +17,25 @@ repository = "https://github.com/gamedaoco/gamedao-protocol" serde = { version = "1.0.143", default-features = false } codec = { package = "parity-scale-codec", version = "3.2.2", default-features = false, features = ["derive"] } scale-info = { version = "2.1.1", default-features = false, features = ["derive"] } -sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.39", default-features = false } -sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.39", default-features = false } -frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.39", default-features = false } -frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.39", default-features = false } -frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.39", default-features = false, optional = true } -sp-io = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39", default-features=false } +sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40", default-features = false } +sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40", default-features = false } +frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40", default-features = false } +frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40", default-features = false } +frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40", default-features = false, optional = true } +sp-io = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.40", default-features=false } -orml-currencies = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.39", default-features = false } -orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.39", default-features = false } -orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.39", default-features = false } +orml-currencies = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.40", default-features = false } +orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.40", default-features = false } +orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.40", default-features = false } gamedao-traits = { package = "gamedao-traits", path = "../traits", default-features = false } gamedao-control = { package = "gamedao-control", path = "../control", default-features = false } [dev-dependencies] -sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.39" } +sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.40" } -pallet-timestamp = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.39" } -pallet-balances = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.39" } +pallet-timestamp = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" } +pallet-balances = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" } gamedao-control = { package = "gamedao-control", path = "../control", default-features = true } diff --git a/sense/Cargo.toml b/sense/Cargo.toml index 020fc2849..30a2bf279 100755 --- a/sense/Cargo.toml +++ b/sense/Cargo.toml @@ -23,16 +23,16 @@ categories = [ serde = { version = "1.0.143", default-features = false } codec = { package = "parity-scale-codec", version = "3.2.2", default-features = false, features = ["derive"] } scale-info = { version = "2.1.1", default-features = false, features = ["derive"] } -sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.39", default-features = false } -sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.39", default-features = false } -frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.39", default-features = false } -frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.39", default-features = false } -frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.39", default-features = false, optional = true } +sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40", default-features = false } +sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40", default-features = false } +frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40", default-features = false } +frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40", default-features = false } +frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40", default-features = false, optional = true } [dev-dependencies] -sp-io = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.39" } -sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.39" } -sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.39" } +sp-io = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.40" } +sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.40" } +sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.40" } [features] default = ["std"] diff --git a/signal/Cargo.toml b/signal/Cargo.toml index c560903ce..dee315196 100644 --- a/signal/Cargo.toml +++ b/signal/Cargo.toml @@ -24,24 +24,24 @@ categories = [ serde = { version = "1.0.143", default-features = false } codec = { package = "parity-scale-codec", version = "3.2.2", default-features = false, features = ["derive"] } scale-info = { version = "2.1.1", default-features = false, features = ["derive"] } -sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.39", default-features = false } -sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.39", default-features = false } -frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.39", default-features = false } -frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.39", default-features = false } -frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.39", default-features = false, optional = true } -orml-traits = { git = 'https://github.com/open-web3-stack/open-runtime-module-library', branch= "polkadot-v0.9.39", default-features = false } +sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40", default-features = false } +sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40", default-features = false } +frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40", default-features = false } +frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40", default-features = false } +frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40", default-features = false, optional = true } +orml-traits = { git = 'https://github.com/open-web3-stack/open-runtime-module-library', branch= "polkadot-v0.9.40", default-features = false } gamedao-traits = { package = "gamedao-traits", path = "../traits", default-features = false } -sp-io = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39", default-features=false } +sp-io = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.40", default-features=false } [dev-dependencies] -sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.39" } -sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.39" } +sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.40" } +sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.40" } -pallet-balances = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.39" } -pallet-timestamp = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.39" } +pallet-balances = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" } +pallet-timestamp = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" } -orml-currencies = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.39", default-features = false } -orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.39", default-features = false } +orml-currencies = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.40", default-features = false } +orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.40", default-features = false } gamedao-control = { path = "../control", default-features = true } gamedao-flow = { path = "../flow", default-features = true } diff --git a/traits/Cargo.toml b/traits/Cargo.toml index e97967141..a04674e9d 100644 --- a/traits/Cargo.toml +++ b/traits/Cargo.toml @@ -18,9 +18,9 @@ repository = "https://github.com/gamedaoco/gamedao-protocol" serde = { version = "1.0.143", default-features = false } codec = { package = "parity-scale-codec", version = "3.2.2", default-features = false, features = ["derive"] } scale-info = { version = "2.1.1", default-features = false, features = ["derive"] } -frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.39", default-features = false } -frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.39", default-features = false, optional = true } -sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.39", default-features = false } +frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40", default-features = false } +frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40", default-features = false, optional = true } +sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40", default-features = false } [features] default = ["std"] From 73f29882ce0dbd6d4fd4c30ba934ccb572d80dee Mon Sep 17 00:00:00 2001 From: FiberMan Date: Sat, 15 Apr 2023 15:20:51 +0200 Subject: [PATCH 45/49] remove deprecated macros --- battlepass/src/lib.rs | 1 - control/src/lib.rs | 1 - flow/src/lib.rs | 1 - sense/src/lib.rs | 1 - signal/src/lib.rs | 1 - 5 files changed, 5 deletions(-) diff --git a/battlepass/src/lib.rs b/battlepass/src/lib.rs index 59b68d636..141bb7a83 100644 --- a/battlepass/src/lib.rs +++ b/battlepass/src/lib.rs @@ -56,7 +56,6 @@ pub mod pallet { use super::*; #[pallet::pallet] - #[pallet::generate_store(pub(super) trait Store)] pub struct Pallet(_); #[pallet::config] diff --git a/control/src/lib.rs b/control/src/lib.rs index fa13dd9f5..3f02ae55f 100644 --- a/control/src/lib.rs +++ b/control/src/lib.rs @@ -56,7 +56,6 @@ pub mod pallet { use frame_system::pallet_prelude::*; #[pallet::pallet] - #[pallet::generate_store(pub(super) trait Store)] pub struct Pallet(_); #[pallet::config] diff --git a/flow/src/lib.rs b/flow/src/lib.rs index 731428ee5..2b5d08303 100644 --- a/flow/src/lib.rs +++ b/flow/src/lib.rs @@ -77,7 +77,6 @@ pub mod pallet { use frame_system::pallet_prelude::*; #[pallet::pallet] - #[pallet::generate_store(pub(super) trait Store)] pub struct Pallet(_); #[pallet::config] diff --git a/sense/src/lib.rs b/sense/src/lib.rs index 0c8458175..f2bc6f80b 100644 --- a/sense/src/lib.rs +++ b/sense/src/lib.rs @@ -44,7 +44,6 @@ pub mod pallet { } #[pallet::pallet] - #[pallet::generate_store(pub(super) trait Store)] pub struct Pallet(_); /// Sense Entity of the account. diff --git a/signal/src/lib.rs b/signal/src/lib.rs index 3085531c2..6c00c2a45 100644 --- a/signal/src/lib.rs +++ b/signal/src/lib.rs @@ -70,7 +70,6 @@ pub mod pallet { use frame_system::pallet_prelude::*; #[pallet::pallet] - #[pallet::generate_store(pub(super) trait Store)] pub struct Pallet(_); #[pallet::config] From 0b6262a05499ce5929dd775e8743a15b74c4e811 Mon Sep 17 00:00:00 2001 From: Yura Date: Tue, 25 Apr 2023 16:18:14 +0200 Subject: [PATCH 46/49] replace pallet_uniques with pallet_nfts (#152) --- battlepass/Cargo.toml | 8 +- battlepass/src/benchmarking.rs | 2 +- battlepass/src/lib.rs | 65 ++-- battlepass/src/mock.rs | 36 ++- battlepass/src/tests.rs | 72 ++--- battlepass/src/weights.rs | 552 ++++++++++++++++++--------------- control/src/mock.rs | 2 - control/src/weights.rs | 148 ++++----- flow/src/mock.rs | 1 - flow/src/tests.rs | 2 +- flow/src/weights.rs | 76 ++--- sense/src/weights.rs | 28 +- signal/src/tests.rs | 28 +- signal/src/weights.rs | 68 ++-- 14 files changed, 564 insertions(+), 524 deletions(-) diff --git a/battlepass/Cargo.toml b/battlepass/Cargo.toml index 0651ba995..0015a9e11 100644 --- a/battlepass/Cargo.toml +++ b/battlepass/Cargo.toml @@ -25,7 +25,7 @@ frame-support = { git = "https://github.com/paritytech/substrate", branch = "pol frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40", default-features = false } frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40", default-features = false, optional = true } -pallet-uniques = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" } +pallet-nfts = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" } orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.40", default-features = false } @@ -37,7 +37,6 @@ sp-core = { git = "https://github.com/paritytech/substrate", default-features = codec = { package = "parity-scale-codec", version = "3.2.2", default-features = false, features = ["derive"] } pallet-balances = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" } -pallet-uniques = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" } orml-currencies = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.40", default-features = false } orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.40", default-features = false } orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.40", default-features = false } @@ -47,7 +46,8 @@ default = ['std'] runtime-benchmarks = [ "frame-benchmarking/runtime-benchmarks", "gamedao-traits/runtime-benchmarks", - "gamedao-control/runtime-benchmarks" + "gamedao-control/runtime-benchmarks", + "pallet-nfts/runtime-benchmarks" ] std = [ "serde/std", @@ -66,7 +66,7 @@ std = [ "orml-tokens/std", "orml-currencies/std", - "pallet-uniques/std", + "pallet-nfts/std", "gamedao-control/std", "gamedao-traits/std", diff --git a/battlepass/src/benchmarking.rs b/battlepass/src/benchmarking.rs index 356a17817..9262d872e 100644 --- a/battlepass/src/benchmarking.rs +++ b/battlepass/src/benchmarking.rs @@ -128,7 +128,7 @@ benchmarks! { verify { let collection_id = T::BattlepassHelper::collection(0); let item_id = T::BattlepassHelper::item(0); - assert!( as InspectEnumerable>::items(&collection_id).any(|x| x == item_id)); + assert!( as InspectEnumerable>::items(&collection_id).any(|x| x == item_id)); } activate_battlepass { diff --git a/battlepass/src/lib.rs b/battlepass/src/lib.rs index 67b9c91b5..a8dcdef1d 100644 --- a/battlepass/src/lib.rs +++ b/battlepass/src/lib.rs @@ -14,10 +14,11 @@ pub use pallet::*; use frame_support::{pallet_prelude::*, transactional, dispatch::RawOrigin}; -use frame_support::traits::tokens::nonfungibles::InspectEnumerable; +use frame_support::traits::tokens::nonfungibles_v2::InspectEnumerable; use frame_system::pallet_prelude::*; +use pallet_nfts::{CollectionConfig, CollectionSettings, MintSettings, NextCollectionId, Incrementable}; use sp_std::convert::TryInto; -use sp_runtime::traits::{AtLeast32BitUnsigned, Hash}; +use sp_runtime::traits::{AtLeast32BitUnsigned, Hash, StaticLookup}; use gamedao_traits::ControlTrait; #[cfg(feature = "runtime-benchmarks")] use gamedao_traits::ControlBenchmarkingTrait; @@ -59,7 +60,7 @@ pub mod pallet { pub struct Pallet(_); #[pallet::config] - pub trait Config: frame_system::Config + pallet_uniques::Config { + pub trait Config: frame_system::Config + pallet_nfts::Config { type RuntimeEvent: From> + IsType<::RuntimeEvent> + Into<::RuntimeEvent>; @@ -299,13 +300,6 @@ pub mod pallet { OptionQuery >; - /// A counter for created collections - /// - /// CollectionIndex: u32 - #[pallet::storage] - #[pallet::getter(fn get_collection_index)] - pub(super) type CollectionIndex = StorageValue<_, u32, ValueQuery>; - /// A counter for created NFTs /// /// NftIndex: u32 @@ -857,15 +851,6 @@ impl Pallet { levels.count() == 1 } - fn bump_collection_index() -> Result { - CollectionIndex::::try_mutate(|n| -> Result { - let id = *n; - ensure!(id != u32::max_value(), Error::::NoAvailableCollectionId); - *n += 1; - Ok(id) - }) - } - fn bump_nft_index() -> Result { NftIndex::::try_mutate(|n| -> Result { let id = *n; @@ -877,38 +862,34 @@ impl Pallet { fn create_collection(owner: T::AccountId, max: Option, cid: String) -> Result { let metadata = BoundedVec::truncate_from(cid.into()); - let collection_index = Self::bump_collection_index()?; - let collection_id = T::BattlepassHelper::collection(collection_index); + let collection = NextCollectionId::::get().unwrap_or(T::CollectionId::initial_value()); let origin = OriginFor::::from(RawOrigin::Signed(owner.clone())); + let config = CollectionConfig { + settings: CollectionSettings::all_enabled(), + max_supply: max, + mint_settings: MintSettings::default(), + }; - pallet_uniques::Pallet::::do_create_collection( - collection_id, + pallet_nfts::Pallet::::do_create_collection( + collection, owner.clone(), owner.clone(), + config, T::CollectionDeposit::get(), - false, - pallet_uniques::Event::Created { - collection: collection_id, - creator: owner.clone(), - owner, - }, + pallet_nfts::Event::Created { collection, creator: owner.clone(), owner }, )?; - pallet_uniques::Pallet::::set_collection_metadata(origin.clone(), collection_id, metadata, false)?; - pallet_uniques::Pallet::::freeze_collection(origin.clone(), collection_id)?; - if max.is_some() { - pallet_uniques::Pallet::::set_collection_max_supply(origin, collection_id, max.unwrap())?; - } - Ok(collection_id) + pallet_nfts::Pallet::::set_collection_metadata(origin, collection, metadata)?; + + Ok(collection) } - fn create_nft(creator: T::AccountId, for_who: T::AccountId, collection_id: T::CollectionId, nft_id: T::ItemId, metadata: BoundedVec::StringLimit>) -> DispatchResult { + fn create_nft(creator: T::AccountId, for_who: T::AccountId, collection_id: T::CollectionId, nft_id: T::ItemId, metadata: BoundedVec::StringLimit>) -> DispatchResult { let creator = OriginFor::::from(RawOrigin::Signed(creator)); + let for_who = T::Lookup::unlookup(for_who); - pallet_uniques::Pallet::::do_mint(collection_id, nft_id, for_who, |_details| { - Ok(()) - })?; - pallet_uniques::Pallet::::set_metadata(creator, collection_id, nft_id, metadata, false)?; + pallet_nfts::Pallet::::mint(creator.clone(), collection_id, nft_id, for_who, None)?; + pallet_nfts::Pallet::::set_metadata(creator, collection_id, nft_id, metadata)?; Ok(()) } @@ -917,7 +898,7 @@ impl Pallet { let origin = OriginFor::::from(RawOrigin::Signed(owner)); let metadata = BoundedVec::truncate_from(cid.into()); - pallet_uniques::Pallet::::set_collection_metadata(origin, collection_id, metadata, false)?; + pallet_nfts::Pallet::::set_collection_metadata(origin, collection_id, metadata)?; Ok(()) } @@ -1030,7 +1011,7 @@ impl Pallet { } fn is_battlepass_member(account: T::AccountId, bp_collection_id: T::CollectionId) -> bool { - let bp_owned_count = as InspectEnumerable>::owned_in_collection(&bp_collection_id, &account).count(); + let bp_owned_count = as InspectEnumerable>::owned_in_collection(&bp_collection_id, &account).count(); bp_owned_count > 0 } } diff --git a/battlepass/src/mock.rs b/battlepass/src/mock.rs index c4e7402b3..74e0f0f3c 100644 --- a/battlepass/src/mock.rs +++ b/battlepass/src/mock.rs @@ -6,12 +6,12 @@ use frame_support::{construct_runtime, parameter_types, PalletId, pallet_prelude::*, }; use frame_system; -use frame_system::{EnsureRoot, EnsureSigned}; +use pallet_nfts::PalletFeatures; use sp_std::convert::{TryFrom, TryInto}; use sp_core::H256; use sp_runtime::{ - testing::Header, - traits::{BlakeTwo256, IdentityLookup}, + testing::{Header, TestSignature}, + traits::{BlakeTwo256, IdentityLookup, Verify, IdentifyAccount}, }; use orml_traits::parameter_type_with_key; @@ -22,9 +22,11 @@ type Block = frame_system::mocking::MockBlock; pub type Hash = H256; pub type Balance = u128; pub type BlockNumber = u64; -pub type AccountId = u32; pub type CurrencyId = u32; pub type Amount = i128; +pub type Signature = TestSignature; +pub type AccountPublic = ::Signer; +pub type AccountId = ::AccountId; /// Constants: pub const MILLICENTS: Balance = 1_000_000_000; @@ -68,7 +70,7 @@ construct_runtime!( PalletBalances: pallet_balances::{Pallet, Call, Storage, Event}, Tokens: orml_tokens::{Pallet, Storage, Event, Config}, Currencies: orml_currencies::{Pallet, Call}, - Uniques: pallet_uniques::{Pallet, Call, Storage, Event}, + Nfts: pallet_nfts::{Pallet, Call, Storage, Event}, Control: gamedao_control, Battlepass: gamedao_battlepass::{Pallet, Call, Event, Storage}, } @@ -156,6 +158,12 @@ impl orml_currencies::Config for Test { } parameter_types! { + pub Features: PalletFeatures = PalletFeatures::all_enabled(); + pub const MaxAttributesPerCall: u32 = 10; + pub const ApprovalsLimit: u32 = 20; + pub const ItemAttributesApprovalsLimit: u32 = 20; + pub const MaxTips: u32 = 10; + pub const MaxDeadlineDuration: BlockNumber = 10000; pub CollectionDeposit: Balance = 0; pub ItemDeposit: Balance = 0; pub const KeyLimit: u32 = 32; // Max 32 bytes per key @@ -165,14 +173,12 @@ parameter_types! { pub const StringLimit: u32 = 64; } -impl pallet_uniques::Config for Test { +impl pallet_nfts::Config for Test { type RuntimeEvent = RuntimeEvent; type CollectionId = u32; type ItemId = u32; type Currency = PalletBalances; - type ForceOrigin = EnsureRoot; - type CreateOrigin = AsEnsureOriginWithArg>; - type Locker = (); + type ForceOrigin = frame_system::EnsureRoot; type CollectionDeposit = CollectionDeposit; type ItemDeposit = ItemDeposit; type MetadataDepositBase = MetadataDepositBase; @@ -181,7 +187,19 @@ impl pallet_uniques::Config for Test { type StringLimit = StringLimit; type KeyLimit = KeyLimit; type ValueLimit = ValueLimit; + type ApprovalsLimit = ApprovalsLimit; + type ItemAttributesApprovalsLimit = ItemAttributesApprovalsLimit; + type MaxTips = MaxTips; + type MaxDeadlineDuration = MaxDeadlineDuration; + type MaxAttributesPerCall = MaxAttributesPerCall; + type Features = Features; + type OffchainSignature = Signature; + type OffchainPublic = AccountPublic; type WeightInfo = (); + #[cfg(feature = "runtime-benchmarks")] + type Helper = (); + type CreateOrigin = AsEnsureOriginWithArg>; + type Locker = (); } parameter_types! { diff --git a/battlepass/src/tests.rs b/battlepass/src/tests.rs index 92be2e59a..b20d2ac33 100644 --- a/battlepass/src/tests.rs +++ b/battlepass/src/tests.rs @@ -1,12 +1,12 @@ #![cfg(test)] use frame_support::{assert_noop, assert_ok}; -use frame_support::traits::tokens::nonfungibles::{Inspect, InspectEnumerable, Mutate, Transfer}; +use frame_support::traits::tokens::nonfungibles_v2::{Inspect, InspectEnumerable, Transfer}; use sp_core::H256; use crate::mock::{ new_test_ext, RuntimeOrigin as Origin, Test, - Battlepass, Control, Uniques, + Battlepass, Control, Nfts, ALICE, BOB, EVA, TOM, BOT, PROTOCOL_TOKEN_ID, PAYMENT_TOKEN_ID, DOLLARS, AccountId, StringLimit, }; @@ -53,7 +53,7 @@ fn create_battlepass(org_id: H256) -> H256 { let creator = ALICE; let season = Battlepass::get_battlepass_info(&org_id).0 + 1; let price = 10; - let collection_id = CollectionIndex::::get(); + let collection_id = NextCollectionId::::get().unwrap_or(::CollectionId::initial_value()); assert_ok!( Battlepass::create_battlepass(Origin::signed(creator), org_id, string(), string(), price) @@ -157,7 +157,7 @@ fn create_battlepass_test(){ Battlepass::create_battlepass(Origin::signed(creator), org_id, string(), string(), 10) ); // Check if NFT collection created - assert_eq!(>::collections().any(|x| x == 0), true); + assert_eq!(>::collections().any(|x| x == 0), true); // Check if Battlepass created let battlepass = Battlepasses::::get(battlepass_id_1); assert_eq!(battlepass.is_some(), true); @@ -176,7 +176,7 @@ fn create_battlepass_test(){ Battlepass::create_battlepass(Origin::signed(creator), org_id, string(), string(), 10) ); // Check if NFT collection created - assert_eq!(>::collections().any(|x| x == 1), true); + assert_eq!(>::collections().any(|x| x == 1), true); // Check if Battlepass created let battlepass = Battlepasses::::get(battlepass_id_2); assert_eq!(battlepass.is_some(), true); @@ -198,7 +198,7 @@ fn create_battlepass_test(){ Battlepass::create_battlepass(Origin::signed(creator), org_id, string(), string(), 10) ); // Check if NFT collection created - assert_eq!(>::collections().any(|x| x == 1), true); + assert_eq!(>::collections().any(|x| x == 1), true); // Check if Battlepass created let battlepass = Battlepasses::::get(battlepass_id_3); assert_eq!(battlepass.is_some(), true); @@ -280,7 +280,7 @@ fn update_battlepass_test() { assert_eq!(updated.cid, new_cid.clone()); assert_eq!(updated.price, new_price.clone()); // Check if Collection metadata updated - assert_eq!(>::collection_attribute(&0, &[]), Some(new_cid.clone().into())); + assert_eq!(>::collection_attribute(&0, &[]), Some(new_cid.clone().into())); // Should update some fields in battlepass assert_ok!( @@ -470,7 +470,7 @@ fn claim_battlepass_test() { let creator = ALICE; let not_creator = BOB; let not_creator_2 = TOM; - let not_creator_3 = 22u32; + let not_creator_3 = 22u64; let not_member = EVA; let not_member_2 = 40; add_member(org_id, not_creator); @@ -530,9 +530,9 @@ fn claim_battlepass_test() { Battlepass::claim_battlepass(Origin::signed(creator), battlepass_id, not_creator, None) ); // Check if NFT minted - assert_eq!(>::items(&0).any(|x| x == 0) , true); + assert_eq!(>::items(&0).any(|x| x == 0) , true); // Check NFT metadata - assert_eq!(>::attribute(&0, &0, &[]), Some(string().into())); + assert_eq!(>::attribute(&0, &0, &[]), Some(string().into())); // Should not claim if it was already claimed assert_noop!( @@ -542,16 +542,13 @@ fn claim_battlepass_test() { // Should claim again after transferring Battlepass NFT to someone else assert_ok!( - Uniques::thaw_collection(Origin::signed(creator), 0) - ); - assert_ok!( - >::transfer(&0, &0, ¬_member_2) + >::transfer(&0, &0, ¬_member_2) ); assert_ok!( Battlepass::claim_battlepass(Origin::signed(creator), battlepass_id, not_creator, None) ); // Check if NFT minted - assert_eq!(>::items(&0).any(|x| x == 1) , true); + assert_eq!(>::items(&0).any(|x| x == 1) , true); // Should not claim if user received Battlepass NFT from someone else assert_noop!( @@ -567,16 +564,16 @@ fn claim_battlepass_test() { Battlepass::claim_battlepass(Origin::signed(BOT), battlepass_id, not_creator_3, None) ); // Check if NFT minted - assert_eq!(>::items(&0).any(|x| x == 2) , true); + assert_eq!(>::items(&0).any(|x| x == 2) , true); // Should claim for accounts outside of org assert_ok!( Battlepass::claim_battlepass(Origin::signed(creator), battlepass_id, not_member, Some(cid.clone())), ); // Check if NFT minted - assert_eq!(>::items(&0).any(|x| x == 3) , true); + assert_eq!(>::items(&0).any(|x| x == 3) , true); // Check NFT metadata - assert_eq!(>::attribute(&0, &3, &[]), Some(cid.into())); + assert_eq!(>::attribute(&0, &3, &[]), Some(cid.into())); // Should not claim Battlepass in ENDED state assert_ok!( @@ -730,9 +727,9 @@ fn create_reward_test() { Battlepass::create_reward(Origin::signed(creator), battlepass_id, string(), string(), Some(1), 1, true) ); // Check if NFT collection created - assert_eq!(>::collections().any(|x| x == 1) , true); + assert_eq!(>::collections().any(|x| x == 1) , true); // Check if collection owner is a Prime - assert_eq!(>::collection_owner(&1).unwrap(), creator); + assert_eq!(>::collection_owner(&1).unwrap(), creator); // Check if Reward created let reward_id = get_reward_hash(battlepass_id, 1, true, 1); let reward = Rewards::::get(reward_id); @@ -749,9 +746,9 @@ fn create_reward_test() { Battlepass::create_reward(Origin::signed(creator), battlepass_id, string(), string(), Some(1), 1, true) ); // Check if NFT collection created - assert_eq!(>::collections().any(|x| x == 2) , true); + assert_eq!(>::collections().any(|x| x == 2) , true); // Check if collection owner is a Prime - assert_eq!(>::collection_owner(&2).unwrap(), creator); + assert_eq!(>::collection_owner(&2).unwrap(), creator); // Check if Reward created let reward_id = get_reward_hash(battlepass_id, 1, true, 2); let reward = Rewards::::get(reward_id); @@ -774,9 +771,9 @@ fn create_reward_test() { Battlepass::create_reward(Origin::signed(BOT), battlepass_id, string(), string(), Some(1), 1, true) ); // Check if NFT collection created - assert_eq!(>::collections().any(|x| x == 3) , true); + assert_eq!(>::collections().any(|x| x == 3) , true); // Check if collection owner is a Prime - assert_eq!(>::collection_owner(&3).unwrap(), creator); + assert_eq!(>::collection_owner(&3).unwrap(), creator); // Check if Reward created let reward_id = get_reward_hash(battlepass_id, 1, true, 3); let reward = Rewards::::get(reward_id); @@ -877,7 +874,7 @@ fn update_reward_test() { assert_eq!(updated.cid, new_cid.clone()); assert_eq!(updated.transferable, new_transferable.clone()); // Check if Collection metadata updated - assert_eq!(>::collection_attribute(&1, &[]), Some(new_cid.clone().into())); + assert_eq!(>::collection_attribute(&1, &[]), Some(new_cid.clone().into())); // Should update some fields in Reward assert_ok!( @@ -1108,7 +1105,7 @@ fn claim_reward_test() { Battlepass::claim_battlepass(Origin::signed(creator), battlepass_id, not_creator, None) ); assert_ok!( - >::burn(&0, &0, None) + Nfts::do_burn(0, 0, |_details| { Ok(()) }) ); assert_noop!( Battlepass::claim_reward(Origin::signed(creator), reward_id, not_creator, None), @@ -1120,10 +1117,7 @@ fn claim_reward_test() { Battlepass::claim_battlepass(Origin::signed(creator), battlepass_id, creator, None) ); assert_ok!( - Uniques::thaw_collection(Origin::signed(creator), 0) - ); - assert_ok!( - >::transfer(&0, &1, ¬_member_2) + >::transfer(&0, &1, ¬_member_2) ); assert_noop!( Battlepass::claim_reward(Origin::signed(creator), reward_id, creator, None), @@ -1152,9 +1146,9 @@ fn claim_reward_test() { // Check if Reward claimed assert_eq!(ClaimedRewards::::contains_key(reward_id, not_creator_3), true); // Check if NFT minted - assert_eq!(>::items(&3).any(|x| x == 3) , true); + assert_eq!(>::items(&3).any(|x| x == 3) , true); // Check NFT metadata - assert_eq!(>::attribute(&3, &3, &[]), Some(string().into())); + assert_eq!(>::attribute(&3, &3, &[]), Some(string().into())); // Should not claim if Reward already claimed assert_noop!( @@ -1171,7 +1165,7 @@ fn claim_reward_test() { ); assert_noop!( Battlepass::claim_reward(Origin::signed(creator), reward_id, not_creator_4, None), - pallet_uniques::Error::::MaxSupplyReached + pallet_nfts::Error::::MaxSupplyReached ); // Should claim Reward by Bot @@ -1185,9 +1179,9 @@ fn claim_reward_test() { // Check if Reward claimed assert_eq!(ClaimedRewards::::contains_key(reward_id, not_creator_4), true); // Check if NFT minted - assert_eq!(>::items(&4).any(|x| x == 5) , true); + assert_eq!(>::items(&4).any(|x| x == 5) , true); // Check NFT metadata - assert_eq!(>::attribute(&4, &5, &[]), Some(string().into())); + assert_eq!(>::attribute(&4, &5, &[]), Some(string().into())); // Should claim Reward for non-member let reward_id = create_reward(battlepass_id); @@ -1203,9 +1197,9 @@ fn claim_reward_test() { // Check if Reward claimed assert_eq!(ClaimedRewards::::contains_key(reward_id, not_member), true); // Check if NFT minted - assert_eq!(>::items(&5).any(|x| x == 7) , true); + assert_eq!(>::items(&5).any(|x| x == 7) , true); // Check NFT metadata - assert_eq!(>::attribute(&5, &7, &[]), Some(cid.into())); + assert_eq!(>::attribute(&5, &7, &[]), Some(cid.into())); // Should claim Reward after receiving Battlepass NFT from elsewhere let reward_id = create_reward(battlepass_id); @@ -1218,9 +1212,9 @@ fn claim_reward_test() { // Check if Reward claimed assert_eq!(ClaimedRewards::::contains_key(reward_id, not_member_2), true); // Check if NFT minted - assert_eq!(>::items(&6).any(|x| x == 8) , true); + assert_eq!(>::items(&6).any(|x| x == 8) , true); // Check NFT metadata - assert_eq!(>::attribute(&6, &8, &[]), Some(string().into())); + assert_eq!(>::attribute(&6, &8, &[]), Some(string().into())); // Should not claim if Battlepass state is ENDED assert_ok!( diff --git a/battlepass/src/weights.rs b/battlepass/src/weights.rs index ab3d4e8a3..c06cb083d 100644 --- a/battlepass/src/weights.rs +++ b/battlepass/src/weights.rs @@ -2,12 +2,12 @@ //! Autogenerated weights for gamedao_battlepass //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-03-16, STEPS: `20`, REPEAT: `10`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2023-04-19, STEPS: `20`, REPEAT: `10`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: None, DB CACHE: 1024 // Executed Command: -// ./target/release/subzero-dev +// ./target/release/subzero // benchmark // pallet // --execution=wasm @@ -51,29 +51,33 @@ impl WeightInfo for SubstrateWeight { /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) /// Storage: Battlepass BattlepassInfoByOrg (r:1 w:1) /// Proof: Battlepass BattlepassInfoByOrg (max_values: None, max_size: Some(118), added: 2593, mode: MaxEncodedLen) - /// Storage: Battlepass CollectionIndex (r:1 w:1) - /// Proof: Battlepass CollectionIndex (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: Uniques ClassMetadataOf (r:1 w:1) - /// Proof: Uniques ClassMetadataOf (max_values: None, max_size: Some(167), added: 2642, mode: MaxEncodedLen) - /// Storage: Uniques ClassAccount (r:0 w:1) - /// Proof: Uniques ClassAccount (max_values: None, max_size: Some(68), added: 2543, mode: MaxEncodedLen) + /// Storage: Nfts NextCollectionId (r:1 w:1) + /// Proof: Nfts NextCollectionId (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) + /// Storage: Nfts Collection (r:1 w:1) + /// Proof: Nfts Collection (max_values: None, max_size: Some(84), added: 2559, mode: MaxEncodedLen) + /// Storage: Nfts CollectionMetadataOf (r:1 w:1) + /// Proof: Nfts CollectionMetadataOf (max_values: None, max_size: Some(102), added: 2577, mode: MaxEncodedLen) /// Storage: Battlepass BattlepassStates (r:0 w:1) /// Proof: Battlepass BattlepassStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) /// Storage: Battlepass Battlepasses (r:0 w:1) - /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(382), added: 2857, mode: MaxEncodedLen) + /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(254), added: 2729, mode: MaxEncodedLen) + /// Storage: Nfts CollectionRoleOf (r:0 w:1) + /// Proof: Nfts CollectionRoleOf (max_values: None, max_size: Some(69), added: 2544, mode: MaxEncodedLen) + /// Storage: Nfts CollectionConfigOf (r:0 w:1) + /// Proof: Nfts CollectionConfigOf (max_values: None, max_size: Some(73), added: 2548, mode: MaxEncodedLen) + /// Storage: Nfts CollectionAccount (r:0 w:1) + /// Proof: Nfts CollectionAccount (max_values: None, max_size: Some(68), added: 2543, mode: MaxEncodedLen) fn create_battlepass() -> Weight { // Proof Size summary in bytes: - // Measured: `597` - // Estimated: `13676` - // Minimum execution time: 86_000 nanoseconds. - Weight::from_parts(88_000_000, 13676) + // Measured: `566` + // Estimated: `19457` + // Minimum execution time: 102_000 nanoseconds. + Weight::from_parts(106_000_000, 19457) .saturating_add(T::DbWeight::get().reads(6_u64)) - .saturating_add(T::DbWeight::get().writes(7_u64)) + .saturating_add(T::DbWeight::get().writes(9_u64)) } /// Storage: Battlepass Battlepasses (r:1 w:1) - /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(382), added: 2857, mode: MaxEncodedLen) + /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(254), added: 2729, mode: MaxEncodedLen) /// Storage: Battlepass BattlepassStates (r:1 w:0) /// Proof: Battlepass BattlepassStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) /// Storage: Control OrgStates (r:1 w:0) @@ -82,21 +86,25 @@ impl WeightInfo for SubstrateWeight { /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) /// Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) /// Proof: Battlepass BattlepassInfoByOrg (max_values: None, max_size: Some(118), added: 2593, mode: MaxEncodedLen) - /// Storage: Uniques Class (r:1 w:1) - /// Proof: Uniques Class (max_values: None, max_size: Some(178), added: 2653, mode: MaxEncodedLen) - /// Storage: Uniques ClassMetadataOf (r:1 w:1) - /// Proof: Uniques ClassMetadataOf (max_values: None, max_size: Some(167), added: 2642, mode: MaxEncodedLen) + /// Storage: Nfts CollectionRoleOf (r:1 w:0) + /// Proof: Nfts CollectionRoleOf (max_values: None, max_size: Some(69), added: 2544, mode: MaxEncodedLen) + /// Storage: Nfts CollectionConfigOf (r:1 w:0) + /// Proof: Nfts CollectionConfigOf (max_values: None, max_size: Some(73), added: 2548, mode: MaxEncodedLen) + /// Storage: Nfts Collection (r:1 w:1) + /// Proof: Nfts Collection (max_values: None, max_size: Some(84), added: 2559, mode: MaxEncodedLen) + /// Storage: Nfts CollectionMetadataOf (r:1 w:1) + /// Proof: Nfts CollectionMetadataOf (max_values: None, max_size: Some(102), added: 2577, mode: MaxEncodedLen) fn update_battlepass() -> Weight { // Proof Size summary in bytes: - // Measured: `1354` - // Estimated: `18558` - // Minimum execution time: 67_000 nanoseconds. - Weight::from_parts(71_000_000, 18558) - .saturating_add(T::DbWeight::get().reads(7_u64)) + // Measured: `1286` + // Estimated: `32273` + // Minimum execution time: 79_000 nanoseconds. + Weight::from_parts(80_000_000, 32273) + .saturating_add(T::DbWeight::get().reads(9_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } /// Storage: Battlepass Battlepasses (r:1 w:0) - /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(382), added: 2857, mode: MaxEncodedLen) + /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(254), added: 2729, mode: MaxEncodedLen) /// Storage: Battlepass BattlepassStates (r:1 w:0) /// Proof: Battlepass BattlepassStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) /// Storage: Control OrgStates (r:1 w:0) @@ -105,29 +113,33 @@ impl WeightInfo for SubstrateWeight { /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) /// Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) /// Proof: Battlepass BattlepassInfoByOrg (max_values: None, max_size: Some(118), added: 2593, mode: MaxEncodedLen) - /// Storage: Uniques Account (r:1 w:1) - /// Proof: Uniques Account (max_values: None, max_size: Some(88), added: 2563, mode: MaxEncodedLen) + /// Storage: Nfts Account (r:1 w:1) + /// Proof: Nfts Account (max_values: None, max_size: Some(88), added: 2563, mode: MaxEncodedLen) /// Storage: Battlepass NftIndex (r:1 w:1) /// Proof: Battlepass NftIndex (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: Uniques Asset (r:1 w:1) - /// Proof: Uniques Asset (max_values: None, max_size: Some(122), added: 2597, mode: MaxEncodedLen) - /// Storage: Uniques Class (r:1 w:1) - /// Proof: Uniques Class (max_values: None, max_size: Some(178), added: 2653, 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(187), added: 2662, mode: MaxEncodedLen) + /// Storage: Nfts CollectionConfigOf (r:1 w:0) + /// Proof: Nfts CollectionConfigOf (max_values: None, max_size: Some(73), added: 2548, mode: MaxEncodedLen) + /// Storage: Nfts Item (r:1 w:1) + /// Proof: Nfts Item (max_values: None, max_size: Some(861), added: 3336, mode: MaxEncodedLen) + /// Storage: Nfts Collection (r:1 w:1) + /// Proof: Nfts Collection (max_values: None, max_size: Some(84), added: 2559, mode: MaxEncodedLen) + /// Storage: Nfts CollectionRoleOf (r:1 w:0) + /// Proof: Nfts CollectionRoleOf (max_values: None, max_size: Some(69), added: 2544, mode: MaxEncodedLen) + /// Storage: Nfts ItemConfigOf (r:1 w:1) + /// Proof: Nfts ItemConfigOf (max_values: None, max_size: Some(48), added: 2523, mode: MaxEncodedLen) + /// Storage: Nfts ItemMetadataOf (r:1 w:1) + /// Proof: Nfts ItemMetadataOf (max_values: None, max_size: Some(155), added: 2630, mode: MaxEncodedLen) fn claim_battlepass() -> Weight { // Proof Size summary in bytes: - // Measured: `1359` - // Estimated: `26736` - // Minimum execution time: 98_000 nanoseconds. - Weight::from_parts(99_000_000, 26736) - .saturating_add(T::DbWeight::get().reads(11_u64)) - .saturating_add(T::DbWeight::get().writes(5_u64)) + // Measured: `1349` + // Estimated: `45207` + // Minimum execution time: 135_000 nanoseconds. + Weight::from_parts(141_000_000, 45207) + .saturating_add(T::DbWeight::get().reads(13_u64)) + .saturating_add(T::DbWeight::get().writes(6_u64)) } /// Storage: Battlepass Battlepasses (r:1 w:0) - /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(382), added: 2857, mode: MaxEncodedLen) + /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(254), added: 2729, mode: MaxEncodedLen) /// Storage: Battlepass BattlepassStates (r:1 w:1) /// Proof: Battlepass BattlepassStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) /// Storage: Control OrgStates (r:1 w:0) @@ -138,15 +150,15 @@ impl WeightInfo for SubstrateWeight { /// Proof: Battlepass BattlepassInfoByOrg (max_values: None, max_size: Some(118), added: 2593, mode: MaxEncodedLen) fn activate_battlepass() -> Weight { // Proof Size summary in bytes: - // Measured: `880` - // Estimated: `13263` - // Minimum execution time: 35_000 nanoseconds. - Weight::from_parts(36_000_000, 13263) + // Measured: `794` + // Estimated: `18085` + // Minimum execution time: 41_000 nanoseconds. + Weight::from_parts(41_000_000, 18085) .saturating_add(T::DbWeight::get().reads(5_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } /// Storage: Battlepass Battlepasses (r:1 w:0) - /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(382), added: 2857, mode: MaxEncodedLen) + /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(254), added: 2729, mode: MaxEncodedLen) /// Storage: Battlepass BattlepassStates (r:1 w:1) /// Proof: Battlepass BattlepassStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) /// Storage: Control Orgs (r:1 w:0) @@ -155,15 +167,15 @@ impl WeightInfo for SubstrateWeight { /// Proof: Battlepass BattlepassInfoByOrg (max_values: None, max_size: Some(118), added: 2593, mode: MaxEncodedLen) fn conclude_battlepass() -> Weight { // Proof Size summary in bytes: - // Measured: `907` - // Estimated: `10739` - // Minimum execution time: 31_000 nanoseconds. - Weight::from_parts(32_000_000, 10739) + // Measured: `790` + // Estimated: `14571` + // Minimum execution time: 35_000 nanoseconds. + Weight::from_parts(38_000_000, 14571) .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } /// Storage: Battlepass Battlepasses (r:1 w:0) - /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(382), added: 2857, mode: MaxEncodedLen) + /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(254), added: 2729, mode: MaxEncodedLen) /// Storage: Battlepass BattlepassStates (r:1 w:0) /// Proof: Battlepass BattlepassStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) /// Storage: Control OrgStates (r:1 w:0) @@ -172,21 +184,21 @@ impl WeightInfo for SubstrateWeight { /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) /// Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) /// Proof: Battlepass BattlepassInfoByOrg (max_values: None, max_size: Some(118), added: 2593, mode: MaxEncodedLen) - /// Storage: Uniques Account (r:2 w:0) - /// Proof: Uniques Account (max_values: None, max_size: Some(88), added: 2563, mode: MaxEncodedLen) + /// Storage: Nfts Account (r:2 w:0) + /// Proof: Nfts Account (max_values: None, max_size: Some(88), added: 2563, mode: MaxEncodedLen) /// Storage: Battlepass Points (r:0 w:1) /// Proof: Battlepass Points (max_values: None, max_size: Some(100), added: 2575, mode: MaxEncodedLen) fn set_points() -> Weight { // Proof Size summary in bytes: - // Measured: `1417` - // Estimated: `18389` - // Minimum execution time: 43_000 nanoseconds. - Weight::from_parts(45_000_000, 18389) + // Measured: `1423` + // Estimated: `24201` + // Minimum execution time: 44_000 nanoseconds. + Weight::from_parts(45_000_000, 24201) .saturating_add(T::DbWeight::get().reads(7_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } /// Storage: Battlepass Battlepasses (r:1 w:0) - /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(382), added: 2857, mode: MaxEncodedLen) + /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(254), added: 2729, mode: MaxEncodedLen) /// Storage: Battlepass BattlepassStates (r:1 w:0) /// Proof: Battlepass BattlepassStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) /// Storage: Control OrgStates (r:1 w:0) @@ -195,35 +207,37 @@ impl WeightInfo for SubstrateWeight { /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) /// Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) /// Proof: Battlepass BattlepassInfoByOrg (max_values: None, max_size: Some(118), added: 2593, mode: MaxEncodedLen) - /// Storage: Battlepass CollectionIndex (r:1 w:1) - /// Proof: Battlepass CollectionIndex (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: Uniques ClassMetadataOf (r:1 w:1) - /// Proof: Uniques ClassMetadataOf (max_values: None, max_size: Some(167), added: 2642, mode: MaxEncodedLen) - /// Storage: Uniques CollectionMaxSupply (r:1 w:1) - /// Proof: Uniques CollectionMaxSupply (max_values: None, max_size: Some(24), added: 2499, mode: MaxEncodedLen) - /// Storage: Uniques ClassAccount (r:0 w:1) - /// Proof: Uniques ClassAccount (max_values: None, max_size: Some(68), added: 2543, mode: MaxEncodedLen) + /// Storage: Nfts NextCollectionId (r:1 w:1) + /// Proof: Nfts NextCollectionId (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) + /// Storage: Nfts Collection (r:1 w:1) + /// Proof: Nfts Collection (max_values: None, max_size: Some(84), added: 2559, mode: MaxEncodedLen) + /// Storage: Nfts CollectionMetadataOf (r:1 w:1) + /// Proof: Nfts CollectionMetadataOf (max_values: None, max_size: Some(102), added: 2577, mode: MaxEncodedLen) /// Storage: Battlepass Rewards (r:0 w:1) - /// Proof: Battlepass Rewards (max_values: None, max_size: Some(346), added: 2821, mode: MaxEncodedLen) + /// Proof: Battlepass Rewards (max_values: None, max_size: Some(218), added: 2693, mode: MaxEncodedLen) /// Storage: Battlepass RewardStates (r:0 w:1) /// Proof: Battlepass RewardStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Nfts CollectionRoleOf (r:0 w:1) + /// Proof: Nfts CollectionRoleOf (max_values: None, max_size: Some(69), added: 2544, mode: MaxEncodedLen) + /// Storage: Nfts CollectionConfigOf (r:0 w:1) + /// Proof: Nfts CollectionConfigOf (max_values: None, max_size: Some(73), added: 2548, mode: MaxEncodedLen) + /// Storage: Nfts CollectionAccount (r:0 w:1) + /// Proof: Nfts CollectionAccount (max_values: None, max_size: Some(68), added: 2543, mode: MaxEncodedLen) fn create_reward() -> Weight { // Proof Size summary in bytes: - // Measured: `1226` - // Estimated: `21556` - // Minimum execution time: 110_000 nanoseconds. - Weight::from_parts(111_000_000, 21556) - .saturating_add(T::DbWeight::get().reads(9_u64)) - .saturating_add(T::DbWeight::get().writes(7_u64)) + // Measured: `1197` + // Estimated: `26690` + // Minimum execution time: 112_000 nanoseconds. + Weight::from_parts(113_000_000, 26690) + .saturating_add(T::DbWeight::get().reads(8_u64)) + .saturating_add(T::DbWeight::get().writes(8_u64)) } /// Storage: Battlepass Rewards (r:1 w:1) - /// Proof: Battlepass Rewards (max_values: None, max_size: Some(346), added: 2821, mode: MaxEncodedLen) + /// Proof: Battlepass Rewards (max_values: None, max_size: Some(218), added: 2693, mode: MaxEncodedLen) /// Storage: Battlepass RewardStates (r:1 w:0) /// Proof: Battlepass RewardStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) /// Storage: Battlepass Battlepasses (r:1 w:0) - /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(382), added: 2857, mode: MaxEncodedLen) + /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(254), added: 2729, mode: MaxEncodedLen) /// Storage: Battlepass BattlepassStates (r:1 w:0) /// Proof: Battlepass BattlepassStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) /// Storage: Control OrgStates (r:1 w:0) @@ -232,46 +246,50 @@ impl WeightInfo for SubstrateWeight { /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) /// Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) /// Proof: Battlepass BattlepassInfoByOrg (max_values: None, max_size: Some(118), added: 2593, mode: MaxEncodedLen) - /// Storage: Uniques Class (r:1 w:1) - /// Proof: Uniques Class (max_values: None, max_size: Some(178), added: 2653, mode: MaxEncodedLen) - /// Storage: Uniques ClassMetadataOf (r:1 w:1) - /// Proof: Uniques ClassMetadataOf (max_values: None, max_size: Some(167), added: 2642, mode: MaxEncodedLen) + /// Storage: Nfts CollectionRoleOf (r:1 w:0) + /// Proof: Nfts CollectionRoleOf (max_values: None, max_size: Some(69), added: 2544, mode: MaxEncodedLen) + /// Storage: Nfts CollectionConfigOf (r:1 w:0) + /// Proof: Nfts CollectionConfigOf (max_values: None, max_size: Some(73), added: 2548, mode: MaxEncodedLen) + /// Storage: Nfts Collection (r:1 w:1) + /// Proof: Nfts Collection (max_values: None, max_size: Some(84), added: 2559, mode: MaxEncodedLen) + /// Storage: Nfts CollectionMetadataOf (r:1 w:1) + /// Proof: Nfts CollectionMetadataOf (max_values: None, max_size: Some(102), added: 2577, mode: MaxEncodedLen) fn update_reward() -> Weight { // Proof Size summary in bytes: - // Measured: `1685` - // Estimated: `23903` - // Minimum execution time: 73_000 nanoseconds. - Weight::from_parts(75_000_000, 23903) - .saturating_add(T::DbWeight::get().reads(9_u64)) + // Measured: `1632` + // Estimated: `39470` + // Minimum execution time: 90_000 nanoseconds. + Weight::from_parts(93_000_000, 39470) + .saturating_add(T::DbWeight::get().reads(11_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } /// Storage: Battlepass Rewards (r:1 w:0) - /// Proof: Battlepass Rewards (max_values: None, max_size: Some(346), added: 2821, mode: MaxEncodedLen) + /// Proof: Battlepass Rewards (max_values: None, max_size: Some(218), added: 2693, mode: MaxEncodedLen) /// Storage: Battlepass RewardStates (r:1 w:1) /// Proof: Battlepass RewardStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) /// Storage: Battlepass Battlepasses (r:1 w:0) - /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(382), added: 2857, mode: MaxEncodedLen) + /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(254), added: 2729, mode: MaxEncodedLen) /// Storage: Control Orgs (r:1 w:0) /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) /// Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) /// Proof: Battlepass BattlepassInfoByOrg (max_values: None, max_size: Some(118), added: 2593, mode: MaxEncodedLen) fn disable_reward() -> Weight { // Proof Size summary in bytes: - // Measured: `1094` - // Estimated: `13560` - // Minimum execution time: 33_000 nanoseconds. - Weight::from_parts(37_000_000, 13560) + // Measured: `946` + // Estimated: `18254` + // Minimum execution time: 37_000 nanoseconds. + Weight::from_parts(38_000_000, 18254) .saturating_add(T::DbWeight::get().reads(5_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } /// Storage: Battlepass Rewards (r:1 w:0) - /// Proof: Battlepass Rewards (max_values: None, max_size: Some(346), added: 2821, mode: MaxEncodedLen) + /// Proof: Battlepass Rewards (max_values: None, max_size: Some(218), added: 2693, mode: MaxEncodedLen) /// Storage: Battlepass RewardStates (r:1 w:0) /// Proof: Battlepass RewardStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) /// Storage: Battlepass ClaimedRewards (r:1 w:1) /// Proof: Battlepass ClaimedRewards (max_values: None, max_size: Some(100), added: 2575, mode: MaxEncodedLen) /// Storage: Battlepass Battlepasses (r:1 w:0) - /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(382), added: 2857, mode: MaxEncodedLen) + /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(254), added: 2729, mode: MaxEncodedLen) /// Storage: Battlepass BattlepassStates (r:1 w:0) /// Proof: Battlepass BattlepassStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) /// Storage: Control OrgStates (r:1 w:0) @@ -280,33 +298,37 @@ impl WeightInfo for SubstrateWeight { /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) /// Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) /// Proof: Battlepass BattlepassInfoByOrg (max_values: None, max_size: Some(118), added: 2593, mode: MaxEncodedLen) - /// Storage: Uniques Account (r:2 w:1) - /// Proof: Uniques Account (max_values: None, max_size: Some(88), added: 2563, mode: MaxEncodedLen) + /// Storage: Nfts Account (r:2 w:1) + /// Proof: Nfts Account (max_values: None, max_size: Some(88), added: 2563, mode: MaxEncodedLen) /// Storage: Battlepass Points (r:1 w:0) /// Proof: Battlepass Points (max_values: None, max_size: Some(100), added: 2575, mode: MaxEncodedLen) /// Storage: Battlepass Levels (r:2 w:0) /// Proof: Battlepass Levels (max_values: None, max_size: Some(69), added: 2544, mode: MaxEncodedLen) /// Storage: Battlepass NftIndex (r:1 w:1) /// Proof: Battlepass NftIndex (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: Uniques Asset (r:1 w:1) - /// Proof: Uniques Asset (max_values: None, max_size: Some(122), added: 2597, mode: MaxEncodedLen) - /// Storage: Uniques Class (r:1 w:1) - /// Proof: Uniques Class (max_values: None, max_size: Some(178), added: 2653, 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(187), added: 2662, mode: MaxEncodedLen) + /// Storage: Nfts CollectionConfigOf (r:1 w:0) + /// Proof: Nfts CollectionConfigOf (max_values: None, max_size: Some(73), added: 2548, mode: MaxEncodedLen) + /// Storage: Nfts Item (r:1 w:1) + /// Proof: Nfts Item (max_values: None, max_size: Some(861), added: 3336, mode: MaxEncodedLen) + /// Storage: Nfts Collection (r:1 w:1) + /// Proof: Nfts Collection (max_values: None, max_size: Some(84), added: 2559, mode: MaxEncodedLen) + /// Storage: Nfts CollectionRoleOf (r:1 w:0) + /// Proof: Nfts CollectionRoleOf (max_values: None, max_size: Some(69), added: 2544, mode: MaxEncodedLen) + /// Storage: Nfts ItemConfigOf (r:1 w:1) + /// Proof: Nfts ItemConfigOf (max_values: None, max_size: Some(48), added: 2523, mode: MaxEncodedLen) + /// Storage: Nfts ItemMetadataOf (r:1 w:1) + /// Proof: Nfts ItemMetadataOf (max_values: None, max_size: Some(155), added: 2630, mode: MaxEncodedLen) fn claim_reward() -> Weight { // Proof Size summary in bytes: - // Measured: `2192` - // Estimated: `44882` - // Minimum execution time: 135_000 nanoseconds. - Weight::from_parts(145_000_000, 44882) - .saturating_add(T::DbWeight::get().reads(18_u64)) - .saturating_add(T::DbWeight::get().writes(6_u64)) + // Measured: `2281` + // Estimated: `68175` + // Minimum execution time: 163_000 nanoseconds. + Weight::from_parts(166_000_000, 68175) + .saturating_add(T::DbWeight::get().reads(20_u64)) + .saturating_add(T::DbWeight::get().writes(7_u64)) } /// Storage: Battlepass Battlepasses (r:1 w:0) - /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(382), added: 2857, mode: MaxEncodedLen) + /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(254), added: 2729, mode: MaxEncodedLen) /// Storage: Battlepass BattlepassStates (r:1 w:0) /// Proof: Battlepass BattlepassStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) /// Storage: Control OrgStates (r:1 w:0) @@ -319,15 +341,15 @@ impl WeightInfo for SubstrateWeight { /// Proof: Battlepass Levels (max_values: None, max_size: Some(69), added: 2544, mode: MaxEncodedLen) fn add_level() -> Weight { // Proof Size summary in bytes: - // Measured: `945` - // Estimated: `13263` - // Minimum execution time: 32_000 nanoseconds. - Weight::from_parts(32_000_000, 13263) + // Measured: `828` + // Estimated: `18085` + // Minimum execution time: 35_000 nanoseconds. + Weight::from_parts(36_000_000, 18085) .saturating_add(T::DbWeight::get().reads(5_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } /// Storage: Battlepass Battlepasses (r:1 w:0) - /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(382), added: 2857, mode: MaxEncodedLen) + /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(254), added: 2729, mode: MaxEncodedLen) /// Storage: Battlepass BattlepassStates (r:1 w:0) /// Proof: Battlepass BattlepassStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) /// Storage: Control OrgStates (r:1 w:0) @@ -340,15 +362,15 @@ impl WeightInfo for SubstrateWeight { /// Proof: Battlepass Levels (max_values: None, max_size: Some(69), added: 2544, mode: MaxEncodedLen) fn remove_level() -> Weight { // Proof Size summary in bytes: - // Measured: `1038` - // Estimated: `15807` - // Minimum execution time: 36_000 nanoseconds. - Weight::from_parts(37_000_000, 15807) + // Measured: `922` + // Estimated: `21619` + // Minimum execution time: 40_000 nanoseconds. + Weight::from_parts(41_000_000, 21619) .saturating_add(T::DbWeight::get().reads(6_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } /// Storage: Battlepass Battlepasses (r:1 w:0) - /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(382), added: 2857, mode: MaxEncodedLen) + /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(254), added: 2729, mode: MaxEncodedLen) /// Storage: Battlepass BattlepassStates (r:1 w:0) /// Proof: Battlepass BattlepassStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) /// Storage: Control OrgStates (r:1 w:0) @@ -359,10 +381,10 @@ impl WeightInfo for SubstrateWeight { /// Proof: Battlepass BattlepassInfoByOrg (max_values: None, max_size: Some(118), added: 2593, mode: MaxEncodedLen) fn add_bot() -> Weight { // Proof Size summary in bytes: - // Measured: `880` - // Estimated: `13263` - // Minimum execution time: 31_000 nanoseconds. - Weight::from_parts(32_000_000, 13263) + // Measured: `794` + // Estimated: `18085` + // Minimum execution time: 32_000 nanoseconds. + Weight::from_parts(33_000_000, 18085) .saturating_add(T::DbWeight::get().reads(5_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -376,29 +398,33 @@ impl WeightInfo for () { /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) /// Storage: Battlepass BattlepassInfoByOrg (r:1 w:1) /// Proof: Battlepass BattlepassInfoByOrg (max_values: None, max_size: Some(118), added: 2593, mode: MaxEncodedLen) - /// Storage: Battlepass CollectionIndex (r:1 w:1) - /// Proof: Battlepass CollectionIndex (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: Uniques ClassMetadataOf (r:1 w:1) - /// Proof: Uniques ClassMetadataOf (max_values: None, max_size: Some(167), added: 2642, mode: MaxEncodedLen) - /// Storage: Uniques ClassAccount (r:0 w:1) - /// Proof: Uniques ClassAccount (max_values: None, max_size: Some(68), added: 2543, mode: MaxEncodedLen) + /// Storage: Nfts NextCollectionId (r:1 w:1) + /// Proof: Nfts NextCollectionId (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) + /// Storage: Nfts Collection (r:1 w:1) + /// Proof: Nfts Collection (max_values: None, max_size: Some(84), added: 2559, mode: MaxEncodedLen) + /// Storage: Nfts CollectionMetadataOf (r:1 w:1) + /// Proof: Nfts CollectionMetadataOf (max_values: None, max_size: Some(102), added: 2577, mode: MaxEncodedLen) /// Storage: Battlepass BattlepassStates (r:0 w:1) /// Proof: Battlepass BattlepassStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) /// Storage: Battlepass Battlepasses (r:0 w:1) - /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(382), added: 2857, mode: MaxEncodedLen) + /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(254), added: 2729, mode: MaxEncodedLen) + /// Storage: Nfts CollectionRoleOf (r:0 w:1) + /// Proof: Nfts CollectionRoleOf (max_values: None, max_size: Some(69), added: 2544, mode: MaxEncodedLen) + /// Storage: Nfts CollectionConfigOf (r:0 w:1) + /// Proof: Nfts CollectionConfigOf (max_values: None, max_size: Some(73), added: 2548, mode: MaxEncodedLen) + /// Storage: Nfts CollectionAccount (r:0 w:1) + /// Proof: Nfts CollectionAccount (max_values: None, max_size: Some(68), added: 2543, mode: MaxEncodedLen) fn create_battlepass() -> Weight { // Proof Size summary in bytes: - // Measured: `597` - // Estimated: `13676` - // Minimum execution time: 86_000 nanoseconds. - Weight::from_parts(88_000_000, 13676) + // Measured: `566` + // Estimated: `19457` + // Minimum execution time: 102_000 nanoseconds. + Weight::from_parts(106_000_000, 19457) .saturating_add(RocksDbWeight::get().reads(6_u64)) - .saturating_add(RocksDbWeight::get().writes(7_u64)) + .saturating_add(RocksDbWeight::get().writes(9_u64)) } /// Storage: Battlepass Battlepasses (r:1 w:1) - /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(382), added: 2857, mode: MaxEncodedLen) + /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(254), added: 2729, mode: MaxEncodedLen) /// Storage: Battlepass BattlepassStates (r:1 w:0) /// Proof: Battlepass BattlepassStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) /// Storage: Control OrgStates (r:1 w:0) @@ -407,21 +433,25 @@ impl WeightInfo for () { /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) /// Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) /// Proof: Battlepass BattlepassInfoByOrg (max_values: None, max_size: Some(118), added: 2593, mode: MaxEncodedLen) - /// Storage: Uniques Class (r:1 w:1) - /// Proof: Uniques Class (max_values: None, max_size: Some(178), added: 2653, mode: MaxEncodedLen) - /// Storage: Uniques ClassMetadataOf (r:1 w:1) - /// Proof: Uniques ClassMetadataOf (max_values: None, max_size: Some(167), added: 2642, mode: MaxEncodedLen) + /// Storage: Nfts CollectionRoleOf (r:1 w:0) + /// Proof: Nfts CollectionRoleOf (max_values: None, max_size: Some(69), added: 2544, mode: MaxEncodedLen) + /// Storage: Nfts CollectionConfigOf (r:1 w:0) + /// Proof: Nfts CollectionConfigOf (max_values: None, max_size: Some(73), added: 2548, mode: MaxEncodedLen) + /// Storage: Nfts Collection (r:1 w:1) + /// Proof: Nfts Collection (max_values: None, max_size: Some(84), added: 2559, mode: MaxEncodedLen) + /// Storage: Nfts CollectionMetadataOf (r:1 w:1) + /// Proof: Nfts CollectionMetadataOf (max_values: None, max_size: Some(102), added: 2577, mode: MaxEncodedLen) fn update_battlepass() -> Weight { // Proof Size summary in bytes: - // Measured: `1354` - // Estimated: `18558` - // Minimum execution time: 67_000 nanoseconds. - Weight::from_parts(71_000_000, 18558) - .saturating_add(RocksDbWeight::get().reads(7_u64)) + // Measured: `1286` + // Estimated: `32273` + // Minimum execution time: 79_000 nanoseconds. + Weight::from_parts(80_000_000, 32273) + .saturating_add(RocksDbWeight::get().reads(9_u64)) .saturating_add(RocksDbWeight::get().writes(3_u64)) } /// Storage: Battlepass Battlepasses (r:1 w:0) - /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(382), added: 2857, mode: MaxEncodedLen) + /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(254), added: 2729, mode: MaxEncodedLen) /// Storage: Battlepass BattlepassStates (r:1 w:0) /// Proof: Battlepass BattlepassStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) /// Storage: Control OrgStates (r:1 w:0) @@ -430,29 +460,33 @@ impl WeightInfo for () { /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) /// Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) /// Proof: Battlepass BattlepassInfoByOrg (max_values: None, max_size: Some(118), added: 2593, mode: MaxEncodedLen) - /// Storage: Uniques Account (r:1 w:1) - /// Proof: Uniques Account (max_values: None, max_size: Some(88), added: 2563, mode: MaxEncodedLen) + /// Storage: Nfts Account (r:1 w:1) + /// Proof: Nfts Account (max_values: None, max_size: Some(88), added: 2563, mode: MaxEncodedLen) /// Storage: Battlepass NftIndex (r:1 w:1) /// Proof: Battlepass NftIndex (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: Uniques Asset (r:1 w:1) - /// Proof: Uniques Asset (max_values: None, max_size: Some(122), added: 2597, mode: MaxEncodedLen) - /// Storage: Uniques Class (r:1 w:1) - /// Proof: Uniques Class (max_values: None, max_size: Some(178), added: 2653, 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(187), added: 2662, mode: MaxEncodedLen) + /// Storage: Nfts CollectionConfigOf (r:1 w:0) + /// Proof: Nfts CollectionConfigOf (max_values: None, max_size: Some(73), added: 2548, mode: MaxEncodedLen) + /// Storage: Nfts Item (r:1 w:1) + /// Proof: Nfts Item (max_values: None, max_size: Some(861), added: 3336, mode: MaxEncodedLen) + /// Storage: Nfts Collection (r:1 w:1) + /// Proof: Nfts Collection (max_values: None, max_size: Some(84), added: 2559, mode: MaxEncodedLen) + /// Storage: Nfts CollectionRoleOf (r:1 w:0) + /// Proof: Nfts CollectionRoleOf (max_values: None, max_size: Some(69), added: 2544, mode: MaxEncodedLen) + /// Storage: Nfts ItemConfigOf (r:1 w:1) + /// Proof: Nfts ItemConfigOf (max_values: None, max_size: Some(48), added: 2523, mode: MaxEncodedLen) + /// Storage: Nfts ItemMetadataOf (r:1 w:1) + /// Proof: Nfts ItemMetadataOf (max_values: None, max_size: Some(155), added: 2630, mode: MaxEncodedLen) fn claim_battlepass() -> Weight { // Proof Size summary in bytes: - // Measured: `1359` - // Estimated: `26736` - // Minimum execution time: 98_000 nanoseconds. - Weight::from_parts(99_000_000, 26736) - .saturating_add(RocksDbWeight::get().reads(11_u64)) - .saturating_add(RocksDbWeight::get().writes(5_u64)) + // Measured: `1349` + // Estimated: `45207` + // Minimum execution time: 135_000 nanoseconds. + Weight::from_parts(141_000_000, 45207) + .saturating_add(RocksDbWeight::get().reads(13_u64)) + .saturating_add(RocksDbWeight::get().writes(6_u64)) } /// Storage: Battlepass Battlepasses (r:1 w:0) - /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(382), added: 2857, mode: MaxEncodedLen) + /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(254), added: 2729, mode: MaxEncodedLen) /// Storage: Battlepass BattlepassStates (r:1 w:1) /// Proof: Battlepass BattlepassStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) /// Storage: Control OrgStates (r:1 w:0) @@ -463,15 +497,15 @@ impl WeightInfo for () { /// Proof: Battlepass BattlepassInfoByOrg (max_values: None, max_size: Some(118), added: 2593, mode: MaxEncodedLen) fn activate_battlepass() -> Weight { // Proof Size summary in bytes: - // Measured: `880` - // Estimated: `13263` - // Minimum execution time: 35_000 nanoseconds. - Weight::from_parts(36_000_000, 13263) + // Measured: `794` + // Estimated: `18085` + // Minimum execution time: 41_000 nanoseconds. + Weight::from_parts(41_000_000, 18085) .saturating_add(RocksDbWeight::get().reads(5_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) } /// Storage: Battlepass Battlepasses (r:1 w:0) - /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(382), added: 2857, mode: MaxEncodedLen) + /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(254), added: 2729, mode: MaxEncodedLen) /// Storage: Battlepass BattlepassStates (r:1 w:1) /// Proof: Battlepass BattlepassStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) /// Storage: Control Orgs (r:1 w:0) @@ -480,15 +514,15 @@ impl WeightInfo for () { /// Proof: Battlepass BattlepassInfoByOrg (max_values: None, max_size: Some(118), added: 2593, mode: MaxEncodedLen) fn conclude_battlepass() -> Weight { // Proof Size summary in bytes: - // Measured: `907` - // Estimated: `10739` - // Minimum execution time: 31_000 nanoseconds. - Weight::from_parts(32_000_000, 10739) + // Measured: `790` + // Estimated: `14571` + // Minimum execution time: 35_000 nanoseconds. + Weight::from_parts(38_000_000, 14571) .saturating_add(RocksDbWeight::get().reads(4_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) } /// Storage: Battlepass Battlepasses (r:1 w:0) - /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(382), added: 2857, mode: MaxEncodedLen) + /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(254), added: 2729, mode: MaxEncodedLen) /// Storage: Battlepass BattlepassStates (r:1 w:0) /// Proof: Battlepass BattlepassStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) /// Storage: Control OrgStates (r:1 w:0) @@ -497,21 +531,21 @@ impl WeightInfo for () { /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) /// Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) /// Proof: Battlepass BattlepassInfoByOrg (max_values: None, max_size: Some(118), added: 2593, mode: MaxEncodedLen) - /// Storage: Uniques Account (r:2 w:0) - /// Proof: Uniques Account (max_values: None, max_size: Some(88), added: 2563, mode: MaxEncodedLen) + /// Storage: Nfts Account (r:2 w:0) + /// Proof: Nfts Account (max_values: None, max_size: Some(88), added: 2563, mode: MaxEncodedLen) /// Storage: Battlepass Points (r:0 w:1) /// Proof: Battlepass Points (max_values: None, max_size: Some(100), added: 2575, mode: MaxEncodedLen) fn set_points() -> Weight { // Proof Size summary in bytes: - // Measured: `1417` - // Estimated: `18389` - // Minimum execution time: 43_000 nanoseconds. - Weight::from_parts(45_000_000, 18389) + // Measured: `1423` + // Estimated: `24201` + // Minimum execution time: 44_000 nanoseconds. + Weight::from_parts(45_000_000, 24201) .saturating_add(RocksDbWeight::get().reads(7_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } /// Storage: Battlepass Battlepasses (r:1 w:0) - /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(382), added: 2857, mode: MaxEncodedLen) + /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(254), added: 2729, mode: MaxEncodedLen) /// Storage: Battlepass BattlepassStates (r:1 w:0) /// Proof: Battlepass BattlepassStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) /// Storage: Control OrgStates (r:1 w:0) @@ -520,35 +554,37 @@ impl WeightInfo for () { /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) /// Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) /// Proof: Battlepass BattlepassInfoByOrg (max_values: None, max_size: Some(118), added: 2593, mode: MaxEncodedLen) - /// Storage: Battlepass CollectionIndex (r:1 w:1) - /// Proof: Battlepass CollectionIndex (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: Uniques ClassMetadataOf (r:1 w:1) - /// Proof: Uniques ClassMetadataOf (max_values: None, max_size: Some(167), added: 2642, mode: MaxEncodedLen) - /// Storage: Uniques CollectionMaxSupply (r:1 w:1) - /// Proof: Uniques CollectionMaxSupply (max_values: None, max_size: Some(24), added: 2499, mode: MaxEncodedLen) - /// Storage: Uniques ClassAccount (r:0 w:1) - /// Proof: Uniques ClassAccount (max_values: None, max_size: Some(68), added: 2543, mode: MaxEncodedLen) + /// Storage: Nfts NextCollectionId (r:1 w:1) + /// Proof: Nfts NextCollectionId (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) + /// Storage: Nfts Collection (r:1 w:1) + /// Proof: Nfts Collection (max_values: None, max_size: Some(84), added: 2559, mode: MaxEncodedLen) + /// Storage: Nfts CollectionMetadataOf (r:1 w:1) + /// Proof: Nfts CollectionMetadataOf (max_values: None, max_size: Some(102), added: 2577, mode: MaxEncodedLen) /// Storage: Battlepass Rewards (r:0 w:1) - /// Proof: Battlepass Rewards (max_values: None, max_size: Some(346), added: 2821, mode: MaxEncodedLen) + /// Proof: Battlepass Rewards (max_values: None, max_size: Some(218), added: 2693, mode: MaxEncodedLen) /// Storage: Battlepass RewardStates (r:0 w:1) /// Proof: Battlepass RewardStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) + /// Storage: Nfts CollectionRoleOf (r:0 w:1) + /// Proof: Nfts CollectionRoleOf (max_values: None, max_size: Some(69), added: 2544, mode: MaxEncodedLen) + /// Storage: Nfts CollectionConfigOf (r:0 w:1) + /// Proof: Nfts CollectionConfigOf (max_values: None, max_size: Some(73), added: 2548, mode: MaxEncodedLen) + /// Storage: Nfts CollectionAccount (r:0 w:1) + /// Proof: Nfts CollectionAccount (max_values: None, max_size: Some(68), added: 2543, mode: MaxEncodedLen) fn create_reward() -> Weight { // Proof Size summary in bytes: - // Measured: `1226` - // Estimated: `21556` - // Minimum execution time: 110_000 nanoseconds. - Weight::from_parts(111_000_000, 21556) - .saturating_add(RocksDbWeight::get().reads(9_u64)) - .saturating_add(RocksDbWeight::get().writes(7_u64)) + // Measured: `1197` + // Estimated: `26690` + // Minimum execution time: 112_000 nanoseconds. + Weight::from_parts(113_000_000, 26690) + .saturating_add(RocksDbWeight::get().reads(8_u64)) + .saturating_add(RocksDbWeight::get().writes(8_u64)) } /// Storage: Battlepass Rewards (r:1 w:1) - /// Proof: Battlepass Rewards (max_values: None, max_size: Some(346), added: 2821, mode: MaxEncodedLen) + /// Proof: Battlepass Rewards (max_values: None, max_size: Some(218), added: 2693, mode: MaxEncodedLen) /// Storage: Battlepass RewardStates (r:1 w:0) /// Proof: Battlepass RewardStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) /// Storage: Battlepass Battlepasses (r:1 w:0) - /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(382), added: 2857, mode: MaxEncodedLen) + /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(254), added: 2729, mode: MaxEncodedLen) /// Storage: Battlepass BattlepassStates (r:1 w:0) /// Proof: Battlepass BattlepassStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) /// Storage: Control OrgStates (r:1 w:0) @@ -557,46 +593,50 @@ impl WeightInfo for () { /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) /// Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) /// Proof: Battlepass BattlepassInfoByOrg (max_values: None, max_size: Some(118), added: 2593, mode: MaxEncodedLen) - /// Storage: Uniques Class (r:1 w:1) - /// Proof: Uniques Class (max_values: None, max_size: Some(178), added: 2653, mode: MaxEncodedLen) - /// Storage: Uniques ClassMetadataOf (r:1 w:1) - /// Proof: Uniques ClassMetadataOf (max_values: None, max_size: Some(167), added: 2642, mode: MaxEncodedLen) + /// Storage: Nfts CollectionRoleOf (r:1 w:0) + /// Proof: Nfts CollectionRoleOf (max_values: None, max_size: Some(69), added: 2544, mode: MaxEncodedLen) + /// Storage: Nfts CollectionConfigOf (r:1 w:0) + /// Proof: Nfts CollectionConfigOf (max_values: None, max_size: Some(73), added: 2548, mode: MaxEncodedLen) + /// Storage: Nfts Collection (r:1 w:1) + /// Proof: Nfts Collection (max_values: None, max_size: Some(84), added: 2559, mode: MaxEncodedLen) + /// Storage: Nfts CollectionMetadataOf (r:1 w:1) + /// Proof: Nfts CollectionMetadataOf (max_values: None, max_size: Some(102), added: 2577, mode: MaxEncodedLen) fn update_reward() -> Weight { // Proof Size summary in bytes: - // Measured: `1685` - // Estimated: `23903` - // Minimum execution time: 73_000 nanoseconds. - Weight::from_parts(75_000_000, 23903) - .saturating_add(RocksDbWeight::get().reads(9_u64)) + // Measured: `1632` + // Estimated: `39470` + // Minimum execution time: 90_000 nanoseconds. + Weight::from_parts(93_000_000, 39470) + .saturating_add(RocksDbWeight::get().reads(11_u64)) .saturating_add(RocksDbWeight::get().writes(3_u64)) } /// Storage: Battlepass Rewards (r:1 w:0) - /// Proof: Battlepass Rewards (max_values: None, max_size: Some(346), added: 2821, mode: MaxEncodedLen) + /// Proof: Battlepass Rewards (max_values: None, max_size: Some(218), added: 2693, mode: MaxEncodedLen) /// Storage: Battlepass RewardStates (r:1 w:1) /// Proof: Battlepass RewardStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) /// Storage: Battlepass Battlepasses (r:1 w:0) - /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(382), added: 2857, mode: MaxEncodedLen) + /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(254), added: 2729, mode: MaxEncodedLen) /// Storage: Control Orgs (r:1 w:0) /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) /// Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) /// Proof: Battlepass BattlepassInfoByOrg (max_values: None, max_size: Some(118), added: 2593, mode: MaxEncodedLen) fn disable_reward() -> Weight { // Proof Size summary in bytes: - // Measured: `1094` - // Estimated: `13560` - // Minimum execution time: 33_000 nanoseconds. - Weight::from_parts(37_000_000, 13560) + // Measured: `946` + // Estimated: `18254` + // Minimum execution time: 37_000 nanoseconds. + Weight::from_parts(38_000_000, 18254) .saturating_add(RocksDbWeight::get().reads(5_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } /// Storage: Battlepass Rewards (r:1 w:0) - /// Proof: Battlepass Rewards (max_values: None, max_size: Some(346), added: 2821, mode: MaxEncodedLen) + /// Proof: Battlepass Rewards (max_values: None, max_size: Some(218), added: 2693, mode: MaxEncodedLen) /// Storage: Battlepass RewardStates (r:1 w:0) /// Proof: Battlepass RewardStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) /// Storage: Battlepass ClaimedRewards (r:1 w:1) /// Proof: Battlepass ClaimedRewards (max_values: None, max_size: Some(100), added: 2575, mode: MaxEncodedLen) /// Storage: Battlepass Battlepasses (r:1 w:0) - /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(382), added: 2857, mode: MaxEncodedLen) + /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(254), added: 2729, mode: MaxEncodedLen) /// Storage: Battlepass BattlepassStates (r:1 w:0) /// Proof: Battlepass BattlepassStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) /// Storage: Control OrgStates (r:1 w:0) @@ -605,33 +645,37 @@ impl WeightInfo for () { /// Proof: Control Orgs (max_values: None, max_size: Some(290), added: 2765, mode: MaxEncodedLen) /// Storage: Battlepass BattlepassInfoByOrg (r:1 w:0) /// Proof: Battlepass BattlepassInfoByOrg (max_values: None, max_size: Some(118), added: 2593, mode: MaxEncodedLen) - /// Storage: Uniques Account (r:2 w:1) - /// Proof: Uniques Account (max_values: None, max_size: Some(88), added: 2563, mode: MaxEncodedLen) + /// Storage: Nfts Account (r:2 w:1) + /// Proof: Nfts Account (max_values: None, max_size: Some(88), added: 2563, mode: MaxEncodedLen) /// Storage: Battlepass Points (r:1 w:0) /// Proof: Battlepass Points (max_values: None, max_size: Some(100), added: 2575, mode: MaxEncodedLen) /// Storage: Battlepass Levels (r:2 w:0) /// Proof: Battlepass Levels (max_values: None, max_size: Some(69), added: 2544, mode: MaxEncodedLen) /// Storage: Battlepass NftIndex (r:1 w:1) /// Proof: Battlepass NftIndex (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: Uniques Asset (r:1 w:1) - /// Proof: Uniques Asset (max_values: None, max_size: Some(122), added: 2597, mode: MaxEncodedLen) - /// Storage: Uniques Class (r:1 w:1) - /// Proof: Uniques Class (max_values: None, max_size: Some(178), added: 2653, 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(187), added: 2662, mode: MaxEncodedLen) + /// Storage: Nfts CollectionConfigOf (r:1 w:0) + /// Proof: Nfts CollectionConfigOf (max_values: None, max_size: Some(73), added: 2548, mode: MaxEncodedLen) + /// Storage: Nfts Item (r:1 w:1) + /// Proof: Nfts Item (max_values: None, max_size: Some(861), added: 3336, mode: MaxEncodedLen) + /// Storage: Nfts Collection (r:1 w:1) + /// Proof: Nfts Collection (max_values: None, max_size: Some(84), added: 2559, mode: MaxEncodedLen) + /// Storage: Nfts CollectionRoleOf (r:1 w:0) + /// Proof: Nfts CollectionRoleOf (max_values: None, max_size: Some(69), added: 2544, mode: MaxEncodedLen) + /// Storage: Nfts ItemConfigOf (r:1 w:1) + /// Proof: Nfts ItemConfigOf (max_values: None, max_size: Some(48), added: 2523, mode: MaxEncodedLen) + /// Storage: Nfts ItemMetadataOf (r:1 w:1) + /// Proof: Nfts ItemMetadataOf (max_values: None, max_size: Some(155), added: 2630, mode: MaxEncodedLen) fn claim_reward() -> Weight { // Proof Size summary in bytes: - // Measured: `2192` - // Estimated: `44882` - // Minimum execution time: 135_000 nanoseconds. - Weight::from_parts(145_000_000, 44882) - .saturating_add(RocksDbWeight::get().reads(18_u64)) - .saturating_add(RocksDbWeight::get().writes(6_u64)) + // Measured: `2281` + // Estimated: `68175` + // Minimum execution time: 163_000 nanoseconds. + Weight::from_parts(166_000_000, 68175) + .saturating_add(RocksDbWeight::get().reads(20_u64)) + .saturating_add(RocksDbWeight::get().writes(7_u64)) } /// Storage: Battlepass Battlepasses (r:1 w:0) - /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(382), added: 2857, mode: MaxEncodedLen) + /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(254), added: 2729, mode: MaxEncodedLen) /// Storage: Battlepass BattlepassStates (r:1 w:0) /// Proof: Battlepass BattlepassStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) /// Storage: Control OrgStates (r:1 w:0) @@ -644,15 +688,15 @@ impl WeightInfo for () { /// Proof: Battlepass Levels (max_values: None, max_size: Some(69), added: 2544, mode: MaxEncodedLen) fn add_level() -> Weight { // Proof Size summary in bytes: - // Measured: `945` - // Estimated: `13263` - // Minimum execution time: 32_000 nanoseconds. - Weight::from_parts(32_000_000, 13263) + // Measured: `828` + // Estimated: `18085` + // Minimum execution time: 35_000 nanoseconds. + Weight::from_parts(36_000_000, 18085) .saturating_add(RocksDbWeight::get().reads(5_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } /// Storage: Battlepass Battlepasses (r:1 w:0) - /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(382), added: 2857, mode: MaxEncodedLen) + /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(254), added: 2729, mode: MaxEncodedLen) /// Storage: Battlepass BattlepassStates (r:1 w:0) /// Proof: Battlepass BattlepassStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) /// Storage: Control OrgStates (r:1 w:0) @@ -665,15 +709,15 @@ impl WeightInfo for () { /// Proof: Battlepass Levels (max_values: None, max_size: Some(69), added: 2544, mode: MaxEncodedLen) fn remove_level() -> Weight { // Proof Size summary in bytes: - // Measured: `1038` - // Estimated: `15807` - // Minimum execution time: 36_000 nanoseconds. - Weight::from_parts(37_000_000, 15807) + // Measured: `922` + // Estimated: `21619` + // Minimum execution time: 40_000 nanoseconds. + Weight::from_parts(41_000_000, 21619) .saturating_add(RocksDbWeight::get().reads(6_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } /// Storage: Battlepass Battlepasses (r:1 w:0) - /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(382), added: 2857, mode: MaxEncodedLen) + /// Proof: Battlepass Battlepasses (max_values: None, max_size: Some(254), added: 2729, mode: MaxEncodedLen) /// Storage: Battlepass BattlepassStates (r:1 w:0) /// Proof: Battlepass BattlepassStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) /// Storage: Control OrgStates (r:1 w:0) @@ -684,10 +728,10 @@ impl WeightInfo for () { /// Proof: Battlepass BattlepassInfoByOrg (max_values: None, max_size: Some(118), added: 2593, mode: MaxEncodedLen) fn add_bot() -> Weight { // Proof Size summary in bytes: - // Measured: `880` - // Estimated: `13263` - // Minimum execution time: 31_000 nanoseconds. - Weight::from_parts(32_000_000, 13263) + // Measured: `794` + // Estimated: `18085` + // Minimum execution time: 32_000 nanoseconds. + Weight::from_parts(33_000_000, 18085) .saturating_add(RocksDbWeight::get().reads(5_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } diff --git a/control/src/mock.rs b/control/src/mock.rs index 9b44bd460..583649d50 100644 --- a/control/src/mock.rs +++ b/control/src/mock.rs @@ -39,12 +39,10 @@ pub const PAYMENT_TOKEN_ID: CurrencyId = 2; // Accounts: pub const TREASURY: AccountId = 1; -pub const GAME3_TREASURY: AccountId = 2; pub const GAMEDAO_TREASURY: AccountId = 3; pub const ALICE: AccountId = 4; pub const BOB: AccountId = 5; pub const CHARLIE: AccountId = 6; -pub const DAVE: AccountId = 7; // Configure a mock runtime to test the pallet. frame_support::construct_runtime!( diff --git a/control/src/weights.rs b/control/src/weights.rs index 6583e7cd7..50bac8f88 100644 --- a/control/src/weights.rs +++ b/control/src/weights.rs @@ -2,12 +2,12 @@ //! Autogenerated weights for gamedao_control //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-03-04, STEPS: `20`, REPEAT: `10`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2023-04-19, STEPS: `20`, REPEAT: `10`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: None, DB CACHE: 1024 // Executed Command: -// ./target/release/subzero-dev +// ./target/release/subzero // benchmark // pallet // --execution=wasm @@ -60,10 +60,10 @@ impl WeightInfo for SubstrateWeight { /// Proof: Control OrgStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) fn create_org() -> Weight { // Proof Size summary in bytes: - // Measured: `408` - // Estimated: `45560` - // Minimum execution time: 70_000 nanoseconds. - Weight::from_parts(71_000_000, 45560) + // Measured: `377` + // Estimated: `50510` + // Minimum execution time: 82_000 nanoseconds. + Weight::from_parts(85_000_000, 50510) .saturating_add(T::DbWeight::get().reads(6_u64)) .saturating_add(T::DbWeight::get().writes(10_u64)) } @@ -73,10 +73,10 @@ impl WeightInfo for SubstrateWeight { /// Proof: Control MemberStates (max_values: None, max_size: Some(97), added: 2572, mode: MaxEncodedLen) fn update_org() -> Weight { // Proof Size summary in bytes: - // Measured: `565` - // Estimated: `5337` - // Minimum execution time: 21_000 nanoseconds. - Weight::from_parts(22_000_000, 5337) + // Measured: `534` + // Estimated: `7317` + // Minimum execution time: 26_000 nanoseconds. + Weight::from_parts(27_000_000, 7317) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -86,10 +86,10 @@ impl WeightInfo for SubstrateWeight { /// Proof: Control OrgStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) fn disable_org() -> Weight { // Proof Size summary in bytes: - // Measured: `480` - // Estimated: `2765` - // Minimum execution time: 17_000 nanoseconds. - Weight::from_parts(18_000_000, 2765) + // Measured: `449` + // Estimated: `3755` + // Minimum execution time: 19_000 nanoseconds. + Weight::from_parts(20_000_000, 3755) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -99,10 +99,10 @@ impl WeightInfo for SubstrateWeight { /// Proof: Control OrgStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) fn enable_org() -> Weight { // Proof Size summary in bytes: - // Measured: `480` - // Estimated: `2765` - // Minimum execution time: 17_000 nanoseconds. - Weight::from_parts(17_000_000, 2765) + // Measured: `449` + // Estimated: `3755` + // Minimum execution time: 18_000 nanoseconds. + Weight::from_parts(19_000_000, 3755) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -119,12 +119,12 @@ impl WeightInfo for SubstrateWeight { /// The range of component `r` is `[1, 999]`. fn add_member(r: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `659 + r * (32 ±0)` - // Estimated: `39845` - // Minimum execution time: 29_000 nanoseconds. - Weight::from_parts(27_804_864, 39845) - // Standard Error: 897 - .saturating_add(Weight::from_ref_time(34_905).saturating_mul(r.into())) + // Measured: `597 + r * (32 ±0)` + // Estimated: `42815` + // Minimum execution time: 32_000 nanoseconds. + Weight::from_parts(31_011_478, 42815) + // Standard Error: 933 + .saturating_add(Weight::from_ref_time(36_876).saturating_mul(r.into())) .saturating_add(T::DbWeight::get().reads(3_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } @@ -134,10 +134,10 @@ impl WeightInfo for SubstrateWeight { /// Proof: Control MemberStates (max_values: None, max_size: Some(97), added: 2572, mode: MaxEncodedLen) fn update_member_state() -> Weight { // Proof Size summary in bytes: - // Measured: `604` - // Estimated: `5337` - // Minimum execution time: 14_000 nanoseconds. - Weight::from_parts(15_000_000, 5337) + // Measured: `573` + // Estimated: `7317` + // Minimum execution time: 16_000 nanoseconds. + Weight::from_parts(17_000_000, 7317) .saturating_add(T::DbWeight::get().reads(2_u64)) } /// Storage: Control Orgs (r:1 w:0) @@ -151,12 +151,12 @@ impl WeightInfo for SubstrateWeight { /// The range of component `r` is `[1, 999]`. fn remove_member(r: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `584 + r * (32 ±0)` - // Estimated: `37290` - // Minimum execution time: 25_000 nanoseconds. - Weight::from_parts(23_223_981, 37290) - // Standard Error: 874 - .saturating_add(Weight::from_ref_time(33_949).saturating_mul(r.into())) + // Measured: `522 + r * (32 ±0)` + // Estimated: `39270` + // Minimum execution time: 28_000 nanoseconds. + Weight::from_parts(27_753_161, 39270) + // Standard Error: 784 + .saturating_add(Weight::from_ref_time(31_088).saturating_mul(r.into())) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } @@ -170,10 +170,10 @@ impl WeightInfo for SubstrateWeight { /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) fn spend_funds() -> Weight { // Proof Size summary in bytes: - // Measured: `1040` - // Estimated: `15694` - // Minimum execution time: 58_000 nanoseconds. - Weight::from_parts(59_000_000, 15694) + // Measured: `946` + // Estimated: `19654` + // Minimum execution time: 64_000 nanoseconds. + Weight::from_parts(65_000_000, 19654) .saturating_add(T::DbWeight::get().reads(6_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } @@ -201,10 +201,10 @@ impl WeightInfo for () { /// Proof: Control OrgStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) fn create_org() -> Weight { // Proof Size summary in bytes: - // Measured: `408` - // Estimated: `45560` - // Minimum execution time: 70_000 nanoseconds. - Weight::from_parts(71_000_000, 45560) + // Measured: `377` + // Estimated: `50510` + // Minimum execution time: 82_000 nanoseconds. + Weight::from_parts(85_000_000, 50510) .saturating_add(RocksDbWeight::get().reads(6_u64)) .saturating_add(RocksDbWeight::get().writes(10_u64)) } @@ -214,10 +214,10 @@ impl WeightInfo for () { /// Proof: Control MemberStates (max_values: None, max_size: Some(97), added: 2572, mode: MaxEncodedLen) fn update_org() -> Weight { // Proof Size summary in bytes: - // Measured: `565` - // Estimated: `5337` - // Minimum execution time: 21_000 nanoseconds. - Weight::from_parts(22_000_000, 5337) + // Measured: `534` + // Estimated: `7317` + // Minimum execution time: 26_000 nanoseconds. + Weight::from_parts(27_000_000, 7317) .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -227,10 +227,10 @@ impl WeightInfo for () { /// Proof: Control OrgStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) fn disable_org() -> Weight { // Proof Size summary in bytes: - // Measured: `480` - // Estimated: `2765` - // Minimum execution time: 17_000 nanoseconds. - Weight::from_parts(18_000_000, 2765) + // Measured: `449` + // Estimated: `3755` + // Minimum execution time: 19_000 nanoseconds. + Weight::from_parts(20_000_000, 3755) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -240,10 +240,10 @@ impl WeightInfo for () { /// Proof: Control OrgStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) fn enable_org() -> Weight { // Proof Size summary in bytes: - // Measured: `480` - // Estimated: `2765` - // Minimum execution time: 17_000 nanoseconds. - Weight::from_parts(17_000_000, 2765) + // Measured: `449` + // Estimated: `3755` + // Minimum execution time: 18_000 nanoseconds. + Weight::from_parts(19_000_000, 3755) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -260,12 +260,12 @@ impl WeightInfo for () { /// The range of component `r` is `[1, 999]`. fn add_member(r: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `659 + r * (32 ±0)` - // Estimated: `39845` - // Minimum execution time: 29_000 nanoseconds. - Weight::from_parts(27_804_864, 39845) - // Standard Error: 897 - .saturating_add(Weight::from_ref_time(34_905).saturating_mul(r.into())) + // Measured: `597 + r * (32 ±0)` + // Estimated: `42815` + // Minimum execution time: 32_000 nanoseconds. + Weight::from_parts(31_011_478, 42815) + // Standard Error: 933 + .saturating_add(Weight::from_ref_time(36_876).saturating_mul(r.into())) .saturating_add(RocksDbWeight::get().reads(3_u64)) .saturating_add(RocksDbWeight::get().writes(3_u64)) } @@ -275,10 +275,10 @@ impl WeightInfo for () { /// Proof: Control MemberStates (max_values: None, max_size: Some(97), added: 2572, mode: MaxEncodedLen) fn update_member_state() -> Weight { // Proof Size summary in bytes: - // Measured: `604` - // Estimated: `5337` - // Minimum execution time: 14_000 nanoseconds. - Weight::from_parts(15_000_000, 5337) + // Measured: `573` + // Estimated: `7317` + // Minimum execution time: 16_000 nanoseconds. + Weight::from_parts(17_000_000, 7317) .saturating_add(RocksDbWeight::get().reads(2_u64)) } /// Storage: Control Orgs (r:1 w:0) @@ -292,12 +292,12 @@ impl WeightInfo for () { /// The range of component `r` is `[1, 999]`. fn remove_member(r: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `584 + r * (32 ±0)` - // Estimated: `37290` - // Minimum execution time: 25_000 nanoseconds. - Weight::from_parts(23_223_981, 37290) - // Standard Error: 874 - .saturating_add(Weight::from_ref_time(33_949).saturating_mul(r.into())) + // Measured: `522 + r * (32 ±0)` + // Estimated: `39270` + // Minimum execution time: 28_000 nanoseconds. + Weight::from_parts(27_753_161, 39270) + // Standard Error: 784 + .saturating_add(Weight::from_ref_time(31_088).saturating_mul(r.into())) .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().writes(3_u64)) } @@ -311,10 +311,10 @@ impl WeightInfo for () { /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) fn spend_funds() -> Weight { // Proof Size summary in bytes: - // Measured: `1040` - // Estimated: `15694` - // Minimum execution time: 58_000 nanoseconds. - Weight::from_parts(59_000_000, 15694) + // Measured: `946` + // Estimated: `19654` + // Minimum execution time: 64_000 nanoseconds. + Weight::from_parts(65_000_000, 19654) .saturating_add(RocksDbWeight::get().reads(6_u64)) .saturating_add(RocksDbWeight::get().writes(3_u64)) } diff --git a/flow/src/mock.rs b/flow/src/mock.rs index 560d9a1f0..e4514b15d 100644 --- a/flow/src/mock.rs +++ b/flow/src/mock.rs @@ -52,7 +52,6 @@ pub const ALICE: AccountId = 11; pub const BOB: AccountId = 12; pub const GAMEDAO_TREASURY: AccountId = 13; -pub const GAME3_TREASURY: AccountId = 14; pub const INIT_BALANCE: Balance = 100 * DOLLARS; diff --git a/flow/src/tests.rs b/flow/src/tests.rs index 049b77f0a..71b7f6863 100644 --- a/flow/src/tests.rs +++ b/flow/src/tests.rs @@ -470,7 +470,7 @@ fn flow_on_finalize_campaign_failed() { campaign.cid.clone(), None, None, None )); - let mut contributors: Vec = (1..11).collect(); + let contributors: Vec = (1..11).collect(); // Contribute (600/1000) for c in &contributors { assert_ok!(Flow::contribute(Origin::signed(*c), campaign_id, contribution)); diff --git a/flow/src/weights.rs b/flow/src/weights.rs index 6f7abf2d2..13e13fa32 100644 --- a/flow/src/weights.rs +++ b/flow/src/weights.rs @@ -2,12 +2,12 @@ //! Autogenerated weights for gamedao_flow //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-03-04, STEPS: `20`, REPEAT: `10`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2023-04-19, STEPS: `20`, REPEAT: `10`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: None, DB CACHE: 1024 // Executed Command: -// ./target/release/subzero-dev +// ./target/release/subzero // benchmark // pallet // --execution=wasm @@ -51,10 +51,10 @@ impl WeightInfo for SubstrateWeight { /// Proof: Flow CampaignStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) fn create_campaign() -> Weight { // Proof Size summary in bytes: - // Measured: `1009` - // Estimated: `14069` - // Minimum execution time: 57_000 nanoseconds. - Weight::from_parts(58_000_000, 14069) + // Measured: `947` + // Estimated: `19019` + // Minimum execution time: 66_000 nanoseconds. + Weight::from_parts(68_000_000, 19019) .saturating_add(T::DbWeight::get().reads(6_u64)) .saturating_add(T::DbWeight::get().writes(6_u64)) } @@ -72,10 +72,10 @@ impl WeightInfo for SubstrateWeight { /// Proof: Flow CampaignBalance (max_values: None, max_size: Some(64), added: 2539, mode: MaxEncodedLen) fn contribute() -> Weight { // Proof Size summary in bytes: - // Measured: `1104` - // Estimated: `15700` - // Minimum execution time: 48_000 nanoseconds. - Weight::from_parts(51_000_000, 15700) + // Measured: `1042` + // Estimated: `21640` + // Minimum execution time: 53_000 nanoseconds. + Weight::from_parts(54_000_000, 21640) .saturating_add(T::DbWeight::get().reads(6_u64)) .saturating_add(T::DbWeight::get().writes(4_u64)) } @@ -97,22 +97,22 @@ impl WeightInfo for SubstrateWeight { /// The range of component `p` is `[0, 10]`. fn on_initialize(c: u32, p: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `1615 + c * (288 ±0) + p * (87 ±0)` - // Estimated: `655398 + c * (5182 ±0) + p * (2558 ±12)` - // Minimum execution time: 136_000 nanoseconds. - Weight::from_parts(62_296_021, 655398) - // Standard Error: 59_341 - .saturating_add(Weight::from_ref_time(25_969_615).saturating_mul(c.into())) - // Standard Error: 593_322 - .saturating_add(Weight::from_ref_time(10_250_535).saturating_mul(p.into())) + // Measured: `1489 + c * (257 ±0) + p * (87 ±0)` + // Estimated: `660937 + c * (5183 ±0) + p * (2595 ±4)` + // Minimum execution time: 146_000 nanoseconds. + Weight::from_parts(68_171_926, 660937) + // Standard Error: 65_182 + .saturating_add(Weight::from_ref_time(29_183_288).saturating_mul(c.into())) + // Standard Error: 651_727 + .saturating_add(Weight::from_ref_time(11_547_431).saturating_mul(p.into())) .saturating_add(T::DbWeight::get().reads(5_u64)) .saturating_add(T::DbWeight::get().reads((2_u64).saturating_mul(c.into()))) .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(p.into()))) .saturating_add(T::DbWeight::get().writes(5_u64)) .saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(c.into()))) .saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(p.into()))) - .saturating_add(Weight::from_proof_size(5182).saturating_mul(c.into())) - .saturating_add(Weight::from_proof_size(2558).saturating_mul(p.into())) + .saturating_add(Weight::from_proof_size(5183).saturating_mul(c.into())) + .saturating_add(Weight::from_proof_size(2595).saturating_mul(p.into())) } } @@ -134,10 +134,10 @@ impl WeightInfo for () { /// Proof: Flow CampaignStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) fn create_campaign() -> Weight { // Proof Size summary in bytes: - // Measured: `1009` - // Estimated: `14069` - // Minimum execution time: 57_000 nanoseconds. - Weight::from_parts(58_000_000, 14069) + // Measured: `947` + // Estimated: `19019` + // Minimum execution time: 66_000 nanoseconds. + Weight::from_parts(68_000_000, 19019) .saturating_add(RocksDbWeight::get().reads(6_u64)) .saturating_add(RocksDbWeight::get().writes(6_u64)) } @@ -155,10 +155,10 @@ impl WeightInfo for () { /// Proof: Flow CampaignBalance (max_values: None, max_size: Some(64), added: 2539, mode: MaxEncodedLen) fn contribute() -> Weight { // Proof Size summary in bytes: - // Measured: `1104` - // Estimated: `15700` - // Minimum execution time: 48_000 nanoseconds. - Weight::from_parts(51_000_000, 15700) + // Measured: `1042` + // Estimated: `21640` + // Minimum execution time: 53_000 nanoseconds. + Weight::from_parts(54_000_000, 21640) .saturating_add(RocksDbWeight::get().reads(6_u64)) .saturating_add(RocksDbWeight::get().writes(4_u64)) } @@ -180,21 +180,21 @@ impl WeightInfo for () { /// The range of component `p` is `[0, 10]`. fn on_initialize(c: u32, p: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `1615 + c * (288 ±0) + p * (87 ±0)` - // Estimated: `655398 + c * (5182 ±0) + p * (2558 ±12)` - // Minimum execution time: 136_000 nanoseconds. - Weight::from_parts(62_296_021, 655398) - // Standard Error: 59_341 - .saturating_add(Weight::from_ref_time(25_969_615).saturating_mul(c.into())) - // Standard Error: 593_322 - .saturating_add(Weight::from_ref_time(10_250_535).saturating_mul(p.into())) + // Measured: `1489 + c * (257 ±0) + p * (87 ±0)` + // Estimated: `660937 + c * (5183 ±0) + p * (2595 ±4)` + // Minimum execution time: 146_000 nanoseconds. + Weight::from_parts(68_171_926, 660937) + // Standard Error: 65_182 + .saturating_add(Weight::from_ref_time(29_183_288).saturating_mul(c.into())) + // Standard Error: 651_727 + .saturating_add(Weight::from_ref_time(11_547_431).saturating_mul(p.into())) .saturating_add(RocksDbWeight::get().reads(5_u64)) .saturating_add(RocksDbWeight::get().reads((2_u64).saturating_mul(c.into()))) .saturating_add(RocksDbWeight::get().reads((1_u64).saturating_mul(p.into()))) .saturating_add(RocksDbWeight::get().writes(5_u64)) .saturating_add(RocksDbWeight::get().writes((1_u64).saturating_mul(c.into()))) .saturating_add(RocksDbWeight::get().writes((1_u64).saturating_mul(p.into()))) - .saturating_add(Weight::from_proof_size(5182).saturating_mul(c.into())) - .saturating_add(Weight::from_proof_size(2558).saturating_mul(p.into())) + .saturating_add(Weight::from_proof_size(5183).saturating_mul(c.into())) + .saturating_add(Weight::from_proof_size(2595).saturating_mul(p.into())) } } \ No newline at end of file diff --git a/sense/src/weights.rs b/sense/src/weights.rs index 6e53933e1..fff14b72c 100644 --- a/sense/src/weights.rs +++ b/sense/src/weights.rs @@ -2,12 +2,12 @@ //! Autogenerated weights for gamedao_sense //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-03-04, STEPS: `20`, REPEAT: `10`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2023-04-19, STEPS: `20`, REPEAT: `10`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: None, DB CACHE: 1024 // Executed Command: -// ./target/release/subzero-dev +// ./target/release/subzero // benchmark // pallet // --execution=wasm @@ -43,9 +43,9 @@ impl WeightInfo for SubstrateWeight { fn create_entity() -> Weight { // Proof Size summary in bytes: // Measured: `142` - // Estimated: `3156` - // Minimum execution time: 21_000 nanoseconds. - Weight::from_parts(22_000_000, 3156) + // Estimated: `5136` + // Minimum execution time: 24_000 nanoseconds. + Weight::from_parts(25_000_000, 5136) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(5_u64)) } @@ -56,9 +56,9 @@ impl WeightInfo for SubstrateWeight { fn update_property() -> Weight { // Proof Size summary in bytes: // Measured: `452` - // Estimated: `5197` - // Minimum execution time: 20_000 nanoseconds. - Weight::from_parts(21_000_000, 5197) + // Estimated: `7177` + // Minimum execution time: 21_000 nanoseconds. + Weight::from_parts(22_000_000, 7177) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -75,9 +75,9 @@ impl WeightInfo for () { fn create_entity() -> Weight { // Proof Size summary in bytes: // Measured: `142` - // Estimated: `3156` - // Minimum execution time: 21_000 nanoseconds. - Weight::from_parts(22_000_000, 3156) + // Estimated: `5136` + // Minimum execution time: 24_000 nanoseconds. + Weight::from_parts(25_000_000, 5136) .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().writes(5_u64)) } @@ -88,9 +88,9 @@ impl WeightInfo for () { fn update_property() -> Weight { // Proof Size summary in bytes: // Measured: `452` - // Estimated: `5197` - // Minimum execution time: 20_000 nanoseconds. - Weight::from_parts(21_000_000, 5197) + // Estimated: `7177` + // Minimum execution time: 21_000 nanoseconds. + Weight::from_parts(22_000_000, 7177) .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } diff --git a/signal/src/tests.rs b/signal/src/tests.rs index bbdb713ab..33bd33002 100644 --- a/signal/src/tests.rs +++ b/signal/src/tests.rs @@ -352,17 +352,23 @@ fn signal_0_1() { // CampaignUnsucceeded let now = campaign_expiry + 1; - let campaign_id = create_finalize_campaign(now, org_id, &(51..52).collect(), 50 * DOLLARS, now + 2 * DAYS, false); - // TODO: fix this test - // assert_ok!(Flow::update_state(Origin::signed(ALICE), campaign_id, CampaignStates::Failed)); - // assert_noop!( - // Signal::proposal( - // Origin::signed(ALICE), proposal.proposal_type.clone(), proposal.org_id, - // proposal.title.clone(), proposal.cid.clone(), proposal.expiry, - // Majority::Relative, Unit::Account, Scale::Linear, None, None, None, - // Some(campaign_id), proposal.amount, proposal.beneficiary, proposal.currency_id), - // Error::::CampaignUnsucceeded - // ); + System::set_block_number(now); + let campaign_expiry = now + 2 * DAYS; + let proposal_expiry = campaign_expiry + 1 + ProposalDurationLimits::get().0; + let campaign_id = create_finalize_campaign(now, org_id, &(51..52).collect(), 5 * DOLLARS, campaign_expiry, false); + System::set_block_number(campaign_expiry); + Flow::on_finalize(campaign_expiry); + System::set_block_number(campaign_expiry + 1); + Flow::on_initialize(campaign_expiry + 1); + assert_eq!(Flow::is_campaign_succeeded(&campaign_id), false); + assert_noop!( + Signal::proposal( + Origin::signed(ALICE), proposal.proposal_type.clone(), proposal.org_id, + proposal.title.clone(), proposal.cid.clone(), proposal_expiry, + Majority::Relative, Unit::Account, Scale::Linear, None, None, None, + Some(campaign_id), proposal.amount, proposal.beneficiary, proposal.currency_id), + Error::::CampaignUnsucceeded + ); }); } diff --git a/signal/src/weights.rs b/signal/src/weights.rs index 03dd2aba9..aef2adc08 100644 --- a/signal/src/weights.rs +++ b/signal/src/weights.rs @@ -2,12 +2,12 @@ //! Autogenerated weights for gamedao_signal //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-03-04, STEPS: `20`, REPEAT: `10`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2023-04-19, STEPS: `20`, REPEAT: `10`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: None, DB CACHE: 1024 // Executed Command: -// ./target/release/subzero-dev +// ./target/release/subzero // benchmark // pallet // --execution=wasm @@ -57,10 +57,10 @@ impl WeightInfo for SubstrateWeight { /// Proof: Signal ProposalStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) fn proposal() -> Weight { // Proof Size summary in bytes: - // Measured: `1390` - // Estimated: `30111` - // Minimum execution time: 82_000 nanoseconds. - Weight::from_parts(82_000_000, 30111) + // Measured: `1328` + // Estimated: `38031` + // Minimum execution time: 98_000 nanoseconds. + Weight::from_parts(100_000_000, 38031) .saturating_add(T::DbWeight::get().reads(10_u64)) .saturating_add(T::DbWeight::get().writes(8_u64)) } @@ -81,12 +81,12 @@ impl WeightInfo for SubstrateWeight { /// The range of component `m` is `[0, 1000]`. fn vote(m: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `3941 + m * (51 ±0)` - // Estimated: `153431` - // Minimum execution time: 99_000 nanoseconds. - Weight::from_parts(94_755_596, 153431) - // Standard Error: 2_268 - .saturating_add(Weight::from_ref_time(112_356).saturating_mul(m.into())) + // Measured: `3816 + m * (51 ±0)` + // Estimated: `160361` + // Minimum execution time: 111_000 nanoseconds. + Weight::from_parts(108_350_723, 160361) + // Standard Error: 1_962 + .saturating_add(Weight::from_ref_time(108_429).saturating_mul(m.into())) .saturating_add(T::DbWeight::get().reads(9_u64)) .saturating_add(T::DbWeight::get().writes(6_u64)) } @@ -97,12 +97,12 @@ impl WeightInfo for SubstrateWeight { /// The range of component `p` is `[0, 100]`. fn on_initialize(p: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `394 + p * (86 ±0)` - // Estimated: `5714 + p * (2524 ±0)` - // Minimum execution time: 3_000 nanoseconds. - Weight::from_parts(3_033_538, 5714) - // Standard Error: 21_933 - .saturating_add(Weight::from_ref_time(3_051_963).saturating_mul(p.into())) + // Measured: `362 + p * (86 ±0)` + // Estimated: `7694 + p * (2524 ±0)` + // Minimum execution time: 4_000 nanoseconds. + Weight::from_parts(9_238_222, 7694) + // Standard Error: 7_826 + .saturating_add(Weight::from_ref_time(3_204_576).saturating_mul(p.into())) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(p.into()))) .saturating_add(Weight::from_proof_size(2524).saturating_mul(p.into())) @@ -133,10 +133,10 @@ impl WeightInfo for () { /// Proof: Signal ProposalStates (max_values: None, max_size: Some(49), added: 2524, mode: MaxEncodedLen) fn proposal() -> Weight { // Proof Size summary in bytes: - // Measured: `1390` - // Estimated: `30111` - // Minimum execution time: 82_000 nanoseconds. - Weight::from_parts(82_000_000, 30111) + // Measured: `1328` + // Estimated: `38031` + // Minimum execution time: 98_000 nanoseconds. + Weight::from_parts(100_000_000, 38031) .saturating_add(RocksDbWeight::get().reads(10_u64)) .saturating_add(RocksDbWeight::get().writes(8_u64)) } @@ -157,12 +157,12 @@ impl WeightInfo for () { /// The range of component `m` is `[0, 1000]`. fn vote(m: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `3941 + m * (51 ±0)` - // Estimated: `153431` - // Minimum execution time: 99_000 nanoseconds. - Weight::from_parts(94_755_596, 153431) - // Standard Error: 2_268 - .saturating_add(Weight::from_ref_time(112_356).saturating_mul(m.into())) + // Measured: `3816 + m * (51 ±0)` + // Estimated: `160361` + // Minimum execution time: 111_000 nanoseconds. + Weight::from_parts(108_350_723, 160361) + // Standard Error: 1_962 + .saturating_add(Weight::from_ref_time(108_429).saturating_mul(m.into())) .saturating_add(RocksDbWeight::get().reads(9_u64)) .saturating_add(RocksDbWeight::get().writes(6_u64)) } @@ -173,12 +173,12 @@ impl WeightInfo for () { /// The range of component `p` is `[0, 100]`. fn on_initialize(p: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `394 + p * (86 ±0)` - // Estimated: `5714 + p * (2524 ±0)` - // Minimum execution time: 3_000 nanoseconds. - Weight::from_parts(3_033_538, 5714) - // Standard Error: 21_933 - .saturating_add(Weight::from_ref_time(3_051_963).saturating_mul(p.into())) + // Measured: `362 + p * (86 ±0)` + // Estimated: `7694 + p * (2524 ±0)` + // Minimum execution time: 4_000 nanoseconds. + Weight::from_parts(9_238_222, 7694) + // Standard Error: 7_826 + .saturating_add(Weight::from_ref_time(3_204_576).saturating_mul(p.into())) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().reads((1_u64).saturating_mul(p.into()))) .saturating_add(Weight::from_proof_size(2524).saturating_mul(p.into())) From f8175c21ced0b2f3218ef13a9198f512edbe9129 Mon Sep 17 00:00:00 2001 From: 2075 <1140449+2075@users.noreply.github.com> Date: Wed, 10 May 2023 10:48:12 +0200 Subject: [PATCH 47/49] fix(battlepass): update permissions (#153) --- battlepass/src/lib.rs | 66 +++++++++++++++++++++---------------------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/battlepass/src/lib.rs b/battlepass/src/lib.rs index a8dcdef1d..c77965b6f 100644 --- a/battlepass/src/lib.rs +++ b/battlepass/src/lib.rs @@ -55,7 +55,7 @@ impl, ItemId: From> BattlepassHelper(_); @@ -127,7 +127,7 @@ pub mod pallet { cid: Option>, price: Option }, - + /// BattlePass claimed BattlepassClaimed { by_who: T::AccountId, @@ -313,7 +313,7 @@ pub mod pallet { /// Creates a Battlepass. /// Also creates a new collection to store claimed Battlepass NFTs. /// May be called only by Organization owner. - /// + /// /// Parameters: /// - `org_id`: ID of the Organization for which to create a Battlepass. /// - `name`: Battlepass name. @@ -349,7 +349,7 @@ pub mod pallet { /// Updates Battlepass. /// Also updates Collection's metadata if Battlepass CID has changed. /// May be called only by Organization owner. - /// + /// /// Parameters: /// - `battlepass_id`: ID of the Battlepass to update. /// - `name`: Battlepass name. @@ -373,7 +373,7 @@ pub mod pallet { let cid_changed = cid.is_some() && cid.clone().unwrap() != battlepass.cid; let price_changed = price.is_some() && price.unwrap() != battlepass.price; ensure!( - name_changed || cid_changed || price_changed, + name_changed || cid_changed || price_changed, Error::::NoChangesProvided ); // check if Battlepass state is not ENDED @@ -402,7 +402,7 @@ pub mod pallet { /// Claims the Battlepass-NFT for user who joined the Battlepass. /// This NFT may be used as a proof of a Battlepass membership. /// May be called by Organization owner or by a specially dedicated for this purpose account (Bot). - /// + /// /// Parameters: /// - `battlepass_id`: ID of the Battlepass for which to claim NFT. /// - `claimer`: Account for which to claim NFT. @@ -428,7 +428,7 @@ pub mod pallet { ensure!(Self::is_prime_or_bot(&org_id, caller.clone())?, Error::::AuthorizationError); // check if user has access to Battlepass ensure!(!Self::is_battlepass_member(claimer.clone(), battlepass.collection_id), Error::::BattlepassOwnershipExists); - + let nft_id = Self::do_claim_battlepass(battlepass.creator.clone(), claimer.clone(), battlepass.collection_id, cid.unwrap_or(battlepass.cid))?; Self::deposit_event(Event::BattlepassClaimed { by_who: caller, for_who: claimer, org_id, battlepass_id, nft_id }); @@ -439,7 +439,7 @@ pub mod pallet { /// Activates the Battlepass. /// Can activate only Battlepass in DRAFT state. /// May be called only by Organization owner. - /// + /// /// Parameters: /// - `battlepass_id`: ID of the Battlepass to activate. #[pallet::call_index(3)] @@ -456,8 +456,8 @@ pub mod pallet { ensure!(Self::check_battlepass_state(battlepass_id, BattlepassState::DRAFT)?, Error::::BattlepassStateWrong); // check if Org is active ensure!(T::Control::is_org_active(&battlepass.org_id), Error::::OrgUnknownOrInactive); - // check permissions (prime) - ensure!(Self::is_prime(&battlepass.org_id, sender.clone())?, Error::::AuthorizationError); + // check permissions (is_prime_or_bot) + ensure!(Self::is_prime_or_bot(&battlepass.org_id, sender.clone())?, Error::::AuthorizationError); // check if there is no active battlepass for the Org let (_, maybe_active, _) = Self::get_battlepass_info(&battlepass.org_id); ensure!(maybe_active.is_none(), Error::::BattlepassExists); @@ -473,7 +473,7 @@ pub mod pallet { /// Can conclude only Battlepass in ACTIVE state. /// After calling this extrinsic Battlepass state can not be changed any more. /// May be called only by Organization owner. - /// + /// /// Parameters: /// - `battlepass_id`: ID of the Battlepass to conclude. #[pallet::call_index(4)] @@ -488,8 +488,8 @@ pub mod pallet { let battlepass = Self::get_battlepass(battlepass_id).ok_or(Error::::BattlepassUnknown)?; // check if Battlepass in ACTIVE state ensure!(Self::check_battlepass_state(battlepass_id, BattlepassState::ACTIVE)?, Error::::BattlepassStateWrong); - // check permissions (prime) - ensure!(Self::is_prime(&battlepass.org_id, sender.clone())?, Error::::AuthorizationError); + // check permissions (is_prime_or_bot) + ensure!(Self::is_prime_or_bot(&battlepass.org_id, sender.clone())?, Error::::AuthorizationError); Self::change_battlepass_state(battlepass.org_id, battlepass_id, BattlepassState::ENDED)?; @@ -500,9 +500,9 @@ pub mod pallet { /// Sets Battlepass Points for user. /// So far no information about users' achievements is stored on chain. A separate trusted service (Bot) - /// should collect such info, process it, validate it and call this extrinsic if user's Points have been updated. + /// should collect such info, process it, validate it and call this extrinsic if user's Points have been updated. /// May be called only by Organization owner or by a specially dedicated for this purpose account (Bot). - /// + /// /// Parameters: /// - `battlepass_id`: ID of the Battlepass. /// - `account`: User's account for which to set Points. @@ -537,7 +537,7 @@ pub mod pallet { /// Creates a Reward Type for the Battlepass. /// Also creates a new collection to store claimed Reward NFTs. /// May be called only by Organization owner or by a specially dedicated for this purpose account (Bot). - /// + /// /// Parameters: /// - `battlepass_id`: ID of the Battlepass to create a Reward for. /// - `name`: Name of the Reward. @@ -566,7 +566,7 @@ pub mod pallet { ensure!(T::Control::is_org_active(&battlepass.org_id), Error::::OrgUnknownOrInactive); // check permissions (prime, bot) ensure!(Self::is_prime_or_bot(&battlepass.org_id, caller)?, Error::::AuthorizationError); - + let prime = T::Control::org_prime_account(&battlepass.org_id).ok_or(Error::::OrgPrimeUnknown)?; let collection_id = Self::create_collection(prime, max, cid.clone())?; let reward_id = Self::do_create_reward(battlepass_id, name, cid, level, transferable, collection_id)?; @@ -579,7 +579,7 @@ pub mod pallet { /// Updates Reward type. /// Also updates Collection's metadata if Reward's CID has changed. /// May be called only by Organization owner or by a specially dedicated for this purpose account (Bot). - /// + /// /// Parameters: /// - `reward_id`: ID of the Reward Type to be updated. /// - `name`: Name of the Reward. @@ -602,7 +602,7 @@ pub mod pallet { let cid_changed = cid.is_some() && cid.clone().unwrap() != reward.cid; let transferable_changed = transferable.is_some() && transferable.unwrap() != reward.transferable; ensure!( - name_changed || cid_changed || transferable_changed, + name_changed || cid_changed || transferable_changed, Error::::NoChangesProvided ); // check if Reward is active @@ -615,10 +615,10 @@ pub mod pallet { ensure!(T::Control::is_org_active(&battlepass.org_id), Error::::OrgUnknownOrInactive); // check permissions (prime, bot) ensure!(Self::is_prime_or_bot(&battlepass.org_id, caller)?, Error::::AuthorizationError); - + if name_changed { reward.name = name.clone().unwrap() }; if transferable_changed { reward.transferable = transferable.unwrap() }; - if cid_changed { + if cid_changed { reward.cid = cid.clone().unwrap(); let prime = T::Control::org_prime_account(&battlepass.org_id).ok_or(Error::::OrgPrimeUnknown)?; @@ -635,7 +635,7 @@ pub mod pallet { /// Disables the Reward Type. /// After calling this extrinsic Reward Type state can not be changed any more. /// May be called only by Organization owner or by a specially dedicated for this purpose account (Bot). - /// + /// /// Parameters: /// - `reward_id`: ID of the Reward Type to be disabled. #[pallet::call_index(8)] @@ -653,7 +653,7 @@ pub mod pallet { let battlepass = Self::get_battlepass(reward.battlepass_id).ok_or(Error::::BattlepassUnknown)?; // check permissions (prime, bot) ensure!(Self::is_prime_or_bot(&battlepass.org_id, caller)?, Error::::AuthorizationError); - + let state = RewardState::INACTIVE; RewardStates::::insert(reward_id, state.clone()); @@ -670,7 +670,7 @@ pub mod pallet { /// - must be a Battlepass member (posess a valid Battlepass NFT). /// - required achievement Level must be reached. /// May be called by Organization owner or by a specially dedicated for this purpose account (Bot). - /// + /// /// Parameters: /// - `reward_id`: ID of the Reward Type to claim. /// - `claimer`: User account for who to claim the reward. @@ -715,7 +715,7 @@ pub mod pallet { /// Adds a new achievement Level. /// May be called only by Organization owner or by a specially dedicated for this purpose account (Bot). - /// + /// /// Parameters: /// - `battlepass_id`: ID of the Battlepass to add a Level for. /// - `level`: Achievement Level. @@ -747,7 +747,7 @@ pub mod pallet { /// Removes achievement Level. /// May be called only by Organization owner or by a specially dedicated for this purpose account (Bot). - /// + /// /// Parameters: /// - `battlepass_id`: ID of the Battlepass to remove a Level for. /// - `level`: Achievement Level. @@ -779,7 +779,7 @@ pub mod pallet { /// Adds for a Battlepass a special trusted account (Bot) which will have a permission to update users' Points. /// May be called only by Organization owner. - /// + /// /// Parameters: /// - `battlepass_id`: ID of the Battlepass to add a Bot for. /// - `bot`: Trusted Account ID. @@ -902,16 +902,16 @@ impl Pallet { Ok(()) } - + fn check_battlepass_state(battlepass_id: T::Hash, state: BattlepassState) -> Result { let current_state = Self::get_battlepass_state(battlepass_id).ok_or(Error::::BattlepassStateUnknown)?; - + Ok(current_state == state) } fn check_reward_state(reward_id: T::Hash, state: RewardState) -> Result { let current_state = Self::get_reward_state(reward_id).ok_or(Error::::RewardStateUnknown)?; - + Ok(current_state == state) } @@ -922,7 +922,7 @@ impl Pallet { (0, None, None) } } - + fn do_create_battlepass(creator: T::AccountId, org_id: T::Hash, name: String, cid: String, collection_id: T::CollectionId, price: u16, season:u32) -> Result { let battlepass: Battlepass, T::CollectionId> = Battlepass { creator, @@ -957,7 +957,7 @@ impl Pallet { let nft_index = Self::bump_nft_index()?; let nft_id: T::ItemId = T::BattlepassHelper::item(nft_index); let metadata = BoundedVec::truncate_from(cid.into()); - + // Create Battlepass NFT Self::create_nft(creator, for_who, collection_id, nft_id, metadata)?; @@ -967,7 +967,7 @@ impl Pallet { fn change_battlepass_state(org_id: T::Hash, battlepass_id: T::Hash, state: BattlepassState) -> DispatchResult { let active_battlepass = if state == BattlepassState::ACTIVE { Some(battlepass_id) } else { None }; - BattlepassStates::::insert(battlepass_id, state); + BattlepassStates::::insert(battlepass_id, state); BattlepassInfoByOrg::::try_mutate(org_id, |info| -> Result<(), DispatchError> { if let Some(inf) = info { inf.active = active_battlepass; From 9e65ed7063559e1cb3c005e53206d6662b08328a Mon Sep 17 00:00:00 2001 From: 2075 Date: Tue, 14 May 2024 18:10:22 +0200 Subject: [PATCH 48/49] feat: update creates, readme --- README.md | 8 +++++++- battlepass/Cargo.toml | 7 +------ control/Cargo.toml | 11 +++-------- flow/Cargo.toml | 6 ------ sense/Cargo.toml | 6 ------ signal/Cargo.toml | 6 ------ traits/Cargo.toml | 6 ------ 7 files changed, 11 insertions(+), 39 deletions(-) diff --git a/README.md b/README.md index 0529d2f2f..78a1140b4 100644 --- a/README.md +++ b/README.md @@ -1 +1,7 @@ -# gamedao-protocol +# GAMEDAO PROTOCOL + +GameDAO Protocol is a toolbox to enable setup and operation of unstoppable on chain collectives. It offers governance via proposals for members of a collective, helping to notarize and enforce decisions, e.g. treasury spending. Collectives can also fundraise through the protocol, enabling them to kickstart their efforts. + +### Copyright + +(c) GameDAO AG diff --git a/battlepass/Cargo.toml b/battlepass/Cargo.toml index 0015a9e11..1898ec537 100644 --- a/battlepass/Cargo.toml +++ b/battlepass/Cargo.toml @@ -1,8 +1,3 @@ -# ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄ -# ███░▄▄▄█░▄▄▀█░▄▀▄░█░▄▄█░▄▀█░▄▄▀█▀▄▄▀██ -# ███░█▄▀█░▀▀░█░█▄█░█░▄▄█░█░█░▀▀░█░██░██ -# ███▄▄▄▄█▄██▄█▄███▄█▄▄▄█▄▄██▄██▄██▄▄███ -# ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ [package] name = "gamedao-battlepass" version = "1.3.0" @@ -71,4 +66,4 @@ std = [ "gamedao-control/std", "gamedao-traits/std", ] -try-runtime = ["frame-support/try-runtime"] \ No newline at end of file +try-runtime = ["frame-support/try-runtime"] diff --git a/control/Cargo.toml b/control/Cargo.toml index 1d298b978..3e5c5744d 100755 --- a/control/Cargo.toml +++ b/control/Cargo.toml @@ -1,8 +1,3 @@ -# ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄ -# ███░▄▄▄█░▄▄▀█░▄▀▄░█░▄▄█░▄▀█░▄▄▀█▀▄▄▀██ -# ███░█▄▀█░▀▀░█░█▄█░█░▄▄█░█░█░▀▀░█░██░██ -# ███▄▄▄▄█▄██▄█▄███▄█▄▄▄█▄▄██▄██▄██▄▄███ -# ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ [package] name = "gamedao-control" version = "1.3.0" @@ -14,9 +9,9 @@ description = "DAO Factory" [dependencies] hex-literal = "0.3.4" -num_enum = { version = "0.5.1", default-features = false } +num_enum = { version = "0.5.1" } -serde = { version = "1.0.143", default-features = false } +serde = { version = "1.0.143", default-features = false, features = ["derive"] } codec = { package = "parity-scale-codec", version = "3.2.2", default-features = false, features = ["derive"] } scale-info = { version = "2.1.1", default-features = false, features = ["derive"] } @@ -62,7 +57,7 @@ std = [ "frame-benchmarking/std", "sp-std/std", - + # "tangram/std", "orml-traits/std", "orml-tokens/std", diff --git a/flow/Cargo.toml b/flow/Cargo.toml index 207f761fd..8534ec9ef 100644 --- a/flow/Cargo.toml +++ b/flow/Cargo.toml @@ -1,9 +1,3 @@ -# ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄ -# ███░▄▄▄█░▄▄▀█░▄▀▄░█░▄▄█░▄▀█░▄▄▀█▀▄▄▀██ -# ███░█▄▀█░▀▀░█░█▄█░█░▄▄█░█░█░▀▀░█░██░██ -# ███▄▄▄▄█▄██▄█▄███▄█▄▄▄█▄▄██▄██▄██▄▄███ -# ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ - [package] name = "gamedao-flow" version = "1.3.0" diff --git a/sense/Cargo.toml b/sense/Cargo.toml index 30a2bf279..8af93cce7 100755 --- a/sense/Cargo.toml +++ b/sense/Cargo.toml @@ -1,9 +1,3 @@ -# ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄ -# ███░▄▄▄█░▄▄▀█░▄▀▄░█░▄▄█░▄▀█░▄▄▀█▀▄▄▀██ -# ███░█▄▀█░▀▀░█░█▄█░█░▄▄█░█░█░▀▀░█░██░██ -# ███▄▄▄▄█▄██▄█▄███▄█▄▄▄█▄▄██▄██▄██▄▄███ -# ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ - [package] name = "gamedao-sense" version = "1.3.0" diff --git a/signal/Cargo.toml b/signal/Cargo.toml index dee315196..1936059ec 100644 --- a/signal/Cargo.toml +++ b/signal/Cargo.toml @@ -1,9 +1,3 @@ -# ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄ -# ███░▄▄▄█░▄▄▀█░▄▀▄░█░▄▄█░▄▀█░▄▄▀█▀▄▄▀██ -# ███░█▄▀█░▀▀░█░█▄█░█░▄▄█░█░█░▀▀░█░██░██ -# ███▄▄▄▄█▄██▄█▄███▄█▄▄▄█▄▄██▄██▄██▄▄███ -# ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ - [package] name = "gamedao-signal" version = "1.3.0" diff --git a/traits/Cargo.toml b/traits/Cargo.toml index a04674e9d..8e43ae00f 100644 --- a/traits/Cargo.toml +++ b/traits/Cargo.toml @@ -1,9 +1,3 @@ -# ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄ -# ███░▄▄▄█░▄▄▀█░▄▀▄░█░▄▄█░▄▀█░▄▄▀█▀▄▄▀██ -# ███░█▄▀█░▀▀░█░█▄█░█░▄▄█░█░█░▀▀░█░██░██ -# ███▄▄▄▄█▄██▄█▄███▄█▄▄▄█▄▄██▄██▄██▄▄███ -# ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ - [package] name = "gamedao-traits" version = "1.3.0" From 7dfcc3940628d0947446c079a6be8120d9b1be25 Mon Sep 17 00:00:00 2001 From: 2075 <1140449+2075@users.noreply.github.com> Date: Thu, 23 May 2024 13:44:20 +0200 Subject: [PATCH 49/49] feat: bump to polkadot + orml v0.9.43 (#155) --- battlepass/Cargo.toml | 30 +++++++++++++++--------------- control/Cargo.toml | 30 +++++++++++++++--------------- flow/Cargo.toml | 24 ++++++++++++------------ sense/Cargo.toml | 16 ++++++++-------- signal/Cargo.toml | 26 +++++++++++++------------- traits/Cargo.toml | 6 +++--- 6 files changed, 66 insertions(+), 66 deletions(-) diff --git a/battlepass/Cargo.toml b/battlepass/Cargo.toml index 1898ec537..4d813d930 100644 --- a/battlepass/Cargo.toml +++ b/battlepass/Cargo.toml @@ -11,30 +11,30 @@ description = "BattlePass pallet provides functionality to create, manage and pa serde = { version = "1.0.143", default-features = false } codec = { package = "parity-scale-codec", version = "3.2.2", default-features = false, features = ["derive"] } scale-info = { version = "2.1.1", default-features = false, features = ["derive"] } -sp-core = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" } -sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" } -sp-std = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" } -sp-storage = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" } -sp-io = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.40", default-features=false } -frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40", default-features = false } -frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40", default-features = false } -frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40", default-features = false, optional = true } +sp-core = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43" } +sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43" } +sp-std = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43" } +sp-storage = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43" } +sp-io = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.43", default-features=false } +frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43", default-features = false } +frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43", default-features = false } +frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43", default-features = false, optional = true } -pallet-nfts = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" } +pallet-nfts = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43" } -orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.40", default-features = false } +orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.43", default-features = false } gamedao-control = { package = "gamedao-control", path = "../control", default-features = false } gamedao-traits = { package = "gamedao-traits", path = "../traits", default-features = false } [dev-dependencies] -sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.40" } +sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43" } codec = { package = "parity-scale-codec", version = "3.2.2", default-features = false, features = ["derive"] } -pallet-balances = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" } -orml-currencies = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.40", default-features = false } -orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.40", default-features = false } -orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.40", default-features = false } +pallet-balances = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43" } +orml-currencies = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.43", default-features = false } +orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.43", default-features = false } +orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.43", default-features = false } [features] default = ['std'] diff --git a/control/Cargo.toml b/control/Cargo.toml index 3e5c5744d..37dffb37a 100755 --- a/control/Cargo.toml +++ b/control/Cargo.toml @@ -15,29 +15,29 @@ serde = { version = "1.0.143", default-features = false, features = ["derive"] } codec = { package = "parity-scale-codec", version = "3.2.2", default-features = false, features = ["derive"] } scale-info = { version = "2.1.1", default-features = false, features = ["derive"] } -sp-core = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" } -sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" } -sp-std = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" } -sp-storage = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" } +sp-core = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43" } +sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43" } +sp-std = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43" } +sp-storage = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43" } -frame-support = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" } -frame-system = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" } -frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40", default-features = false, optional = true } -sp-io = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.40", default-features=false } +frame-support = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43" } +frame-system = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43" } +frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43", default-features = false, optional = true } +sp-io = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.43", default-features=false } -pallet-balances = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" } +pallet-balances = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43" } -orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.40", default-features = false } +orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.43", default-features = false } gamedao-traits = { package = "gamedao-traits", path = "../traits", default-features = false } # tangram = { package = "module-tangram", path = "../../zero/tangram", default-features = false } [dev-dependencies] -sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.40" } -sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.40" } -pallet-balances = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" } -orml-currencies = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.40", default-features = false } -orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.40", default-features = false } +sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43" } +sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43" } +pallet-balances = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43" } +orml-currencies = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.43", default-features = false } +orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.43", default-features = false } [features] default = ["std"] diff --git a/flow/Cargo.toml b/flow/Cargo.toml index 8534ec9ef..fa2891bc8 100644 --- a/flow/Cargo.toml +++ b/flow/Cargo.toml @@ -11,25 +11,25 @@ repository = "https://github.com/gamedaoco/gamedao-protocol" serde = { version = "1.0.143", default-features = false } codec = { package = "parity-scale-codec", version = "3.2.2", default-features = false, features = ["derive"] } scale-info = { version = "2.1.1", default-features = false, features = ["derive"] } -sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40", default-features = false } -sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40", default-features = false } -frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40", default-features = false } -frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40", default-features = false } -frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40", default-features = false, optional = true } -sp-io = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.40", default-features=false } +sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43", default-features = false } +sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43", default-features = false } +frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43", default-features = false } +frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43", default-features = false } +frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43", default-features = false, optional = true } +sp-io = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.43", default-features=false } -orml-currencies = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.40", default-features = false } -orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.40", default-features = false } -orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.40", default-features = false } +orml-currencies = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.43", default-features = false } +orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.43", default-features = false } +orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.43", default-features = false } gamedao-traits = { package = "gamedao-traits", path = "../traits", default-features = false } gamedao-control = { package = "gamedao-control", path = "../control", default-features = false } [dev-dependencies] -sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.40" } +sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43" } -pallet-timestamp = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" } -pallet-balances = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" } +pallet-timestamp = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43" } +pallet-balances = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43" } gamedao-control = { package = "gamedao-control", path = "../control", default-features = true } diff --git a/sense/Cargo.toml b/sense/Cargo.toml index 8af93cce7..e9e70eb8e 100755 --- a/sense/Cargo.toml +++ b/sense/Cargo.toml @@ -17,16 +17,16 @@ categories = [ serde = { version = "1.0.143", default-features = false } codec = { package = "parity-scale-codec", version = "3.2.2", default-features = false, features = ["derive"] } scale-info = { version = "2.1.1", default-features = false, features = ["derive"] } -sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40", default-features = false } -sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40", default-features = false } -frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40", default-features = false } -frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40", default-features = false } -frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40", default-features = false, optional = true } +sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43", default-features = false } +sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43", default-features = false } +frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43", default-features = false } +frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43", default-features = false } +frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43", default-features = false, optional = true } [dev-dependencies] -sp-io = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.40" } -sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.40" } -sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.40" } +sp-io = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43" } +sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43" } +sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43" } [features] default = ["std"] diff --git a/signal/Cargo.toml b/signal/Cargo.toml index 1936059ec..c1955ce62 100644 --- a/signal/Cargo.toml +++ b/signal/Cargo.toml @@ -18,24 +18,24 @@ categories = [ serde = { version = "1.0.143", default-features = false } codec = { package = "parity-scale-codec", version = "3.2.2", default-features = false, features = ["derive"] } scale-info = { version = "2.1.1", default-features = false, features = ["derive"] } -sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40", default-features = false } -sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40", default-features = false } -frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40", default-features = false } -frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40", default-features = false } -frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40", default-features = false, optional = true } -orml-traits = { git = 'https://github.com/open-web3-stack/open-runtime-module-library', branch= "polkadot-v0.9.40", default-features = false } +sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43", default-features = false } +sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43", default-features = false } +frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43", default-features = false } +frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43", default-features = false } +frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43", default-features = false, optional = true } +orml-traits = { git = 'https://github.com/open-web3-stack/open-runtime-module-library', branch= "polkadot-v0.9.43", default-features = false } gamedao-traits = { package = "gamedao-traits", path = "../traits", default-features = false } -sp-io = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.40", default-features=false } +sp-io = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.43", default-features=false } [dev-dependencies] -sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.40" } -sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.40" } +sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43" } +sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43" } -pallet-balances = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" } -pallet-timestamp = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" } +pallet-balances = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43" } +pallet-timestamp = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43" } -orml-currencies = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.40", default-features = false } -orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.40", default-features = false } +orml-currencies = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.43", default-features = false } +orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch= "polkadot-v0.9.43", default-features = false } gamedao-control = { path = "../control", default-features = true } gamedao-flow = { path = "../flow", default-features = true } diff --git a/traits/Cargo.toml b/traits/Cargo.toml index 8e43ae00f..710b0bde1 100644 --- a/traits/Cargo.toml +++ b/traits/Cargo.toml @@ -12,9 +12,9 @@ repository = "https://github.com/gamedaoco/gamedao-protocol" serde = { version = "1.0.143", default-features = false } codec = { package = "parity-scale-codec", version = "3.2.2", default-features = false, features = ["derive"] } scale-info = { version = "2.1.1", default-features = false, features = ["derive"] } -frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40", default-features = false } -frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40", default-features = false, optional = true } -sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40", default-features = false } +frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43", default-features = false } +frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43", default-features = false, optional = true } +sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43", default-features = false } [features] default = ["std"]