From 673ab51ad74113abed58455de8cc28001686d8fa Mon Sep 17 00:00:00 2001 From: Sergej Date: Wed, 29 May 2024 20:52:24 +0200 Subject: [PATCH] fix warnings & dummy test --- pallets/orders/src/mock.rs | 19 +++++++++++-------- pallets/orders/src/tests.rs | 32 ++++++++++++++++++++++++++++++++ pallets/orders/src/types.rs | 8 ++++---- primitives/parachain/src/lib.rs | 4 +--- 4 files changed, 48 insertions(+), 15 deletions(-) diff --git a/pallets/orders/src/mock.rs b/pallets/orders/src/mock.rs index 4d7909c..99ab82e 100644 --- a/pallets/orders/src/mock.rs +++ b/pallets/orders/src/mock.rs @@ -13,20 +13,15 @@ // You should have received a copy of the GNU General Public License // along with RegionX. If not, see . -use frame_support::{ - pallet_prelude::*, - parameter_types, - traits::{nonfungible::Mutate, Everything}, -}; +use frame_support::{pallet_prelude::*, parameter_types, traits::Everything}; use parachain_primitives::ParaId; use sp_core::{ConstU64, H256}; use sp_runtime::{ - traits::{BlakeTwo256, BlockNumberProvider, IdentityLookup}, - AccountId32, BuildStorage, DispatchResult, + traits::{BlakeTwo256, IdentityLookup}, + AccountId32, BuildStorage, }; use xcm::opaque::lts::NetworkId; -use std::sync::Arc; use xcm_builder::{ AccountId32Aliases, ChildParachainConvertsVia, DescribeAllTerminal, HashedDescription, }; @@ -34,6 +29,9 @@ use xcm_builder::{ type AccountId = AccountId32; type Block = frame_system::mocking::MockBlock; +pub const ALICE: AccountId = AccountId::new([0u8; 32]); +pub const BOB: AccountId = AccountId::new([1u8; 32]); + // Configure a mock runtime to test the pallet. frame_support::construct_runtime!( pub enum Test @@ -120,6 +118,11 @@ impl crate::Config for Test { // Build genesis storage according to the mock runtime. pub fn new_test_ext() -> sp_io::TestExternalities { let mut t = frame_system::GenesisConfig::::default().build_storage().unwrap(); + pallet_balances::GenesisConfig:: { + balances: vec![(ALICE, 10_000_000), (BOB, 10_000_000)], + } + .assimilate_storage(&mut t) + .unwrap(); let mut ext = sp_io::TestExternalities::new(t); ext.execute_with(|| System::set_block_number(1)); ext diff --git a/pallets/orders/src/tests.rs b/pallets/orders/src/tests.rs index 8b13789..6099aa1 100644 --- a/pallets/orders/src/tests.rs +++ b/pallets/orders/src/tests.rs @@ -1 +1,33 @@ +// This file is part of RegionX. +// +// RegionX is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// RegionX is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with RegionX. If not, see . +use crate::{mock::*, Requirements}; +use frame_support::assert_ok; + +#[test] +fn create_order_works() { + new_test_ext().execute_with(|| { + // TODO + assert_ok!(Orders::create_order( + RuntimeOrigin::signed(ALICE), + 2000.into(), + Requirements { + begin: 0, + end: 8, + core_occupancy: 28800 // Half of a core. + } + )); + }); +} diff --git a/pallets/orders/src/types.rs b/pallets/orders/src/types.rs index 4d1ca97..4d1c2e1 100644 --- a/pallets/orders/src/types.rs +++ b/pallets/orders/src/types.rs @@ -27,11 +27,11 @@ pub type OrderId = u32; #[derive(Encode, Decode, Debug, Clone, PartialEq, Eq, TypeInfo, MaxEncodedLen)] pub struct Requirements { /// The timeslice at which the Region begins. - begin: Timeslice, + pub begin: Timeslice, /// The timeslice at which the Region ends. - end: Timeslice, - /// The minimum proportion of the core that the region should occupy. - core_occupancy: PartsOf57600, + pub end: Timeslice, + /// The minimum fraction of the core that the region should occupy. + pub core_occupancy: PartsOf57600, } /// The information we store about a Coretime order. diff --git a/primitives/parachain/src/lib.rs b/primitives/parachain/src/lib.rs index 45cdaa3..f5ccb9f 100644 --- a/primitives/parachain/src/lib.rs +++ b/primitives/parachain/src/lib.rs @@ -17,10 +17,8 @@ //! //! Code copied from polkadot-sdk: https://github.com/paritytech/polkadot-sdk/blob/master/polkadot/runtime/parachains/src/origin.rs -use codec::{CompactAs, Decode, Encode, MaxEncodedLen}; pub use cumulus_primitives_core::ParaId; -use scale_info::TypeInfo; -use sp_runtime::{traits::BadOrigin, RuntimeDebug}; +use sp_runtime::traits::BadOrigin; use sp_std::result; pub use pallet::*;