From da60f070053d51b9955dd1f0b11ee467f4d42382 Mon Sep 17 00:00:00 2001 From: recrafter Date: Thu, 9 May 2024 07:29:08 +0200 Subject: [PATCH 01/15] Removing ocw and adding functions --- pallets/game/Cargo.toml | 12 +- pallets/game/src/functions.rs | 386 ++++++++++++++++++++ pallets/game/src/lib.rs | 502 +++----------------------- pallets/game/src/mock.rs | 2 + pallets/game/src/offchain_function.rs | 399 -------------------- pallets/game/src/tests.rs | 115 ++++-- 6 files changed, 541 insertions(+), 875 deletions(-) create mode 100644 pallets/game/src/functions.rs delete mode 100644 pallets/game/src/offchain_function.rs diff --git a/pallets/game/Cargo.toml b/pallets/game/Cargo.toml index 5031ff8..8a95701 100644 --- a/pallets/game/Cargo.toml +++ b/pallets/game/Cargo.toml @@ -22,18 +22,16 @@ serde = { version = "1.0.197", features = ["derive"], optional = true } frame-benchmarking = { version = "4.0.0-dev", default-features = false, optional = true, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } -sp-io = { version = "23.0.0", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0", default-features = false } sp-std = { version = "8.0.0", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0", default-features = false } -sp-core = { version = "21.0.0", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0", default-features = false } -sp-runtime = { version = "24.0.0", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0", default-features = false } pallet-nfts = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.6.0" } enumflags2 = { version = "0.7.7" } -log = { version = "0.4.21", default-features = false } -lite-json = { version = "0.2.0", default-features = false } - [dev-dependencies] +sp-io = { version = "23.0.0", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0", default-features = false } +sp-core = { version = "21.0.0", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0", default-features = false } +sp-runtime = { version = "24.0.0", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0", default-features = false } + pallet-insecure-randomness-collective-flip = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.6.0" } pallet-balances = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.6.0" } @@ -49,8 +47,6 @@ std = [ "pallet-nfts/std", "pallet-balances/std", "sp-std/std", - "log/std", - "lite-json/std", ] runtime-benchmarks = ["frame-benchmarking/runtime-benchmarks"] try-runtime = ["frame-support/try-runtime"] \ No newline at end of file diff --git a/pallets/game/src/functions.rs b/pallets/game/src/functions.rs new file mode 100644 index 0000000..1e6bc82 --- /dev/null +++ b/pallets/game/src/functions.rs @@ -0,0 +1,386 @@ +use crate::*; +use frame_support::pallet_prelude::*; +use frame_system::pallet_prelude::*; + +impl Pallet { + /// Get the account id of the pallet + pub fn account_id() -> AccountIdOf { + ::PalletId::get().into_account_truncating() + } + + /// checks if the signer has enough points to start a game. + pub fn check_enough_points( + signer: AccountIdOf, + game_type: DifficultyLevel, + ) -> DispatchResult { + if game_type == DifficultyLevel::Pro { + ensure!( + Self::users(signer.clone()) + .ok_or(Error::::UserNotRegistered)? + .practise_rounds > 0, + Error::::NoPractise + ); + ensure!( + Self::users(signer).ok_or(Error::::UserNotRegistered)?.points >= 50, + Error::::NotEnoughPoints + ); + } else if game_type == DifficultyLevel::Player { + ensure!( + Self::users(signer.clone()) + .ok_or(Error::::UserNotRegistered)? + .practise_rounds > 0, + Error::::NoPractise + ); + ensure!( + Self::users(signer).ok_or(Error::::UserNotRegistered)?.points >= 25, + Error::::NotEnoughPoints + ); + } else { + ensure!( + Self::users(signer).ok_or(Error::::UserNotRegistered)?.practise_rounds < 5, + Error::::TooManyPractise + ); + } + Ok(()) + } + + /// checks the answer and distributes the rewards accordingly. + pub fn check_result(difference: u16, game_id: u32) -> DispatchResult { + let game_info = GameInfo::::take(game_id).ok_or(Error::::NoActiveGame)?; + if game_info.difficulty == DifficultyLevel::Pro { + match difference { + 0..=10 => { + let (hashi, _) = T::GameRandomness::random(&[game_id as u8]); + let u32_value = u32::from_le_bytes( + hashi.as_ref()[4..8] + .try_into() + .map_err(|_| Error::::ConversionError)?, + ); + let random_number = (u32_value % 8) + .checked_add( + 8 * (Self::current_round() + .checked_sub(1) + .ok_or(Error::::ArithmeticUnderflow)?), + ) + .ok_or(Error::::ArithmeticOverflow)?; + let collection_id: ::CollectionId = + random_number.into(); + let next_item_id = Self::next_color_id(collection_id); + let item_id: ItemId = next_item_id.into(); + let next_item_id = + next_item_id.checked_add(1).ok_or(Error::::ArithmeticOverflow)?; + NextColorId::::insert(collection_id, next_item_id); + pallet_nfts::Pallet::::do_mint( + collection_id.into(), + item_id.into(), + Some(Self::account_id()), + game_info.player.clone(), + Self::default_item_config(), + |_, _| Ok(()), + )?; + let pallet_origin: OriginFor = + RawOrigin::Signed(Self::account_id()).into(); + pallet_nfts::Pallet::::lock_item_transfer( + pallet_origin, + collection_id.into(), + item_id.into(), + )?; + let mut user = Self::users(game_info.player.clone()) + .ok_or(Error::::UserNotRegistered)?; + let color = Self::collection_color(collection_id) + .ok_or(Error::::CollectionUnknown)?; + user.add_nft_color(color.clone())?; + let points = user.calculate_points(color); + user.points = user + .points + .checked_add(points) + .ok_or(Error::::ArithmeticOverflow)?; + Users::::insert(game_info.player.clone(), user.clone()); + if user.has_four_of_all_colors() { + Self::end_game(game_info.player.clone())?; + } + }, + 11..=30 => { + let mut user = Self::users(game_info.player.clone()) + .ok_or(Error::::UserNotRegistered)?; + user.points = + user.points.checked_add(50).ok_or(Error::::ArithmeticOverflow)?; + Users::::insert(game_info.player.clone(), user); + }, + 31..=50 => { + let mut user = Self::users(game_info.player.clone()) + .ok_or(Error::::UserNotRegistered)?; + user.points = + user.points.checked_add(30).ok_or(Error::::ArithmeticOverflow)?; + Users::::insert(game_info.player.clone(), user); + }, + 51..=100 => { + let mut user = Self::users(game_info.player.clone()) + .ok_or(Error::::UserNotRegistered)?; + user.points = + user.points.checked_add(10).ok_or(Error::::ArithmeticOverflow)?; + Users::::insert(game_info.player.clone(), user); + }, + 101..=150 => { + let mut user = Self::users(game_info.player.clone()) + .ok_or(Error::::UserNotRegistered)?; + user.points = + user.points.checked_sub(10).ok_or(Error::::ArithmeticUnderflow)?; + Users::::insert(game_info.player.clone(), user); + }, + 151..=200 => { + let mut user = Self::users(game_info.player.clone()) + .ok_or(Error::::UserNotRegistered)?; + user.points = + user.points.checked_sub(20).ok_or(Error::::ArithmeticUnderflow)?; + Users::::insert(game_info.player.clone(), user); + }, + 201..=250 => { + let mut user = Self::users(game_info.player.clone()) + .ok_or(Error::::UserNotRegistered)?; + user.points = + user.points.checked_sub(30).ok_or(Error::::ArithmeticUnderflow)?; + Users::::insert(game_info.player.clone(), user); + }, + 251..=300 => { + let mut user = Self::users(game_info.player.clone()) + .ok_or(Error::::UserNotRegistered)?; + user.points = + user.points.checked_sub(40).ok_or(Error::::ArithmeticUnderflow)?; + Users::::insert(game_info.player.clone(), user); + }, + _ => { + let mut user = Self::users(game_info.player.clone()) + .ok_or(Error::::UserNotRegistered)?; + user.points = + user.points.checked_sub(50).ok_or(Error::::ArithmeticUnderflow)?; + Users::::insert(game_info.player.clone(), user); + }, + } + } else if game_info.difficulty == DifficultyLevel::Player { + match difference { + 0..=10 => { + let (hashi, _) = T::GameRandomness::random(&[game_id as u8]); + let u32_value = u32::from_le_bytes( + hashi.as_ref()[4..8] + .try_into() + .map_err(|_| Error::::ConversionError)?, + ); + let random_number = (u32_value % 8) + .checked_add( + 8 * (Self::current_round() + .checked_sub(1) + .ok_or(Error::::ArithmeticUnderflow)?), + ) + .ok_or(Error::::ArithmeticOverflow)?; + let collection_id: ::CollectionId = + random_number.into(); + let next_item_id = Self::next_color_id(collection_id); + let item_id: ItemId = next_item_id.into(); + let next_item_id = + next_item_id.checked_add(1).ok_or(Error::::ArithmeticOverflow)?; + NextColorId::::insert(collection_id, next_item_id); + pallet_nfts::Pallet::::do_mint( + collection_id.into(), + item_id.into(), + Some(Self::account_id()), + game_info.player.clone(), + Self::default_item_config(), + |_, _| Ok(()), + )?; + let pallet_origin: OriginFor = + RawOrigin::Signed(Self::account_id()).into(); + pallet_nfts::Pallet::::lock_item_transfer( + pallet_origin, + collection_id.into(), + item_id.into(), + )?; + let mut user = Self::users(game_info.player.clone()) + .ok_or(Error::::UserNotRegistered)?; + let color = Self::collection_color(collection_id) + .ok_or(Error::::CollectionUnknown)?; + user.add_nft_color(color.clone())?; + let points = user.calculate_points(color); + user.points = user + .points + .checked_add(points) + .ok_or(Error::::ArithmeticOverflow)?; + Users::::insert(game_info.player.clone(), user.clone()); + if user.has_four_of_all_colors() { + Self::end_game(game_info.player.clone())?; + } + }, + 11..=30 => { + let mut user = Self::users(game_info.player.clone()) + .ok_or(Error::::UserNotRegistered)?; + user.points = + user.points.checked_add(25).ok_or(Error::::ArithmeticUnderflow)?; + Users::::insert(game_info.player.clone(), user); + }, + 31..=50 => { + let mut user = Self::users(game_info.player.clone()) + .ok_or(Error::::UserNotRegistered)?; + user.points = + user.points.checked_add(15).ok_or(Error::::ArithmeticUnderflow)?; + Users::::insert(game_info.player.clone(), user); + }, + 51..=100 => { + let mut user = Self::users(game_info.player.clone()) + .ok_or(Error::::UserNotRegistered)?; + user.points = + user.points.checked_add(5).ok_or(Error::::ArithmeticUnderflow)?; + Users::::insert(game_info.player.clone(), user); + }, + 101..=150 => { + let mut user = Self::users(game_info.player.clone()) + .ok_or(Error::::UserNotRegistered)?; + user.points = + user.points.checked_sub(5).ok_or(Error::::ArithmeticUnderflow)?; + Users::::insert(game_info.player.clone(), user); + }, + 151..=200 => { + let mut user = Self::users(game_info.player.clone()) + .ok_or(Error::::UserNotRegistered)?; + user.points = + user.points.checked_sub(10).ok_or(Error::::ArithmeticUnderflow)?; + Users::::insert(game_info.player.clone(), user); + }, + 201..=250 => { + let mut user = Self::users(game_info.player.clone()) + .ok_or(Error::::UserNotRegistered)?; + user.points = + user.points.checked_sub(15).ok_or(Error::::ArithmeticUnderflow)?; + Users::::insert(game_info.player.clone(), user); + }, + 251..=300 => { + let mut user = Self::users(game_info.player.clone()) + .ok_or(Error::::UserNotRegistered)?; + user.points = + user.points.checked_sub(20).ok_or(Error::::ArithmeticUnderflow)?; + Users::::insert(game_info.player.clone(), user); + }, + _ => { + let mut user = Self::users(game_info.player.clone()) + .ok_or(Error::::UserNotRegistered)?; + user.points = + user.points.checked_sub(25).ok_or(Error::::ArithmeticUnderflow)?; + Users::::insert(game_info.player.clone(), user); + }, + } + } else { + let mut user = + Self::users(game_info.player.clone()).ok_or(Error::::UserNotRegistered)?; + user.points = user.points.checked_add(5).ok_or(Error::::ArithmeticUnderflow)?; + user.practise_rounds = + user.practise_rounds.checked_add(1).ok_or(Error::::ArithmeticUnderflow)?; + Users::::insert(game_info.player.clone(), user); + } + let user = + Self::users(game_info.player.clone()).ok_or(Error::::UserNotRegistered)?; + Self::update_leaderboard(game_info.player, user.points)?; + Ok(()) + } + + pub fn update_leaderboard(user_id: AccountIdOf, new_points: u32) -> DispatchResult { + let mut leaderboard = Self::leaderboard(); + let leaderboard_size = leaderboard.len(); + + if let Some((_, user_points)) = leaderboard.iter_mut().find(|(id, _)| *id == user_id) { + *user_points = new_points; + leaderboard.sort_by(|a, b| b.1.cmp(&a.1)); + Leaderboard::::put(leaderboard); + return Ok(()); + } + if new_points > 0 && + (leaderboard_size < 10 || + new_points > leaderboard.last().map(|(_, points)| *points).unwrap_or(0)) + { + if leaderboard.len() >= 10 { + leaderboard.pop(); + } + leaderboard + .try_push((user_id, new_points)) + .map_err(|_| Error::::InvalidIndex)?; + leaderboard.sort_by(|a, b| b.1.cmp(&a.1)); + Leaderboard::::put(leaderboard); + } + Ok(()) + } + + pub fn swap_user_points( + nft_holder: AccountIdOf, + collection_id_add: CollectionId, + collection_id_sub: CollectionId, + ) -> DispatchResult { + let mut user = Self::users(nft_holder.clone()).ok_or(Error::::UserNotRegistered)?; + let color_add = + Self::collection_color(collection_id_add).ok_or(Error::::CollectionUnknown)?; + let color_sub = + Self::collection_color(collection_id_sub).ok_or(Error::::CollectionUnknown)?; + user.add_nft_color(color_add.clone())?; + let points = user.calculate_points(color_add); + user.points = user.points.checked_add(points).ok_or(Error::::ArithmeticOverflow)?; + user.sub_nft_color(color_sub.clone())?; + let points = user.subtracting_calculate_points(color_sub); + user.points = user.points.checked_sub(points).ok_or(Error::::ArithmeticOverflow)?; + Users::::insert(nft_holder.clone(), user.clone()); + Self::update_leaderboard(nft_holder.clone(), user.points)?; + if user.has_four_of_all_colors() { + Self::end_game(nft_holder)?; + } + Ok(()) + } + + /// Handles the case if the player did not answer on time. + pub fn no_answer_result(game_info: GameData) -> DispatchResult { + if game_info.difficulty == DifficultyLevel::Pro { + let mut user = + Self::users(game_info.player.clone()).ok_or(Error::::UserNotRegistered)?; + user.points = user.points.checked_sub(10).ok_or(Error::::ArithmeticUnderflow)?; + Users::::insert(game_info.player.clone(), user); + } else if game_info.difficulty == DifficultyLevel::Player { + let mut user = + Self::users(game_info.player.clone()).ok_or(Error::::UserNotRegistered)?; + user.points = user.points.checked_sub(10).ok_or(Error::::ArithmeticUnderflow)?; + Users::::insert(game_info.player.clone(), user); + } else { + } + Ok(()) + } + + pub fn end_game(winner: AccountIdOf) -> DispatchResult { + RoundActive::::put(false); + RoundChampion::::insert(Self::current_round(), winner); + Ok(()) + } + + /// Set the default collection configuration for creating a collection. + pub fn default_collection_config() -> CollectionConfig< + BalanceOf, + BlockNumberFor, + ::CollectionId, + > { + Self::collection_config_from_disabled_settings( + CollectionSetting::DepositRequired.into(), + ) + } + + pub fn collection_config_from_disabled_settings( + settings: BitFlags, + ) -> CollectionConfig< + BalanceOf, + BlockNumberFor, + ::CollectionId, + > { + CollectionConfig { + settings: CollectionSettings::from_disabled(settings), + max_supply: None, + mint_settings: MintSettings::default(), + } + } + + /// Set the default item configuration for minting a nft. + pub fn default_item_config() -> ItemConfig { + ItemConfig { settings: ItemSettings::all_enabled() } + } + } \ No newline at end of file diff --git a/pallets/game/src/lib.rs b/pallets/game/src/lib.rs index ef19d7e..d6587db 100644 --- a/pallets/game/src/lib.rs +++ b/pallets/game/src/lib.rs @@ -15,8 +15,8 @@ mod tests; mod benchmarking; pub mod weights; pub use weights::*; -pub mod offchain_function; pub mod properties; +pub mod functions; type AccountIdOf = ::AccountId; type BalanceOf = <::Currency as Currency< @@ -43,59 +43,6 @@ use enumflags2::BitFlags; use frame_support::traits::Randomness; -use codec::{Decode, Encode}; -use frame_support::traits::Get; -use frame_system::{ - self as system, - offchain::{ - AppCrypto, CreateSignedTransaction, SendSignedTransaction, - Signer, - }, - pallet_prelude::BlockNumberFor, -}; -use lite_json::json::JsonValue; -use scale_info::prelude::string::String; -use sp_core::crypto::KeyTypeId; - -use sp_runtime::{ - offchain::{ - http, - Duration, - }, - BoundedVec, RuntimeDebug, -}; -use sp_std::vec::Vec; - -pub const KEY_TYPE: KeyTypeId = KeyTypeId(*b"btc!"); - -pub mod crypto { - use super::KEY_TYPE; - use sp_core::sr25519::Signature as Sr25519Signature; - use sp_runtime::{ - app_crypto::{app_crypto, sr25519}, - traits::Verify, - MultiSignature, MultiSigner, - }; - app_crypto!(sr25519, KEY_TYPE); - - pub struct TestAuthId; - - impl frame_system::offchain::AppCrypto for TestAuthId { - type RuntimeAppPublic = Public; - type GenericSignature = sp_core::sr25519::Signature; - type GenericPublic = sp_core::sr25519::Public; - } - - // implemented for mock runtime in test - impl frame_system::offchain::AppCrypto<::Signer, Sr25519Signature> - for TestAuthId - { - type RuntimeAppPublic = Public; - type GenericSignature = sp_core::sr25519::Signature; - type GenericPublic = sp_core::sr25519::Public; - } -} - #[frame_support::pallet] pub mod pallet { use super::*; @@ -468,6 +415,8 @@ pub mod pallet { /// The maximum length of leaderboard. #[pallet::constant] type LeaderboardLimit: Get; + #[pallet::constant] + type MaxAdmins: Get; } pub type CollectionId = ::CollectionId; @@ -573,11 +522,16 @@ pub mod pallet { pub type TestProperties = StorageValue<_, BoundedVec, T::MaxProperty>, ValueQuery>; - /// Test for properties + /// Test for properties. #[pallet::storage] #[pallet::getter(fn test_prices)] pub type TestPrices = StorageMap<_, Blake2_128Concat, u32, u32, OptionQuery>; + /// Vector of admins who can register users. + #[pallet::storage] + #[pallet::getter(fn admins)] + pub type Admins = StorageValue<_, BoundedVec, T::MaxAdmins>, ValueQuery>; + #[pallet::event] #[pallet::generate_deposit(pub(super) fn deposit_event)] pub enum Event { @@ -602,8 +556,12 @@ pub mod pallet { OfferWithdrawn { owner: AccountIdOf, offer_id: u32 }, /// An offer has been handled. OfferHandeld { offer_id: u32, offer: Offer }, - /// A new player has been registered + /// A new player has been registered. NewPlayerRegistered { player: AccountIdOf }, + /// A new admins has been added. + NewAdminAdded { new_admin: AccountIdOf }, + /// An admin has been removed. + AdminRemoved { admin: AccountIdOf }, } // Errors inform users that something went wrong. @@ -644,6 +602,12 @@ pub mod pallet { NoActiveRound, /// The player is already registered. PlayerAlreadyRegistered, + /// The account is already an admin. + AccountAlreadyAdmin, + /// This account is not an admin. + NotAdmin, + /// There are already enough admins. + TooManyAdmins, } #[pallet::hooks] @@ -662,14 +626,6 @@ pub mod pallet { }); weight } - - fn offchain_worker(block_number: BlockNumberFor) { - log::info!("Hello World from offchain workers!"); - - let parent_hash = >::block_hash(block_number - 1u32.into()); - log::debug!("Current block: {:?} (parent hash: {:?})", block_number, parent_hash); - - } } #[pallet::call] @@ -727,7 +683,8 @@ pub mod pallet { #[pallet::call_index(1)] #[pallet::weight(::WeightInfo::register_user())] pub fn register_user(origin: OriginFor, player: AccountIdOf) -> DispatchResult { - T::GameOrigin::ensure_origin(origin)?; + let signer = ensure_signed(origin)?; + ensure!(Self::admins().contains(&signer), Error::::NoPermission); ensure!(Self::users(player.clone()).is_none(), Error::::PlayerAlreadyRegistered); let user = User { points: 50, @@ -1114,388 +1071,49 @@ pub mod pallet { TestPrices::::take(id); Ok(()) } - } - impl Pallet { - /// Get the account id of the pallet - pub fn account_id() -> AccountIdOf { - ::PalletId::get().into_account_truncating() - } - - /// checks if the signer has enough points to start a game. - fn check_enough_points( - signer: AccountIdOf, - game_type: DifficultyLevel, - ) -> DispatchResult { - if game_type == DifficultyLevel::Pro { - ensure!( - Self::users(signer.clone()) - .ok_or(Error::::UserNotRegistered)? - .practise_rounds > 0, - Error::::NoPractise - ); - ensure!( - Self::users(signer).ok_or(Error::::UserNotRegistered)?.points >= 50, - Error::::NotEnoughPoints - ); - } else if game_type == DifficultyLevel::Player { - ensure!( - Self::users(signer.clone()) - .ok_or(Error::::UserNotRegistered)? - .practise_rounds > 0, - Error::::NoPractise - ); - ensure!( - Self::users(signer).ok_or(Error::::UserNotRegistered)?.points >= 25, - Error::::NotEnoughPoints - ); - } else { - ensure!( - Self::users(signer).ok_or(Error::::UserNotRegistered)?.practise_rounds < 5, - Error::::TooManyPractise - ); - } - Ok(()) - } - - /// checks the answer and distributes the rewards accordingly. - fn check_result(difference: u16, game_id: u32) -> DispatchResult { - let game_info = GameInfo::::take(game_id).ok_or(Error::::NoActiveGame)?; - if game_info.difficulty == DifficultyLevel::Pro { - match difference { - 0..=10 => { - let (hashi, _) = T::GameRandomness::random(&[game_id as u8]); - let u32_value = u32::from_le_bytes( - hashi.as_ref()[4..8] - .try_into() - .map_err(|_| Error::::ConversionError)?, - ); - let random_number = (u32_value % 8) - .checked_add( - 8 * (Self::current_round() - .checked_sub(1) - .ok_or(Error::::ArithmeticUnderflow)?), - ) - .ok_or(Error::::ArithmeticOverflow)?; - let collection_id: ::CollectionId = - random_number.into(); - let next_item_id = Self::next_color_id(collection_id); - let item_id: ItemId = next_item_id.into(); - let next_item_id = - next_item_id.checked_add(1).ok_or(Error::::ArithmeticOverflow)?; - NextColorId::::insert(collection_id, next_item_id); - pallet_nfts::Pallet::::do_mint( - collection_id.into(), - item_id.into(), - Some(Self::account_id()), - game_info.player.clone(), - Self::default_item_config(), - |_, _| Ok(()), - )?; - let pallet_origin: OriginFor = - RawOrigin::Signed(Self::account_id()).into(); - pallet_nfts::Pallet::::lock_item_transfer( - pallet_origin, - collection_id.into(), - item_id.into(), - )?; - let mut user = Self::users(game_info.player.clone()) - .ok_or(Error::::UserNotRegistered)?; - let color = Self::collection_color(collection_id) - .ok_or(Error::::CollectionUnknown)?; - user.add_nft_color(color.clone())?; - let points = user.calculate_points(color); - user.points = user - .points - .checked_add(points) - .ok_or(Error::::ArithmeticOverflow)?; - Users::::insert(game_info.player.clone(), user.clone()); - if user.has_four_of_all_colors() { - Self::end_game(game_info.player.clone())?; - } - }, - 11..=30 => { - let mut user = Self::users(game_info.player.clone()) - .ok_or(Error::::UserNotRegistered)?; - user.points = - user.points.checked_add(50).ok_or(Error::::ArithmeticOverflow)?; - Users::::insert(game_info.player.clone(), user); - }, - 31..=50 => { - let mut user = Self::users(game_info.player.clone()) - .ok_or(Error::::UserNotRegistered)?; - user.points = - user.points.checked_add(30).ok_or(Error::::ArithmeticOverflow)?; - Users::::insert(game_info.player.clone(), user); - }, - 51..=100 => { - let mut user = Self::users(game_info.player.clone()) - .ok_or(Error::::UserNotRegistered)?; - user.points = - user.points.checked_add(10).ok_or(Error::::ArithmeticOverflow)?; - Users::::insert(game_info.player.clone(), user); - }, - 101..=150 => { - let mut user = Self::users(game_info.player.clone()) - .ok_or(Error::::UserNotRegistered)?; - user.points = - user.points.checked_sub(10).ok_or(Error::::ArithmeticUnderflow)?; - Users::::insert(game_info.player.clone(), user); - }, - 151..=200 => { - let mut user = Self::users(game_info.player.clone()) - .ok_or(Error::::UserNotRegistered)?; - user.points = - user.points.checked_sub(20).ok_or(Error::::ArithmeticUnderflow)?; - Users::::insert(game_info.player.clone(), user); - }, - 201..=250 => { - let mut user = Self::users(game_info.player.clone()) - .ok_or(Error::::UserNotRegistered)?; - user.points = - user.points.checked_sub(30).ok_or(Error::::ArithmeticUnderflow)?; - Users::::insert(game_info.player.clone(), user); - }, - 251..=300 => { - let mut user = Self::users(game_info.player.clone()) - .ok_or(Error::::UserNotRegistered)?; - user.points = - user.points.checked_sub(40).ok_or(Error::::ArithmeticUnderflow)?; - Users::::insert(game_info.player.clone(), user); - }, - _ => { - let mut user = Self::users(game_info.player.clone()) - .ok_or(Error::::UserNotRegistered)?; - user.points = - user.points.checked_sub(50).ok_or(Error::::ArithmeticUnderflow)?; - Users::::insert(game_info.player.clone(), user); - }, - } - } else if game_info.difficulty == DifficultyLevel::Player { - match difference { - 0..=10 => { - let (hashi, _) = T::GameRandomness::random(&[game_id as u8]); - let u32_value = u32::from_le_bytes( - hashi.as_ref()[4..8] - .try_into() - .map_err(|_| Error::::ConversionError)?, - ); - let random_number = (u32_value % 8) - .checked_add( - 8 * (Self::current_round() - .checked_sub(1) - .ok_or(Error::::ArithmeticUnderflow)?), - ) - .ok_or(Error::::ArithmeticOverflow)?; - let collection_id: ::CollectionId = - random_number.into(); - let next_item_id = Self::next_color_id(collection_id); - let item_id: ItemId = next_item_id.into(); - let next_item_id = - next_item_id.checked_add(1).ok_or(Error::::ArithmeticOverflow)?; - NextColorId::::insert(collection_id, next_item_id); - pallet_nfts::Pallet::::do_mint( - collection_id.into(), - item_id.into(), - Some(Self::account_id()), - game_info.player.clone(), - Self::default_item_config(), - |_, _| Ok(()), - )?; - let pallet_origin: OriginFor = - RawOrigin::Signed(Self::account_id()).into(); - pallet_nfts::Pallet::::lock_item_transfer( - pallet_origin, - collection_id.into(), - item_id.into(), - )?; - let mut user = Self::users(game_info.player.clone()) - .ok_or(Error::::UserNotRegistered)?; - let color = Self::collection_color(collection_id) - .ok_or(Error::::CollectionUnknown)?; - user.add_nft_color(color.clone())?; - let points = user.calculate_points(color); - user.points = user - .points - .checked_add(points) - .ok_or(Error::::ArithmeticOverflow)?; - Users::::insert(game_info.player.clone(), user.clone()); - if user.has_four_of_all_colors() { - Self::end_game(game_info.player.clone())?; - } - }, - 11..=30 => { - let mut user = Self::users(game_info.player.clone()) - .ok_or(Error::::UserNotRegistered)?; - user.points = - user.points.checked_add(25).ok_or(Error::::ArithmeticUnderflow)?; - Users::::insert(game_info.player.clone(), user); - }, - 31..=50 => { - let mut user = Self::users(game_info.player.clone()) - .ok_or(Error::::UserNotRegistered)?; - user.points = - user.points.checked_add(15).ok_or(Error::::ArithmeticUnderflow)?; - Users::::insert(game_info.player.clone(), user); - }, - 51..=100 => { - let mut user = Self::users(game_info.player.clone()) - .ok_or(Error::::UserNotRegistered)?; - user.points = - user.points.checked_add(5).ok_or(Error::::ArithmeticUnderflow)?; - Users::::insert(game_info.player.clone(), user); - }, - 101..=150 => { - let mut user = Self::users(game_info.player.clone()) - .ok_or(Error::::UserNotRegistered)?; - user.points = - user.points.checked_sub(5).ok_or(Error::::ArithmeticUnderflow)?; - Users::::insert(game_info.player.clone(), user); - }, - 151..=200 => { - let mut user = Self::users(game_info.player.clone()) - .ok_or(Error::::UserNotRegistered)?; - user.points = - user.points.checked_sub(10).ok_or(Error::::ArithmeticUnderflow)?; - Users::::insert(game_info.player.clone(), user); - }, - 201..=250 => { - let mut user = Self::users(game_info.player.clone()) - .ok_or(Error::::UserNotRegistered)?; - user.points = - user.points.checked_sub(15).ok_or(Error::::ArithmeticUnderflow)?; - Users::::insert(game_info.player.clone(), user); - }, - 251..=300 => { - let mut user = Self::users(game_info.player.clone()) - .ok_or(Error::::UserNotRegistered)?; - user.points = - user.points.checked_sub(20).ok_or(Error::::ArithmeticUnderflow)?; - Users::::insert(game_info.player.clone(), user); - }, - _ => { - let mut user = Self::users(game_info.player.clone()) - .ok_or(Error::::UserNotRegistered)?; - user.points = - user.points.checked_sub(25).ok_or(Error::::ArithmeticUnderflow)?; - Users::::insert(game_info.player.clone(), user); - }, - } - } else { - let mut user = - Self::users(game_info.player.clone()).ok_or(Error::::UserNotRegistered)?; - user.points = user.points.checked_add(5).ok_or(Error::::ArithmeticUnderflow)?; - user.practise_rounds = - user.practise_rounds.checked_add(1).ok_or(Error::::ArithmeticUnderflow)?; - Users::::insert(game_info.player.clone(), user); - } - let user = - Self::users(game_info.player.clone()).ok_or(Error::::UserNotRegistered)?; - Self::update_leaderboard(game_info.player, user.points)?; - Ok(()) - } - - fn update_leaderboard(user_id: AccountIdOf, new_points: u32) -> DispatchResult { - let mut leaderboard = Self::leaderboard(); - let leaderboard_size = leaderboard.len(); - - if let Some((_, user_points)) = leaderboard.iter_mut().find(|(id, _)| *id == user_id) { - *user_points = new_points; - leaderboard.sort_by(|a, b| b.1.cmp(&a.1)); - Leaderboard::::put(leaderboard); - return Ok(()); - } - if new_points > 0 && - (leaderboard_size < 10 || - new_points > leaderboard.last().map(|(_, points)| *points).unwrap_or(0)) - { - if leaderboard.len() >= 10 { - leaderboard.pop(); - } - leaderboard - .try_push((user_id, new_points)) - .map_err(|_| Error::::InvalidIndex)?; - leaderboard.sort_by(|a, b| b.1.cmp(&a.1)); - Leaderboard::::put(leaderboard); - } - Ok(()) - } - - fn swap_user_points( - nft_holder: AccountIdOf, - collection_id_add: CollectionId, - collection_id_sub: CollectionId, - ) -> DispatchResult { - let mut user = Self::users(nft_holder.clone()).ok_or(Error::::UserNotRegistered)?; - let color_add = - Self::collection_color(collection_id_add).ok_or(Error::::CollectionUnknown)?; - let color_sub = - Self::collection_color(collection_id_sub).ok_or(Error::::CollectionUnknown)?; - user.add_nft_color(color_add.clone())?; - let points = user.calculate_points(color_add); - user.points = user.points.checked_add(points).ok_or(Error::::ArithmeticOverflow)?; - user.sub_nft_color(color_sub.clone())?; - let points = user.subtracting_calculate_points(color_sub); - user.points = user.points.checked_sub(points).ok_or(Error::::ArithmeticOverflow)?; - Users::::insert(nft_holder.clone(), user.clone()); - Self::update_leaderboard(nft_holder.clone(), user.points)?; - if user.has_four_of_all_colors() { - Self::end_game(nft_holder)?; - } - Ok(()) - } - - /// Handles the case if the player did not answer on time. - fn no_answer_result(game_info: GameData) -> DispatchResult { - if game_info.difficulty == DifficultyLevel::Pro { - let mut user = - Self::users(game_info.player.clone()).ok_or(Error::::UserNotRegistered)?; - user.points = user.points.checked_sub(10).ok_or(Error::::ArithmeticUnderflow)?; - Users::::insert(game_info.player.clone(), user); - } else if game_info.difficulty == DifficultyLevel::Player { - let mut user = - Self::users(game_info.player.clone()).ok_or(Error::::UserNotRegistered)?; - user.points = user.points.checked_sub(10).ok_or(Error::::ArithmeticUnderflow)?; - Users::::insert(game_info.player.clone(), user); - } else { - } + /// Adds an account to the admins. + /// + /// The origin must be the sudo. + /// + /// Parameters: + /// - `new_admin`: The address of the new account added to the list. + /// + /// Emits `NewAdminAdded` event when succesfful + #[pallet::call_index(12)] + #[pallet::weight(T::DbWeight::get().reads_writes(1, 1))] + pub fn add_to_admins(origin: OriginFor, new_admin: AccountIdOf) -> DispatchResult { + T::GameOrigin::ensure_origin(origin)?; + ensure!( + !Self::admins().contains(&new_admin), + Error::::AccountAlreadyAdmin, + ); + let mut admins = Self::admins(); + Admins::::try_append(new_admin.clone()) + .map_err(|_| Error::::TooManyAdmins)?; + Self::deposit_event(Event::::NewAdminAdded { new_admin }); Ok(()) } - fn end_game(winner: AccountIdOf) -> DispatchResult { - RoundActive::::put(false); - RoundChampion::::insert(Self::current_round(), winner); + /// Removes an account from the admins. + /// + /// The origin must be the sudo. + /// + /// Parameters: + /// - `admin`: The address of the admin removed from the admins. + /// + /// Emits `UserRemoved` event when succesfful + #[pallet::call_index(13)] + #[pallet::weight(T::DbWeight::get().reads_writes(1, 1))] + pub fn remove_from_admins(origin: OriginFor, admin: AccountIdOf) -> DispatchResult { + T::GameOrigin::ensure_origin(origin)?; + ensure!(Self::admins().contains(&admin), Error::::NotAdmin); + let mut admins = Self::admins(); + let index = admins.iter().position(|x| *x == admin).ok_or(Error::::InvalidIndex)?; + admins.remove(index); + Admins::::put(admins); + Self::deposit_event(Event::::AdminRemoved { admin }); Ok(()) } - - /// Set the default collection configuration for creating a collection. - fn default_collection_config() -> CollectionConfig< - BalanceOf, - BlockNumberFor, - ::CollectionId, - > { - Self::collection_config_from_disabled_settings( - CollectionSetting::DepositRequired.into(), - ) - } - - fn collection_config_from_disabled_settings( - settings: BitFlags, - ) -> CollectionConfig< - BalanceOf, - BlockNumberFor, - ::CollectionId, - > { - CollectionConfig { - settings: CollectionSettings::from_disabled(settings), - max_supply: None, - mint_settings: MintSettings::default(), - } - } - - /// Set the default item configuration for minting a nft. - fn default_item_config() -> ItemConfig { - ItemConfig { settings: ItemSettings::all_enabled() } - } } } diff --git a/pallets/game/src/mock.rs b/pallets/game/src/mock.rs index b06cfe7..3c9009e 100644 --- a/pallets/game/src/mock.rs +++ b/pallets/game/src/mock.rs @@ -131,6 +131,7 @@ parameter_types! { pub const GamePalletId: PalletId = PalletId(*b"py/rlxdl"); pub const MaxOngoingGame: u32 = 200; pub const LeaderLimit: u32 = 10; + pub const MaxAdmin: u32 = 10; } /// Configure the pallet-game in pallets/game. @@ -146,6 +147,7 @@ impl pallet_game::Config for Test { type GameRandomness = RandomnessCollectiveFlip; type StringLimit = ConstU32<5000>; type LeaderboardLimit = LeaderLimit; + type MaxAdmins = MaxAdmin; } // Build genesis storage according to the mock runtime. diff --git a/pallets/game/src/offchain_function.rs b/pallets/game/src/offchain_function.rs deleted file mode 100644 index 705d788..0000000 --- a/pallets/game/src/offchain_function.rs +++ /dev/null @@ -1,399 +0,0 @@ -use crate::*; -use frame_support::pallet_prelude::*; - -impl Pallet { - /// Fetch current price and return the result in cents. - pub fn fetch_property() -> Result, http::Error> { - // We want to keep the offchain worker execution time reasonable, so we set a hard-coded - // deadline to 2s to complete the external call. - // You can also wait indefinitely for the response, however you may still get a timeout - // coming from the host machine. - let deadline = sp_io::offchain::timestamp().add(Duration::from_millis(2_000)); - // Initiate an external HTTP GET request. - // This is using high-level wrappers from `sp_runtime`, for the low-level calls that - // you can find in `sp_io`. The API is trying to be similar to `request`, but - // since we are running in a custom WASM execution environment we can't simply - // import the library here. - - let request = http::Request::get( - "https://ipfs.io/ipfs/QmZ3Dn5B2UMuv9PFr1Ba3NGSKft2rwToBKCPaCTCmSab4k?filename=testing_data.json" - ); - - // We set the deadline for sending of the request, note that awaiting response can - // have a separate deadline. Next we send the request, before that it's also possible - // to alter request headers or stream body content in case of non-GET requests. - let pending = request.deadline(deadline).send().map_err(|_| http::Error::IoError)?; - - // The request is already being processed by the host, we are free to do anything - // else in the worker (we can send multiple concurrent requests too). - // At some point however we probably want to check the response though, - // so we can block current thread and wait for it to finish. - // Note that since the request is being driven by the host, we don't have to wait - // for the request to have it complete, we will just not read the response. - let response = pending.try_wait(deadline).map_err(|_| http::Error::DeadlineReached)??; - // Let's check the status code before we proceed to reading the response. - if response.code != 200 { - log::warn!("Unexpected status code: {}", response.code); - return Err(http::Error::Unknown) - } - - // Next we want to fully read the response body and collect it to a vector of bytes. - // Note that the return object allows you to read the body in chunks as well - // with a way to control the deadline. - let body = response.body().collect::>(); - - // Create a str slice from the body. - let body_str = sp_std::str::from_utf8(&body).map_err(|_| { - log::warn!("No UTF8 body"); - http::Error::Unknown - })?; - - let property = match Self::parse_property(body_str) { - Some(property) => Ok(property), - None => { - log::warn!("Unable to extract price from the response: {:?}", body_str); - Err(http::Error::Unknown) - }, - }?; - - // log::warn!("Got property: {:?} cents", price); - - Ok(property) - } - - /// Parse the price from the given JSON string using `lite-json`. - /// - /// Returns `None` when parsing failed or `Some(price in cents)` when parsing is successful. - pub fn parse_property(property_str: &str) -> Option> { - let val = lite_json::parse_json(property_str); - let id = match val.ok()? { - JsonValue::Array(mut arr) => { - // Check if the array has at least one element - if let Some(obj) = arr.pop() { - // Check if the first element is an object - if let JsonValue::Object(obj) = obj { - // Find the 'id' field in the first object - if let Some((_, v)) = - obj.into_iter().find(|(k, _)| k.iter().copied().eq("id".chars())) - { - // Check if the value associated with 'id' is a number - if let JsonValue::Number(number) = v { - number - } else { - return None; - } - } else { - return None; - } - } else { - return None; - } - } else { - return None; - } - }, - _ => return None, - }; - let val = lite_json::parse_json(property_str); - let bedrooms = match val.ok()? { - JsonValue::Array(mut arr) => { - // Check if the array has at least one element - if let Some(obj) = arr.pop() { - // Check if the first element is an object - if let JsonValue::Object(obj) = obj { - // Find the 'bedrooms' field in the first object - if let Some((_, v)) = - obj.into_iter().find(|(k, _)| k.iter().copied().eq("bedrooms".chars())) - { - // Check if the value associated with 'id' is a number - if let JsonValue::Number(number) = v { - number - } else { - return None; - } - } else { - return None; - } - } else { - return None; - } - } else { - return None; - } - }, - _ => return None, - }; - let val = lite_json::parse_json(property_str); - let bathrooms = match val.ok()? { - JsonValue::Array(mut arr) => { - // Check if the array has at least one element - if let Some(obj) = arr.pop() { - // Check if the first element is an object - if let JsonValue::Object(obj) = obj { - // Find the 'bathrooms' field in the first object - if let Some((_, v)) = - obj.into_iter().find(|(k, _)| k.iter().copied().eq("bathrooms".chars())) - { - // Check if the value associated with 'id' is a number - if let JsonValue::Number(number) = v { - number - } else { - return None; - } - } else { - return None; - } - } else { - return None; - } - } else { - return None; - } - }, - _ => return None, - }; - - let val = lite_json::parse_json(property_str); - let summary = match val.ok()? { - JsonValue::Array(mut arr) => { - // Check if the array has at least one element - if let Some(obj) = arr.pop() { - // Check if the first element is an object - if let JsonValue::Object(obj) = obj { - // Find the 'summary' field in the first object - if let Some((_, v)) = - obj.into_iter().find(|(k, _)| k.iter().copied().eq("summary".chars())) - { - // Check if the value associated with 'id' is a number - if let JsonValue::String(number) = v { - number - } else { - return None; - } - } else { - return None; - } - } else { - return None; - } - } else { - return None; - } - }, - _ => return None, - }; - - let val = lite_json::parse_json(property_str); - let property_sub_type = match val.ok()? { - JsonValue::Array(mut arr) => { - // Check if the array has at least one element - if let Some(obj) = arr.pop() { - // Check if the first element is an object - if let JsonValue::Object(obj) = obj { - // Find the 'propertySubType' field in the first object - if let Some((_, v)) = obj - .into_iter() - .find(|(k, _)| k.iter().copied().eq("propertySubType".chars())) - { - // Check if the value associated with 'id' is a number - if let JsonValue::String(number) = v { - number - } else { - return None; - } - } else { - return None; - } - } else { - return None; - } - } else { - return None; - } - }, - _ => return None, - }; - - let val = lite_json::parse_json(property_str); - let first_visible_date = match val.ok()? { - JsonValue::Array(mut arr) => { - // Check if the array has at least one element - if let Some(obj) = arr.pop() { - // Check if the first element is an object - if let JsonValue::Object(obj) = obj { - // Find the 'firstVisibleDate' field in the first object - if let Some((_, v)) = obj - .into_iter() - .find(|(k, _)| k.iter().copied().eq("firstVisibleDate".chars())) - { - // Check if the value associated with 'id' is a number - if let JsonValue::String(number) = v { - number - } else { - return None; - } - } else { - return None; - } - } else { - return None; - } - } else { - return None; - } - }, - _ => return None, - }; - - let val = lite_json::parse_json(property_str); - let display_size = match val.ok()? { - JsonValue::Array(mut arr) => { - // Check if the array has at least one element - if let Some(obj) = arr.pop() { - // Check if the first element is an object - if let JsonValue::Object(obj) = obj { - // Find the 'displaySize' field in the first object - if let Some((_, v)) = obj - .into_iter() - .find(|(k, _)| k.iter().copied().eq("displaySize".chars())) - { - // Check if the value associated with 'id' is a number - if let JsonValue::String(number) = v { - number - } else { - return None; - } - } else { - return None; - } - } else { - return None; - } - } else { - return None; - } - }, - _ => return None, - }; - - let val = lite_json::parse_json(property_str); - let display_address = match val.ok()? { - JsonValue::Array(mut arr) => { - // Check if the array has at least one element - if let Some(obj) = arr.pop() { - // Check if the first element is an object - if let JsonValue::Object(obj) = obj { - // Find the 'displayAddress' field in the first object - if let Some((_, v)) = obj - .into_iter() - .find(|(k, _)| k.iter().copied().eq("displayAddress".chars())) - { - // Check if the value associated with 'id' is a number - if let JsonValue::String(number) = v { - number - } else { - return None; - } - } else { - return None; - } - } else { - return None; - } - } else { - return None; - } - }, - _ => return None, - }; - - let val = lite_json::parse_json(property_str); - let property_images = match val.ok()? { - JsonValue::Array(mut arr) => { - // Check if the array has at least one element - if let Some(obj) = arr.pop() { - // Check if the first element is an object - if let JsonValue::Object(obj) = obj { - // Find the 'propertyImages' field in the first object - if let Some((_, v)) = obj - .into_iter() - .find(|(k, _)| k.iter().copied().eq("propertyImages".chars())) - { - // Check if the value associated with 'id' is a number - if let JsonValue::String(number) = v { - number - } else { - return None; - } - } else { - return None; - } - } else { - return None; - } - } else { - return None; - } - }, - _ => return None, - }; - - let id = id.integer as u32; - let bedrooms = bedrooms.integer as u32; - let bathrooms = bathrooms.integer as u32; - let summary: &str = &summary.iter().collect::(); - let property_sub_type: &str = &property_sub_type.iter().collect::(); - let first_visible_date: &str = &first_visible_date.iter().collect::(); - let display_size: &str = &display_size.iter().collect::(); - let display_address: &str = &display_address.iter().collect::(); - let property_images: &str = &property_images.iter().collect::(); - - let property = PropertyInfoData { - id, - bedrooms, - bathrooms, - summary: summary.as_bytes().to_vec().try_into().unwrap(), - property_sub_type: property_sub_type.as_bytes().to_vec().try_into().unwrap(), - first_visible_date: first_visible_date.as_bytes().to_vec().try_into().unwrap(), - display_size: display_size.as_bytes().to_vec().try_into().unwrap(), - display_address: display_address.as_bytes().to_vec().try_into().unwrap(), - property_images1: property_images.as_bytes().to_vec().try_into().unwrap(), - }; - - Some(property) - - // Some(price.integer as u32 * 100 + (price.fraction / 10_u64.pow(exp)) as u32) - } - - /* pub fn fetch_property_and_send_signed() -> DispatchResult { - let signer = Signer::::all_accounts(); - if !signer.can_sign() { - return Err( - "No local accounts available. Consider adding one via `author_insertKey` RPC.", - ) - } - // Make an external HTTP request to fetch the current price. - // Note this call will block until response is received. - let property = Self::fetch_property().map_err(|_| "Failed to fetch price")?; - - // Using `send_signed_transaction` associated type we create and submit a transaction - // representing the call, we've just created. - // Submit signed will return a vector of results for all accounts that were found in the - // local keystore with expected `KEY_TYPE`. - let results = signer.send_signed_transaction(|_account| { - // Received price is wrapped into a call to `submit_price` public function of this - // pallet. This means that the transaction, when executed, will simply call that - // function passing `price` as an argument. - //Call::submit_price { property: property.clone() } - }); - - for (acc, res) in &results { - match res { - Ok(()) => log::info!("[{:?}] Submitted price of {:?} cents", acc.id, property), - Err(e) => log::error!("[{:?}] Failed to submit transaction: {:?}", acc.id, e), - } - } - - Ok(()) - } */ -} diff --git a/pallets/game/src/tests.rs b/pallets/game/src/tests.rs index cc5034a..b17a830 100644 --- a/pallets/game/src/tests.rs +++ b/pallets/game/src/tests.rs @@ -27,13 +27,56 @@ fn setup_game_fails() { }); } +#[test] +fn add_to_admins_works() { + new_test_ext().execute_with(|| { + System::set_block_number(1); + assert_ok!(GameModule::add_to_admins(RuntimeOrigin::root(), [0; 32].into())); + assert_eq!(GameModule::admins().len(), 1); + }); +} + +#[test] +fn add_to_admins_fails() { + new_test_ext().execute_with(|| { + System::set_block_number(1); + assert_noop!(GameModule::add_to_admins(RuntimeOrigin::signed([0; 32].into()), [0; 32].into()), BadOrigin); + assert_ok!(GameModule::add_to_admins(RuntimeOrigin::root(), [0; 32].into())); + assert_eq!(GameModule::admins().len(), 1); + assert_noop!(GameModule::add_to_admins(RuntimeOrigin::root(), [0; 32].into()), Error::::AccountAlreadyAdmin); + }); +} + +#[test] +fn remove_admins_works() { + new_test_ext().execute_with(|| { + System::set_block_number(1); + assert_ok!(GameModule::add_to_admins(RuntimeOrigin::root(), [0; 32].into())); + assert_eq!(GameModule::admins().len(), 1); + assert_ok!(GameModule::remove_from_admins(RuntimeOrigin::root(), [0; 32].into())); + assert_eq!(GameModule::admins().len(), 0); + }); +} + +#[test] +fn remove_admins_fails() { + new_test_ext().execute_with(|| { + System::set_block_number(1); + assert_noop!(GameModule::remove_from_admins(RuntimeOrigin::root(), [0; 32].into()), Error::::NotAdmin); + assert_ok!(GameModule::add_to_admins(RuntimeOrigin::root(), [0; 32].into())); + assert_eq!(GameModule::admins().len(), 1); + assert_noop!(GameModule::remove_from_admins(RuntimeOrigin::signed([0; 32].into()), [0; 32].into()), BadOrigin); + }); +} + #[test] fn play_game_works() { new_test_ext().execute_with(|| { System::set_block_number(1); assert_ok!(GameModule::setup_game(RuntimeOrigin::root())); assert_eq!(GameModule::test_properties().len(), 4); - assert_ok!(GameModule::register_user(RuntimeOrigin::root(), [0; 32].into())); + assert_ok!(GameModule::add_to_admins(RuntimeOrigin::root(), [4; 32].into())); + assert_ok!(GameModule::register_user(RuntimeOrigin::signed([4; 32].into()), [0; 32].into())); assert_ok!(GameModule::give_points(RuntimeOrigin::root(), [0; 32].into())); practise_round([0; 32].into(), 0); assert_ok!(GameModule::play_game( @@ -64,7 +107,8 @@ fn play_game_fails() { fn play_game_fails_no_active_round() { new_test_ext().execute_with(|| { System::set_block_number(1); - assert_ok!(GameModule::register_user(RuntimeOrigin::root(), [0; 32].into())); + assert_ok!(GameModule::add_to_admins(RuntimeOrigin::root(), [4; 32].into())); + assert_ok!(GameModule::register_user(RuntimeOrigin::signed([4; 32].into()), [0; 32].into())); assert_noop!( GameModule::play_game( RuntimeOrigin::signed([0; 32].into()), @@ -81,7 +125,8 @@ fn play_game_fails_not_enough_points() { System::set_block_number(1); assert_ok!(GameModule::setup_game(RuntimeOrigin::root())); assert_eq!(GameModule::test_properties().len(), 4); - assert_ok!(GameModule::register_user(RuntimeOrigin::root(), [0; 32].into())); + assert_ok!(GameModule::add_to_admins(RuntimeOrigin::root(), [4; 32].into())); + assert_ok!(GameModule::register_user(RuntimeOrigin::signed([4; 32].into()), [0; 32].into())); practise_round([0; 32].into(), 0); assert_ok!(GameModule::play_game( RuntimeOrigin::signed([0; 32].into()), @@ -101,7 +146,8 @@ fn submit_answer_works() { System::set_block_number(1); assert_ok!(GameModule::setup_game(RuntimeOrigin::root())); assert_eq!(GameModule::test_properties().len(), 4); - assert_ok!(GameModule::register_user(RuntimeOrigin::root(), [0; 32].into())); + assert_ok!(GameModule::add_to_admins(RuntimeOrigin::root(), [4; 32].into())); + assert_ok!(GameModule::register_user(RuntimeOrigin::signed([4; 32].into()), [0; 32].into())); practise_round([0; 32].into(), 0); assert_ok!(GameModule::play_game( RuntimeOrigin::signed([0; 32].into()), @@ -128,9 +174,10 @@ fn leaderboard_works() { System::set_block_number(1); assert_ok!(GameModule::setup_game(RuntimeOrigin::root())); assert_eq!(GameModule::test_properties().len(), 4); - assert_ok!(GameModule::register_user(RuntimeOrigin::root(), [0; 32].into())); - assert_ok!(GameModule::register_user(RuntimeOrigin::root(), [1; 32].into())); - assert_ok!(GameModule::register_user(RuntimeOrigin::root(), [2; 32].into())); + assert_ok!(GameModule::add_to_admins(RuntimeOrigin::root(), [4; 32].into())); + assert_ok!(GameModule::register_user(RuntimeOrigin::signed([4; 32].into()), [0; 32].into())); + assert_ok!(GameModule::register_user(RuntimeOrigin::signed([4; 32].into()), [1; 32].into())); + assert_ok!(GameModule::register_user(RuntimeOrigin::signed([4; 32].into()), [2; 32].into())); practise_round([0; 32].into(), 0); practise_round([1; 32].into(), 1); practise_round([2; 32].into(), 2); @@ -154,6 +201,9 @@ fn leaderboard_works() { assert_eq!(GameModule::users::([1; 32].into()).unwrap().points, 80); assert_eq!(GameModule::users::([0; 32].into()).unwrap().points, 70); assert_eq!(GameModule::leaderboard().len(), 3); + assert_eq!(GameModule::leaderboard()[0], ([2; 32].into(), 155)); + assert_eq!(GameModule::leaderboard()[1], ([1; 32].into(), 80)); + assert_eq!(GameModule::leaderboard()[2], ([0; 32].into(), 70)); }); } @@ -176,7 +226,8 @@ fn transfer_of_nft_does_not_work() { System::set_block_number(1); assert_ok!(GameModule::setup_game(RuntimeOrigin::root())); assert_eq!(GameModule::test_properties().len(), 4); - assert_ok!(GameModule::register_user(RuntimeOrigin::root(), [0; 32].into())); + assert_ok!(GameModule::add_to_admins(RuntimeOrigin::root(), [4; 32].into())); + assert_ok!(GameModule::register_user(RuntimeOrigin::signed([4; 32].into()), [0; 32].into())); assert_ok!(GameModule::give_points(RuntimeOrigin::root(), [0; 32].into())); practise_round([0; 32].into(), 0); assert_ok!(GameModule::play_game( @@ -208,7 +259,8 @@ fn list_nft_works() { System::set_block_number(1); assert_ok!(GameModule::setup_game(RuntimeOrigin::root())); assert_eq!(GameModule::test_properties().len(), 4); - assert_ok!(GameModule::register_user(RuntimeOrigin::root(), [0; 32].into())); + assert_ok!(GameModule::add_to_admins(RuntimeOrigin::root(), [4; 32].into())); + assert_ok!(GameModule::register_user(RuntimeOrigin::signed([4; 32].into()), [0; 32].into())); practise_round([0; 32].into(), 0); assert_ok!(GameModule::play_game( RuntimeOrigin::signed([0; 32].into()), @@ -230,7 +282,8 @@ fn list_nft_doesnt_work() { System::set_block_number(1); assert_ok!(GameModule::setup_game(RuntimeOrigin::root())); assert_eq!(GameModule::test_properties().len(), 4); - assert_ok!(GameModule::register_user(RuntimeOrigin::root(), [0; 32].into())); + assert_ok!(GameModule::add_to_admins(RuntimeOrigin::root(), [4; 32].into())); + assert_ok!(GameModule::register_user(RuntimeOrigin::signed([4; 32].into()), [0; 32].into())); practise_round([0; 32].into(), 0); assert_ok!(GameModule::play_game( RuntimeOrigin::signed([0; 32].into()), @@ -253,7 +306,8 @@ fn delist_nft_works() { System::set_block_number(1); assert_ok!(GameModule::setup_game(RuntimeOrigin::root())); assert_eq!(GameModule::test_properties().len(), 4); - assert_ok!(GameModule::register_user(RuntimeOrigin::root(), [0; 32].into())); + assert_ok!(GameModule::add_to_admins(RuntimeOrigin::root(), [4; 32].into())); + assert_ok!(GameModule::register_user(RuntimeOrigin::signed([4; 32].into()), [0; 32].into())); practise_round([0; 32].into(), 0); assert_ok!(GameModule::play_game( RuntimeOrigin::signed([0; 32].into()), @@ -289,7 +343,8 @@ fn delist_nft_doesnt_works() { System::set_block_number(1); assert_ok!(GameModule::setup_game(RuntimeOrigin::root())); assert_eq!(GameModule::test_properties().len(), 4); - assert_ok!(GameModule::register_user(RuntimeOrigin::root(), [0; 32].into())); + assert_ok!(GameModule::add_to_admins(RuntimeOrigin::root(), [4; 32].into())); + assert_ok!(GameModule::register_user(RuntimeOrigin::signed([4; 32].into()), [0; 32].into())); practise_round([0; 32].into(), 0); assert_ok!(GameModule::play_game( RuntimeOrigin::signed([0; 32].into()), @@ -315,8 +370,9 @@ fn make_offer_works() { System::set_block_number(1); assert_ok!(GameModule::setup_game(RuntimeOrigin::root())); assert_eq!(GameModule::test_properties().len(), 4); - assert_ok!(GameModule::register_user(RuntimeOrigin::root(), [0; 32].into())); - assert_ok!(GameModule::register_user(RuntimeOrigin::root(), [1; 32].into())); + assert_ok!(GameModule::add_to_admins(RuntimeOrigin::root(), [4; 32].into())); + assert_ok!(GameModule::register_user(RuntimeOrigin::signed([4; 32].into()), [0; 32].into())); + assert_ok!(GameModule::register_user(RuntimeOrigin::signed([4; 32].into()), [1; 32].into())); practise_round([0; 32].into(), 0); assert_ok!(GameModule::play_game( RuntimeOrigin::signed([0; 32].into()), @@ -347,7 +403,8 @@ fn make_offer_doesnt_works() { System::set_block_number(1); assert_ok!(GameModule::setup_game(RuntimeOrigin::root())); assert_eq!(GameModule::test_properties().len(), 4); - assert_ok!(GameModule::register_user(RuntimeOrigin::root(), [0; 32].into())); + assert_ok!(GameModule::add_to_admins(RuntimeOrigin::root(), [4; 32].into())); + assert_ok!(GameModule::register_user(RuntimeOrigin::signed([4; 32].into()), [0; 32].into())); assert_ok!(GameModule::give_points(RuntimeOrigin::root(), [0; 32].into())); practise_round([0; 32].into(), 0); assert_ok!(GameModule::play_game( @@ -368,8 +425,9 @@ fn withdraw_offer_works() { System::set_block_number(1); assert_ok!(GameModule::setup_game(RuntimeOrigin::root())); assert_eq!(GameModule::test_properties().len(), 4); - assert_ok!(GameModule::register_user(RuntimeOrigin::root(), [0; 32].into())); - assert_ok!(GameModule::register_user(RuntimeOrigin::root(), [1; 32].into())); + assert_ok!(GameModule::add_to_admins(RuntimeOrigin::root(), [4; 32].into())); + assert_ok!(GameModule::register_user(RuntimeOrigin::signed([4; 32].into()), [0; 32].into())); + assert_ok!(GameModule::register_user(RuntimeOrigin::signed([4; 32].into()), [1; 32].into())); practise_round([0; 32].into(), 0); assert_ok!(GameModule::play_game( RuntimeOrigin::signed([0; 32].into()), @@ -402,8 +460,9 @@ fn withdraw_offer_fails() { System::set_block_number(1); assert_ok!(GameModule::setup_game(RuntimeOrigin::root())); assert_eq!(GameModule::test_properties().len(), 4); - assert_ok!(GameModule::register_user(RuntimeOrigin::root(), [0; 32].into())); - assert_ok!(GameModule::register_user(RuntimeOrigin::root(), [1; 32].into())); + assert_ok!(GameModule::add_to_admins(RuntimeOrigin::root(), [4; 32].into())); + assert_ok!(GameModule::register_user(RuntimeOrigin::signed([4; 32].into()), [0; 32].into())); + assert_ok!(GameModule::register_user(RuntimeOrigin::signed([4; 32].into()), [1; 32].into())); practise_round([0; 32].into(), 0); assert_ok!(GameModule::play_game( RuntimeOrigin::signed([0; 32].into()), @@ -442,8 +501,9 @@ fn handle_offer_accept_works() { System::set_block_number(1); assert_ok!(GameModule::setup_game(RuntimeOrigin::root())); assert_eq!(GameModule::test_properties().len(), 4); - assert_ok!(GameModule::register_user(RuntimeOrigin::root(), [0; 32].into())); - assert_ok!(GameModule::register_user(RuntimeOrigin::root(), [1; 32].into())); + assert_ok!(GameModule::add_to_admins(RuntimeOrigin::root(), [4; 32].into())); + assert_ok!(GameModule::register_user(RuntimeOrigin::signed([4; 32].into()), [0; 32].into())); + assert_ok!(GameModule::register_user(RuntimeOrigin::signed([4; 32].into()), [1; 32].into())); practise_round([0; 32].into(), 0); assert_ok!(GameModule::play_game( RuntimeOrigin::signed([0; 32].into()), @@ -527,8 +587,9 @@ fn handle_offer_reject_works() { System::set_block_number(1); assert_ok!(GameModule::setup_game(RuntimeOrigin::root())); assert_eq!(GameModule::test_properties().len(), 4); - assert_ok!(GameModule::register_user(RuntimeOrigin::root(), [0; 32].into())); - assert_ok!(GameModule::register_user(RuntimeOrigin::root(), [1; 32].into())); + assert_ok!(GameModule::add_to_admins(RuntimeOrigin::root(), [4; 32].into())); + assert_ok!(GameModule::register_user(RuntimeOrigin::signed([4; 32].into()), [0; 32].into())); + assert_ok!(GameModule::register_user(RuntimeOrigin::signed([4; 32].into()), [1; 32].into())); practise_round([0; 32].into(), 0); assert_ok!(GameModule::play_game( RuntimeOrigin::signed([0; 32].into()), @@ -580,8 +641,9 @@ fn handle_offer_doesnt_works() { System::set_block_number(1); assert_ok!(GameModule::setup_game(RuntimeOrigin::root())); assert_eq!(GameModule::test_properties().len(), 4); - assert_ok!(GameModule::register_user(RuntimeOrigin::root(), [0; 32].into())); - assert_ok!(GameModule::register_user(RuntimeOrigin::root(), [1; 32].into())); + assert_ok!(GameModule::add_to_admins(RuntimeOrigin::root(), [4; 32].into())); + assert_ok!(GameModule::register_user(RuntimeOrigin::signed([4; 32].into()), [0; 32].into())); + assert_ok!(GameModule::register_user(RuntimeOrigin::signed([4; 32].into()), [1; 32].into())); practise_round([0; 32].into(), 0); assert_ok!(GameModule::play_game( RuntimeOrigin::signed([0; 32].into()), @@ -618,7 +680,8 @@ fn play_multiple_rounds_works() { System::set_block_number(1); assert_ok!(GameModule::setup_game(RuntimeOrigin::root())); assert_eq!(GameModule::test_properties().len(), 4); - assert_ok!(GameModule::register_user(RuntimeOrigin::root(), [0; 32].into())); + assert_ok!(GameModule::add_to_admins(RuntimeOrigin::root(), [4; 32].into())); + assert_ok!(GameModule::register_user(RuntimeOrigin::signed([4; 32].into()), [0; 32].into())); practise_round([0; 32].into(), 0); for x in 1..=20 { assert_ok!(GameModule::play_game( From b3b929ae75835a27062fc6118afb18a03bab175f Mon Sep 17 00:00:00 2001 From: recrafter Date: Thu, 9 May 2024 07:31:35 +0200 Subject: [PATCH 02/15] Adjusting runtime and node --- Cargo.lock | 20 -------------------- node/src/service.rs | 17 ----------------- runtime/src/lib.rs | 2 ++ 3 files changed, 2 insertions(+), 37 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6a89d4f..e7fa102 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4081,24 +4081,6 @@ dependencies = [ "keystream", ] -[[package]] -name = "lite-json" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd0e787ffe1153141a0f6f6d759fdf1cc34b1226e088444523812fd412a5cca2" -dependencies = [ - "lite-parser", -] - -[[package]] -name = "lite-parser" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3d5f9dc37c52d889a21fd701983d02bb6a84f852c5140a6c80ef4557f7dc29e" -dependencies = [ - "paste", -] - [[package]] name = "lock_api" version = "0.4.11" @@ -4913,8 +4895,6 @@ dependencies = [ "frame-benchmarking", "frame-support", "frame-system", - "lite-json", - "log", "pallet-balances", "pallet-insecure-randomness-collective-flip", "pallet-nfts", diff --git a/node/src/service.rs b/node/src/service.rs index df88269..c4a2b2f 100644 --- a/node/src/service.rs +++ b/node/src/service.rs @@ -66,23 +66,6 @@ pub fn new_partial( )?; let client = Arc::new(client); - let keystore = keystore_container.keystore(); - if config.offchain_worker.enabled { - // Initialize seed for signing transaction using off-chain workers. This is a convenience - // so learners can see the transactions submitted simply running the node. - // Typically these keys should be inserted with RPC calls to `author_insertKey`. - - // For pallet-ocw - sp_keystore::Keystore::sr25519_generate_new( - &*keystore, - node_template_runtime::pallet_game::KEY_TYPE, - Some("//Alice"), - ) - .expect("Creating key with account Alice should succeed."); - - // For pallet-example-offchain-worker - } - let telemetry = telemetry.map(|(worker, telemetry)| { task_manager.spawn_handle().spawn("telemetry", None, worker.run()); telemetry diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 0718001..8babf00 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -269,6 +269,7 @@ parameter_types! { pub const GamePalletId: PalletId = PalletId(*b"py/rlxdl"); pub const MaxOngoingGame: u32 = 200; pub const LeaderLimit: u32 = 10; + pub const MaxAdmin: u32 = 10; } /// Configure the pallet-game in pallets/game. @@ -284,6 +285,7 @@ impl pallet_game::Config for Runtime { type GameRandomness = RandomnessCollectiveFlip; type StringLimit = StringLimit; type LeaderboardLimit = LeaderLimit; + type MaxAdmins = MaxAdmin; } parameter_types! { From 403e902fad1597c99d6a54200d38863da4945f42 Mon Sep 17 00:00:00 2001 From: recrafter Date: Thu, 9 May 2024 07:45:46 +0200 Subject: [PATCH 03/15] Fixing things --- pallets/game/src/lib.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pallets/game/src/lib.rs b/pallets/game/src/lib.rs index d6587db..6a2fc89 100644 --- a/pallets/game/src/lib.rs +++ b/pallets/game/src/lib.rs @@ -734,7 +734,7 @@ pub mod pallet { ensure!(Self::round_active(), Error::::NoActiveRound); let mut user = Self::users(signer.clone()).ok_or(Error::::UserNotRegistered)?; if Self::current_round() != user.last_played_round { - user.nfts == Default::default(); + user.nfts = Default::default(); user.last_played_round = user.last_played_round.checked_add(1).ok_or(Error::::ArithmeticOverflow)?; Users::::insert(signer.clone(), user); } @@ -805,7 +805,7 @@ pub mod pallet { .checked_div(result as i32) .ok_or(Error::::DivisionError)? .abs(); - Self::check_result(difference_value.try_into().unwrap(), game_id)?; + Self::check_result(difference_value.try_into().map_err(|_| Error::::ConversionError)?, game_id)?; Self::deposit_event(Event::::AnswerSubmitted { player: signer, game_id }); Ok(()) } @@ -1088,7 +1088,6 @@ pub mod pallet { !Self::admins().contains(&new_admin), Error::::AccountAlreadyAdmin, ); - let mut admins = Self::admins(); Admins::::try_append(new_admin.clone()) .map_err(|_| Error::::TooManyAdmins)?; Self::deposit_event(Event::::NewAdminAdded { new_admin }); From 548dc022126a87e83a761b76e927efdf48bdc3ea Mon Sep 17 00:00:00 2001 From: recrafter Date: Fri, 10 May 2024 08:41:48 +0200 Subject: [PATCH 04/15] Extending tests and adding benchmarks --- pallets/game/src/benchmarking.rs | 76 ++++++++++-- pallets/game/src/functions.rs | 5 +- pallets/game/src/lib.rs | 51 ++++++-- pallets/game/src/mock.rs | 3 + pallets/game/src/tests.rs | 24 ++++ pallets/game/src/weights.rs | 204 ++++++++++++++++++++++--------- runtime/src/lib.rs | 6 +- 7 files changed, 290 insertions(+), 79 deletions(-) diff --git a/pallets/game/src/benchmarking.rs b/pallets/game/src/benchmarking.rs index cd436d5..b3ccbc3 100644 --- a/pallets/game/src/benchmarking.rs +++ b/pallets/game/src/benchmarking.rs @@ -10,11 +10,14 @@ use frame_support::{ traits::{OnFinalize, OnInitialize}, }; use frame_system::RawOrigin; +use pallet_nfts::Pallet as Nfts; fn create_setup() -> T::AccountId { let caller: T::AccountId = whitelisted_caller(); + let admin: T::AccountId = account("admin", 0, 0); assert_ok!(GameModule::::setup_game(RawOrigin::Root.into())); - assert_ok!(GameModule::::register_user(RawOrigin::Root.into(), caller.clone())); + assert_ok!(GameModule::::add_to_admins(RawOrigin::Root.into(), admin.clone())); + assert_ok!(GameModule::::register_user(RawOrigin::Signed(admin).into(), caller.clone())); caller } @@ -42,10 +45,12 @@ mod benchmarks { #[benchmark] fn register_user() { - let caller: T::AccountId = whitelisted_caller(); + let caller: T::AccountId = account("caller", 0, 0); assert_ok!(GameModule::::setup_game(RawOrigin::Root.into())); + let admin: T::AccountId = account("admin", 0, 0); + assert_ok!(GameModule::::add_to_admins(RawOrigin::Root.into(), admin.clone())); #[extrinsic_call] - register_user(RawOrigin::Root, caller); + register_user(RawOrigin::Signed(admin), caller); } #[benchmark] @@ -137,14 +142,16 @@ mod benchmarks { 0.into(), 0.into() )); - let caller2 = create_setup::(); + let caller2: T::AccountId = account("caller2", 0, 0); + let admin: T::AccountId = account("admin", 0, 0); + assert_ok!(GameModule::::register_user(RawOrigin::Signed(admin).into(), caller2.clone())); practise_round::(caller2.clone(), 2); assert_ok!(GameModule::::play_game( - RawOrigin::Signed(caller.clone()).into(), + RawOrigin::Signed(caller2.clone()).into(), crate::DifficultyLevel::Player )); assert_ok!(GameModule::::submit_answer( - RawOrigin::Signed(caller.clone()).into(), + RawOrigin::Signed(caller2.clone()).into(), 220000, 3 )); @@ -171,7 +178,9 @@ mod benchmarks { 0.into(), 0.into() )); - let caller2 = create_setup::(); + let caller2: T::AccountId = account("caller2", 0, 0); + let admin: T::AccountId = account("admin", 0, 0); + assert_ok!(GameModule::::register_user(RawOrigin::Signed(admin).into(), caller2.clone())); practise_round::(caller2.clone(), 2); assert_ok!(GameModule::::play_game( RawOrigin::Signed(caller2.clone()).into(), @@ -194,7 +203,58 @@ mod benchmarks { )); #[extrinsic_call] - handle_offer(RawOrigin::Signed(caller2), 0, crate::Offer::Accept); + handle_offer(RawOrigin::Signed(caller), 0, crate::Offer::Accept); + } + + #[benchmark] + fn add_property() { + assert_ok!(GameModule::::setup_game(RawOrigin::Root.into())); + let new_property = PropertyInfoData { + id: 147229391, + bedrooms: 2, + bathrooms: 1, + summary: "Superb 2 double bedroom ground floor purpose-built apartment with sole use of garden. Directly opposite Hackney Downs Park, within walking distance of Clapton, Hackney Downs & Rectory Rd Stations. Benefitting from; 2 double bedrooms, fitted kitchen/diner, modern shower/WC, separate lounge with di...".as_bytes().to_vec().try_into().unwrap(), + property_sub_type: "Flat".as_bytes().to_vec().try_into().unwrap(), + first_visible_date: "2024-04-24T16:39:27Z".as_bytes().to_vec().try_into().unwrap(), + display_size: "".as_bytes().to_vec().try_into().unwrap(), + display_address: "St Peters Street, Islington".as_bytes().to_vec().try_into().unwrap(), + property_images1: "https://media.rightmove.co.uk/dir/crop/10:9-16:9/56k/55489/146480642/55489_2291824_IMG_00_0000_max_476x317.jpeg".as_bytes().to_vec().try_into().unwrap(), + }; + #[extrinsic_call] + add_property(RawOrigin::Root, new_property, 200000); + } + + #[benchmark] + fn remove_property() { + assert_ok!(GameModule::::setup_game(RawOrigin::Root.into())); + #[extrinsic_call] + remove_property(RawOrigin::Root, 146480642); + } + + #[benchmark] + fn add_to_admins() { + assert_ok!(GameModule::::setup_game(RawOrigin::Root.into())); + let new_admin: T::AccountId = account("new_admin", 0, 0); + #[extrinsic_call] + add_to_admins(RawOrigin::Root, new_admin); + } + + #[benchmark] + fn remove_from_admins() { + assert_ok!(GameModule::::setup_game(RawOrigin::Root.into())); + let new_admin: T::AccountId = account("new_admin", 0, 0); + assert_ok!(GameModule::::add_to_admins(RawOrigin::Root.into(), new_admin.clone())); + #[extrinsic_call] + remove_from_admins(RawOrigin::Root, new_admin); + } + + #[benchmark] + fn request_token() { + let caller = create_setup::(); + current_block::(30u32.into()); + current_block::(100801u32.into()); + #[extrinsic_call] + request_token(RawOrigin::Signed(caller)); } impl_benchmark_test_suite!(GameModule, crate::mock::new_test_ext(), crate::mock::Test); diff --git a/pallets/game/src/functions.rs b/pallets/game/src/functions.rs index 1e6bc82..792d517 100644 --- a/pallets/game/src/functions.rs +++ b/pallets/game/src/functions.rs @@ -336,14 +336,13 @@ impl Pallet { if game_info.difficulty == DifficultyLevel::Pro { let mut user = Self::users(game_info.player.clone()).ok_or(Error::::UserNotRegistered)?; - user.points = user.points.checked_sub(10).ok_or(Error::::ArithmeticUnderflow)?; + user.points = user.points.checked_sub(50).ok_or(Error::::ArithmeticUnderflow)?; Users::::insert(game_info.player.clone(), user); } else if game_info.difficulty == DifficultyLevel::Player { let mut user = Self::users(game_info.player.clone()).ok_or(Error::::UserNotRegistered)?; - user.points = user.points.checked_sub(10).ok_or(Error::::ArithmeticUnderflow)?; + user.points = user.points.checked_sub(25).ok_or(Error::::ArithmeticUnderflow)?; Users::::insert(game_info.player.clone(), user); - } else { } Ok(()) } diff --git a/pallets/game/src/lib.rs b/pallets/game/src/lib.rs index 6a2fc89..62048b0 100644 --- a/pallets/game/src/lib.rs +++ b/pallets/game/src/lib.rs @@ -24,7 +24,7 @@ type BalanceOf = <::Currency as Currency< >>::Balance; use frame_support::{ - traits::{Currency, Incrementable}, + traits::{Currency, Incrementable, ReservableCurrency}, PalletId, }; @@ -166,16 +166,17 @@ pub mod pallet { #[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))] #[derive(Encode, Decode, Clone, PartialEq, Eq, MaxEncodedLen, RuntimeDebug, TypeInfo)] #[scale_info(skip_type_params(T))] - pub struct User { + pub struct User { pub points: u32, pub wins: u32, pub losses: u32, pub practise_rounds: u8, pub last_played_round: u32, + pub next_token_request: BlockNumberFor, pub nfts: CollectedColors, } - impl User { + impl User { pub fn add_nft_color(&mut self, color: NftColor) -> DispatchResult { self.nfts.add_nft_color(color)?; Ok(()) @@ -378,6 +379,8 @@ pub mod pallet { { /// Because this pallet emits events, it depends on the runtime's definition of an event. type RuntimeEvent: From> + IsType<::RuntimeEvent>; + /// The currency type. + type Currency: Currency> + ReservableCurrency>; /// Type representing the weight of this pallet type WeightInfo: WeightInfo; /// Origin who can create a new game. @@ -417,6 +420,8 @@ pub mod pallet { type LeaderboardLimit: Get; #[pallet::constant] type MaxAdmins: Get; + /// The amount of time until player can request more token. + type RequestLimit: Get>; } pub type CollectionId = ::CollectionId; @@ -477,7 +482,7 @@ pub mod pallet { /// Mapping of an account id to the user data of the account. #[pallet::storage] #[pallet::getter(fn users)] - pub type Users = StorageMap<_, Blake2_128Concat, AccountIdOf, User, OptionQuery>; + pub type Users = StorageMap<_, Blake2_128Concat, AccountIdOf, User, OptionQuery>; /// Mapping of game id to the game info. #[pallet::storage] @@ -562,6 +567,8 @@ pub mod pallet { NewAdminAdded { new_admin: AccountIdOf }, /// An admin has been removed. AdminRemoved { admin: AccountIdOf }, + /// The user received token. + TokenReceived { player: AccountIdOf }, } // Errors inform users that something went wrong. @@ -608,6 +615,8 @@ pub mod pallet { NotAdmin, /// There are already enough admins. TooManyAdmins, + /// The user has to wait to request token. + CantRequestToken, } #[pallet::hooks] @@ -686,14 +695,18 @@ pub mod pallet { let signer = ensure_signed(origin)?; ensure!(Self::admins().contains(&signer), Error::::NoPermission); ensure!(Self::users(player.clone()).is_none(), Error::::PlayerAlreadyRegistered); + let current_block_number = >::block_number(); + let next_request = current_block_number.saturating_add(::RequestLimit::get()); let user = User { points: 50, wins: Default::default(), losses: Default::default(), practise_rounds: Default::default(), last_played_round: Default::default(), + next_token_request: next_request, nfts: CollectedColors::default(), }; + ::Currency::make_free_balance_be(&player, 10u32.try_into().map_err(|_| Error::::ConversionError)?); Users::::insert(player.clone(), user); Self::deposit_event(Event::::NewPlayerRegistered { player }); Ok(()) @@ -978,7 +991,7 @@ pub mod pallet { /// /// Emits `OfferHandeld` event when succesfful. #[pallet::call_index(9)] - #[pallet::weight(T::DbWeight::get().reads_writes(1, 1))] + #[pallet::weight(::WeightInfo::handle_offer())] pub fn handle_offer(origin: OriginFor, offer_id: u32, offer: Offer) -> DispatchResult { let signer = ensure_signed(origin.clone())?; let offer_details = Offers::::take(offer_id).ok_or(Error::::OfferDoesNotExist)?; @@ -1047,7 +1060,7 @@ pub mod pallet { /// - `property`: The new property that will be added. /// - `price`: The price of the property that will be added. #[pallet::call_index(10)] - #[pallet::weight(T::DbWeight::get().reads_writes(1, 1))] + #[pallet::weight(::WeightInfo::add_property())] pub fn add_property(origin: OriginFor, property: PropertyInfoData, price: u32) -> DispatchResult { T::GameOrigin::ensure_origin(origin)?; TestProperties::::try_append(property.clone()).map_err(|_| Error::::TooManyTest)?; @@ -1062,7 +1075,7 @@ pub mod pallet { /// Parameters: /// - `id`: The id of the property that should be removed. #[pallet::call_index(11)] - #[pallet::weight(T::DbWeight::get().reads_writes(1, 1))] + #[pallet::weight(::WeightInfo::remove_property())] pub fn remove_property(origin: OriginFor, id: u32) -> DispatchResult { T::GameOrigin::ensure_origin(origin)?; let mut properties = TestProperties::::take(); @@ -1081,7 +1094,7 @@ pub mod pallet { /// /// Emits `NewAdminAdded` event when succesfful #[pallet::call_index(12)] - #[pallet::weight(T::DbWeight::get().reads_writes(1, 1))] + #[pallet::weight(::WeightInfo::add_to_admins())] pub fn add_to_admins(origin: OriginFor, new_admin: AccountIdOf) -> DispatchResult { T::GameOrigin::ensure_origin(origin)?; ensure!( @@ -1103,7 +1116,7 @@ pub mod pallet { /// /// Emits `UserRemoved` event when succesfful #[pallet::call_index(13)] - #[pallet::weight(T::DbWeight::get().reads_writes(1, 1))] + #[pallet::weight(::WeightInfo::remove_from_admins())] pub fn remove_from_admins(origin: OriginFor, admin: AccountIdOf) -> DispatchResult { T::GameOrigin::ensure_origin(origin)?; ensure!(Self::admins().contains(&admin), Error::::NotAdmin); @@ -1114,5 +1127,25 @@ pub mod pallet { Self::deposit_event(Event::::AdminRemoved { admin }); Ok(()) } + + /// Lets the player request token to play. + /// + /// The origin must be Signed and the sender must have sufficient funds free. + /// + /// Emits `TokenReceived` event when succesfful. + #[pallet::call_index(14)] + #[pallet::weight(::WeightInfo::request_token())] + pub fn request_token(origin: OriginFor) -> DispatchResult { + let signer = ensure_signed(origin)?; + let current_block_number = >::block_number(); + let mut user = Self::users(signer.clone()).ok_or(Error::::UserNotRegistered)?; + ensure!(user.next_token_request < current_block_number, Error::::CantRequestToken); + let next_request = current_block_number.saturating_add(::RequestLimit::get()); + user.next_token_request = next_request; + ::Currency::make_free_balance_be(&signer, 10u32.try_into().map_err(|_| Error::::ConversionError)?); + Users::::insert(signer.clone(), user); + Self::deposit_event(Event::::TokenReceived { player: signer }); + Ok(()) + } } } diff --git a/pallets/game/src/mock.rs b/pallets/game/src/mock.rs index 3c9009e..e5ace75 100644 --- a/pallets/game/src/mock.rs +++ b/pallets/game/src/mock.rs @@ -132,11 +132,13 @@ parameter_types! { pub const MaxOngoingGame: u32 = 200; pub const LeaderLimit: u32 = 10; pub const MaxAdmin: u32 = 10; + pub const RequestLimits: BlockNumber = 180; } /// Configure the pallet-game in pallets/game. impl pallet_game::Config for Test { type RuntimeEvent = RuntimeEvent; + type Currency = Balances; type WeightInfo = pallet_game::weights::SubstrateWeight; type GameOrigin = EnsureRoot; type CollectionId = u32; @@ -148,6 +150,7 @@ impl pallet_game::Config for Test { type StringLimit = ConstU32<5000>; type LeaderboardLimit = LeaderLimit; type MaxAdmins = MaxAdmin; + type RequestLimit = RequestLimits; } // Build genesis storage according to the mock runtime. diff --git a/pallets/game/src/tests.rs b/pallets/game/src/tests.rs index b17a830..69289d6 100644 --- a/pallets/game/src/tests.rs +++ b/pallets/game/src/tests.rs @@ -733,3 +733,27 @@ fn remove_property_works() { assert_eq!(GameModule::test_properties().len(), 3); }); } + +#[test] +fn request_token_works() { + new_test_ext().execute_with(|| { + System::set_block_number(1); + assert_ok!(GameModule::setup_game(RuntimeOrigin::root())); + assert_ok!(GameModule::add_to_admins(RuntimeOrigin::root(), [4; 32].into())); + assert_ok!(GameModule::register_user(RuntimeOrigin::signed([4; 32].into()), [0; 32].into())); + System::set_block_number(100802); + assert_ok!(GameModule::request_token(RuntimeOrigin::signed([0; 32].into()))); + }); +} + +#[test] +fn request_token_doesnt_works() { + new_test_ext().execute_with(|| { + System::set_block_number(1); + assert_ok!(GameModule::setup_game(RuntimeOrigin::root())); + assert_noop!(GameModule::request_token(RuntimeOrigin::signed([0; 32].into())), Error::::UserNotRegistered); + assert_ok!(GameModule::add_to_admins(RuntimeOrigin::root(), [4; 32].into())); + assert_ok!(GameModule::register_user(RuntimeOrigin::signed([4; 32].into()), [0; 32].into())); + assert_noop!(GameModule::request_token(RuntimeOrigin::signed([0; 32].into())), Error::::CantRequestToken); + }); +} diff --git a/pallets/game/src/weights.rs b/pallets/game/src/weights.rs index 2f31c37..5fbe9a4 100644 --- a/pallets/game/src/weights.rs +++ b/pallets/game/src/weights.rs @@ -2,7 +2,7 @@ //! Autogenerated weights for `pallet_game` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2024-05-05, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2024-05-10, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` //! HOSTNAME: `LAPTOP-DFFNONK6`, CPU: `11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz` //! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: 1024 @@ -43,6 +43,11 @@ pub trait WeightInfo { fn delist_nft() -> Weight; fn make_offer() -> Weight; fn handle_offer() -> Weight; + fn add_property() -> Weight; + fn remove_property() -> Weight; + fn add_to_admins() -> Weight; + fn remove_from_admins() -> Weight; + fn request_token() -> Weight; } /// Weight functions for `pallet_game`. @@ -55,8 +60,14 @@ impl WeightInfo for SubstrateWeight { /// Storage: `System::Account` (r:1 w:1) /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) /// Storage: `GameModule::TestProperties` (r:1 w:1) - /// Proof: `GameModule::TestProperties` (`max_values`: Some(1), `max_size`: Some(2002002), added: 2002497, mode: `MaxEncodedLen`) - /// Storage: `GameModule::TestPrices` (r:0 w:4) + /// Proof: `GameModule::TestProperties` (`max_values`: Some(1), `max_size`: Some(3002402), added: 3002897, mode: `MaxEncodedLen`) + /// Storage: `GameModule::CurrentRound` (r:1 w:1) + /// Proof: `GameModule::CurrentRound` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `GameModule::RoundActive` (r:0 w:1) + /// Proof: `GameModule::RoundActive` (`max_values`: Some(1), `max_size`: Some(1), added: 496, mode: `MaxEncodedLen`) + /// Storage: `GameModule::CollectionColor` (r:0 w:8) + /// Proof: `GameModule::CollectionColor` (`max_values`: None, `max_size`: Some(21), added: 2496, mode: `MaxEncodedLen`) + /// Storage: `GameModule::TestPrices` (r:0 w:3) /// Proof: `GameModule::TestPrices` (`max_values`: None, `max_size`: Some(24), added: 2499, mode: `MaxEncodedLen`) /// Storage: `Nfts::CollectionRoleOf` (r:0 w:8) /// Proof: `Nfts::CollectionRoleOf` (`max_values`: None, `max_size`: Some(69), added: 2544, mode: `MaxEncodedLen`) @@ -67,38 +78,47 @@ impl WeightInfo for SubstrateWeight { fn setup_game() -> Weight { // Proof Size summary in bytes: // Measured: `166` - // Estimated: `2003487` - // Minimum execution time: 282_362_000 picoseconds. - Weight::from_parts(348_148_000, 0) - .saturating_add(Weight::from_parts(0, 2003487)) - .saturating_add(T::DbWeight::get().reads(11)) - .saturating_add(T::DbWeight::get().writes(39)) + // Estimated: `3003887` + // Minimum execution time: 217_169_000 picoseconds. + Weight::from_parts(248_356_000, 0) + .saturating_add(Weight::from_parts(0, 3003887)) + .saturating_add(T::DbWeight::get().reads(12)) + .saturating_add(T::DbWeight::get().writes(48)) } - /// Storage: `GameModule::Users` (r:0 w:1) - /// Proof: `GameModule::Users` (`max_values`: None, `max_size`: Some(61), added: 2536, mode: `MaxEncodedLen`) + /// Storage: `GameModule::Admins` (r:1 w:0) + /// Proof: `GameModule::Admins` (`max_values`: Some(1), `max_size`: Some(321), added: 816, mode: `MaxEncodedLen`) + /// Storage: `GameModule::Users` (r:1 w:1) + /// Proof: `GameModule::Users` (`max_values`: None, `max_size`: Some(101), added: 2576, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:1 w:0) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) fn register_user() -> Weight { // Proof Size summary in bytes: - // Measured: `0` - // Estimated: `0` - // Minimum execution time: 10_548_000 picoseconds. - Weight::from_parts(12_842_000, 0) - .saturating_add(Weight::from_parts(0, 0)) + // Measured: `187` + // Estimated: `3593` + // Minimum execution time: 19_511_000 picoseconds. + Weight::from_parts(21_802_000, 0) + .saturating_add(Weight::from_parts(0, 3593)) + .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(1)) } /// Storage: `GameModule::Users` (r:1 w:1) - /// Proof: `GameModule::Users` (`max_values`: None, `max_size`: Some(61), added: 2536, mode: `MaxEncodedLen`) + /// Proof: `GameModule::Users` (`max_values`: None, `max_size`: Some(101), added: 2576, mode: `MaxEncodedLen`) fn give_points() -> Weight { // Proof Size summary in bytes: - // Measured: `159` - // Estimated: `3526` - // Minimum execution time: 22_795_000 picoseconds. - Weight::from_parts(35_614_000, 0) - .saturating_add(Weight::from_parts(0, 3526)) + // Measured: `290` + // Estimated: `3566` + // Minimum execution time: 13_864_000 picoseconds. + Weight::from_parts(20_611_000, 0) + .saturating_add(Weight::from_parts(0, 3566)) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)) } /// Storage: `GameModule::Users` (r:1 w:0) - /// Proof: `GameModule::Users` (`max_values`: None, `max_size`: Some(61), added: 2536, mode: `MaxEncodedLen`) + /// Proof: `GameModule::Users` (`max_values`: None, `max_size`: Some(101), added: 2576, mode: `MaxEncodedLen`) + /// Storage: `GameModule::RoundActive` (r:1 w:0) + /// Proof: `GameModule::RoundActive` (`max_values`: Some(1), `max_size`: Some(1), added: 496, mode: `MaxEncodedLen`) + /// Storage: `GameModule::CurrentRound` (r:1 w:0) + /// Proof: `GameModule::CurrentRound` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) /// Storage: `GameModule::GameId` (r:1 w:1) /// Proof: `GameModule::GameId` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) /// Storage: `GameModule::GamesExpiring` (r:1 w:1) @@ -106,36 +126,36 @@ impl WeightInfo for SubstrateWeight { /// Storage: `RandomnessCollectiveFlip::RandomMaterial` (r:1 w:0) /// Proof: `RandomnessCollectiveFlip::RandomMaterial` (`max_values`: Some(1), `max_size`: Some(2594), added: 3089, mode: `MaxEncodedLen`) /// Storage: `GameModule::TestProperties` (r:1 w:0) - /// Proof: `GameModule::TestProperties` (`max_values`: Some(1), `max_size`: Some(2002002), added: 2002497, mode: `MaxEncodedLen`) + /// Proof: `GameModule::TestProperties` (`max_values`: Some(1), `max_size`: Some(3002402), added: 3002897, mode: `MaxEncodedLen`) /// Storage: `GameModule::GameInfo` (r:0 w:1) - /// Proof: `GameModule::GameInfo` (`max_values`: None, `max_size`: Some(20073), added: 22548, mode: `MaxEncodedLen`) - /// Storage: `GameModule::StoredHash` (r:0 w:1) - /// Proof: `GameModule::StoredHash` (`max_values`: Some(1), `max_size`: Some(32), added: 527, mode: `MaxEncodedLen`) + /// Proof: `GameModule::GameInfo` (`max_values`: None, `max_size`: Some(30077), added: 32552, mode: `MaxEncodedLen`) fn play_game() -> Weight { // Proof Size summary in bytes: - // Measured: `596` - // Estimated: `2003487` - // Minimum execution time: 38_152_000 picoseconds. - Weight::from_parts(53_722_000, 0) - .saturating_add(Weight::from_parts(0, 2003487)) - .saturating_add(T::DbWeight::get().reads(5)) - .saturating_add(T::DbWeight::get().writes(4)) + // Measured: `1966` + // Estimated: `3003887` + // Minimum execution time: 41_464_000 picoseconds. + Weight::from_parts(46_440_000, 0) + .saturating_add(Weight::from_parts(0, 3003887)) + .saturating_add(T::DbWeight::get().reads(7)) + .saturating_add(T::DbWeight::get().writes(3)) } /// Storage: `GameModule::GameInfo` (r:1 w:1) - /// Proof: `GameModule::GameInfo` (`max_values`: None, `max_size`: Some(20073), added: 22548, mode: `MaxEncodedLen`) + /// Proof: `GameModule::GameInfo` (`max_values`: None, `max_size`: Some(30077), added: 32552, mode: `MaxEncodedLen`) /// Storage: `GameModule::TestPrices` (r:1 w:0) /// Proof: `GameModule::TestPrices` (`max_values`: None, `max_size`: Some(24), added: 2499, mode: `MaxEncodedLen`) /// Storage: `GameModule::Users` (r:1 w:1) - /// Proof: `GameModule::Users` (`max_values`: None, `max_size`: Some(61), added: 2536, mode: `MaxEncodedLen`) + /// Proof: `GameModule::Users` (`max_values`: None, `max_size`: Some(101), added: 2576, mode: `MaxEncodedLen`) + /// Storage: `GameModule::Leaderboard` (r:1 w:1) + /// Proof: `GameModule::Leaderboard` (`max_values`: Some(1), `max_size`: Some(361), added: 856, mode: `MaxEncodedLen`) fn submit_answer() -> Weight { // Proof Size summary in bytes: - // Measured: `489` - // Estimated: `23538` - // Minimum execution time: 32_358_000 picoseconds. - Weight::from_parts(44_190_000, 0) - .saturating_add(Weight::from_parts(0, 23538)) - .saturating_add(T::DbWeight::get().reads(3)) - .saturating_add(T::DbWeight::get().writes(2)) + // Measured: `1014` + // Estimated: `33542` + // Minimum execution time: 34_340_000 picoseconds. + Weight::from_parts(36_929_000, 0) + .saturating_add(Weight::from_parts(0, 33542)) + .saturating_add(T::DbWeight::get().reads(4)) + .saturating_add(T::DbWeight::get().writes(3)) } /// Storage: `Nfts::Item` (r:1 w:1) /// Proof: `Nfts::Item` (`max_values`: None, `max_size`: Some(861), added: 3336, mode: `MaxEncodedLen`) @@ -161,10 +181,10 @@ impl WeightInfo for SubstrateWeight { /// Proof: `Nfts::PendingSwapOf` (`max_values`: None, `max_size`: Some(71), added: 2546, mode: `MaxEncodedLen`) fn list_nft() -> Weight { // Proof Size summary in bytes: - // Measured: `1290` + // Measured: `1379` // Estimated: `4326` - // Minimum execution time: 84_211_000 picoseconds. - Weight::from_parts(106_018_000, 0) + // Minimum execution time: 80_220_000 picoseconds. + Weight::from_parts(88_509_000, 0) .saturating_add(Weight::from_parts(0, 4326)) .saturating_add(T::DbWeight::get().reads(7)) .saturating_add(T::DbWeight::get().writes(8)) @@ -191,10 +211,10 @@ impl WeightInfo for SubstrateWeight { /// Proof: `Nfts::PendingSwapOf` (`max_values`: None, `max_size`: Some(71), added: 2546, mode: `MaxEncodedLen`) fn delist_nft() -> Weight { // Proof Size summary in bytes: - // Measured: `1396` + // Measured: `1476` // Estimated: `4326` - // Minimum execution time: 75_643_000 picoseconds. - Weight::from_parts(87_909_000, 0) + // Minimum execution time: 73_031_000 picoseconds. + Weight::from_parts(80_820_000, 0) .saturating_add(Weight::from_parts(0, 4326)) .saturating_add(T::DbWeight::get().reads(7)) .saturating_add(T::DbWeight::get().writes(7)) @@ -225,10 +245,10 @@ impl WeightInfo for SubstrateWeight { /// Proof: `Nfts::PendingSwapOf` (`max_values`: None, `max_size`: Some(71), added: 2546, mode: `MaxEncodedLen`) fn make_offer() -> Weight { // Proof Size summary in bytes: - // Measured: `1968` + // Measured: `1550` // Estimated: `4326` - // Minimum execution time: 87_841_000 picoseconds. - Weight::from_parts(97_331_000, 0) + // Minimum execution time: 80_820_000 picoseconds. + Weight::from_parts(88_066_000, 0) .saturating_add(Weight::from_parts(0, 4326)) .saturating_add(T::DbWeight::get().reads(8)) .saturating_add(T::DbWeight::get().writes(8)) @@ -249,6 +269,12 @@ impl WeightInfo for SubstrateWeight { /// Proof: `Nfts::Item` (`max_values`: None, `max_size`: Some(861), added: 3336, mode: `MaxEncodedLen`) /// Storage: `Nfts::CollectionRoleOf` (r:1 w:0) /// Proof: `Nfts::CollectionRoleOf` (`max_values`: None, `max_size`: Some(69), added: 2544, mode: `MaxEncodedLen`) + /// Storage: `GameModule::Users` (r:2 w:2) + /// Proof: `GameModule::Users` (`max_values`: None, `max_size`: Some(101), added: 2576, mode: `MaxEncodedLen`) + /// Storage: `GameModule::CollectionColor` (r:1 w:0) + /// Proof: `GameModule::CollectionColor` (`max_values`: None, `max_size`: Some(21), added: 2496, mode: `MaxEncodedLen`) + /// Storage: `GameModule::Leaderboard` (r:1 w:1) + /// Proof: `GameModule::Leaderboard` (`max_values`: Some(1), `max_size`: Some(361), added: 856, mode: `MaxEncodedLen`) /// Storage: `Nfts::Account` (r:0 w:4) /// Proof: `Nfts::Account` (`max_values`: None, `max_size`: Some(88), added: 2563, mode: `MaxEncodedLen`) /// Storage: `Nfts::ItemPriceOf` (r:0 w:2) @@ -257,12 +283,76 @@ impl WeightInfo for SubstrateWeight { /// Proof: `Nfts::PendingSwapOf` (`max_values`: None, `max_size`: Some(71), added: 2546, mode: `MaxEncodedLen`) fn handle_offer() -> Weight { // Proof Size summary in bytes: - // Measured: `2152` + // Measured: `2178` // Estimated: `7662` - // Minimum execution time: 127_517_000 picoseconds. - Weight::from_parts(155_423_000, 0) + // Minimum execution time: 154_210_000 picoseconds. + Weight::from_parts(166_048_000, 0) .saturating_add(Weight::from_parts(0, 7662)) - .saturating_add(T::DbWeight::get().reads(11)) - .saturating_add(T::DbWeight::get().writes(14)) + .saturating_add(T::DbWeight::get().reads(15)) + .saturating_add(T::DbWeight::get().writes(17)) + } + /// Storage: `GameModule::TestProperties` (r:1 w:1) + /// Proof: `GameModule::TestProperties` (`max_values`: Some(1), `max_size`: Some(3002402), added: 3002897, mode: `MaxEncodedLen`) + /// Storage: `GameModule::TestPrices` (r:0 w:1) + /// Proof: `GameModule::TestPrices` (`max_values`: None, `max_size`: Some(24), added: 2499, mode: `MaxEncodedLen`) + fn add_property() -> Weight { + // Proof Size summary in bytes: + // Measured: `1670` + // Estimated: `3003887` + // Minimum execution time: 11_789_000 picoseconds. + Weight::from_parts(15_564_000, 0) + .saturating_add(Weight::from_parts(0, 3003887)) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(2)) + } + /// Storage: `GameModule::TestProperties` (r:1 w:1) + /// Proof: `GameModule::TestProperties` (`max_values`: Some(1), `max_size`: Some(3002402), added: 3002897, mode: `MaxEncodedLen`) + /// Storage: `GameModule::TestPrices` (r:1 w:1) + /// Proof: `GameModule::TestPrices` (`max_values`: None, `max_size`: Some(24), added: 2499, mode: `MaxEncodedLen`) + fn remove_property() -> Weight { + // Proof Size summary in bytes: + // Measured: `1740` + // Estimated: `3003887` + // Minimum execution time: 18_385_000 picoseconds. + Weight::from_parts(20_622_000, 0) + .saturating_add(Weight::from_parts(0, 3003887)) + .saturating_add(T::DbWeight::get().reads(2)) + .saturating_add(T::DbWeight::get().writes(2)) + } + /// Storage: `GameModule::Admins` (r:1 w:1) + /// Proof: `GameModule::Admins` (`max_values`: Some(1), `max_size`: Some(321), added: 816, mode: `MaxEncodedLen`) + fn add_to_admins() -> Weight { + // Proof Size summary in bytes: + // Measured: `132` + // Estimated: `1806` + // Minimum execution time: 10_448_000 picoseconds. + Weight::from_parts(12_934_000, 0) + .saturating_add(Weight::from_parts(0, 1806)) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)) + } + /// Storage: `GameModule::Admins` (r:1 w:1) + /// Proof: `GameModule::Admins` (`max_values`: Some(1), `max_size`: Some(321), added: 816, mode: `MaxEncodedLen`) + fn remove_from_admins() -> Weight { + // Proof Size summary in bytes: + // Measured: `187` + // Estimated: `1806` + // Minimum execution time: 11_069_000 picoseconds. + Weight::from_parts(14_432_000, 0) + .saturating_add(Weight::from_parts(0, 1806)) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)) + } + /// Storage: `GameModule::Users` (r:1 w:1) + /// Proof: `GameModule::Users` (`max_values`: None, `max_size`: Some(101), added: 2576, mode: `MaxEncodedLen`) + fn request_token() -> Weight { + // Proof Size summary in bytes: + // Measured: `290` + // Estimated: `3566` + // Minimum execution time: 41_262_000 picoseconds. + Weight::from_parts(53_983_000, 0) + .saturating_add(Weight::from_parts(0, 3566)) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)) } } diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 8babf00..c5efff4 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -264,17 +264,18 @@ impl sp_core::Get for MaxProperties { } } -// Define the parameter types using the custom struct. parameter_types! { pub const GamePalletId: PalletId = PalletId(*b"py/rlxdl"); pub const MaxOngoingGame: u32 = 200; pub const LeaderLimit: u32 = 10; pub const MaxAdmin: u32 = 10; + pub const RequestLimits: BlockNumber = 100800; } /// Configure the pallet-game in pallets/game. impl pallet_game::Config for Runtime { type RuntimeEvent = RuntimeEvent; + type Currency = Balances; type WeightInfo = pallet_game::weights::SubstrateWeight; type GameOrigin = EnsureRoot; type CollectionId = u32; @@ -286,6 +287,7 @@ impl pallet_game::Config for Runtime { type StringLimit = StringLimit; type LeaderboardLimit = LeaderLimit; type MaxAdmins = MaxAdmin; + type RequestLimit = RequestLimits; } parameter_types! { @@ -380,7 +382,7 @@ where raw_payload.using_encoded(|payload| C::sign(payload, public))?; let address = account; let (call, extra, _) = raw_payload.deconstruct(); - Some((call, (sp_runtime::MultiAddress::Id(address), signature.into(), extra))) + Some((call, (sp_runtime::MultiAddress::Id(address), signature, extra))) } } From 28ae65b5a6463df21fde99daa98f372d31a227e2 Mon Sep 17 00:00:00 2001 From: recrafter Date: Sat, 11 May 2024 06:56:25 +0200 Subject: [PATCH 05/15] Adjusting tests and refactoring --- pallets/game/src/benchmarking.rs | 36 +++- pallets/game/src/lib.rs | 322 +------------------------------ pallets/game/src/mock.rs | 4 - pallets/game/src/tests.rs | 2 + pallets/game/src/types.rs | 322 +++++++++++++++++++++++++++++++ 5 files changed, 355 insertions(+), 331 deletions(-) create mode 100644 pallets/game/src/types.rs diff --git a/pallets/game/src/benchmarking.rs b/pallets/game/src/benchmarking.rs index b3ccbc3..31d7885 100644 --- a/pallets/game/src/benchmarking.rs +++ b/pallets/game/src/benchmarking.rs @@ -10,7 +10,6 @@ use frame_support::{ traits::{OnFinalize, OnInitialize}, }; use frame_system::RawOrigin; -use pallet_nfts::Pallet as Nfts; fn create_setup() -> T::AccountId { let caller: T::AccountId = whitelisted_caller(); @@ -50,14 +49,18 @@ mod benchmarks { let admin: T::AccountId = account("admin", 0, 0); assert_ok!(GameModule::::add_to_admins(RawOrigin::Root.into(), admin.clone())); #[extrinsic_call] - register_user(RawOrigin::Signed(admin), caller); + register_user(RawOrigin::Signed(admin), caller.clone()); + + assert!(GameModule::::users(caller).is_some()); } #[benchmark] fn give_points() { let caller = create_setup::(); #[extrinsic_call] - give_points(RawOrigin::Root, caller); + give_points(RawOrigin::Root, caller.clone()); + + assert_eq!(GameModule::::users(caller).unwrap().points, 150); } #[benchmark] @@ -66,7 +69,9 @@ mod benchmarks { current_block::(30u32.into()); practise_round::(caller.clone(), 0); #[extrinsic_call] - play_game(RawOrigin::Signed(caller), crate::DifficultyLevel::Player); + play_game(RawOrigin::Signed(caller.clone()), crate::DifficultyLevel::Player); + + assert_eq!(GameModule::::game_info(1).unwrap().player, caller); } #[benchmark] @@ -79,7 +84,9 @@ mod benchmarks { crate::DifficultyLevel::Player )); #[extrinsic_call] - submit_answer(RawOrigin::Signed(caller), 200000, 1); + submit_answer(RawOrigin::Signed(caller.clone()), 220000, 1); + + assert_eq!(GameModule::::users::>(caller).unwrap().nfts.xorange, 1); } #[benchmark] @@ -97,7 +104,9 @@ mod benchmarks { 1 )); #[extrinsic_call] - list_nft(RawOrigin::Signed(caller), 0.into(), 0.into()); + list_nft(RawOrigin::Signed(caller.clone()), 0.into(), 0.into()); + + assert_eq!(GameModule::::listings(0).unwrap().owner, caller); } #[benchmark] @@ -121,6 +130,8 @@ mod benchmarks { )); #[extrinsic_call] delist_nft(RawOrigin::Signed(caller), 0); + + assert!(GameModule::::listings(0).is_none()); } #[benchmark] @@ -156,7 +167,9 @@ mod benchmarks { 3 )); #[extrinsic_call] - make_offer(RawOrigin::Signed(caller2), 0, 0.into(), 1.into()); + make_offer(RawOrigin::Signed(caller2.clone()), 0, 0.into(), 1.into()); + + assert_eq!(GameModule::::offers(0).unwrap().owner, caller2); } #[benchmark] @@ -204,6 +217,9 @@ mod benchmarks { #[extrinsic_call] handle_offer(RawOrigin::Signed(caller), 0, crate::Offer::Accept); + + assert_eq!(GameModule::::offers(0).is_none(), true); + assert_eq!(GameModule::::listings(0).is_none(), true); } #[benchmark] @@ -222,6 +238,8 @@ mod benchmarks { }; #[extrinsic_call] add_property(RawOrigin::Root, new_property, 200000); + + assert_eq!(GameModule::::test_properties().len(), 5); } #[benchmark] @@ -229,12 +247,14 @@ mod benchmarks { assert_ok!(GameModule::::setup_game(RawOrigin::Root.into())); #[extrinsic_call] remove_property(RawOrigin::Root, 146480642); + + assert_eq!(GameModule::::test_properties().len(), 3); } #[benchmark] fn add_to_admins() { assert_ok!(GameModule::::setup_game(RawOrigin::Root.into())); - let new_admin: T::AccountId = account("new_admin", 0, 0); + let new_admin: T::AccountId = account("new_admin", 1, 0); #[extrinsic_call] add_to_admins(RawOrigin::Root, new_admin); } diff --git a/pallets/game/src/lib.rs b/pallets/game/src/lib.rs index 62048b0..e012ec2 100644 --- a/pallets/game/src/lib.rs +++ b/pallets/game/src/lib.rs @@ -17,6 +17,7 @@ pub mod weights; pub use weights::*; pub mod properties; pub mod functions; +pub mod types; type AccountIdOf = ::AccountId; type BalanceOf = <::Currency as Currency< @@ -43,6 +44,8 @@ use enumflags2::BitFlags; use frame_support::traits::Randomness; +pub use types::*; + #[frame_support::pallet] pub mod pallet { use super::*; @@ -52,325 +55,6 @@ pub mod pallet { #[pallet::pallet] pub struct Pallet(_); - /// Difficulty level of game enum. - #[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))] - #[derive(Encode, Decode, Clone, PartialEq, Eq, MaxEncodedLen, RuntimeDebug, TypeInfo)] - pub enum DifficultyLevel { - Practice, - Player, - Pro, - } - - /// Offer enum. - #[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))] - #[derive(Encode, Decode, Clone, PartialEq, Eq, MaxEncodedLen, RuntimeDebug, TypeInfo)] - pub enum Offer { - Accept, - Reject, - } - - /// Nft color enum. - #[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))] - #[derive(Encode, Decode, Clone, PartialEq, Eq, MaxEncodedLen, RuntimeDebug, TypeInfo)] - pub enum NftColor { - Xorange, - Xpink, - Xblue, - Xcyan, - Xcoral, - Xpurple, - Xleafgreen, - Xgreen, - } - - impl NftColor { - pub fn from_index(index: usize) -> Option { - match index { - 0 => Some(NftColor::Xorange), - 1 => Some(NftColor::Xpink), - 2 => Some(NftColor::Xblue), - 3 => Some(NftColor::Xcyan), - 4 => Some(NftColor::Xcoral), - 5 => Some(NftColor::Xpurple), - 6 => Some(NftColor::Xleafgreen), - 7 => Some(NftColor::Xgreen), - _ => None, - } - } - } - - /// AccountId storage. - #[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))] - #[derive(Encode, Decode, Clone, PartialEq, Eq, MaxEncodedLen, RuntimeDebug, TypeInfo)] - pub struct PalletIdStorage { - pallet_id: AccountIdOf, - } - - /// Game Data. - #[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))] - #[derive(Encode, Decode, Clone, PartialEq, Eq, MaxEncodedLen, RuntimeDebug, TypeInfo)] - #[scale_info(skip_type_params(T))] - pub struct GameData { - pub difficulty: DifficultyLevel, - pub player: AccountIdOf, - pub property: PropertyInfoData, - } - - /// Listing infos of a NFT. - #[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))] - #[derive(Encode, Decode, Clone, PartialEq, Eq, MaxEncodedLen, RuntimeDebug, TypeInfo)] - #[scale_info(skip_type_params(T))] - pub struct ListingInfo { - pub owner: AccountIdOf, - pub collection_id: CollectionId, - pub item_id: ItemId, - } - - /// Offer infos of a listing. - #[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))] - #[derive(Encode, Decode, Clone, PartialEq, Eq, MaxEncodedLen, RuntimeDebug, TypeInfo)] - #[scale_info(skip_type_params(T))] - pub struct OfferInfo { - pub owner: AccountIdOf, - pub listing_id: u32, - pub collection_id: CollectionId, - pub item_id: ItemId, - } - - /// Struct to store the property data for a game. - #[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))] - #[derive( - Encode, - Decode, - Clone, - PartialEq, - Eq, - MaxEncodedLen, - frame_support::pallet_prelude::RuntimeDebugNoBound, - TypeInfo, - )] - #[scale_info(skip_type_params(T))] - pub struct PropertyInfoData { - pub id: u32, - pub bedrooms: u32, - pub bathrooms: u32, - pub summary: BoundedVec::StringLimit>, - pub property_sub_type: BoundedVec::StringLimit>, - pub first_visible_date: BoundedVec::StringLimit>, - pub display_size: BoundedVec::StringLimit>, - pub display_address: BoundedVec::StringLimit>, - pub property_images1: BoundedVec::StringLimit>, - } - - /// Struct for the user datas. - #[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))] - #[derive(Encode, Decode, Clone, PartialEq, Eq, MaxEncodedLen, RuntimeDebug, TypeInfo)] - #[scale_info(skip_type_params(T))] - pub struct User { - pub points: u32, - pub wins: u32, - pub losses: u32, - pub practise_rounds: u8, - pub last_played_round: u32, - pub next_token_request: BlockNumberFor, - pub nfts: CollectedColors, - } - - impl User { - pub fn add_nft_color(&mut self, color: NftColor) -> DispatchResult { - self.nfts.add_nft_color(color)?; - Ok(()) - } - - pub fn sub_nft_color(&mut self, color: NftColor) -> DispatchResult { - self.nfts.sub_nft_color(color)?; - Ok(()) - } - - pub fn has_four_of_all_colors(&self) -> bool { - self.nfts.has_four_of_all_colors() - } - - pub fn calculate_points(&mut self, color: NftColor) -> u32 { - match color { - NftColor::Xorange if self.nfts.xorange == 1 => 100, - NftColor::Xorange if self.nfts.xorange == 2 => 120, - NftColor::Xorange if self.nfts.xorange == 3 => 220, - NftColor::Xorange if self.nfts.xorange == 4 => 340, - NftColor::Xpink if self.nfts.xpink == 1 => 100, - NftColor::Xpink if self.nfts.xpink == 2 => 120, - NftColor::Xpink if self.nfts.xpink == 3 => 220, - NftColor::Xpink if self.nfts.xpink == 4 => 340, - NftColor::Xblue if self.nfts.xblue == 1 => 100, - NftColor::Xblue if self.nfts.xblue == 2 => 120, - NftColor::Xblue if self.nfts.xblue == 3 => 220, - NftColor::Xblue if self.nfts.xblue == 4 => 340, - NftColor::Xcyan if self.nfts.xcyan == 1 => 100, - NftColor::Xcyan if self.nfts.xcyan == 2 => 120, - NftColor::Xcyan if self.nfts.xcyan == 3 => 220, - NftColor::Xcyan if self.nfts.xcyan == 4 => 340, - NftColor::Xcoral if self.nfts.xcoral == 1 => 100, - NftColor::Xcoral if self.nfts.xcoral == 2 => 120, - NftColor::Xcoral if self.nfts.xcoral == 3 => 220, - NftColor::Xcoral if self.nfts.xcoral == 4 => 340, - NftColor::Xpurple if self.nfts.xpurple == 1 => 100, - NftColor::Xpurple if self.nfts.xpurple == 2 => 120, - NftColor::Xpurple if self.nfts.xpurple == 3 => 220, - NftColor::Xpurple if self.nfts.xpurple == 4 => 340, - NftColor::Xleafgreen if self.nfts.xleafgreen == 1 => 100, - NftColor::Xleafgreen if self.nfts.xleafgreen == 2 => 120, - NftColor::Xleafgreen if self.nfts.xleafgreen == 3 => 220, - NftColor::Xleafgreen if self.nfts.xleafgreen == 4 => 340, - NftColor::Xgreen if self.nfts.xgreen == 1 => 100, - NftColor::Xgreen if self.nfts.xgreen == 2 => 120, - NftColor::Xgreen if self.nfts.xgreen == 3 => 220, - NftColor::Xgreen if self.nfts.xgreen == 4 => 340, - _ => 0, - } - } - - pub fn subtracting_calculate_points(&mut self, color: NftColor) -> u32 { - match color { - NftColor::Xorange if self.nfts.xorange == 0 => 100, - NftColor::Xorange if self.nfts.xorange == 1 => 120, - NftColor::Xorange if self.nfts.xorange == 2 => 220, - NftColor::Xorange if self.nfts.xorange == 3 => 340, - NftColor::Xpink if self.nfts.xpink == 0 => 100, - NftColor::Xpink if self.nfts.xpink == 1 => 120, - NftColor::Xpink if self.nfts.xpink == 2 => 220, - NftColor::Xpink if self.nfts.xpink == 3 => 340, - NftColor::Xblue if self.nfts.xblue == 0 => 100, - NftColor::Xblue if self.nfts.xblue == 1 => 120, - NftColor::Xblue if self.nfts.xblue == 2 => 220, - NftColor::Xblue if self.nfts.xblue == 3 => 340, - NftColor::Xcyan if self.nfts.xcyan == 0 => 100, - NftColor::Xcyan if self.nfts.xcyan == 1 => 120, - NftColor::Xcyan if self.nfts.xcyan == 2 => 220, - NftColor::Xcyan if self.nfts.xcyan == 3 => 340, - NftColor::Xcoral if self.nfts.xcoral == 0 => 100, - NftColor::Xcoral if self.nfts.xcoral == 1 => 120, - NftColor::Xcoral if self.nfts.xcoral == 2 => 220, - NftColor::Xcoral if self.nfts.xcoral == 3 => 340, - NftColor::Xpurple if self.nfts.xpurple == 0 => 100, - NftColor::Xpurple if self.nfts.xpurple == 1 => 120, - NftColor::Xpurple if self.nfts.xpurple == 2 => 220, - NftColor::Xpurple if self.nfts.xpurple == 3 => 340, - NftColor::Xleafgreen if self.nfts.xleafgreen == 0 => 100, - NftColor::Xleafgreen if self.nfts.xleafgreen == 1 => 120, - NftColor::Xleafgreen if self.nfts.xleafgreen == 2 => 220, - NftColor::Xleafgreen if self.nfts.xleafgreen == 3 => 340, - NftColor::Xgreen if self.nfts.xgreen == 0 => 100, - NftColor::Xgreen if self.nfts.xgreen == 1 => 120, - NftColor::Xgreen if self.nfts.xgreen == 2 => 220, - NftColor::Xgreen if self.nfts.xgreen == 3 => 340, - _ => 0, - } - } - } - - #[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))] - #[derive( - Encode, Decode, Clone, PartialEq, Eq, MaxEncodedLen, RuntimeDebug, TypeInfo, Default, - )] - #[scale_info(skip_type_params(T))] - pub struct CollectedColors { - pub xorange: u32, - pub xpink: u32, - pub xblue: u32, - pub xcyan: u32, - pub xcoral: u32, - pub xpurple: u32, - pub xleafgreen: u32, - pub xgreen: u32, - } - - impl CollectedColors { - pub fn add_nft_color(&mut self, color: NftColor) -> DispatchResult { - match color { - NftColor::Xorange => { - self.xorange = self.xorange.checked_add(1).ok_or("Arithmetic overflow")?; - Ok(()) - }, - NftColor::Xpink => { - self.xpink = self.xpink.checked_add(1).ok_or("Arithmetic overflow")?; - Ok(()) - }, - NftColor::Xblue => { - self.xblue = self.xblue.checked_add(1).ok_or("Arithmetic overflow")?; - Ok(()) - }, - NftColor::Xcyan => { - self.xcyan = self.xcyan.checked_add(1).ok_or("Arithmetic overflow")?; - Ok(()) - }, - NftColor::Xcoral => { - self.xcoral = self.xcoral.checked_add(1).ok_or("Arithmetic overflow")?; - Ok(()) - }, - NftColor::Xpurple => { - self.xpurple = self.xpurple.checked_add(1).ok_or("Arithmetic overflow")?; - Ok(()) - }, - NftColor::Xleafgreen => { - self.xleafgreen = - self.xleafgreen.checked_add(1).ok_or("Arithmetic overflow")?; - Ok(()) - }, - NftColor::Xgreen => { - self.xgreen = self.xgreen.checked_add(1).ok_or("Arithmetic overflow")?; - Ok(()) - }, - } - } - - pub fn sub_nft_color(&mut self, color: NftColor) -> DispatchResult { - match color { - NftColor::Xorange => { - self.xorange = self.xorange.checked_sub(1).ok_or("Arithmetic underflow")?; - Ok(()) - }, - NftColor::Xpink => { - self.xpink = self.xpink.checked_sub(1).ok_or("Arithmetic underflow")?; - Ok(()) - }, - NftColor::Xblue => { - self.xblue = self.xblue.checked_sub(1).ok_or("Arithmetic underflow")?; - Ok(()) - }, - NftColor::Xcyan => { - self.xcyan = self.xcyan.checked_sub(1).ok_or("Arithmetic underflow")?; - Ok(()) - }, - NftColor::Xcoral => { - self.xcoral = self.xcoral.checked_sub(1).ok_or("Arithmetic underflow")?; - Ok(()) - }, - NftColor::Xpurple => { - self.xpurple = self.xpurple.checked_sub(1).ok_or("Arithmetic underflow")?; - Ok(()) - }, - NftColor::Xleafgreen => { - self.xleafgreen = - self.xleafgreen.checked_sub(1).ok_or("Arithmetic underflow")?; - Ok(()) - }, - NftColor::Xgreen => { - self.xgreen = self.xgreen.checked_sub(1).ok_or("Arithmetic underflow")?; - Ok(()) - }, - } - } - - pub fn has_four_of_all_colors(&self) -> bool { - self.xorange >= 4 && - self.xpink >= 4 && self.xblue >= 4 && - self.xcyan >= 4 && self.xcoral >= 4 && - self.xpurple >= 4 && - self.xleafgreen >= 4 && - self.xgreen >= 4 - } - } - /// Configure the pallet by specifying the parameters and types on which it depends. #[pallet::config] pub trait Config: diff --git a/pallets/game/src/mock.rs b/pallets/game/src/mock.rs index e5ace75..0be5d63 100644 --- a/pallets/game/src/mock.rs +++ b/pallets/game/src/mock.rs @@ -159,10 +159,6 @@ pub fn new_test_ext() -> sp_io::TestExternalities { pallet_balances::GenesisConfig:: { balances: vec![ - ([0; 32].into(), 1_000_000), - ([1; 32].into(), 1_000_000), - ([2; 32].into(), 1_000_000), - ([3; 32].into(), 1_000_000), (GameModule::account_id(), 1_000_000), ], } diff --git a/pallets/game/src/tests.rs b/pallets/game/src/tests.rs index 69289d6..6c4784e 100644 --- a/pallets/game/src/tests.rs +++ b/pallets/game/src/tests.rs @@ -77,6 +77,7 @@ fn play_game_works() { assert_eq!(GameModule::test_properties().len(), 4); assert_ok!(GameModule::add_to_admins(RuntimeOrigin::root(), [4; 32].into())); assert_ok!(GameModule::register_user(RuntimeOrigin::signed([4; 32].into()), [0; 32].into())); + assert_eq!(Balances::free_balance(&([0; 32].into())), 10); assert_ok!(GameModule::give_points(RuntimeOrigin::root(), [0; 32].into())); practise_round([0; 32].into(), 0); assert_ok!(GameModule::play_game( @@ -743,6 +744,7 @@ fn request_token_works() { assert_ok!(GameModule::register_user(RuntimeOrigin::signed([4; 32].into()), [0; 32].into())); System::set_block_number(100802); assert_ok!(GameModule::request_token(RuntimeOrigin::signed([0; 32].into()))); + assert_eq!(Balances::free_balance(&([0; 32].into())), 10); }); } diff --git a/pallets/game/src/types.rs b/pallets/game/src/types.rs new file mode 100644 index 0000000..e84c30d --- /dev/null +++ b/pallets/game/src/types.rs @@ -0,0 +1,322 @@ +use crate::*; +use frame_support::pallet_prelude::*; +use frame_system::pallet_prelude::*; + + /// Difficulty level of game enum. + #[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))] + #[derive(Encode, Decode, Clone, PartialEq, Eq, MaxEncodedLen, RuntimeDebug, TypeInfo)] + pub enum DifficultyLevel { + Practice, + Player, + Pro, + } + + /// Offer enum. + #[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))] + #[derive(Encode, Decode, Clone, PartialEq, Eq, MaxEncodedLen, RuntimeDebug, TypeInfo)] + pub enum Offer { + Accept, + Reject, + } + + /// Nft color enum. + #[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))] + #[derive(Encode, Decode, Clone, PartialEq, Eq, MaxEncodedLen, RuntimeDebug, TypeInfo)] + pub enum NftColor { + Xorange, + Xpink, + Xblue, + Xcyan, + Xcoral, + Xpurple, + Xleafgreen, + Xgreen, + } + + impl NftColor { + pub fn from_index(index: usize) -> Option { + match index { + 0 => Some(NftColor::Xorange), + 1 => Some(NftColor::Xpink), + 2 => Some(NftColor::Xblue), + 3 => Some(NftColor::Xcyan), + 4 => Some(NftColor::Xcoral), + 5 => Some(NftColor::Xpurple), + 6 => Some(NftColor::Xleafgreen), + 7 => Some(NftColor::Xgreen), + _ => None, + } + } + } + + /// AccountId storage. + #[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))] + #[derive(Encode, Decode, Clone, PartialEq, Eq, MaxEncodedLen, RuntimeDebug, TypeInfo)] + pub struct PalletIdStorage { + pallet_id: AccountIdOf, + } + + /// Game Data. + #[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))] + #[derive(Encode, Decode, Clone, PartialEq, Eq, MaxEncodedLen, RuntimeDebug, TypeInfo)] + #[scale_info(skip_type_params(T))] + pub struct GameData { + pub difficulty: DifficultyLevel, + pub player: AccountIdOf, + pub property: PropertyInfoData, + } + + /// Listing infos of a NFT. + #[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))] + #[derive(Encode, Decode, Clone, PartialEq, Eq, MaxEncodedLen, RuntimeDebug, TypeInfo)] + #[scale_info(skip_type_params(T))] + pub struct ListingInfo { + pub owner: AccountIdOf, + pub collection_id: CollectionId, + pub item_id: ItemId, + } + + /// Offer infos of a listing. + #[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))] + #[derive(Encode, Decode, Clone, PartialEq, Eq, MaxEncodedLen, RuntimeDebug, TypeInfo)] + #[scale_info(skip_type_params(T))] + pub struct OfferInfo { + pub owner: AccountIdOf, + pub listing_id: u32, + pub collection_id: CollectionId, + pub item_id: ItemId, + } + + /// Struct to store the property data for a game. + #[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))] + #[derive( + Encode, + Decode, + Clone, + PartialEq, + Eq, + MaxEncodedLen, + frame_support::pallet_prelude::RuntimeDebugNoBound, + TypeInfo, + )] + #[scale_info(skip_type_params(T))] + pub struct PropertyInfoData { + pub id: u32, + pub bedrooms: u32, + pub bathrooms: u32, + pub summary: BoundedVec::StringLimit>, + pub property_sub_type: BoundedVec::StringLimit>, + pub first_visible_date: BoundedVec::StringLimit>, + pub display_size: BoundedVec::StringLimit>, + pub display_address: BoundedVec::StringLimit>, + pub property_images1: BoundedVec::StringLimit>, + } + + /// Struct for the user datas. + #[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))] + #[derive(Encode, Decode, Clone, PartialEq, Eq, MaxEncodedLen, RuntimeDebug, TypeInfo)] + #[scale_info(skip_type_params(T))] + pub struct User { + pub points: u32, + pub wins: u32, + pub losses: u32, + pub practise_rounds: u8, + pub last_played_round: u32, + pub next_token_request: BlockNumberFor, + pub nfts: CollectedColors, + } + + impl User { + pub fn add_nft_color(&mut self, color: NftColor) -> DispatchResult { + self.nfts.add_nft_color(color)?; + Ok(()) + } + + pub fn sub_nft_color(&mut self, color: NftColor) -> DispatchResult { + self.nfts.sub_nft_color(color)?; + Ok(()) + } + + pub fn has_four_of_all_colors(&self) -> bool { + self.nfts.has_four_of_all_colors() + } + + pub fn calculate_points(&mut self, color: NftColor) -> u32 { + match color { + NftColor::Xorange if self.nfts.xorange == 1 => 100, + NftColor::Xorange if self.nfts.xorange == 2 => 120, + NftColor::Xorange if self.nfts.xorange == 3 => 220, + NftColor::Xorange if self.nfts.xorange == 4 => 340, + NftColor::Xpink if self.nfts.xpink == 1 => 100, + NftColor::Xpink if self.nfts.xpink == 2 => 120, + NftColor::Xpink if self.nfts.xpink == 3 => 220, + NftColor::Xpink if self.nfts.xpink == 4 => 340, + NftColor::Xblue if self.nfts.xblue == 1 => 100, + NftColor::Xblue if self.nfts.xblue == 2 => 120, + NftColor::Xblue if self.nfts.xblue == 3 => 220, + NftColor::Xblue if self.nfts.xblue == 4 => 340, + NftColor::Xcyan if self.nfts.xcyan == 1 => 100, + NftColor::Xcyan if self.nfts.xcyan == 2 => 120, + NftColor::Xcyan if self.nfts.xcyan == 3 => 220, + NftColor::Xcyan if self.nfts.xcyan == 4 => 340, + NftColor::Xcoral if self.nfts.xcoral == 1 => 100, + NftColor::Xcoral if self.nfts.xcoral == 2 => 120, + NftColor::Xcoral if self.nfts.xcoral == 3 => 220, + NftColor::Xcoral if self.nfts.xcoral == 4 => 340, + NftColor::Xpurple if self.nfts.xpurple == 1 => 100, + NftColor::Xpurple if self.nfts.xpurple == 2 => 120, + NftColor::Xpurple if self.nfts.xpurple == 3 => 220, + NftColor::Xpurple if self.nfts.xpurple == 4 => 340, + NftColor::Xleafgreen if self.nfts.xleafgreen == 1 => 100, + NftColor::Xleafgreen if self.nfts.xleafgreen == 2 => 120, + NftColor::Xleafgreen if self.nfts.xleafgreen == 3 => 220, + NftColor::Xleafgreen if self.nfts.xleafgreen == 4 => 340, + NftColor::Xgreen if self.nfts.xgreen == 1 => 100, + NftColor::Xgreen if self.nfts.xgreen == 2 => 120, + NftColor::Xgreen if self.nfts.xgreen == 3 => 220, + NftColor::Xgreen if self.nfts.xgreen == 4 => 340, + _ => 0, + } + } + + pub fn subtracting_calculate_points(&mut self, color: NftColor) -> u32 { + match color { + NftColor::Xorange if self.nfts.xorange == 0 => 100, + NftColor::Xorange if self.nfts.xorange == 1 => 120, + NftColor::Xorange if self.nfts.xorange == 2 => 220, + NftColor::Xorange if self.nfts.xorange == 3 => 340, + NftColor::Xpink if self.nfts.xpink == 0 => 100, + NftColor::Xpink if self.nfts.xpink == 1 => 120, + NftColor::Xpink if self.nfts.xpink == 2 => 220, + NftColor::Xpink if self.nfts.xpink == 3 => 340, + NftColor::Xblue if self.nfts.xblue == 0 => 100, + NftColor::Xblue if self.nfts.xblue == 1 => 120, + NftColor::Xblue if self.nfts.xblue == 2 => 220, + NftColor::Xblue if self.nfts.xblue == 3 => 340, + NftColor::Xcyan if self.nfts.xcyan == 0 => 100, + NftColor::Xcyan if self.nfts.xcyan == 1 => 120, + NftColor::Xcyan if self.nfts.xcyan == 2 => 220, + NftColor::Xcyan if self.nfts.xcyan == 3 => 340, + NftColor::Xcoral if self.nfts.xcoral == 0 => 100, + NftColor::Xcoral if self.nfts.xcoral == 1 => 120, + NftColor::Xcoral if self.nfts.xcoral == 2 => 220, + NftColor::Xcoral if self.nfts.xcoral == 3 => 340, + NftColor::Xpurple if self.nfts.xpurple == 0 => 100, + NftColor::Xpurple if self.nfts.xpurple == 1 => 120, + NftColor::Xpurple if self.nfts.xpurple == 2 => 220, + NftColor::Xpurple if self.nfts.xpurple == 3 => 340, + NftColor::Xleafgreen if self.nfts.xleafgreen == 0 => 100, + NftColor::Xleafgreen if self.nfts.xleafgreen == 1 => 120, + NftColor::Xleafgreen if self.nfts.xleafgreen == 2 => 220, + NftColor::Xleafgreen if self.nfts.xleafgreen == 3 => 340, + NftColor::Xgreen if self.nfts.xgreen == 0 => 100, + NftColor::Xgreen if self.nfts.xgreen == 1 => 120, + NftColor::Xgreen if self.nfts.xgreen == 2 => 220, + NftColor::Xgreen if self.nfts.xgreen == 3 => 340, + _ => 0, + } + } + } + + #[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))] + #[derive( + Encode, Decode, Clone, PartialEq, Eq, MaxEncodedLen, RuntimeDebug, TypeInfo, Default, + )] + #[scale_info(skip_type_params(T))] + pub struct CollectedColors { + pub xorange: u32, + pub xpink: u32, + pub xblue: u32, + pub xcyan: u32, + pub xcoral: u32, + pub xpurple: u32, + pub xleafgreen: u32, + pub xgreen: u32, + } + + impl CollectedColors { + pub fn add_nft_color(&mut self, color: NftColor) -> DispatchResult { + match color { + NftColor::Xorange => { + self.xorange = self.xorange.checked_add(1).ok_or("Arithmetic overflow")?; + Ok(()) + }, + NftColor::Xpink => { + self.xpink = self.xpink.checked_add(1).ok_or("Arithmetic overflow")?; + Ok(()) + }, + NftColor::Xblue => { + self.xblue = self.xblue.checked_add(1).ok_or("Arithmetic overflow")?; + Ok(()) + }, + NftColor::Xcyan => { + self.xcyan = self.xcyan.checked_add(1).ok_or("Arithmetic overflow")?; + Ok(()) + }, + NftColor::Xcoral => { + self.xcoral = self.xcoral.checked_add(1).ok_or("Arithmetic overflow")?; + Ok(()) + }, + NftColor::Xpurple => { + self.xpurple = self.xpurple.checked_add(1).ok_or("Arithmetic overflow")?; + Ok(()) + }, + NftColor::Xleafgreen => { + self.xleafgreen = + self.xleafgreen.checked_add(1).ok_or("Arithmetic overflow")?; + Ok(()) + }, + NftColor::Xgreen => { + self.xgreen = self.xgreen.checked_add(1).ok_or("Arithmetic overflow")?; + Ok(()) + }, + } + } + + pub fn sub_nft_color(&mut self, color: NftColor) -> DispatchResult { + match color { + NftColor::Xorange => { + self.xorange = self.xorange.checked_sub(1).ok_or("Arithmetic underflow")?; + Ok(()) + }, + NftColor::Xpink => { + self.xpink = self.xpink.checked_sub(1).ok_or("Arithmetic underflow")?; + Ok(()) + }, + NftColor::Xblue => { + self.xblue = self.xblue.checked_sub(1).ok_or("Arithmetic underflow")?; + Ok(()) + }, + NftColor::Xcyan => { + self.xcyan = self.xcyan.checked_sub(1).ok_or("Arithmetic underflow")?; + Ok(()) + }, + NftColor::Xcoral => { + self.xcoral = self.xcoral.checked_sub(1).ok_or("Arithmetic underflow")?; + Ok(()) + }, + NftColor::Xpurple => { + self.xpurple = self.xpurple.checked_sub(1).ok_or("Arithmetic underflow")?; + Ok(()) + }, + NftColor::Xleafgreen => { + self.xleafgreen = + self.xleafgreen.checked_sub(1).ok_or("Arithmetic underflow")?; + Ok(()) + }, + NftColor::Xgreen => { + self.xgreen = self.xgreen.checked_sub(1).ok_or("Arithmetic underflow")?; + Ok(()) + }, + } + } + + pub fn has_four_of_all_colors(&self) -> bool { + self.xorange >= 4 && + self.xpink >= 4 && self.xblue >= 4 && + self.xcyan >= 4 && self.xcoral >= 4 && + self.xpurple >= 4 && + self.xleafgreen >= 4 && + self.xgreen >= 4 + } + } \ No newline at end of file From 2db8736c1f900fcd4b1873893072832bf90fdcc6 Mon Sep 17 00:00:00 2001 From: Recrafter Date: Tue, 25 Jun 2024 10:19:01 +0700 Subject: [PATCH 06/15] Refactoring game pallet --- pallets/game/src/functions.rs | 3 +- pallets/game/src/lib.rs | 61 ++++++++++++++-------- pallets/game/src/properties.rs | 44 +++------------- pallets/game/src/tests.rs | 92 +++++++++++++++++++++++++++++----- pallets/game/src/types.rs | 11 ++-- 5 files changed, 132 insertions(+), 79 deletions(-) diff --git a/pallets/game/src/functions.rs b/pallets/game/src/functions.rs index 792d517..845229e 100644 --- a/pallets/game/src/functions.rs +++ b/pallets/game/src/functions.rs @@ -45,8 +45,9 @@ impl Pallet { } /// checks the answer and distributes the rewards accordingly. - pub fn check_result(difference: u16, game_id: u32) -> DispatchResult { + pub fn do_check_result(difference: u16, game_id: u32) -> DispatchResult { let game_info = GameInfo::::take(game_id).ok_or(Error::::NoActiveGame)?; + ensure!(game_info.guess.is_some(), Error::::NoGuess); if game_info.difficulty == DifficultyLevel::Pro { match difference { 0..=10 => { diff --git a/pallets/game/src/lib.rs b/pallets/game/src/lib.rs index e012ec2..88d559e 100644 --- a/pallets/game/src/lib.rs +++ b/pallets/game/src/lib.rs @@ -211,11 +211,6 @@ pub mod pallet { pub type TestProperties = StorageValue<_, BoundedVec, T::MaxProperty>, ValueQuery>; - /// Test for properties. - #[pallet::storage] - #[pallet::getter(fn test_prices)] - pub type TestPrices = StorageMap<_, Blake2_128Concat, u32, u32, OptionQuery>; - /// Vector of admins who can register users. #[pallet::storage] #[pallet::getter(fn admins)] @@ -229,7 +224,9 @@ pub mod pallet { /// A game has started. GameStarted { player: AccountIdOf, game_id: u32 }, /// An answer has been submitted. - AnswerSubmitted { player: AccountIdOf, game_id: u32 }, + AnswerSubmitted { player: AccountIdOf, game_id: u32, guess: u32 }, + /// The result has been checked. + ResultChecked { game_id: u32 }, /// A nft has been listed. NftListed { owner: AccountIdOf, collection_id: CollectionId, item_id: ItemId }, /// A nft has been delisted. @@ -301,6 +298,8 @@ pub mod pallet { TooManyAdmins, /// The user has to wait to request token. CantRequestToken, + /// There has been no guess from the player. + NoGuess, } #[pallet::hooks] @@ -469,7 +468,10 @@ pub mod pallet { Self::test_properties() .len(); let property = Self::test_properties()[random_number].clone(); - let game_datas = GameData { difficulty: game_type, player: signer.clone(), property }; + let game_datas = GameData { difficulty: game_type, player: signer.clone(), property, guess: None }; + let mut properties = TestProperties::::take(); + properties.retain(|property| property.id as usize != random_number); + TestProperties::::put(properties); GameInfo::::insert(game_id, game_datas); let next_game_id = game_id.checked_add(1).ok_or(Error::::ArithmeticOverflow)?; GameId::::put(next_game_id); @@ -490,20 +492,39 @@ pub mod pallet { #[pallet::weight(::WeightInfo::submit_answer())] pub fn submit_answer(origin: OriginFor, guess: u32, game_id: u32) -> DispatchResult { let signer = ensure_signed(origin)?; - let game_info = Self::game_info(game_id).ok_or(Error::::NoActiveGame)?; + let mut game_info = Self::game_info(game_id).ok_or(Error::::NoActiveGame)?; ensure!(signer == game_info.player, Error::::NoThePlayer); - let property_id = game_info.property.id; - let result: u32 = Self::test_prices(property_id).ok_or(Error::::NoProperty)?; - let difference_value = ((result as i32) + game_info.guess = Some(guess); + GameInfo::::insert(game_id, game_info); + Self::deposit_event(Event::::AnswerSubmitted { player: signer, game_id, guess }); + Ok(()) + } + + /// Checks the answer of the player and handles rewards accordingly. + /// + /// The origin must be root. + /// + /// Parameters: + /// - `guess`: The answer of the player. + /// - `game_id`: The id of the game that the result should be compared to. + /// - `price`: The price of the property. + /// - `secret`: The secret to decrypt the price and property data. + /// + /// Emits `ResultChecked` event when succesfful. + #[pallet::call_index(15)] + #[pallet::weight(::WeightInfo::submit_answer())] + pub fn check_result(origin: OriginFor, guess: u32, game_id: u32, price: u32, secret: BoundedVec::StringLimit>) -> DispatchResult { + T::GameOrigin::ensure_origin(origin)?; + let difference_value = ((price as i32) .checked_sub(guess as i32) .ok_or(Error::::ArithmeticUnderflow)?) - .checked_mul(1000) - .ok_or(Error::::MultiplyError)? - .checked_div(result as i32) - .ok_or(Error::::DivisionError)? - .abs(); - Self::check_result(difference_value.try_into().map_err(|_| Error::::ConversionError)?, game_id)?; - Self::deposit_event(Event::::AnswerSubmitted { player: signer, game_id }); + .checked_mul(1000) + .ok_or(Error::::MultiplyError)? + .checked_div(price as i32) + .ok_or(Error::::DivisionError)? + .abs(); + Self::do_check_result(difference_value.try_into().map_err(|_| Error::::ConversionError)?, game_id)?; + Self::deposit_event(Event::::ResultChecked { game_id }); Ok(()) } @@ -745,10 +766,9 @@ pub mod pallet { /// - `price`: The price of the property that will be added. #[pallet::call_index(10)] #[pallet::weight(::WeightInfo::add_property())] - pub fn add_property(origin: OriginFor, property: PropertyInfoData, price: u32) -> DispatchResult { + pub fn add_property(origin: OriginFor, property: PropertyInfoData) -> DispatchResult { T::GameOrigin::ensure_origin(origin)?; TestProperties::::try_append(property.clone()).map_err(|_| Error::::TooManyTest)?; - TestPrices::::insert(property.id, price); Ok(()) } @@ -765,7 +785,6 @@ pub mod pallet { let mut properties = TestProperties::::take(); properties.retain(|property| property.id != id); TestProperties::::put(properties); - TestPrices::::take(id); Ok(()) } diff --git a/pallets/game/src/properties.rs b/pallets/game/src/properties.rs index a65aa02..dbf3376 100644 --- a/pallets/game/src/properties.rs +++ b/pallets/game/src/properties.rs @@ -5,56 +5,28 @@ impl Pallet { pub(crate) fn create_test_properties() -> DispatchResult { let new_property = PropertyInfoData { id: 147229391, - bedrooms: 2, - bathrooms: 1, - summary: "Superb 2 double bedroom ground floor purpose-built apartment with sole use of garden. Directly opposite Hackney Downs Park, within walking distance of Clapton, Hackney Downs & Rectory Rd Stations. Benefitting from; 2 double bedrooms, fitted kitchen/diner, modern shower/WC, separate lounge with di...".as_bytes().to_vec().try_into().unwrap(), - property_sub_type: "Flat".as_bytes().to_vec().try_into().unwrap(), - first_visible_date: "2024-04-24T16:39:27Z".as_bytes().to_vec().try_into().unwrap(), - display_size: "".as_bytes().to_vec().try_into().unwrap(), - display_address: "St Peters Street, Islington".as_bytes().to_vec().try_into().unwrap(), - property_images1: "https://media.rightmove.co.uk/dir/crop/10:9-16:9/56k/55489/146480642/55489_2291824_IMG_00_0000_max_476x317.jpeg".as_bytes().to_vec().try_into().unwrap(), + data: "nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap(), + price: "kkjfkdjdkdjdkdjdk".as_bytes().to_vec().try_into().unwrap(), }; TestProperties::::try_append(new_property.clone()).map_err(|_| Error::::TooManyTest)?; - TestPrices::::insert(new_property.id, 220000); let new_property = PropertyInfoData { id: 146480642, - bedrooms: 2, - bathrooms: 1, - summary: "Exceptional, bright and spacious 915 sq ft period upper maisonette for sale with a balcony and 22'2 rear patio garden, presented in good condition and available chain free.".as_bytes().to_vec().try_into().unwrap(), - property_sub_type: "Flat".as_bytes().to_vec().try_into().unwrap(), - first_visible_date: "2024-04-24T16:39:27Z".as_bytes().to_vec().try_into().unwrap(), - display_size: "".as_bytes().to_vec().try_into().unwrap(), - display_address: "Aragon Tower, London, SE8".as_bytes().to_vec().try_into().unwrap(), - property_images1: "https://media.rightmove.co.uk/dir/crop/10:9-16:9/128k/127876/147229391/127876_33052394_IMG_12_0000_max_476x317.gif".as_bytes().to_vec().try_into().unwrap(), + data: "nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap(), + price: "kkjfkdjdkdjdkdjdk".as_bytes().to_vec().try_into().unwrap(), }; TestProperties::::try_append(new_property.clone()).map_err(|_| Error::::TooManyTest)?; - TestPrices::::insert(new_property.id, 650000); let new_property = PropertyInfoData { id: 147031382, - bedrooms: 3, - bathrooms: 2, - summary: "Exceptional, bright and spacious 915 sq ft period upper maisonette for sale with a balcony and 22'2 rear patio garden, presented in good condition and available chain free.".as_bytes().to_vec().try_into().unwrap(), - property_sub_type: "Flat".as_bytes().to_vec().try_into().unwrap(), - first_visible_date: "2024-04-24T16:39:27Z".as_bytes().to_vec().try_into().unwrap(), - display_size: "".as_bytes().to_vec().try_into().unwrap(), - display_address: "Aragon Tower, London, SE8".as_bytes().to_vec().try_into().unwrap(), - property_images1: "https://media.rightmove.co.uk/dir/crop/10:9-16:9/128k/127876/147229391/127876_33052394_IMG_12_0000_max_476x317.gif".as_bytes().to_vec().try_into().unwrap(), + data: "nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap(), + price: "kkjfkdjdkdjdkdjdk".as_bytes().to_vec().try_into().unwrap(), }; TestProperties::::try_append(new_property.clone()).map_err(|_| Error::::TooManyTest)?; - TestPrices::::insert(new_property.id, 525000); let new_property = PropertyInfoData { id: 147031382, - bedrooms: 3, - bathrooms: 2, - summary: "Exceptional, bright and spacious 915 sq ft period upper maisonette for sale with a balcony and 22'2 rear patio garden, presented in good condition and available chain free.".as_bytes().to_vec().try_into().unwrap(), - property_sub_type: "Flat".as_bytes().to_vec().try_into().unwrap(), - first_visible_date: "2024-04-24T16:39:27Z".as_bytes().to_vec().try_into().unwrap(), - display_size: "".as_bytes().to_vec().try_into().unwrap(), - display_address: "Aragon Tower, London, SE8".as_bytes().to_vec().try_into().unwrap(), - property_images1: "https://media.rightmove.co.uk/dir/crop/10:9-16:9/128k/127876/147229391/127876_33052394_IMG_12_0000_max_476x317.gif".as_bytes().to_vec().try_into().unwrap(), + data: "nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap(), + price: "kkjfkdjdkdjdkdjdk".as_bytes().to_vec().try_into().unwrap(), }; TestProperties::::try_append(new_property.clone()).map_err(|_| Error::::TooManyTest)?; - TestPrices::::insert(new_property.id, 525000); Ok(()) } } diff --git a/pallets/game/src/tests.rs b/pallets/game/src/tests.rs index 6c4784e..3e2c9c3 100644 --- a/pallets/game/src/tests.rs +++ b/pallets/game/src/tests.rs @@ -1,4 +1,4 @@ -use crate::{mock::*, Error}; +use crate::{mock::*, Error, Event}; use frame_support::{assert_noop, assert_ok}; use sp_runtime::{traits::BadOrigin, DispatchError, ModuleError}; use crate::PropertyInfoData; @@ -8,7 +8,9 @@ fn practise_round(player: AccountId, game_id: u32) { RuntimeOrigin::signed(player.clone()), crate::DifficultyLevel::Practice, )); - assert_ok!(GameModule::submit_answer(RuntimeOrigin::signed(player), 220000, game_id)); + assert_ok!(GameModule::submit_answer(RuntimeOrigin::signed(player.clone()), 220000, game_id)); + System::assert_last_event(Event::AnswerSubmitted { player: player, game_id: game_id, guess: 220_000 }.into()); + assert_ok!(GameModule::check_result(RuntimeOrigin::root(), 220_000, game_id, 220_000,"nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap())); } #[test] @@ -155,6 +157,8 @@ fn submit_answer_works() { crate::DifficultyLevel::Player, )); assert_ok!(GameModule::submit_answer(RuntimeOrigin::signed([0; 32].into()), 223_000, 1)); + System::assert_last_event(Event::AnswerSubmitted { player: [0; 32].into(), game_id: 1, guess: 223_000 }.into()); + assert_ok!(GameModule::check_result(RuntimeOrigin::root(), 223_000, 1, 220_000,"nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap())); assert_eq!(GameModule::game_info(0).is_none(), true); assert_eq!(GameModule::users::([0; 32].into()).unwrap().points, 80); assert_ok!(GameModule::play_game( @@ -162,6 +166,8 @@ fn submit_answer_works() { crate::DifficultyLevel::Player, )); assert_ok!(GameModule::submit_answer(RuntimeOrigin::signed([0; 32].into()), 220_000, 2)); + System::assert_last_event(Event::AnswerSubmitted { player: [0; 32].into(), game_id: 2, guess: 220_000 }.into()); + assert_ok!(GameModule::check_result(RuntimeOrigin::root(), 220_000, 2, 220_000,"nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap())); assert_eq!(GameModule::game_info(1).is_none(), true); assert_eq!(GameModule::users::([0; 32].into()).unwrap().points, 180); assert_eq!(Nfts::owner(0, 0).unwrap(), [0; 32].into()); @@ -187,16 +193,22 @@ fn leaderboard_works() { crate::DifficultyLevel::Player, )); assert_ok!(GameModule::submit_answer(RuntimeOrigin::signed([0; 32].into()), 230_000, 3)); + System::assert_last_event(Event::AnswerSubmitted { player: [0; 32].into(), game_id: 3, guess: 230_000 }.into()); + assert_ok!(GameModule::check_result(RuntimeOrigin::root(), 230_000, 3, 220_000,"nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap())); assert_ok!(GameModule::play_game( RuntimeOrigin::signed([1; 32].into()), crate::DifficultyLevel::Player, )); assert_ok!(GameModule::submit_answer(RuntimeOrigin::signed([1; 32].into()), 225_000, 4)); + System::assert_last_event(Event::AnswerSubmitted { player: [1; 32].into(), game_id: 4, guess: 225_000 }.into()); + assert_ok!(GameModule::check_result(RuntimeOrigin::root(), 225_000, 4, 220_000,"nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap())); assert_ok!(GameModule::play_game( RuntimeOrigin::signed([2; 32].into()), crate::DifficultyLevel::Player, )); assert_ok!(GameModule::submit_answer(RuntimeOrigin::signed([2; 32].into()), 220_000, 5)); + System::assert_last_event(Event::AnswerSubmitted { player: [2; 32].into(), game_id: 5, guess: 220_000 }.into()); + assert_ok!(GameModule::check_result(RuntimeOrigin::root(), 220_000, 5, 220_000,"nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap())); assert_eq!(GameModule::game_info(0).is_none(), true); assert_eq!(GameModule::users::([2; 32].into()).unwrap().points, 155); assert_eq!(GameModule::users::([1; 32].into()).unwrap().points, 80); @@ -236,6 +248,8 @@ fn transfer_of_nft_does_not_work() { crate::DifficultyLevel::Player, )); assert_ok!(GameModule::submit_answer(RuntimeOrigin::signed([0; 32].into()), 220_000, 1)); + System::assert_last_event(Event::AnswerSubmitted { player: [0; 32].into(), game_id: 1, guess: 220_000 }.into()); + assert_ok!(GameModule::check_result(RuntimeOrigin::root(), 220_000, 1, 220_000,"nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap())); assert_eq!(GameModule::game_info(1).is_none(), true); assert_eq!(Nfts::owner(0, 0).unwrap(), [0; 32].into()); assert_noop!( @@ -268,6 +282,8 @@ fn list_nft_works() { crate::DifficultyLevel::Player, )); assert_ok!(GameModule::submit_answer(RuntimeOrigin::signed([0; 32].into()), 220_000, 1)); + System::assert_last_event(Event::AnswerSubmitted { player: [0; 32].into(), game_id: 1, guess: 220_000 }.into()); + assert_ok!(GameModule::check_result(RuntimeOrigin::root(), 220_000, 1, 220_000,"nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap())); assert_eq!(GameModule::game_info(1).is_none(), true); assert_eq!(GameModule::users::([0; 32].into()).unwrap().points, 155); assert_eq!(Nfts::owner(0, 0).unwrap(), [0; 32].into()); @@ -291,6 +307,8 @@ fn list_nft_doesnt_work() { crate::DifficultyLevel::Player, )); assert_ok!(GameModule::submit_answer(RuntimeOrigin::signed([0; 32].into()), 220_000, 1)); + System::assert_last_event(Event::AnswerSubmitted { player: [0; 32].into(), game_id: 1, guess: 220_000 }.into()); + assert_ok!(GameModule::check_result(RuntimeOrigin::root(), 220_000, 1, 220_000,"nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap())); assert_eq!(GameModule::game_info(1).is_none(), true); assert_eq!(GameModule::users::([0; 32].into()).unwrap().points, 155); assert_eq!(Nfts::owner(0, 0).unwrap(), [0; 32].into()); @@ -315,6 +333,8 @@ fn delist_nft_works() { crate::DifficultyLevel::Player, )); assert_ok!(GameModule::submit_answer(RuntimeOrigin::signed([0; 32].into()), 220_000, 1)); + System::assert_last_event(Event::AnswerSubmitted { player: [0; 32].into(), game_id: 1, guess: 220_000 }.into()); + assert_ok!(GameModule::check_result(RuntimeOrigin::root(), 220_000, 1, 220_000,"nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap())); assert_eq!(GameModule::game_info(0).is_none(), true); assert_eq!(GameModule::users::([0; 32].into()).unwrap().points, 155); assert_eq!(Nfts::owner(0, 0).unwrap(), [0; 32].into()); @@ -352,6 +372,8 @@ fn delist_nft_doesnt_works() { crate::DifficultyLevel::Player, )); assert_ok!(GameModule::submit_answer(RuntimeOrigin::signed([0; 32].into()), 220_000, 1)); + System::assert_last_event(Event::AnswerSubmitted { player: [0; 32].into(), game_id: 1, guess: 220_000 }.into()); + assert_ok!(GameModule::check_result(RuntimeOrigin::root(), 220_000, 1, 220_000,"nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap())); assert_eq!(GameModule::game_info(0).is_none(), true); assert_eq!(GameModule::users::([0; 32].into()).unwrap().points, 155); assert_eq!(Nfts::owner(0, 0).unwrap(), [0; 32].into()); @@ -380,6 +402,8 @@ fn make_offer_works() { crate::DifficultyLevel::Player, )); assert_ok!(GameModule::submit_answer(RuntimeOrigin::signed([0; 32].into()), 220_000, 1)); + System::assert_last_event(Event::AnswerSubmitted { player: [0; 32].into(), game_id: 1, guess: 220_000 }.into()); + assert_ok!(GameModule::check_result(RuntimeOrigin::root(), 220_000, 1, 220_000,"nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap())); assert_eq!(GameModule::game_info(0).is_none(), true); assert_eq!(GameModule::users::([0; 32].into()).unwrap().points, 155); assert_eq!(Nfts::owner(0, 0).unwrap(), [0; 32].into()); @@ -389,6 +413,8 @@ fn make_offer_works() { crate::DifficultyLevel::Player, )); assert_ok!(GameModule::submit_answer(RuntimeOrigin::signed([1; 32].into()), 220_000, 3)); + System::assert_last_event(Event::AnswerSubmitted { player: [1; 32].into(), game_id: 3, guess: 220_000 }.into()); + assert_ok!(GameModule::check_result(RuntimeOrigin::root(), 220_000, 3, 220_000,"nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap())); assert_eq!(Nfts::owner(0, 1).unwrap(), [1; 32].into()); assert_ok!(GameModule::list_nft(RuntimeOrigin::signed([0; 32].into()), 0, 0,)); assert_eq!(Nfts::owner(0, 0).unwrap(), GameModule::account_id()); @@ -435,6 +461,8 @@ fn withdraw_offer_works() { crate::DifficultyLevel::Player, )); assert_ok!(GameModule::submit_answer(RuntimeOrigin::signed([0; 32].into()), 220_000, 1)); + System::assert_last_event(Event::AnswerSubmitted { player: [0; 32].into(), game_id: 1, guess: 220_000 }.into()); + assert_ok!(GameModule::check_result(RuntimeOrigin::root(), 220_000, 1, 220_000,"nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap())); assert_eq!(GameModule::game_info(0).is_none(), true); assert_eq!(GameModule::users::([0; 32].into()).unwrap().points, 155); assert_eq!(Nfts::owner(0, 0).unwrap(), [0; 32].into()); @@ -444,6 +472,8 @@ fn withdraw_offer_works() { crate::DifficultyLevel::Player, )); assert_ok!(GameModule::submit_answer(RuntimeOrigin::signed([1; 32].into()), 220_000, 3)); + System::assert_last_event(Event::AnswerSubmitted { player: [1; 32].into(), game_id: 3, guess: 220_000 }.into()); + assert_ok!(GameModule::check_result(RuntimeOrigin::root(), 220_000, 3, 220_000,"nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap())); assert_eq!(Nfts::owner(0, 1).unwrap(), [1; 32].into()); assert_ok!(GameModule::list_nft(RuntimeOrigin::signed([0; 32].into()), 0, 0,)); assert_eq!(Nfts::owner(0, 0).unwrap(), GameModule::account_id()); @@ -470,6 +500,8 @@ fn withdraw_offer_fails() { crate::DifficultyLevel::Player, )); assert_ok!(GameModule::submit_answer(RuntimeOrigin::signed([0; 32].into()), 220_000, 1)); + System::assert_last_event(Event::AnswerSubmitted { player: [0; 32].into(), game_id: 1, guess: 220_000 }.into()); + assert_ok!(GameModule::check_result(RuntimeOrigin::root(), 220_000, 1, 220_000,"nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap())); assert_eq!(GameModule::game_info(0).is_none(), true); assert_eq!(GameModule::users::([0; 32].into()).unwrap().points, 155); assert_eq!(Nfts::owner(0, 0).unwrap(), [0; 32].into()); @@ -479,6 +511,8 @@ fn withdraw_offer_fails() { crate::DifficultyLevel::Player, )); assert_ok!(GameModule::submit_answer(RuntimeOrigin::signed([1; 32].into()), 220_000, 3)); + System::assert_last_event(Event::AnswerSubmitted { player: [1; 32].into(), game_id: 3, guess: 220_000 }.into()); + assert_ok!(GameModule::check_result(RuntimeOrigin::root(), 220_000, 3, 220_000,"nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap())); assert_eq!(Nfts::owner(0, 1).unwrap(), [1; 32].into()); assert_ok!(GameModule::list_nft(RuntimeOrigin::signed([0; 32].into()), 0, 0,)); assert_eq!(Nfts::owner(0, 0).unwrap(), GameModule::account_id()); @@ -511,6 +545,8 @@ fn handle_offer_accept_works() { crate::DifficultyLevel::Player, )); assert_ok!(GameModule::submit_answer(RuntimeOrigin::signed([0; 32].into()), 220_000, 1)); + System::assert_last_event(Event::AnswerSubmitted { player: [0; 32].into(), game_id: 1, guess: 220_000 }.into()); + assert_ok!(GameModule::check_result(RuntimeOrigin::root(), 220_000, 1, 220_000,"nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap())); assert_eq!(GameModule::users::([0; 32].into()).unwrap().points, 155); assert_eq!(GameModule::game_info(0).is_none(), true); assert_eq!(Nfts::owner(0, 0).unwrap(), [0; 32].into()); @@ -520,17 +556,23 @@ fn handle_offer_accept_works() { crate::DifficultyLevel::Player, )); assert_ok!(GameModule::submit_answer(RuntimeOrigin::signed([1; 32].into()), 220_000, 3)); + System::assert_last_event(Event::AnswerSubmitted { player: [1; 32].into(), game_id: 3, guess: 220_000 }.into()); + assert_ok!(GameModule::check_result(RuntimeOrigin::root(), 220_000, 3, 220_000,"nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap())); assert_ok!(GameModule::play_game( RuntimeOrigin::signed([0; 32].into()), crate::DifficultyLevel::Player, )); assert_ok!(GameModule::submit_answer(RuntimeOrigin::signed([0; 32].into()), 220_000, 4)); + System::assert_last_event(Event::AnswerSubmitted { player: [0; 32].into(), game_id: 4, guess: 220_000 }.into()); + assert_ok!(GameModule::check_result(RuntimeOrigin::root(), 220_000, 4, 220_000,"nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap())); assert_eq!(GameModule::users::([0; 32].into()).unwrap().points, 275); assert_ok!(GameModule::play_game( RuntimeOrigin::signed([0; 32].into()), crate::DifficultyLevel::Player, )); assert_ok!(GameModule::submit_answer(RuntimeOrigin::signed([0; 32].into()), 220_000, 5)); + System::assert_last_event(Event::AnswerSubmitted { player: [0; 32].into(), game_id: 5, guess: 220_000 }.into()); + assert_ok!(GameModule::check_result(RuntimeOrigin::root(), 220_000, 5, 220_000,"nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap())); assert_eq!(GameModule::users::([0; 32].into()).unwrap().nfts.xorange, 3); assert_eq!(GameModule::users::([0; 32].into()).unwrap().points, 495); assert_eq!(GameModule::users::([1; 32].into()).unwrap().nfts.xorange, 1); @@ -597,6 +639,8 @@ fn handle_offer_reject_works() { crate::DifficultyLevel::Player, )); assert_ok!(GameModule::submit_answer(RuntimeOrigin::signed([0; 32].into()), 220_000, 1)); + System::assert_last_event(Event::AnswerSubmitted { player: [0; 32].into(), game_id: 1, guess: 220_000 }.into()); + assert_ok!(GameModule::check_result(RuntimeOrigin::root(), 220_000, 1, 220_000,"nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap())); assert_eq!(GameModule::game_info(0).is_none(), true); assert_eq!(GameModule::users::([0; 32].into()).unwrap().points, 155); assert_eq!(Nfts::owner(0, 0).unwrap(), [0; 32].into()); @@ -606,6 +650,8 @@ fn handle_offer_reject_works() { crate::DifficultyLevel::Player, )); assert_ok!(GameModule::submit_answer(RuntimeOrigin::signed([1; 32].into()), 220_000, 3)); + System::assert_last_event(Event::AnswerSubmitted { player: [1; 32].into(), game_id: 3, guess: 220_000 }.into()); + assert_ok!(GameModule::check_result(RuntimeOrigin::root(), 220_000, 3, 220_000,"nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap())); assert_eq!(Nfts::owner(0, 1).unwrap(), [1; 32].into()); assert_ok!(GameModule::list_nft(RuntimeOrigin::signed([0; 32].into()), 0, 0,)); assert_eq!(Nfts::owner(0, 0).unwrap(), GameModule::account_id()); @@ -651,6 +697,8 @@ fn handle_offer_doesnt_works() { crate::DifficultyLevel::Player, )); assert_ok!(GameModule::submit_answer(RuntimeOrigin::signed([0; 32].into()), 220_000, 1)); + System::assert_last_event(Event::AnswerSubmitted { player: [0; 32].into(), game_id: 1, guess: 220_000 }.into()); + assert_ok!(GameModule::check_result(RuntimeOrigin::root(), 220_000, 1, 220_000,"nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap())); assert_eq!(GameModule::game_info(0).is_none(), true); assert_eq!(GameModule::users::([0; 32].into()).unwrap().points, 155); assert_eq!(Nfts::owner(0, 0).unwrap(), [0; 32].into()); @@ -660,6 +708,8 @@ fn handle_offer_doesnt_works() { crate::DifficultyLevel::Player, )); assert_ok!(GameModule::submit_answer(RuntimeOrigin::signed([1; 32].into()), 220_000, 3)); + System::assert_last_event(Event::AnswerSubmitted { player: [1; 32].into(), game_id: 3, guess: 220_000 }.into()); + assert_ok!(GameModule::check_result(RuntimeOrigin::root(), 220_000, 3, 220_000,"nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap())); assert_eq!(Nfts::owner(0, 1).unwrap(), [1; 32].into()); assert_ok!(GameModule::list_nft(RuntimeOrigin::signed([0; 32].into()), 0, 0,)); assert_eq!(Nfts::owner(0, 0).unwrap(), GameModule::account_id()); @@ -694,6 +744,8 @@ fn play_multiple_rounds_works() { 217_000, x )); + System::assert_last_event(Event::AnswerSubmitted { player: [0; 32].into(), game_id: x, guess: 217_000 }.into()); + assert_ok!(GameModule::check_result(RuntimeOrigin::root(), 217_000, x, 220_000,"nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap())); } assert_ok!(GameModule::play_game( RuntimeOrigin::signed([0; 32].into()), @@ -710,17 +762,11 @@ fn add_property_works() { System::set_block_number(1); assert_ok!(GameModule::setup_game(RuntimeOrigin::root())); let new_property = PropertyInfoData { - id: 146480642, - bedrooms: 2, - bathrooms: 1, - summary: "Spacious apartment in the heart of New York City with a balcony and garden.".as_bytes().to_vec().try_into().unwrap(), - property_sub_type: "Apartment".as_bytes().to_vec().try_into().unwrap(), - first_visible_date: "2024-05-06T12:00:00Z".as_bytes().to_vec().try_into().unwrap(), - display_size: "1000 sq ft".as_bytes().to_vec().try_into().unwrap(), - display_address: "New York City, NY".as_bytes().to_vec().try_into().unwrap(), - property_images1: "https://example.com/image1.jpg".as_bytes().to_vec().try_into().unwrap(), - }; - assert_ok!(GameModule::add_property(RuntimeOrigin::root(), new_property, 122565)); + id: 147031382, + data: "nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap(), + price: "kkjfkdjdkdjdkdjdk".as_bytes().to_vec().try_into().unwrap(), + }; + assert_ok!(GameModule::add_property(RuntimeOrigin::root(), new_property)); assert_eq!(GameModule::test_properties().len(), 5); }); } @@ -759,3 +805,23 @@ fn request_token_doesnt_works() { assert_noop!(GameModule::request_token(RuntimeOrigin::signed([0; 32].into())), Error::::CantRequestToken); }); } + +#[test] +fn check_result_fails() { + new_test_ext().execute_with(|| { + System::set_block_number(1); + assert_ok!(GameModule::setup_game(RuntimeOrigin::root())); + assert_eq!(GameModule::test_properties().len(), 4); + assert_ok!(GameModule::add_to_admins(RuntimeOrigin::root(), [4; 32].into())); + assert_ok!(GameModule::register_user(RuntimeOrigin::signed([4; 32].into()), [0; 32].into())); + practise_round([0; 32].into(), 0); + assert_noop!(GameModule::check_result(RuntimeOrigin::root(), 223_000, 0, 220_000,"nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap()), Error::::NoActiveGame); + assert_noop!(GameModule::check_result(RuntimeOrigin::root(), 223_000, 1, 220_000,"nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap()), Error::::NoActiveGame); + assert_ok!(GameModule::play_game( + RuntimeOrigin::signed([0; 32].into()), + crate::DifficultyLevel::Player, + )); + assert_noop!(GameModule::check_result(RuntimeOrigin::root(), 223_000, 1, 220_000,"nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap()), Error::::NoGuess); + }); +} + \ No newline at end of file diff --git a/pallets/game/src/types.rs b/pallets/game/src/types.rs index e84c30d..8eacc6f 100644 --- a/pallets/game/src/types.rs +++ b/pallets/game/src/types.rs @@ -64,6 +64,7 @@ use frame_system::pallet_prelude::*; pub difficulty: DifficultyLevel, pub player: AccountIdOf, pub property: PropertyInfoData, + pub guess: Option, } /// Listing infos of a NFT. @@ -102,14 +103,8 @@ use frame_system::pallet_prelude::*; #[scale_info(skip_type_params(T))] pub struct PropertyInfoData { pub id: u32, - pub bedrooms: u32, - pub bathrooms: u32, - pub summary: BoundedVec::StringLimit>, - pub property_sub_type: BoundedVec::StringLimit>, - pub first_visible_date: BoundedVec::StringLimit>, - pub display_size: BoundedVec::StringLimit>, - pub display_address: BoundedVec::StringLimit>, - pub property_images1: BoundedVec::StringLimit>, + pub data: BoundedVec::StringLimit>, + pub price: BoundedVec::StringLimit>, } /// Struct for the user datas. From bdf96d2664e0018c644448820b3ddd196ab5aa76 Mon Sep 17 00:00:00 2001 From: Recrafter Date: Tue, 25 Jun 2024 16:46:14 +0700 Subject: [PATCH 07/15] Adding pallet_skip_feeless_payment --- Cargo.lock | 63 ++- node/Cargo.toml | 1 + node/src/benchmarking.rs | 4 +- pallets/game/src/benchmarking.rs | 10 +- pallets/game/src/functions.rs | 704 +++++++++++++++---------------- pallets/game/src/lib.rs | 108 +++-- pallets/game/src/mock.rs | 4 +- pallets/game/src/properties.rs | 24 +- pallets/game/src/tests.rs | 527 ++++++++++++++++++----- pallets/game/src/types.rs | 572 +++++++++++++------------ runtime/Cargo.toml | 4 + runtime/src/lib.rs | 14 +- 12 files changed, 1210 insertions(+), 825 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e7fa102..a9bd2ad 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4584,6 +4584,7 @@ dependencies = [ "futures", "jsonrpsee", "node-template-runtime", + "pallet-skip-feeless-payment", "pallet-transaction-payment", "pallet-transaction-payment-rpc", "sc-basic-authorship", @@ -4637,6 +4638,7 @@ dependencies = [ "pallet-grandpa", "pallet-insecure-randomness-collective-flip", "pallet-nfts", + "pallet-skip-feeless-payment", "pallet-sudo", "pallet-timestamp", "pallet-transaction-payment", @@ -4985,6 +4987,19 @@ dependencies = [ "sp-trie", ] +[[package]] +name = "pallet-skip-feeless-payment" +version = "1.0.0-dev" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +dependencies = [ + "frame-support", + "frame-system", + "parity-scale-codec", + "scale-info", + "sp-runtime", + "sp-std 8.0.0", +] + [[package]] name = "pallet-sudo" version = "4.0.0-dev" @@ -5088,9 +5103,9 @@ dependencies = [ [[package]] name = "parity-scale-codec" -version = "3.6.9" +version = "3.6.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "881331e34fa842a2fb61cc2db9643a8fedc615e47cfcc52597d1af0db9a7e8fe" +checksum = "306800abfa29c7f16596b5970a588435e3d5b3149683d00c12b699cc19f895ee" dependencies = [ "arrayvec", "bitvec", @@ -5103,11 +5118,11 @@ dependencies = [ [[package]] name = "parity-scale-codec-derive" -version = "3.6.9" +version = "3.6.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be30eaf4b0a9fba5336683b38de57bb86d179a35862ba6bfcf57625d006bde5b" +checksum = "d830939c76d294956402033aee57a6da7b438f2294eb94864c37b0569053a42c" dependencies = [ - "proc-macro-crate 2.0.0", + "proc-macro-crate 3.1.0", "proc-macro2", "quote", "syn 1.0.109", @@ -5512,15 +5527,6 @@ dependencies = [ "toml 0.5.11", ] -[[package]] -name = "proc-macro-crate" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e8366a6159044a37876a2b9817124296703c586a5c92e2c53751fa06d8d43e8" -dependencies = [ - "toml_edit 0.20.7", -] - [[package]] name = "proc-macro-crate" version = "3.1.0" @@ -7870,7 +7876,7 @@ dependencies = [ [[package]] name = "sp-crypto-ec-utils" version = "0.10.0" -source = "git+https://github.com/paritytech/polkadot-sdk#4875ea11aeef4f3fc7d724940e5ffb703830619b" +source = "git+https://github.com/paritytech/polkadot-sdk#63e264446f6cabff06be72912eae902662dcb699" dependencies = [ "ark-bls12-377", "ark-bls12-377-ext", @@ -7909,7 +7915,7 @@ dependencies = [ [[package]] name = "sp-debug-derive" version = "14.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#4875ea11aeef4f3fc7d724940e5ffb703830619b" +source = "git+https://github.com/paritytech/polkadot-sdk#63e264446f6cabff06be72912eae902662dcb699" dependencies = [ "proc-macro2", "quote", @@ -7930,7 +7936,7 @@ dependencies = [ [[package]] name = "sp-externalities" version = "0.25.0" -source = "git+https://github.com/paritytech/polkadot-sdk#4875ea11aeef4f3fc7d724940e5ffb703830619b" +source = "git+https://github.com/paritytech/polkadot-sdk#63e264446f6cabff06be72912eae902662dcb699" dependencies = [ "environmental", "parity-scale-codec", @@ -8115,7 +8121,7 @@ dependencies = [ [[package]] name = "sp-runtime-interface" version = "24.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#4875ea11aeef4f3fc7d724940e5ffb703830619b" +source = "git+https://github.com/paritytech/polkadot-sdk#63e264446f6cabff06be72912eae902662dcb699" dependencies = [ "bytes", "impl-trait-for-tuples", @@ -8147,7 +8153,7 @@ dependencies = [ [[package]] name = "sp-runtime-interface-proc-macro" version = "17.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#4875ea11aeef4f3fc7d724940e5ffb703830619b" +source = "git+https://github.com/paritytech/polkadot-sdk#63e264446f6cabff06be72912eae902662dcb699" dependencies = [ "Inflector", "expander", @@ -8239,7 +8245,7 @@ source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0 [[package]] name = "sp-std" version = "14.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#4875ea11aeef4f3fc7d724940e5ffb703830619b" +source = "git+https://github.com/paritytech/polkadot-sdk#63e264446f6cabff06be72912eae902662dcb699" [[package]] name = "sp-storage" @@ -8257,7 +8263,7 @@ dependencies = [ [[package]] name = "sp-storage" version = "19.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#4875ea11aeef4f3fc7d724940e5ffb703830619b" +source = "git+https://github.com/paritytech/polkadot-sdk#63e264446f6cabff06be72912eae902662dcb699" dependencies = [ "impl-serde", "parity-scale-codec", @@ -8294,7 +8300,7 @@ dependencies = [ [[package]] name = "sp-tracing" version = "16.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#4875ea11aeef4f3fc7d724940e5ffb703830619b" +source = "git+https://github.com/paritytech/polkadot-sdk#63e264446f6cabff06be72912eae902662dcb699" dependencies = [ "parity-scale-codec", "tracing", @@ -8394,7 +8400,7 @@ dependencies = [ [[package]] name = "sp-wasm-interface" version = "20.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#4875ea11aeef4f3fc7d724940e5ffb703830619b" +source = "git+https://github.com/paritytech/polkadot-sdk#63e264446f6cabff06be72912eae902662dcb699" dependencies = [ "impl-trait-for-tuples", "log", @@ -8965,17 +8971,6 @@ dependencies = [ "serde", ] -[[package]] -name = "toml_edit" -version = "0.20.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70f427fce4d84c72b5b732388bf4a9f4531b53f74e2887e3ecb2481f68f66d81" -dependencies = [ - "indexmap 2.2.6", - "toml_datetime", - "winnow 0.5.40", -] - [[package]] name = "toml_edit" version = "0.21.1" diff --git a/node/Cargo.toml b/node/Cargo.toml index 45c8b62..4a94998 100644 --- a/node/Cargo.toml +++ b/node/Cargo.toml @@ -44,6 +44,7 @@ sp-inherents = { version = "4.0.0-dev", git = "https://github.com/paritytech/pol sp-keyring = { version = "24.0.0", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } frame-system = { version = "4.0.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } pallet-transaction-payment = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } +pallet-skip-feeless-payment = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } # These dependencies are used for the node template's RPCs jsonrpsee = { version = "0.16.2", features = ["server"] } diff --git a/node/src/benchmarking.rs b/node/src/benchmarking.rs index 6e29ad1..7c0b8cb 100644 --- a/node/src/benchmarking.rs +++ b/node/src/benchmarking.rs @@ -120,7 +120,9 @@ pub fn create_benchmark_extrinsic( )), frame_system::CheckNonce::::from(nonce), frame_system::CheckWeight::::new(), - pallet_transaction_payment::ChargeTransactionPayment::::from(0), + pallet_skip_feeless_payment::SkipCheckIfFeeless::from( + pallet_transaction_payment::ChargeTransactionPayment::::from(0), + ), ); let raw_payload = runtime::SignedPayload::from_raw( diff --git a/pallets/game/src/benchmarking.rs b/pallets/game/src/benchmarking.rs index 31d7885..bcbca53 100644 --- a/pallets/game/src/benchmarking.rs +++ b/pallets/game/src/benchmarking.rs @@ -155,7 +155,10 @@ mod benchmarks { )); let caller2: T::AccountId = account("caller2", 0, 0); let admin: T::AccountId = account("admin", 0, 0); - assert_ok!(GameModule::::register_user(RawOrigin::Signed(admin).into(), caller2.clone())); + assert_ok!(GameModule::::register_user( + RawOrigin::Signed(admin).into(), + caller2.clone() + )); practise_round::(caller2.clone(), 2); assert_ok!(GameModule::::play_game( RawOrigin::Signed(caller2.clone()).into(), @@ -193,7 +196,10 @@ mod benchmarks { )); let caller2: T::AccountId = account("caller2", 0, 0); let admin: T::AccountId = account("admin", 0, 0); - assert_ok!(GameModule::::register_user(RawOrigin::Signed(admin).into(), caller2.clone())); + assert_ok!(GameModule::::register_user( + RawOrigin::Signed(admin).into(), + caller2.clone() + )); practise_round::(caller2.clone(), 2); assert_ok!(GameModule::::play_game( RawOrigin::Signed(caller2.clone()).into(), diff --git a/pallets/game/src/functions.rs b/pallets/game/src/functions.rs index 845229e..ff94b31 100644 --- a/pallets/game/src/functions.rs +++ b/pallets/game/src/functions.rs @@ -3,384 +3,364 @@ use frame_support::pallet_prelude::*; use frame_system::pallet_prelude::*; impl Pallet { - /// Get the account id of the pallet - pub fn account_id() -> AccountIdOf { - ::PalletId::get().into_account_truncating() - } + /// Get the account id of the pallet + pub fn account_id() -> AccountIdOf { + ::PalletId::get().into_account_truncating() + } - /// checks if the signer has enough points to start a game. - pub fn check_enough_points( - signer: AccountIdOf, - game_type: DifficultyLevel, - ) -> DispatchResult { - if game_type == DifficultyLevel::Pro { - ensure!( - Self::users(signer.clone()) - .ok_or(Error::::UserNotRegistered)? - .practise_rounds > 0, - Error::::NoPractise - ); - ensure!( - Self::users(signer).ok_or(Error::::UserNotRegistered)?.points >= 50, - Error::::NotEnoughPoints - ); - } else if game_type == DifficultyLevel::Player { - ensure!( - Self::users(signer.clone()) - .ok_or(Error::::UserNotRegistered)? - .practise_rounds > 0, - Error::::NoPractise - ); - ensure!( - Self::users(signer).ok_or(Error::::UserNotRegistered)?.points >= 25, - Error::::NotEnoughPoints - ); - } else { - ensure!( - Self::users(signer).ok_or(Error::::UserNotRegistered)?.practise_rounds < 5, - Error::::TooManyPractise - ); - } - Ok(()) + /// checks if the signer has enough points to start a game. + pub fn check_enough_points( + signer: AccountIdOf, + game_type: DifficultyLevel, + ) -> DispatchResult { + if game_type == DifficultyLevel::Pro { + ensure!( + Self::users(signer.clone()) + .ok_or(Error::::UserNotRegistered)? + .practise_rounds > 0, + Error::::NoPractise + ); + ensure!( + Self::users(signer).ok_or(Error::::UserNotRegistered)?.points >= 50, + Error::::NotEnoughPoints + ); + } else if game_type == DifficultyLevel::Player { + ensure!( + Self::users(signer.clone()) + .ok_or(Error::::UserNotRegistered)? + .practise_rounds > 0, + Error::::NoPractise + ); + ensure!( + Self::users(signer).ok_or(Error::::UserNotRegistered)?.points >= 25, + Error::::NotEnoughPoints + ); + } else { + ensure!( + Self::users(signer).ok_or(Error::::UserNotRegistered)?.practise_rounds < 5, + Error::::TooManyPractise + ); } + Ok(()) + } - /// checks the answer and distributes the rewards accordingly. - pub fn do_check_result(difference: u16, game_id: u32) -> DispatchResult { - let game_info = GameInfo::::take(game_id).ok_or(Error::::NoActiveGame)?; - ensure!(game_info.guess.is_some(), Error::::NoGuess); - if game_info.difficulty == DifficultyLevel::Pro { - match difference { - 0..=10 => { - let (hashi, _) = T::GameRandomness::random(&[game_id as u8]); - let u32_value = u32::from_le_bytes( - hashi.as_ref()[4..8] - .try_into() - .map_err(|_| Error::::ConversionError)?, - ); - let random_number = (u32_value % 8) - .checked_add( - 8 * (Self::current_round() - .checked_sub(1) - .ok_or(Error::::ArithmeticUnderflow)?), - ) - .ok_or(Error::::ArithmeticOverflow)?; - let collection_id: ::CollectionId = - random_number.into(); - let next_item_id = Self::next_color_id(collection_id); - let item_id: ItemId = next_item_id.into(); - let next_item_id = - next_item_id.checked_add(1).ok_or(Error::::ArithmeticOverflow)?; - NextColorId::::insert(collection_id, next_item_id); - pallet_nfts::Pallet::::do_mint( - collection_id.into(), - item_id.into(), - Some(Self::account_id()), - game_info.player.clone(), - Self::default_item_config(), - |_, _| Ok(()), - )?; - let pallet_origin: OriginFor = - RawOrigin::Signed(Self::account_id()).into(); - pallet_nfts::Pallet::::lock_item_transfer( - pallet_origin, - collection_id.into(), - item_id.into(), - )?; - let mut user = Self::users(game_info.player.clone()) - .ok_or(Error::::UserNotRegistered)?; - let color = Self::collection_color(collection_id) - .ok_or(Error::::CollectionUnknown)?; - user.add_nft_color(color.clone())?; - let points = user.calculate_points(color); - user.points = user - .points - .checked_add(points) - .ok_or(Error::::ArithmeticOverflow)?; - Users::::insert(game_info.player.clone(), user.clone()); - if user.has_four_of_all_colors() { - Self::end_game(game_info.player.clone())?; - } - }, - 11..=30 => { - let mut user = Self::users(game_info.player.clone()) - .ok_or(Error::::UserNotRegistered)?; - user.points = - user.points.checked_add(50).ok_or(Error::::ArithmeticOverflow)?; - Users::::insert(game_info.player.clone(), user); - }, - 31..=50 => { - let mut user = Self::users(game_info.player.clone()) - .ok_or(Error::::UserNotRegistered)?; - user.points = - user.points.checked_add(30).ok_or(Error::::ArithmeticOverflow)?; - Users::::insert(game_info.player.clone(), user); - }, - 51..=100 => { - let mut user = Self::users(game_info.player.clone()) - .ok_or(Error::::UserNotRegistered)?; - user.points = - user.points.checked_add(10).ok_or(Error::::ArithmeticOverflow)?; - Users::::insert(game_info.player.clone(), user); - }, - 101..=150 => { - let mut user = Self::users(game_info.player.clone()) - .ok_or(Error::::UserNotRegistered)?; - user.points = - user.points.checked_sub(10).ok_or(Error::::ArithmeticUnderflow)?; - Users::::insert(game_info.player.clone(), user); - }, - 151..=200 => { - let mut user = Self::users(game_info.player.clone()) - .ok_or(Error::::UserNotRegistered)?; - user.points = - user.points.checked_sub(20).ok_or(Error::::ArithmeticUnderflow)?; - Users::::insert(game_info.player.clone(), user); - }, - 201..=250 => { - let mut user = Self::users(game_info.player.clone()) - .ok_or(Error::::UserNotRegistered)?; - user.points = - user.points.checked_sub(30).ok_or(Error::::ArithmeticUnderflow)?; - Users::::insert(game_info.player.clone(), user); - }, - 251..=300 => { - let mut user = Self::users(game_info.player.clone()) - .ok_or(Error::::UserNotRegistered)?; - user.points = - user.points.checked_sub(40).ok_or(Error::::ArithmeticUnderflow)?; - Users::::insert(game_info.player.clone(), user); - }, - _ => { - let mut user = Self::users(game_info.player.clone()) - .ok_or(Error::::UserNotRegistered)?; - user.points = - user.points.checked_sub(50).ok_or(Error::::ArithmeticUnderflow)?; - Users::::insert(game_info.player.clone(), user); - }, - } - } else if game_info.difficulty == DifficultyLevel::Player { - match difference { - 0..=10 => { - let (hashi, _) = T::GameRandomness::random(&[game_id as u8]); - let u32_value = u32::from_le_bytes( - hashi.as_ref()[4..8] - .try_into() - .map_err(|_| Error::::ConversionError)?, - ); - let random_number = (u32_value % 8) - .checked_add( - 8 * (Self::current_round() - .checked_sub(1) - .ok_or(Error::::ArithmeticUnderflow)?), - ) - .ok_or(Error::::ArithmeticOverflow)?; - let collection_id: ::CollectionId = - random_number.into(); - let next_item_id = Self::next_color_id(collection_id); - let item_id: ItemId = next_item_id.into(); - let next_item_id = - next_item_id.checked_add(1).ok_or(Error::::ArithmeticOverflow)?; - NextColorId::::insert(collection_id, next_item_id); - pallet_nfts::Pallet::::do_mint( - collection_id.into(), - item_id.into(), - Some(Self::account_id()), - game_info.player.clone(), - Self::default_item_config(), - |_, _| Ok(()), - )?; - let pallet_origin: OriginFor = - RawOrigin::Signed(Self::account_id()).into(); - pallet_nfts::Pallet::::lock_item_transfer( - pallet_origin, - collection_id.into(), - item_id.into(), - )?; - let mut user = Self::users(game_info.player.clone()) - .ok_or(Error::::UserNotRegistered)?; - let color = Self::collection_color(collection_id) - .ok_or(Error::::CollectionUnknown)?; - user.add_nft_color(color.clone())?; - let points = user.calculate_points(color); - user.points = user - .points - .checked_add(points) - .ok_or(Error::::ArithmeticOverflow)?; - Users::::insert(game_info.player.clone(), user.clone()); - if user.has_four_of_all_colors() { - Self::end_game(game_info.player.clone())?; - } - }, - 11..=30 => { - let mut user = Self::users(game_info.player.clone()) - .ok_or(Error::::UserNotRegistered)?; - user.points = - user.points.checked_add(25).ok_or(Error::::ArithmeticUnderflow)?; - Users::::insert(game_info.player.clone(), user); - }, - 31..=50 => { - let mut user = Self::users(game_info.player.clone()) - .ok_or(Error::::UserNotRegistered)?; - user.points = - user.points.checked_add(15).ok_or(Error::::ArithmeticUnderflow)?; - Users::::insert(game_info.player.clone(), user); - }, - 51..=100 => { - let mut user = Self::users(game_info.player.clone()) - .ok_or(Error::::UserNotRegistered)?; - user.points = - user.points.checked_add(5).ok_or(Error::::ArithmeticUnderflow)?; - Users::::insert(game_info.player.clone(), user); - }, - 101..=150 => { - let mut user = Self::users(game_info.player.clone()) - .ok_or(Error::::UserNotRegistered)?; - user.points = - user.points.checked_sub(5).ok_or(Error::::ArithmeticUnderflow)?; - Users::::insert(game_info.player.clone(), user); - }, - 151..=200 => { - let mut user = Self::users(game_info.player.clone()) - .ok_or(Error::::UserNotRegistered)?; - user.points = - user.points.checked_sub(10).ok_or(Error::::ArithmeticUnderflow)?; - Users::::insert(game_info.player.clone(), user); - }, - 201..=250 => { - let mut user = Self::users(game_info.player.clone()) - .ok_or(Error::::UserNotRegistered)?; - user.points = - user.points.checked_sub(15).ok_or(Error::::ArithmeticUnderflow)?; - Users::::insert(game_info.player.clone(), user); - }, - 251..=300 => { - let mut user = Self::users(game_info.player.clone()) - .ok_or(Error::::UserNotRegistered)?; - user.points = - user.points.checked_sub(20).ok_or(Error::::ArithmeticUnderflow)?; - Users::::insert(game_info.player.clone(), user); - }, - _ => { - let mut user = Self::users(game_info.player.clone()) - .ok_or(Error::::UserNotRegistered)?; - user.points = - user.points.checked_sub(25).ok_or(Error::::ArithmeticUnderflow)?; - Users::::insert(game_info.player.clone(), user); - }, - } - } else { - let mut user = - Self::users(game_info.player.clone()).ok_or(Error::::UserNotRegistered)?; - user.points = user.points.checked_add(5).ok_or(Error::::ArithmeticUnderflow)?; - user.practise_rounds = - user.practise_rounds.checked_add(1).ok_or(Error::::ArithmeticUnderflow)?; - Users::::insert(game_info.player.clone(), user); + /// checks the answer and distributes the rewards accordingly. + pub fn do_check_result(difference: u16, game_id: u32) -> DispatchResult { + let game_info = GameInfo::::take(game_id).ok_or(Error::::NoActiveGame)?; + ensure!(game_info.guess.is_some(), Error::::NoGuess); + if game_info.difficulty == DifficultyLevel::Pro { + match difference { + 0..=10 => { + let (hashi, _) = T::GameRandomness::random(&[game_id as u8]); + let u32_value = u32::from_le_bytes( + hashi.as_ref()[4..8].try_into().map_err(|_| Error::::ConversionError)?, + ); + let random_number = (u32_value % 8) + .checked_add( + 8 * (Self::current_round() + .checked_sub(1) + .ok_or(Error::::ArithmeticUnderflow)?), + ) + .ok_or(Error::::ArithmeticOverflow)?; + let collection_id: ::CollectionId = random_number.into(); + let next_item_id = Self::next_color_id(collection_id); + let item_id: ItemId = next_item_id.into(); + let next_item_id = + next_item_id.checked_add(1).ok_or(Error::::ArithmeticOverflow)?; + NextColorId::::insert(collection_id, next_item_id); + pallet_nfts::Pallet::::do_mint( + collection_id.into(), + item_id.into(), + Some(Self::account_id()), + game_info.player.clone(), + Self::default_item_config(), + |_, _| Ok(()), + )?; + let pallet_origin: OriginFor = RawOrigin::Signed(Self::account_id()).into(); + pallet_nfts::Pallet::::lock_item_transfer( + pallet_origin, + collection_id.into(), + item_id.into(), + )?; + let mut user = Self::users(game_info.player.clone()) + .ok_or(Error::::UserNotRegistered)?; + let color = Self::collection_color(collection_id) + .ok_or(Error::::CollectionUnknown)?; + user.add_nft_color(color.clone())?; + let points = user.calculate_points(color); + user.points = + user.points.checked_add(points).ok_or(Error::::ArithmeticOverflow)?; + Users::::insert(game_info.player.clone(), user.clone()); + if user.has_four_of_all_colors() { + Self::end_game(game_info.player.clone())?; + } + }, + 11..=30 => { + let mut user = Self::users(game_info.player.clone()) + .ok_or(Error::::UserNotRegistered)?; + user.points = + user.points.checked_add(50).ok_or(Error::::ArithmeticOverflow)?; + Users::::insert(game_info.player.clone(), user); + }, + 31..=50 => { + let mut user = Self::users(game_info.player.clone()) + .ok_or(Error::::UserNotRegistered)?; + user.points = + user.points.checked_add(30).ok_or(Error::::ArithmeticOverflow)?; + Users::::insert(game_info.player.clone(), user); + }, + 51..=100 => { + let mut user = Self::users(game_info.player.clone()) + .ok_or(Error::::UserNotRegistered)?; + user.points = + user.points.checked_add(10).ok_or(Error::::ArithmeticOverflow)?; + Users::::insert(game_info.player.clone(), user); + }, + 101..=150 => { + let mut user = Self::users(game_info.player.clone()) + .ok_or(Error::::UserNotRegistered)?; + user.points = + user.points.checked_sub(10).ok_or(Error::::ArithmeticUnderflow)?; + Users::::insert(game_info.player.clone(), user); + }, + 151..=200 => { + let mut user = Self::users(game_info.player.clone()) + .ok_or(Error::::UserNotRegistered)?; + user.points = + user.points.checked_sub(20).ok_or(Error::::ArithmeticUnderflow)?; + Users::::insert(game_info.player.clone(), user); + }, + 201..=250 => { + let mut user = Self::users(game_info.player.clone()) + .ok_or(Error::::UserNotRegistered)?; + user.points = + user.points.checked_sub(30).ok_or(Error::::ArithmeticUnderflow)?; + Users::::insert(game_info.player.clone(), user); + }, + 251..=300 => { + let mut user = Self::users(game_info.player.clone()) + .ok_or(Error::::UserNotRegistered)?; + user.points = + user.points.checked_sub(40).ok_or(Error::::ArithmeticUnderflow)?; + Users::::insert(game_info.player.clone(), user); + }, + _ => { + let mut user = Self::users(game_info.player.clone()) + .ok_or(Error::::UserNotRegistered)?; + user.points = + user.points.checked_sub(50).ok_or(Error::::ArithmeticUnderflow)?; + Users::::insert(game_info.player.clone(), user); + }, } - let user = + } else if game_info.difficulty == DifficultyLevel::Player { + match difference { + 0..=10 => { + let (hashi, _) = T::GameRandomness::random(&[game_id as u8]); + let u32_value = u32::from_le_bytes( + hashi.as_ref()[4..8].try_into().map_err(|_| Error::::ConversionError)?, + ); + let random_number = (u32_value % 8) + .checked_add( + 8 * (Self::current_round() + .checked_sub(1) + .ok_or(Error::::ArithmeticUnderflow)?), + ) + .ok_or(Error::::ArithmeticOverflow)?; + let collection_id: ::CollectionId = random_number.into(); + let next_item_id = Self::next_color_id(collection_id); + let item_id: ItemId = next_item_id.into(); + let next_item_id = + next_item_id.checked_add(1).ok_or(Error::::ArithmeticOverflow)?; + NextColorId::::insert(collection_id, next_item_id); + pallet_nfts::Pallet::::do_mint( + collection_id.into(), + item_id.into(), + Some(Self::account_id()), + game_info.player.clone(), + Self::default_item_config(), + |_, _| Ok(()), + )?; + let pallet_origin: OriginFor = RawOrigin::Signed(Self::account_id()).into(); + pallet_nfts::Pallet::::lock_item_transfer( + pallet_origin, + collection_id.into(), + item_id.into(), + )?; + let mut user = Self::users(game_info.player.clone()) + .ok_or(Error::::UserNotRegistered)?; + let color = Self::collection_color(collection_id) + .ok_or(Error::::CollectionUnknown)?; + user.add_nft_color(color.clone())?; + let points = user.calculate_points(color); + user.points = + user.points.checked_add(points).ok_or(Error::::ArithmeticOverflow)?; + Users::::insert(game_info.player.clone(), user.clone()); + if user.has_four_of_all_colors() { + Self::end_game(game_info.player.clone())?; + } + }, + 11..=30 => { + let mut user = Self::users(game_info.player.clone()) + .ok_or(Error::::UserNotRegistered)?; + user.points = + user.points.checked_add(25).ok_or(Error::::ArithmeticUnderflow)?; + Users::::insert(game_info.player.clone(), user); + }, + 31..=50 => { + let mut user = Self::users(game_info.player.clone()) + .ok_or(Error::::UserNotRegistered)?; + user.points = + user.points.checked_add(15).ok_or(Error::::ArithmeticUnderflow)?; + Users::::insert(game_info.player.clone(), user); + }, + 51..=100 => { + let mut user = Self::users(game_info.player.clone()) + .ok_or(Error::::UserNotRegistered)?; + user.points = + user.points.checked_add(5).ok_or(Error::::ArithmeticUnderflow)?; + Users::::insert(game_info.player.clone(), user); + }, + 101..=150 => { + let mut user = Self::users(game_info.player.clone()) + .ok_or(Error::::UserNotRegistered)?; + user.points = + user.points.checked_sub(5).ok_or(Error::::ArithmeticUnderflow)?; + Users::::insert(game_info.player.clone(), user); + }, + 151..=200 => { + let mut user = Self::users(game_info.player.clone()) + .ok_or(Error::::UserNotRegistered)?; + user.points = + user.points.checked_sub(10).ok_or(Error::::ArithmeticUnderflow)?; + Users::::insert(game_info.player.clone(), user); + }, + 201..=250 => { + let mut user = Self::users(game_info.player.clone()) + .ok_or(Error::::UserNotRegistered)?; + user.points = + user.points.checked_sub(15).ok_or(Error::::ArithmeticUnderflow)?; + Users::::insert(game_info.player.clone(), user); + }, + 251..=300 => { + let mut user = Self::users(game_info.player.clone()) + .ok_or(Error::::UserNotRegistered)?; + user.points = + user.points.checked_sub(20).ok_or(Error::::ArithmeticUnderflow)?; + Users::::insert(game_info.player.clone(), user); + }, + _ => { + let mut user = Self::users(game_info.player.clone()) + .ok_or(Error::::UserNotRegistered)?; + user.points = + user.points.checked_sub(25).ok_or(Error::::ArithmeticUnderflow)?; + Users::::insert(game_info.player.clone(), user); + }, + } + } else { + let mut user = Self::users(game_info.player.clone()).ok_or(Error::::UserNotRegistered)?; - Self::update_leaderboard(game_info.player, user.points)?; - Ok(()) + user.points = user.points.checked_add(5).ok_or(Error::::ArithmeticUnderflow)?; + user.practise_rounds = + user.practise_rounds.checked_add(1).ok_or(Error::::ArithmeticUnderflow)?; + Users::::insert(game_info.player.clone(), user); } + let user = Self::users(game_info.player.clone()).ok_or(Error::::UserNotRegistered)?; + Self::update_leaderboard(game_info.player, user.points)?; + Ok(()) + } - pub fn update_leaderboard(user_id: AccountIdOf, new_points: u32) -> DispatchResult { - let mut leaderboard = Self::leaderboard(); - let leaderboard_size = leaderboard.len(); + pub fn update_leaderboard(user_id: AccountIdOf, new_points: u32) -> DispatchResult { + let mut leaderboard = Self::leaderboard(); + let leaderboard_size = leaderboard.len(); - if let Some((_, user_points)) = leaderboard.iter_mut().find(|(id, _)| *id == user_id) { - *user_points = new_points; - leaderboard.sort_by(|a, b| b.1.cmp(&a.1)); - Leaderboard::::put(leaderboard); - return Ok(()); - } - if new_points > 0 && - (leaderboard_size < 10 || - new_points > leaderboard.last().map(|(_, points)| *points).unwrap_or(0)) - { - if leaderboard.len() >= 10 { - leaderboard.pop(); - } - leaderboard - .try_push((user_id, new_points)) - .map_err(|_| Error::::InvalidIndex)?; - leaderboard.sort_by(|a, b| b.1.cmp(&a.1)); - Leaderboard::::put(leaderboard); - } - Ok(()) + if let Some((_, user_points)) = leaderboard.iter_mut().find(|(id, _)| *id == user_id) { + *user_points = new_points; + leaderboard.sort_by(|a, b| b.1.cmp(&a.1)); + Leaderboard::::put(leaderboard); + return Ok(()); } - - pub fn swap_user_points( - nft_holder: AccountIdOf, - collection_id_add: CollectionId, - collection_id_sub: CollectionId, - ) -> DispatchResult { - let mut user = Self::users(nft_holder.clone()).ok_or(Error::::UserNotRegistered)?; - let color_add = - Self::collection_color(collection_id_add).ok_or(Error::::CollectionUnknown)?; - let color_sub = - Self::collection_color(collection_id_sub).ok_or(Error::::CollectionUnknown)?; - user.add_nft_color(color_add.clone())?; - let points = user.calculate_points(color_add); - user.points = user.points.checked_add(points).ok_or(Error::::ArithmeticOverflow)?; - user.sub_nft_color(color_sub.clone())?; - let points = user.subtracting_calculate_points(color_sub); - user.points = user.points.checked_sub(points).ok_or(Error::::ArithmeticOverflow)?; - Users::::insert(nft_holder.clone(), user.clone()); - Self::update_leaderboard(nft_holder.clone(), user.points)?; - if user.has_four_of_all_colors() { - Self::end_game(nft_holder)?; + if new_points > 0 && + (leaderboard_size < 10 || + new_points > leaderboard.last().map(|(_, points)| *points).unwrap_or(0)) + { + if leaderboard.len() >= 10 { + leaderboard.pop(); } - Ok(()) + leaderboard + .try_push((user_id, new_points)) + .map_err(|_| Error::::InvalidIndex)?; + leaderboard.sort_by(|a, b| b.1.cmp(&a.1)); + Leaderboard::::put(leaderboard); } + Ok(()) + } - /// Handles the case if the player did not answer on time. - pub fn no_answer_result(game_info: GameData) -> DispatchResult { - if game_info.difficulty == DifficultyLevel::Pro { - let mut user = - Self::users(game_info.player.clone()).ok_or(Error::::UserNotRegistered)?; - user.points = user.points.checked_sub(50).ok_or(Error::::ArithmeticUnderflow)?; - Users::::insert(game_info.player.clone(), user); - } else if game_info.difficulty == DifficultyLevel::Player { - let mut user = - Self::users(game_info.player.clone()).ok_or(Error::::UserNotRegistered)?; - user.points = user.points.checked_sub(25).ok_or(Error::::ArithmeticUnderflow)?; - Users::::insert(game_info.player.clone(), user); - } - Ok(()) + pub fn swap_user_points( + nft_holder: AccountIdOf, + collection_id_add: CollectionId, + collection_id_sub: CollectionId, + ) -> DispatchResult { + let mut user = Self::users(nft_holder.clone()).ok_or(Error::::UserNotRegistered)?; + let color_add = + Self::collection_color(collection_id_add).ok_or(Error::::CollectionUnknown)?; + let color_sub = + Self::collection_color(collection_id_sub).ok_or(Error::::CollectionUnknown)?; + user.add_nft_color(color_add.clone())?; + let points = user.calculate_points(color_add); + user.points = user.points.checked_add(points).ok_or(Error::::ArithmeticOverflow)?; + user.sub_nft_color(color_sub.clone())?; + let points = user.subtracting_calculate_points(color_sub); + user.points = user.points.checked_sub(points).ok_or(Error::::ArithmeticOverflow)?; + Users::::insert(nft_holder.clone(), user.clone()); + Self::update_leaderboard(nft_holder.clone(), user.points)?; + if user.has_four_of_all_colors() { + Self::end_game(nft_holder)?; } + Ok(()) + } - pub fn end_game(winner: AccountIdOf) -> DispatchResult { - RoundActive::::put(false); - RoundChampion::::insert(Self::current_round(), winner); - Ok(()) + /// Handles the case if the player did not answer on time. + pub fn no_answer_result(game_info: GameData) -> DispatchResult { + if game_info.difficulty == DifficultyLevel::Pro { + let mut user = + Self::users(game_info.player.clone()).ok_or(Error::::UserNotRegistered)?; + user.points = user.points.checked_sub(50).ok_or(Error::::ArithmeticUnderflow)?; + Users::::insert(game_info.player.clone(), user); + } else if game_info.difficulty == DifficultyLevel::Player { + let mut user = + Self::users(game_info.player.clone()).ok_or(Error::::UserNotRegistered)?; + user.points = user.points.checked_sub(25).ok_or(Error::::ArithmeticUnderflow)?; + Users::::insert(game_info.player.clone(), user); } + Ok(()) + } - /// Set the default collection configuration for creating a collection. - pub fn default_collection_config() -> CollectionConfig< - BalanceOf, - BlockNumberFor, - ::CollectionId, - > { - Self::collection_config_from_disabled_settings( - CollectionSetting::DepositRequired.into(), - ) - } + pub fn end_game(winner: AccountIdOf) -> DispatchResult { + RoundActive::::put(false); + RoundChampion::::insert(Self::current_round(), winner); + Ok(()) + } - pub fn collection_config_from_disabled_settings( - settings: BitFlags, - ) -> CollectionConfig< - BalanceOf, - BlockNumberFor, - ::CollectionId, - > { - CollectionConfig { - settings: CollectionSettings::from_disabled(settings), - max_supply: None, - mint_settings: MintSettings::default(), - } - } + /// Set the default collection configuration for creating a collection. + pub fn default_collection_config( + ) -> CollectionConfig, BlockNumberFor, ::CollectionId> + { + Self::collection_config_from_disabled_settings(CollectionSetting::DepositRequired.into()) + } - /// Set the default item configuration for minting a nft. - pub fn default_item_config() -> ItemConfig { - ItemConfig { settings: ItemSettings::all_enabled() } + pub fn collection_config_from_disabled_settings( + settings: BitFlags, + ) -> CollectionConfig, BlockNumberFor, ::CollectionId> + { + CollectionConfig { + settings: CollectionSettings::from_disabled(settings), + max_supply: None, + mint_settings: MintSettings::default(), } - } \ No newline at end of file + } + + /// Set the default item configuration for minting a nft. + pub fn default_item_config() -> ItemConfig { + ItemConfig { settings: ItemSettings::all_enabled() } + } +} diff --git a/pallets/game/src/lib.rs b/pallets/game/src/lib.rs index 88d559e..10ba833 100644 --- a/pallets/game/src/lib.rs +++ b/pallets/game/src/lib.rs @@ -15,8 +15,8 @@ mod tests; mod benchmarking; pub mod weights; pub use weights::*; -pub mod properties; pub mod functions; +pub mod properties; pub mod types; type AccountIdOf = ::AccountId; @@ -57,9 +57,7 @@ pub mod pallet { /// Configure the pallet by specifying the parameters and types on which it depends. #[pallet::config] - pub trait Config: - frame_system::Config + pallet_nfts::Config - //+ pallet_babe::Config + pub trait Config: frame_system::Config + pallet_nfts::Config //+ pallet_babe::Config { /// Because this pallet emits events, it depends on the runtime's definition of an event. type RuntimeEvent: From> + IsType<::RuntimeEvent>; @@ -214,7 +212,8 @@ pub mod pallet { /// Vector of admins who can register users. #[pallet::storage] #[pallet::getter(fn admins)] - pub type Admins = StorageValue<_, BoundedVec, T::MaxAdmins>, ValueQuery>; + pub type Admins = + StorageValue<_, BoundedVec, T::MaxAdmins>, ValueQuery>; #[pallet::event] #[pallet::generate_deposit(pub(super) fn deposit_event)] @@ -313,7 +312,9 @@ pub mod pallet { weight = weight.saturating_add(T::DbWeight::get().reads_writes(1, 1)); let game_info = >::take(index); if let Some(game_info) = game_info { - let _ = Self::no_answer_result(game_info); + if game_info.guess.is_none() { + let _ = Self::no_answer_result(game_info); + } } }); weight @@ -379,7 +380,8 @@ pub mod pallet { ensure!(Self::admins().contains(&signer), Error::::NoPermission); ensure!(Self::users(player.clone()).is_none(), Error::::PlayerAlreadyRegistered); let current_block_number = >::block_number(); - let next_request = current_block_number.saturating_add(::RequestLimit::get()); + let next_request = + current_block_number.saturating_add(::RequestLimit::get()); let user = User { points: 50, wins: Default::default(), @@ -389,8 +391,12 @@ pub mod pallet { next_token_request: next_request, nfts: CollectedColors::default(), }; - ::Currency::make_free_balance_be(&player, 10u32.try_into().map_err(|_| Error::::ConversionError)?); + ::Currency::make_free_balance_be( + &player, + 10u32.try_into().map_err(|_| Error::::ConversionError)?, + ); Users::::insert(player.clone(), user); + frame_system::Pallet::::inc_providers(&player); Self::deposit_event(Event::::NewPlayerRegistered { player }); Ok(()) } @@ -424,6 +430,30 @@ pub mod pallet { /// Emits `GameStarted` event when succesfful. #[pallet::call_index(3)] #[pallet::weight(::WeightInfo::play_game())] + #[pallet::feeless_if(|origin: &OriginFor, game_type: &DifficultyLevel| -> bool { + if let Ok(signer) = ensure_signed(origin.clone()) { + match game_type { + DifficultyLevel::Pro => { + if let Some(user) = Users::::get(&signer) { + if user.points >= 50 { + return true; + } + } + }, + DifficultyLevel::Player => { + if let Some(user) = Users::::get(&signer) { + if user.points >= 25 { + return true; + } + } + }, + DifficultyLevel::Practice => { + return true; + } + } + } + false + })] pub fn play_game(origin: OriginFor, game_type: DifficultyLevel) -> DispatchResult { let signer = ensure_signed(origin)?; Self::check_enough_points(signer.clone(), game_type.clone())?; @@ -431,7 +461,8 @@ pub mod pallet { let mut user = Self::users(signer.clone()).ok_or(Error::::UserNotRegistered)?; if Self::current_round() != user.last_played_round { user.nfts = Default::default(); - user.last_played_round = user.last_played_round.checked_add(1).ok_or(Error::::ArithmeticOverflow)?; + user.last_played_round = + user.last_played_round.checked_add(1).ok_or(Error::::ArithmeticOverflow)?; Users::::insert(signer.clone(), user); } let game_id = Self::game_id(); @@ -464,11 +495,10 @@ pub mod pallet { let u32_value = u32::from_le_bytes( hashi.as_ref()[4..8].try_into().map_err(|_| Error::::ConversionError)?, ); - let random_number = u32_value as usize % - Self::test_properties() - .len(); + let random_number = u32_value as usize % Self::test_properties().len(); let property = Self::test_properties()[random_number].clone(); - let game_datas = GameData { difficulty: game_type, player: signer.clone(), property, guess: None }; + let game_datas = + GameData { difficulty: game_type, player: signer.clone(), property, guess: None }; let mut properties = TestProperties::::take(); properties.retain(|property| property.id as usize != random_number); TestProperties::::put(properties); @@ -490,6 +520,16 @@ pub mod pallet { /// Emits `AnswerSubmitted` event when succesfful. #[pallet::call_index(4)] #[pallet::weight(::WeightInfo::submit_answer())] + #[pallet::feeless_if(|origin: &OriginFor, guess: &u32, game_id: &u32| -> bool { + if let Ok(signer) = ensure_signed(origin.clone()) { + if let Some(game_info) = GameInfo::::get(*game_id) { + if signer == game_info.player { + return true; + } + } + } + false + })] pub fn submit_answer(origin: OriginFor, guess: u32, game_id: u32) -> DispatchResult { let signer = ensure_signed(origin)?; let mut game_info = Self::game_info(game_id).ok_or(Error::::NoActiveGame)?; @@ -513,17 +553,26 @@ pub mod pallet { /// Emits `ResultChecked` event when succesfful. #[pallet::call_index(15)] #[pallet::weight(::WeightInfo::submit_answer())] - pub fn check_result(origin: OriginFor, guess: u32, game_id: u32, price: u32, secret: BoundedVec::StringLimit>) -> DispatchResult { + pub fn check_result( + origin: OriginFor, + guess: u32, + game_id: u32, + price: u32, + secret: BoundedVec::StringLimit>, + ) -> DispatchResult { T::GameOrigin::ensure_origin(origin)?; let difference_value = ((price as i32) .checked_sub(guess as i32) .ok_or(Error::::ArithmeticUnderflow)?) - .checked_mul(1000) - .ok_or(Error::::MultiplyError)? - .checked_div(price as i32) - .ok_or(Error::::DivisionError)? - .abs(); - Self::do_check_result(difference_value.try_into().map_err(|_| Error::::ConversionError)?, game_id)?; + .checked_mul(1000) + .ok_or(Error::::MultiplyError)? + .checked_div(price as i32) + .ok_or(Error::::DivisionError)? + .abs(); + Self::do_check_result( + difference_value.try_into().map_err(|_| Error::::ConversionError)?, + game_id, + )?; Self::deposit_event(Event::::ResultChecked { game_id }); Ok(()) } @@ -768,7 +817,8 @@ pub mod pallet { #[pallet::weight(::WeightInfo::add_property())] pub fn add_property(origin: OriginFor, property: PropertyInfoData) -> DispatchResult { T::GameOrigin::ensure_origin(origin)?; - TestProperties::::try_append(property.clone()).map_err(|_| Error::::TooManyTest)?; + TestProperties::::try_append(property.clone()) + .map_err(|_| Error::::TooManyTest)?; Ok(()) } @@ -800,12 +850,8 @@ pub mod pallet { #[pallet::weight(::WeightInfo::add_to_admins())] pub fn add_to_admins(origin: OriginFor, new_admin: AccountIdOf) -> DispatchResult { T::GameOrigin::ensure_origin(origin)?; - ensure!( - !Self::admins().contains(&new_admin), - Error::::AccountAlreadyAdmin, - ); - Admins::::try_append(new_admin.clone()) - .map_err(|_| Error::::TooManyAdmins)?; + ensure!(!Self::admins().contains(&new_admin), Error::::AccountAlreadyAdmin,); + Admins::::try_append(new_admin.clone()).map_err(|_| Error::::TooManyAdmins)?; Self::deposit_event(Event::::NewAdminAdded { new_admin }); Ok(()) } @@ -843,9 +889,13 @@ pub mod pallet { let current_block_number = >::block_number(); let mut user = Self::users(signer.clone()).ok_or(Error::::UserNotRegistered)?; ensure!(user.next_token_request < current_block_number, Error::::CantRequestToken); - let next_request = current_block_number.saturating_add(::RequestLimit::get()); + let next_request = + current_block_number.saturating_add(::RequestLimit::get()); user.next_token_request = next_request; - ::Currency::make_free_balance_be(&signer, 10u32.try_into().map_err(|_| Error::::ConversionError)?); + ::Currency::make_free_balance_be( + &signer, + 10u32.try_into().map_err(|_| Error::::ConversionError)?, + ); Users::::insert(signer.clone(), user); Self::deposit_event(Event::::TokenReceived { player: signer }); Ok(()) diff --git a/pallets/game/src/mock.rs b/pallets/game/src/mock.rs index 0be5d63..265fe33 100644 --- a/pallets/game/src/mock.rs +++ b/pallets/game/src/mock.rs @@ -158,9 +158,7 @@ pub fn new_test_ext() -> sp_io::TestExternalities { let mut test = frame_system::GenesisConfig::::default().build_storage().unwrap(); pallet_balances::GenesisConfig:: { - balances: vec![ - (GameModule::account_id(), 1_000_000), - ], + balances: vec![(GameModule::account_id(), 1_000_000)], } .assimilate_storage(&mut test) .unwrap(); diff --git a/pallets/game/src/properties.rs b/pallets/game/src/properties.rs index dbf3376..35c2df5 100644 --- a/pallets/game/src/properties.rs +++ b/pallets/game/src/properties.rs @@ -2,31 +2,35 @@ use crate::*; use frame_support::pallet_prelude::*; impl Pallet { - pub(crate) fn create_test_properties() -> DispatchResult { + pub(crate) fn create_test_properties() -> DispatchResult { let new_property = PropertyInfoData { id: 147229391, data: "nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap(), price: "kkjfkdjdkdjdkdjdk".as_bytes().to_vec().try_into().unwrap(), - }; - TestProperties::::try_append(new_property.clone()).map_err(|_| Error::::TooManyTest)?; + }; + TestProperties::::try_append(new_property.clone()) + .map_err(|_| Error::::TooManyTest)?; let new_property = PropertyInfoData { id: 146480642, data: "nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap(), price: "kkjfkdjdkdjdkdjdk".as_bytes().to_vec().try_into().unwrap(), - }; - TestProperties::::try_append(new_property.clone()).map_err(|_| Error::::TooManyTest)?; + }; + TestProperties::::try_append(new_property.clone()) + .map_err(|_| Error::::TooManyTest)?; let new_property = PropertyInfoData { id: 147031382, data: "nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap(), price: "kkjfkdjdkdjdkdjdk".as_bytes().to_vec().try_into().unwrap(), - }; - TestProperties::::try_append(new_property.clone()).map_err(|_| Error::::TooManyTest)?; + }; + TestProperties::::try_append(new_property.clone()) + .map_err(|_| Error::::TooManyTest)?; let new_property = PropertyInfoData { id: 147031382, data: "nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap(), price: "kkjfkdjdkdjdkdjdk".as_bytes().to_vec().try_into().unwrap(), - }; - TestProperties::::try_append(new_property.clone()).map_err(|_| Error::::TooManyTest)?; + }; + TestProperties::::try_append(new_property.clone()) + .map_err(|_| Error::::TooManyTest)?; Ok(()) - } + } } diff --git a/pallets/game/src/tests.rs b/pallets/game/src/tests.rs index 3e2c9c3..6150676 100644 --- a/pallets/game/src/tests.rs +++ b/pallets/game/src/tests.rs @@ -1,7 +1,6 @@ -use crate::{mock::*, Error, Event}; +use crate::{mock::*, Error, Event, PropertyInfoData}; use frame_support::{assert_noop, assert_ok}; use sp_runtime::{traits::BadOrigin, DispatchError, ModuleError}; -use crate::PropertyInfoData; fn practise_round(player: AccountId, game_id: u32) { assert_ok!(GameModule::play_game( @@ -9,8 +8,14 @@ fn practise_round(player: AccountId, game_id: u32) { crate::DifficultyLevel::Practice, )); assert_ok!(GameModule::submit_answer(RuntimeOrigin::signed(player.clone()), 220000, game_id)); - System::assert_last_event(Event::AnswerSubmitted { player: player, game_id: game_id, guess: 220_000 }.into()); - assert_ok!(GameModule::check_result(RuntimeOrigin::root(), 220_000, game_id, 220_000,"nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap())); + System::assert_last_event(Event::AnswerSubmitted { player, game_id, guess: 220_000 }.into()); + assert_ok!(GameModule::check_result( + RuntimeOrigin::root(), + 220_000, + game_id, + 220_000, + "nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap() + )); } #[test] @@ -42,10 +47,16 @@ fn add_to_admins_works() { fn add_to_admins_fails() { new_test_ext().execute_with(|| { System::set_block_number(1); - assert_noop!(GameModule::add_to_admins(RuntimeOrigin::signed([0; 32].into()), [0; 32].into()), BadOrigin); + assert_noop!( + GameModule::add_to_admins(RuntimeOrigin::signed([0; 32].into()), [0; 32].into()), + BadOrigin + ); assert_ok!(GameModule::add_to_admins(RuntimeOrigin::root(), [0; 32].into())); assert_eq!(GameModule::admins().len(), 1); - assert_noop!(GameModule::add_to_admins(RuntimeOrigin::root(), [0; 32].into()), Error::::AccountAlreadyAdmin); + assert_noop!( + GameModule::add_to_admins(RuntimeOrigin::root(), [0; 32].into()), + Error::::AccountAlreadyAdmin + ); }); } @@ -64,10 +75,16 @@ fn remove_admins_works() { fn remove_admins_fails() { new_test_ext().execute_with(|| { System::set_block_number(1); - assert_noop!(GameModule::remove_from_admins(RuntimeOrigin::root(), [0; 32].into()), Error::::NotAdmin); + assert_noop!( + GameModule::remove_from_admins(RuntimeOrigin::root(), [0; 32].into()), + Error::::NotAdmin + ); assert_ok!(GameModule::add_to_admins(RuntimeOrigin::root(), [0; 32].into())); assert_eq!(GameModule::admins().len(), 1); - assert_noop!(GameModule::remove_from_admins(RuntimeOrigin::signed([0; 32].into()), [0; 32].into()), BadOrigin); + assert_noop!( + GameModule::remove_from_admins(RuntimeOrigin::signed([0; 32].into()), [0; 32].into()), + BadOrigin + ); }); } @@ -78,7 +95,10 @@ fn play_game_works() { assert_ok!(GameModule::setup_game(RuntimeOrigin::root())); assert_eq!(GameModule::test_properties().len(), 4); assert_ok!(GameModule::add_to_admins(RuntimeOrigin::root(), [4; 32].into())); - assert_ok!(GameModule::register_user(RuntimeOrigin::signed([4; 32].into()), [0; 32].into())); + assert_ok!(GameModule::register_user( + RuntimeOrigin::signed([4; 32].into()), + [0; 32].into() + )); assert_eq!(Balances::free_balance(&([0; 32].into())), 10); assert_ok!(GameModule::give_points(RuntimeOrigin::root(), [0; 32].into())); practise_round([0; 32].into(), 0); @@ -111,7 +131,10 @@ fn play_game_fails_no_active_round() { new_test_ext().execute_with(|| { System::set_block_number(1); assert_ok!(GameModule::add_to_admins(RuntimeOrigin::root(), [4; 32].into())); - assert_ok!(GameModule::register_user(RuntimeOrigin::signed([4; 32].into()), [0; 32].into())); + assert_ok!(GameModule::register_user( + RuntimeOrigin::signed([4; 32].into()), + [0; 32].into() + )); assert_noop!( GameModule::play_game( RuntimeOrigin::signed([0; 32].into()), @@ -129,7 +152,10 @@ fn play_game_fails_not_enough_points() { assert_ok!(GameModule::setup_game(RuntimeOrigin::root())); assert_eq!(GameModule::test_properties().len(), 4); assert_ok!(GameModule::add_to_admins(RuntimeOrigin::root(), [4; 32].into())); - assert_ok!(GameModule::register_user(RuntimeOrigin::signed([4; 32].into()), [0; 32].into())); + assert_ok!(GameModule::register_user( + RuntimeOrigin::signed([4; 32].into()), + [0; 32].into() + )); practise_round([0; 32].into(), 0); assert_ok!(GameModule::play_game( RuntimeOrigin::signed([0; 32].into()), @@ -150,15 +176,26 @@ fn submit_answer_works() { assert_ok!(GameModule::setup_game(RuntimeOrigin::root())); assert_eq!(GameModule::test_properties().len(), 4); assert_ok!(GameModule::add_to_admins(RuntimeOrigin::root(), [4; 32].into())); - assert_ok!(GameModule::register_user(RuntimeOrigin::signed([4; 32].into()), [0; 32].into())); + assert_ok!(GameModule::register_user( + RuntimeOrigin::signed([4; 32].into()), + [0; 32].into() + )); practise_round([0; 32].into(), 0); assert_ok!(GameModule::play_game( RuntimeOrigin::signed([0; 32].into()), crate::DifficultyLevel::Player, )); assert_ok!(GameModule::submit_answer(RuntimeOrigin::signed([0; 32].into()), 223_000, 1)); - System::assert_last_event(Event::AnswerSubmitted { player: [0; 32].into(), game_id: 1, guess: 223_000 }.into()); - assert_ok!(GameModule::check_result(RuntimeOrigin::root(), 223_000, 1, 220_000,"nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap())); + System::assert_last_event( + Event::AnswerSubmitted { player: [0; 32].into(), game_id: 1, guess: 223_000 }.into(), + ); + assert_ok!(GameModule::check_result( + RuntimeOrigin::root(), + 223_000, + 1, + 220_000, + "nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap() + )); assert_eq!(GameModule::game_info(0).is_none(), true); assert_eq!(GameModule::users::([0; 32].into()).unwrap().points, 80); assert_ok!(GameModule::play_game( @@ -166,8 +203,16 @@ fn submit_answer_works() { crate::DifficultyLevel::Player, )); assert_ok!(GameModule::submit_answer(RuntimeOrigin::signed([0; 32].into()), 220_000, 2)); - System::assert_last_event(Event::AnswerSubmitted { player: [0; 32].into(), game_id: 2, guess: 220_000 }.into()); - assert_ok!(GameModule::check_result(RuntimeOrigin::root(), 220_000, 2, 220_000,"nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap())); + System::assert_last_event( + Event::AnswerSubmitted { player: [0; 32].into(), game_id: 2, guess: 220_000 }.into(), + ); + assert_ok!(GameModule::check_result( + RuntimeOrigin::root(), + 220_000, + 2, + 220_000, + "nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap() + )); assert_eq!(GameModule::game_info(1).is_none(), true); assert_eq!(GameModule::users::([0; 32].into()).unwrap().points, 180); assert_eq!(Nfts::owner(0, 0).unwrap(), [0; 32].into()); @@ -182,9 +227,18 @@ fn leaderboard_works() { assert_ok!(GameModule::setup_game(RuntimeOrigin::root())); assert_eq!(GameModule::test_properties().len(), 4); assert_ok!(GameModule::add_to_admins(RuntimeOrigin::root(), [4; 32].into())); - assert_ok!(GameModule::register_user(RuntimeOrigin::signed([4; 32].into()), [0; 32].into())); - assert_ok!(GameModule::register_user(RuntimeOrigin::signed([4; 32].into()), [1; 32].into())); - assert_ok!(GameModule::register_user(RuntimeOrigin::signed([4; 32].into()), [2; 32].into())); + assert_ok!(GameModule::register_user( + RuntimeOrigin::signed([4; 32].into()), + [0; 32].into() + )); + assert_ok!(GameModule::register_user( + RuntimeOrigin::signed([4; 32].into()), + [1; 32].into() + )); + assert_ok!(GameModule::register_user( + RuntimeOrigin::signed([4; 32].into()), + [2; 32].into() + )); practise_round([0; 32].into(), 0); practise_round([1; 32].into(), 1); practise_round([2; 32].into(), 2); @@ -193,22 +247,46 @@ fn leaderboard_works() { crate::DifficultyLevel::Player, )); assert_ok!(GameModule::submit_answer(RuntimeOrigin::signed([0; 32].into()), 230_000, 3)); - System::assert_last_event(Event::AnswerSubmitted { player: [0; 32].into(), game_id: 3, guess: 230_000 }.into()); - assert_ok!(GameModule::check_result(RuntimeOrigin::root(), 230_000, 3, 220_000,"nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap())); + System::assert_last_event( + Event::AnswerSubmitted { player: [0; 32].into(), game_id: 3, guess: 230_000 }.into(), + ); + assert_ok!(GameModule::check_result( + RuntimeOrigin::root(), + 230_000, + 3, + 220_000, + "nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap() + )); assert_ok!(GameModule::play_game( RuntimeOrigin::signed([1; 32].into()), crate::DifficultyLevel::Player, )); assert_ok!(GameModule::submit_answer(RuntimeOrigin::signed([1; 32].into()), 225_000, 4)); - System::assert_last_event(Event::AnswerSubmitted { player: [1; 32].into(), game_id: 4, guess: 225_000 }.into()); - assert_ok!(GameModule::check_result(RuntimeOrigin::root(), 225_000, 4, 220_000,"nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap())); + System::assert_last_event( + Event::AnswerSubmitted { player: [1; 32].into(), game_id: 4, guess: 225_000 }.into(), + ); + assert_ok!(GameModule::check_result( + RuntimeOrigin::root(), + 225_000, + 4, + 220_000, + "nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap() + )); assert_ok!(GameModule::play_game( RuntimeOrigin::signed([2; 32].into()), crate::DifficultyLevel::Player, )); assert_ok!(GameModule::submit_answer(RuntimeOrigin::signed([2; 32].into()), 220_000, 5)); - System::assert_last_event(Event::AnswerSubmitted { player: [2; 32].into(), game_id: 5, guess: 220_000 }.into()); - assert_ok!(GameModule::check_result(RuntimeOrigin::root(), 220_000, 5, 220_000,"nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap())); + System::assert_last_event( + Event::AnswerSubmitted { player: [2; 32].into(), game_id: 5, guess: 220_000 }.into(), + ); + assert_ok!(GameModule::check_result( + RuntimeOrigin::root(), + 220_000, + 5, + 220_000, + "nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap() + )); assert_eq!(GameModule::game_info(0).is_none(), true); assert_eq!(GameModule::users::([2; 32].into()).unwrap().points, 155); assert_eq!(GameModule::users::([1; 32].into()).unwrap().points, 80); @@ -240,7 +318,10 @@ fn transfer_of_nft_does_not_work() { assert_ok!(GameModule::setup_game(RuntimeOrigin::root())); assert_eq!(GameModule::test_properties().len(), 4); assert_ok!(GameModule::add_to_admins(RuntimeOrigin::root(), [4; 32].into())); - assert_ok!(GameModule::register_user(RuntimeOrigin::signed([4; 32].into()), [0; 32].into())); + assert_ok!(GameModule::register_user( + RuntimeOrigin::signed([4; 32].into()), + [0; 32].into() + )); assert_ok!(GameModule::give_points(RuntimeOrigin::root(), [0; 32].into())); practise_round([0; 32].into(), 0); assert_ok!(GameModule::play_game( @@ -248,8 +329,16 @@ fn transfer_of_nft_does_not_work() { crate::DifficultyLevel::Player, )); assert_ok!(GameModule::submit_answer(RuntimeOrigin::signed([0; 32].into()), 220_000, 1)); - System::assert_last_event(Event::AnswerSubmitted { player: [0; 32].into(), game_id: 1, guess: 220_000 }.into()); - assert_ok!(GameModule::check_result(RuntimeOrigin::root(), 220_000, 1, 220_000,"nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap())); + System::assert_last_event( + Event::AnswerSubmitted { player: [0; 32].into(), game_id: 1, guess: 220_000 }.into(), + ); + assert_ok!(GameModule::check_result( + RuntimeOrigin::root(), + 220_000, + 1, + 220_000, + "nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap() + )); assert_eq!(GameModule::game_info(1).is_none(), true); assert_eq!(Nfts::owner(0, 0).unwrap(), [0; 32].into()); assert_noop!( @@ -275,15 +364,26 @@ fn list_nft_works() { assert_ok!(GameModule::setup_game(RuntimeOrigin::root())); assert_eq!(GameModule::test_properties().len(), 4); assert_ok!(GameModule::add_to_admins(RuntimeOrigin::root(), [4; 32].into())); - assert_ok!(GameModule::register_user(RuntimeOrigin::signed([4; 32].into()), [0; 32].into())); + assert_ok!(GameModule::register_user( + RuntimeOrigin::signed([4; 32].into()), + [0; 32].into() + )); practise_round([0; 32].into(), 0); assert_ok!(GameModule::play_game( RuntimeOrigin::signed([0; 32].into()), crate::DifficultyLevel::Player, )); assert_ok!(GameModule::submit_answer(RuntimeOrigin::signed([0; 32].into()), 220_000, 1)); - System::assert_last_event(Event::AnswerSubmitted { player: [0; 32].into(), game_id: 1, guess: 220_000 }.into()); - assert_ok!(GameModule::check_result(RuntimeOrigin::root(), 220_000, 1, 220_000,"nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap())); + System::assert_last_event( + Event::AnswerSubmitted { player: [0; 32].into(), game_id: 1, guess: 220_000 }.into(), + ); + assert_ok!(GameModule::check_result( + RuntimeOrigin::root(), + 220_000, + 1, + 220_000, + "nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap() + )); assert_eq!(GameModule::game_info(1).is_none(), true); assert_eq!(GameModule::users::([0; 32].into()).unwrap().points, 155); assert_eq!(Nfts::owner(0, 0).unwrap(), [0; 32].into()); @@ -300,15 +400,26 @@ fn list_nft_doesnt_work() { assert_ok!(GameModule::setup_game(RuntimeOrigin::root())); assert_eq!(GameModule::test_properties().len(), 4); assert_ok!(GameModule::add_to_admins(RuntimeOrigin::root(), [4; 32].into())); - assert_ok!(GameModule::register_user(RuntimeOrigin::signed([4; 32].into()), [0; 32].into())); + assert_ok!(GameModule::register_user( + RuntimeOrigin::signed([4; 32].into()), + [0; 32].into() + )); practise_round([0; 32].into(), 0); assert_ok!(GameModule::play_game( RuntimeOrigin::signed([0; 32].into()), crate::DifficultyLevel::Player, )); assert_ok!(GameModule::submit_answer(RuntimeOrigin::signed([0; 32].into()), 220_000, 1)); - System::assert_last_event(Event::AnswerSubmitted { player: [0; 32].into(), game_id: 1, guess: 220_000 }.into()); - assert_ok!(GameModule::check_result(RuntimeOrigin::root(), 220_000, 1, 220_000,"nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap())); + System::assert_last_event( + Event::AnswerSubmitted { player: [0; 32].into(), game_id: 1, guess: 220_000 }.into(), + ); + assert_ok!(GameModule::check_result( + RuntimeOrigin::root(), + 220_000, + 1, + 220_000, + "nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap() + )); assert_eq!(GameModule::game_info(1).is_none(), true); assert_eq!(GameModule::users::([0; 32].into()).unwrap().points, 155); assert_eq!(Nfts::owner(0, 0).unwrap(), [0; 32].into()); @@ -326,15 +437,26 @@ fn delist_nft_works() { assert_ok!(GameModule::setup_game(RuntimeOrigin::root())); assert_eq!(GameModule::test_properties().len(), 4); assert_ok!(GameModule::add_to_admins(RuntimeOrigin::root(), [4; 32].into())); - assert_ok!(GameModule::register_user(RuntimeOrigin::signed([4; 32].into()), [0; 32].into())); + assert_ok!(GameModule::register_user( + RuntimeOrigin::signed([4; 32].into()), + [0; 32].into() + )); practise_round([0; 32].into(), 0); assert_ok!(GameModule::play_game( RuntimeOrigin::signed([0; 32].into()), crate::DifficultyLevel::Player, )); assert_ok!(GameModule::submit_answer(RuntimeOrigin::signed([0; 32].into()), 220_000, 1)); - System::assert_last_event(Event::AnswerSubmitted { player: [0; 32].into(), game_id: 1, guess: 220_000 }.into()); - assert_ok!(GameModule::check_result(RuntimeOrigin::root(), 220_000, 1, 220_000,"nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap())); + System::assert_last_event( + Event::AnswerSubmitted { player: [0; 32].into(), game_id: 1, guess: 220_000 }.into(), + ); + assert_ok!(GameModule::check_result( + RuntimeOrigin::root(), + 220_000, + 1, + 220_000, + "nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap() + )); assert_eq!(GameModule::game_info(0).is_none(), true); assert_eq!(GameModule::users::([0; 32].into()).unwrap().points, 155); assert_eq!(Nfts::owner(0, 0).unwrap(), [0; 32].into()); @@ -365,15 +487,26 @@ fn delist_nft_doesnt_works() { assert_ok!(GameModule::setup_game(RuntimeOrigin::root())); assert_eq!(GameModule::test_properties().len(), 4); assert_ok!(GameModule::add_to_admins(RuntimeOrigin::root(), [4; 32].into())); - assert_ok!(GameModule::register_user(RuntimeOrigin::signed([4; 32].into()), [0; 32].into())); + assert_ok!(GameModule::register_user( + RuntimeOrigin::signed([4; 32].into()), + [0; 32].into() + )); practise_round([0; 32].into(), 0); assert_ok!(GameModule::play_game( RuntimeOrigin::signed([0; 32].into()), crate::DifficultyLevel::Player, )); assert_ok!(GameModule::submit_answer(RuntimeOrigin::signed([0; 32].into()), 220_000, 1)); - System::assert_last_event(Event::AnswerSubmitted { player: [0; 32].into(), game_id: 1, guess: 220_000 }.into()); - assert_ok!(GameModule::check_result(RuntimeOrigin::root(), 220_000, 1, 220_000,"nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap())); + System::assert_last_event( + Event::AnswerSubmitted { player: [0; 32].into(), game_id: 1, guess: 220_000 }.into(), + ); + assert_ok!(GameModule::check_result( + RuntimeOrigin::root(), + 220_000, + 1, + 220_000, + "nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap() + )); assert_eq!(GameModule::game_info(0).is_none(), true); assert_eq!(GameModule::users::([0; 32].into()).unwrap().points, 155); assert_eq!(Nfts::owner(0, 0).unwrap(), [0; 32].into()); @@ -394,16 +527,30 @@ fn make_offer_works() { assert_ok!(GameModule::setup_game(RuntimeOrigin::root())); assert_eq!(GameModule::test_properties().len(), 4); assert_ok!(GameModule::add_to_admins(RuntimeOrigin::root(), [4; 32].into())); - assert_ok!(GameModule::register_user(RuntimeOrigin::signed([4; 32].into()), [0; 32].into())); - assert_ok!(GameModule::register_user(RuntimeOrigin::signed([4; 32].into()), [1; 32].into())); + assert_ok!(GameModule::register_user( + RuntimeOrigin::signed([4; 32].into()), + [0; 32].into() + )); + assert_ok!(GameModule::register_user( + RuntimeOrigin::signed([4; 32].into()), + [1; 32].into() + )); practise_round([0; 32].into(), 0); assert_ok!(GameModule::play_game( RuntimeOrigin::signed([0; 32].into()), crate::DifficultyLevel::Player, )); assert_ok!(GameModule::submit_answer(RuntimeOrigin::signed([0; 32].into()), 220_000, 1)); - System::assert_last_event(Event::AnswerSubmitted { player: [0; 32].into(), game_id: 1, guess: 220_000 }.into()); - assert_ok!(GameModule::check_result(RuntimeOrigin::root(), 220_000, 1, 220_000,"nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap())); + System::assert_last_event( + Event::AnswerSubmitted { player: [0; 32].into(), game_id: 1, guess: 220_000 }.into(), + ); + assert_ok!(GameModule::check_result( + RuntimeOrigin::root(), + 220_000, + 1, + 220_000, + "nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap() + )); assert_eq!(GameModule::game_info(0).is_none(), true); assert_eq!(GameModule::users::([0; 32].into()).unwrap().points, 155); assert_eq!(Nfts::owner(0, 0).unwrap(), [0; 32].into()); @@ -413,8 +560,16 @@ fn make_offer_works() { crate::DifficultyLevel::Player, )); assert_ok!(GameModule::submit_answer(RuntimeOrigin::signed([1; 32].into()), 220_000, 3)); - System::assert_last_event(Event::AnswerSubmitted { player: [1; 32].into(), game_id: 3, guess: 220_000 }.into()); - assert_ok!(GameModule::check_result(RuntimeOrigin::root(), 220_000, 3, 220_000,"nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap())); + System::assert_last_event( + Event::AnswerSubmitted { player: [1; 32].into(), game_id: 3, guess: 220_000 }.into(), + ); + assert_ok!(GameModule::check_result( + RuntimeOrigin::root(), + 220_000, + 3, + 220_000, + "nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap() + )); assert_eq!(Nfts::owner(0, 1).unwrap(), [1; 32].into()); assert_ok!(GameModule::list_nft(RuntimeOrigin::signed([0; 32].into()), 0, 0,)); assert_eq!(Nfts::owner(0, 0).unwrap(), GameModule::account_id()); @@ -431,7 +586,10 @@ fn make_offer_doesnt_works() { assert_ok!(GameModule::setup_game(RuntimeOrigin::root())); assert_eq!(GameModule::test_properties().len(), 4); assert_ok!(GameModule::add_to_admins(RuntimeOrigin::root(), [4; 32].into())); - assert_ok!(GameModule::register_user(RuntimeOrigin::signed([4; 32].into()), [0; 32].into())); + assert_ok!(GameModule::register_user( + RuntimeOrigin::signed([4; 32].into()), + [0; 32].into() + )); assert_ok!(GameModule::give_points(RuntimeOrigin::root(), [0; 32].into())); practise_round([0; 32].into(), 0); assert_ok!(GameModule::play_game( @@ -453,16 +611,30 @@ fn withdraw_offer_works() { assert_ok!(GameModule::setup_game(RuntimeOrigin::root())); assert_eq!(GameModule::test_properties().len(), 4); assert_ok!(GameModule::add_to_admins(RuntimeOrigin::root(), [4; 32].into())); - assert_ok!(GameModule::register_user(RuntimeOrigin::signed([4; 32].into()), [0; 32].into())); - assert_ok!(GameModule::register_user(RuntimeOrigin::signed([4; 32].into()), [1; 32].into())); + assert_ok!(GameModule::register_user( + RuntimeOrigin::signed([4; 32].into()), + [0; 32].into() + )); + assert_ok!(GameModule::register_user( + RuntimeOrigin::signed([4; 32].into()), + [1; 32].into() + )); practise_round([0; 32].into(), 0); assert_ok!(GameModule::play_game( RuntimeOrigin::signed([0; 32].into()), crate::DifficultyLevel::Player, )); assert_ok!(GameModule::submit_answer(RuntimeOrigin::signed([0; 32].into()), 220_000, 1)); - System::assert_last_event(Event::AnswerSubmitted { player: [0; 32].into(), game_id: 1, guess: 220_000 }.into()); - assert_ok!(GameModule::check_result(RuntimeOrigin::root(), 220_000, 1, 220_000,"nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap())); + System::assert_last_event( + Event::AnswerSubmitted { player: [0; 32].into(), game_id: 1, guess: 220_000 }.into(), + ); + assert_ok!(GameModule::check_result( + RuntimeOrigin::root(), + 220_000, + 1, + 220_000, + "nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap() + )); assert_eq!(GameModule::game_info(0).is_none(), true); assert_eq!(GameModule::users::([0; 32].into()).unwrap().points, 155); assert_eq!(Nfts::owner(0, 0).unwrap(), [0; 32].into()); @@ -472,8 +644,16 @@ fn withdraw_offer_works() { crate::DifficultyLevel::Player, )); assert_ok!(GameModule::submit_answer(RuntimeOrigin::signed([1; 32].into()), 220_000, 3)); - System::assert_last_event(Event::AnswerSubmitted { player: [1; 32].into(), game_id: 3, guess: 220_000 }.into()); - assert_ok!(GameModule::check_result(RuntimeOrigin::root(), 220_000, 3, 220_000,"nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap())); + System::assert_last_event( + Event::AnswerSubmitted { player: [1; 32].into(), game_id: 3, guess: 220_000 }.into(), + ); + assert_ok!(GameModule::check_result( + RuntimeOrigin::root(), + 220_000, + 3, + 220_000, + "nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap() + )); assert_eq!(Nfts::owner(0, 1).unwrap(), [1; 32].into()); assert_ok!(GameModule::list_nft(RuntimeOrigin::signed([0; 32].into()), 0, 0,)); assert_eq!(Nfts::owner(0, 0).unwrap(), GameModule::account_id()); @@ -492,16 +672,30 @@ fn withdraw_offer_fails() { assert_ok!(GameModule::setup_game(RuntimeOrigin::root())); assert_eq!(GameModule::test_properties().len(), 4); assert_ok!(GameModule::add_to_admins(RuntimeOrigin::root(), [4; 32].into())); - assert_ok!(GameModule::register_user(RuntimeOrigin::signed([4; 32].into()), [0; 32].into())); - assert_ok!(GameModule::register_user(RuntimeOrigin::signed([4; 32].into()), [1; 32].into())); + assert_ok!(GameModule::register_user( + RuntimeOrigin::signed([4; 32].into()), + [0; 32].into() + )); + assert_ok!(GameModule::register_user( + RuntimeOrigin::signed([4; 32].into()), + [1; 32].into() + )); practise_round([0; 32].into(), 0); assert_ok!(GameModule::play_game( RuntimeOrigin::signed([0; 32].into()), crate::DifficultyLevel::Player, )); assert_ok!(GameModule::submit_answer(RuntimeOrigin::signed([0; 32].into()), 220_000, 1)); - System::assert_last_event(Event::AnswerSubmitted { player: [0; 32].into(), game_id: 1, guess: 220_000 }.into()); - assert_ok!(GameModule::check_result(RuntimeOrigin::root(), 220_000, 1, 220_000,"nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap())); + System::assert_last_event( + Event::AnswerSubmitted { player: [0; 32].into(), game_id: 1, guess: 220_000 }.into(), + ); + assert_ok!(GameModule::check_result( + RuntimeOrigin::root(), + 220_000, + 1, + 220_000, + "nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap() + )); assert_eq!(GameModule::game_info(0).is_none(), true); assert_eq!(GameModule::users::([0; 32].into()).unwrap().points, 155); assert_eq!(Nfts::owner(0, 0).unwrap(), [0; 32].into()); @@ -511,8 +705,16 @@ fn withdraw_offer_fails() { crate::DifficultyLevel::Player, )); assert_ok!(GameModule::submit_answer(RuntimeOrigin::signed([1; 32].into()), 220_000, 3)); - System::assert_last_event(Event::AnswerSubmitted { player: [1; 32].into(), game_id: 3, guess: 220_000 }.into()); - assert_ok!(GameModule::check_result(RuntimeOrigin::root(), 220_000, 3, 220_000,"nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap())); + System::assert_last_event( + Event::AnswerSubmitted { player: [1; 32].into(), game_id: 3, guess: 220_000 }.into(), + ); + assert_ok!(GameModule::check_result( + RuntimeOrigin::root(), + 220_000, + 3, + 220_000, + "nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap() + )); assert_eq!(Nfts::owner(0, 1).unwrap(), [1; 32].into()); assert_ok!(GameModule::list_nft(RuntimeOrigin::signed([0; 32].into()), 0, 0,)); assert_eq!(Nfts::owner(0, 0).unwrap(), GameModule::account_id()); @@ -537,16 +739,30 @@ fn handle_offer_accept_works() { assert_ok!(GameModule::setup_game(RuntimeOrigin::root())); assert_eq!(GameModule::test_properties().len(), 4); assert_ok!(GameModule::add_to_admins(RuntimeOrigin::root(), [4; 32].into())); - assert_ok!(GameModule::register_user(RuntimeOrigin::signed([4; 32].into()), [0; 32].into())); - assert_ok!(GameModule::register_user(RuntimeOrigin::signed([4; 32].into()), [1; 32].into())); + assert_ok!(GameModule::register_user( + RuntimeOrigin::signed([4; 32].into()), + [0; 32].into() + )); + assert_ok!(GameModule::register_user( + RuntimeOrigin::signed([4; 32].into()), + [1; 32].into() + )); practise_round([0; 32].into(), 0); assert_ok!(GameModule::play_game( RuntimeOrigin::signed([0; 32].into()), crate::DifficultyLevel::Player, )); assert_ok!(GameModule::submit_answer(RuntimeOrigin::signed([0; 32].into()), 220_000, 1)); - System::assert_last_event(Event::AnswerSubmitted { player: [0; 32].into(), game_id: 1, guess: 220_000 }.into()); - assert_ok!(GameModule::check_result(RuntimeOrigin::root(), 220_000, 1, 220_000,"nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap())); + System::assert_last_event( + Event::AnswerSubmitted { player: [0; 32].into(), game_id: 1, guess: 220_000 }.into(), + ); + assert_ok!(GameModule::check_result( + RuntimeOrigin::root(), + 220_000, + 1, + 220_000, + "nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap() + )); assert_eq!(GameModule::users::([0; 32].into()).unwrap().points, 155); assert_eq!(GameModule::game_info(0).is_none(), true); assert_eq!(Nfts::owner(0, 0).unwrap(), [0; 32].into()); @@ -556,23 +772,47 @@ fn handle_offer_accept_works() { crate::DifficultyLevel::Player, )); assert_ok!(GameModule::submit_answer(RuntimeOrigin::signed([1; 32].into()), 220_000, 3)); - System::assert_last_event(Event::AnswerSubmitted { player: [1; 32].into(), game_id: 3, guess: 220_000 }.into()); - assert_ok!(GameModule::check_result(RuntimeOrigin::root(), 220_000, 3, 220_000,"nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap())); + System::assert_last_event( + Event::AnswerSubmitted { player: [1; 32].into(), game_id: 3, guess: 220_000 }.into(), + ); + assert_ok!(GameModule::check_result( + RuntimeOrigin::root(), + 220_000, + 3, + 220_000, + "nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap() + )); assert_ok!(GameModule::play_game( RuntimeOrigin::signed([0; 32].into()), crate::DifficultyLevel::Player, )); assert_ok!(GameModule::submit_answer(RuntimeOrigin::signed([0; 32].into()), 220_000, 4)); - System::assert_last_event(Event::AnswerSubmitted { player: [0; 32].into(), game_id: 4, guess: 220_000 }.into()); - assert_ok!(GameModule::check_result(RuntimeOrigin::root(), 220_000, 4, 220_000,"nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap())); + System::assert_last_event( + Event::AnswerSubmitted { player: [0; 32].into(), game_id: 4, guess: 220_000 }.into(), + ); + assert_ok!(GameModule::check_result( + RuntimeOrigin::root(), + 220_000, + 4, + 220_000, + "nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap() + )); assert_eq!(GameModule::users::([0; 32].into()).unwrap().points, 275); assert_ok!(GameModule::play_game( RuntimeOrigin::signed([0; 32].into()), crate::DifficultyLevel::Player, )); assert_ok!(GameModule::submit_answer(RuntimeOrigin::signed([0; 32].into()), 220_000, 5)); - System::assert_last_event(Event::AnswerSubmitted { player: [0; 32].into(), game_id: 5, guess: 220_000 }.into()); - assert_ok!(GameModule::check_result(RuntimeOrigin::root(), 220_000, 5, 220_000,"nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap())); + System::assert_last_event( + Event::AnswerSubmitted { player: [0; 32].into(), game_id: 5, guess: 220_000 }.into(), + ); + assert_ok!(GameModule::check_result( + RuntimeOrigin::root(), + 220_000, + 5, + 220_000, + "nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap() + )); assert_eq!(GameModule::users::([0; 32].into()).unwrap().nfts.xorange, 3); assert_eq!(GameModule::users::([0; 32].into()).unwrap().points, 495); assert_eq!(GameModule::users::([1; 32].into()).unwrap().nfts.xorange, 1); @@ -631,16 +871,30 @@ fn handle_offer_reject_works() { assert_ok!(GameModule::setup_game(RuntimeOrigin::root())); assert_eq!(GameModule::test_properties().len(), 4); assert_ok!(GameModule::add_to_admins(RuntimeOrigin::root(), [4; 32].into())); - assert_ok!(GameModule::register_user(RuntimeOrigin::signed([4; 32].into()), [0; 32].into())); - assert_ok!(GameModule::register_user(RuntimeOrigin::signed([4; 32].into()), [1; 32].into())); + assert_ok!(GameModule::register_user( + RuntimeOrigin::signed([4; 32].into()), + [0; 32].into() + )); + assert_ok!(GameModule::register_user( + RuntimeOrigin::signed([4; 32].into()), + [1; 32].into() + )); practise_round([0; 32].into(), 0); assert_ok!(GameModule::play_game( RuntimeOrigin::signed([0; 32].into()), crate::DifficultyLevel::Player, )); assert_ok!(GameModule::submit_answer(RuntimeOrigin::signed([0; 32].into()), 220_000, 1)); - System::assert_last_event(Event::AnswerSubmitted { player: [0; 32].into(), game_id: 1, guess: 220_000 }.into()); - assert_ok!(GameModule::check_result(RuntimeOrigin::root(), 220_000, 1, 220_000,"nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap())); + System::assert_last_event( + Event::AnswerSubmitted { player: [0; 32].into(), game_id: 1, guess: 220_000 }.into(), + ); + assert_ok!(GameModule::check_result( + RuntimeOrigin::root(), + 220_000, + 1, + 220_000, + "nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap() + )); assert_eq!(GameModule::game_info(0).is_none(), true); assert_eq!(GameModule::users::([0; 32].into()).unwrap().points, 155); assert_eq!(Nfts::owner(0, 0).unwrap(), [0; 32].into()); @@ -650,8 +904,16 @@ fn handle_offer_reject_works() { crate::DifficultyLevel::Player, )); assert_ok!(GameModule::submit_answer(RuntimeOrigin::signed([1; 32].into()), 220_000, 3)); - System::assert_last_event(Event::AnswerSubmitted { player: [1; 32].into(), game_id: 3, guess: 220_000 }.into()); - assert_ok!(GameModule::check_result(RuntimeOrigin::root(), 220_000, 3, 220_000,"nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap())); + System::assert_last_event( + Event::AnswerSubmitted { player: [1; 32].into(), game_id: 3, guess: 220_000 }.into(), + ); + assert_ok!(GameModule::check_result( + RuntimeOrigin::root(), + 220_000, + 3, + 220_000, + "nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap() + )); assert_eq!(Nfts::owner(0, 1).unwrap(), [1; 32].into()); assert_ok!(GameModule::list_nft(RuntimeOrigin::signed([0; 32].into()), 0, 0,)); assert_eq!(Nfts::owner(0, 0).unwrap(), GameModule::account_id()); @@ -689,16 +951,30 @@ fn handle_offer_doesnt_works() { assert_ok!(GameModule::setup_game(RuntimeOrigin::root())); assert_eq!(GameModule::test_properties().len(), 4); assert_ok!(GameModule::add_to_admins(RuntimeOrigin::root(), [4; 32].into())); - assert_ok!(GameModule::register_user(RuntimeOrigin::signed([4; 32].into()), [0; 32].into())); - assert_ok!(GameModule::register_user(RuntimeOrigin::signed([4; 32].into()), [1; 32].into())); + assert_ok!(GameModule::register_user( + RuntimeOrigin::signed([4; 32].into()), + [0; 32].into() + )); + assert_ok!(GameModule::register_user( + RuntimeOrigin::signed([4; 32].into()), + [1; 32].into() + )); practise_round([0; 32].into(), 0); assert_ok!(GameModule::play_game( RuntimeOrigin::signed([0; 32].into()), crate::DifficultyLevel::Player, )); assert_ok!(GameModule::submit_answer(RuntimeOrigin::signed([0; 32].into()), 220_000, 1)); - System::assert_last_event(Event::AnswerSubmitted { player: [0; 32].into(), game_id: 1, guess: 220_000 }.into()); - assert_ok!(GameModule::check_result(RuntimeOrigin::root(), 220_000, 1, 220_000,"nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap())); + System::assert_last_event( + Event::AnswerSubmitted { player: [0; 32].into(), game_id: 1, guess: 220_000 }.into(), + ); + assert_ok!(GameModule::check_result( + RuntimeOrigin::root(), + 220_000, + 1, + 220_000, + "nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap() + )); assert_eq!(GameModule::game_info(0).is_none(), true); assert_eq!(GameModule::users::([0; 32].into()).unwrap().points, 155); assert_eq!(Nfts::owner(0, 0).unwrap(), [0; 32].into()); @@ -708,8 +984,16 @@ fn handle_offer_doesnt_works() { crate::DifficultyLevel::Player, )); assert_ok!(GameModule::submit_answer(RuntimeOrigin::signed([1; 32].into()), 220_000, 3)); - System::assert_last_event(Event::AnswerSubmitted { player: [1; 32].into(), game_id: 3, guess: 220_000 }.into()); - assert_ok!(GameModule::check_result(RuntimeOrigin::root(), 220_000, 3, 220_000,"nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap())); + System::assert_last_event( + Event::AnswerSubmitted { player: [1; 32].into(), game_id: 3, guess: 220_000 }.into(), + ); + assert_ok!(GameModule::check_result( + RuntimeOrigin::root(), + 220_000, + 3, + 220_000, + "nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap() + )); assert_eq!(Nfts::owner(0, 1).unwrap(), [1; 32].into()); assert_ok!(GameModule::list_nft(RuntimeOrigin::signed([0; 32].into()), 0, 0,)); assert_eq!(Nfts::owner(0, 0).unwrap(), GameModule::account_id()); @@ -732,7 +1016,10 @@ fn play_multiple_rounds_works() { assert_ok!(GameModule::setup_game(RuntimeOrigin::root())); assert_eq!(GameModule::test_properties().len(), 4); assert_ok!(GameModule::add_to_admins(RuntimeOrigin::root(), [4; 32].into())); - assert_ok!(GameModule::register_user(RuntimeOrigin::signed([4; 32].into()), [0; 32].into())); + assert_ok!(GameModule::register_user( + RuntimeOrigin::signed([4; 32].into()), + [0; 32].into() + )); practise_round([0; 32].into(), 0); for x in 1..=20 { assert_ok!(GameModule::play_game( @@ -744,8 +1031,17 @@ fn play_multiple_rounds_works() { 217_000, x )); - System::assert_last_event(Event::AnswerSubmitted { player: [0; 32].into(), game_id: x, guess: 217_000 }.into()); - assert_ok!(GameModule::check_result(RuntimeOrigin::root(), 217_000, x, 220_000,"nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap())); + System::assert_last_event( + Event::AnswerSubmitted { player: [0; 32].into(), game_id: x, guess: 217_000 } + .into(), + ); + assert_ok!(GameModule::check_result( + RuntimeOrigin::root(), + 217_000, + x, + 220_000, + "nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap() + )); } assert_ok!(GameModule::play_game( RuntimeOrigin::signed([0; 32].into()), @@ -765,7 +1061,7 @@ fn add_property_works() { id: 147031382, data: "nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap(), price: "kkjfkdjdkdjdkdjdk".as_bytes().to_vec().try_into().unwrap(), - }; + }; assert_ok!(GameModule::add_property(RuntimeOrigin::root(), new_property)); assert_eq!(GameModule::test_properties().len(), 5); }); @@ -787,7 +1083,10 @@ fn request_token_works() { System::set_block_number(1); assert_ok!(GameModule::setup_game(RuntimeOrigin::root())); assert_ok!(GameModule::add_to_admins(RuntimeOrigin::root(), [4; 32].into())); - assert_ok!(GameModule::register_user(RuntimeOrigin::signed([4; 32].into()), [0; 32].into())); + assert_ok!(GameModule::register_user( + RuntimeOrigin::signed([4; 32].into()), + [0; 32].into() + )); System::set_block_number(100802); assert_ok!(GameModule::request_token(RuntimeOrigin::signed([0; 32].into()))); assert_eq!(Balances::free_balance(&([0; 32].into())), 10); @@ -799,10 +1098,19 @@ fn request_token_doesnt_works() { new_test_ext().execute_with(|| { System::set_block_number(1); assert_ok!(GameModule::setup_game(RuntimeOrigin::root())); - assert_noop!(GameModule::request_token(RuntimeOrigin::signed([0; 32].into())), Error::::UserNotRegistered); + assert_noop!( + GameModule::request_token(RuntimeOrigin::signed([0; 32].into())), + Error::::UserNotRegistered + ); assert_ok!(GameModule::add_to_admins(RuntimeOrigin::root(), [4; 32].into())); - assert_ok!(GameModule::register_user(RuntimeOrigin::signed([4; 32].into()), [0; 32].into())); - assert_noop!(GameModule::request_token(RuntimeOrigin::signed([0; 32].into())), Error::::CantRequestToken); + assert_ok!(GameModule::register_user( + RuntimeOrigin::signed([4; 32].into()), + [0; 32].into() + )); + assert_noop!( + GameModule::request_token(RuntimeOrigin::signed([0; 32].into())), + Error::::CantRequestToken + ); }); } @@ -813,15 +1121,44 @@ fn check_result_fails() { assert_ok!(GameModule::setup_game(RuntimeOrigin::root())); assert_eq!(GameModule::test_properties().len(), 4); assert_ok!(GameModule::add_to_admins(RuntimeOrigin::root(), [4; 32].into())); - assert_ok!(GameModule::register_user(RuntimeOrigin::signed([4; 32].into()), [0; 32].into())); + assert_ok!(GameModule::register_user( + RuntimeOrigin::signed([4; 32].into()), + [0; 32].into() + )); practise_round([0; 32].into(), 0); - assert_noop!(GameModule::check_result(RuntimeOrigin::root(), 223_000, 0, 220_000,"nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap()), Error::::NoActiveGame); - assert_noop!(GameModule::check_result(RuntimeOrigin::root(), 223_000, 1, 220_000,"nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap()), Error::::NoActiveGame); + assert_noop!( + GameModule::check_result( + RuntimeOrigin::root(), + 223_000, + 0, + 220_000, + "nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap() + ), + Error::::NoActiveGame + ); + assert_noop!( + GameModule::check_result( + RuntimeOrigin::root(), + 223_000, + 1, + 220_000, + "nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap() + ), + Error::::NoActiveGame + ); assert_ok!(GameModule::play_game( RuntimeOrigin::signed([0; 32].into()), crate::DifficultyLevel::Player, )); - assert_noop!(GameModule::check_result(RuntimeOrigin::root(), 223_000, 1, 220_000,"nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap()), Error::::NoGuess); + assert_noop!( + GameModule::check_result( + RuntimeOrigin::root(), + 223_000, + 1, + 220_000, + "nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap() + ), + Error::::NoGuess + ); }); -} - \ No newline at end of file +} diff --git a/pallets/game/src/types.rs b/pallets/game/src/types.rs index 8eacc6f..f44da95 100644 --- a/pallets/game/src/types.rs +++ b/pallets/game/src/types.rs @@ -2,316 +2,314 @@ use crate::*; use frame_support::pallet_prelude::*; use frame_system::pallet_prelude::*; - /// Difficulty level of game enum. - #[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))] - #[derive(Encode, Decode, Clone, PartialEq, Eq, MaxEncodedLen, RuntimeDebug, TypeInfo)] - pub enum DifficultyLevel { - Practice, - Player, - Pro, - } +/// Difficulty level of game enum. +#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))] +#[derive(Encode, Decode, Clone, PartialEq, Eq, MaxEncodedLen, RuntimeDebug, TypeInfo)] +pub enum DifficultyLevel { + Practice, + Player, + Pro, +} - /// Offer enum. - #[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))] - #[derive(Encode, Decode, Clone, PartialEq, Eq, MaxEncodedLen, RuntimeDebug, TypeInfo)] - pub enum Offer { - Accept, - Reject, - } +/// Offer enum. +#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))] +#[derive(Encode, Decode, Clone, PartialEq, Eq, MaxEncodedLen, RuntimeDebug, TypeInfo)] +pub enum Offer { + Accept, + Reject, +} - /// Nft color enum. - #[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))] - #[derive(Encode, Decode, Clone, PartialEq, Eq, MaxEncodedLen, RuntimeDebug, TypeInfo)] - pub enum NftColor { - Xorange, - Xpink, - Xblue, - Xcyan, - Xcoral, - Xpurple, - Xleafgreen, - Xgreen, - } +/// Nft color enum. +#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))] +#[derive(Encode, Decode, Clone, PartialEq, Eq, MaxEncodedLen, RuntimeDebug, TypeInfo)] +pub enum NftColor { + Xorange, + Xpink, + Xblue, + Xcyan, + Xcoral, + Xpurple, + Xleafgreen, + Xgreen, +} - impl NftColor { - pub fn from_index(index: usize) -> Option { - match index { - 0 => Some(NftColor::Xorange), - 1 => Some(NftColor::Xpink), - 2 => Some(NftColor::Xblue), - 3 => Some(NftColor::Xcyan), - 4 => Some(NftColor::Xcoral), - 5 => Some(NftColor::Xpurple), - 6 => Some(NftColor::Xleafgreen), - 7 => Some(NftColor::Xgreen), - _ => None, - } +impl NftColor { + pub fn from_index(index: usize) -> Option { + match index { + 0 => Some(NftColor::Xorange), + 1 => Some(NftColor::Xpink), + 2 => Some(NftColor::Xblue), + 3 => Some(NftColor::Xcyan), + 4 => Some(NftColor::Xcoral), + 5 => Some(NftColor::Xpurple), + 6 => Some(NftColor::Xleafgreen), + 7 => Some(NftColor::Xgreen), + _ => None, } } +} - /// AccountId storage. - #[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))] - #[derive(Encode, Decode, Clone, PartialEq, Eq, MaxEncodedLen, RuntimeDebug, TypeInfo)] - pub struct PalletIdStorage { - pallet_id: AccountIdOf, - } +/// AccountId storage. +#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))] +#[derive(Encode, Decode, Clone, PartialEq, Eq, MaxEncodedLen, RuntimeDebug, TypeInfo)] +pub struct PalletIdStorage { + pallet_id: AccountIdOf, +} - /// Game Data. - #[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))] - #[derive(Encode, Decode, Clone, PartialEq, Eq, MaxEncodedLen, RuntimeDebug, TypeInfo)] - #[scale_info(skip_type_params(T))] - pub struct GameData { - pub difficulty: DifficultyLevel, - pub player: AccountIdOf, - pub property: PropertyInfoData, - pub guess: Option, - } +/// Game Data. +#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))] +#[derive(Encode, Decode, Clone, PartialEq, Eq, MaxEncodedLen, RuntimeDebug, TypeInfo)] +#[scale_info(skip_type_params(T))] +pub struct GameData { + pub difficulty: DifficultyLevel, + pub player: AccountIdOf, + pub property: PropertyInfoData, + pub guess: Option, +} - /// Listing infos of a NFT. - #[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))] - #[derive(Encode, Decode, Clone, PartialEq, Eq, MaxEncodedLen, RuntimeDebug, TypeInfo)] - #[scale_info(skip_type_params(T))] - pub struct ListingInfo { - pub owner: AccountIdOf, - pub collection_id: CollectionId, - pub item_id: ItemId, - } +/// Listing infos of a NFT. +#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))] +#[derive(Encode, Decode, Clone, PartialEq, Eq, MaxEncodedLen, RuntimeDebug, TypeInfo)] +#[scale_info(skip_type_params(T))] +pub struct ListingInfo { + pub owner: AccountIdOf, + pub collection_id: CollectionId, + pub item_id: ItemId, +} + +/// Offer infos of a listing. +#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))] +#[derive(Encode, Decode, Clone, PartialEq, Eq, MaxEncodedLen, RuntimeDebug, TypeInfo)] +#[scale_info(skip_type_params(T))] +pub struct OfferInfo { + pub owner: AccountIdOf, + pub listing_id: u32, + pub collection_id: CollectionId, + pub item_id: ItemId, +} + +/// Struct to store the property data for a game. +#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))] +#[derive( + Encode, + Decode, + Clone, + PartialEq, + Eq, + MaxEncodedLen, + frame_support::pallet_prelude::RuntimeDebugNoBound, + TypeInfo, +)] +#[scale_info(skip_type_params(T))] +pub struct PropertyInfoData { + pub id: u32, + pub data: BoundedVec::StringLimit>, + pub price: BoundedVec::StringLimit>, +} - /// Offer infos of a listing. - #[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))] - #[derive(Encode, Decode, Clone, PartialEq, Eq, MaxEncodedLen, RuntimeDebug, TypeInfo)] - #[scale_info(skip_type_params(T))] - pub struct OfferInfo { - pub owner: AccountIdOf, - pub listing_id: u32, - pub collection_id: CollectionId, - pub item_id: ItemId, +/// Struct for the user datas. +#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))] +#[derive(Encode, Decode, Clone, PartialEq, Eq, MaxEncodedLen, RuntimeDebug, TypeInfo)] +#[scale_info(skip_type_params(T))] +pub struct User { + pub points: u32, + pub wins: u32, + pub losses: u32, + pub practise_rounds: u8, + pub last_played_round: u32, + pub next_token_request: BlockNumberFor, + pub nfts: CollectedColors, +} + +impl User { + pub fn add_nft_color(&mut self, color: NftColor) -> DispatchResult { + self.nfts.add_nft_color(color)?; + Ok(()) } - /// Struct to store the property data for a game. - #[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))] - #[derive( - Encode, - Decode, - Clone, - PartialEq, - Eq, - MaxEncodedLen, - frame_support::pallet_prelude::RuntimeDebugNoBound, - TypeInfo, - )] - #[scale_info(skip_type_params(T))] - pub struct PropertyInfoData { - pub id: u32, - pub data: BoundedVec::StringLimit>, - pub price: BoundedVec::StringLimit>, + pub fn sub_nft_color(&mut self, color: NftColor) -> DispatchResult { + self.nfts.sub_nft_color(color)?; + Ok(()) } - /// Struct for the user datas. - #[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))] - #[derive(Encode, Decode, Clone, PartialEq, Eq, MaxEncodedLen, RuntimeDebug, TypeInfo)] - #[scale_info(skip_type_params(T))] - pub struct User { - pub points: u32, - pub wins: u32, - pub losses: u32, - pub practise_rounds: u8, - pub last_played_round: u32, - pub next_token_request: BlockNumberFor, - pub nfts: CollectedColors, + pub fn has_four_of_all_colors(&self) -> bool { + self.nfts.has_four_of_all_colors() } - impl User { - pub fn add_nft_color(&mut self, color: NftColor) -> DispatchResult { - self.nfts.add_nft_color(color)?; - Ok(()) + pub fn calculate_points(&mut self, color: NftColor) -> u32 { + match color { + NftColor::Xorange if self.nfts.xorange == 1 => 100, + NftColor::Xorange if self.nfts.xorange == 2 => 120, + NftColor::Xorange if self.nfts.xorange == 3 => 220, + NftColor::Xorange if self.nfts.xorange == 4 => 340, + NftColor::Xpink if self.nfts.xpink == 1 => 100, + NftColor::Xpink if self.nfts.xpink == 2 => 120, + NftColor::Xpink if self.nfts.xpink == 3 => 220, + NftColor::Xpink if self.nfts.xpink == 4 => 340, + NftColor::Xblue if self.nfts.xblue == 1 => 100, + NftColor::Xblue if self.nfts.xblue == 2 => 120, + NftColor::Xblue if self.nfts.xblue == 3 => 220, + NftColor::Xblue if self.nfts.xblue == 4 => 340, + NftColor::Xcyan if self.nfts.xcyan == 1 => 100, + NftColor::Xcyan if self.nfts.xcyan == 2 => 120, + NftColor::Xcyan if self.nfts.xcyan == 3 => 220, + NftColor::Xcyan if self.nfts.xcyan == 4 => 340, + NftColor::Xcoral if self.nfts.xcoral == 1 => 100, + NftColor::Xcoral if self.nfts.xcoral == 2 => 120, + NftColor::Xcoral if self.nfts.xcoral == 3 => 220, + NftColor::Xcoral if self.nfts.xcoral == 4 => 340, + NftColor::Xpurple if self.nfts.xpurple == 1 => 100, + NftColor::Xpurple if self.nfts.xpurple == 2 => 120, + NftColor::Xpurple if self.nfts.xpurple == 3 => 220, + NftColor::Xpurple if self.nfts.xpurple == 4 => 340, + NftColor::Xleafgreen if self.nfts.xleafgreen == 1 => 100, + NftColor::Xleafgreen if self.nfts.xleafgreen == 2 => 120, + NftColor::Xleafgreen if self.nfts.xleafgreen == 3 => 220, + NftColor::Xleafgreen if self.nfts.xleafgreen == 4 => 340, + NftColor::Xgreen if self.nfts.xgreen == 1 => 100, + NftColor::Xgreen if self.nfts.xgreen == 2 => 120, + NftColor::Xgreen if self.nfts.xgreen == 3 => 220, + NftColor::Xgreen if self.nfts.xgreen == 4 => 340, + _ => 0, } + } - pub fn sub_nft_color(&mut self, color: NftColor) -> DispatchResult { - self.nfts.sub_nft_color(color)?; - Ok(()) + pub fn subtracting_calculate_points(&mut self, color: NftColor) -> u32 { + match color { + NftColor::Xorange if self.nfts.xorange == 0 => 100, + NftColor::Xorange if self.nfts.xorange == 1 => 120, + NftColor::Xorange if self.nfts.xorange == 2 => 220, + NftColor::Xorange if self.nfts.xorange == 3 => 340, + NftColor::Xpink if self.nfts.xpink == 0 => 100, + NftColor::Xpink if self.nfts.xpink == 1 => 120, + NftColor::Xpink if self.nfts.xpink == 2 => 220, + NftColor::Xpink if self.nfts.xpink == 3 => 340, + NftColor::Xblue if self.nfts.xblue == 0 => 100, + NftColor::Xblue if self.nfts.xblue == 1 => 120, + NftColor::Xblue if self.nfts.xblue == 2 => 220, + NftColor::Xblue if self.nfts.xblue == 3 => 340, + NftColor::Xcyan if self.nfts.xcyan == 0 => 100, + NftColor::Xcyan if self.nfts.xcyan == 1 => 120, + NftColor::Xcyan if self.nfts.xcyan == 2 => 220, + NftColor::Xcyan if self.nfts.xcyan == 3 => 340, + NftColor::Xcoral if self.nfts.xcoral == 0 => 100, + NftColor::Xcoral if self.nfts.xcoral == 1 => 120, + NftColor::Xcoral if self.nfts.xcoral == 2 => 220, + NftColor::Xcoral if self.nfts.xcoral == 3 => 340, + NftColor::Xpurple if self.nfts.xpurple == 0 => 100, + NftColor::Xpurple if self.nfts.xpurple == 1 => 120, + NftColor::Xpurple if self.nfts.xpurple == 2 => 220, + NftColor::Xpurple if self.nfts.xpurple == 3 => 340, + NftColor::Xleafgreen if self.nfts.xleafgreen == 0 => 100, + NftColor::Xleafgreen if self.nfts.xleafgreen == 1 => 120, + NftColor::Xleafgreen if self.nfts.xleafgreen == 2 => 220, + NftColor::Xleafgreen if self.nfts.xleafgreen == 3 => 340, + NftColor::Xgreen if self.nfts.xgreen == 0 => 100, + NftColor::Xgreen if self.nfts.xgreen == 1 => 120, + NftColor::Xgreen if self.nfts.xgreen == 2 => 220, + NftColor::Xgreen if self.nfts.xgreen == 3 => 340, + _ => 0, } + } +} - pub fn has_four_of_all_colors(&self) -> bool { - self.nfts.has_four_of_all_colors() - } +#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))] +#[derive(Encode, Decode, Clone, PartialEq, Eq, MaxEncodedLen, RuntimeDebug, TypeInfo, Default)] +#[scale_info(skip_type_params(T))] +pub struct CollectedColors { + pub xorange: u32, + pub xpink: u32, + pub xblue: u32, + pub xcyan: u32, + pub xcoral: u32, + pub xpurple: u32, + pub xleafgreen: u32, + pub xgreen: u32, +} - pub fn calculate_points(&mut self, color: NftColor) -> u32 { - match color { - NftColor::Xorange if self.nfts.xorange == 1 => 100, - NftColor::Xorange if self.nfts.xorange == 2 => 120, - NftColor::Xorange if self.nfts.xorange == 3 => 220, - NftColor::Xorange if self.nfts.xorange == 4 => 340, - NftColor::Xpink if self.nfts.xpink == 1 => 100, - NftColor::Xpink if self.nfts.xpink == 2 => 120, - NftColor::Xpink if self.nfts.xpink == 3 => 220, - NftColor::Xpink if self.nfts.xpink == 4 => 340, - NftColor::Xblue if self.nfts.xblue == 1 => 100, - NftColor::Xblue if self.nfts.xblue == 2 => 120, - NftColor::Xblue if self.nfts.xblue == 3 => 220, - NftColor::Xblue if self.nfts.xblue == 4 => 340, - NftColor::Xcyan if self.nfts.xcyan == 1 => 100, - NftColor::Xcyan if self.nfts.xcyan == 2 => 120, - NftColor::Xcyan if self.nfts.xcyan == 3 => 220, - NftColor::Xcyan if self.nfts.xcyan == 4 => 340, - NftColor::Xcoral if self.nfts.xcoral == 1 => 100, - NftColor::Xcoral if self.nfts.xcoral == 2 => 120, - NftColor::Xcoral if self.nfts.xcoral == 3 => 220, - NftColor::Xcoral if self.nfts.xcoral == 4 => 340, - NftColor::Xpurple if self.nfts.xpurple == 1 => 100, - NftColor::Xpurple if self.nfts.xpurple == 2 => 120, - NftColor::Xpurple if self.nfts.xpurple == 3 => 220, - NftColor::Xpurple if self.nfts.xpurple == 4 => 340, - NftColor::Xleafgreen if self.nfts.xleafgreen == 1 => 100, - NftColor::Xleafgreen if self.nfts.xleafgreen == 2 => 120, - NftColor::Xleafgreen if self.nfts.xleafgreen == 3 => 220, - NftColor::Xleafgreen if self.nfts.xleafgreen == 4 => 340, - NftColor::Xgreen if self.nfts.xgreen == 1 => 100, - NftColor::Xgreen if self.nfts.xgreen == 2 => 120, - NftColor::Xgreen if self.nfts.xgreen == 3 => 220, - NftColor::Xgreen if self.nfts.xgreen == 4 => 340, - _ => 0, - } +impl CollectedColors { + pub fn add_nft_color(&mut self, color: NftColor) -> DispatchResult { + match color { + NftColor::Xorange => { + self.xorange = self.xorange.checked_add(1).ok_or("Arithmetic overflow")?; + Ok(()) + }, + NftColor::Xpink => { + self.xpink = self.xpink.checked_add(1).ok_or("Arithmetic overflow")?; + Ok(()) + }, + NftColor::Xblue => { + self.xblue = self.xblue.checked_add(1).ok_or("Arithmetic overflow")?; + Ok(()) + }, + NftColor::Xcyan => { + self.xcyan = self.xcyan.checked_add(1).ok_or("Arithmetic overflow")?; + Ok(()) + }, + NftColor::Xcoral => { + self.xcoral = self.xcoral.checked_add(1).ok_or("Arithmetic overflow")?; + Ok(()) + }, + NftColor::Xpurple => { + self.xpurple = self.xpurple.checked_add(1).ok_or("Arithmetic overflow")?; + Ok(()) + }, + NftColor::Xleafgreen => { + self.xleafgreen = self.xleafgreen.checked_add(1).ok_or("Arithmetic overflow")?; + Ok(()) + }, + NftColor::Xgreen => { + self.xgreen = self.xgreen.checked_add(1).ok_or("Arithmetic overflow")?; + Ok(()) + }, } + } - pub fn subtracting_calculate_points(&mut self, color: NftColor) -> u32 { - match color { - NftColor::Xorange if self.nfts.xorange == 0 => 100, - NftColor::Xorange if self.nfts.xorange == 1 => 120, - NftColor::Xorange if self.nfts.xorange == 2 => 220, - NftColor::Xorange if self.nfts.xorange == 3 => 340, - NftColor::Xpink if self.nfts.xpink == 0 => 100, - NftColor::Xpink if self.nfts.xpink == 1 => 120, - NftColor::Xpink if self.nfts.xpink == 2 => 220, - NftColor::Xpink if self.nfts.xpink == 3 => 340, - NftColor::Xblue if self.nfts.xblue == 0 => 100, - NftColor::Xblue if self.nfts.xblue == 1 => 120, - NftColor::Xblue if self.nfts.xblue == 2 => 220, - NftColor::Xblue if self.nfts.xblue == 3 => 340, - NftColor::Xcyan if self.nfts.xcyan == 0 => 100, - NftColor::Xcyan if self.nfts.xcyan == 1 => 120, - NftColor::Xcyan if self.nfts.xcyan == 2 => 220, - NftColor::Xcyan if self.nfts.xcyan == 3 => 340, - NftColor::Xcoral if self.nfts.xcoral == 0 => 100, - NftColor::Xcoral if self.nfts.xcoral == 1 => 120, - NftColor::Xcoral if self.nfts.xcoral == 2 => 220, - NftColor::Xcoral if self.nfts.xcoral == 3 => 340, - NftColor::Xpurple if self.nfts.xpurple == 0 => 100, - NftColor::Xpurple if self.nfts.xpurple == 1 => 120, - NftColor::Xpurple if self.nfts.xpurple == 2 => 220, - NftColor::Xpurple if self.nfts.xpurple == 3 => 340, - NftColor::Xleafgreen if self.nfts.xleafgreen == 0 => 100, - NftColor::Xleafgreen if self.nfts.xleafgreen == 1 => 120, - NftColor::Xleafgreen if self.nfts.xleafgreen == 2 => 220, - NftColor::Xleafgreen if self.nfts.xleafgreen == 3 => 340, - NftColor::Xgreen if self.nfts.xgreen == 0 => 100, - NftColor::Xgreen if self.nfts.xgreen == 1 => 120, - NftColor::Xgreen if self.nfts.xgreen == 2 => 220, - NftColor::Xgreen if self.nfts.xgreen == 3 => 340, - _ => 0, - } + pub fn sub_nft_color(&mut self, color: NftColor) -> DispatchResult { + match color { + NftColor::Xorange => { + self.xorange = self.xorange.checked_sub(1).ok_or("Arithmetic underflow")?; + Ok(()) + }, + NftColor::Xpink => { + self.xpink = self.xpink.checked_sub(1).ok_or("Arithmetic underflow")?; + Ok(()) + }, + NftColor::Xblue => { + self.xblue = self.xblue.checked_sub(1).ok_or("Arithmetic underflow")?; + Ok(()) + }, + NftColor::Xcyan => { + self.xcyan = self.xcyan.checked_sub(1).ok_or("Arithmetic underflow")?; + Ok(()) + }, + NftColor::Xcoral => { + self.xcoral = self.xcoral.checked_sub(1).ok_or("Arithmetic underflow")?; + Ok(()) + }, + NftColor::Xpurple => { + self.xpurple = self.xpurple.checked_sub(1).ok_or("Arithmetic underflow")?; + Ok(()) + }, + NftColor::Xleafgreen => { + self.xleafgreen = self.xleafgreen.checked_sub(1).ok_or("Arithmetic underflow")?; + Ok(()) + }, + NftColor::Xgreen => { + self.xgreen = self.xgreen.checked_sub(1).ok_or("Arithmetic underflow")?; + Ok(()) + }, } } - #[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))] - #[derive( - Encode, Decode, Clone, PartialEq, Eq, MaxEncodedLen, RuntimeDebug, TypeInfo, Default, - )] - #[scale_info(skip_type_params(T))] - pub struct CollectedColors { - pub xorange: u32, - pub xpink: u32, - pub xblue: u32, - pub xcyan: u32, - pub xcoral: u32, - pub xpurple: u32, - pub xleafgreen: u32, - pub xgreen: u32, + pub fn has_four_of_all_colors(&self) -> bool { + self.xorange >= 4 && + self.xpink >= 4 && + self.xblue >= 4 && + self.xcyan >= 4 && + self.xcoral >= 4 && + self.xpurple >= 4 && + self.xleafgreen >= 4 && + self.xgreen >= 4 } - - impl CollectedColors { - pub fn add_nft_color(&mut self, color: NftColor) -> DispatchResult { - match color { - NftColor::Xorange => { - self.xorange = self.xorange.checked_add(1).ok_or("Arithmetic overflow")?; - Ok(()) - }, - NftColor::Xpink => { - self.xpink = self.xpink.checked_add(1).ok_or("Arithmetic overflow")?; - Ok(()) - }, - NftColor::Xblue => { - self.xblue = self.xblue.checked_add(1).ok_or("Arithmetic overflow")?; - Ok(()) - }, - NftColor::Xcyan => { - self.xcyan = self.xcyan.checked_add(1).ok_or("Arithmetic overflow")?; - Ok(()) - }, - NftColor::Xcoral => { - self.xcoral = self.xcoral.checked_add(1).ok_or("Arithmetic overflow")?; - Ok(()) - }, - NftColor::Xpurple => { - self.xpurple = self.xpurple.checked_add(1).ok_or("Arithmetic overflow")?; - Ok(()) - }, - NftColor::Xleafgreen => { - self.xleafgreen = - self.xleafgreen.checked_add(1).ok_or("Arithmetic overflow")?; - Ok(()) - }, - NftColor::Xgreen => { - self.xgreen = self.xgreen.checked_add(1).ok_or("Arithmetic overflow")?; - Ok(()) - }, - } - } - - pub fn sub_nft_color(&mut self, color: NftColor) -> DispatchResult { - match color { - NftColor::Xorange => { - self.xorange = self.xorange.checked_sub(1).ok_or("Arithmetic underflow")?; - Ok(()) - }, - NftColor::Xpink => { - self.xpink = self.xpink.checked_sub(1).ok_or("Arithmetic underflow")?; - Ok(()) - }, - NftColor::Xblue => { - self.xblue = self.xblue.checked_sub(1).ok_or("Arithmetic underflow")?; - Ok(()) - }, - NftColor::Xcyan => { - self.xcyan = self.xcyan.checked_sub(1).ok_or("Arithmetic underflow")?; - Ok(()) - }, - NftColor::Xcoral => { - self.xcoral = self.xcoral.checked_sub(1).ok_or("Arithmetic underflow")?; - Ok(()) - }, - NftColor::Xpurple => { - self.xpurple = self.xpurple.checked_sub(1).ok_or("Arithmetic underflow")?; - Ok(()) - }, - NftColor::Xleafgreen => { - self.xleafgreen = - self.xleafgreen.checked_sub(1).ok_or("Arithmetic underflow")?; - Ok(()) - }, - NftColor::Xgreen => { - self.xgreen = self.xgreen.checked_sub(1).ok_or("Arithmetic underflow")?; - Ok(()) - }, - } - } - - pub fn has_four_of_all_colors(&self) -> bool { - self.xorange >= 4 && - self.xpink >= 4 && self.xblue >= 4 && - self.xcyan >= 4 && self.xcoral >= 4 && - self.xpurple >= 4 && - self.xleafgreen >= 4 && - self.xgreen >= 4 - } - } \ No newline at end of file +} diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index d61cfc6..d9e90bf 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -52,6 +52,7 @@ serde_json = { version = "1.0.111", default-features = false, features = [ pallet-nfts = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.6.0" } node-primitives = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.6.0" } pallet-insecure-randomness-collective-flip = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.6.0" } +pallet-skip-feeless-payment = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.6.0" } # Used for the node template's RPCs frame-system-rpc-runtime-api = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } @@ -107,6 +108,7 @@ std = [ "pallet-nfts/std", "node-primitives/std", "pallet-insecure-randomness-collective-flip/std", + "pallet-skip-feeless-payment/std", ] runtime-benchmarks = [ "frame-benchmarking/runtime-benchmarks", @@ -120,6 +122,7 @@ runtime-benchmarks = [ "pallet-timestamp/runtime-benchmarks", "sp-runtime/runtime-benchmarks", "pallet-nfts/runtime-benchmarks", + "pallet-skip-feeless-payment/runtime-benchmarks", ] try-runtime = [ "frame-try-runtime/try-runtime", @@ -135,4 +138,5 @@ try-runtime = [ "pallet-transaction-payment/try-runtime", "pallet-nfts/try-runtime", "pallet-insecure-randomness-collective-flip/try-runtime", + "pallet-skip-feeless-payment/try-runtime", ] \ No newline at end of file diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index c5efff4..a4aa2d8 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -340,6 +340,10 @@ impl pallet_nfts::Config for Runtime { impl pallet_insecure_randomness_collective_flip::Config for Runtime {} +impl pallet_skip_feeless_payment::Config for Runtime { + type RuntimeEvent = RuntimeEvent; +} + impl frame_system::offchain::CreateSignedTransaction for Runtime where RuntimeCall: From, @@ -371,7 +375,9 @@ where frame_system::CheckEra::::from(generic::Era::mortal(period, current_block)), frame_system::CheckNonce::::from(nonce), frame_system::CheckWeight::::new(), - pallet_transaction_payment::ChargeTransactionPayment::::from(tip), + pallet_skip_feeless_payment::SkipCheckIfFeeless::from( + pallet_transaction_payment::ChargeTransactionPayment::::from(tip), + ), ); let raw_payload = SignedPayload::new(call, extra) .map_err(|e| { @@ -413,6 +419,7 @@ construct_runtime!( GameModule: pallet_game, Nfts: pallet_nfts, RandomnessCollectiveFlip: pallet_insecure_randomness_collective_flip, + SkipFeelessPayment: pallet_skip_feeless_payment, } ); @@ -431,7 +438,10 @@ pub type SignedExtra = ( frame_system::CheckEra, frame_system::CheckNonce, frame_system::CheckWeight, - pallet_transaction_payment::ChargeTransactionPayment, + pallet_skip_feeless_payment::SkipCheckIfFeeless< + Runtime, + pallet_transaction_payment::ChargeTransactionPayment, + >, ); /// All migrations of the runtime, aside from the ones declared in the pallets. From e458771f9cf06feb00e69e94c0c43415b62eb64a Mon Sep 17 00:00:00 2001 From: Recrafter Date: Wed, 26 Jun 2024 19:54:10 +0700 Subject: [PATCH 08/15] Updating --- pallets/game/src/benchmarking.rs | 78 +++++++++++++--- pallets/game/src/lib.rs | 22 +++-- pallets/game/src/properties.rs | 10 +- pallets/game/src/tests.rs | 44 ++++----- pallets/game/src/weights.rs | 156 ++++++++++++++----------------- runtime/src/lib.rs | 3 +- 6 files changed, 177 insertions(+), 136 deletions(-) diff --git a/pallets/game/src/benchmarking.rs b/pallets/game/src/benchmarking.rs index bcbca53..a1f3188 100644 --- a/pallets/game/src/benchmarking.rs +++ b/pallets/game/src/benchmarking.rs @@ -30,6 +30,13 @@ fn practise_round(caller: T::AccountId, game_id: u32) { 20, game_id )); + assert_ok!(GameModule::::check_result( + RawOrigin::Root.into(), + 20, + game_id, + 20, + "test".as_bytes().to_vec().try_into().unwrap(), + )); } #[benchmarks] @@ -74,7 +81,7 @@ mod benchmarks { assert_eq!(GameModule::::game_info(1).unwrap().player, caller); } - #[benchmark] + #[benchmark] fn submit_answer() { let caller = create_setup::(); current_block::(30u32.into()); @@ -86,6 +93,13 @@ mod benchmarks { #[extrinsic_call] submit_answer(RawOrigin::Signed(caller.clone()), 220000, 1); + assert_ok!(GameModule::::check_result( + RawOrigin::Root.into(), + 220000, + 1, + 220000, + "test".as_bytes().to_vec().try_into().unwrap(), + )); assert_eq!(GameModule::::users::>(caller).unwrap().nfts.xorange, 1); } @@ -103,6 +117,13 @@ mod benchmarks { 220000, 1 )); + assert_ok!(GameModule::::check_result( + RawOrigin::Root.into(), + 220000, + 1, + 220000, + "test".as_bytes().to_vec().try_into().unwrap(), + )); #[extrinsic_call] list_nft(RawOrigin::Signed(caller.clone()), 0.into(), 0.into()); @@ -123,6 +144,13 @@ mod benchmarks { 220000, 1 )); + assert_ok!(GameModule::::check_result( + RawOrigin::Root.into(), + 220000, + 1, + 220000, + "test".as_bytes().to_vec().try_into().unwrap(), + )); assert_ok!(GameModule::::list_nft( RawOrigin::Signed(caller.clone()).into(), 0.into(), @@ -148,6 +176,13 @@ mod benchmarks { 220000, 1 )); + assert_ok!(GameModule::::check_result( + RawOrigin::Root.into(), + 220000, + 1, + 220000, + "test".as_bytes().to_vec().try_into().unwrap(), + )); assert_ok!(GameModule::::list_nft( RawOrigin::Signed(caller.clone()).into(), 0.into(), @@ -169,6 +204,13 @@ mod benchmarks { 220000, 3 )); + assert_ok!(GameModule::::check_result( + RawOrigin::Root.into(), + 220000, + 3, + 220000, + "test".as_bytes().to_vec().try_into().unwrap(), + )); #[extrinsic_call] make_offer(RawOrigin::Signed(caller2.clone()), 0, 0.into(), 1.into()); @@ -189,6 +231,13 @@ mod benchmarks { 220000, 1 )); + assert_ok!(GameModule::::check_result( + RawOrigin::Root.into(), + 220000, + 1, + 220000, + "test".as_bytes().to_vec().try_into().unwrap(), + )); assert_ok!(GameModule::::list_nft( RawOrigin::Signed(caller.clone()).into(), 0.into(), @@ -210,6 +259,13 @@ mod benchmarks { 220000, 3 )); + assert_ok!(GameModule::::check_result( + RawOrigin::Root.into(), + 220000, + 3, + 220000, + "test".as_bytes().to_vec().try_into().unwrap(), + )); assert_eq!( GameModule::::users::>(caller2.clone()).unwrap().nfts.xorange, 1 @@ -232,20 +288,14 @@ mod benchmarks { fn add_property() { assert_ok!(GameModule::::setup_game(RawOrigin::Root.into())); let new_property = PropertyInfoData { - id: 147229391, - bedrooms: 2, - bathrooms: 1, - summary: "Superb 2 double bedroom ground floor purpose-built apartment with sole use of garden. Directly opposite Hackney Downs Park, within walking distance of Clapton, Hackney Downs & Rectory Rd Stations. Benefitting from; 2 double bedrooms, fitted kitchen/diner, modern shower/WC, separate lounge with di...".as_bytes().to_vec().try_into().unwrap(), - property_sub_type: "Flat".as_bytes().to_vec().try_into().unwrap(), - first_visible_date: "2024-04-24T16:39:27Z".as_bytes().to_vec().try_into().unwrap(), - display_size: "".as_bytes().to_vec().try_into().unwrap(), - display_address: "St Peters Street, Islington".as_bytes().to_vec().try_into().unwrap(), - property_images1: "https://media.rightmove.co.uk/dir/crop/10:9-16:9/56k/55489/146480642/55489_2291824_IMG_00_0000_max_476x317.jpeg".as_bytes().to_vec().try_into().unwrap(), - }; + id: 147031382, + data: "nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap(), + price: "kkjfkdjdkdjdkdjdk".as_bytes().to_vec().try_into().unwrap(), + }; #[extrinsic_call] - add_property(RawOrigin::Root, new_property, 200000); + add_property(RawOrigin::Root, new_property); - assert_eq!(GameModule::::test_properties().len(), 5); + assert_eq!(GameModule::::game_properties().len(), 5); } #[benchmark] @@ -254,7 +304,7 @@ mod benchmarks { #[extrinsic_call] remove_property(RawOrigin::Root, 146480642); - assert_eq!(GameModule::::test_properties().len(), 3); + assert_eq!(GameModule::::game_properties().len(), 3); } #[benchmark] diff --git a/pallets/game/src/lib.rs b/pallets/game/src/lib.rs index 10ba833..aab507d 100644 --- a/pallets/game/src/lib.rs +++ b/pallets/game/src/lib.rs @@ -205,8 +205,8 @@ pub mod pallet { /// A List of test properties #[pallet::storage] - #[pallet::getter(fn test_properties)] - pub type TestProperties = + #[pallet::getter(fn game_properties)] + pub type GameProperties = StorageValue<_, BoundedVec, T::MaxProperty>, ValueQuery>; /// Vector of admins who can register users. @@ -314,6 +314,8 @@ pub mod pallet { if let Some(game_info) = game_info { if game_info.guess.is_none() { let _ = Self::no_answer_result(game_info); + } else { + GameInfo::::insert(index, game_info); } } }); @@ -357,7 +359,7 @@ pub mod pallet { let color = NftColor::from_index(x).ok_or(Error::::InvalidIndex)?; CollectionColor::::insert(collection_id, color); } - Self::create_test_properties()?; + Self::create_game_properties()?; let mut round = Self::current_round(); round = round.checked_add(1).ok_or(Error::::ArithmeticOverflow)?; CurrentRound::::put(round); @@ -495,13 +497,13 @@ pub mod pallet { let u32_value = u32::from_le_bytes( hashi.as_ref()[4..8].try_into().map_err(|_| Error::::ConversionError)?, ); - let random_number = u32_value as usize % Self::test_properties().len(); - let property = Self::test_properties()[random_number].clone(); + let random_number = u32_value as usize % Self::game_properties().len(); + let property = Self::game_properties()[random_number].clone(); let game_datas = GameData { difficulty: game_type, player: signer.clone(), property, guess: None }; - let mut properties = TestProperties::::take(); + let mut properties = GameProperties::::take(); properties.retain(|property| property.id as usize != random_number); - TestProperties::::put(properties); + GameProperties::::put(properties); GameInfo::::insert(game_id, game_datas); let next_game_id = game_id.checked_add(1).ok_or(Error::::ArithmeticOverflow)?; GameId::::put(next_game_id); @@ -817,7 +819,7 @@ pub mod pallet { #[pallet::weight(::WeightInfo::add_property())] pub fn add_property(origin: OriginFor, property: PropertyInfoData) -> DispatchResult { T::GameOrigin::ensure_origin(origin)?; - TestProperties::::try_append(property.clone()) + GameProperties::::try_append(property.clone()) .map_err(|_| Error::::TooManyTest)?; Ok(()) } @@ -832,9 +834,9 @@ pub mod pallet { #[pallet::weight(::WeightInfo::remove_property())] pub fn remove_property(origin: OriginFor, id: u32) -> DispatchResult { T::GameOrigin::ensure_origin(origin)?; - let mut properties = TestProperties::::take(); + let mut properties = GameProperties::::take(); properties.retain(|property| property.id != id); - TestProperties::::put(properties); + GameProperties::::put(properties); Ok(()) } diff --git a/pallets/game/src/properties.rs b/pallets/game/src/properties.rs index 35c2df5..eedf82f 100644 --- a/pallets/game/src/properties.rs +++ b/pallets/game/src/properties.rs @@ -2,34 +2,34 @@ use crate::*; use frame_support::pallet_prelude::*; impl Pallet { - pub(crate) fn create_test_properties() -> DispatchResult { + pub(crate) fn create_game_properties() -> DispatchResult { let new_property = PropertyInfoData { id: 147229391, data: "nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap(), price: "kkjfkdjdkdjdkdjdk".as_bytes().to_vec().try_into().unwrap(), }; - TestProperties::::try_append(new_property.clone()) + GameProperties::::try_append(new_property.clone()) .map_err(|_| Error::::TooManyTest)?; let new_property = PropertyInfoData { id: 146480642, data: "nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap(), price: "kkjfkdjdkdjdkdjdk".as_bytes().to_vec().try_into().unwrap(), }; - TestProperties::::try_append(new_property.clone()) + GameProperties::::try_append(new_property.clone()) .map_err(|_| Error::::TooManyTest)?; let new_property = PropertyInfoData { id: 147031382, data: "nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap(), price: "kkjfkdjdkdjdkdjdk".as_bytes().to_vec().try_into().unwrap(), }; - TestProperties::::try_append(new_property.clone()) + GameProperties::::try_append(new_property.clone()) .map_err(|_| Error::::TooManyTest)?; let new_property = PropertyInfoData { id: 147031382, data: "nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap(), price: "kkjfkdjdkdjdkdjdk".as_bytes().to_vec().try_into().unwrap(), }; - TestProperties::::try_append(new_property.clone()) + GameProperties::::try_append(new_property.clone()) .map_err(|_| Error::::TooManyTest)?; Ok(()) } diff --git a/pallets/game/src/tests.rs b/pallets/game/src/tests.rs index 6150676..5e4f29e 100644 --- a/pallets/game/src/tests.rs +++ b/pallets/game/src/tests.rs @@ -93,7 +93,7 @@ fn play_game_works() { new_test_ext().execute_with(|| { System::set_block_number(1); assert_ok!(GameModule::setup_game(RuntimeOrigin::root())); - assert_eq!(GameModule::test_properties().len(), 4); + assert_eq!(GameModule::game_properties().len(), 4); assert_ok!(GameModule::add_to_admins(RuntimeOrigin::root(), [4; 32].into())); assert_ok!(GameModule::register_user( RuntimeOrigin::signed([4; 32].into()), @@ -115,7 +115,7 @@ fn play_game_fails() { new_test_ext().execute_with(|| { System::set_block_number(1); assert_ok!(GameModule::setup_game(RuntimeOrigin::root())); - assert_eq!(GameModule::test_properties().len(), 4); + assert_eq!(GameModule::game_properties().len(), 4); assert_noop!( GameModule::play_game( RuntimeOrigin::signed([0; 32].into()), @@ -150,7 +150,7 @@ fn play_game_fails_not_enough_points() { new_test_ext().execute_with(|| { System::set_block_number(1); assert_ok!(GameModule::setup_game(RuntimeOrigin::root())); - assert_eq!(GameModule::test_properties().len(), 4); + assert_eq!(GameModule::game_properties().len(), 4); assert_ok!(GameModule::add_to_admins(RuntimeOrigin::root(), [4; 32].into())); assert_ok!(GameModule::register_user( RuntimeOrigin::signed([4; 32].into()), @@ -174,7 +174,7 @@ fn submit_answer_works() { new_test_ext().execute_with(|| { System::set_block_number(1); assert_ok!(GameModule::setup_game(RuntimeOrigin::root())); - assert_eq!(GameModule::test_properties().len(), 4); + assert_eq!(GameModule::game_properties().len(), 4); assert_ok!(GameModule::add_to_admins(RuntimeOrigin::root(), [4; 32].into())); assert_ok!(GameModule::register_user( RuntimeOrigin::signed([4; 32].into()), @@ -225,7 +225,7 @@ fn leaderboard_works() { new_test_ext().execute_with(|| { System::set_block_number(1); assert_ok!(GameModule::setup_game(RuntimeOrigin::root())); - assert_eq!(GameModule::test_properties().len(), 4); + assert_eq!(GameModule::game_properties().len(), 4); assert_ok!(GameModule::add_to_admins(RuntimeOrigin::root(), [4; 32].into())); assert_ok!(GameModule::register_user( RuntimeOrigin::signed([4; 32].into()), @@ -303,7 +303,7 @@ fn submit_answer_fails() { new_test_ext().execute_with(|| { System::set_block_number(1); assert_ok!(GameModule::setup_game(RuntimeOrigin::root())); - assert_eq!(GameModule::test_properties().len(), 4); + assert_eq!(GameModule::game_properties().len(), 4); assert_noop!( GameModule::submit_answer(RuntimeOrigin::signed([0; 32].into()), 223_000, 0), Error::::NoActiveGame @@ -316,7 +316,7 @@ fn transfer_of_nft_does_not_work() { new_test_ext().execute_with(|| { System::set_block_number(1); assert_ok!(GameModule::setup_game(RuntimeOrigin::root())); - assert_eq!(GameModule::test_properties().len(), 4); + assert_eq!(GameModule::game_properties().len(), 4); assert_ok!(GameModule::add_to_admins(RuntimeOrigin::root(), [4; 32].into())); assert_ok!(GameModule::register_user( RuntimeOrigin::signed([4; 32].into()), @@ -362,7 +362,7 @@ fn list_nft_works() { new_test_ext().execute_with(|| { System::set_block_number(1); assert_ok!(GameModule::setup_game(RuntimeOrigin::root())); - assert_eq!(GameModule::test_properties().len(), 4); + assert_eq!(GameModule::game_properties().len(), 4); assert_ok!(GameModule::add_to_admins(RuntimeOrigin::root(), [4; 32].into())); assert_ok!(GameModule::register_user( RuntimeOrigin::signed([4; 32].into()), @@ -398,7 +398,7 @@ fn list_nft_doesnt_work() { new_test_ext().execute_with(|| { System::set_block_number(1); assert_ok!(GameModule::setup_game(RuntimeOrigin::root())); - assert_eq!(GameModule::test_properties().len(), 4); + assert_eq!(GameModule::game_properties().len(), 4); assert_ok!(GameModule::add_to_admins(RuntimeOrigin::root(), [4; 32].into())); assert_ok!(GameModule::register_user( RuntimeOrigin::signed([4; 32].into()), @@ -435,7 +435,7 @@ fn delist_nft_works() { new_test_ext().execute_with(|| { System::set_block_number(1); assert_ok!(GameModule::setup_game(RuntimeOrigin::root())); - assert_eq!(GameModule::test_properties().len(), 4); + assert_eq!(GameModule::game_properties().len(), 4); assert_ok!(GameModule::add_to_admins(RuntimeOrigin::root(), [4; 32].into())); assert_ok!(GameModule::register_user( RuntimeOrigin::signed([4; 32].into()), @@ -485,7 +485,7 @@ fn delist_nft_doesnt_works() { new_test_ext().execute_with(|| { System::set_block_number(1); assert_ok!(GameModule::setup_game(RuntimeOrigin::root())); - assert_eq!(GameModule::test_properties().len(), 4); + assert_eq!(GameModule::game_properties().len(), 4); assert_ok!(GameModule::add_to_admins(RuntimeOrigin::root(), [4; 32].into())); assert_ok!(GameModule::register_user( RuntimeOrigin::signed([4; 32].into()), @@ -525,7 +525,7 @@ fn make_offer_works() { new_test_ext().execute_with(|| { System::set_block_number(1); assert_ok!(GameModule::setup_game(RuntimeOrigin::root())); - assert_eq!(GameModule::test_properties().len(), 4); + assert_eq!(GameModule::game_properties().len(), 4); assert_ok!(GameModule::add_to_admins(RuntimeOrigin::root(), [4; 32].into())); assert_ok!(GameModule::register_user( RuntimeOrigin::signed([4; 32].into()), @@ -584,7 +584,7 @@ fn make_offer_doesnt_works() { new_test_ext().execute_with(|| { System::set_block_number(1); assert_ok!(GameModule::setup_game(RuntimeOrigin::root())); - assert_eq!(GameModule::test_properties().len(), 4); + assert_eq!(GameModule::game_properties().len(), 4); assert_ok!(GameModule::add_to_admins(RuntimeOrigin::root(), [4; 32].into())); assert_ok!(GameModule::register_user( RuntimeOrigin::signed([4; 32].into()), @@ -609,7 +609,7 @@ fn withdraw_offer_works() { new_test_ext().execute_with(|| { System::set_block_number(1); assert_ok!(GameModule::setup_game(RuntimeOrigin::root())); - assert_eq!(GameModule::test_properties().len(), 4); + assert_eq!(GameModule::game_properties().len(), 4); assert_ok!(GameModule::add_to_admins(RuntimeOrigin::root(), [4; 32].into())); assert_ok!(GameModule::register_user( RuntimeOrigin::signed([4; 32].into()), @@ -670,7 +670,7 @@ fn withdraw_offer_fails() { new_test_ext().execute_with(|| { System::set_block_number(1); assert_ok!(GameModule::setup_game(RuntimeOrigin::root())); - assert_eq!(GameModule::test_properties().len(), 4); + assert_eq!(GameModule::game_properties().len(), 4); assert_ok!(GameModule::add_to_admins(RuntimeOrigin::root(), [4; 32].into())); assert_ok!(GameModule::register_user( RuntimeOrigin::signed([4; 32].into()), @@ -737,7 +737,7 @@ fn handle_offer_accept_works() { new_test_ext().execute_with(|| { System::set_block_number(1); assert_ok!(GameModule::setup_game(RuntimeOrigin::root())); - assert_eq!(GameModule::test_properties().len(), 4); + assert_eq!(GameModule::game_properties().len(), 4); assert_ok!(GameModule::add_to_admins(RuntimeOrigin::root(), [4; 32].into())); assert_ok!(GameModule::register_user( RuntimeOrigin::signed([4; 32].into()), @@ -869,7 +869,7 @@ fn handle_offer_reject_works() { new_test_ext().execute_with(|| { System::set_block_number(1); assert_ok!(GameModule::setup_game(RuntimeOrigin::root())); - assert_eq!(GameModule::test_properties().len(), 4); + assert_eq!(GameModule::game_properties().len(), 4); assert_ok!(GameModule::add_to_admins(RuntimeOrigin::root(), [4; 32].into())); assert_ok!(GameModule::register_user( RuntimeOrigin::signed([4; 32].into()), @@ -949,7 +949,7 @@ fn handle_offer_doesnt_works() { new_test_ext().execute_with(|| { System::set_block_number(1); assert_ok!(GameModule::setup_game(RuntimeOrigin::root())); - assert_eq!(GameModule::test_properties().len(), 4); + assert_eq!(GameModule::game_properties().len(), 4); assert_ok!(GameModule::add_to_admins(RuntimeOrigin::root(), [4; 32].into())); assert_ok!(GameModule::register_user( RuntimeOrigin::signed([4; 32].into()), @@ -1014,7 +1014,7 @@ fn play_multiple_rounds_works() { new_test_ext().execute_with(|| { System::set_block_number(1); assert_ok!(GameModule::setup_game(RuntimeOrigin::root())); - assert_eq!(GameModule::test_properties().len(), 4); + assert_eq!(GameModule::game_properties().len(), 4); assert_ok!(GameModule::add_to_admins(RuntimeOrigin::root(), [4; 32].into())); assert_ok!(GameModule::register_user( RuntimeOrigin::signed([4; 32].into()), @@ -1063,7 +1063,7 @@ fn add_property_works() { price: "kkjfkdjdkdjdkdjdk".as_bytes().to_vec().try_into().unwrap(), }; assert_ok!(GameModule::add_property(RuntimeOrigin::root(), new_property)); - assert_eq!(GameModule::test_properties().len(), 5); + assert_eq!(GameModule::game_properties().len(), 5); }); } @@ -1073,7 +1073,7 @@ fn remove_property_works() { System::set_block_number(1); assert_ok!(GameModule::setup_game(RuntimeOrigin::root())); assert_ok!(GameModule::remove_property(RuntimeOrigin::root(), 146480642)); - assert_eq!(GameModule::test_properties().len(), 3); + assert_eq!(GameModule::game_properties().len(), 3); }); } @@ -1119,7 +1119,7 @@ fn check_result_fails() { new_test_ext().execute_with(|| { System::set_block_number(1); assert_ok!(GameModule::setup_game(RuntimeOrigin::root())); - assert_eq!(GameModule::test_properties().len(), 4); + assert_eq!(GameModule::game_properties().len(), 4); assert_ok!(GameModule::add_to_admins(RuntimeOrigin::root(), [4; 32].into())); assert_ok!(GameModule::register_user( RuntimeOrigin::signed([4; 32].into()), diff --git a/pallets/game/src/weights.rs b/pallets/game/src/weights.rs index 5fbe9a4..bd51d3e 100644 --- a/pallets/game/src/weights.rs +++ b/pallets/game/src/weights.rs @@ -2,9 +2,9 @@ //! Autogenerated weights for `pallet_game` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2024-05-10, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2024-06-26, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` -//! HOSTNAME: `LAPTOP-DFFNONK6`, CPU: `11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz` +//! HOSTNAME: `recrafter-Legion-5-16IRX9`, CPU: `Intel(R) Core(TM) i7-14650HX` //! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: 1024 // Executed Command: @@ -59,16 +59,14 @@ impl WeightInfo for SubstrateWeight { /// Proof: `Nfts::Collection` (`max_values`: None, `max_size`: Some(84), added: 2559, mode: `MaxEncodedLen`) /// Storage: `System::Account` (r:1 w:1) /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) - /// Storage: `GameModule::TestProperties` (r:1 w:1) - /// Proof: `GameModule::TestProperties` (`max_values`: Some(1), `max_size`: Some(3002402), added: 3002897, mode: `MaxEncodedLen`) + /// Storage: `GameModule::GameProperties` (r:1 w:1) + /// Proof: `GameModule::GameProperties` (`max_values`: Some(1), `max_size`: Some(100802), added: 101297, mode: `MaxEncodedLen`) /// Storage: `GameModule::CurrentRound` (r:1 w:1) /// Proof: `GameModule::CurrentRound` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) /// Storage: `GameModule::RoundActive` (r:0 w:1) /// Proof: `GameModule::RoundActive` (`max_values`: Some(1), `max_size`: Some(1), added: 496, mode: `MaxEncodedLen`) /// Storage: `GameModule::CollectionColor` (r:0 w:8) /// Proof: `GameModule::CollectionColor` (`max_values`: None, `max_size`: Some(21), added: 2496, mode: `MaxEncodedLen`) - /// Storage: `GameModule::TestPrices` (r:0 w:3) - /// Proof: `GameModule::TestPrices` (`max_values`: None, `max_size`: Some(24), added: 2499, mode: `MaxEncodedLen`) /// Storage: `Nfts::CollectionRoleOf` (r:0 w:8) /// Proof: `Nfts::CollectionRoleOf` (`max_values`: None, `max_size`: Some(69), added: 2544, mode: `MaxEncodedLen`) /// Storage: `Nfts::CollectionConfigOf` (r:0 w:8) @@ -78,37 +76,37 @@ impl WeightInfo for SubstrateWeight { fn setup_game() -> Weight { // Proof Size summary in bytes: // Measured: `166` - // Estimated: `3003887` - // Minimum execution time: 217_169_000 picoseconds. - Weight::from_parts(248_356_000, 0) - .saturating_add(Weight::from_parts(0, 3003887)) + // Estimated: `102287` + // Minimum execution time: 194_288_000 picoseconds. + Weight::from_parts(200_222_000, 0) + .saturating_add(Weight::from_parts(0, 102287)) .saturating_add(T::DbWeight::get().reads(12)) - .saturating_add(T::DbWeight::get().writes(48)) + .saturating_add(T::DbWeight::get().writes(45)) } /// Storage: `GameModule::Admins` (r:1 w:0) /// Proof: `GameModule::Admins` (`max_values`: Some(1), `max_size`: Some(321), added: 816, mode: `MaxEncodedLen`) /// Storage: `GameModule::Users` (r:1 w:1) /// Proof: `GameModule::Users` (`max_values`: None, `max_size`: Some(101), added: 2576, mode: `MaxEncodedLen`) - /// Storage: `System::Account` (r:1 w:0) + /// Storage: `System::Account` (r:1 w:1) /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) fn register_user() -> Weight { // Proof Size summary in bytes: - // Measured: `187` + // Measured: `159` // Estimated: `3593` - // Minimum execution time: 19_511_000 picoseconds. - Weight::from_parts(21_802_000, 0) + // Minimum execution time: 23_342_000 picoseconds. + Weight::from_parts(25_000_000, 0) .saturating_add(Weight::from_parts(0, 3593)) .saturating_add(T::DbWeight::get().reads(3)) - .saturating_add(T::DbWeight::get().writes(1)) + .saturating_add(T::DbWeight::get().writes(2)) } /// Storage: `GameModule::Users` (r:1 w:1) /// Proof: `GameModule::Users` (`max_values`: None, `max_size`: Some(101), added: 2576, mode: `MaxEncodedLen`) fn give_points() -> Weight { // Proof Size summary in bytes: - // Measured: `290` + // Measured: `224` // Estimated: `3566` - // Minimum execution time: 13_864_000 picoseconds. - Weight::from_parts(20_611_000, 0) + // Minimum execution time: 13_887_000 picoseconds. + Weight::from_parts(14_389_000, 0) .saturating_add(Weight::from_parts(0, 3566)) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)) @@ -125,37 +123,31 @@ impl WeightInfo for SubstrateWeight { /// Proof: `GameModule::GamesExpiring` (`max_values`: None, `max_size`: Some(822), added: 3297, mode: `MaxEncodedLen`) /// Storage: `RandomnessCollectiveFlip::RandomMaterial` (r:1 w:0) /// Proof: `RandomnessCollectiveFlip::RandomMaterial` (`max_values`: Some(1), `max_size`: Some(2594), added: 3089, mode: `MaxEncodedLen`) - /// Storage: `GameModule::TestProperties` (r:1 w:0) - /// Proof: `GameModule::TestProperties` (`max_values`: Some(1), `max_size`: Some(3002402), added: 3002897, mode: `MaxEncodedLen`) + /// Storage: `GameModule::GameProperties` (r:1 w:1) + /// Proof: `GameModule::GameProperties` (`max_values`: Some(1), `max_size`: Some(100802), added: 101297, mode: `MaxEncodedLen`) /// Storage: `GameModule::GameInfo` (r:0 w:1) - /// Proof: `GameModule::GameInfo` (`max_values`: None, `max_size`: Some(30077), added: 32552, mode: `MaxEncodedLen`) + /// Proof: `GameModule::GameInfo` (`max_values`: None, `max_size`: Some(1066), added: 3541, mode: `MaxEncodedLen`) fn play_game() -> Weight { // Proof Size summary in bytes: - // Measured: `1966` - // Estimated: `3003887` - // Minimum execution time: 41_464_000 picoseconds. - Weight::from_parts(46_440_000, 0) - .saturating_add(Weight::from_parts(0, 3003887)) + // Measured: `616` + // Estimated: `102287` + // Minimum execution time: 36_774_000 picoseconds. + Weight::from_parts(38_151_000, 0) + .saturating_add(Weight::from_parts(0, 102287)) .saturating_add(T::DbWeight::get().reads(7)) - .saturating_add(T::DbWeight::get().writes(3)) + .saturating_add(T::DbWeight::get().writes(4)) } /// Storage: `GameModule::GameInfo` (r:1 w:1) - /// Proof: `GameModule::GameInfo` (`max_values`: None, `max_size`: Some(30077), added: 32552, mode: `MaxEncodedLen`) - /// Storage: `GameModule::TestPrices` (r:1 w:0) - /// Proof: `GameModule::TestPrices` (`max_values`: None, `max_size`: Some(24), added: 2499, mode: `MaxEncodedLen`) - /// Storage: `GameModule::Users` (r:1 w:1) - /// Proof: `GameModule::Users` (`max_values`: None, `max_size`: Some(101), added: 2576, mode: `MaxEncodedLen`) - /// Storage: `GameModule::Leaderboard` (r:1 w:1) - /// Proof: `GameModule::Leaderboard` (`max_values`: Some(1), `max_size`: Some(361), added: 856, mode: `MaxEncodedLen`) + /// Proof: `GameModule::GameInfo` (`max_values`: None, `max_size`: Some(1066), added: 3541, mode: `MaxEncodedLen`) fn submit_answer() -> Weight { // Proof Size summary in bytes: - // Measured: `1014` - // Estimated: `33542` - // Minimum execution time: 34_340_000 picoseconds. - Weight::from_parts(36_929_000, 0) - .saturating_add(Weight::from_parts(0, 33542)) - .saturating_add(T::DbWeight::get().reads(4)) - .saturating_add(T::DbWeight::get().writes(3)) + // Measured: `359` + // Estimated: `4531` + // Minimum execution time: 14_246_000 picoseconds. + Weight::from_parts(14_937_000, 0) + .saturating_add(Weight::from_parts(0, 4531)) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)) } /// Storage: `Nfts::Item` (r:1 w:1) /// Proof: `Nfts::Item` (`max_values`: None, `max_size`: Some(861), added: 3336, mode: `MaxEncodedLen`) @@ -181,10 +173,10 @@ impl WeightInfo for SubstrateWeight { /// Proof: `Nfts::PendingSwapOf` (`max_values`: None, `max_size`: Some(71), added: 2546, mode: `MaxEncodedLen`) fn list_nft() -> Weight { // Proof Size summary in bytes: - // Measured: `1379` + // Measured: `1336` // Estimated: `4326` - // Minimum execution time: 80_220_000 picoseconds. - Weight::from_parts(88_509_000, 0) + // Minimum execution time: 72_547_000 picoseconds. + Weight::from_parts(76_222_000, 0) .saturating_add(Weight::from_parts(0, 4326)) .saturating_add(T::DbWeight::get().reads(7)) .saturating_add(T::DbWeight::get().writes(8)) @@ -211,10 +203,10 @@ impl WeightInfo for SubstrateWeight { /// Proof: `Nfts::PendingSwapOf` (`max_values`: None, `max_size`: Some(71), added: 2546, mode: `MaxEncodedLen`) fn delist_nft() -> Weight { // Proof Size summary in bytes: - // Measured: `1476` + // Measured: `1433` // Estimated: `4326` - // Minimum execution time: 73_031_000 picoseconds. - Weight::from_parts(80_820_000, 0) + // Minimum execution time: 67_805_000 picoseconds. + Weight::from_parts(70_396_000, 0) .saturating_add(Weight::from_parts(0, 4326)) .saturating_add(T::DbWeight::get().reads(7)) .saturating_add(T::DbWeight::get().writes(7)) @@ -245,10 +237,10 @@ impl WeightInfo for SubstrateWeight { /// Proof: `Nfts::PendingSwapOf` (`max_values`: None, `max_size`: Some(71), added: 2546, mode: `MaxEncodedLen`) fn make_offer() -> Weight { // Proof Size summary in bytes: - // Measured: `1550` + // Measured: `1507` // Estimated: `4326` - // Minimum execution time: 80_820_000 picoseconds. - Weight::from_parts(88_066_000, 0) + // Minimum execution time: 74_122_000 picoseconds. + Weight::from_parts(78_309_000, 0) .saturating_add(Weight::from_parts(0, 4326)) .saturating_add(T::DbWeight::get().reads(8)) .saturating_add(T::DbWeight::get().writes(8)) @@ -283,50 +275,46 @@ impl WeightInfo for SubstrateWeight { /// Proof: `Nfts::PendingSwapOf` (`max_values`: None, `max_size`: Some(71), added: 2546, mode: `MaxEncodedLen`) fn handle_offer() -> Weight { // Proof Size summary in bytes: - // Measured: `2178` + // Measured: `2135` // Estimated: `7662` - // Minimum execution time: 154_210_000 picoseconds. - Weight::from_parts(166_048_000, 0) + // Minimum execution time: 142_320_000 picoseconds. + Weight::from_parts(147_285_000, 0) .saturating_add(Weight::from_parts(0, 7662)) .saturating_add(T::DbWeight::get().reads(15)) .saturating_add(T::DbWeight::get().writes(17)) } - /// Storage: `GameModule::TestProperties` (r:1 w:1) - /// Proof: `GameModule::TestProperties` (`max_values`: Some(1), `max_size`: Some(3002402), added: 3002897, mode: `MaxEncodedLen`) - /// Storage: `GameModule::TestPrices` (r:0 w:1) - /// Proof: `GameModule::TestPrices` (`max_values`: None, `max_size`: Some(24), added: 2499, mode: `MaxEncodedLen`) + /// Storage: `GameModule::GameProperties` (r:1 w:1) + /// Proof: `GameModule::GameProperties` (`max_values`: Some(1), `max_size`: Some(100802), added: 101297, mode: `MaxEncodedLen`) fn add_property() -> Weight { // Proof Size summary in bytes: - // Measured: `1670` - // Estimated: `3003887` - // Minimum execution time: 11_789_000 picoseconds. - Weight::from_parts(15_564_000, 0) - .saturating_add(Weight::from_parts(0, 3003887)) + // Measured: `318` + // Estimated: `102287` + // Minimum execution time: 7_875_000 picoseconds. + Weight::from_parts(8_632_000, 0) + .saturating_add(Weight::from_parts(0, 102287)) .saturating_add(T::DbWeight::get().reads(1)) - .saturating_add(T::DbWeight::get().writes(2)) + .saturating_add(T::DbWeight::get().writes(1)) } - /// Storage: `GameModule::TestProperties` (r:1 w:1) - /// Proof: `GameModule::TestProperties` (`max_values`: Some(1), `max_size`: Some(3002402), added: 3002897, mode: `MaxEncodedLen`) - /// Storage: `GameModule::TestPrices` (r:1 w:1) - /// Proof: `GameModule::TestPrices` (`max_values`: None, `max_size`: Some(24), added: 2499, mode: `MaxEncodedLen`) + /// Storage: `GameModule::GameProperties` (r:1 w:1) + /// Proof: `GameModule::GameProperties` (`max_values`: Some(1), `max_size`: Some(100802), added: 101297, mode: `MaxEncodedLen`) fn remove_property() -> Weight { // Proof Size summary in bytes: - // Measured: `1740` - // Estimated: `3003887` - // Minimum execution time: 18_385_000 picoseconds. - Weight::from_parts(20_622_000, 0) - .saturating_add(Weight::from_parts(0, 3003887)) - .saturating_add(T::DbWeight::get().reads(2)) - .saturating_add(T::DbWeight::get().writes(2)) + // Measured: `318` + // Estimated: `102287` + // Minimum execution time: 8_871_000 picoseconds. + Weight::from_parts(9_508_000, 0) + .saturating_add(Weight::from_parts(0, 102287)) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)) } /// Storage: `GameModule::Admins` (r:1 w:1) /// Proof: `GameModule::Admins` (`max_values`: Some(1), `max_size`: Some(321), added: 816, mode: `MaxEncodedLen`) fn add_to_admins() -> Weight { // Proof Size summary in bytes: - // Measured: `132` + // Measured: `118` // Estimated: `1806` - // Minimum execution time: 10_448_000 picoseconds. - Weight::from_parts(12_934_000, 0) + // Minimum execution time: 9_738_000 picoseconds. + Weight::from_parts(10_432_000, 0) .saturating_add(Weight::from_parts(0, 1806)) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)) @@ -335,10 +323,10 @@ impl WeightInfo for SubstrateWeight { /// Proof: `GameModule::Admins` (`max_values`: Some(1), `max_size`: Some(321), added: 816, mode: `MaxEncodedLen`) fn remove_from_admins() -> Weight { // Proof Size summary in bytes: - // Measured: `187` + // Measured: `159` // Estimated: `1806` - // Minimum execution time: 11_069_000 picoseconds. - Weight::from_parts(14_432_000, 0) + // Minimum execution time: 11_026_000 picoseconds. + Weight::from_parts(11_756_000, 0) .saturating_add(Weight::from_parts(0, 1806)) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)) @@ -347,10 +335,10 @@ impl WeightInfo for SubstrateWeight { /// Proof: `GameModule::Users` (`max_values`: None, `max_size`: Some(101), added: 2576, mode: `MaxEncodedLen`) fn request_token() -> Weight { // Proof Size summary in bytes: - // Measured: `290` + // Measured: `224` // Estimated: `3566` - // Minimum execution time: 41_262_000 picoseconds. - Weight::from_parts(53_983_000, 0) + // Minimum execution time: 34_106_000 picoseconds. + Weight::from_parts(39_606_000, 0) .saturating_add(Weight::from_parts(0, 3566)) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)) diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index a4aa2d8..54c6fc0 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -270,6 +270,7 @@ parameter_types! { pub const LeaderLimit: u32 = 10; pub const MaxAdmin: u32 = 10; pub const RequestLimits: BlockNumber = 100800; + pub const GameStringLimit: u32 = 500; } /// Configure the pallet-game in pallets/game. @@ -284,7 +285,7 @@ impl pallet_game::Config for Runtime { type PalletId = GamePalletId; type MaxOngoingGames = MaxOngoingGame; type GameRandomness = RandomnessCollectiveFlip; - type StringLimit = StringLimit; + type StringLimit = GameStringLimit; type LeaderboardLimit = LeaderLimit; type MaxAdmins = MaxAdmin; type RequestLimit = RequestLimits; From bf924235f4606d3e111db18029eeb2c2042d5ea6 Mon Sep 17 00:00:00 2001 From: Recrafter Date: Thu, 27 Jun 2024 10:57:04 +0700 Subject: [PATCH 09/15] Refactoring and adding benchmark --- pallets/game/src/benchmarking.rs | 22 +++++++- pallets/game/src/functions.rs | 4 +- pallets/game/src/lib.rs | 58 ++++++++++--------- pallets/game/src/tests.rs | 6 +- pallets/game/src/weights.rs | 95 ++++++++++++++++++++++---------- 5 files changed, 120 insertions(+), 65 deletions(-) diff --git a/pallets/game/src/benchmarking.rs b/pallets/game/src/benchmarking.rs index a1f3188..9586a28 100644 --- a/pallets/game/src/benchmarking.rs +++ b/pallets/game/src/benchmarking.rs @@ -65,7 +65,7 @@ mod benchmarks { fn give_points() { let caller = create_setup::(); #[extrinsic_call] - give_points(RawOrigin::Root, caller.clone()); + give_points(RawOrigin::Root, caller.clone(), 100); assert_eq!(GameModule::::users(caller).unwrap().points, 150); } @@ -103,6 +103,26 @@ mod benchmarks { assert_eq!(GameModule::::users::>(caller).unwrap().nfts.xorange, 1); } + #[benchmark] + fn check_result() { + let caller = create_setup::(); + current_block::(30u32.into()); + practise_round::(caller.clone(), 0); + assert_ok!(GameModule::::play_game( + RawOrigin::Signed(caller.clone()).into(), + crate::DifficultyLevel::Player + )); + assert_ok!(GameModule::::submit_answer( + RawOrigin::Signed(caller.clone()).into(), + 220000, + 1 + )); + #[extrinsic_call] + check_result(RawOrigin::Root, 220000, 1, 220000, "test".as_bytes().to_vec().try_into().unwrap()); + + assert_eq!(GameModule::::users::>(caller).unwrap().nfts.xorange, 1); + } + #[benchmark] fn list_nft() { let caller = create_setup::(); diff --git a/pallets/game/src/functions.rs b/pallets/game/src/functions.rs index ff94b31..9332597 100644 --- a/pallets/game/src/functions.rs +++ b/pallets/game/src/functions.rs @@ -63,7 +63,7 @@ impl Pallet { ) .ok_or(Error::::ArithmeticOverflow)?; let collection_id: ::CollectionId = random_number.into(); - let next_item_id = Self::next_color_id(collection_id); + let next_item_id = NextColorId::::get(collection_id); let item_id: ItemId = next_item_id.into(); let next_item_id = next_item_id.checked_add(1).ok_or(Error::::ArithmeticOverflow)?; @@ -167,7 +167,7 @@ impl Pallet { ) .ok_or(Error::::ArithmeticOverflow)?; let collection_id: ::CollectionId = random_number.into(); - let next_item_id = Self::next_color_id(collection_id); + let next_item_id = NextColorId::::get(collection_id); let item_id: ItemId = next_item_id.into(); let next_item_id = next_item_id.checked_add(1).ok_or(Error::::ArithmeticOverflow)?; diff --git a/pallets/game/src/lib.rs b/pallets/game/src/lib.rs index aab507d..52f50a5 100644 --- a/pallets/game/src/lib.rs +++ b/pallets/game/src/lib.rs @@ -127,7 +127,6 @@ pub mod pallet { /// The next item id in a collection. #[pallet::storage] - #[pallet::getter(fn next_color_id)] pub(super) type NextColorId = StorageMap<_, Blake2_128Concat, ::CollectionId, u32, ValueQuery>; @@ -139,7 +138,6 @@ pub mod pallet { /// The next id of listings. #[pallet::storage] - #[pallet::getter(fn next_lising_id)] pub(super) type NextListingId = StorageValue<_, u32, ValueQuery>; /// The next id of offers. @@ -360,7 +358,7 @@ pub mod pallet { CollectionColor::::insert(collection_id, color); } Self::create_game_properties()?; - let mut round = Self::current_round(); + let mut round = CurrentRound::::get(); round = round.checked_add(1).ok_or(Error::::ArithmeticOverflow)?; CurrentRound::::put(round); RoundActive::::put(true); @@ -379,8 +377,8 @@ pub mod pallet { #[pallet::weight(::WeightInfo::register_user())] pub fn register_user(origin: OriginFor, player: AccountIdOf) -> DispatchResult { let signer = ensure_signed(origin)?; - ensure!(Self::admins().contains(&signer), Error::::NoPermission); - ensure!(Self::users(player.clone()).is_none(), Error::::PlayerAlreadyRegistered); + ensure!(Admins::::get().contains(&signer), Error::::NoPermission); + ensure!(Users::::get(player.clone()).is_none(), Error::::PlayerAlreadyRegistered); let current_block_number = >::block_number(); let next_request = current_block_number.saturating_add(::RequestLimit::get()); @@ -413,10 +411,10 @@ pub mod pallet { /// Emits `LocationCreated` event when succesfful. #[pallet::call_index(2)] #[pallet::weight(::WeightInfo::give_points())] - pub fn give_points(origin: OriginFor, receiver: AccountIdOf) -> DispatchResult { + pub fn give_points(origin: OriginFor, receiver: AccountIdOf, amount: u32) -> DispatchResult { T::GameOrigin::ensure_origin(origin)?; - let mut user = Self::users(receiver.clone()).ok_or(Error::::UserNotRegistered)?; - user.points = user.points.checked_add(100).ok_or(Error::::ArithmeticOverflow)?; + let mut user = Users::::get(receiver.clone()).ok_or(Error::::UserNotRegistered)?; + user.points = user.points.checked_add(amount).ok_or(Error::::ArithmeticOverflow)?; Users::::insert(receiver.clone(), user); Self::deposit_event(Event::::PointsReceived { receiver, amount: 100 }); Ok(()) @@ -459,15 +457,15 @@ pub mod pallet { pub fn play_game(origin: OriginFor, game_type: DifficultyLevel) -> DispatchResult { let signer = ensure_signed(origin)?; Self::check_enough_points(signer.clone(), game_type.clone())?; - ensure!(Self::round_active(), Error::::NoActiveRound); - let mut user = Self::users(signer.clone()).ok_or(Error::::UserNotRegistered)?; - if Self::current_round() != user.last_played_round { + ensure!(RoundActive::::get(), Error::::NoActiveRound); + let mut user = Users::::get(signer.clone()).ok_or(Error::::UserNotRegistered)?; + let current_round = CurrentRound::::get(); + if current_round != user.last_played_round { user.nfts = Default::default(); - user.last_played_round = - user.last_played_round.checked_add(1).ok_or(Error::::ArithmeticOverflow)?; + user.last_played_round = current_round; Users::::insert(signer.clone(), user); } - let game_id = Self::game_id(); + let game_id = GameId::::get(); if game_type == DifficultyLevel::Player { let current_block_number = >::block_number(); let expiry_block = current_block_number.saturating_add(8u32.into()); @@ -497,13 +495,13 @@ pub mod pallet { let u32_value = u32::from_le_bytes( hashi.as_ref()[4..8].try_into().map_err(|_| Error::::ConversionError)?, ); - let random_number = u32_value as usize % Self::game_properties().len(); - let property = Self::game_properties()[random_number].clone(); + let mut game_properties = GameProperties::::take(); + let random_number = u32_value as usize % game_properties.len(); + let property = game_properties[random_number].clone(); let game_datas = GameData { difficulty: game_type, player: signer.clone(), property, guess: None }; - let mut properties = GameProperties::::take(); - properties.retain(|property| property.id as usize != random_number); - GameProperties::::put(properties); + game_properties.retain(|property| property.id as usize != random_number); + GameProperties::::put(game_properties); GameInfo::::insert(game_id, game_datas); let next_game_id = game_id.checked_add(1).ok_or(Error::::ArithmeticOverflow)?; GameId::::put(next_game_id); @@ -534,7 +532,7 @@ pub mod pallet { })] pub fn submit_answer(origin: OriginFor, guess: u32, game_id: u32) -> DispatchResult { let signer = ensure_signed(origin)?; - let mut game_info = Self::game_info(game_id).ok_or(Error::::NoActiveGame)?; + let mut game_info = GameInfo::::get(game_id).ok_or(Error::::NoActiveGame)?; ensure!(signer == game_info.player, Error::::NoThePlayer); game_info.guess = Some(guess); GameInfo::::insert(game_id, game_info); @@ -554,7 +552,7 @@ pub mod pallet { /// /// Emits `ResultChecked` event when succesfful. #[pallet::call_index(15)] - #[pallet::weight(::WeightInfo::submit_answer())] + #[pallet::weight(::WeightInfo::check_result())] pub fn check_result( origin: OriginFor, guess: u32, @@ -615,7 +613,7 @@ pub mod pallet { pallet_lookup, )?; let listing_info = ListingInfo { owner: signer.clone(), collection_id, item_id }; - let mut listing_id = Self::next_lising_id(); + let mut listing_id = NextListingId::::get(); Listings::::insert(listing_id, listing_info); listing_id = listing_id.checked_add(1).ok_or(Error::::ArithmeticOverflow)?; NextListingId::::put(listing_id); @@ -677,7 +675,7 @@ pub mod pallet { item_id: ItemId, ) -> DispatchResult { let signer = ensure_signed(origin.clone())?; - ensure!(Self::listings(listing_id).is_some(), Error::::ListingDoesNotExist); + ensure!(Listings::::get(listing_id).is_some(), Error::::ListingDoesNotExist); let pallet_lookup = ::unlookup(Self::account_id()); let pallet_origin: OriginFor = RawOrigin::Signed(Self::account_id()).into(); pallet_nfts::Pallet::::unlock_item_transfer( @@ -693,7 +691,7 @@ pub mod pallet { )?; let offer_info = OfferInfo { owner: signer.clone(), listing_id, collection_id, item_id }; - let offer_id = Self::next_offer_id(); + let offer_id = NextOfferId::::get(); Offers::::insert(offer_id, offer_info); let offer_id = offer_id.checked_add(1).ok_or(Error::::ArithmeticOverflow)?; NextOfferId::::put(offer_id); @@ -718,7 +716,7 @@ pub mod pallet { #[pallet::weight(::WeightInfo::make_offer())] pub fn withdraw_offer(origin: OriginFor, offer_id: u32) -> DispatchResult { let signer = ensure_signed(origin.clone())?; - let offer_details = Self::offers(offer_id).ok_or(Error::::OfferDoesNotExist)?; + let offer_details = Offers::::get(offer_id).ok_or(Error::::OfferDoesNotExist)?; ensure!(offer_details.owner == signer, Error::::NoPermission); pallet_nfts::Pallet::::do_transfer( offer_details.collection_id.into(), @@ -752,7 +750,7 @@ pub mod pallet { let signer = ensure_signed(origin.clone())?; let offer_details = Offers::::take(offer_id).ok_or(Error::::OfferDoesNotExist)?; let listing_details = - Self::listings(offer_details.listing_id).ok_or(Error::::ListingDoesNotExist)?; + Listings::::get(offer_details.listing_id).ok_or(Error::::ListingDoesNotExist)?; ensure!(listing_details.owner == signer, Error::::NoPermission); let pallet_origin: OriginFor = RawOrigin::Signed(Self::account_id()).into(); if offer == Offer::Accept { @@ -852,7 +850,7 @@ pub mod pallet { #[pallet::weight(::WeightInfo::add_to_admins())] pub fn add_to_admins(origin: OriginFor, new_admin: AccountIdOf) -> DispatchResult { T::GameOrigin::ensure_origin(origin)?; - ensure!(!Self::admins().contains(&new_admin), Error::::AccountAlreadyAdmin,); + ensure!(!Admins::::get().contains(&new_admin), Error::::AccountAlreadyAdmin,); Admins::::try_append(new_admin.clone()).map_err(|_| Error::::TooManyAdmins)?; Self::deposit_event(Event::::NewAdminAdded { new_admin }); Ok(()) @@ -870,8 +868,8 @@ pub mod pallet { #[pallet::weight(::WeightInfo::remove_from_admins())] pub fn remove_from_admins(origin: OriginFor, admin: AccountIdOf) -> DispatchResult { T::GameOrigin::ensure_origin(origin)?; - ensure!(Self::admins().contains(&admin), Error::::NotAdmin); - let mut admins = Self::admins(); + ensure!(Admins::::get().contains(&admin), Error::::NotAdmin); + let mut admins = Admins::::get(); let index = admins.iter().position(|x| *x == admin).ok_or(Error::::InvalidIndex)?; admins.remove(index); Admins::::put(admins); @@ -889,7 +887,7 @@ pub mod pallet { pub fn request_token(origin: OriginFor) -> DispatchResult { let signer = ensure_signed(origin)?; let current_block_number = >::block_number(); - let mut user = Self::users(signer.clone()).ok_or(Error::::UserNotRegistered)?; + let mut user = Users::::get(signer.clone()).ok_or(Error::::UserNotRegistered)?; ensure!(user.next_token_request < current_block_number, Error::::CantRequestToken); let next_request = current_block_number.saturating_add(::RequestLimit::get()); diff --git a/pallets/game/src/tests.rs b/pallets/game/src/tests.rs index 5e4f29e..e844dab 100644 --- a/pallets/game/src/tests.rs +++ b/pallets/game/src/tests.rs @@ -100,7 +100,7 @@ fn play_game_works() { [0; 32].into() )); assert_eq!(Balances::free_balance(&([0; 32].into())), 10); - assert_ok!(GameModule::give_points(RuntimeOrigin::root(), [0; 32].into())); + assert_ok!(GameModule::give_points(RuntimeOrigin::root(), [0; 32].into(), 100)); practise_round([0; 32].into(), 0); assert_ok!(GameModule::play_game( RuntimeOrigin::signed([0; 32].into()), @@ -322,7 +322,7 @@ fn transfer_of_nft_does_not_work() { RuntimeOrigin::signed([4; 32].into()), [0; 32].into() )); - assert_ok!(GameModule::give_points(RuntimeOrigin::root(), [0; 32].into())); + assert_ok!(GameModule::give_points(RuntimeOrigin::root(), [0; 32].into(), 100)); practise_round([0; 32].into(), 0); assert_ok!(GameModule::play_game( RuntimeOrigin::signed([0; 32].into()), @@ -590,7 +590,7 @@ fn make_offer_doesnt_works() { RuntimeOrigin::signed([4; 32].into()), [0; 32].into() )); - assert_ok!(GameModule::give_points(RuntimeOrigin::root(), [0; 32].into())); + assert_ok!(GameModule::give_points(RuntimeOrigin::root(), [0; 32].into(), 100)); practise_round([0; 32].into(), 0); assert_ok!(GameModule::play_game( RuntimeOrigin::signed([0; 32].into()), diff --git a/pallets/game/src/weights.rs b/pallets/game/src/weights.rs index bd51d3e..81f4ad3 100644 --- a/pallets/game/src/weights.rs +++ b/pallets/game/src/weights.rs @@ -2,7 +2,7 @@ //! Autogenerated weights for `pallet_game` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2024-06-26, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2024-06-27, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` //! HOSTNAME: `recrafter-Legion-5-16IRX9`, CPU: `Intel(R) Core(TM) i7-14650HX` //! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: 1024 @@ -39,6 +39,7 @@ pub trait WeightInfo { fn give_points() -> Weight; fn play_game() -> Weight; fn submit_answer() -> Weight; + fn check_result() -> Weight; fn list_nft() -> Weight; fn delist_nft() -> Weight; fn make_offer() -> Weight; @@ -77,8 +78,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `166` // Estimated: `102287` - // Minimum execution time: 194_288_000 picoseconds. - Weight::from_parts(200_222_000, 0) + // Minimum execution time: 308_578_000 picoseconds. + Weight::from_parts(339_653_000, 0) .saturating_add(Weight::from_parts(0, 102287)) .saturating_add(T::DbWeight::get().reads(12)) .saturating_add(T::DbWeight::get().writes(45)) @@ -93,8 +94,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `159` // Estimated: `3593` - // Minimum execution time: 23_342_000 picoseconds. - Weight::from_parts(25_000_000, 0) + // Minimum execution time: 41_121_000 picoseconds. + Weight::from_parts(42_984_000, 0) .saturating_add(Weight::from_parts(0, 3593)) .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(2)) @@ -105,8 +106,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `224` // Estimated: `3566` - // Minimum execution time: 13_887_000 picoseconds. - Weight::from_parts(14_389_000, 0) + // Minimum execution time: 23_671_000 picoseconds. + Weight::from_parts(25_223_000, 0) .saturating_add(Weight::from_parts(0, 3566)) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)) @@ -131,8 +132,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `616` // Estimated: `102287` - // Minimum execution time: 36_774_000 picoseconds. - Weight::from_parts(38_151_000, 0) + // Minimum execution time: 56_741_000 picoseconds. + Weight::from_parts(58_181_000, 0) .saturating_add(Weight::from_parts(0, 102287)) .saturating_add(T::DbWeight::get().reads(7)) .saturating_add(T::DbWeight::get().writes(4)) @@ -143,12 +144,48 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `359` // Estimated: `4531` - // Minimum execution time: 14_246_000 picoseconds. - Weight::from_parts(14_937_000, 0) + // Minimum execution time: 24_181_000 picoseconds. + Weight::from_parts(25_776_000, 0) .saturating_add(Weight::from_parts(0, 4531)) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)) } + /// Storage: `GameModule::GameInfo` (r:1 w:1) + /// Proof: `GameModule::GameInfo` (`max_values`: None, `max_size`: Some(1066), added: 3541, mode: `MaxEncodedLen`) + /// Storage: `RandomnessCollectiveFlip::RandomMaterial` (r:1 w:0) + /// Proof: `RandomnessCollectiveFlip::RandomMaterial` (`max_values`: Some(1), `max_size`: Some(2594), added: 3089, mode: `MaxEncodedLen`) + /// Storage: `GameModule::CurrentRound` (r:1 w:0) + /// Proof: `GameModule::CurrentRound` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `GameModule::NextColorId` (r:1 w:1) + /// Proof: `GameModule::NextColorId` (`max_values`: None, `max_size`: Some(24), added: 2499, 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::CollectionConfigOf` (r:1 w:0) + /// Proof: `Nfts::CollectionConfigOf` (`max_values`: None, `max_size`: Some(73), added: 2548, 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::CollectionRoleOf` (r:1 w:0) + /// Proof: `Nfts::CollectionRoleOf` (`max_values`: None, `max_size`: Some(69), added: 2544, mode: `MaxEncodedLen`) + /// Storage: `GameModule::Users` (r:1 w:1) + /// Proof: `GameModule::Users` (`max_values`: None, `max_size`: Some(101), added: 2576, mode: `MaxEncodedLen`) + /// Storage: `GameModule::CollectionColor` (r:1 w:0) + /// Proof: `GameModule::CollectionColor` (`max_values`: None, `max_size`: Some(21), added: 2496, mode: `MaxEncodedLen`) + /// Storage: `GameModule::Leaderboard` (r:1 w:1) + /// Proof: `GameModule::Leaderboard` (`max_values`: Some(1), `max_size`: Some(361), added: 856, mode: `MaxEncodedLen`) + /// Storage: `Nfts::Account` (r:0 w:1) + /// Proof: `Nfts::Account` (`max_values`: None, `max_size`: Some(88), added: 2563, mode: `MaxEncodedLen`) + fn check_result() -> Weight { + // Proof Size summary in bytes: + // Measured: `1697` + // Estimated: `4531` + // Minimum execution time: 138_495_000 picoseconds. + Weight::from_parts(143_328_000, 0) + .saturating_add(Weight::from_parts(0, 4531)) + .saturating_add(T::DbWeight::get().reads(12)) + .saturating_add(T::DbWeight::get().writes(8)) + } /// Storage: `Nfts::Item` (r:1 w:1) /// Proof: `Nfts::Item` (`max_values`: None, `max_size`: Some(861), added: 3336, mode: `MaxEncodedLen`) /// Storage: `Nfts::CollectionRoleOf` (r:1 w:0) @@ -175,8 +212,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `1336` // Estimated: `4326` - // Minimum execution time: 72_547_000 picoseconds. - Weight::from_parts(76_222_000, 0) + // Minimum execution time: 126_027_000 picoseconds. + Weight::from_parts(130_586_000, 0) .saturating_add(Weight::from_parts(0, 4326)) .saturating_add(T::DbWeight::get().reads(7)) .saturating_add(T::DbWeight::get().writes(8)) @@ -205,8 +242,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `1433` // Estimated: `4326` - // Minimum execution time: 67_805_000 picoseconds. - Weight::from_parts(70_396_000, 0) + // Minimum execution time: 117_027_000 picoseconds. + Weight::from_parts(120_312_000, 0) .saturating_add(Weight::from_parts(0, 4326)) .saturating_add(T::DbWeight::get().reads(7)) .saturating_add(T::DbWeight::get().writes(7)) @@ -239,8 +276,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `1507` // Estimated: `4326` - // Minimum execution time: 74_122_000 picoseconds. - Weight::from_parts(78_309_000, 0) + // Minimum execution time: 129_876_000 picoseconds. + Weight::from_parts(135_878_000, 0) .saturating_add(Weight::from_parts(0, 4326)) .saturating_add(T::DbWeight::get().reads(8)) .saturating_add(T::DbWeight::get().writes(8)) @@ -277,8 +314,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `2135` // Estimated: `7662` - // Minimum execution time: 142_320_000 picoseconds. - Weight::from_parts(147_285_000, 0) + // Minimum execution time: 247_002_000 picoseconds. + Weight::from_parts(253_028_000, 0) .saturating_add(Weight::from_parts(0, 7662)) .saturating_add(T::DbWeight::get().reads(15)) .saturating_add(T::DbWeight::get().writes(17)) @@ -289,8 +326,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `318` // Estimated: `102287` - // Minimum execution time: 7_875_000 picoseconds. - Weight::from_parts(8_632_000, 0) + // Minimum execution time: 13_589_000 picoseconds. + Weight::from_parts(14_532_000, 0) .saturating_add(Weight::from_parts(0, 102287)) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)) @@ -301,8 +338,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `318` // Estimated: `102287` - // Minimum execution time: 8_871_000 picoseconds. - Weight::from_parts(9_508_000, 0) + // Minimum execution time: 15_500_000 picoseconds. + Weight::from_parts(16_219_000, 0) .saturating_add(Weight::from_parts(0, 102287)) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)) @@ -313,8 +350,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `118` // Estimated: `1806` - // Minimum execution time: 9_738_000 picoseconds. - Weight::from_parts(10_432_000, 0) + // Minimum execution time: 16_918_000 picoseconds. + Weight::from_parts(17_898_000, 0) .saturating_add(Weight::from_parts(0, 1806)) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)) @@ -325,8 +362,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `159` // Estimated: `1806` - // Minimum execution time: 11_026_000 picoseconds. - Weight::from_parts(11_756_000, 0) + // Minimum execution time: 18_854_000 picoseconds. + Weight::from_parts(19_924_000, 0) .saturating_add(Weight::from_parts(0, 1806)) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)) @@ -337,8 +374,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `224` // Estimated: `3566` - // Minimum execution time: 34_106_000 picoseconds. - Weight::from_parts(39_606_000, 0) + // Minimum execution time: 54_081_000 picoseconds. + Weight::from_parts(61_848_000, 0) .saturating_add(Weight::from_parts(0, 3566)) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)) From 8cc1fd0f78479ca3811ba9ff0c8756882ffee999 Mon Sep 17 00:00:00 2001 From: Recrafter Date: Fri, 28 Jun 2024 09:07:44 +0700 Subject: [PATCH 10/15] Adding events and extending tests --- pallets/game/src/benchmarking.rs | 10 +++- pallets/game/src/functions.rs | 25 +++++++++- pallets/game/src/lib.rs | 43 ++++++++++------- pallets/game/src/tests.rs | 80 +++++++++++++++++++++++++++++++- 4 files changed, 135 insertions(+), 23 deletions(-) diff --git a/pallets/game/src/benchmarking.rs b/pallets/game/src/benchmarking.rs index 9586a28..d096d49 100644 --- a/pallets/game/src/benchmarking.rs +++ b/pallets/game/src/benchmarking.rs @@ -81,7 +81,7 @@ mod benchmarks { assert_eq!(GameModule::::game_info(1).unwrap().player, caller); } - #[benchmark] + #[benchmark] fn submit_answer() { let caller = create_setup::(); current_block::(30u32.into()); @@ -118,7 +118,13 @@ mod benchmarks { 1 )); #[extrinsic_call] - check_result(RawOrigin::Root, 220000, 1, 220000, "test".as_bytes().to_vec().try_into().unwrap()); + check_result( + RawOrigin::Root, + 220000, + 1, + 220000, + "test".as_bytes().to_vec().try_into().unwrap(), + ); assert_eq!(GameModule::::users::>(caller).unwrap().nfts.xorange, 1); } diff --git a/pallets/game/src/functions.rs b/pallets/game/src/functions.rs index 9332597..e770387 100644 --- a/pallets/game/src/functions.rs +++ b/pallets/game/src/functions.rs @@ -45,7 +45,7 @@ impl Pallet { } /// checks the answer and distributes the rewards accordingly. - pub fn do_check_result(difference: u16, game_id: u32) -> DispatchResult { + pub fn do_check_result(difference: u16, game_id: u32, secret: BoundedVec::StringLimit> ) -> DispatchResult { let game_info = GameInfo::::take(game_id).ok_or(Error::::NoActiveGame)?; ensure!(game_info.guess.is_some(), Error::::NoGuess); if game_info.difficulty == DifficultyLevel::Pro { @@ -94,6 +94,7 @@ impl Pallet { if user.has_four_of_all_colors() { Self::end_game(game_info.player.clone())?; } + Self::deposit_event(Event::::ResultChecked { game_id, secret, points, won: true }); }, 11..=30 => { let mut user = Self::users(game_info.player.clone()) @@ -101,6 +102,7 @@ impl Pallet { user.points = user.points.checked_add(50).ok_or(Error::::ArithmeticOverflow)?; Users::::insert(game_info.player.clone(), user); + Self::deposit_event(Event::::ResultChecked { game_id, secret, points: 50, won: true }); }, 31..=50 => { let mut user = Self::users(game_info.player.clone()) @@ -108,6 +110,7 @@ impl Pallet { user.points = user.points.checked_add(30).ok_or(Error::::ArithmeticOverflow)?; Users::::insert(game_info.player.clone(), user); + Self::deposit_event(Event::::ResultChecked { game_id, secret, points: 30, won: true }); }, 51..=100 => { let mut user = Self::users(game_info.player.clone()) @@ -115,6 +118,7 @@ impl Pallet { user.points = user.points.checked_add(10).ok_or(Error::::ArithmeticOverflow)?; Users::::insert(game_info.player.clone(), user); + Self::deposit_event(Event::::ResultChecked { game_id, secret, points: 10, won: true }); }, 101..=150 => { let mut user = Self::users(game_info.player.clone()) @@ -122,6 +126,7 @@ impl Pallet { user.points = user.points.checked_sub(10).ok_or(Error::::ArithmeticUnderflow)?; Users::::insert(game_info.player.clone(), user); + Self::deposit_event(Event::::ResultChecked { game_id, secret, points: 10, won: false }); }, 151..=200 => { let mut user = Self::users(game_info.player.clone()) @@ -129,6 +134,7 @@ impl Pallet { user.points = user.points.checked_sub(20).ok_or(Error::::ArithmeticUnderflow)?; Users::::insert(game_info.player.clone(), user); + Self::deposit_event(Event::::ResultChecked { game_id, secret, points: 20, won: false }); }, 201..=250 => { let mut user = Self::users(game_info.player.clone()) @@ -136,6 +142,7 @@ impl Pallet { user.points = user.points.checked_sub(30).ok_or(Error::::ArithmeticUnderflow)?; Users::::insert(game_info.player.clone(), user); + Self::deposit_event(Event::::ResultChecked { game_id, secret, points: 30, won: false }); }, 251..=300 => { let mut user = Self::users(game_info.player.clone()) @@ -143,6 +150,7 @@ impl Pallet { user.points = user.points.checked_sub(40).ok_or(Error::::ArithmeticUnderflow)?; Users::::insert(game_info.player.clone(), user); + Self::deposit_event(Event::::ResultChecked { game_id, secret, points: 40, won: false }); }, _ => { let mut user = Self::users(game_info.player.clone()) @@ -150,6 +158,7 @@ impl Pallet { user.points = user.points.checked_sub(50).ok_or(Error::::ArithmeticUnderflow)?; Users::::insert(game_info.player.clone(), user); + Self::deposit_event(Event::::ResultChecked { game_id, secret, points: 50, won: false }); }, } } else if game_info.difficulty == DifficultyLevel::Player { @@ -198,6 +207,7 @@ impl Pallet { if user.has_four_of_all_colors() { Self::end_game(game_info.player.clone())?; } + Self::deposit_event(Event::::ResultChecked { game_id, secret, points, won: true }); }, 11..=30 => { let mut user = Self::users(game_info.player.clone()) @@ -205,6 +215,7 @@ impl Pallet { user.points = user.points.checked_add(25).ok_or(Error::::ArithmeticUnderflow)?; Users::::insert(game_info.player.clone(), user); + Self::deposit_event(Event::::ResultChecked { game_id, secret, points: 25, won: true }); }, 31..=50 => { let mut user = Self::users(game_info.player.clone()) @@ -212,6 +223,7 @@ impl Pallet { user.points = user.points.checked_add(15).ok_or(Error::::ArithmeticUnderflow)?; Users::::insert(game_info.player.clone(), user); + Self::deposit_event(Event::::ResultChecked { game_id, secret, points: 15, won: true }); }, 51..=100 => { let mut user = Self::users(game_info.player.clone()) @@ -219,6 +231,7 @@ impl Pallet { user.points = user.points.checked_add(5).ok_or(Error::::ArithmeticUnderflow)?; Users::::insert(game_info.player.clone(), user); + Self::deposit_event(Event::::ResultChecked { game_id, secret, points: 5, won: true }); }, 101..=150 => { let mut user = Self::users(game_info.player.clone()) @@ -226,6 +239,7 @@ impl Pallet { user.points = user.points.checked_sub(5).ok_or(Error::::ArithmeticUnderflow)?; Users::::insert(game_info.player.clone(), user); + Self::deposit_event(Event::::ResultChecked { game_id, secret, points: 5, won: false }); }, 151..=200 => { let mut user = Self::users(game_info.player.clone()) @@ -233,6 +247,7 @@ impl Pallet { user.points = user.points.checked_sub(10).ok_or(Error::::ArithmeticUnderflow)?; Users::::insert(game_info.player.clone(), user); + Self::deposit_event(Event::::ResultChecked { game_id, secret, points: 10, won: false }); }, 201..=250 => { let mut user = Self::users(game_info.player.clone()) @@ -240,6 +255,7 @@ impl Pallet { user.points = user.points.checked_sub(15).ok_or(Error::::ArithmeticUnderflow)?; Users::::insert(game_info.player.clone(), user); + Self::deposit_event(Event::::ResultChecked { game_id, secret, points: 15, won: false }); }, 251..=300 => { let mut user = Self::users(game_info.player.clone()) @@ -247,6 +263,7 @@ impl Pallet { user.points = user.points.checked_sub(20).ok_or(Error::::ArithmeticUnderflow)?; Users::::insert(game_info.player.clone(), user); + Self::deposit_event(Event::::ResultChecked { game_id, secret, points: 20, won: false }); }, _ => { let mut user = Self::users(game_info.player.clone()) @@ -254,6 +271,7 @@ impl Pallet { user.points = user.points.checked_sub(25).ok_or(Error::::ArithmeticUnderflow)?; Users::::insert(game_info.player.clone(), user); + Self::deposit_event(Event::::ResultChecked { game_id, secret, points: 25, won: false }); }, } } else { @@ -263,6 +281,7 @@ impl Pallet { user.practise_rounds = user.practise_rounds.checked_add(1).ok_or(Error::::ArithmeticUnderflow)?; Users::::insert(game_info.player.clone(), user); + Self::deposit_event(Event::::ResultChecked { game_id, secret, points: 5, won: true }); } let user = Self::users(game_info.player.clone()).ok_or(Error::::UserNotRegistered)?; Self::update_leaderboard(game_info.player, user.points)?; @@ -320,17 +339,19 @@ impl Pallet { } /// Handles the case if the player did not answer on time. - pub fn no_answer_result(game_info: GameData) -> DispatchResult { + pub fn no_answer_result(game_info: GameData, game_id: u32) -> DispatchResult { if game_info.difficulty == DifficultyLevel::Pro { let mut user = Self::users(game_info.player.clone()).ok_or(Error::::UserNotRegistered)?; user.points = user.points.checked_sub(50).ok_or(Error::::ArithmeticUnderflow)?; Users::::insert(game_info.player.clone(), user); + Self::deposit_event(Event::::NoAnswer { game_id, points: 50 }); } else if game_info.difficulty == DifficultyLevel::Player { let mut user = Self::users(game_info.player.clone()).ok_or(Error::::UserNotRegistered)?; user.points = user.points.checked_sub(25).ok_or(Error::::ArithmeticUnderflow)?; Users::::insert(game_info.player.clone(), user); + Self::deposit_event(Event::::NoAnswer { game_id, points: 25 }); } Ok(()) } diff --git a/pallets/game/src/lib.rs b/pallets/game/src/lib.rs index 52f50a5..df0a7d5 100644 --- a/pallets/game/src/lib.rs +++ b/pallets/game/src/lib.rs @@ -223,7 +223,9 @@ pub mod pallet { /// An answer has been submitted. AnswerSubmitted { player: AccountIdOf, game_id: u32, guess: u32 }, /// The result has been checked. - ResultChecked { game_id: u32 }, + ResultChecked { game_id: u32, secret: BoundedVec::StringLimit>, points: u32, won: bool }, + /// No Answer has been submitted. + NoAnswer { game_id: u32, points: u32 }, /// A nft has been listed. NftListed { owner: AccountIdOf, collection_id: CollectionId, item_id: ItemId }, /// A nft has been delisted. @@ -311,7 +313,7 @@ pub mod pallet { let game_info = >::take(index); if let Some(game_info) = game_info { if game_info.guess.is_none() { - let _ = Self::no_answer_result(game_info); + let _ = Self::no_answer_result(game_info, *index); } else { GameInfo::::insert(index, game_info); } @@ -411,9 +413,14 @@ pub mod pallet { /// Emits `LocationCreated` event when succesfful. #[pallet::call_index(2)] #[pallet::weight(::WeightInfo::give_points())] - pub fn give_points(origin: OriginFor, receiver: AccountIdOf, amount: u32) -> DispatchResult { + pub fn give_points( + origin: OriginFor, + receiver: AccountIdOf, + amount: u32, + ) -> DispatchResult { T::GameOrigin::ensure_origin(origin)?; - let mut user = Users::::get(receiver.clone()).ok_or(Error::::UserNotRegistered)?; + let mut user = + Users::::get(receiver.clone()).ok_or(Error::::UserNotRegistered)?; user.points = user.points.checked_add(amount).ok_or(Error::::ArithmeticOverflow)?; Users::::insert(receiver.clone(), user); Self::deposit_event(Event::::PointsReceived { receiver, amount: 100 }); @@ -551,7 +558,7 @@ pub mod pallet { /// - `secret`: The secret to decrypt the price and property data. /// /// Emits `ResultChecked` event when succesfful. - #[pallet::call_index(15)] + #[pallet::call_index(5)] #[pallet::weight(::WeightInfo::check_result())] pub fn check_result( origin: OriginFor, @@ -572,8 +579,8 @@ pub mod pallet { Self::do_check_result( difference_value.try_into().map_err(|_| Error::::ConversionError)?, game_id, + secret, )?; - Self::deposit_event(Event::::ResultChecked { game_id }); Ok(()) } @@ -586,7 +593,7 @@ pub mod pallet { /// - `item_id`: The item id of the nft that will be listed. /// /// Emits `NftListed` event when succesfful. - #[pallet::call_index(5)] + #[pallet::call_index(6)] #[pallet::weight(::WeightInfo::list_nft())] pub fn list_nft( origin: OriginFor, @@ -629,7 +636,7 @@ pub mod pallet { /// - `listing_id`: The listing id of the listing. /// /// Emits `NftDelisted` event when succesfful. - #[pallet::call_index(6)] + #[pallet::call_index(7)] #[pallet::weight(::WeightInfo::delist_nft())] pub fn delist_nft(origin: OriginFor, listing_id: u32) -> DispatchResult { let signer = ensure_signed(origin.clone())?; @@ -666,7 +673,7 @@ pub mod pallet { /// - `item_id`: The item id of the nft that will be offered. /// /// Emits `OfferMade` event when succesfful. - #[pallet::call_index(7)] + #[pallet::call_index(8)] #[pallet::weight(::WeightInfo::make_offer())] pub fn make_offer( origin: OriginFor, @@ -712,7 +719,7 @@ pub mod pallet { /// - `offer_id`: The id of the offer. /// /// Emits `OfferWithdrawn` event when succesfful. - #[pallet::call_index(8)] + #[pallet::call_index(9)] #[pallet::weight(::WeightInfo::make_offer())] pub fn withdraw_offer(origin: OriginFor, offer_id: u32) -> DispatchResult { let signer = ensure_signed(origin.clone())?; @@ -744,13 +751,13 @@ pub mod pallet { /// - `offer`: Must be either Accept or Reject. /// /// Emits `OfferHandeld` event when succesfful. - #[pallet::call_index(9)] + #[pallet::call_index(10)] #[pallet::weight(::WeightInfo::handle_offer())] pub fn handle_offer(origin: OriginFor, offer_id: u32, offer: Offer) -> DispatchResult { let signer = ensure_signed(origin.clone())?; let offer_details = Offers::::take(offer_id).ok_or(Error::::OfferDoesNotExist)?; - let listing_details = - Listings::::get(offer_details.listing_id).ok_or(Error::::ListingDoesNotExist)?; + let listing_details = Listings::::get(offer_details.listing_id) + .ok_or(Error::::ListingDoesNotExist)?; ensure!(listing_details.owner == signer, Error::::NoPermission); let pallet_origin: OriginFor = RawOrigin::Signed(Self::account_id()).into(); if offer == Offer::Accept { @@ -813,7 +820,7 @@ pub mod pallet { /// Parameters: /// - `property`: The new property that will be added. /// - `price`: The price of the property that will be added. - #[pallet::call_index(10)] + #[pallet::call_index(11)] #[pallet::weight(::WeightInfo::add_property())] pub fn add_property(origin: OriginFor, property: PropertyInfoData) -> DispatchResult { T::GameOrigin::ensure_origin(origin)?; @@ -828,7 +835,7 @@ pub mod pallet { /// /// Parameters: /// - `id`: The id of the property that should be removed. - #[pallet::call_index(11)] + #[pallet::call_index(12)] #[pallet::weight(::WeightInfo::remove_property())] pub fn remove_property(origin: OriginFor, id: u32) -> DispatchResult { T::GameOrigin::ensure_origin(origin)?; @@ -846,7 +853,7 @@ pub mod pallet { /// - `new_admin`: The address of the new account added to the list. /// /// Emits `NewAdminAdded` event when succesfful - #[pallet::call_index(12)] + #[pallet::call_index(13)] #[pallet::weight(::WeightInfo::add_to_admins())] pub fn add_to_admins(origin: OriginFor, new_admin: AccountIdOf) -> DispatchResult { T::GameOrigin::ensure_origin(origin)?; @@ -864,7 +871,7 @@ pub mod pallet { /// - `admin`: The address of the admin removed from the admins. /// /// Emits `UserRemoved` event when succesfful - #[pallet::call_index(13)] + #[pallet::call_index(14)] #[pallet::weight(::WeightInfo::remove_from_admins())] pub fn remove_from_admins(origin: OriginFor, admin: AccountIdOf) -> DispatchResult { T::GameOrigin::ensure_origin(origin)?; @@ -882,7 +889,7 @@ pub mod pallet { /// The origin must be Signed and the sender must have sufficient funds free. /// /// Emits `TokenReceived` event when succesfful. - #[pallet::call_index(14)] + #[pallet::call_index(15)] #[pallet::weight(::WeightInfo::request_token())] pub fn request_token(origin: OriginFor) -> DispatchResult { let signer = ensure_signed(origin)?; diff --git a/pallets/game/src/tests.rs b/pallets/game/src/tests.rs index e844dab..2a58fd0 100644 --- a/pallets/game/src/tests.rs +++ b/pallets/game/src/tests.rs @@ -1,5 +1,8 @@ use crate::{mock::*, Error, Event, PropertyInfoData}; -use frame_support::{assert_noop, assert_ok}; +use frame_support::{ + assert_noop, assert_ok, + traits::{OnFinalize, OnInitialize}, +}; use sp_runtime::{traits::BadOrigin, DispatchError, ModuleError}; fn practise_round(player: AccountId, game_id: u32) { @@ -18,6 +21,17 @@ fn practise_round(player: AccountId, game_id: u32) { )); } +fn run_to_block(n: u64) { + while System::block_number() < n { + GameModule::on_finalize(System::block_number()); + System::on_finalize(System::block_number()); + System::set_block_number(System::block_number() + 1); + System::on_initialize(System::block_number()); + GameModule::on_initialize(System::block_number()); + } +} + + #[test] fn setup_game_works() { new_test_ext().execute_with(|| { @@ -196,6 +210,7 @@ fn submit_answer_works() { 220_000, "nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap() )); + System::assert_last_event(Event::ResultChecked { game_id: 1, secret: "nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap(), points: 25, won: true }.into()); assert_eq!(GameModule::game_info(0).is_none(), true); assert_eq!(GameModule::users::([0; 32].into()).unwrap().points, 80); assert_ok!(GameModule::play_game( @@ -213,10 +228,72 @@ fn submit_answer_works() { 220_000, "nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap() )); + System::assert_last_event(Event::ResultChecked { game_id: 2, secret: "nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap(), points: 100, won: true }.into()); assert_eq!(GameModule::game_info(1).is_none(), true); assert_eq!(GameModule::users::([0; 32].into()).unwrap().points, 180); assert_eq!(Nfts::owner(0, 0).unwrap(), [0; 32].into()); assert_eq!(GameModule::users::([0; 32].into()).unwrap().nfts.xorange, 1); + assert_ok!(GameModule::play_game( + RuntimeOrigin::signed([0; 32].into()), + crate::DifficultyLevel::Player, + )); + assert_ok!(GameModule::submit_answer(RuntimeOrigin::signed([0; 32].into()), 0, 3)); + System::assert_last_event( + Event::AnswerSubmitted { player: [0; 32].into(), game_id: 3, guess: 0 }.into(), + ); + assert_ok!(GameModule::check_result( + RuntimeOrigin::root(), + 0, + 3, + 220_000, + "nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap() + )); + assert_eq!(GameModule::users::([0; 32].into()).unwrap().points, 155); + }); +} + +#[test] +fn game_expires_works() { + new_test_ext().execute_with(|| { + System::set_block_number(1); + assert_ok!(GameModule::setup_game(RuntimeOrigin::root())); + assert_eq!(GameModule::game_properties().len(), 4); + assert_ok!(GameModule::add_to_admins(RuntimeOrigin::root(), [4; 32].into())); + assert_ok!(GameModule::register_user( + RuntimeOrigin::signed([4; 32].into()), + [0; 32].into() + )); + practise_round([0; 32].into(), 0); + assert_ok!(GameModule::play_game( + RuntimeOrigin::signed([0; 32].into()), + crate::DifficultyLevel::Player, + )); + run_to_block(20); + System::assert_last_event(Event::NoAnswer { game_id: 1, points: 25 }.into()); + assert_eq!(GameModule::users::([0; 32].into()).unwrap().points, 30); + assert_ok!(GameModule::play_game( + RuntimeOrigin::signed([0; 32].into()), + crate::DifficultyLevel::Player, + )); + assert_ok!(GameModule::submit_answer(RuntimeOrigin::signed([0; 32].into()), 220_000, 2)); + System::assert_last_event( + Event::AnswerSubmitted { player: [0; 32].into(), game_id: 2, guess: 220_000 }.into(), + ); + assert_ok!(GameModule::check_result( + RuntimeOrigin::root(), + 220_000, + 2, + 223_000, + "nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap() + )); + assert_eq!(GameModule::users::([0; 32].into()).unwrap().points, 55); + assert_ok!(GameModule::play_game( + RuntimeOrigin::signed([0; 32].into()), + crate::DifficultyLevel::Pro, + )); + run_to_block(30); + System::assert_last_event(Event::NoAnswer { game_id: 3, points: 50 }.into()); + assert_eq!(GameModule::users::([0; 32].into()).unwrap().points, 5); }); } @@ -257,6 +334,7 @@ fn leaderboard_works() { 220_000, "nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap() )); + System::assert_last_event(Event::ResultChecked { game_id: 3, secret: "nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap(), points: 15, won: true }.into()); assert_ok!(GameModule::play_game( RuntimeOrigin::signed([1; 32].into()), crate::DifficultyLevel::Player, From 2ed464aa70605a75302a173522dfe5fe614703d2 Mon Sep 17 00:00:00 2001 From: Recrafter Date: Tue, 2 Jul 2024 08:06:25 +0700 Subject: [PATCH 11/15] Upgrading events and functions --- pallets/game/src/functions.rs | 20 +++++++++++++++++ pallets/game/src/lib.rs | 41 ++++++++++++++--------------------- pallets/game/src/tests.rs | 15 +++++++++++++ 3 files changed, 51 insertions(+), 25 deletions(-) diff --git a/pallets/game/src/functions.rs b/pallets/game/src/functions.rs index e770387..40782e9 100644 --- a/pallets/game/src/functions.rs +++ b/pallets/game/src/functions.rs @@ -90,6 +90,7 @@ impl Pallet { let points = user.calculate_points(color); user.points = user.points.checked_add(points).ok_or(Error::::ArithmeticOverflow)?; + user.wins = user.wins.checked_add(1).ok_or(Error::::ArithmeticOverflow)?; Users::::insert(game_info.player.clone(), user.clone()); if user.has_four_of_all_colors() { Self::end_game(game_info.player.clone())?; @@ -101,6 +102,7 @@ impl Pallet { .ok_or(Error::::UserNotRegistered)?; user.points = user.points.checked_add(50).ok_or(Error::::ArithmeticOverflow)?; + user.wins = user.wins.checked_add(1).ok_or(Error::::ArithmeticOverflow)?; Users::::insert(game_info.player.clone(), user); Self::deposit_event(Event::::ResultChecked { game_id, secret, points: 50, won: true }); }, @@ -109,6 +111,7 @@ impl Pallet { .ok_or(Error::::UserNotRegistered)?; user.points = user.points.checked_add(30).ok_or(Error::::ArithmeticOverflow)?; + user.wins = user.wins.checked_add(1).ok_or(Error::::ArithmeticOverflow)?; Users::::insert(game_info.player.clone(), user); Self::deposit_event(Event::::ResultChecked { game_id, secret, points: 30, won: true }); }, @@ -117,6 +120,7 @@ impl Pallet { .ok_or(Error::::UserNotRegistered)?; user.points = user.points.checked_add(10).ok_or(Error::::ArithmeticOverflow)?; + user.wins = user.wins.checked_add(1).ok_or(Error::::ArithmeticOverflow)?; Users::::insert(game_info.player.clone(), user); Self::deposit_event(Event::::ResultChecked { game_id, secret, points: 10, won: true }); }, @@ -125,6 +129,7 @@ impl Pallet { .ok_or(Error::::UserNotRegistered)?; user.points = user.points.checked_sub(10).ok_or(Error::::ArithmeticUnderflow)?; + user.losses = user.losses.checked_add(1).ok_or(Error::::ArithmeticOverflow)?; Users::::insert(game_info.player.clone(), user); Self::deposit_event(Event::::ResultChecked { game_id, secret, points: 10, won: false }); }, @@ -133,6 +138,7 @@ impl Pallet { .ok_or(Error::::UserNotRegistered)?; user.points = user.points.checked_sub(20).ok_or(Error::::ArithmeticUnderflow)?; + user.losses = user.losses.checked_add(1).ok_or(Error::::ArithmeticOverflow)?; Users::::insert(game_info.player.clone(), user); Self::deposit_event(Event::::ResultChecked { game_id, secret, points: 20, won: false }); }, @@ -141,6 +147,7 @@ impl Pallet { .ok_or(Error::::UserNotRegistered)?; user.points = user.points.checked_sub(30).ok_or(Error::::ArithmeticUnderflow)?; + user.losses = user.losses.checked_add(1).ok_or(Error::::ArithmeticOverflow)?; Users::::insert(game_info.player.clone(), user); Self::deposit_event(Event::::ResultChecked { game_id, secret, points: 30, won: false }); }, @@ -149,6 +156,7 @@ impl Pallet { .ok_or(Error::::UserNotRegistered)?; user.points = user.points.checked_sub(40).ok_or(Error::::ArithmeticUnderflow)?; + user.losses = user.losses.checked_add(1).ok_or(Error::::ArithmeticOverflow)?; Users::::insert(game_info.player.clone(), user); Self::deposit_event(Event::::ResultChecked { game_id, secret, points: 40, won: false }); }, @@ -157,6 +165,7 @@ impl Pallet { .ok_or(Error::::UserNotRegistered)?; user.points = user.points.checked_sub(50).ok_or(Error::::ArithmeticUnderflow)?; + user.losses = user.losses.checked_add(1).ok_or(Error::::ArithmeticOverflow)?; Users::::insert(game_info.player.clone(), user); Self::deposit_event(Event::::ResultChecked { game_id, secret, points: 50, won: false }); }, @@ -203,6 +212,7 @@ impl Pallet { let points = user.calculate_points(color); user.points = user.points.checked_add(points).ok_or(Error::::ArithmeticOverflow)?; + user.wins = user.wins.checked_add(1).ok_or(Error::::ArithmeticOverflow)?; Users::::insert(game_info.player.clone(), user.clone()); if user.has_four_of_all_colors() { Self::end_game(game_info.player.clone())?; @@ -214,6 +224,7 @@ impl Pallet { .ok_or(Error::::UserNotRegistered)?; user.points = user.points.checked_add(25).ok_or(Error::::ArithmeticUnderflow)?; + user.wins = user.wins.checked_add(1).ok_or(Error::::ArithmeticOverflow)?; Users::::insert(game_info.player.clone(), user); Self::deposit_event(Event::::ResultChecked { game_id, secret, points: 25, won: true }); }, @@ -222,6 +233,7 @@ impl Pallet { .ok_or(Error::::UserNotRegistered)?; user.points = user.points.checked_add(15).ok_or(Error::::ArithmeticUnderflow)?; + user.wins = user.wins.checked_add(1).ok_or(Error::::ArithmeticOverflow)?; Users::::insert(game_info.player.clone(), user); Self::deposit_event(Event::::ResultChecked { game_id, secret, points: 15, won: true }); }, @@ -230,6 +242,7 @@ impl Pallet { .ok_or(Error::::UserNotRegistered)?; user.points = user.points.checked_add(5).ok_or(Error::::ArithmeticUnderflow)?; + user.wins = user.wins.checked_add(1).ok_or(Error::::ArithmeticOverflow)?; Users::::insert(game_info.player.clone(), user); Self::deposit_event(Event::::ResultChecked { game_id, secret, points: 5, won: true }); }, @@ -238,6 +251,7 @@ impl Pallet { .ok_or(Error::::UserNotRegistered)?; user.points = user.points.checked_sub(5).ok_or(Error::::ArithmeticUnderflow)?; + user.losses = user.losses.checked_add(1).ok_or(Error::::ArithmeticOverflow)?; Users::::insert(game_info.player.clone(), user); Self::deposit_event(Event::::ResultChecked { game_id, secret, points: 5, won: false }); }, @@ -246,6 +260,7 @@ impl Pallet { .ok_or(Error::::UserNotRegistered)?; user.points = user.points.checked_sub(10).ok_or(Error::::ArithmeticUnderflow)?; + user.losses = user.losses.checked_add(1).ok_or(Error::::ArithmeticOverflow)?; Users::::insert(game_info.player.clone(), user); Self::deposit_event(Event::::ResultChecked { game_id, secret, points: 10, won: false }); }, @@ -254,6 +269,7 @@ impl Pallet { .ok_or(Error::::UserNotRegistered)?; user.points = user.points.checked_sub(15).ok_or(Error::::ArithmeticUnderflow)?; + user.losses = user.losses.checked_add(1).ok_or(Error::::ArithmeticOverflow)?; Users::::insert(game_info.player.clone(), user); Self::deposit_event(Event::::ResultChecked { game_id, secret, points: 15, won: false }); }, @@ -262,6 +278,7 @@ impl Pallet { .ok_or(Error::::UserNotRegistered)?; user.points = user.points.checked_sub(20).ok_or(Error::::ArithmeticUnderflow)?; + user.losses = user.losses.checked_add(1).ok_or(Error::::ArithmeticOverflow)?; Users::::insert(game_info.player.clone(), user); Self::deposit_event(Event::::ResultChecked { game_id, secret, points: 20, won: false }); }, @@ -270,6 +287,7 @@ impl Pallet { .ok_or(Error::::UserNotRegistered)?; user.points = user.points.checked_sub(25).ok_or(Error::::ArithmeticUnderflow)?; + user.losses = user.losses.checked_add(1).ok_or(Error::::ArithmeticOverflow)?; Users::::insert(game_info.player.clone(), user); Self::deposit_event(Event::::ResultChecked { game_id, secret, points: 25, won: false }); }, @@ -344,12 +362,14 @@ impl Pallet { let mut user = Self::users(game_info.player.clone()).ok_or(Error::::UserNotRegistered)?; user.points = user.points.checked_sub(50).ok_or(Error::::ArithmeticUnderflow)?; + user.losses = user.losses.checked_add(1).ok_or(Error::::ArithmeticOverflow)?; Users::::insert(game_info.player.clone(), user); Self::deposit_event(Event::::NoAnswer { game_id, points: 50 }); } else if game_info.difficulty == DifficultyLevel::Player { let mut user = Self::users(game_info.player.clone()).ok_or(Error::::UserNotRegistered)?; user.points = user.points.checked_sub(25).ok_or(Error::::ArithmeticUnderflow)?; + user.losses = user.losses.checked_add(1).ok_or(Error::::ArithmeticOverflow)?; Users::::insert(game_info.player.clone(), user); Self::deposit_event(Event::::NoAnswer { game_id, points: 25 }); } diff --git a/pallets/game/src/lib.rs b/pallets/game/src/lib.rs index df0a7d5..7fbb7a9 100644 --- a/pallets/game/src/lib.rs +++ b/pallets/game/src/lib.rs @@ -219,7 +219,7 @@ pub mod pallet { /// A user has received points. PointsReceived { receiver: AccountIdOf, amount: u32 }, /// A game has started. - GameStarted { player: AccountIdOf, game_id: u32 }, + GameStarted { player: AccountIdOf, game_id: u32, ending_block: BlockNumberFor }, /// An answer has been submitted. AnswerSubmitted { player: AccountIdOf, game_id: u32, guess: u32 }, /// The result has been checked. @@ -473,31 +473,22 @@ pub mod pallet { Users::::insert(signer.clone(), user); } let game_id = GameId::::get(); - if game_type == DifficultyLevel::Player { - let current_block_number = >::block_number(); - let expiry_block = current_block_number.saturating_add(8u32.into()); - - GamesExpiring::::try_mutate(expiry_block, |keys| { - keys.try_push(game_id).map_err(|_| Error::::TooManyGames)?; - Ok::<(), DispatchError>(()) - })?; + let current_block_number = >::block_number(); + + // Determine expiry block based on game type + let expiry_block = if game_type == DifficultyLevel::Player { + current_block_number.saturating_add(8u32.into()) } else if game_type == DifficultyLevel::Pro { - let current_block_number = >::block_number(); - let expiry_block = current_block_number.saturating_add(5u32.into()); - - GamesExpiring::::try_mutate(expiry_block, |keys| { - keys.try_push(game_id).map_err(|_| Error::::TooManyGames)?; - Ok::<(), DispatchError>(()) - })?; + current_block_number.saturating_add(5u32.into()) } else { - let current_block_number = >::block_number(); - let expiry_block = current_block_number.saturating_add(10u32.into()); - - GamesExpiring::::try_mutate(expiry_block, |keys| { - keys.try_push(game_id).map_err(|_| Error::::TooManyGames)?; - Ok::<(), DispatchError>(()) - })?; - } + current_block_number.saturating_add(10u32.into()) + }; + + GamesExpiring::::try_mutate(expiry_block, |keys| { + keys.try_push(game_id).map_err(|_| Error::::TooManyGames)?; + Ok::<(), DispatchError>(()) + })?; + let (hashi, _) = T::GameRandomness::random(&[(game_id % 256) as u8]); let u32_value = u32::from_le_bytes( hashi.as_ref()[4..8].try_into().map_err(|_| Error::::ConversionError)?, @@ -512,7 +503,7 @@ pub mod pallet { GameInfo::::insert(game_id, game_datas); let next_game_id = game_id.checked_add(1).ok_or(Error::::ArithmeticOverflow)?; GameId::::put(next_game_id); - Self::deposit_event(Event::::GameStarted { player: signer, game_id }); + Self::deposit_event(Event::::GameStarted { player: signer, game_id, ending_block: expiry_block }); Ok(()) } diff --git a/pallets/game/src/tests.rs b/pallets/game/src/tests.rs index 2a58fd0..58246bd 100644 --- a/pallets/game/src/tests.rs +++ b/pallets/game/src/tests.rs @@ -368,7 +368,9 @@ fn leaderboard_works() { assert_eq!(GameModule::game_info(0).is_none(), true); assert_eq!(GameModule::users::([2; 32].into()).unwrap().points, 155); assert_eq!(GameModule::users::([1; 32].into()).unwrap().points, 80); + assert_eq!(GameModule::users::([1; 32].into()).unwrap().wins, 1); assert_eq!(GameModule::users::([0; 32].into()).unwrap().points, 70); + assert_eq!(GameModule::users::([0; 32].into()).unwrap().wins, 1); assert_eq!(GameModule::leaderboard().len(), 3); assert_eq!(GameModule::leaderboard()[0], ([2; 32].into(), 155)); assert_eq!(GameModule::leaderboard()[1], ([1; 32].into(), 80)); @@ -715,6 +717,7 @@ fn withdraw_offer_works() { )); assert_eq!(GameModule::game_info(0).is_none(), true); assert_eq!(GameModule::users::([0; 32].into()).unwrap().points, 155); + assert_eq!(GameModule::users::([0; 32].into()).unwrap().wins, 1); assert_eq!(Nfts::owner(0, 0).unwrap(), [0; 32].into()); practise_round([1; 32].into(), 2); assert_ok!(GameModule::play_game( @@ -939,6 +942,18 @@ fn handle_offer_accept_works() { message: Some("ItemLocked") }) ); + assert_ok!(GameModule::play_game( + RuntimeOrigin::signed([0; 32].into()), + crate::DifficultyLevel::Player, + )); + System::assert_last_event( + Event::GameStarted { player: [0; 32].into(), game_id: 6, ending_block: 9 }.into(), + ); + run_to_block(20); + assert_eq!(GameModule::users::([0; 32].into()).unwrap().nfts.xorange, 3); + assert_eq!(GameModule::users::([0; 32].into()).unwrap().points, 470); + assert_eq!(GameModule::users::([0; 32].into()).unwrap().wins, 3); + assert_eq!(GameModule::users::([0; 32].into()).unwrap().losses, 1); }); } From fe034dfe1c8eb9286c763ffbd9ca3f827fb3554b Mon Sep 17 00:00:00 2001 From: Recrafter Date: Tue, 2 Jul 2024 08:23:38 +0700 Subject: [PATCH 12/15] Updating weight --- pallets/game/src/weights.rs | 62 ++++++++++++++++++------------------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/pallets/game/src/weights.rs b/pallets/game/src/weights.rs index 81f4ad3..ad54e6d 100644 --- a/pallets/game/src/weights.rs +++ b/pallets/game/src/weights.rs @@ -2,7 +2,7 @@ //! Autogenerated weights for `pallet_game` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2024-06-27, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2024-07-02, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` //! HOSTNAME: `recrafter-Legion-5-16IRX9`, CPU: `Intel(R) Core(TM) i7-14650HX` //! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: 1024 @@ -78,8 +78,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `166` // Estimated: `102287` - // Minimum execution time: 308_578_000 picoseconds. - Weight::from_parts(339_653_000, 0) + // Minimum execution time: 203_338_000 picoseconds. + Weight::from_parts(207_008_000, 0) .saturating_add(Weight::from_parts(0, 102287)) .saturating_add(T::DbWeight::get().reads(12)) .saturating_add(T::DbWeight::get().writes(45)) @@ -94,8 +94,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `159` // Estimated: `3593` - // Minimum execution time: 41_121_000 picoseconds. - Weight::from_parts(42_984_000, 0) + // Minimum execution time: 23_973_000 picoseconds. + Weight::from_parts(25_287_000, 0) .saturating_add(Weight::from_parts(0, 3593)) .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(2)) @@ -106,8 +106,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `224` // Estimated: `3566` - // Minimum execution time: 23_671_000 picoseconds. - Weight::from_parts(25_223_000, 0) + // Minimum execution time: 13_927_000 picoseconds. + Weight::from_parts(14_546_000, 0) .saturating_add(Weight::from_parts(0, 3566)) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)) @@ -132,8 +132,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `616` // Estimated: `102287` - // Minimum execution time: 56_741_000 picoseconds. - Weight::from_parts(58_181_000, 0) + // Minimum execution time: 33_772_000 picoseconds. + Weight::from_parts(35_079_000, 0) .saturating_add(Weight::from_parts(0, 102287)) .saturating_add(T::DbWeight::get().reads(7)) .saturating_add(T::DbWeight::get().writes(4)) @@ -144,8 +144,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `359` // Estimated: `4531` - // Minimum execution time: 24_181_000 picoseconds. - Weight::from_parts(25_776_000, 0) + // Minimum execution time: 14_305_000 picoseconds. + Weight::from_parts(15_213_000, 0) .saturating_add(Weight::from_parts(0, 4531)) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)) @@ -180,8 +180,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `1697` // Estimated: `4531` - // Minimum execution time: 138_495_000 picoseconds. - Weight::from_parts(143_328_000, 0) + // Minimum execution time: 83_106_000 picoseconds. + Weight::from_parts(85_634_000, 0) .saturating_add(Weight::from_parts(0, 4531)) .saturating_add(T::DbWeight::get().reads(12)) .saturating_add(T::DbWeight::get().writes(8)) @@ -212,8 +212,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `1336` // Estimated: `4326` - // Minimum execution time: 126_027_000 picoseconds. - Weight::from_parts(130_586_000, 0) + // Minimum execution time: 74_512_000 picoseconds. + Weight::from_parts(77_636_000, 0) .saturating_add(Weight::from_parts(0, 4326)) .saturating_add(T::DbWeight::get().reads(7)) .saturating_add(T::DbWeight::get().writes(8)) @@ -242,8 +242,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `1433` // Estimated: `4326` - // Minimum execution time: 117_027_000 picoseconds. - Weight::from_parts(120_312_000, 0) + // Minimum execution time: 69_764_000 picoseconds. + Weight::from_parts(71_311_000, 0) .saturating_add(Weight::from_parts(0, 4326)) .saturating_add(T::DbWeight::get().reads(7)) .saturating_add(T::DbWeight::get().writes(7)) @@ -276,8 +276,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `1507` // Estimated: `4326` - // Minimum execution time: 129_876_000 picoseconds. - Weight::from_parts(135_878_000, 0) + // Minimum execution time: 77_751_000 picoseconds. + Weight::from_parts(82_016_000, 0) .saturating_add(Weight::from_parts(0, 4326)) .saturating_add(T::DbWeight::get().reads(8)) .saturating_add(T::DbWeight::get().writes(8)) @@ -314,8 +314,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `2135` // Estimated: `7662` - // Minimum execution time: 247_002_000 picoseconds. - Weight::from_parts(253_028_000, 0) + // Minimum execution time: 144_786_000 picoseconds. + Weight::from_parts(151_331_000, 0) .saturating_add(Weight::from_parts(0, 7662)) .saturating_add(T::DbWeight::get().reads(15)) .saturating_add(T::DbWeight::get().writes(17)) @@ -326,8 +326,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `318` // Estimated: `102287` - // Minimum execution time: 13_589_000 picoseconds. - Weight::from_parts(14_532_000, 0) + // Minimum execution time: 7_812_000 picoseconds. + Weight::from_parts(8_412_000, 0) .saturating_add(Weight::from_parts(0, 102287)) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)) @@ -338,8 +338,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `318` // Estimated: `102287` - // Minimum execution time: 15_500_000 picoseconds. - Weight::from_parts(16_219_000, 0) + // Minimum execution time: 8_975_000 picoseconds. + Weight::from_parts(9_389_000, 0) .saturating_add(Weight::from_parts(0, 102287)) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)) @@ -350,8 +350,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `118` // Estimated: `1806` - // Minimum execution time: 16_918_000 picoseconds. - Weight::from_parts(17_898_000, 0) + // Minimum execution time: 10_116_000 picoseconds. + Weight::from_parts(10_550_000, 0) .saturating_add(Weight::from_parts(0, 1806)) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)) @@ -362,8 +362,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `159` // Estimated: `1806` - // Minimum execution time: 18_854_000 picoseconds. - Weight::from_parts(19_924_000, 0) + // Minimum execution time: 11_207_000 picoseconds. + Weight::from_parts(11_767_000, 0) .saturating_add(Weight::from_parts(0, 1806)) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)) @@ -374,8 +374,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `224` // Estimated: `3566` - // Minimum execution time: 54_081_000 picoseconds. - Weight::from_parts(61_848_000, 0) + // Minimum execution time: 33_530_000 picoseconds. + Weight::from_parts(37_591_000, 0) .saturating_add(Weight::from_parts(0, 3566)) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)) From 3c16d04de7accdbb8faf31635d82d5b423b0d80b Mon Sep 17 00:00:00 2001 From: Recrafter Date: Wed, 3 Jul 2024 08:40:09 +0700 Subject: [PATCH 13/15] Adjusting events --- pallets/game/src/lib.rs | 7 ++++--- pallets/game/src/properties.rs | 4 ---- pallets/game/src/tests.rs | 3 +-- pallets/game/src/types.rs | 1 - 4 files changed, 5 insertions(+), 10 deletions(-) diff --git a/pallets/game/src/lib.rs b/pallets/game/src/lib.rs index 7fbb7a9..ed617ff 100644 --- a/pallets/game/src/lib.rs +++ b/pallets/game/src/lib.rs @@ -219,7 +219,7 @@ pub mod pallet { /// A user has received points. PointsReceived { receiver: AccountIdOf, amount: u32 }, /// A game has started. - GameStarted { player: AccountIdOf, game_id: u32, ending_block: BlockNumberFor }, + GameStarted { player: AccountIdOf, game_id: u32, ending_block: BlockNumberFor, property_id: u32 }, /// An answer has been submitted. AnswerSubmitted { player: AccountIdOf, game_id: u32, guess: u32 }, /// The result has been checked. @@ -497,13 +497,14 @@ pub mod pallet { let random_number = u32_value as usize % game_properties.len(); let property = game_properties[random_number].clone(); let game_datas = - GameData { difficulty: game_type, player: signer.clone(), property, guess: None }; + GameData { difficulty: game_type, player: signer.clone(), property: property.clone(), guess: None }; game_properties.retain(|property| property.id as usize != random_number); GameProperties::::put(game_properties); GameInfo::::insert(game_id, game_datas); let next_game_id = game_id.checked_add(1).ok_or(Error::::ArithmeticOverflow)?; GameId::::put(next_game_id); - Self::deposit_event(Event::::GameStarted { player: signer, game_id, ending_block: expiry_block }); + // Submit the encrypted property data and delete the price + Self::deposit_event(Event::::GameStarted { player: signer, game_id, ending_block: expiry_block, property_id: property.id }); Ok(()) } diff --git a/pallets/game/src/properties.rs b/pallets/game/src/properties.rs index eedf82f..d85acac 100644 --- a/pallets/game/src/properties.rs +++ b/pallets/game/src/properties.rs @@ -6,28 +6,24 @@ impl Pallet { let new_property = PropertyInfoData { id: 147229391, data: "nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap(), - price: "kkjfkdjdkdjdkdjdk".as_bytes().to_vec().try_into().unwrap(), }; GameProperties::::try_append(new_property.clone()) .map_err(|_| Error::::TooManyTest)?; let new_property = PropertyInfoData { id: 146480642, data: "nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap(), - price: "kkjfkdjdkdjdkdjdk".as_bytes().to_vec().try_into().unwrap(), }; GameProperties::::try_append(new_property.clone()) .map_err(|_| Error::::TooManyTest)?; let new_property = PropertyInfoData { id: 147031382, data: "nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap(), - price: "kkjfkdjdkdjdkdjdk".as_bytes().to_vec().try_into().unwrap(), }; GameProperties::::try_append(new_property.clone()) .map_err(|_| Error::::TooManyTest)?; let new_property = PropertyInfoData { id: 147031382, data: "nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap(), - price: "kkjfkdjdkdjdkdjdk".as_bytes().to_vec().try_into().unwrap(), }; GameProperties::::try_append(new_property.clone()) .map_err(|_| Error::::TooManyTest)?; diff --git a/pallets/game/src/tests.rs b/pallets/game/src/tests.rs index 58246bd..d907971 100644 --- a/pallets/game/src/tests.rs +++ b/pallets/game/src/tests.rs @@ -947,7 +947,7 @@ fn handle_offer_accept_works() { crate::DifficultyLevel::Player, )); System::assert_last_event( - Event::GameStarted { player: [0; 32].into(), game_id: 6, ending_block: 9 }.into(), + Event::GameStarted { player: [0; 32].into(), game_id: 6, ending_block: 9, property_id: 147229391 }.into(), ); run_to_block(20); assert_eq!(GameModule::users::([0; 32].into()).unwrap().nfts.xorange, 3); @@ -1153,7 +1153,6 @@ fn add_property_works() { let new_property = PropertyInfoData { id: 147031382, data: "nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap(), - price: "kkjfkdjdkdjdkdjdk".as_bytes().to_vec().try_into().unwrap(), }; assert_ok!(GameModule::add_property(RuntimeOrigin::root(), new_property)); assert_eq!(GameModule::game_properties().len(), 5); diff --git a/pallets/game/src/types.rs b/pallets/game/src/types.rs index f44da95..5a514ff 100644 --- a/pallets/game/src/types.rs +++ b/pallets/game/src/types.rs @@ -104,7 +104,6 @@ pub struct OfferInfo { pub struct PropertyInfoData { pub id: u32, pub data: BoundedVec::StringLimit>, - pub price: BoundedVec::StringLimit>, } /// Struct for the user datas. From 9f5208cc3cf361ec2eb01f45cb5f60d3a131bc29 Mon Sep 17 00:00:00 2001 From: Recrafter Date: Wed, 3 Jul 2024 17:50:28 +0700 Subject: [PATCH 14/15] Fixing bug --- pallets/game/src/lib.rs | 6 +++--- pallets/game/src/tests.rs | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pallets/game/src/lib.rs b/pallets/game/src/lib.rs index ed617ff..95e5485 100644 --- a/pallets/game/src/lib.rs +++ b/pallets/game/src/lib.rs @@ -219,7 +219,7 @@ pub mod pallet { /// A user has received points. PointsReceived { receiver: AccountIdOf, amount: u32 }, /// A game has started. - GameStarted { player: AccountIdOf, game_id: u32, ending_block: BlockNumberFor, property_id: u32 }, + GameStarted { player: AccountIdOf, game_id: u32, ending_block: BlockNumberFor }, /// An answer has been submitted. AnswerSubmitted { player: AccountIdOf, game_id: u32, guess: u32 }, /// The result has been checked. @@ -497,14 +497,14 @@ pub mod pallet { let random_number = u32_value as usize % game_properties.len(); let property = game_properties[random_number].clone(); let game_datas = - GameData { difficulty: game_type, player: signer.clone(), property: property.clone(), guess: None }; + GameData { difficulty: game_type, player: signer.clone(), property: property, guess: None }; game_properties.retain(|property| property.id as usize != random_number); GameProperties::::put(game_properties); GameInfo::::insert(game_id, game_datas); let next_game_id = game_id.checked_add(1).ok_or(Error::::ArithmeticOverflow)?; GameId::::put(next_game_id); // Submit the encrypted property data and delete the price - Self::deposit_event(Event::::GameStarted { player: signer, game_id, ending_block: expiry_block, property_id: property.id }); + Self::deposit_event(Event::::GameStarted { player: signer, game_id, ending_block: expiry_block }); Ok(()) } diff --git a/pallets/game/src/tests.rs b/pallets/game/src/tests.rs index d907971..3cd1415 100644 --- a/pallets/game/src/tests.rs +++ b/pallets/game/src/tests.rs @@ -947,7 +947,7 @@ fn handle_offer_accept_works() { crate::DifficultyLevel::Player, )); System::assert_last_event( - Event::GameStarted { player: [0; 32].into(), game_id: 6, ending_block: 9, property_id: 147229391 }.into(), + Event::GameStarted { player: [0; 32].into(), game_id: 6, ending_block: 9 }.into(), ); run_to_block(20); assert_eq!(GameModule::users::([0; 32].into()).unwrap().nfts.xorange, 3); From 1ebcd50ddfb5edbf242a1fd66ea36cd2c5f7795a Mon Sep 17 00:00:00 2001 From: Ganesh oli Date: Sat, 6 Jul 2024 07:48:47 +0545 Subject: [PATCH 15/15] updated v1.11.0 --- Cargo.lock | 240 ++++++++++++++++++++-------------------- node/Cargo.toml | 79 ++++++------- pallets/game/Cargo.toml | 26 +++-- runtime/Cargo.toml | 68 ++++++------ 4 files changed, 209 insertions(+), 204 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a9bd2ad..efe06e0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2230,7 +2230,7 @@ checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" [[package]] name = "fork-tree" version = "3.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "parity-scale-codec", ] @@ -2253,7 +2253,7 @@ checksum = "6c2141d6d6c8512188a7891b4b01590a45f6dac67afb4f255c4124dbb86d4eaa" [[package]] name = "frame-benchmarking" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "frame-support", "frame-support-procedural", @@ -2278,7 +2278,7 @@ dependencies = [ [[package]] name = "frame-benchmarking-cli" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "Inflector", "array-bytes 6.2.2", @@ -2326,7 +2326,7 @@ dependencies = [ [[package]] name = "frame-executive" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "frame-support", "frame-system", @@ -2356,7 +2356,7 @@ dependencies = [ [[package]] name = "frame-remote-externalities" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "futures", "indicatif", @@ -2377,7 +2377,7 @@ dependencies = [ [[package]] name = "frame-support" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "aquamarine", "array-bytes 6.2.2", @@ -2418,7 +2418,7 @@ dependencies = [ [[package]] name = "frame-support-procedural" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "Inflector", "cfg-expr", @@ -2437,7 +2437,7 @@ dependencies = [ [[package]] name = "frame-support-procedural-tools" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "frame-support-procedural-tools-derive", "proc-macro-crate 3.1.0", @@ -2449,7 +2449,7 @@ dependencies = [ [[package]] name = "frame-support-procedural-tools-derive" version = "3.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "proc-macro2", "quote", @@ -2459,7 +2459,7 @@ dependencies = [ [[package]] name = "frame-system" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "cfg-if", "docify", @@ -2479,7 +2479,7 @@ dependencies = [ [[package]] name = "frame-system-benchmarking" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "frame-benchmarking", "frame-support", @@ -2494,7 +2494,7 @@ dependencies = [ [[package]] name = "frame-system-rpc-runtime-api" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "parity-scale-codec", "sp-api", @@ -2503,7 +2503,7 @@ dependencies = [ [[package]] name = "frame-try-runtime" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "frame-support", "parity-scale-codec", @@ -4567,7 +4567,7 @@ dependencies = [ [[package]] name = "node-primitives" version = "2.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "sp-core", "sp-runtime", @@ -4846,7 +4846,7 @@ checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" [[package]] name = "pallet-aura" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "frame-support", "frame-system", @@ -4863,7 +4863,7 @@ dependencies = [ [[package]] name = "pallet-authorship" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "frame-support", "frame-system", @@ -4877,7 +4877,7 @@ dependencies = [ [[package]] name = "pallet-balances" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "frame-benchmarking", "frame-support", @@ -4913,7 +4913,7 @@ dependencies = [ [[package]] name = "pallet-grandpa" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "frame-benchmarking", "frame-support", @@ -4936,7 +4936,7 @@ dependencies = [ [[package]] name = "pallet-insecure-randomness-collective-flip" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "frame-support", "frame-system", @@ -4950,7 +4950,7 @@ dependencies = [ [[package]] name = "pallet-nfts" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "enumflags2", "frame-benchmarking", @@ -4968,7 +4968,7 @@ dependencies = [ [[package]] name = "pallet-session" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "frame-support", "frame-system", @@ -4990,7 +4990,7 @@ dependencies = [ [[package]] name = "pallet-skip-feeless-payment" version = "1.0.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "frame-support", "frame-system", @@ -5003,7 +5003,7 @@ dependencies = [ [[package]] name = "pallet-sudo" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "docify", "frame-benchmarking", @@ -5019,7 +5019,7 @@ dependencies = [ [[package]] name = "pallet-timestamp" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "docify", "frame-benchmarking", @@ -5039,7 +5039,7 @@ dependencies = [ [[package]] name = "pallet-transaction-payment" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "frame-support", "frame-system", @@ -5055,7 +5055,7 @@ dependencies = [ [[package]] name = "pallet-transaction-payment-rpc" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "jsonrpsee", "pallet-transaction-payment-rpc-runtime-api", @@ -5071,7 +5071,7 @@ dependencies = [ [[package]] name = "pallet-transaction-payment-rpc-runtime-api" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "pallet-transaction-payment", "parity-scale-codec", @@ -6245,7 +6245,7 @@ dependencies = [ [[package]] name = "sc-allocator" version = "4.1.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "log", "sp-core", @@ -6256,7 +6256,7 @@ dependencies = [ [[package]] name = "sc-basic-authorship" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "futures", "futures-timer", @@ -6278,7 +6278,7 @@ dependencies = [ [[package]] name = "sc-block-builder" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "parity-scale-codec", "sp-api", @@ -6293,7 +6293,7 @@ dependencies = [ [[package]] name = "sc-chain-spec" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "array-bytes 6.2.2", "docify", @@ -6318,7 +6318,7 @@ dependencies = [ [[package]] name = "sc-chain-spec-derive" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "proc-macro-crate 3.1.0", "proc-macro2", @@ -6329,7 +6329,7 @@ dependencies = [ [[package]] name = "sc-cli" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "array-bytes 6.2.2", "bip39", @@ -6370,7 +6370,7 @@ dependencies = [ [[package]] name = "sc-client-api" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "fnv", "futures", @@ -6397,7 +6397,7 @@ dependencies = [ [[package]] name = "sc-client-db" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "hash-db", "kvdb", @@ -6423,7 +6423,7 @@ dependencies = [ [[package]] name = "sc-consensus" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "async-trait", "futures", @@ -6448,7 +6448,7 @@ dependencies = [ [[package]] name = "sc-consensus-aura" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "async-trait", "futures", @@ -6477,7 +6477,7 @@ dependencies = [ [[package]] name = "sc-consensus-grandpa" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "ahash 0.8.11", "array-bytes 6.2.2", @@ -6519,7 +6519,7 @@ dependencies = [ [[package]] name = "sc-consensus-slots" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "async-trait", "futures", @@ -6542,7 +6542,7 @@ dependencies = [ [[package]] name = "sc-executor" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "parity-scale-codec", "parking_lot 0.12.1", @@ -6564,7 +6564,7 @@ dependencies = [ [[package]] name = "sc-executor-common" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "sc-allocator", "sp-maybe-compressed-blob", @@ -6576,7 +6576,7 @@ dependencies = [ [[package]] name = "sc-executor-wasmtime" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "anyhow", "cfg-if", @@ -6594,7 +6594,7 @@ dependencies = [ [[package]] name = "sc-informant" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "ansi_term", "futures", @@ -6611,7 +6611,7 @@ dependencies = [ [[package]] name = "sc-keystore" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "array-bytes 6.2.2", "parking_lot 0.12.1", @@ -6625,7 +6625,7 @@ dependencies = [ [[package]] name = "sc-mixnet" version = "0.1.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "array-bytes 4.2.0", "arrayvec", @@ -6654,7 +6654,7 @@ dependencies = [ [[package]] name = "sc-network" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "array-bytes 6.2.2", "async-channel", @@ -6697,7 +6697,7 @@ dependencies = [ [[package]] name = "sc-network-bitswap" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "async-channel", "cid", @@ -6717,7 +6717,7 @@ dependencies = [ [[package]] name = "sc-network-common" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "async-trait", "bitflags 1.3.2", @@ -6734,7 +6734,7 @@ dependencies = [ [[package]] name = "sc-network-gossip" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "ahash 0.8.11", "futures", @@ -6753,7 +6753,7 @@ dependencies = [ [[package]] name = "sc-network-light" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "array-bytes 6.2.2", "async-channel", @@ -6774,7 +6774,7 @@ dependencies = [ [[package]] name = "sc-network-sync" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "array-bytes 6.2.2", "async-channel", @@ -6810,7 +6810,7 @@ dependencies = [ [[package]] name = "sc-network-transactions" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "array-bytes 6.2.2", "futures", @@ -6829,7 +6829,7 @@ dependencies = [ [[package]] name = "sc-offchain" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "array-bytes 6.2.2", "bytes", @@ -6863,7 +6863,7 @@ dependencies = [ [[package]] name = "sc-proposer-metrics" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "log", "substrate-prometheus-endpoint", @@ -6872,7 +6872,7 @@ dependencies = [ [[package]] name = "sc-rpc" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "futures", "jsonrpsee", @@ -6904,7 +6904,7 @@ dependencies = [ [[package]] name = "sc-rpc-api" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "jsonrpsee", "parity-scale-codec", @@ -6924,7 +6924,7 @@ dependencies = [ [[package]] name = "sc-rpc-server" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "http", "jsonrpsee", @@ -6939,7 +6939,7 @@ dependencies = [ [[package]] name = "sc-rpc-spec-v2" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "array-bytes 6.2.2", "futures", @@ -6968,7 +6968,7 @@ dependencies = [ [[package]] name = "sc-service" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "async-trait", "directories", @@ -7031,7 +7031,7 @@ dependencies = [ [[package]] name = "sc-state-db" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "log", "parity-scale-codec", @@ -7042,7 +7042,7 @@ dependencies = [ [[package]] name = "sc-statement-store" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "log", "parity-db", @@ -7061,7 +7061,7 @@ dependencies = [ [[package]] name = "sc-sysinfo" version = "6.0.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "derive_more", "futures", @@ -7081,7 +7081,7 @@ dependencies = [ [[package]] name = "sc-telemetry" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "chrono", "futures", @@ -7100,7 +7100,7 @@ dependencies = [ [[package]] name = "sc-tracing" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "ansi_term", "chrono", @@ -7130,7 +7130,7 @@ dependencies = [ [[package]] name = "sc-tracing-proc-macro" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "proc-macro-crate 3.1.0", "proc-macro2", @@ -7141,7 +7141,7 @@ dependencies = [ [[package]] name = "sc-transaction-pool" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "async-trait", "futures", @@ -7167,7 +7167,7 @@ dependencies = [ [[package]] name = "sc-transaction-pool-api" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "async-trait", "futures", @@ -7183,7 +7183,7 @@ dependencies = [ [[package]] name = "sc-utils" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "async-channel", "futures", @@ -7617,7 +7617,7 @@ dependencies = [ [[package]] name = "sp-api" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "hash-db", "log", @@ -7638,7 +7638,7 @@ dependencies = [ [[package]] name = "sp-api-proc-macro" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "Inflector", "blake2 0.10.6", @@ -7652,7 +7652,7 @@ dependencies = [ [[package]] name = "sp-application-crypto" version = "23.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "parity-scale-codec", "scale-info", @@ -7665,7 +7665,7 @@ dependencies = [ [[package]] name = "sp-arithmetic" version = "16.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "integer-sqrt", "num-traits", @@ -7697,7 +7697,7 @@ dependencies = [ [[package]] name = "sp-block-builder" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "sp-api", "sp-inherents", @@ -7708,7 +7708,7 @@ dependencies = [ [[package]] name = "sp-blockchain" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "futures", "log", @@ -7726,7 +7726,7 @@ dependencies = [ [[package]] name = "sp-consensus" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "async-trait", "futures", @@ -7741,7 +7741,7 @@ dependencies = [ [[package]] name = "sp-consensus-aura" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "async-trait", "parity-scale-codec", @@ -7758,7 +7758,7 @@ dependencies = [ [[package]] name = "sp-consensus-babe" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "async-trait", "parity-scale-codec", @@ -7777,7 +7777,7 @@ dependencies = [ [[package]] name = "sp-consensus-grandpa" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "finality-grandpa", "log", @@ -7795,7 +7795,7 @@ dependencies = [ [[package]] name = "sp-consensus-slots" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "parity-scale-codec", "scale-info", @@ -7807,7 +7807,7 @@ dependencies = [ [[package]] name = "sp-core" version = "21.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "array-bytes 6.2.2", "bandersnatch_vrfs", @@ -7853,7 +7853,7 @@ dependencies = [ [[package]] name = "sp-core-hashing" version = "9.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "blake2b_simd", "byteorder", @@ -7866,7 +7866,7 @@ dependencies = [ [[package]] name = "sp-core-hashing-proc-macro" version = "9.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "quote", "sp-core-hashing", @@ -7896,7 +7896,7 @@ dependencies = [ [[package]] name = "sp-database" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "kvdb", "parking_lot 0.12.1", @@ -7905,7 +7905,7 @@ dependencies = [ [[package]] name = "sp-debug-derive" version = "8.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "proc-macro2", "quote", @@ -7925,7 +7925,7 @@ dependencies = [ [[package]] name = "sp-externalities" version = "0.19.0" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "environmental", "parity-scale-codec", @@ -7946,7 +7946,7 @@ dependencies = [ [[package]] name = "sp-genesis-builder" version = "0.1.0" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "serde_json", "sp-api", @@ -7957,7 +7957,7 @@ dependencies = [ [[package]] name = "sp-inherents" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "async-trait", "impl-trait-for-tuples", @@ -7971,7 +7971,7 @@ dependencies = [ [[package]] name = "sp-io" version = "23.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "bytes", "ed25519-dalek", @@ -7995,7 +7995,7 @@ dependencies = [ [[package]] name = "sp-keyring" version = "24.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "sp-core", "sp-runtime", @@ -8005,7 +8005,7 @@ dependencies = [ [[package]] name = "sp-keystore" version = "0.27.0" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "parity-scale-codec", "parking_lot 0.12.1", @@ -8017,7 +8017,7 @@ dependencies = [ [[package]] name = "sp-maybe-compressed-blob" version = "4.1.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "thiserror", "zstd 0.12.4", @@ -8026,7 +8026,7 @@ dependencies = [ [[package]] name = "sp-metadata-ir" version = "0.1.0" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "frame-metadata", "parity-scale-codec", @@ -8037,7 +8037,7 @@ dependencies = [ [[package]] name = "sp-mixnet" version = "0.1.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "parity-scale-codec", "scale-info", @@ -8049,7 +8049,7 @@ dependencies = [ [[package]] name = "sp-offchain" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "sp-api", "sp-core", @@ -8059,7 +8059,7 @@ dependencies = [ [[package]] name = "sp-panic-handler" version = "8.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "backtrace", "lazy_static", @@ -8069,7 +8069,7 @@ dependencies = [ [[package]] name = "sp-rpc" version = "6.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "rustc-hash", "serde", @@ -8079,7 +8079,7 @@ dependencies = [ [[package]] name = "sp-runtime" version = "24.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "docify", "either", @@ -8103,7 +8103,7 @@ dependencies = [ [[package]] name = "sp-runtime-interface" version = "17.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "bytes", "impl-trait-for-tuples", @@ -8140,7 +8140,7 @@ dependencies = [ [[package]] name = "sp-runtime-interface-proc-macro" version = "11.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "Inflector", "expander", @@ -8166,7 +8166,7 @@ dependencies = [ [[package]] name = "sp-session" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "parity-scale-codec", "scale-info", @@ -8181,7 +8181,7 @@ dependencies = [ [[package]] name = "sp-staking" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "impl-trait-for-tuples", "parity-scale-codec", @@ -8195,7 +8195,7 @@ dependencies = [ [[package]] name = "sp-state-machine" version = "0.28.0" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "hash-db", "log", @@ -8216,7 +8216,7 @@ dependencies = [ [[package]] name = "sp-statement-store" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "aes-gcm", "curve25519-dalek 4.1.2", @@ -8240,7 +8240,7 @@ dependencies = [ [[package]] name = "sp-std" version = "8.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" [[package]] name = "sp-std" @@ -8250,7 +8250,7 @@ source = "git+https://github.com/paritytech/polkadot-sdk#63e264446f6cabff06be729 [[package]] name = "sp-storage" version = "13.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "impl-serde", "parity-scale-codec", @@ -8275,7 +8275,7 @@ dependencies = [ [[package]] name = "sp-timestamp" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "async-trait", "parity-scale-codec", @@ -8288,7 +8288,7 @@ dependencies = [ [[package]] name = "sp-tracing" version = "10.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "parity-scale-codec", "sp-std 8.0.0", @@ -8311,7 +8311,7 @@ dependencies = [ [[package]] name = "sp-transaction-pool" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "sp-api", "sp-runtime", @@ -8320,7 +8320,7 @@ dependencies = [ [[package]] name = "sp-transaction-storage-proof" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "async-trait", "parity-scale-codec", @@ -8335,7 +8335,7 @@ dependencies = [ [[package]] name = "sp-trie" version = "22.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "ahash 0.8.11", "hash-db", @@ -8359,7 +8359,7 @@ dependencies = [ [[package]] name = "sp-version" version = "22.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "impl-serde", "parity-scale-codec", @@ -8376,7 +8376,7 @@ dependencies = [ [[package]] name = "sp-version-proc-macro" version = "8.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "parity-scale-codec", "proc-macro2", @@ -8387,7 +8387,7 @@ dependencies = [ [[package]] name = "sp-wasm-interface" version = "14.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "anyhow", "impl-trait-for-tuples", @@ -8410,7 +8410,7 @@ dependencies = [ [[package]] name = "sp-weights" version = "20.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "bounded-collections", "parity-scale-codec", @@ -8573,12 +8573,12 @@ dependencies = [ [[package]] name = "substrate-build-script-utils" version = "3.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" [[package]] name = "substrate-frame-rpc-system" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "frame-system-rpc-runtime-api", "futures", @@ -8597,7 +8597,7 @@ dependencies = [ [[package]] name = "substrate-prometheus-endpoint" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "hyper", "log", @@ -8609,7 +8609,7 @@ dependencies = [ [[package]] name = "substrate-rpc-client" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "async-trait", "jsonrpsee", @@ -8622,7 +8622,7 @@ dependencies = [ [[package]] name = "substrate-wasm-builder" version = "5.0.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "ansi_term", "build-helper", @@ -9229,7 +9229,7 @@ checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" [[package]] name = "try-runtime-cli" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.6.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.11.0#481165d92297d7dfd5eaf9c7f442441761fc0a12" dependencies = [ "async-trait", "clap", diff --git a/node/Cargo.toml b/node/Cargo.toml index 4a94998..8215dec 100644 --- a/node/Cargo.toml +++ b/node/Cargo.toml @@ -18,56 +18,56 @@ name = "node-template" [dependencies] clap = { version = "4.4.2", features = ["derive"] } -futures = { version = "0.3.21", features = ["thread-pool"]} +futures = { version = "0.3.21", features = ["thread-pool"] } -sc-cli = { version = "0.10.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } -sp-core = { version = "21.0.0", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } -sc-executor = { version = "0.10.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } -sc-network = { version = "0.10.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } -sc-service = { version = "0.10.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } -sc-telemetry = { version = "4.0.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } -sc-transaction-pool = { version = "4.0.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } -sc-transaction-pool-api = { version = "4.0.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } -sc-offchain = { version = "4.0.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } -sc-statement-store = { version = "4.0.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } -sc-consensus-aura = { version = "0.10.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } -sp-consensus-aura = { version = "0.10.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } -sc-consensus = { version = "0.10.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } -sc-consensus-grandpa = { version = "0.10.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } -sp-consensus-grandpa = { version = "4.0.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } -sp-keystore = {git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } -sc-client-api = { version = "4.0.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } -sp-runtime = { version = "24.0.0", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } -sp-io = { version = "23.0.0", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } -sp-timestamp = { version = "4.0.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } -sp-inherents = { version = "4.0.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } -sp-keyring = { version = "24.0.0", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } -frame-system = { version = "4.0.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } -pallet-transaction-payment = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } -pallet-skip-feeless-payment = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } +sc-cli = { version = "0.10.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } +sp-core = { version = "21.0.0", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } +sc-executor = { version = "0.10.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } +sc-network = { version = "0.10.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } +sc-service = { version = "0.10.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } +sc-telemetry = { version = "4.0.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } +sc-transaction-pool = { version = "4.0.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } +sc-transaction-pool-api = { version = "4.0.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } +sc-offchain = { version = "4.0.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } +sc-statement-store = { version = "4.0.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } +sc-consensus-aura = { version = "0.10.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } +sp-consensus-aura = { version = "0.10.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } +sc-consensus = { version = "0.10.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } +sc-consensus-grandpa = { version = "0.10.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } +sp-consensus-grandpa = { version = "4.0.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } +sp-keystore = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } +sc-client-api = { version = "4.0.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } +sp-runtime = { version = "24.0.0", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } +sp-io = { version = "23.0.0", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } +sp-timestamp = { version = "4.0.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } +sp-inherents = { version = "4.0.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } +sp-keyring = { version = "24.0.0", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } +frame-system = { version = "4.0.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } +pallet-transaction-payment = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } +pallet-skip-feeless-payment = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } # These dependencies are used for the node template's RPCs jsonrpsee = { version = "0.16.2", features = ["server"] } -sp-api = { version = "4.0.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } -sc-rpc-api = { version = "0.10.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } -sp-blockchain = { version = "4.0.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } -sp-block-builder = { version = "4.0.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } -sc-basic-authorship = { version = "0.10.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } -substrate-frame-rpc-system = { version = "4.0.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } -pallet-transaction-payment-rpc = { version = "4.0.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } +sp-api = { version = "4.0.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } +sc-rpc-api = { version = "0.10.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } +sp-blockchain = { version = "4.0.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } +sp-block-builder = { version = "4.0.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } +sc-basic-authorship = { version = "0.10.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } +substrate-frame-rpc-system = { version = "4.0.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } +pallet-transaction-payment-rpc = { version = "4.0.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } # These dependencies are used for runtime benchmarking -frame-benchmarking = { version = "4.0.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } -frame-benchmarking-cli = { version = "4.0.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } +frame-benchmarking = { version = "4.0.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } +frame-benchmarking-cli = { version = "4.0.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } # Local Dependencies node-template-runtime = { version = "4.0.0-dev", path = "../runtime" } # CLI-specific dependencies -try-runtime-cli = { version = "0.10.0-dev", optional = true, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } +try-runtime-cli = { version = "0.10.0-dev", optional = true, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } [build-dependencies] -substrate-build-script-utils = { version = "3.0.0", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } +substrate-build-script-utils = { version = "3.0.0", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } [features] default = [] @@ -79,4 +79,7 @@ runtime-benchmarks = [ ] # Enable features that allow the runtime to be tried and debugged. Name might be subject to change # in the near future. -try-runtime = ["node-template-runtime/try-runtime", "try-runtime-cli/try-runtime"] \ No newline at end of file +try-runtime = [ + "node-template-runtime/try-runtime", + "try-runtime-cli/try-runtime", +] diff --git a/pallets/game/Cargo.toml b/pallets/game/Cargo.toml index 8a95701..cfa0157 100644 --- a/pallets/game/Cargo.toml +++ b/pallets/game/Cargo.toml @@ -17,23 +17,25 @@ serde_json = { version = "1.0", default-features = false, features = ["alloc"] } codec = { package = "parity-scale-codec", version = "3.6.1", default-features = false, features = [ "derive", ] } -scale-info = { version = "2.5.0", default-features = false, features = ["derive"] } +scale-info = { version = "2.5.0", default-features = false, features = [ + "derive", +] } serde = { version = "1.0.197", features = ["derive"], optional = true } -frame-benchmarking = { version = "4.0.0-dev", default-features = false, optional = true, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } -frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } -frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } -sp-std = { version = "8.0.0", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0", default-features = false } +frame-benchmarking = { version = "4.0.0-dev", default-features = false, optional = true, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } +frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } +frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } +sp-std = { version = "8.0.0", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0", default-features = false } -pallet-nfts = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.6.0" } +pallet-nfts = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.11.0" } enumflags2 = { version = "0.7.7" } [dev-dependencies] -sp-io = { version = "23.0.0", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0", default-features = false } -sp-core = { version = "21.0.0", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0", default-features = false } -sp-runtime = { version = "24.0.0", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0", default-features = false } +sp-io = { version = "23.0.0", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0", default-features = false } +sp-core = { version = "21.0.0", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0", default-features = false } +sp-runtime = { version = "24.0.0", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0", default-features = false } -pallet-insecure-randomness-collective-flip = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.6.0" } -pallet-balances = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.6.0" } +pallet-insecure-randomness-collective-flip = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.11.0" } +pallet-balances = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.11.0" } [features] default = ["std"] @@ -49,4 +51,4 @@ std = [ "sp-std/std", ] runtime-benchmarks = ["frame-benchmarking/runtime-benchmarks"] -try-runtime = ["frame-support/try-runtime"] \ No newline at end of file +try-runtime = ["frame-support/try-runtime"] diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index d9e90bf..5942b5b 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -21,52 +21,52 @@ scale-info = { version = "2.5.0", default-features = false, features = [ ] } log = { version = '0.4.14', default-features = false } -sp-genesis-builder = { version = "0.1.0", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } +sp-genesis-builder = { version = "0.1.0", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } -pallet-aura = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } -pallet-balances = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } -frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } -pallet-grandpa = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } -pallet-sudo = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } -frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } -frame-try-runtime = { version = "0.10.0-dev", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", optional = true, tag = "polkadot-v1.6.0" } -pallet-timestamp = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } -pallet-transaction-payment = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } -frame-executive = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } -sp-api = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } -sp-block-builder = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } -sp-consensus-aura = { version = "0.10.0-dev", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } -sp-consensus-grandpa = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } -sp-core = { version = "21.0.0", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } -sp-inherents = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } -sp-offchain = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } -sp-runtime = { version = "24.0.0", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } -sp-session = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } -sp-std = { version = "8.0.0", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } -sp-storage = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.6.0" } -sp-transaction-pool = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } -sp-version = { version = "22.0.0", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } +pallet-aura = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } +pallet-balances = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } +frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } +pallet-grandpa = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } +pallet-sudo = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } +frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } +frame-try-runtime = { version = "0.10.0-dev", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", optional = true, tag = "polkadot-v1.11.0" } +pallet-timestamp = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } +pallet-transaction-payment = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } +frame-executive = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } +sp-api = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } +sp-block-builder = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } +sp-consensus-aura = { version = "0.10.0-dev", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } +sp-consensus-grandpa = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } +sp-core = { version = "21.0.0", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } +sp-inherents = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } +sp-offchain = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } +sp-runtime = { version = "24.0.0", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } +sp-session = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } +sp-std = { version = "8.0.0", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } +sp-storage = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.11.0" } +sp-transaction-pool = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } +sp-version = { version = "22.0.0", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } serde_json = { version = "1.0.111", default-features = false, features = [ "alloc", ] } -pallet-nfts = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.6.0" } -node-primitives = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.6.0" } -pallet-insecure-randomness-collective-flip = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.6.0" } -pallet-skip-feeless-payment = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.6.0" } +pallet-nfts = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.11.0" } +node-primitives = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.11.0" } +pallet-insecure-randomness-collective-flip = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.11.0" } +pallet-skip-feeless-payment = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.11.0" } # Used for the node template's RPCs -frame-system-rpc-runtime-api = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } -pallet-transaction-payment-rpc-runtime-api = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.6.0" } +frame-system-rpc-runtime-api = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } +pallet-transaction-payment-rpc-runtime-api = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.11.0" } # Used for runtime benchmarking -frame-benchmarking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", optional = true, tag = "polkadot-v1.6.0" } -frame-system-benchmarking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", optional = true, tag = "polkadot-v1.6.0" } +frame-benchmarking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", optional = true, tag = "polkadot-v1.11.0" } +frame-system-benchmarking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", optional = true, tag = "polkadot-v1.11.0" } # Local Dependencies pallet-game = { version = "4.0.0-dev", default-features = false, path = "../pallets/game" } [build-dependencies] -substrate-wasm-builder = { version = "5.0.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", optional = true, tag = "polkadot-v1.6.0" } +substrate-wasm-builder = { version = "5.0.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", optional = true, tag = "polkadot-v1.11.0" } [features] default = ["std"] @@ -139,4 +139,4 @@ try-runtime = [ "pallet-nfts/try-runtime", "pallet-insecure-randomness-collective-flip/try-runtime", "pallet-skip-feeless-payment/try-runtime", -] \ No newline at end of file +]