git.delta.rocks / unique-network / refs/commits / c3c95caf228f

difftreelog

test fix build

Yaroslav Bolyukin2023-10-09parent: #22a5178.patch.diff
in: master

9 files changed

modifiedpallets/collator-selection/src/mock.rsdiffbeforeafterboth
--- a/pallets/collator-selection/src/mock.rs
+++ b/pallets/collator-selection/src/mock.rs
@@ -32,23 +32,22 @@
 
 use frame_support::{
 	ord_parameter_types, parameter_types,
-	traits::{FindAuthor, GenesisBuild, ValidatorRegistration},
+	traits::{ConstU32, FindAuthor, ValidatorRegistration},
 	PalletId,
 };
 use frame_system as system;
 use frame_system::EnsureSignedBy;
-use sp_core::H256;
+use sp_core::{ConstBool, H256};
 use sp_runtime::{
-	testing::{Header, UintAuthorityId},
+	testing::UintAuthorityId,
 	traits::{BlakeTwo256, IdentityLookup, OpaqueKeys},
-	Perbill, RuntimeAppPublic,
+	BuildStorage, Perbill, RuntimeAppPublic,
 };
 
 use super::*;
 use crate as collator_selection;
 
-type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
-type Block = frame_system::mocking::MockBlock<Test>;
+type Block = frame_system::mocking::MockBlockU32<Test>;
 
 // Configure a mock runtime to test the pallet.
 frame_support::construct_runtime!(
@@ -64,12 +63,13 @@
 );
 
 parameter_types! {
-	pub const BlockHashCount: u64 = 250;
+	pub const BlockHashCount: u32 = 250;
 	pub const SS58Prefix: u8 = 42;
 }
 
 impl system::Config for Test {
 	type BaseCallFilter = frame_support::traits::Everything;
+	type Block = Block;
 	type BlockWeights = ();
 	type BlockLength = ();
 	type DbWeight = ();
@@ -90,7 +90,7 @@
 	type SystemWeightInfo = ();
 	type SS58Prefix = SS58Prefix;
 	type OnSetCode = ();
-	type MaxConsumers = frame_support::traits::ConstU32<16>;
+	type MaxConsumers = ConstU32<16>;
 }
 
 parameter_types! {
@@ -113,6 +113,7 @@
 	type FreezeIdentifier = [u8; 16];
 	type MaxHolds = MaxHolds;
 	type MaxFreezes = MaxFreezes;
+	type RuntimeHoldReason = RuntimeHoldReason;
 }
 
 pub struct Author4;
@@ -145,6 +146,7 @@
 	type AuthorityId = sp_consensus_aura::sr25519::AuthorityId;
 	type MaxAuthorities = MaxAuthorities;
 	type DisabledValidators = ();
+	type AllowMultipleBlocksPerSlot = ConstBool<true>;
 }
 
 sp_runtime::impl_opaque_keys! {
@@ -162,27 +164,27 @@
 
 parameter_types! {
 	pub static SessionHandlerCollators: Vec<u64> = Vec::new();
-	pub static SessionChangeBlock: u64 = 0;
+	pub static SessionChangeBlock: u32 = 0;
 }
 
 pub struct TestSessionHandler;
 impl pallet_session::SessionHandler<u64> for TestSessionHandler {
 	const KEY_TYPE_IDS: &'static [sp_runtime::KeyTypeId] = &[UintAuthorityId::ID];
 	fn on_genesis_session<Ks: OpaqueKeys>(keys: &[(u64, Ks)]) {
-		SessionHandlerCollators::set(keys.into_iter().map(|(a, _)| *a).collect::<Vec<_>>())
+		SessionHandlerCollators::set(keys.iter().map(|(a, _)| *a).collect::<Vec<_>>())
 	}
 	fn on_new_session<Ks: OpaqueKeys>(_: bool, keys: &[(u64, Ks)], _: &[(u64, Ks)]) {
 		SessionChangeBlock::set(System::block_number());
 		dbg!(keys.len());
-		SessionHandlerCollators::set(keys.into_iter().map(|(a, _)| *a).collect::<Vec<_>>())
+		SessionHandlerCollators::set(keys.iter().map(|(a, _)| *a).collect::<Vec<_>>())
 	}
 	fn on_before_session_ending() {}
 	fn on_disabled(_: u32) {}
 }
 
 parameter_types! {
-	pub const Offset: u64 = 0;
-	pub const Period: u64 = 10;
+	pub const Offset: u32 = 0;
+	pub const Period: u32 = 10;
 }
 
 impl pallet_session::Config for Test {
@@ -201,7 +203,7 @@
 parameter_types! {
 	pub const MaxCollators: u32 = 5;
 	pub const LicenseBond: u64 = 10;
-	pub const KickThreshold: u64 = 10;
+	pub const KickThreshold: u32 = 10;
 	// the following values do not matter and are meaningless, etc.
 	pub const DefaultWeightToFeeCoefficient: u64 = 100_000;
 	pub const DefaultMinGasPrice: u64 = 100_000;
@@ -230,6 +232,7 @@
 
 impl Config for Test {
 	type RuntimeEvent = RuntimeEvent;
+	type RuntimeHoldReason = RuntimeHoldReason;
 	type UpdateOrigin = EnsureSignedBy<RootAccount, u64>;
 	type PotId = PotId;
 	type MaxCollators = MaxCollators;
@@ -238,7 +241,6 @@
 	type ValidatorId = <Self as frame_system::Config>::AccountId;
 	type ValidatorIdOf = IdentityCollator;
 	type ValidatorRegistration = IsRegistered;
-	type LicenceBondIdentifier = LicenceBondIdentifier;
 	type Currency = Balances;
 	type DesiredCollators = MaxCollators;
 	type LicenseBond = LicenseBond;
@@ -248,8 +250,8 @@
 
 pub fn new_test_ext() -> sp_io::TestExternalities {
 	sp_tracing::try_init_simple();
-	let mut t = frame_system::GenesisConfig::default()
-		.build_storage::<Test>()
+	let mut t = <frame_system::GenesisConfig<Test>>::default()
+		.build_storage()
 		.unwrap();
 	let invulnerables = vec![1, 2];
 
@@ -284,9 +286,9 @@
 	t.into()
 }
 
-pub fn initialize_to_block(n: u64) {
+pub fn initialize_to_block(n: u32) {
 	for i in System::block_number() + 1..=n {
 		System::set_block_number(i);
-		<AllPalletsWithSystem as frame_support::traits::OnInitialize<u64>>::on_initialize(i);
+		<AllPalletsWithSystem as frame_support::traits::OnInitialize<u32>>::on_initialize(i);
 	}
 }
modifiedpallets/collator-selection/src/tests.rsdiffbeforeafterboth
--- a/pallets/collator-selection/src/tests.rs
+++ b/pallets/collator-selection/src/tests.rs
@@ -32,10 +32,10 @@
 
 use frame_support::{
 	assert_noop, assert_ok,
-	traits::{fungible, GenesisBuild, OnInitialize},
+	traits::{fungible, OnInitialize},
 };
 use scale_info::prelude::*;
-use sp_runtime::{traits::BadOrigin, TokenError};
+use sp_runtime::{traits::BadOrigin, BuildStorage, TokenError};
 
 use crate::{self as collator_selection, mock::*, Config, Error};
 
@@ -464,8 +464,8 @@
 #[should_panic = "duplicate invulnerables in genesis."]
 fn cannot_set_genesis_value_twice() {
 	sp_tracing::try_init_simple();
-	let mut t = frame_system::GenesisConfig::default()
-		.build_storage::<Test>()
+	let mut t = <frame_system::GenesisConfig<Test>>::default()
+		.build_storage()
 		.unwrap();
 	let invulnerables = vec![1, 1];
 
modifiedpallets/identity/src/tests.rsdiffbeforeafterboth
before · pallets/identity/src/tests.rs
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617// Original license:18// This file is part of Substrate.1920// Copyright (C) 2019-2022 Parity Technologies (UK) Ltd.21// SPDX-License-Identifier: Apache-2.02223// Licensed under the Apache License, Version 2.0 (the "License");24// you may not use this file except in compliance with the License.25// You may obtain a copy of the License at26//27// 	http://www.apache.org/licenses/LICENSE-2.028//29// Unless required by applicable law or agreed to in writing, software30// distributed under the License is distributed on an "AS IS" BASIS,31// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.32// See the License for the specific language governing permissions and33// limitations under the License.3435// Tests for Identity Pallet3637use frame_support::{38	assert_noop, assert_ok, ord_parameter_types, parameter_types,39	traits::{ConstU32, ConstU64, EitherOfDiverse},40	BoundedVec,41};42use frame_system::{EnsureRoot, EnsureSignedBy};43use parity_scale_codec::{Decode, Encode};44use sp_core::H256;45use sp_runtime::{46	testing::Header,47	traits::{BadOrigin, BlakeTwo256, IdentityLookup},48	BuildStorage,49};5051use super::*;52use crate as pallet_identity;5354type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;55type Block = frame_system::mocking::MockBlock<Test>;5657frame_support::construct_runtime!(58	pub enum Test {59		System: frame_system,60		Balances: pallet_balances,61		Identity: pallet_identity,62	}63);6465parameter_types! {66	pub BlockWeights: frame_system::limits::BlockWeights =67		frame_system::limits::BlockWeights::simple_max(frame_support::weights::Weight::from_parts(1024, 0));68}69impl frame_system::Config for Test {70	type BaseCallFilter = frame_support::traits::Everything;71	type Block = Block;72	type BlockWeights = ();73	type BlockLength = ();74	type RuntimeOrigin = RuntimeOrigin;75	type Nonce = u64;76	type Hash = H256;77	type RuntimeCall = RuntimeCall;78	type Hashing = BlakeTwo256;79	type AccountId = u64;80	type Lookup = IdentityLookup<Self::AccountId>;81	type RuntimeEvent = RuntimeEvent;82	type BlockHashCount = ConstU64<250>;83	type DbWeight = ();84	type Version = ();85	type PalletInfo = PalletInfo;86	type AccountData = pallet_balances::AccountData<u64>;87	type OnNewAccount = ();88	type OnKilledAccount = ();89	type SystemWeightInfo = ();90	type SS58Prefix = ();91	type OnSetCode = ();92	type MaxConsumers = ConstU32<16>;93}9495impl pallet_balances::Config for Test {96	type Balance = u64;97	type RuntimeEvent = RuntimeEvent;98	type DustRemoval = ();99	type ExistentialDeposit = ConstU64<1>;100	type AccountStore = System;101	type MaxLocks = ();102	type MaxReserves = ();103	type ReserveIdentifier = [u8; 8];104	type WeightInfo = ();105	type RuntimeHoldReason = RuntimeHoldReason;106	type FreezeIdentifier = ();107	type MaxHolds = ();108	type MaxFreezes = ();109}110111parameter_types! {112	pub const MaxAdditionalFields: u32 = 2;113	pub const MaxRegistrars: u32 = 20;114}115116ord_parameter_types! {117	pub const One: u64 = 1;118	pub const Two: u64 = 2;119}120type EnsureOneOrRoot = EitherOfDiverse<EnsureRoot<u64>, EnsureSignedBy<One, u64>>;121type EnsureTwoOrRoot = EitherOfDiverse<EnsureRoot<u64>, EnsureSignedBy<Two, u64>>;122impl pallet_identity::Config for Test {123	type RuntimeEvent = RuntimeEvent;124	type Currency = Balances;125	type Slashed = ();126	type BasicDeposit = ConstU64<10>;127	type FieldDeposit = ConstU64<10>;128	type SubAccountDeposit = ConstU64<10>;129	type MaxSubAccounts = ConstU32<2>;130	type MaxAdditionalFields = MaxAdditionalFields;131	type MaxRegistrars = MaxRegistrars;132	type RegistrarOrigin = EnsureOneOrRoot;133	type ForceOrigin = EnsureTwoOrRoot;134	type WeightInfo = ();135}136137pub fn new_test_ext() -> sp_io::TestExternalities {138	let mut t = <frame_system::GenesisConfig<Test>>::default()139		.build_storage()140		.unwrap();141	pallet_balances::GenesisConfig::<Test> {142		balances: vec![(1, 10), (2, 10), (3, 10), (10, 100), (20, 100), (30, 100)],143	}144	.assimilate_storage(&mut t)145	.unwrap();146	t.into()147}148149fn ten() -> IdentityInfo<MaxAdditionalFields> {150	IdentityInfo {151		display: Data::Raw(b"ten".to_vec().try_into().unwrap()),152		legal: Data::Raw(b"The Right Ordinal Ten, Esq.".to_vec().try_into().unwrap()),153		..Default::default()154	}155}156157fn twenty() -> IdentityInfo<MaxAdditionalFields> {158	IdentityInfo {159		display: Data::Raw(b"twenty".to_vec().try_into().unwrap()),160		legal: Data::Raw(161			b"The Right Ordinal Twenty, Esq."162				.to_vec()163				.try_into()164				.unwrap(),165		),166		..Default::default()167	}168}169170#[test]171fn editing_subaccounts_should_work() {172	new_test_ext().execute_with(|| {173		let data = |x| Data::Raw(vec![x; 1].try_into().unwrap());174175		assert_noop!(176			Identity::add_sub(RuntimeOrigin::signed(10), 20, data(1)),177			Error::<Test>::NoIdentity178		);179180		assert_ok!(Identity::set_identity(181			RuntimeOrigin::signed(10),182			Box::new(ten())183		));184185		// first sub account186		assert_ok!(Identity::add_sub(RuntimeOrigin::signed(10), 1, data(1)));187		assert_eq!(SuperOf::<Test>::get(1), Some((10, data(1))));188		assert_eq!(Balances::free_balance(10), 80);189190		// second sub account191		assert_ok!(Identity::add_sub(RuntimeOrigin::signed(10), 2, data(2)));192		assert_eq!(SuperOf::<Test>::get(1), Some((10, data(1))));193		assert_eq!(SuperOf::<Test>::get(2), Some((10, data(2))));194		assert_eq!(Balances::free_balance(10), 70);195196		// third sub account is too many197		assert_noop!(198			Identity::add_sub(RuntimeOrigin::signed(10), 3, data(3)),199			Error::<Test>::TooManySubAccounts200		);201202		// rename first sub account203		assert_ok!(Identity::rename_sub(RuntimeOrigin::signed(10), 1, data(11)));204		assert_eq!(SuperOf::<Test>::get(1), Some((10, data(11))));205		assert_eq!(SuperOf::<Test>::get(2), Some((10, data(2))));206		assert_eq!(Balances::free_balance(10), 70);207208		// remove first sub account209		assert_ok!(Identity::remove_sub(RuntimeOrigin::signed(10), 1));210		assert_eq!(SuperOf::<Test>::get(1), None);211		assert_eq!(SuperOf::<Test>::get(2), Some((10, data(2))));212		assert_eq!(Balances::free_balance(10), 80);213214		// add third sub account215		assert_ok!(Identity::add_sub(RuntimeOrigin::signed(10), 3, data(3)));216		assert_eq!(SuperOf::<Test>::get(1), None);217		assert_eq!(SuperOf::<Test>::get(2), Some((10, data(2))));218		assert_eq!(SuperOf::<Test>::get(3), Some((10, data(3))));219		assert_eq!(Balances::free_balance(10), 70);220	});221}222223#[test]224fn resolving_subaccount_ownership_works() {225	new_test_ext().execute_with(|| {226		let data = |x| Data::Raw(vec![x; 1].try_into().unwrap());227228		assert_ok!(Identity::set_identity(229			RuntimeOrigin::signed(10),230			Box::new(ten())231		));232		assert_ok!(Identity::set_identity(233			RuntimeOrigin::signed(20),234			Box::new(twenty())235		));236237		// 10 claims 1 as a subaccount238		assert_ok!(Identity::add_sub(RuntimeOrigin::signed(10), 1, data(1)));239		assert_eq!(Balances::free_balance(1), 10);240		assert_eq!(Balances::free_balance(10), 80);241		assert_eq!(Balances::reserved_balance(10), 20);242		// 20 cannot claim 1 now243		assert_noop!(244			Identity::add_sub(RuntimeOrigin::signed(20), 1, data(1)),245			Error::<Test>::AlreadyClaimed246		);247		// 1 wants to be with 20 so it quits from 10248		assert_ok!(Identity::quit_sub(RuntimeOrigin::signed(1)));249		// 1 gets the 10 that 10 paid.250		assert_eq!(Balances::free_balance(1), 20);251		assert_eq!(Balances::free_balance(10), 80);252		assert_eq!(Balances::reserved_balance(10), 10);253		// 20 can claim 1 now254		assert_ok!(Identity::add_sub(RuntimeOrigin::signed(20), 1, data(1)));255	});256}257258#[test]259fn trailing_zeros_decodes_into_default_data() {260	let encoded = Data::Raw(b"Hello".to_vec().try_into().unwrap()).encode();261	assert!(<(Data, Data)>::decode(&mut &encoded[..]).is_err());262	let input = &mut &encoded[..];263	let (a, b) = <(Data, Data)>::decode(&mut AppendZerosInput::new(input)).unwrap();264	assert_eq!(a, Data::Raw(b"Hello".to_vec().try_into().unwrap()));265	assert_eq!(b, Data::None);266}267268#[test]269fn adding_registrar_should_work() {270	new_test_ext().execute_with(|| {271		assert_ok!(Identity::add_registrar(RuntimeOrigin::signed(1), 3));272		assert_ok!(Identity::set_fee(RuntimeOrigin::signed(3), 0, 10));273		let fields = IdentityFields(IdentityField::Display | IdentityField::Legal);274		assert_ok!(Identity::set_fields(RuntimeOrigin::signed(3), 0, fields));275		assert_eq!(276			Identity::registrars(),277			vec![Some(RegistrarInfo {278				account: 3,279				fee: 10,280				fields281			})]282		);283	});284}285286#[test]287fn amount_of_registrars_is_limited() {288	new_test_ext().execute_with(|| {289		for i in 1..MaxRegistrars::get() + 1 {290			assert_ok!(Identity::add_registrar(RuntimeOrigin::signed(1), i as u64));291		}292		let last_registrar = MaxRegistrars::get() as u64 + 1;293		assert_noop!(294			Identity::add_registrar(RuntimeOrigin::signed(1), last_registrar),295			Error::<Test>::TooManyRegistrars296		);297	});298}299300#[test]301fn registration_should_work() {302	new_test_ext().execute_with(|| {303		assert_ok!(Identity::add_registrar(RuntimeOrigin::signed(1), 3));304		assert_ok!(Identity::set_fee(RuntimeOrigin::signed(3), 0, 10));305		let mut three_fields = ten();306		three_fields307			.additional308			.try_push(Default::default())309			.unwrap();310		three_fields311			.additional312			.try_push(Default::default())313			.unwrap();314		assert!(three_fields315			.additional316			.try_push(Default::default())317			.is_err());318		assert_ok!(Identity::set_identity(319			RuntimeOrigin::signed(10),320			Box::new(ten())321		));322		assert_eq!(Identity::identity(10).unwrap().info, ten());323		assert_eq!(Balances::free_balance(10), 90);324		assert_ok!(Identity::clear_identity(RuntimeOrigin::signed(10)));325		assert_eq!(Balances::free_balance(10), 100);326		assert_noop!(327			Identity::clear_identity(RuntimeOrigin::signed(10)),328			Error::<Test>::NotNamed329		);330	});331}332333#[test]334fn uninvited_judgement_should_work() {335	new_test_ext().execute_with(|| {336		assert_noop!(337			Identity::provide_judgement(338				RuntimeOrigin::signed(3),339				0,340				10,341				Judgement::Reasonable,342				H256::random()343			),344			Error::<Test>::InvalidIndex345		);346347		assert_ok!(Identity::add_registrar(RuntimeOrigin::signed(1), 3));348		assert_noop!(349			Identity::provide_judgement(350				RuntimeOrigin::signed(3),351				0,352				10,353				Judgement::Reasonable,354				H256::random()355			),356			Error::<Test>::InvalidTarget357		);358359		assert_ok!(Identity::set_identity(360			RuntimeOrigin::signed(10),361			Box::new(ten())362		));363		assert_noop!(364			Identity::provide_judgement(365				RuntimeOrigin::signed(3),366				0,367				10,368				Judgement::Reasonable,369				H256::random()370			),371			Error::<Test>::JudgementForDifferentIdentity372		);373374		let identity_hash = BlakeTwo256::hash_of(&ten());375376		assert_noop!(377			Identity::provide_judgement(378				RuntimeOrigin::signed(10),379				0,380				10,381				Judgement::Reasonable,382				identity_hash383			),384			Error::<Test>::InvalidIndex385		);386		assert_noop!(387			Identity::provide_judgement(388				RuntimeOrigin::signed(3),389				0,390				10,391				Judgement::FeePaid(1),392				identity_hash393			),394			Error::<Test>::InvalidJudgement395		);396397		assert_ok!(Identity::provide_judgement(398			RuntimeOrigin::signed(3),399			0,400			10,401			Judgement::Reasonable,402			identity_hash403		));404		assert_eq!(405			Identity::identity(10).unwrap().judgements,406			vec![(0, Judgement::Reasonable)]407		);408	});409}410411#[test]412fn clearing_judgement_should_work() {413	new_test_ext().execute_with(|| {414		assert_ok!(Identity::add_registrar(RuntimeOrigin::signed(1), 3));415		assert_ok!(Identity::set_identity(416			RuntimeOrigin::signed(10),417			Box::new(ten())418		));419		assert_ok!(Identity::provide_judgement(420			RuntimeOrigin::signed(3),421			0,422			10,423			Judgement::Reasonable,424			BlakeTwo256::hash_of(&ten())425		));426		assert_ok!(Identity::clear_identity(RuntimeOrigin::signed(10)));427		assert_eq!(Identity::identity(10), None);428	});429}430431#[test]432fn killing_slashing_should_work() {433	new_test_ext().execute_with(|| {434		assert_ok!(Identity::set_identity(435			RuntimeOrigin::signed(10),436			Box::new(ten())437		));438		assert_noop!(439			Identity::kill_identity(RuntimeOrigin::signed(1), 10),440			BadOrigin441		);442		assert_ok!(Identity::kill_identity(RuntimeOrigin::signed(2), 10));443		assert_eq!(Identity::identity(10), None);444		assert_eq!(Balances::free_balance(10), 90);445		assert_noop!(446			Identity::kill_identity(RuntimeOrigin::signed(2), 10),447			Error::<Test>::NotNamed448		);449	});450}451452#[test]453fn setting_subaccounts_should_work() {454	new_test_ext().execute_with(|| {455		let mut subs = vec![(20, Data::Raw(vec![40; 1].try_into().unwrap()))];456		assert_noop!(457			Identity::set_subs(RuntimeOrigin::signed(10), subs.clone()),458			Error::<Test>::NotFound459		);460461		assert_ok!(Identity::set_identity(462			RuntimeOrigin::signed(10),463			Box::new(ten())464		));465		assert_ok!(Identity::set_subs(RuntimeOrigin::signed(10), subs.clone()));466		assert_eq!(Balances::free_balance(10), 80);467		assert_eq!(Identity::subs_of(10), (10, vec![20].try_into().unwrap()));468		assert_eq!(469			Identity::super_of(20),470			Some((10, Data::Raw(vec![40; 1].try_into().unwrap())))471		);472473		// push another item and re-set it.474		subs.push((30, Data::Raw(vec![50; 1].try_into().unwrap())));475		assert_ok!(Identity::set_subs(RuntimeOrigin::signed(10), subs.clone()));476		assert_eq!(Balances::free_balance(10), 70);477		assert_eq!(478			Identity::subs_of(10),479			(20, vec![20, 30].try_into().unwrap())480		);481		assert_eq!(482			Identity::super_of(20),483			Some((10, Data::Raw(vec![40; 1].try_into().unwrap())))484		);485		assert_eq!(486			Identity::super_of(30),487			Some((10, Data::Raw(vec![50; 1].try_into().unwrap())))488		);489490		// switch out one of the items and re-set.491		subs[0] = (40, Data::Raw(vec![60; 1].try_into().unwrap()));492		assert_ok!(Identity::set_subs(RuntimeOrigin::signed(10), subs.clone()));493		assert_eq!(Balances::free_balance(10), 70); // no change in the balance494		assert_eq!(495			Identity::subs_of(10),496			(20, vec![40, 30].try_into().unwrap())497		);498		assert_eq!(Identity::super_of(20), None);499		assert_eq!(500			Identity::super_of(30),501			Some((10, Data::Raw(vec![50; 1].try_into().unwrap())))502		);503		assert_eq!(504			Identity::super_of(40),505			Some((10, Data::Raw(vec![60; 1].try_into().unwrap())))506		);507508		// clear509		assert_ok!(Identity::set_subs(RuntimeOrigin::signed(10), vec![]));510		assert_eq!(Balances::free_balance(10), 90);511		assert_eq!(Identity::subs_of(10), (0, BoundedVec::default()));512		assert_eq!(Identity::super_of(30), None);513		assert_eq!(Identity::super_of(40), None);514515		subs.push((20, Data::Raw(vec![40; 1].try_into().unwrap())));516		assert_noop!(517			Identity::set_subs(RuntimeOrigin::signed(10), subs.clone()),518			Error::<Test>::TooManySubAccounts519		);520	});521}522523#[test]524fn clearing_account_should_remove_subaccounts_and_refund() {525	new_test_ext().execute_with(|| {526		assert_ok!(Identity::set_identity(527			RuntimeOrigin::signed(10),528			Box::new(ten())529		));530		assert_ok!(Identity::set_subs(531			RuntimeOrigin::signed(10),532			vec![(20, Data::Raw(vec![40; 1].try_into().unwrap()))]533		));534		assert_ok!(Identity::clear_identity(RuntimeOrigin::signed(10)));535		assert_eq!(Balances::free_balance(10), 100);536		assert!(Identity::super_of(20).is_none());537	});538}539540#[test]541fn killing_account_should_remove_subaccounts_and_not_refund() {542	new_test_ext().execute_with(|| {543		assert_ok!(Identity::set_identity(544			RuntimeOrigin::signed(10),545			Box::new(ten())546		));547		assert_ok!(Identity::set_subs(548			RuntimeOrigin::signed(10),549			vec![(20, Data::Raw(vec![40; 1].try_into().unwrap()))]550		));551		assert_ok!(Identity::kill_identity(RuntimeOrigin::signed(2), 10));552		assert_eq!(Balances::free_balance(10), 80);553		assert!(Identity::super_of(20).is_none());554	});555}556557#[test]558fn cancelling_requested_judgement_should_work() {559	new_test_ext().execute_with(|| {560		assert_ok!(Identity::add_registrar(RuntimeOrigin::signed(1), 3));561		assert_ok!(Identity::set_fee(RuntimeOrigin::signed(3), 0, 10));562		assert_noop!(563			Identity::cancel_request(RuntimeOrigin::signed(10), 0),564			Error::<Test>::NoIdentity565		);566		assert_ok!(Identity::set_identity(567			RuntimeOrigin::signed(10),568			Box::new(ten())569		));570		assert_ok!(Identity::request_judgement(571			RuntimeOrigin::signed(10),572			0,573			10574		));575		assert_ok!(Identity::cancel_request(RuntimeOrigin::signed(10), 0));576		assert_eq!(Balances::free_balance(10), 90);577		assert_noop!(578			Identity::cancel_request(RuntimeOrigin::signed(10), 0),579			Error::<Test>::NotFound580		);581582		assert_ok!(Identity::provide_judgement(583			RuntimeOrigin::signed(3),584			0,585			10,586			Judgement::Reasonable,587			BlakeTwo256::hash_of(&ten())588		));589		assert_noop!(590			Identity::cancel_request(RuntimeOrigin::signed(10), 0),591			Error::<Test>::JudgementGiven592		);593	});594}595596#[test]597fn requesting_judgement_should_work() {598	new_test_ext().execute_with(|| {599		assert_ok!(Identity::add_registrar(RuntimeOrigin::signed(1), 3));600		assert_ok!(Identity::set_fee(RuntimeOrigin::signed(3), 0, 10));601		assert_ok!(Identity::set_identity(602			RuntimeOrigin::signed(10),603			Box::new(ten())604		));605		assert_noop!(606			Identity::request_judgement(RuntimeOrigin::signed(10), 0, 9),607			Error::<Test>::FeeChanged608		);609		assert_ok!(Identity::request_judgement(610			RuntimeOrigin::signed(10),611			0,612			10613		));614		// 10 for the judgement request, 10 for the identity.615		assert_eq!(Balances::free_balance(10), 80);616617		// Re-requesting won't work as we already paid.618		assert_noop!(619			Identity::request_judgement(RuntimeOrigin::signed(10), 0, 10),620			Error::<Test>::StickyJudgement621		);622		assert_ok!(Identity::provide_judgement(623			RuntimeOrigin::signed(3),624			0,625			10,626			Judgement::Erroneous,627			BlakeTwo256::hash_of(&ten())628		));629		// Registrar got their payment now.630		assert_eq!(Balances::free_balance(3), 20);631632		// Re-requesting still won't work as it's erroneous.633		assert_noop!(634			Identity::request_judgement(RuntimeOrigin::signed(10), 0, 10),635			Error::<Test>::StickyJudgement636		);637638		// Requesting from a second registrar still works.639		assert_ok!(Identity::add_registrar(RuntimeOrigin::signed(1), 4));640		assert_ok!(Identity::request_judgement(641			RuntimeOrigin::signed(10),642			1,643			10644		));645646		// Re-requesting after the judgement has been reduced works.647		assert_ok!(Identity::provide_judgement(648			RuntimeOrigin::signed(3),649			0,650			10,651			Judgement::OutOfDate,652			BlakeTwo256::hash_of(&ten())653		));654		assert_ok!(Identity::request_judgement(655			RuntimeOrigin::signed(10),656			0,657			10658		));659	});660}661662#[test]663fn provide_judgement_should_return_judgement_payment_failed_error() {664	new_test_ext().execute_with(|| {665		assert_ok!(Identity::add_registrar(RuntimeOrigin::signed(1), 3));666		assert_ok!(Identity::set_fee(RuntimeOrigin::signed(3), 0, 10));667		assert_ok!(Identity::set_identity(668			RuntimeOrigin::signed(10),669			Box::new(ten())670		));671		assert_ok!(Identity::request_judgement(672			RuntimeOrigin::signed(10),673			0,674			10675		));676		// 10 for the judgement request, 10 for the identity.677		assert_eq!(Balances::free_balance(10), 80);678679		// This forces judgement payment failed error680		Balances::make_free_balance_be(&3, 0);681		assert_noop!(682			Identity::provide_judgement(683				RuntimeOrigin::signed(3),684				0,685				10,686				Judgement::Erroneous,687				BlakeTwo256::hash_of(&ten())688			),689			Error::<Test>::JudgementPaymentFailed690		);691	});692}693694#[test]695fn field_deposit_should_work() {696	new_test_ext().execute_with(|| {697		assert_ok!(Identity::add_registrar(RuntimeOrigin::signed(1), 3));698		assert_ok!(Identity::set_fee(RuntimeOrigin::signed(3), 0, 10));699		assert_ok!(Identity::set_identity(700			RuntimeOrigin::signed(10),701			Box::new(IdentityInfo {702				additional: vec![703					(704						Data::Raw(b"number".to_vec().try_into().unwrap()),705						Data::Raw(10u32.encode().try_into().unwrap())706					),707					(708						Data::Raw(b"text".to_vec().try_into().unwrap()),709						Data::Raw(b"10".to_vec().try_into().unwrap())710					),711				]712				.try_into()713				.unwrap(),714				..Default::default()715			})716		));717		assert_eq!(Balances::free_balance(10), 70);718	});719}720721#[test]722fn setting_account_id_should_work() {723	new_test_ext().execute_with(|| {724		assert_ok!(Identity::add_registrar(RuntimeOrigin::signed(1), 3));725		// account 4 cannot change the first registrar's identity since it's owned by 3.726		assert_noop!(727			Identity::set_account_id(RuntimeOrigin::signed(4), 0, 3),728			Error::<Test>::InvalidIndex729		);730		// account 3 can, because that's the registrar's current account.731		assert_ok!(Identity::set_account_id(RuntimeOrigin::signed(3), 0, 4));732		// account 4 can now, because that's their new ID.733		assert_ok!(Identity::set_account_id(RuntimeOrigin::signed(4), 0, 3));734	});735}736737#[test]738fn test_has_identity() {739	new_test_ext().execute_with(|| {740		assert_ok!(Identity::set_identity(741			RuntimeOrigin::signed(10),742			Box::new(ten())743		));744		assert!(Identity::has_identity(&10, IdentityField::Display as u64));745		assert!(Identity::has_identity(&10, IdentityField::Legal as u64));746		assert!(Identity::has_identity(747			&10,748			IdentityField::Display as u64 | IdentityField::Legal as u64749		));750		assert!(!Identity::has_identity(751			&10,752			IdentityField::Display as u64 | IdentityField::Legal as u64 | IdentityField::Web as u64753		));754	});755}
after · pallets/identity/src/tests.rs
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617// Original license:18// This file is part of Substrate.1920// Copyright (C) 2019-2022 Parity Technologies (UK) Ltd.21// SPDX-License-Identifier: Apache-2.02223// Licensed under the Apache License, Version 2.0 (the "License");24// you may not use this file except in compliance with the License.25// You may obtain a copy of the License at26//27// 	http://www.apache.org/licenses/LICENSE-2.028//29// Unless required by applicable law or agreed to in writing, software30// distributed under the License is distributed on an "AS IS" BASIS,31// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.32// See the License for the specific language governing permissions and33// limitations under the License.3435// Tests for Identity Pallet3637use frame_support::{38	assert_noop, assert_ok, ord_parameter_types, parameter_types,39	traits::{ConstU32, ConstU64, EitherOfDiverse},40	BoundedVec,41};42use frame_system::{EnsureRoot, EnsureSignedBy};43use parity_scale_codec::{Decode, Encode};44use sp_core::H256;45use sp_runtime::{46	traits::{BadOrigin, BlakeTwo256, IdentityLookup},47	BuildStorage,48};4950use super::*;51use crate as pallet_identity;5253type Block = frame_system::mocking::MockBlockU32<Test>;5455frame_support::construct_runtime!(56	pub enum Test {57		System: frame_system,58		Balances: pallet_balances,59		Identity: pallet_identity,60	}61);6263parameter_types! {64	pub BlockWeights: frame_system::limits::BlockWeights =65		frame_system::limits::BlockWeights::simple_max(frame_support::weights::Weight::from_parts(1024, 0));66}67impl frame_system::Config for Test {68	type BaseCallFilter = frame_support::traits::Everything;69	type Block = Block;70	type BlockWeights = ();71	type BlockLength = ();72	type RuntimeOrigin = RuntimeOrigin;73	type Nonce = u64;74	type Hash = H256;75	type RuntimeCall = RuntimeCall;76	type Hashing = BlakeTwo256;77	type AccountId = u64;78	type Lookup = IdentityLookup<Self::AccountId>;79	type RuntimeEvent = RuntimeEvent;80	type BlockHashCount = ConstU32<250>;81	type DbWeight = ();82	type Version = ();83	type PalletInfo = PalletInfo;84	type AccountData = pallet_balances::AccountData<u64>;85	type OnNewAccount = ();86	type OnKilledAccount = ();87	type SystemWeightInfo = ();88	type SS58Prefix = ();89	type OnSetCode = ();90	type MaxConsumers = ConstU32<16>;91}9293impl pallet_balances::Config for Test {94	type Balance = u64;95	type RuntimeEvent = RuntimeEvent;96	type DustRemoval = ();97	type ExistentialDeposit = ConstU64<1>;98	type AccountStore = System;99	type MaxLocks = ();100	type MaxReserves = ();101	type ReserveIdentifier = [u8; 8];102	type WeightInfo = ();103	type RuntimeHoldReason = RuntimeHoldReason;104	type FreezeIdentifier = ();105	type MaxHolds = ();106	type MaxFreezes = ();107}108109parameter_types! {110	pub const MaxAdditionalFields: u32 = 2;111	pub const MaxRegistrars: u32 = 20;112}113114ord_parameter_types! {115	pub const One: u64 = 1;116	pub const Two: u64 = 2;117}118type EnsureOneOrRoot = EitherOfDiverse<EnsureRoot<u64>, EnsureSignedBy<One, u64>>;119type EnsureTwoOrRoot = EitherOfDiverse<EnsureRoot<u64>, EnsureSignedBy<Two, u64>>;120impl pallet_identity::Config for Test {121	type RuntimeEvent = RuntimeEvent;122	type Currency = Balances;123	type Slashed = ();124	type BasicDeposit = ConstU64<10>;125	type FieldDeposit = ConstU64<10>;126	type SubAccountDeposit = ConstU64<10>;127	type MaxSubAccounts = ConstU32<2>;128	type MaxAdditionalFields = MaxAdditionalFields;129	type MaxRegistrars = MaxRegistrars;130	type RegistrarOrigin = EnsureOneOrRoot;131	type ForceOrigin = EnsureTwoOrRoot;132	type WeightInfo = ();133}134135pub fn new_test_ext() -> sp_io::TestExternalities {136	let mut t = <frame_system::GenesisConfig<Test>>::default()137		.build_storage()138		.unwrap();139	pallet_balances::GenesisConfig::<Test> {140		balances: vec![(1, 10), (2, 10), (3, 10), (10, 100), (20, 100), (30, 100)],141	}142	.assimilate_storage(&mut t)143	.unwrap();144	t.into()145}146147fn ten() -> IdentityInfo<MaxAdditionalFields> {148	IdentityInfo {149		display: Data::Raw(b"ten".to_vec().try_into().unwrap()),150		legal: Data::Raw(b"The Right Ordinal Ten, Esq.".to_vec().try_into().unwrap()),151		..Default::default()152	}153}154155fn twenty() -> IdentityInfo<MaxAdditionalFields> {156	IdentityInfo {157		display: Data::Raw(b"twenty".to_vec().try_into().unwrap()),158		legal: Data::Raw(159			b"The Right Ordinal Twenty, Esq."160				.to_vec()161				.try_into()162				.unwrap(),163		),164		..Default::default()165	}166}167168#[test]169fn editing_subaccounts_should_work() {170	new_test_ext().execute_with(|| {171		let data = |x| Data::Raw(vec![x; 1].try_into().unwrap());172173		assert_noop!(174			Identity::add_sub(RuntimeOrigin::signed(10), 20, data(1)),175			Error::<Test>::NoIdentity176		);177178		assert_ok!(Identity::set_identity(179			RuntimeOrigin::signed(10),180			Box::new(ten())181		));182183		// first sub account184		assert_ok!(Identity::add_sub(RuntimeOrigin::signed(10), 1, data(1)));185		assert_eq!(SuperOf::<Test>::get(1), Some((10, data(1))));186		assert_eq!(Balances::free_balance(10), 80);187188		// second sub account189		assert_ok!(Identity::add_sub(RuntimeOrigin::signed(10), 2, data(2)));190		assert_eq!(SuperOf::<Test>::get(1), Some((10, data(1))));191		assert_eq!(SuperOf::<Test>::get(2), Some((10, data(2))));192		assert_eq!(Balances::free_balance(10), 70);193194		// third sub account is too many195		assert_noop!(196			Identity::add_sub(RuntimeOrigin::signed(10), 3, data(3)),197			Error::<Test>::TooManySubAccounts198		);199200		// rename first sub account201		assert_ok!(Identity::rename_sub(RuntimeOrigin::signed(10), 1, data(11)));202		assert_eq!(SuperOf::<Test>::get(1), Some((10, data(11))));203		assert_eq!(SuperOf::<Test>::get(2), Some((10, data(2))));204		assert_eq!(Balances::free_balance(10), 70);205206		// remove first sub account207		assert_ok!(Identity::remove_sub(RuntimeOrigin::signed(10), 1));208		assert_eq!(SuperOf::<Test>::get(1), None);209		assert_eq!(SuperOf::<Test>::get(2), Some((10, data(2))));210		assert_eq!(Balances::free_balance(10), 80);211212		// add third sub account213		assert_ok!(Identity::add_sub(RuntimeOrigin::signed(10), 3, data(3)));214		assert_eq!(SuperOf::<Test>::get(1), None);215		assert_eq!(SuperOf::<Test>::get(2), Some((10, data(2))));216		assert_eq!(SuperOf::<Test>::get(3), Some((10, data(3))));217		assert_eq!(Balances::free_balance(10), 70);218	});219}220221#[test]222fn resolving_subaccount_ownership_works() {223	new_test_ext().execute_with(|| {224		let data = |x| Data::Raw(vec![x; 1].try_into().unwrap());225226		assert_ok!(Identity::set_identity(227			RuntimeOrigin::signed(10),228			Box::new(ten())229		));230		assert_ok!(Identity::set_identity(231			RuntimeOrigin::signed(20),232			Box::new(twenty())233		));234235		// 10 claims 1 as a subaccount236		assert_ok!(Identity::add_sub(RuntimeOrigin::signed(10), 1, data(1)));237		assert_eq!(Balances::free_balance(1), 10);238		assert_eq!(Balances::free_balance(10), 80);239		assert_eq!(Balances::reserved_balance(10), 20);240		// 20 cannot claim 1 now241		assert_noop!(242			Identity::add_sub(RuntimeOrigin::signed(20), 1, data(1)),243			Error::<Test>::AlreadyClaimed244		);245		// 1 wants to be with 20 so it quits from 10246		assert_ok!(Identity::quit_sub(RuntimeOrigin::signed(1)));247		// 1 gets the 10 that 10 paid.248		assert_eq!(Balances::free_balance(1), 20);249		assert_eq!(Balances::free_balance(10), 80);250		assert_eq!(Balances::reserved_balance(10), 10);251		// 20 can claim 1 now252		assert_ok!(Identity::add_sub(RuntimeOrigin::signed(20), 1, data(1)));253	});254}255256#[test]257fn trailing_zeros_decodes_into_default_data() {258	let encoded = Data::Raw(b"Hello".to_vec().try_into().unwrap()).encode();259	assert!(<(Data, Data)>::decode(&mut &encoded[..]).is_err());260	let input = &mut &encoded[..];261	let (a, b) = <(Data, Data)>::decode(&mut AppendZerosInput::new(input)).unwrap();262	assert_eq!(a, Data::Raw(b"Hello".to_vec().try_into().unwrap()));263	assert_eq!(b, Data::None);264}265266#[test]267fn adding_registrar_should_work() {268	new_test_ext().execute_with(|| {269		assert_ok!(Identity::add_registrar(RuntimeOrigin::signed(1), 3));270		assert_ok!(Identity::set_fee(RuntimeOrigin::signed(3), 0, 10));271		let fields = IdentityFields(IdentityField::Display | IdentityField::Legal);272		assert_ok!(Identity::set_fields(RuntimeOrigin::signed(3), 0, fields));273		assert_eq!(274			Identity::registrars(),275			vec![Some(RegistrarInfo {276				account: 3,277				fee: 10,278				fields279			})]280		);281	});282}283284#[test]285fn amount_of_registrars_is_limited() {286	new_test_ext().execute_with(|| {287		for i in 1..MaxRegistrars::get() + 1 {288			assert_ok!(Identity::add_registrar(RuntimeOrigin::signed(1), i as u64));289		}290		let last_registrar = MaxRegistrars::get() as u64 + 1;291		assert_noop!(292			Identity::add_registrar(RuntimeOrigin::signed(1), last_registrar),293			Error::<Test>::TooManyRegistrars294		);295	});296}297298#[test]299fn registration_should_work() {300	new_test_ext().execute_with(|| {301		assert_ok!(Identity::add_registrar(RuntimeOrigin::signed(1), 3));302		assert_ok!(Identity::set_fee(RuntimeOrigin::signed(3), 0, 10));303		let mut three_fields = ten();304		three_fields305			.additional306			.try_push(Default::default())307			.unwrap();308		three_fields309			.additional310			.try_push(Default::default())311			.unwrap();312		assert!(three_fields313			.additional314			.try_push(Default::default())315			.is_err());316		assert_ok!(Identity::set_identity(317			RuntimeOrigin::signed(10),318			Box::new(ten())319		));320		assert_eq!(Identity::identity(10).unwrap().info, ten());321		assert_eq!(Balances::free_balance(10), 90);322		assert_ok!(Identity::clear_identity(RuntimeOrigin::signed(10)));323		assert_eq!(Balances::free_balance(10), 100);324		assert_noop!(325			Identity::clear_identity(RuntimeOrigin::signed(10)),326			Error::<Test>::NotNamed327		);328	});329}330331#[test]332fn uninvited_judgement_should_work() {333	new_test_ext().execute_with(|| {334		assert_noop!(335			Identity::provide_judgement(336				RuntimeOrigin::signed(3),337				0,338				10,339				Judgement::Reasonable,340				H256::random()341			),342			Error::<Test>::InvalidIndex343		);344345		assert_ok!(Identity::add_registrar(RuntimeOrigin::signed(1), 3));346		assert_noop!(347			Identity::provide_judgement(348				RuntimeOrigin::signed(3),349				0,350				10,351				Judgement::Reasonable,352				H256::random()353			),354			Error::<Test>::InvalidTarget355		);356357		assert_ok!(Identity::set_identity(358			RuntimeOrigin::signed(10),359			Box::new(ten())360		));361		assert_noop!(362			Identity::provide_judgement(363				RuntimeOrigin::signed(3),364				0,365				10,366				Judgement::Reasonable,367				H256::random()368			),369			Error::<Test>::JudgementForDifferentIdentity370		);371372		let identity_hash = BlakeTwo256::hash_of(&ten());373374		assert_noop!(375			Identity::provide_judgement(376				RuntimeOrigin::signed(10),377				0,378				10,379				Judgement::Reasonable,380				identity_hash381			),382			Error::<Test>::InvalidIndex383		);384		assert_noop!(385			Identity::provide_judgement(386				RuntimeOrigin::signed(3),387				0,388				10,389				Judgement::FeePaid(1),390				identity_hash391			),392			Error::<Test>::InvalidJudgement393		);394395		assert_ok!(Identity::provide_judgement(396			RuntimeOrigin::signed(3),397			0,398			10,399			Judgement::Reasonable,400			identity_hash401		));402		assert_eq!(403			Identity::identity(10).unwrap().judgements,404			vec![(0, Judgement::Reasonable)]405		);406	});407}408409#[test]410fn clearing_judgement_should_work() {411	new_test_ext().execute_with(|| {412		assert_ok!(Identity::add_registrar(RuntimeOrigin::signed(1), 3));413		assert_ok!(Identity::set_identity(414			RuntimeOrigin::signed(10),415			Box::new(ten())416		));417		assert_ok!(Identity::provide_judgement(418			RuntimeOrigin::signed(3),419			0,420			10,421			Judgement::Reasonable,422			BlakeTwo256::hash_of(&ten())423		));424		assert_ok!(Identity::clear_identity(RuntimeOrigin::signed(10)));425		assert_eq!(Identity::identity(10), None);426	});427}428429#[test]430fn killing_slashing_should_work() {431	new_test_ext().execute_with(|| {432		assert_ok!(Identity::set_identity(433			RuntimeOrigin::signed(10),434			Box::new(ten())435		));436		assert_noop!(437			Identity::kill_identity(RuntimeOrigin::signed(1), 10),438			BadOrigin439		);440		assert_ok!(Identity::kill_identity(RuntimeOrigin::signed(2), 10));441		assert_eq!(Identity::identity(10), None);442		assert_eq!(Balances::free_balance(10), 90);443		assert_noop!(444			Identity::kill_identity(RuntimeOrigin::signed(2), 10),445			Error::<Test>::NotNamed446		);447	});448}449450#[test]451fn setting_subaccounts_should_work() {452	new_test_ext().execute_with(|| {453		let mut subs = vec![(20, Data::Raw(vec![40; 1].try_into().unwrap()))];454		assert_noop!(455			Identity::set_subs(RuntimeOrigin::signed(10), subs.clone()),456			Error::<Test>::NotFound457		);458459		assert_ok!(Identity::set_identity(460			RuntimeOrigin::signed(10),461			Box::new(ten())462		));463		assert_ok!(Identity::set_subs(RuntimeOrigin::signed(10), subs.clone()));464		assert_eq!(Balances::free_balance(10), 80);465		assert_eq!(Identity::subs_of(10), (10, vec![20].try_into().unwrap()));466		assert_eq!(467			Identity::super_of(20),468			Some((10, Data::Raw(vec![40; 1].try_into().unwrap())))469		);470471		// push another item and re-set it.472		subs.push((30, Data::Raw(vec![50; 1].try_into().unwrap())));473		assert_ok!(Identity::set_subs(RuntimeOrigin::signed(10), subs.clone()));474		assert_eq!(Balances::free_balance(10), 70);475		assert_eq!(476			Identity::subs_of(10),477			(20, vec![20, 30].try_into().unwrap())478		);479		assert_eq!(480			Identity::super_of(20),481			Some((10, Data::Raw(vec![40; 1].try_into().unwrap())))482		);483		assert_eq!(484			Identity::super_of(30),485			Some((10, Data::Raw(vec![50; 1].try_into().unwrap())))486		);487488		// switch out one of the items and re-set.489		subs[0] = (40, Data::Raw(vec![60; 1].try_into().unwrap()));490		assert_ok!(Identity::set_subs(RuntimeOrigin::signed(10), subs.clone()));491		assert_eq!(Balances::free_balance(10), 70); // no change in the balance492		assert_eq!(493			Identity::subs_of(10),494			(20, vec![40, 30].try_into().unwrap())495		);496		assert_eq!(Identity::super_of(20), None);497		assert_eq!(498			Identity::super_of(30),499			Some((10, Data::Raw(vec![50; 1].try_into().unwrap())))500		);501		assert_eq!(502			Identity::super_of(40),503			Some((10, Data::Raw(vec![60; 1].try_into().unwrap())))504		);505506		// clear507		assert_ok!(Identity::set_subs(RuntimeOrigin::signed(10), vec![]));508		assert_eq!(Balances::free_balance(10), 90);509		assert_eq!(Identity::subs_of(10), (0, BoundedVec::default()));510		assert_eq!(Identity::super_of(30), None);511		assert_eq!(Identity::super_of(40), None);512513		subs.push((20, Data::Raw(vec![40; 1].try_into().unwrap())));514		assert_noop!(515			Identity::set_subs(RuntimeOrigin::signed(10), subs.clone()),516			Error::<Test>::TooManySubAccounts517		);518	});519}520521#[test]522fn clearing_account_should_remove_subaccounts_and_refund() {523	new_test_ext().execute_with(|| {524		assert_ok!(Identity::set_identity(525			RuntimeOrigin::signed(10),526			Box::new(ten())527		));528		assert_ok!(Identity::set_subs(529			RuntimeOrigin::signed(10),530			vec![(20, Data::Raw(vec![40; 1].try_into().unwrap()))]531		));532		assert_ok!(Identity::clear_identity(RuntimeOrigin::signed(10)));533		assert_eq!(Balances::free_balance(10), 100);534		assert!(Identity::super_of(20).is_none());535	});536}537538#[test]539fn killing_account_should_remove_subaccounts_and_not_refund() {540	new_test_ext().execute_with(|| {541		assert_ok!(Identity::set_identity(542			RuntimeOrigin::signed(10),543			Box::new(ten())544		));545		assert_ok!(Identity::set_subs(546			RuntimeOrigin::signed(10),547			vec![(20, Data::Raw(vec![40; 1].try_into().unwrap()))]548		));549		assert_ok!(Identity::kill_identity(RuntimeOrigin::signed(2), 10));550		assert_eq!(Balances::free_balance(10), 80);551		assert!(Identity::super_of(20).is_none());552	});553}554555#[test]556fn cancelling_requested_judgement_should_work() {557	new_test_ext().execute_with(|| {558		assert_ok!(Identity::add_registrar(RuntimeOrigin::signed(1), 3));559		assert_ok!(Identity::set_fee(RuntimeOrigin::signed(3), 0, 10));560		assert_noop!(561			Identity::cancel_request(RuntimeOrigin::signed(10), 0),562			Error::<Test>::NoIdentity563		);564		assert_ok!(Identity::set_identity(565			RuntimeOrigin::signed(10),566			Box::new(ten())567		));568		assert_ok!(Identity::request_judgement(569			RuntimeOrigin::signed(10),570			0,571			10572		));573		assert_ok!(Identity::cancel_request(RuntimeOrigin::signed(10), 0));574		assert_eq!(Balances::free_balance(10), 90);575		assert_noop!(576			Identity::cancel_request(RuntimeOrigin::signed(10), 0),577			Error::<Test>::NotFound578		);579580		assert_ok!(Identity::provide_judgement(581			RuntimeOrigin::signed(3),582			0,583			10,584			Judgement::Reasonable,585			BlakeTwo256::hash_of(&ten())586		));587		assert_noop!(588			Identity::cancel_request(RuntimeOrigin::signed(10), 0),589			Error::<Test>::JudgementGiven590		);591	});592}593594#[test]595fn requesting_judgement_should_work() {596	new_test_ext().execute_with(|| {597		assert_ok!(Identity::add_registrar(RuntimeOrigin::signed(1), 3));598		assert_ok!(Identity::set_fee(RuntimeOrigin::signed(3), 0, 10));599		assert_ok!(Identity::set_identity(600			RuntimeOrigin::signed(10),601			Box::new(ten())602		));603		assert_noop!(604			Identity::request_judgement(RuntimeOrigin::signed(10), 0, 9),605			Error::<Test>::FeeChanged606		);607		assert_ok!(Identity::request_judgement(608			RuntimeOrigin::signed(10),609			0,610			10611		));612		// 10 for the judgement request, 10 for the identity.613		assert_eq!(Balances::free_balance(10), 80);614615		// Re-requesting won't work as we already paid.616		assert_noop!(617			Identity::request_judgement(RuntimeOrigin::signed(10), 0, 10),618			Error::<Test>::StickyJudgement619		);620		assert_ok!(Identity::provide_judgement(621			RuntimeOrigin::signed(3),622			0,623			10,624			Judgement::Erroneous,625			BlakeTwo256::hash_of(&ten())626		));627		// Registrar got their payment now.628		assert_eq!(Balances::free_balance(3), 20);629630		// Re-requesting still won't work as it's erroneous.631		assert_noop!(632			Identity::request_judgement(RuntimeOrigin::signed(10), 0, 10),633			Error::<Test>::StickyJudgement634		);635636		// Requesting from a second registrar still works.637		assert_ok!(Identity::add_registrar(RuntimeOrigin::signed(1), 4));638		assert_ok!(Identity::request_judgement(639			RuntimeOrigin::signed(10),640			1,641			10642		));643644		// Re-requesting after the judgement has been reduced works.645		assert_ok!(Identity::provide_judgement(646			RuntimeOrigin::signed(3),647			0,648			10,649			Judgement::OutOfDate,650			BlakeTwo256::hash_of(&ten())651		));652		assert_ok!(Identity::request_judgement(653			RuntimeOrigin::signed(10),654			0,655			10656		));657	});658}659660#[test]661fn provide_judgement_should_return_judgement_payment_failed_error() {662	new_test_ext().execute_with(|| {663		assert_ok!(Identity::add_registrar(RuntimeOrigin::signed(1), 3));664		assert_ok!(Identity::set_fee(RuntimeOrigin::signed(3), 0, 10));665		assert_ok!(Identity::set_identity(666			RuntimeOrigin::signed(10),667			Box::new(ten())668		));669		assert_ok!(Identity::request_judgement(670			RuntimeOrigin::signed(10),671			0,672			10673		));674		// 10 for the judgement request, 10 for the identity.675		assert_eq!(Balances::free_balance(10), 80);676677		// This forces judgement payment failed error678		Balances::make_free_balance_be(&3, 0);679		assert_noop!(680			Identity::provide_judgement(681				RuntimeOrigin::signed(3),682				0,683				10,684				Judgement::Erroneous,685				BlakeTwo256::hash_of(&ten())686			),687			Error::<Test>::JudgementPaymentFailed688		);689	});690}691692#[test]693fn field_deposit_should_work() {694	new_test_ext().execute_with(|| {695		assert_ok!(Identity::add_registrar(RuntimeOrigin::signed(1), 3));696		assert_ok!(Identity::set_fee(RuntimeOrigin::signed(3), 0, 10));697		assert_ok!(Identity::set_identity(698			RuntimeOrigin::signed(10),699			Box::new(IdentityInfo {700				additional: vec![701					(702						Data::Raw(b"number".to_vec().try_into().unwrap()),703						Data::Raw(10u32.encode().try_into().unwrap())704					),705					(706						Data::Raw(b"text".to_vec().try_into().unwrap()),707						Data::Raw(b"10".to_vec().try_into().unwrap())708					),709				]710				.try_into()711				.unwrap(),712				..Default::default()713			})714		));715		assert_eq!(Balances::free_balance(10), 70);716	});717}718719#[test]720fn setting_account_id_should_work() {721	new_test_ext().execute_with(|| {722		assert_ok!(Identity::add_registrar(RuntimeOrigin::signed(1), 3));723		// account 4 cannot change the first registrar's identity since it's owned by 3.724		assert_noop!(725			Identity::set_account_id(RuntimeOrigin::signed(4), 0, 3),726			Error::<Test>::InvalidIndex727		);728		// account 3 can, because that's the registrar's current account.729		assert_ok!(Identity::set_account_id(RuntimeOrigin::signed(3), 0, 4));730		// account 4 can now, because that's their new ID.731		assert_ok!(Identity::set_account_id(RuntimeOrigin::signed(4), 0, 3));732	});733}734735#[test]736fn test_has_identity() {737	new_test_ext().execute_with(|| {738		assert_ok!(Identity::set_identity(739			RuntimeOrigin::signed(10),740			Box::new(ten())741		));742		assert!(Identity::has_identity(&10, IdentityField::Display as u64));743		assert!(Identity::has_identity(&10, IdentityField::Legal as u64));744		assert!(Identity::has_identity(745			&10,746			IdentityField::Display as u64 | IdentityField::Legal as u64747		));748		assert!(!Identity::has_identity(749			&10,750			IdentityField::Display as u64 | IdentityField::Legal as u64 | IdentityField::Web as u64751		));752	});753}
modifiedpallets/inflation/src/tests.rsdiffbeforeafterboth
--- a/pallets/inflation/src/tests.rs
+++ b/pallets/inflation/src/tests.rs
@@ -34,12 +34,12 @@
 
 use crate as pallet_inflation;
 
-type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
-type Block = frame_system::mocking::MockBlock<Test>;
+type Block = frame_system::mocking::MockBlockU32<Test>;
 
-const YEAR: u64 = 5_259_600; // 6-second blocks
-							 // const YEAR: u64 = 2_629_800; // 12-second blocks
-							 // Expected 100-block inflation for year 1 is 100 * 100_000_000 / YEAR = FIRST_YEAR_BLOCK_INFLATION
+// 6-second blocks
+// const YEAR: u32 = 2_629_800; // 12-second blocks
+// Expected 100-block inflation for year 1 is 100 * 100_000_000 / YEAR = FIRST_YEAR_BLOCK_INFLATION
+const YEAR: u32 = 5_259_600;
 const FIRST_YEAR_BLOCK_INFLATION: u64 = 1901;
 
 parameter_types! {
@@ -60,6 +60,7 @@
 	type FreezeIdentifier = ();
 	type MaxHolds = ();
 	type MaxFreezes = ();
+	type RuntimeHoldReason = RuntimeHoldReason;
 }
 
 frame_support::construct_runtime!(
@@ -71,7 +72,7 @@
 );
 
 parameter_types! {
-	pub const BlockHashCount: u64 = 250;
+	pub const BlockHashCount: u32 = 250;
 	pub BlockWeights: frame_system::limits::BlockWeights =
 		frame_system::limits::BlockWeights::simple_max(Weight::from_parts(1024, 0));
 	pub const SS58Prefix: u8 = 42;
@@ -79,6 +80,7 @@
 
 impl frame_system::Config for Test {
 	type BaseCallFilter = Everything;
+	type Block = Block;
 	type BlockWeights = ();
 	type BlockLength = ();
 	type DbWeight = ();
@@ -187,7 +189,7 @@
 fn inflation_second_deposit() {
 	new_test_ext().execute_with(|| {
 		// Total issuance = 1_000_000_000
-		let initial_issuance: u64 = 1_000_000_000;
+		let initial_issuance = 1_000_000_000;
 		let _ = <Balances as Balanced<_>>::deposit(&1234, initial_issuance, Precision::Exact);
 		assert_eq!(Balances::free_balance(1234), initial_issuance);
 		MockBlockNumberProvider::set(1);
@@ -196,20 +198,20 @@
 		assert_ok!(Inflation::start_inflation(RawOrigin::Root.into(), 1));
 
 		// Next inflation deposit happens when block is greater then or equal to NextInflationBlock
-		let mut block: u64 = 2;
-		let balance_before: u64 = Balances::free_balance(1234);
+		let mut block = 2;
+		let balance_before = Balances::free_balance(1234);
 		while block < <pallet_inflation::NextInflationBlock<Test>>::get() {
-			MockBlockNumberProvider::set(block as u64);
+			MockBlockNumberProvider::set(block);
 			Inflation::on_initialize(0);
 			block += 1;
 		}
-		let balance_just_before: u64 = Balances::free_balance(1234);
+		let balance_just_before = Balances::free_balance(1234);
 		assert_eq!(balance_before, balance_just_before);
 
 		// The block with inflation
-		MockBlockNumberProvider::set(block as u64);
+		MockBlockNumberProvider::set(block);
 		Inflation::on_initialize(0);
-		let balance_after: u64 = Balances::free_balance(1234);
+		let balance_after = Balances::free_balance(1234);
 		assert_eq!(balance_after - balance_just_before, block_inflation!());
 	});
 }
@@ -234,7 +236,7 @@
 			Inflation::on_initialize(0);
 		}
 		assert_eq!(
-			initial_issuance + (FIRST_YEAR_BLOCK_INFLATION * (YEAR / 100)),
+			initial_issuance + (FIRST_YEAR_BLOCK_INFLATION * ((YEAR as u64) / 100)),
 			<Balances as Inspect<_>>::total_issuance()
 		);
 
@@ -243,8 +245,8 @@
 		let block_inflation_year_2 = block_inflation!();
 		// Expected 100-block inflation for year 2: 100 * 9.33% * initial issuance * 110% / YEAR == 1951
 		let expecter_year_2_inflation: u64 = (initial_issuance
-			+ FIRST_YEAR_BLOCK_INFLATION * YEAR / 100)
-			* 933 * 100 / (10000 * YEAR);
+			+ FIRST_YEAR_BLOCK_INFLATION * (YEAR as u64) / 100)
+			* 933 * 100 / (10000 * (YEAR as u64));
 		assert_eq!(block_inflation_year_2 / 10, expecter_year_2_inflation / 10); // divide by 10 for approx. equality
 	});
 }
@@ -253,8 +255,8 @@
 fn inflation_start_large_kusama_block() {
 	new_test_ext().execute_with(|| {
 		// Total issuance = 1_000_000_000
-		let initial_issuance: u64 = 1_000_000_000;
-		let start_block: u64 = 10457457;
+		let initial_issuance = 1_000_000_000;
+		let start_block = 10457457;
 		let _ = <Balances as Balanced<_>>::deposit(&1234, initial_issuance, Precision::Exact);
 		assert_eq!(Balances::free_balance(1234), initial_issuance);
 		MockBlockNumberProvider::set(start_block);
@@ -273,7 +275,7 @@
 			Inflation::on_initialize(0);
 		}
 		assert_eq!(
-			initial_issuance + (FIRST_YEAR_BLOCK_INFLATION * (YEAR / 100)),
+			initial_issuance + (FIRST_YEAR_BLOCK_INFLATION * ((YEAR as u64) / 100)),
 			<Balances as Inspect<_>>::total_issuance()
 		);
 
@@ -282,8 +284,8 @@
 		let block_inflation_year_2 = block_inflation!();
 		// Expected 100-block inflation for year 2: 100 * 9.33% * initial issuance * 110% / YEAR == 1951
 		let expecter_year_2_inflation: u64 = (initial_issuance
-			+ FIRST_YEAR_BLOCK_INFLATION * YEAR / 100)
-			* 933 * 100 / (10000 * YEAR);
+			+ FIRST_YEAR_BLOCK_INFLATION * (YEAR as u64) / 100)
+			* 933 * 100 / (10000 * (YEAR as u64));
 		assert_eq!(block_inflation_year_2 / 10, expecter_year_2_inflation / 10); // divide by 10 for approx. equality
 	});
 }
@@ -320,14 +322,14 @@
 #[test]
 fn inflation_rate_by_year() {
 	new_test_ext().execute_with(|| {
-		let payouts: u64 = YEAR / InflationBlockInterval::get() as u64;
+		let payouts = (YEAR / InflationBlockInterval::get()) as u64;
 
 		// Inflation starts at 10% and does down by 2/3% every year until year 9 (included),
 		// then it is flat.
 		let payout_by_year: [u64; 11] = [1000, 933, 867, 800, 733, 667, 600, 533, 467, 400, 400];
 
 		// For accuracy total issuance = payout0 * payouts * 10;
-		let initial_issuance: u64 = payout_by_year[0] * payouts * 10;
+		let initial_issuance = payout_by_year[0] * payouts * 10;
 		let _ = <Balances as Balanced<_>>::deposit(&1234, initial_issuance, Precision::Exact);
 		assert_eq!(Balances::free_balance(1234), initial_issuance);
 
modifiedruntime/common/tests/mod.rsdiffbeforeafterboth
--- a/runtime/common/tests/mod.rs
+++ b/runtime/common/tests/mod.rs
@@ -19,7 +19,7 @@
 use sp_runtime::{BuildStorage, Storage};
 use up_common::types::AuraId;
 
-use crate::{BuildGenesisConfig, ParachainInfoConfig, Runtime, RuntimeEvent, System};
+use crate::{ParachainInfoConfig, Runtime, RuntimeEvent, RuntimeGenesisConfig, System};
 pub type Balance = u128;
 
 pub mod xcm;
@@ -51,8 +51,8 @@
 fn new_test_ext(balances: Vec<(AccountId, Balance)>) -> sp_io::TestExternalities {
 	let mut storage = make_basic_storage();
 
-	pallet_balances::BuildGenesisConfig::<Runtime> { balances }
-		.build_storage(&mut storage)
+	pallet_balances::GenesisConfig::<Runtime> { balances }
+		.assimilate_storage(&mut storage)
 		.unwrap();
 
 	let mut ext = sp_io::TestExternalities::new(storage);
@@ -95,7 +95,7 @@
 		.map(|acc| get_account_id_from_seed::<sr25519::Public>(acc))
 		.collect::<Vec<_>>();
 
-	let cfg = BuildGenesisConfig {
+	let cfg = RuntimeGenesisConfig {
 		collator_selection: CollatorSelectionConfig { invulnerables },
 		session: SessionConfig { keys },
 		parachain_info: ParachainInfoConfig {
@@ -112,7 +112,7 @@
 fn make_basic_storage() -> Storage {
 	use crate::AuraConfig;
 
-	let cfg = BuildGenesisConfig {
+	let cfg = RuntimeGenesisConfig {
 		aura: AuraConfig {
 			authorities: vec![
 				get_from_seed::<AuraId>("Alice"),
modifiedruntime/common/tests/xcm.rsdiffbeforeafterboth
--- a/runtime/common/tests/xcm.rs
+++ b/runtime/common/tests/xcm.rs
@@ -52,9 +52,9 @@
 
 		let xcm_event = &last_events(1)[0];
 		match xcm_event {
-			RuntimeEvent::PolkadotXcm(pallet_xcm::Event::<Runtime>::Attempted(
-				Outcome::Incomplete(_weight, Error::NoPermission),
-			)) => { /* Pass */ }
+			RuntimeEvent::PolkadotXcm(pallet_xcm::Event::<Runtime>::Attempted {
+				outcome: Outcome::Incomplete(_weight, Error::NoPermission),
+			}) => { /* Pass */ }
 			_ => panic!(
 				"Expected PolkadotXcm.Attempted(Incomplete(_weight, NoPermission)),\
 				found: {xcm_event:#?}"
addedruntime/tests/src/dispatch.rsdiffbeforeafterboth
--- /dev/null
+++ b/runtime/tests/src/dispatch.rs
@@ -0,0 +1 @@
+../../common/dispatch.rs
\ No newline at end of file
modifiedruntime/tests/src/lib.rsdiffbeforeafterboth
--- a/runtime/tests/src/lib.rs
+++ b/runtime/tests/src/lib.rs
@@ -33,23 +33,20 @@
 use scale_info::TypeInfo;
 use sp_core::{H160, H256, U256};
 use sp_runtime::{
-	testing::Header,
 	traits::{BlakeTwo256, IdentityLookup},
+	BuildStorage,
 };
 use up_data_structs::mapping::{CrossTokenAddressMapping, EvmTokenAddressMapping};
 
-#[path = "../../common/dispatch.rs"]
 mod dispatch;
 
 use dispatch::CollectionDispatchT;
 
-#[path = "../../common/weights/mod.rs"]
 mod weights;
 
 use weights::CommonWeights;
 
-type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
-type Block = frame_system::mocking::MockBlock<Test>;
+type Block = frame_system::mocking::MockBlockU32<Test>;
 
 #[cfg(test)]
 mod tests;
@@ -73,13 +70,14 @@
 );
 
 parameter_types! {
-	pub const BlockHashCount: u64 = 250;
+	pub const BlockHashCount: u32 = 250;
 	pub const SS58Prefix: u8 = 42;
 }
 
 impl system::Config for Test {
 	type RuntimeEvent = RuntimeEvent;
 	type BaseCallFilter = Everything;
+	type Block = Block;
 	type BlockWeights = ();
 	type BlockLength = ();
 	type DbWeight = ();
@@ -120,6 +118,7 @@
 	type MaxFreezes = MaxLocks;
 	type FreezeIdentifier = [u8; 8];
 	type MaxHolds = MaxLocks;
+	type RuntimeHoldReason = RuntimeHoldReason;
 }
 
 parameter_types! {
@@ -232,6 +231,7 @@
 	type OnMethodCall = ();
 	type OnCreate = ();
 	type OnChargeTransaction = ();
+	type OnCheckEvmTransaction = ();
 	type FindAuthor = ();
 	type BlockHashMapping = SubstrateBlockHashMapping<Self>;
 	type Timestamp = Timestamp;
@@ -296,8 +296,8 @@
 
 // Build genesis storage according to the mock runtime.
 pub fn new_test_ext() -> sp_io::TestExternalities {
-	system::GenesisConfig::default()
-		.build_storage::<Test>()
+	<system::GenesisConfig<Test>>::default()
+		.build_storage()
 		.unwrap()
 		.into()
 }
addedruntime/tests/src/weightsdiffbeforeafterboth
--- /dev/null
+++ b/runtime/tests/src/weights
@@ -0,0 +1 @@
+../../common/weights
\ No newline at end of file