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

difftreelog

test fix unit

Yaroslav Bolyukin2023-11-24parent: #3e2337f.patch.diff
in: master

4 files changed

modifiedpallets/collator-selection/src/mock.rsdiffbeforeafterboth
--- a/pallets/collator-selection/src/mock.rs
+++ b/pallets/collator-selection/src/mock.rs
@@ -114,6 +114,7 @@
 	type MaxHolds = MaxHolds;
 	type MaxFreezes = MaxFreezes;
 	type RuntimeHoldReason = RuntimeHoldReason;
+	type RuntimeFreezeReason = RuntimeFreezeReason;
 }
 
 pub struct Author4;
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	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}
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 RuntimeFreezeReason = RuntimeFreezeReason;105	type FreezeIdentifier = ();106	type MaxHolds = ();107	type MaxFreezes = ();108}109110parameter_types! {111	pub const MaxAdditionalFields: u32 = 2;112	pub const MaxRegistrars: u32 = 20;113}114115ord_parameter_types! {116	pub const One: u64 = 1;117	pub const Two: u64 = 2;118}119type EnsureOneOrRoot = EitherOfDiverse<EnsureRoot<u64>, EnsureSignedBy<One, u64>>;120type EnsureTwoOrRoot = EitherOfDiverse<EnsureRoot<u64>, EnsureSignedBy<Two, u64>>;121impl pallet_identity::Config for Test {122	type RuntimeEvent = RuntimeEvent;123	type Currency = Balances;124	type Slashed = ();125	type BasicDeposit = ConstU64<10>;126	type FieldDeposit = ConstU64<10>;127	type SubAccountDeposit = ConstU64<10>;128	type MaxSubAccounts = ConstU32<2>;129	type MaxAdditionalFields = MaxAdditionalFields;130	type MaxRegistrars = MaxRegistrars;131	type RegistrarOrigin = EnsureOneOrRoot;132	type ForceOrigin = EnsureTwoOrRoot;133	type WeightInfo = ();134}135136pub fn new_test_ext() -> sp_io::TestExternalities {137	let mut t = <frame_system::GenesisConfig<Test>>::default()138		.build_storage()139		.unwrap();140	pallet_balances::GenesisConfig::<Test> {141		balances: vec![(1, 10), (2, 10), (3, 10), (10, 100), (20, 100), (30, 100)],142	}143	.assimilate_storage(&mut t)144	.unwrap();145	t.into()146}147148fn ten() -> IdentityInfo<MaxAdditionalFields> {149	IdentityInfo {150		display: Data::Raw(b"ten".to_vec().try_into().unwrap()),151		legal: Data::Raw(b"The Right Ordinal Ten, Esq.".to_vec().try_into().unwrap()),152		..Default::default()153	}154}155156fn twenty() -> IdentityInfo<MaxAdditionalFields> {157	IdentityInfo {158		display: Data::Raw(b"twenty".to_vec().try_into().unwrap()),159		legal: Data::Raw(160			b"The Right Ordinal Twenty, Esq."161				.to_vec()162				.try_into()163				.unwrap(),164		),165		..Default::default()166	}167}168169#[test]170fn editing_subaccounts_should_work() {171	new_test_ext().execute_with(|| {172		let data = |x| Data::Raw(vec![x; 1].try_into().unwrap());173174		assert_noop!(175			Identity::add_sub(RuntimeOrigin::signed(10), 20, data(1)),176			Error::<Test>::NoIdentity177		);178179		assert_ok!(Identity::set_identity(180			RuntimeOrigin::signed(10),181			Box::new(ten())182		));183184		// first sub account185		assert_ok!(Identity::add_sub(RuntimeOrigin::signed(10), 1, data(1)));186		assert_eq!(SuperOf::<Test>::get(1), Some((10, data(1))));187		assert_eq!(Balances::free_balance(10), 80);188189		// second sub account190		assert_ok!(Identity::add_sub(RuntimeOrigin::signed(10), 2, data(2)));191		assert_eq!(SuperOf::<Test>::get(1), Some((10, data(1))));192		assert_eq!(SuperOf::<Test>::get(2), Some((10, data(2))));193		assert_eq!(Balances::free_balance(10), 70);194195		// third sub account is too many196		assert_noop!(197			Identity::add_sub(RuntimeOrigin::signed(10), 3, data(3)),198			Error::<Test>::TooManySubAccounts199		);200201		// rename first sub account202		assert_ok!(Identity::rename_sub(RuntimeOrigin::signed(10), 1, data(11)));203		assert_eq!(SuperOf::<Test>::get(1), Some((10, data(11))));204		assert_eq!(SuperOf::<Test>::get(2), Some((10, data(2))));205		assert_eq!(Balances::free_balance(10), 70);206207		// remove first sub account208		assert_ok!(Identity::remove_sub(RuntimeOrigin::signed(10), 1));209		assert_eq!(SuperOf::<Test>::get(1), None);210		assert_eq!(SuperOf::<Test>::get(2), Some((10, data(2))));211		assert_eq!(Balances::free_balance(10), 80);212213		// add third sub account214		assert_ok!(Identity::add_sub(RuntimeOrigin::signed(10), 3, data(3)));215		assert_eq!(SuperOf::<Test>::get(1), None);216		assert_eq!(SuperOf::<Test>::get(2), Some((10, data(2))));217		assert_eq!(SuperOf::<Test>::get(3), Some((10, data(3))));218		assert_eq!(Balances::free_balance(10), 70);219	});220}221222#[test]223fn resolving_subaccount_ownership_works() {224	new_test_ext().execute_with(|| {225		let data = |x| Data::Raw(vec![x; 1].try_into().unwrap());226227		assert_ok!(Identity::set_identity(228			RuntimeOrigin::signed(10),229			Box::new(ten())230		));231		assert_ok!(Identity::set_identity(232			RuntimeOrigin::signed(20),233			Box::new(twenty())234		));235236		// 10 claims 1 as a subaccount237		assert_ok!(Identity::add_sub(RuntimeOrigin::signed(10), 1, data(1)));238		assert_eq!(Balances::free_balance(1), 10);239		assert_eq!(Balances::free_balance(10), 80);240		assert_eq!(Balances::reserved_balance(10), 20);241		// 20 cannot claim 1 now242		assert_noop!(243			Identity::add_sub(RuntimeOrigin::signed(20), 1, data(1)),244			Error::<Test>::AlreadyClaimed245		);246		// 1 wants to be with 20 so it quits from 10247		assert_ok!(Identity::quit_sub(RuntimeOrigin::signed(1)));248		// 1 gets the 10 that 10 paid.249		assert_eq!(Balances::free_balance(1), 20);250		assert_eq!(Balances::free_balance(10), 80);251		assert_eq!(Balances::reserved_balance(10), 10);252		// 20 can claim 1 now253		assert_ok!(Identity::add_sub(RuntimeOrigin::signed(20), 1, data(1)));254	});255}256257#[test]258fn trailing_zeros_decodes_into_default_data() {259	let encoded = Data::Raw(b"Hello".to_vec().try_into().unwrap()).encode();260	assert!(<(Data, Data)>::decode(&mut &encoded[..]).is_err());261	let input = &mut &encoded[..];262	let (a, b) = <(Data, Data)>::decode(&mut AppendZerosInput::new(input)).unwrap();263	assert_eq!(a, Data::Raw(b"Hello".to_vec().try_into().unwrap()));264	assert_eq!(b, Data::None);265}266267#[test]268fn adding_registrar_should_work() {269	new_test_ext().execute_with(|| {270		assert_ok!(Identity::add_registrar(RuntimeOrigin::signed(1), 3));271		assert_ok!(Identity::set_fee(RuntimeOrigin::signed(3), 0, 10));272		let fields = IdentityFields(IdentityField::Display | IdentityField::Legal);273		assert_ok!(Identity::set_fields(RuntimeOrigin::signed(3), 0, fields));274		assert_eq!(275			Identity::registrars(),276			vec![Some(RegistrarInfo {277				account: 3,278				fee: 10,279				fields280			})]281		);282	});283}284285#[test]286fn amount_of_registrars_is_limited() {287	new_test_ext().execute_with(|| {288		for i in 1..MaxRegistrars::get() + 1 {289			assert_ok!(Identity::add_registrar(RuntimeOrigin::signed(1), i as u64));290		}291		let last_registrar = MaxRegistrars::get() as u64 + 1;292		assert_noop!(293			Identity::add_registrar(RuntimeOrigin::signed(1), last_registrar),294			Error::<Test>::TooManyRegistrars295		);296	});297}298299#[test]300fn registration_should_work() {301	new_test_ext().execute_with(|| {302		assert_ok!(Identity::add_registrar(RuntimeOrigin::signed(1), 3));303		assert_ok!(Identity::set_fee(RuntimeOrigin::signed(3), 0, 10));304		let mut three_fields = ten();305		three_fields306			.additional307			.try_push(Default::default())308			.unwrap();309		three_fields310			.additional311			.try_push(Default::default())312			.unwrap();313		assert!(three_fields314			.additional315			.try_push(Default::default())316			.is_err());317		assert_ok!(Identity::set_identity(318			RuntimeOrigin::signed(10),319			Box::new(ten())320		));321		assert_eq!(Identity::identity(10).unwrap().info, ten());322		assert_eq!(Balances::free_balance(10), 90);323		assert_ok!(Identity::clear_identity(RuntimeOrigin::signed(10)));324		assert_eq!(Balances::free_balance(10), 100);325		assert_noop!(326			Identity::clear_identity(RuntimeOrigin::signed(10)),327			Error::<Test>::NotNamed328		);329	});330}331332#[test]333fn uninvited_judgement_should_work() {334	new_test_ext().execute_with(|| {335		assert_noop!(336			Identity::provide_judgement(337				RuntimeOrigin::signed(3),338				0,339				10,340				Judgement::Reasonable,341				H256::random()342			),343			Error::<Test>::InvalidIndex344		);345346		assert_ok!(Identity::add_registrar(RuntimeOrigin::signed(1), 3));347		assert_noop!(348			Identity::provide_judgement(349				RuntimeOrigin::signed(3),350				0,351				10,352				Judgement::Reasonable,353				H256::random()354			),355			Error::<Test>::InvalidTarget356		);357358		assert_ok!(Identity::set_identity(359			RuntimeOrigin::signed(10),360			Box::new(ten())361		));362		assert_noop!(363			Identity::provide_judgement(364				RuntimeOrigin::signed(3),365				0,366				10,367				Judgement::Reasonable,368				H256::random()369			),370			Error::<Test>::JudgementForDifferentIdentity371		);372373		let identity_hash = BlakeTwo256::hash_of(&ten());374375		assert_noop!(376			Identity::provide_judgement(377				RuntimeOrigin::signed(10),378				0,379				10,380				Judgement::Reasonable,381				identity_hash382			),383			Error::<Test>::InvalidIndex384		);385		assert_noop!(386			Identity::provide_judgement(387				RuntimeOrigin::signed(3),388				0,389				10,390				Judgement::FeePaid(1),391				identity_hash392			),393			Error::<Test>::InvalidJudgement394		);395396		assert_ok!(Identity::provide_judgement(397			RuntimeOrigin::signed(3),398			0,399			10,400			Judgement::Reasonable,401			identity_hash402		));403		assert_eq!(404			Identity::identity(10).unwrap().judgements,405			vec![(0, Judgement::Reasonable)]406		);407	});408}409410#[test]411fn clearing_judgement_should_work() {412	new_test_ext().execute_with(|| {413		assert_ok!(Identity::add_registrar(RuntimeOrigin::signed(1), 3));414		assert_ok!(Identity::set_identity(415			RuntimeOrigin::signed(10),416			Box::new(ten())417		));418		assert_ok!(Identity::provide_judgement(419			RuntimeOrigin::signed(3),420			0,421			10,422			Judgement::Reasonable,423			BlakeTwo256::hash_of(&ten())424		));425		assert_ok!(Identity::clear_identity(RuntimeOrigin::signed(10)));426		assert_eq!(Identity::identity(10), None);427	});428}429430#[test]431fn killing_slashing_should_work() {432	new_test_ext().execute_with(|| {433		assert_ok!(Identity::set_identity(434			RuntimeOrigin::signed(10),435			Box::new(ten())436		));437		assert_noop!(438			Identity::kill_identity(RuntimeOrigin::signed(1), 10),439			BadOrigin440		);441		assert_ok!(Identity::kill_identity(RuntimeOrigin::signed(2), 10));442		assert_eq!(Identity::identity(10), None);443		assert_eq!(Balances::free_balance(10), 90);444		assert_noop!(445			Identity::kill_identity(RuntimeOrigin::signed(2), 10),446			Error::<Test>::NotNamed447		);448	});449}450451#[test]452fn setting_subaccounts_should_work() {453	new_test_ext().execute_with(|| {454		let mut subs = vec![(20, Data::Raw(vec![40; 1].try_into().unwrap()))];455		assert_noop!(456			Identity::set_subs(RuntimeOrigin::signed(10), subs.clone()),457			Error::<Test>::NotFound458		);459460		assert_ok!(Identity::set_identity(461			RuntimeOrigin::signed(10),462			Box::new(ten())463		));464		assert_ok!(Identity::set_subs(RuntimeOrigin::signed(10), subs.clone()));465		assert_eq!(Balances::free_balance(10), 80);466		assert_eq!(Identity::subs_of(10), (10, vec![20].try_into().unwrap()));467		assert_eq!(468			Identity::super_of(20),469			Some((10, Data::Raw(vec![40; 1].try_into().unwrap())))470		);471472		// push another item and re-set it.473		subs.push((30, Data::Raw(vec![50; 1].try_into().unwrap())));474		assert_ok!(Identity::set_subs(RuntimeOrigin::signed(10), subs.clone()));475		assert_eq!(Balances::free_balance(10), 70);476		assert_eq!(477			Identity::subs_of(10),478			(20, vec![20, 30].try_into().unwrap())479		);480		assert_eq!(481			Identity::super_of(20),482			Some((10, Data::Raw(vec![40; 1].try_into().unwrap())))483		);484		assert_eq!(485			Identity::super_of(30),486			Some((10, Data::Raw(vec![50; 1].try_into().unwrap())))487		);488489		// switch out one of the items and re-set.490		subs[0] = (40, Data::Raw(vec![60; 1].try_into().unwrap()));491		assert_ok!(Identity::set_subs(RuntimeOrigin::signed(10), subs.clone()));492		assert_eq!(Balances::free_balance(10), 70); // no change in the balance493		assert_eq!(494			Identity::subs_of(10),495			(20, vec![40, 30].try_into().unwrap())496		);497		assert_eq!(Identity::super_of(20), None);498		assert_eq!(499			Identity::super_of(30),500			Some((10, Data::Raw(vec![50; 1].try_into().unwrap())))501		);502		assert_eq!(503			Identity::super_of(40),504			Some((10, Data::Raw(vec![60; 1].try_into().unwrap())))505		);506507		// clear508		assert_ok!(Identity::set_subs(RuntimeOrigin::signed(10), vec![]));509		assert_eq!(Balances::free_balance(10), 90);510		assert_eq!(Identity::subs_of(10), (0, BoundedVec::default()));511		assert_eq!(Identity::super_of(30), None);512		assert_eq!(Identity::super_of(40), None);513514		subs.push((20, Data::Raw(vec![40; 1].try_into().unwrap())));515		assert_noop!(516			Identity::set_subs(RuntimeOrigin::signed(10), subs.clone()),517			Error::<Test>::TooManySubAccounts518		);519	});520}521522#[test]523fn clearing_account_should_remove_subaccounts_and_refund() {524	new_test_ext().execute_with(|| {525		assert_ok!(Identity::set_identity(526			RuntimeOrigin::signed(10),527			Box::new(ten())528		));529		assert_ok!(Identity::set_subs(530			RuntimeOrigin::signed(10),531			vec![(20, Data::Raw(vec![40; 1].try_into().unwrap()))]532		));533		assert_ok!(Identity::clear_identity(RuntimeOrigin::signed(10)));534		assert_eq!(Balances::free_balance(10), 100);535		assert!(Identity::super_of(20).is_none());536	});537}538539#[test]540fn killing_account_should_remove_subaccounts_and_not_refund() {541	new_test_ext().execute_with(|| {542		assert_ok!(Identity::set_identity(543			RuntimeOrigin::signed(10),544			Box::new(ten())545		));546		assert_ok!(Identity::set_subs(547			RuntimeOrigin::signed(10),548			vec![(20, Data::Raw(vec![40; 1].try_into().unwrap()))]549		));550		assert_ok!(Identity::kill_identity(RuntimeOrigin::signed(2), 10));551		assert_eq!(Balances::free_balance(10), 80);552		assert!(Identity::super_of(20).is_none());553	});554}555556#[test]557fn cancelling_requested_judgement_should_work() {558	new_test_ext().execute_with(|| {559		assert_ok!(Identity::add_registrar(RuntimeOrigin::signed(1), 3));560		assert_ok!(Identity::set_fee(RuntimeOrigin::signed(3), 0, 10));561		assert_noop!(562			Identity::cancel_request(RuntimeOrigin::signed(10), 0),563			Error::<Test>::NoIdentity564		);565		assert_ok!(Identity::set_identity(566			RuntimeOrigin::signed(10),567			Box::new(ten())568		));569		assert_ok!(Identity::request_judgement(570			RuntimeOrigin::signed(10),571			0,572			10573		));574		assert_ok!(Identity::cancel_request(RuntimeOrigin::signed(10), 0));575		assert_eq!(Balances::free_balance(10), 90);576		assert_noop!(577			Identity::cancel_request(RuntimeOrigin::signed(10), 0),578			Error::<Test>::NotFound579		);580581		assert_ok!(Identity::provide_judgement(582			RuntimeOrigin::signed(3),583			0,584			10,585			Judgement::Reasonable,586			BlakeTwo256::hash_of(&ten())587		));588		assert_noop!(589			Identity::cancel_request(RuntimeOrigin::signed(10), 0),590			Error::<Test>::JudgementGiven591		);592	});593}594595#[test]596fn requesting_judgement_should_work() {597	new_test_ext().execute_with(|| {598		assert_ok!(Identity::add_registrar(RuntimeOrigin::signed(1), 3));599		assert_ok!(Identity::set_fee(RuntimeOrigin::signed(3), 0, 10));600		assert_ok!(Identity::set_identity(601			RuntimeOrigin::signed(10),602			Box::new(ten())603		));604		assert_noop!(605			Identity::request_judgement(RuntimeOrigin::signed(10), 0, 9),606			Error::<Test>::FeeChanged607		);608		assert_ok!(Identity::request_judgement(609			RuntimeOrigin::signed(10),610			0,611			10612		));613		// 10 for the judgement request, 10 for the identity.614		assert_eq!(Balances::free_balance(10), 80);615616		// Re-requesting won't work as we already paid.617		assert_noop!(618			Identity::request_judgement(RuntimeOrigin::signed(10), 0, 10),619			Error::<Test>::StickyJudgement620		);621		assert_ok!(Identity::provide_judgement(622			RuntimeOrigin::signed(3),623			0,624			10,625			Judgement::Erroneous,626			BlakeTwo256::hash_of(&ten())627		));628		// Registrar got their payment now.629		assert_eq!(Balances::free_balance(3), 20);630631		// Re-requesting still won't work as it's erroneous.632		assert_noop!(633			Identity::request_judgement(RuntimeOrigin::signed(10), 0, 10),634			Error::<Test>::StickyJudgement635		);636637		// Requesting from a second registrar still works.638		assert_ok!(Identity::add_registrar(RuntimeOrigin::signed(1), 4));639		assert_ok!(Identity::request_judgement(640			RuntimeOrigin::signed(10),641			1,642			10643		));644645		// Re-requesting after the judgement has been reduced works.646		assert_ok!(Identity::provide_judgement(647			RuntimeOrigin::signed(3),648			0,649			10,650			Judgement::OutOfDate,651			BlakeTwo256::hash_of(&ten())652		));653		assert_ok!(Identity::request_judgement(654			RuntimeOrigin::signed(10),655			0,656			10657		));658	});659}660661#[test]662fn provide_judgement_should_return_judgement_payment_failed_error() {663	new_test_ext().execute_with(|| {664		assert_ok!(Identity::add_registrar(RuntimeOrigin::signed(1), 3));665		assert_ok!(Identity::set_fee(RuntimeOrigin::signed(3), 0, 10));666		assert_ok!(Identity::set_identity(667			RuntimeOrigin::signed(10),668			Box::new(ten())669		));670		assert_ok!(Identity::request_judgement(671			RuntimeOrigin::signed(10),672			0,673			10674		));675		// 10 for the judgement request, 10 for the identity.676		assert_eq!(Balances::free_balance(10), 80);677678		// This forces judgement payment failed error679		Balances::make_free_balance_be(&3, 0);680		assert_noop!(681			Identity::provide_judgement(682				RuntimeOrigin::signed(3),683				0,684				10,685				Judgement::Erroneous,686				BlakeTwo256::hash_of(&ten())687			),688			Error::<Test>::JudgementPaymentFailed689		);690	});691}692693#[test]694fn field_deposit_should_work() {695	new_test_ext().execute_with(|| {696		assert_ok!(Identity::add_registrar(RuntimeOrigin::signed(1), 3));697		assert_ok!(Identity::set_fee(RuntimeOrigin::signed(3), 0, 10));698		assert_ok!(Identity::set_identity(699			RuntimeOrigin::signed(10),700			Box::new(IdentityInfo {701				additional: vec![702					(703						Data::Raw(b"number".to_vec().try_into().unwrap()),704						Data::Raw(10u32.encode().try_into().unwrap())705					),706					(707						Data::Raw(b"text".to_vec().try_into().unwrap()),708						Data::Raw(b"10".to_vec().try_into().unwrap())709					),710				]711				.try_into()712				.unwrap(),713				..Default::default()714			})715		));716		assert_eq!(Balances::free_balance(10), 70);717	});718}719720#[test]721fn setting_account_id_should_work() {722	new_test_ext().execute_with(|| {723		assert_ok!(Identity::add_registrar(RuntimeOrigin::signed(1), 3));724		// account 4 cannot change the first registrar's identity since it's owned by 3.725		assert_noop!(726			Identity::set_account_id(RuntimeOrigin::signed(4), 0, 3),727			Error::<Test>::InvalidIndex728		);729		// account 3 can, because that's the registrar's current account.730		assert_ok!(Identity::set_account_id(RuntimeOrigin::signed(3), 0, 4));731		// account 4 can now, because that's their new ID.732		assert_ok!(Identity::set_account_id(RuntimeOrigin::signed(4), 0, 3));733	});734}735736#[test]737fn test_has_identity() {738	new_test_ext().execute_with(|| {739		assert_ok!(Identity::set_identity(740			RuntimeOrigin::signed(10),741			Box::new(ten())742		));743		assert!(Identity::has_identity(&10, IdentityField::Display as u64));744		assert!(Identity::has_identity(&10, IdentityField::Legal as u64));745		assert!(Identity::has_identity(746			&10,747			IdentityField::Display as u64 | IdentityField::Legal as u64748		));749		assert!(!Identity::has_identity(750			&10,751			IdentityField::Display as u64 | IdentityField::Legal as u64 | IdentityField::Web as u64752		));753	});754}
modifiedpallets/inflation/src/tests.rsdiffbeforeafterboth
--- a/pallets/inflation/src/tests.rs
+++ b/pallets/inflation/src/tests.rs
@@ -61,6 +61,7 @@
 	type MaxHolds = ();
 	type MaxFreezes = ();
 	type RuntimeHoldReason = RuntimeHoldReason;
+	type RuntimeFreezeReason = RuntimeFreezeReason;
 }
 
 frame_support::construct_runtime!(
modifiedruntime/tests/src/lib.rsdiffbeforeafterboth
--- a/runtime/tests/src/lib.rs
+++ b/runtime/tests/src/lib.rs
@@ -119,6 +119,7 @@
 	type FreezeIdentifier = [u8; 8];
 	type MaxHolds = MaxLocks;
 	type RuntimeHoldReason = RuntimeHoldReason;
+	type RuntimeFreezeReason = RuntimeFreezeReason;
 }
 
 parameter_types! {