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

difftreelog

source

pallets/unique/src/tests.rs67.3 KiBsourcehistory
1// Tests to be written here2use super::*;3use crate::mock::*;4use crate::{AccessMode, CollectionMode};5use up_data_structs::{6	COLLECTION_NUMBER_LIMIT, CollectionId, CreateItemData, CreateFungibleData, CreateNftData,7	CreateReFungibleData, MAX_DECIMAL_POINTS, COLLECTION_ADMINS_LIMIT, MetaUpdatePermission,8	TokenId, MAX_TOKEN_OWNERSHIP,9};10use frame_support::{assert_noop, assert_ok, assert_err};11use sp_std::convert::TryInto;12use pallet_balances;1314fn add_balance(user: u64, value: u64) {15	const DONOR_USER: u64 = 999;16	assert_ok!(<pallet_balances::Pallet<Test>>::set_balance(17		Origin::root(),18		DONOR_USER,19		value,20		021	));22	assert_ok!(<pallet_balances::Pallet<Test>>::force_transfer(23		Origin::root(),24		DONOR_USER,25		user,26		value27	));28}2930fn default_nft_data() -> CreateNftData {31	CreateNftData {32		const_data: vec![1, 2, 3].try_into().unwrap(),33		variable_data: vec![3, 2, 1].try_into().unwrap(),34	}35}3637fn default_fungible_data() -> CreateFungibleData {38	CreateFungibleData { value: 5 }39}4041fn default_re_fungible_data() -> CreateReFungibleData {42	CreateReFungibleData {43		const_data: vec![1, 2, 3].try_into().unwrap(),44		variable_data: vec![3, 2, 1].try_into().unwrap(),45		pieces: 1023,46	}47}4849fn create_test_collection_for_owner(50	mode: &CollectionMode,51	owner: u64,52	id: CollectionId,53) -> CollectionId {54	add_balance(owner, CollectionCreationPrice::get() as u64 + 1);5556	let col_name1: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();57	let col_desc1: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();58	let token_prefix1: Vec<u8> = b"token_prefix1\0".to_vec();5960	let origin1 = Origin::signed(owner);61	assert_ok!(TemplateModule::create_collection(62		origin1,63		col_name1.try_into().unwrap(),64		col_desc1.try_into().unwrap(),65		token_prefix1.try_into().unwrap(),66		mode.clone()67	));6869	let saved_col_name: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();70	let saved_description: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();71	let saved_prefix: Vec<u8> = b"token_prefix1\0".to_vec();72	assert_eq!(73		<pallet_common::CollectionById<Test>>::get(id)74			.unwrap()75			.owner,76		owner77	);78	assert_eq!(79		<pallet_common::CollectionById<Test>>::get(id).unwrap().name,80		saved_col_name81	);82	assert_eq!(83		<pallet_common::CollectionById<Test>>::get(id).unwrap().mode,84		*mode85	);86	assert_eq!(87		<pallet_common::CollectionById<Test>>::get(id)88			.unwrap()89			.description,90		saved_description91	);92	assert_eq!(93		<pallet_common::CollectionById<Test>>::get(id)94			.unwrap()95			.token_prefix,96		saved_prefix97	);98	id99}100101fn create_test_collection(mode: &CollectionMode, id: CollectionId) -> CollectionId {102	create_test_collection_for_owner(&mode, 1, id)103}104105fn create_test_item(collection_id: CollectionId, data: &CreateItemData) {106	let origin1 = Origin::signed(1);107	assert_ok!(TemplateModule::create_item(108		origin1,109		collection_id,110		account(1),111		data.clone()112	));113}114115fn account(sub: u64) -> TestCrossAccountId {116	TestCrossAccountId::from_sub(sub)117}118119// Use cases tests region120// #region121122#[test]123fn set_version_schema() {124	new_test_ext().execute_with(|| {125		let origin1 = Origin::signed(1);126		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));127128		assert_ok!(TemplateModule::set_schema_version(129			origin1,130			collection_id,131			SchemaVersion::Unique132		));133		assert_eq!(134			<pallet_common::CollectionById<Test>>::get(collection_id)135				.unwrap()136				.schema_version,137			SchemaVersion::Unique138		);139	});140}141142#[test]143fn check_not_sufficient_founds() {144	new_test_ext().execute_with(|| {145		let acc: u64 = 1;146		<pallet_balances::Pallet<Test>>::set_balance(Origin::root(), acc, 0, 0).unwrap();147148		let name: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();149		let description: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();150		let token_prefix: Vec<u8> = b"token_prefix1\0".to_vec();151152		let data: CreateCollectionData<<Test as system::Config>::AccountId> =153			CreateCollectionData {154				name: name.try_into().unwrap(),155				description: description.try_into().unwrap(),156				token_prefix: token_prefix.try_into().unwrap(),157				mode: CollectionMode::NFT,158				..Default::default()159			};160161		let result = TemplateModule::create_collection_ex(Origin::signed(acc), data);162		assert_err!(result, <CommonError<Test>>::NotSufficientFounds);163	});164}165166#[test]167fn create_fungible_collection_fails_with_large_decimal_numbers() {168	new_test_ext().execute_with(|| {169		let col_name1: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();170		let col_desc1: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();171		let token_prefix1: Vec<u8> = b"token_prefix1\0".to_vec();172173		let origin1 = Origin::signed(1);174		assert_noop!(175			TemplateModule::create_collection(176				origin1,177				col_name1.try_into().unwrap(),178				col_desc1.try_into().unwrap(),179				token_prefix1.try_into().unwrap(),180				CollectionMode::Fungible(MAX_DECIMAL_POINTS + 1)181			),182			Error::<Test>::CollectionDecimalPointLimitExceeded183		);184	});185}186187#[test]188fn create_nft_item() {189	new_test_ext().execute_with(|| {190		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));191192		let data = default_nft_data();193		create_test_item(collection_id, &data.clone().into());194195		let item = <pallet_nonfungible::TokenData<Test>>::get((collection_id, 1)).unwrap();196		assert_eq!(item.const_data, data.const_data.into_inner());197		assert_eq!(item.variable_data, data.variable_data.into_inner());198	});199}200201// Use cases tests region202// #region203#[test]204fn create_nft_multiple_items() {205	new_test_ext().execute_with(|| {206		create_test_collection(&CollectionMode::NFT, CollectionId(1));207208		let origin1 = Origin::signed(1);209210		let items_data = vec![default_nft_data(), default_nft_data(), default_nft_data()];211212		assert_ok!(TemplateModule::create_multiple_items(213			origin1,214			CollectionId(1),215			account(1),216			items_data217				.clone()218				.into_iter()219				.map(|d| { d.into() })220				.collect()221		));222		for (index, data) in items_data.into_iter().enumerate() {223			let item = <pallet_nonfungible::TokenData<Test>>::get((224				CollectionId(1),225				TokenId((index + 1) as u32),226			))227			.unwrap();228			assert_eq!(item.const_data.to_vec(), data.const_data.into_inner());229			assert_eq!(item.variable_data.to_vec(), data.variable_data.into_inner());230		}231	});232}233234#[test]235fn create_refungible_item() {236	new_test_ext().execute_with(|| {237		let collection_id = create_test_collection(&CollectionMode::ReFungible, CollectionId(1));238239		let data = default_re_fungible_data();240		create_test_item(collection_id, &data.clone().into());241		let item = <pallet_refungible::TokenData<Test>>::get((collection_id, TokenId(1)));242		let balance =243			<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1)));244		assert_eq!(item.const_data, data.const_data.into_inner());245		assert_eq!(item.variable_data, data.variable_data.into_inner());246		assert_eq!(balance, 1023);247	});248}249250#[test]251fn create_multiple_refungible_items() {252	new_test_ext().execute_with(|| {253		create_test_collection(&CollectionMode::ReFungible, CollectionId(1));254255		let origin1 = Origin::signed(1);256257		let items_data = vec![258			default_re_fungible_data(),259			default_re_fungible_data(),260			default_re_fungible_data(),261		];262263		assert_ok!(TemplateModule::create_multiple_items(264			origin1,265			CollectionId(1),266			account(1),267			items_data268				.clone()269				.into_iter()270				.map(|d| { d.into() })271				.collect()272		));273		for (index, data) in items_data.into_iter().enumerate() {274			let item = <pallet_refungible::TokenData<Test>>::get((275				CollectionId(1),276				TokenId((index + 1) as u32),277			));278			let balance =279				<pallet_refungible::Balance<Test>>::get((CollectionId(1), TokenId(1), account(1)));280			assert_eq!(item.const_data.to_vec(), data.const_data.into_inner());281			assert_eq!(item.variable_data.to_vec(), data.variable_data.into_inner());282			assert_eq!(balance, 1023);283		}284	});285}286287#[test]288fn create_fungible_item() {289	new_test_ext().execute_with(|| {290		let collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));291292		let data = default_fungible_data();293		create_test_item(collection_id, &data.into());294295		assert_eq!(296			<pallet_fungible::Balance<Test>>::get((collection_id, account(1))),297			5298		);299	});300}301302//#[test]303// fn create_multiple_fungible_items() {304//     new_test_ext().execute_with(|| {305//         default_limits();306307//         create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));308309//         let origin1 = Origin::signed(1);310311//         let items_data = vec![default_fungible_data(), default_fungible_data(), default_fungible_data()];312313//         assert_ok!(TemplateModule::create_multiple_items(314//             origin1.clone(),315//             1,316//             1,317//             items_data.clone().into_iter().map(|d| { d.into() }).collect()318//         ));319320//         for (index, _) in items_data.iter().enumerate() {321//             assert_eq!(TemplateModule::fungible_item_id(1, (index + 1) as TokenId).value, 5);322//         }323//         assert_eq!(TemplateModule::balance_count(1, 1), 3000);324//         assert_eq!(TemplateModule::address_tokens(1, 1), [1, 2, 3]);325//     });326// }327328#[test]329fn transfer_fungible_item() {330	new_test_ext().execute_with(|| {331		let collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));332333		let origin1 = Origin::signed(1);334		let origin2 = Origin::signed(2);335336		let data = default_fungible_data();337		create_test_item(collection_id, &data.into());338339		assert_eq!(340			<pallet_fungible::Balance<Test>>::get((CollectionId(1), account(1))),341			5342		);343344		// change owner scenario345		assert_ok!(TemplateModule::transfer(346			origin1,347			account(2),348			CollectionId(1),349			TokenId(0),350			5351		));352		assert_eq!(353			<pallet_fungible::Balance<Test>>::get((CollectionId(1), account(1))),354			0355		);356357		// split item scenario358		assert_ok!(TemplateModule::transfer(359			origin2.clone(),360			account(3),361			CollectionId(1),362			TokenId(0),363			3364		));365366		// split item and new owner has account scenario367		assert_ok!(TemplateModule::transfer(368			origin2,369			account(3),370			CollectionId(1),371			TokenId(0),372			1373		));374		assert_eq!(375			<pallet_fungible::Balance<Test>>::get((CollectionId(1), account(2))),376			1377		);378		assert_eq!(379			<pallet_fungible::Balance<Test>>::get((CollectionId(1), account(3))),380			4381		);382	});383}384385#[test]386fn transfer_refungible_item() {387	new_test_ext().execute_with(|| {388		let collection_id = create_test_collection(&CollectionMode::ReFungible, CollectionId(1));389390		// Create RFT 1 in 1023 pieces for account 1391		let data = default_re_fungible_data();392		create_test_item(collection_id, &data.clone().into());393		let item = <pallet_refungible::TokenData<Test>>::get((collection_id, TokenId(1)));394		assert_eq!(item.const_data, data.const_data.into_inner());395		assert_eq!(item.variable_data, data.variable_data.into_inner());396		assert_eq!(397			<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))),398			1399		);400		assert_eq!(401			<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1))),402			1023403		);404		assert_eq!(405			<pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),406			true407		);408409		// Account 1 transfers all 1023 pieces of RFT 1 to account 2410		let origin1 = Origin::signed(1);411		let origin2 = Origin::signed(2);412		assert_ok!(TemplateModule::transfer(413			origin1,414			account(2),415			CollectionId(1),416			TokenId(1),417			1023418		));419		assert_eq!(420			<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(2))),421			1023422		);423		assert_eq!(424			<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))),425			0426		);427		assert_eq!(428			<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(2))),429			1430		);431		assert_eq!(432			<pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),433			false434		);435		assert_eq!(436			<pallet_refungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))),437			true438		);439440		// Account 2 transfers 500 pieces of RFT 1 to account 3441		assert_ok!(TemplateModule::transfer(442			origin2.clone(),443			account(3),444			CollectionId(1),445			TokenId(1),446			500447		));448		assert_eq!(449			<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(2))),450			523451		);452		assert_eq!(453			<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(3))),454			500455		);456		assert_eq!(457			<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(2))),458			1459		);460		assert_eq!(461			<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(3))),462			1463		);464		assert_eq!(465			<pallet_refungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))),466			true467		);468		assert_eq!(469			<pallet_refungible::Owned<Test>>::get((collection_id, account(3), TokenId(1))),470			true471		);472473		// Account 2 transfers 200 more pieces of RFT 1 to account 3 with pre-existing balance474		assert_ok!(TemplateModule::transfer(475			origin2,476			account(3),477			CollectionId(1),478			TokenId(1),479			200480		));481		assert_eq!(482			<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(2))),483			323484		);485		assert_eq!(486			<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(3))),487			700488		);489		assert_eq!(490			<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(2))),491			1492		);493		assert_eq!(494			<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(3))),495			1496		);497		assert_eq!(498			<pallet_refungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))),499			true500		);501		assert_eq!(502			<pallet_refungible::Owned<Test>>::get((collection_id, account(3), TokenId(1))),503			true504		);505	});506}507508#[test]509fn transfer_nft_item() {510	new_test_ext().execute_with(|| {511		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));512513		let data = default_nft_data();514		create_test_item(collection_id, &data.into());515		assert_eq!(516			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),517			1518		);519		assert_eq!(520			<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),521			true522		);523524		let origin1 = Origin::signed(1);525		// default scenario526		assert_ok!(TemplateModule::transfer(527			origin1,528			account(2),529			CollectionId(1),530			TokenId(1),531			1532		));533		assert_eq!(534			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),535			0536		);537		assert_eq!(538			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(2))),539			1540		);541		assert_eq!(542			<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),543			false544		);545		assert_eq!(546			<pallet_nonfungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))),547			true548		);549	});550}551552#[test]553fn transfer_nft_item_wrong_value() {554	new_test_ext().execute_with(|| {555		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));556557		let data = default_nft_data();558		create_test_item(collection_id, &data.into());559		assert_eq!(560			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),561			1562		);563		assert_eq!(564			<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),565			true566		);567568		let origin1 = Origin::signed(1);569570		assert_noop!(571			TemplateModule::transfer(origin1, account(2), CollectionId(1), TokenId(1), 2)572				.map_err(|e| e.error),573			<pallet_nonfungible::Error::<Test>>::NonfungibleItemsHaveNoAmount574		);575	});576}577578#[test]579fn transfer_nft_item_zero_value() {580	new_test_ext().execute_with(|| {581		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));582583		let data = default_nft_data();584		create_test_item(collection_id, &data.into());585		assert_eq!(586			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),587			1588		);589		assert_eq!(590			<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),591			true592		);593594		let origin1 = Origin::signed(1);595596		// Transferring 0 amount works on NFT...597		assert_ok!(TemplateModule::transfer(598			origin1,599			account(2),600			CollectionId(1),601			TokenId(1),602			0603		));604		// ... and results in no transfer605		assert_eq!(606			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),607			1608		);609		assert_eq!(610			<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),611			true612		);613	});614}615616#[test]617fn nft_approve_and_transfer_from() {618	new_test_ext().execute_with(|| {619		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));620621		let data = default_nft_data();622		create_test_item(collection_id, &data.into());623624		let origin1 = Origin::signed(1);625		let origin2 = Origin::signed(2);626627		assert_eq!(628			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),629			1630		);631		assert_eq!(632			<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),633			true634		);635636		// neg transfer_from637		assert_noop!(638			TemplateModule::transfer_from(639				origin2.clone(),640				account(1),641				account(2),642				CollectionId(1),643				TokenId(1),644				1645			)646			.map_err(|e| e.error),647			CommonError::<Test>::ApprovedValueTooLow648		);649650		// do approve651		assert_ok!(TemplateModule::approve(652			origin1,653			account(2),654			CollectionId(1),655			TokenId(1),656			1657		));658		assert_eq!(659			<pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),660			account(2)661		);662663		assert_ok!(TemplateModule::transfer_from(664			origin2,665			account(1),666			account(3),667			CollectionId(1),668			TokenId(1),669			1670		));671		assert!(672			<pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).is_none()673		);674	});675}676677#[test]678fn nft_approve_and_transfer_from_allow_list() {679	new_test_ext().execute_with(|| {680		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));681682		let origin1 = Origin::signed(1);683		let origin2 = Origin::signed(2);684685		// Create NFT 1 for account 1686		let data = default_nft_data();687		create_test_item(collection_id, &data.clone().into());688		assert_eq!(689			&<pallet_nonfungible::TokenData<Test>>::get((collection_id, TokenId(1)))690				.unwrap()691				.const_data,692			&data.const_data.into_inner()693		);694		assert_eq!(695			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),696			1697		);698		assert_eq!(699			<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),700			true701		);702703		// Allow allow-list users to mint and add accounts 1, 2, and 3 to allow-list704		assert_ok!(TemplateModule::set_mint_permission(705			origin1.clone(),706			CollectionId(1),707			true708		));709		assert_ok!(TemplateModule::set_public_access_mode(710			origin1.clone(),711			CollectionId(1),712			AccessMode::AllowList713		));714		assert_ok!(TemplateModule::add_to_allow_list(715			origin1.clone(),716			CollectionId(1),717			account(1)718		));719		assert_ok!(TemplateModule::add_to_allow_list(720			origin1.clone(),721			CollectionId(1),722			account(2)723		));724		assert_ok!(TemplateModule::add_to_allow_list(725			origin1.clone(),726			CollectionId(1),727			account(3)728		));729730		// Account 1 approves account 2 for NFT 1731		assert_ok!(TemplateModule::approve(732			origin1.clone(),733			account(2),734			CollectionId(1),735			TokenId(1),736			1737		));738		assert_eq!(739			<pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),740			account(2)741		);742743		// Account 2 transfers NFT 1 from account 1 to account 3744		assert_ok!(TemplateModule::transfer_from(745			origin2,746			account(1),747			account(3),748			CollectionId(1),749			TokenId(1),750			1751		));752		assert!(753			<pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).is_none()754		);755	});756}757758#[test]759fn refungible_approve_and_transfer_from() {760	new_test_ext().execute_with(|| {761		let collection_id = create_test_collection(&CollectionMode::ReFungible, CollectionId(1));762763		let origin1 = Origin::signed(1);764		let origin2 = Origin::signed(2);765766		// Create RFT 1 in 1023 pieces for account 1767		let data = default_re_fungible_data();768		create_test_item(collection_id, &data.into());769770		assert_eq!(771			<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))),772			1773		);774		assert_eq!(775			<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1))),776			1023777		);778		assert_eq!(779			<pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),780			true781		);782783		// Allow public minting, enable allow-list and add accounts 1, 2, 3 to allow-list784		assert_ok!(TemplateModule::set_mint_permission(785			origin1.clone(),786			CollectionId(1),787			true788		));789		assert_ok!(TemplateModule::set_public_access_mode(790			origin1.clone(),791			CollectionId(1),792			AccessMode::AllowList793		));794		assert_ok!(TemplateModule::add_to_allow_list(795			origin1.clone(),796			CollectionId(1),797			account(1)798		));799		assert_ok!(TemplateModule::add_to_allow_list(800			origin1.clone(),801			CollectionId(1),802			account(2)803		));804		assert_ok!(TemplateModule::add_to_allow_list(805			origin1.clone(),806			CollectionId(1),807			account(3)808		));809810		// Account 1 approves account 2 for 1023 pieces of RFT 1811		assert_ok!(TemplateModule::approve(812			origin1,813			account(2),814			CollectionId(1),815			TokenId(1),816			1023817		));818		assert_eq!(819			<pallet_refungible::Allowance<Test>>::get((820				CollectionId(1),821				TokenId(1),822				account(1),823				account(2)824			)),825			1023826		);827828		// Account 2 transfers 100 pieces of RFT 1 from account 1 to account 3829		assert_ok!(TemplateModule::transfer_from(830			origin2,831			account(1),832			account(3),833			CollectionId(1),834			TokenId(1),835			100836		));837		assert_eq!(838			<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))),839			1840		);841		assert_eq!(842			<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(3))),843			1844		);845		assert_eq!(846			<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1))),847			923848		);849		assert_eq!(850			<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(3))),851			100852		);853		assert_eq!(854			<pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),855			true856		);857		assert_eq!(858			<pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),859			true860		);861		assert_eq!(862			<pallet_refungible::Allowance<Test>>::get((863				CollectionId(1),864				TokenId(1),865				account(1),866				account(2)867			)),868			923869		);870	});871}872873#[test]874fn fungible_approve_and_transfer_from() {875	new_test_ext().execute_with(|| {876		let collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));877878		let data = default_fungible_data();879		create_test_item(collection_id, &data.into());880881		let origin1 = Origin::signed(1);882		let origin2 = Origin::signed(2);883884		assert_ok!(TemplateModule::set_mint_permission(885			origin1.clone(),886			CollectionId(1),887			true888		));889		assert_ok!(TemplateModule::set_public_access_mode(890			origin1.clone(),891			CollectionId(1),892			AccessMode::AllowList893		));894		assert_ok!(TemplateModule::add_to_allow_list(895			origin1.clone(),896			CollectionId(1),897			account(1)898		));899		assert_ok!(TemplateModule::add_to_allow_list(900			origin1.clone(),901			CollectionId(1),902			account(2)903		));904		assert_ok!(TemplateModule::add_to_allow_list(905			origin1.clone(),906			CollectionId(1),907			account(3)908		));909910		// do approve911		assert_ok!(TemplateModule::approve(912			origin1.clone(),913			account(2),914			CollectionId(1),915			TokenId(0),916			5917		));918		assert_eq!(919			<pallet_fungible::Allowance<Test>>::get((CollectionId(1), account(1), account(2))),920			5921		);922		assert_ok!(TemplateModule::approve(923			origin1,924			account(3),925			CollectionId(1),926			TokenId(0),927			5928		));929		assert_eq!(930			<pallet_fungible::Allowance<Test>>::get((CollectionId(1), account(1), account(2))),931			5932		);933		assert_eq!(934			<pallet_fungible::Allowance<Test>>::get((CollectionId(1), account(1), account(3))),935			5936		);937938		assert_ok!(TemplateModule::transfer_from(939			origin2.clone(),940			account(1),941			account(3),942			CollectionId(1),943			TokenId(0),944			4945		));946947		assert_eq!(948			<pallet_fungible::Allowance<Test>>::get((CollectionId(1), account(1), account(2))),949			1950		);951952		assert_noop!(953			TemplateModule::transfer_from(954				origin2,955				account(1),956				account(3),957				CollectionId(1),958				TokenId(0),959				4960			)961			.map_err(|e| e.error),962			CommonError::<Test>::ApprovedValueTooLow963		);964	});965}966967#[test]968fn change_collection_owner() {969	new_test_ext().execute_with(|| {970		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));971972		let origin1 = Origin::signed(1);973		assert_ok!(TemplateModule::change_collection_owner(974			origin1,975			collection_id,976			2977		));978		assert_eq!(979			<pallet_common::CollectionById<Test>>::get(collection_id)980				.unwrap()981				.owner,982			2983		);984	});985}986987#[test]988fn destroy_collection() {989	new_test_ext().execute_with(|| {990		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));991992		let origin1 = Origin::signed(1);993		assert_ok!(TemplateModule::destroy_collection(origin1, collection_id));994	});995}996997#[test]998fn burn_nft_item() {999	new_test_ext().execute_with(|| {1000		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));10011002		let origin1 = Origin::signed(1);10031004		let data = default_nft_data();1005		create_test_item(collection_id, &data.into());10061007		// check balance (collection with id = 1, user id = 1)1008		assert_eq!(1009			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),1010			11011		);10121013		// burn item1014		assert_ok!(TemplateModule::burn_item(1015			origin1.clone(),1016			collection_id,1017			TokenId(1),1018			11019		));1020		assert_eq!(1021			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),1022			01023		);1024	});1025}10261027#[test]1028fn burn_same_nft_item_twice() {1029	new_test_ext().execute_with(|| {1030		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));10311032		let origin1 = Origin::signed(1);10331034		let data = default_nft_data();1035		create_test_item(collection_id, &data.into());10361037		// check balance (collection with id = 1, user id = 1)1038		assert_eq!(1039			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),1040			11041		);10421043		// burn item1044		assert_ok!(TemplateModule::burn_item(1045			origin1.clone(),1046			collection_id,1047			TokenId(1),1048			11049		));10501051		// burn item again1052		assert_noop!(1053			TemplateModule::burn_item(origin1, collection_id, TokenId(1), 1).map_err(|e| e.error),1054			CommonError::<Test>::TokenNotFound1055		);10561057		assert_eq!(1058			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),1059			01060		);1061	});1062}10631064#[test]1065fn burn_fungible_item() {1066	new_test_ext().execute_with(|| {1067		let collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));10681069		let origin1 = Origin::signed(1);1070		assert_ok!(TemplateModule::add_collection_admin(1071			origin1.clone(),1072			collection_id,1073			account(2)1074		));10751076		let data = default_fungible_data();1077		create_test_item(collection_id, &data.into());10781079		// check balance (collection with id = 1, user id = 1)1080		assert_eq!(1081			<pallet_fungible::Balance<Test>>::get((collection_id, account(1))),1082			51083		);10841085		// burn item1086		assert_ok!(TemplateModule::burn_item(1087			origin1.clone(),1088			CollectionId(1),1089			TokenId(0),1090			51091		));1092		assert_noop!(1093			TemplateModule::burn_item(origin1, CollectionId(1), TokenId(0), 5).map_err(|e| e.error),1094			CommonError::<Test>::TokenValueTooLow1095		);10961097		assert_eq!(1098			<pallet_fungible::Balance<Test>>::get((collection_id, account(1))),1099			01100		);1101	});1102}11031104#[test]1105fn burn_fungible_item_with_token_id() {1106	new_test_ext().execute_with(|| {1107		let collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));11081109		let origin1 = Origin::signed(1);1110		assert_ok!(TemplateModule::add_collection_admin(1111			origin1.clone(),1112			collection_id,1113			account(2)1114		));11151116		let data = default_fungible_data();1117		create_test_item(collection_id, &data.into());11181119		// check balance (collection with id = 1, user id = 1)1120		assert_eq!(1121			<pallet_fungible::Balance<Test>>::get((collection_id, account(1))),1122			51123		);11241125		// Try to burn item using Token ID1126		assert_noop!(1127			TemplateModule::burn_item(origin1, CollectionId(1), TokenId(1), 5).map_err(|e| e.error),1128			<pallet_fungible::Error::<Test>>::FungibleItemsHaveNoId1129		);1130	});1131}1132#[test]1133fn burn_refungible_item() {1134	new_test_ext().execute_with(|| {1135		let collection_id = create_test_collection(&CollectionMode::ReFungible, CollectionId(1));1136		let origin1 = Origin::signed(1);11371138		assert_ok!(TemplateModule::set_mint_permission(1139			origin1.clone(),1140			collection_id,1141			true1142		));1143		assert_ok!(TemplateModule::set_public_access_mode(1144			origin1.clone(),1145			collection_id,1146			AccessMode::AllowList1147		));1148		assert_ok!(TemplateModule::add_to_allow_list(1149			origin1.clone(),1150			collection_id,1151			account(1)1152		));11531154		assert_ok!(TemplateModule::add_collection_admin(1155			origin1.clone(),1156			collection_id,1157			account(2)1158		));11591160		let data = default_re_fungible_data();1161		create_test_item(collection_id, &data.into());11621163		// check balance (collection with id = 1, user id = 2)1164		assert_eq!(1165			<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))),1166			11167		);1168		assert_eq!(1169			<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1))),1170			10231171		);11721173		// burn item1174		assert_ok!(TemplateModule::burn_item(1175			origin1.clone(),1176			collection_id,1177			TokenId(1),1178			10231179		));1180		assert_noop!(1181			TemplateModule::burn_item(origin1, collection_id, TokenId(1), 1023)1182				.map_err(|e| e.error),1183			CommonError::<Test>::TokenValueTooLow1184		);11851186		assert_eq!(1187			<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1))),1188			01189		);1190	});1191}11921193#[test]1194fn add_collection_admin() {1195	new_test_ext().execute_with(|| {1196		let collection1_id =1197			create_test_collection_for_owner(&CollectionMode::NFT, 1, CollectionId(1));1198		let origin1 = Origin::signed(1);11991200		// Add collection admins1201		assert_ok!(TemplateModule::add_collection_admin(1202			origin1.clone(),1203			collection1_id,1204			account(2)1205		));1206		assert_ok!(TemplateModule::add_collection_admin(1207			origin1,1208			collection1_id,1209			account(3)1210		));12111212		// Owner is not an admin by default1213		assert_eq!(1214			<pallet_common::IsAdmin<Test>>::get((CollectionId(1), account(1))),1215			false1216		);1217		assert!(<pallet_common::IsAdmin<Test>>::get((1218			CollectionId(1),1219			account(2)1220		)));1221		assert!(<pallet_common::IsAdmin<Test>>::get((1222			CollectionId(1),1223			account(3)1224		)));1225	});1226}12271228#[test]1229fn remove_collection_admin() {1230	new_test_ext().execute_with(|| {1231		let collection1_id =1232			create_test_collection_for_owner(&CollectionMode::NFT, 1, CollectionId(1));1233		let origin1 = Origin::signed(1);1234		let origin2 = Origin::signed(2);12351236		// Add collection admins 2 and 31237		assert_ok!(TemplateModule::add_collection_admin(1238			origin1.clone(),1239			collection1_id,1240			account(2)1241		));1242		assert_ok!(TemplateModule::add_collection_admin(1243			origin1,1244			collection1_id,1245			account(3)1246		));12471248		assert!(<pallet_common::IsAdmin<Test>>::get((1249			CollectionId(1),1250			account(2)1251		)));1252		assert!(<pallet_common::IsAdmin<Test>>::get((1253			CollectionId(1),1254			account(3)1255		)));12561257		// remove admin 31258		assert_ok!(TemplateModule::remove_collection_admin(1259			origin2,1260			CollectionId(1),1261			account(3)1262		));12631264		// 2 is still admin, 3 is not an admin anymore1265		assert!(<pallet_common::IsAdmin<Test>>::get((1266			CollectionId(1),1267			account(2)1268		)));1269		assert_eq!(1270			<pallet_common::IsAdmin<Test>>::get((CollectionId(1), account(3))),1271			false1272		);1273	});1274}12751276#[test]1277fn balance_of() {1278	new_test_ext().execute_with(|| {1279		let nft_collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1280		let fungible_collection_id =1281			create_test_collection(&CollectionMode::Fungible(3), CollectionId(2));1282		let re_fungible_collection_id =1283			create_test_collection(&CollectionMode::ReFungible, CollectionId(3));12841285		// check balance before1286		assert_eq!(1287			<pallet_nonfungible::AccountBalance<Test>>::get((nft_collection_id, account(1))),1288			01289		);1290		assert_eq!(1291			<pallet_fungible::Balance<Test>>::get((fungible_collection_id, account(1))),1292			01293		);1294		assert_eq!(1295			<pallet_refungible::AccountBalance<Test>>::get((re_fungible_collection_id, account(1))),1296			01297		);12981299		let nft_data = default_nft_data();1300		create_test_item(nft_collection_id, &nft_data.into());13011302		let fungible_data = default_fungible_data();1303		create_test_item(fungible_collection_id, &fungible_data.into());13041305		let re_fungible_data = default_re_fungible_data();1306		create_test_item(re_fungible_collection_id, &re_fungible_data.into());13071308		// check balance (collection with id = 1, user id = 1)1309		assert_eq!(1310			<pallet_nonfungible::AccountBalance<Test>>::get((nft_collection_id, account(1))),1311			11312		);1313		assert_eq!(1314			<pallet_fungible::Balance<Test>>::get((fungible_collection_id, account(1))),1315			51316		);1317		assert_eq!(1318			<pallet_refungible::AccountBalance<Test>>::get((re_fungible_collection_id, account(1))),1319			11320		);13211322		assert_eq!(1323			<pallet_nonfungible::Owned<Test>>::get((nft_collection_id, account(1), TokenId(1))),1324			true1325		);1326		assert_eq!(1327			<pallet_refungible::Owned<Test>>::get((1328				re_fungible_collection_id,1329				account(1),1330				TokenId(1)1331			)),1332			true1333		);1334	});1335}13361337#[test]1338fn approve() {1339	new_test_ext().execute_with(|| {1340		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));13411342		let data = default_nft_data();1343		create_test_item(collection_id, &data.into());13441345		let origin1 = Origin::signed(1);13461347		// approve1348		assert_ok!(TemplateModule::approve(1349			origin1,1350			account(2),1351			CollectionId(1),1352			TokenId(1),1353			11354		));1355		assert_eq!(1356			<pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),1357			account(2)1358		);1359	});1360}13611362#[test]1363fn transfer_from() {1364	new_test_ext().execute_with(|| {1365		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1366		let origin1 = Origin::signed(1);1367		let origin2 = Origin::signed(2);13681369		let data = default_nft_data();1370		create_test_item(collection_id, &data.into());13711372		// approve1373		assert_ok!(TemplateModule::approve(1374			origin1.clone(),1375			account(2),1376			CollectionId(1),1377			TokenId(1),1378			11379		));1380		assert_eq!(1381			<pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),1382			account(2)1383		);13841385		assert_ok!(TemplateModule::set_mint_permission(1386			origin1.clone(),1387			CollectionId(1),1388			true1389		));1390		assert_ok!(TemplateModule::set_public_access_mode(1391			origin1.clone(),1392			CollectionId(1),1393			AccessMode::AllowList1394		));1395		assert_ok!(TemplateModule::add_to_allow_list(1396			origin1.clone(),1397			CollectionId(1),1398			account(1)1399		));1400		assert_ok!(TemplateModule::add_to_allow_list(1401			origin1.clone(),1402			CollectionId(1),1403			account(2)1404		));1405		assert_ok!(TemplateModule::add_to_allow_list(1406			origin1,1407			CollectionId(1),1408			account(3)1409		));14101411		assert_ok!(TemplateModule::transfer_from(1412			origin2,1413			account(1),1414			account(2),1415			CollectionId(1),1416			TokenId(1),1417			11418		));14191420		// after transfer1421		assert_eq!(1422			<pallet_nonfungible::AccountBalance<Test>>::get((CollectionId(1), account(1))),1423			01424		);1425		assert_eq!(1426			<pallet_nonfungible::AccountBalance<Test>>::get((CollectionId(1), account(2))),1427			11428		);1429	});1430}14311432// #endregion14331434// Coverage tests region1435// #region14361437#[test]1438fn owner_can_add_address_to_allow_list() {1439	new_test_ext().execute_with(|| {1440		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));14411442		let origin1 = Origin::signed(1);1443		assert_ok!(TemplateModule::add_to_allow_list(1444			origin1,1445			collection_id,1446			account(2)1447		));1448		assert!(<pallet_common::Allowlist<Test>>::get((1449			collection_id,1450			account(2)1451		)));1452	});1453}14541455#[test]1456fn admin_can_add_address_to_allow_list() {1457	new_test_ext().execute_with(|| {1458		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1459		let origin1 = Origin::signed(1);1460		let origin2 = Origin::signed(2);14611462		assert_ok!(TemplateModule::add_collection_admin(1463			origin1,1464			collection_id,1465			account(2)1466		));1467		assert_ok!(TemplateModule::add_to_allow_list(1468			origin2,1469			collection_id,1470			account(3)1471		));1472		assert!(<pallet_common::Allowlist<Test>>::get((1473			collection_id,1474			account(3)1475		)));1476	});1477}14781479#[test]1480fn nonprivileged_user_cannot_add_address_to_allow_list() {1481	new_test_ext().execute_with(|| {1482		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));14831484		let origin2 = Origin::signed(2);1485		assert_noop!(1486			TemplateModule::add_to_allow_list(origin2, collection_id, account(3)),1487			CommonError::<Test>::NoPermission1488		);1489	});1490}14911492#[test]1493fn nobody_can_add_address_to_allow_list_of_nonexisting_collection() {1494	new_test_ext().execute_with(|| {1495		let origin1 = Origin::signed(1);14961497		assert_noop!(1498			TemplateModule::add_to_allow_list(origin1, CollectionId(1), account(2)),1499			CommonError::<Test>::CollectionNotFound1500		);1501	});1502}15031504#[test]1505fn nobody_can_add_address_to_allow_list_of_deleted_collection() {1506	new_test_ext().execute_with(|| {1507		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));15081509		let origin1 = Origin::signed(1);1510		assert_ok!(TemplateModule::destroy_collection(1511			origin1.clone(),1512			collection_id1513		));1514		assert_noop!(1515			TemplateModule::add_to_allow_list(origin1, collection_id, account(2)),1516			CommonError::<Test>::CollectionNotFound1517		);1518	});1519}15201521// If address is already added to allow list, nothing happens1522#[test]1523fn address_is_already_added_to_allow_list() {1524	new_test_ext().execute_with(|| {1525		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1526		let origin1 = Origin::signed(1);15271528		assert_ok!(TemplateModule::add_to_allow_list(1529			origin1.clone(),1530			collection_id,1531			account(2)1532		));1533		assert_ok!(TemplateModule::add_to_allow_list(1534			origin1,1535			collection_id,1536			account(2)1537		));1538		assert!(<pallet_common::Allowlist<Test>>::get((1539			collection_id,1540			account(2)1541		)));1542	});1543}15441545#[test]1546fn owner_can_remove_address_from_allow_list() {1547	new_test_ext().execute_with(|| {1548		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));15491550		let origin1 = Origin::signed(1);1551		assert_ok!(TemplateModule::add_to_allow_list(1552			origin1.clone(),1553			collection_id,1554			account(2)1555		));1556		assert_ok!(TemplateModule::remove_from_allow_list(1557			origin1,1558			collection_id,1559			account(2)1560		));1561		assert_eq!(1562			<pallet_common::Allowlist<Test>>::get((collection_id, account(2))),1563			false1564		);1565	});1566}15671568#[test]1569fn admin_can_remove_address_from_allow_list() {1570	new_test_ext().execute_with(|| {1571		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1572		let origin1 = Origin::signed(1);1573		let origin2 = Origin::signed(2);15741575		// Owner adds admin1576		assert_ok!(TemplateModule::add_collection_admin(1577			origin1.clone(),1578			collection_id,1579			account(2)1580		));15811582		// Owner adds address 3 to allow list1583		assert_ok!(TemplateModule::add_to_allow_list(1584			origin1,1585			collection_id,1586			account(3)1587		));15881589		// Admin removes address 3 from allow list1590		assert_ok!(TemplateModule::remove_from_allow_list(1591			origin2,1592			collection_id,1593			account(3)1594		));1595		assert_eq!(1596			<pallet_common::Allowlist<Test>>::get((collection_id, account(3))),1597			false1598		);1599	});1600}16011602#[test]1603fn nonprivileged_user_cannot_remove_address_from_allow_list() {1604	new_test_ext().execute_with(|| {1605		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1606		let origin1 = Origin::signed(1);1607		let origin2 = Origin::signed(2);16081609		assert_ok!(TemplateModule::add_to_allow_list(1610			origin1,1611			collection_id,1612			account(2)1613		));1614		assert_noop!(1615			TemplateModule::remove_from_allow_list(origin2, collection_id, account(2)),1616			CommonError::<Test>::NoPermission1617		);1618		assert!(<pallet_common::Allowlist<Test>>::get((1619			collection_id,1620			account(2)1621		)));1622	});1623}16241625#[test]1626fn nobody_can_remove_address_from_allow_list_of_nonexisting_collection() {1627	new_test_ext().execute_with(|| {1628		let origin1 = Origin::signed(1);16291630		assert_noop!(1631			TemplateModule::remove_from_allow_list(origin1, CollectionId(1), account(2)),1632			CommonError::<Test>::CollectionNotFound1633		);1634	});1635}16361637#[test]1638fn nobody_can_remove_address_from_allow_list_of_deleted_collection() {1639	new_test_ext().execute_with(|| {1640		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1641		let origin1 = Origin::signed(1);1642		let origin2 = Origin::signed(2);16431644		// Add account 2 to allow list1645		assert_ok!(TemplateModule::add_to_allow_list(1646			origin1.clone(),1647			collection_id,1648			account(2)1649		));16501651		// Account 2 is in collection allow-list1652		assert!(<pallet_common::Allowlist<Test>>::get((1653			collection_id,1654			account(2)1655		)));16561657		// Destroy collection1658		assert_ok!(TemplateModule::destroy_collection(origin1, collection_id));16591660		// Attempt to remove account 2 from collection allow-list => error1661		assert_noop!(1662			TemplateModule::remove_from_allow_list(origin2, collection_id, account(2)),1663			CommonError::<Test>::CollectionNotFound1664		);16651666		// Account 2 is not found in collection allow-list anyway1667		assert_eq!(1668			<pallet_common::Allowlist<Test>>::get((collection_id, account(2))),1669			false1670		);1671	});1672}16731674// If address is already removed from allow list, nothing happens1675#[test]1676fn address_is_already_removed_from_allow_list() {1677	new_test_ext().execute_with(|| {1678		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1679		let origin1 = Origin::signed(1);16801681		assert_ok!(TemplateModule::add_to_allow_list(1682			origin1.clone(),1683			collection_id,1684			account(2)1685		));1686		assert_ok!(TemplateModule::remove_from_allow_list(1687			origin1.clone(),1688			collection_id,1689			account(2)1690		));1691		assert_eq!(1692			<pallet_common::Allowlist<Test>>::get((collection_id, account(2))),1693			false1694		);1695		assert_ok!(TemplateModule::remove_from_allow_list(1696			origin1,1697			collection_id,1698			account(2)1699		));1700		assert_eq!(1701			<pallet_common::Allowlist<Test>>::get((collection_id, account(2))),1702			false1703		);1704	});1705}17061707// If Public Access mode is set to AllowList, tokens can’t be transferred from a non-allowlisted address with transfer or transferFrom (2 tests)1708#[test]1709fn allow_list_test_1() {1710	new_test_ext().execute_with(|| {1711		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));17121713		let origin1 = Origin::signed(1);17141715		let data = default_nft_data();1716		create_test_item(collection_id, &data.into());17171718		assert_ok!(TemplateModule::set_public_access_mode(1719			origin1.clone(),1720			collection_id,1721			AccessMode::AllowList1722		));1723		assert_ok!(TemplateModule::add_to_allow_list(1724			origin1.clone(),1725			collection_id,1726			account(2)1727		));17281729		assert_noop!(1730			TemplateModule::transfer(origin1, account(3), CollectionId(1), TokenId(1), 1)1731				.map_err(|e| e.error),1732			CommonError::<Test>::AddressNotInAllowlist1733		);1734	});1735}17361737#[test]1738fn allow_list_test_2() {1739	new_test_ext().execute_with(|| {1740		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1741		let origin1 = Origin::signed(1);17421743		let data = default_nft_data();1744		create_test_item(collection_id, &data.into());17451746		assert_ok!(TemplateModule::set_public_access_mode(1747			origin1.clone(),1748			collection_id,1749			AccessMode::AllowList1750		));1751		assert_ok!(TemplateModule::add_to_allow_list(1752			origin1.clone(),1753			collection_id,1754			account(1)1755		));1756		assert_ok!(TemplateModule::add_to_allow_list(1757			origin1.clone(),1758			collection_id,1759			account(2)1760		));17611762		// do approve1763		assert_ok!(TemplateModule::approve(1764			origin1.clone(),1765			account(1),1766			collection_id,1767			TokenId(1),1768			11769		));1770		assert_eq!(1771			<pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),1772			account(1)1773		);17741775		assert_ok!(TemplateModule::remove_from_allow_list(1776			origin1.clone(),1777			collection_id,1778			account(1)1779		));17801781		assert_noop!(1782			TemplateModule::transfer_from(1783				origin1,1784				account(1),1785				account(3),1786				CollectionId(1),1787				TokenId(1),1788				11789			)1790			.map_err(|e| e.error),1791			CommonError::<Test>::AddressNotInAllowlist1792		);1793	});1794}17951796// If Public Access mode is set to AllowList, tokens can’t be transferred to a non-allowlisted address with transfer or transferFrom (2 tests)1797#[test]1798fn allow_list_test_3() {1799	new_test_ext().execute_with(|| {1800		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));18011802		let origin1 = Origin::signed(1);18031804		let data = default_nft_data();1805		create_test_item(collection_id, &data.into());18061807		assert_ok!(TemplateModule::set_public_access_mode(1808			origin1.clone(),1809			collection_id,1810			AccessMode::AllowList1811		));1812		assert_ok!(TemplateModule::add_to_allow_list(1813			origin1.clone(),1814			collection_id,1815			account(1)1816		));18171818		assert_noop!(1819			TemplateModule::transfer(origin1, account(3), collection_id, TokenId(1), 1)1820				.map_err(|e| e.error),1821			CommonError::<Test>::AddressNotInAllowlist1822		);1823	});1824}18251826#[test]1827fn allow_list_test_4() {1828	new_test_ext().execute_with(|| {1829		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));18301831		let origin1 = Origin::signed(1);18321833		let data = default_nft_data();1834		create_test_item(collection_id, &data.into());18351836		assert_ok!(TemplateModule::set_public_access_mode(1837			origin1.clone(),1838			collection_id,1839			AccessMode::AllowList1840		));1841		assert_ok!(TemplateModule::add_to_allow_list(1842			origin1.clone(),1843			collection_id,1844			account(1)1845		));1846		assert_ok!(TemplateModule::add_to_allow_list(1847			origin1.clone(),1848			collection_id,1849			account(2)1850		));18511852		// do approve1853		assert_ok!(TemplateModule::approve(1854			origin1.clone(),1855			account(1),1856			collection_id,1857			TokenId(1),1858			11859		));1860		assert_eq!(1861			<pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),1862			account(1)1863		);18641865		assert_ok!(TemplateModule::remove_from_allow_list(1866			origin1.clone(),1867			collection_id,1868			account(2)1869		));18701871		assert_noop!(1872			TemplateModule::transfer_from(1873				origin1,1874				account(1),1875				account(3),1876				collection_id,1877				TokenId(1),1878				11879			)1880			.map_err(|e| e.error),1881			CommonError::<Test>::AddressNotInAllowlist1882		);1883	});1884}18851886// If Public Access mode is set to AllowList, tokens can’t be destroyed by a non-allowlisted address (even if it owned them before enabling AllowList mode)1887#[test]1888fn allow_list_test_5() {1889	new_test_ext().execute_with(|| {1890		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));18911892		let origin1 = Origin::signed(1);18931894		let data = default_nft_data();1895		create_test_item(collection_id, &data.into());18961897		assert_ok!(TemplateModule::set_public_access_mode(1898			origin1.clone(),1899			collection_id,1900			AccessMode::AllowList1901		));1902		assert_noop!(1903			TemplateModule::burn_item(origin1.clone(), CollectionId(1), TokenId(1), 1)1904				.map_err(|e| e.error),1905			CommonError::<Test>::AddressNotInAllowlist1906		);1907	});1908}19091910// If Public Access mode is set to AllowList, token transfers can’t be Approved by a non-allowlisted address (see Approve method).1911#[test]1912fn allow_list_test_6() {1913	new_test_ext().execute_with(|| {1914		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));19151916		let origin1 = Origin::signed(1);19171918		let data = default_nft_data();1919		create_test_item(collection_id, &data.into());19201921		assert_ok!(TemplateModule::set_public_access_mode(1922			origin1.clone(),1923			collection_id,1924			AccessMode::AllowList1925		));19261927		// do approve1928		assert_noop!(1929			TemplateModule::approve(origin1, account(1), CollectionId(1), TokenId(1), 1)1930				.map_err(|e| e.error),1931			CommonError::<Test>::AddressNotInAllowlist1932		);1933	});1934}19351936// If Public Access mode is set to AllowList, tokens can be transferred from a allowlisted address with transfer or transferFrom (2 tests) and1937//          tokens can be transferred from a allowlisted address with transfer or transferFrom (2 tests)1938#[test]1939fn allow_list_test_7() {1940	new_test_ext().execute_with(|| {1941		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));19421943		let data = default_nft_data();1944		create_test_item(collection_id, &data.into());19451946		let origin1 = Origin::signed(1);19471948		assert_ok!(TemplateModule::set_public_access_mode(1949			origin1.clone(),1950			collection_id,1951			AccessMode::AllowList1952		));1953		assert_ok!(TemplateModule::add_to_allow_list(1954			origin1.clone(),1955			collection_id,1956			account(1)1957		));1958		assert_ok!(TemplateModule::add_to_allow_list(1959			origin1.clone(),1960			collection_id,1961			account(2)1962		));19631964		assert_ok!(TemplateModule::transfer(1965			origin1,1966			account(2),1967			CollectionId(1),1968			TokenId(1),1969			11970		));1971	});1972}19731974#[test]1975fn allow_list_test_8() {1976	new_test_ext().execute_with(|| {1977		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));19781979		// Create NFT for account 11980		let data = default_nft_data();1981		create_test_item(collection_id, &data.into());19821983		let origin1 = Origin::signed(1);19841985		// Toggle Allow List mode and add accounts 1 and 21986		assert_ok!(TemplateModule::set_public_access_mode(1987			origin1.clone(),1988			collection_id,1989			AccessMode::AllowList1990		));1991		assert_ok!(TemplateModule::add_to_allow_list(1992			origin1.clone(),1993			collection_id,1994			account(1)1995		));1996		assert_ok!(TemplateModule::add_to_allow_list(1997			origin1.clone(),1998			collection_id,1999			account(2)2000		));20012002		// Sself-approve account 1 for NFT 12003		assert_ok!(TemplateModule::approve(2004			origin1.clone(),2005			account(1),2006			CollectionId(1),2007			TokenId(1),2008			12009		));2010		assert_eq!(2011			<pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),2012			account(1)2013		);20142015		// Transfer from 1 to 22016		assert_ok!(TemplateModule::transfer_from(2017			origin1,2018			account(1),2019			account(2),2020			CollectionId(1),2021			TokenId(1),2022			12023		));2024	});2025}20262027// If Public Access mode is set to AllowList, and Mint Permission is set to false, tokens can be created by owner.2028#[test]2029fn allow_list_test_9() {2030	new_test_ext().execute_with(|| {2031		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));2032		let origin1 = Origin::signed(1);20332034		assert_ok!(TemplateModule::set_public_access_mode(2035			origin1.clone(),2036			collection_id,2037			AccessMode::AllowList2038		));2039		assert_ok!(TemplateModule::set_mint_permission(2040			origin1,2041			collection_id,2042			false2043		));20442045		let data = default_nft_data();2046		create_test_item(collection_id, &data.into());2047	});2048}20492050// If Public Access mode is set to AllowList, and Mint Permission is set to false, tokens can be created by admin.2051#[test]2052fn allow_list_test_10() {2053	new_test_ext().execute_with(|| {2054		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));20552056		let origin1 = Origin::signed(1);2057		let origin2 = Origin::signed(2);20582059		assert_ok!(TemplateModule::set_public_access_mode(2060			origin1.clone(),2061			collection_id,2062			AccessMode::AllowList2063		));2064		assert_ok!(TemplateModule::set_mint_permission(2065			origin1.clone(),2066			collection_id,2067			false2068		));20692070		assert_ok!(TemplateModule::add_collection_admin(2071			origin1,2072			collection_id,2073			account(2)2074		));20752076		assert_ok!(TemplateModule::create_item(2077			origin2,2078			collection_id,2079			account(2),2080			default_nft_data().into()2081		));2082	});2083}20842085// If Public Access mode is set to AllowList, and Mint Permission is set to false, tokens cannot be created by non-privileged and allow listed address.2086#[test]2087fn allow_list_test_11() {2088	new_test_ext().execute_with(|| {2089		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));20902091		let origin1 = Origin::signed(1);2092		let origin2 = Origin::signed(2);20932094		assert_ok!(TemplateModule::set_public_access_mode(2095			origin1.clone(),2096			collection_id,2097			AccessMode::AllowList2098		));2099		assert_ok!(TemplateModule::set_mint_permission(2100			origin1.clone(),2101			collection_id,2102			false2103		));2104		assert_ok!(TemplateModule::add_to_allow_list(2105			origin1,2106			collection_id,2107			account(2)2108		));21092110		assert_noop!(2111			TemplateModule::create_item(2112				origin2,2113				CollectionId(1),2114				account(2),2115				default_nft_data().into()2116			)2117			.map_err(|e| e.error),2118			CommonError::<Test>::PublicMintingNotAllowed2119		);2120	});2121}21222123// If Public Access mode is set to AllowList, and Mint Permission is set to false, tokens cannot be created by non-privileged and non-allow listed address.2124#[test]2125fn allow_list_test_12() {2126	new_test_ext().execute_with(|| {2127		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));21282129		let origin1 = Origin::signed(1);2130		let origin2 = Origin::signed(2);21312132		assert_ok!(TemplateModule::set_public_access_mode(2133			origin1.clone(),2134			collection_id,2135			AccessMode::AllowList2136		));2137		assert_ok!(TemplateModule::set_mint_permission(2138			origin1,2139			collection_id,2140			false2141		));21422143		assert_noop!(2144			TemplateModule::create_item(2145				origin2,2146				CollectionId(1),2147				account(2),2148				default_nft_data().into()2149			)2150			.map_err(|e| e.error),2151			CommonError::<Test>::PublicMintingNotAllowed2152		);2153	});2154}21552156// If Public Access mode is set to AllowList, and Mint Permission is set to true, tokens can be created by owner.2157#[test]2158fn allow_list_test_13() {2159	new_test_ext().execute_with(|| {2160		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));21612162		let origin1 = Origin::signed(1);21632164		assert_ok!(TemplateModule::set_public_access_mode(2165			origin1.clone(),2166			collection_id,2167			AccessMode::AllowList2168		));2169		assert_ok!(TemplateModule::set_mint_permission(2170			origin1,2171			collection_id,2172			true2173		));21742175		let data = default_nft_data();2176		create_test_item(collection_id, &data.into());2177	});2178}21792180// If Public Access mode is set to AllowList, and Mint Permission is set to true, tokens can be created by admin.2181#[test]2182fn allow_list_test_14() {2183	new_test_ext().execute_with(|| {2184		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));21852186		let origin1 = Origin::signed(1);2187		let origin2 = Origin::signed(2);21882189		assert_ok!(TemplateModule::set_public_access_mode(2190			origin1.clone(),2191			collection_id,2192			AccessMode::AllowList2193		));2194		assert_ok!(TemplateModule::set_mint_permission(2195			origin1.clone(),2196			collection_id,2197			true2198		));21992200		assert_ok!(TemplateModule::add_collection_admin(2201			origin1,2202			collection_id,2203			account(2)2204		));22052206		assert_ok!(TemplateModule::create_item(2207			origin2,2208			collection_id,2209			account(2),2210			default_nft_data().into()2211		));2212	});2213}22142215// If Public Access mode is set to AllowList, and Mint Permission is set to true, tokens cannot be created by non-privileged and non-allow listed address.2216#[test]2217fn allow_list_test_15() {2218	new_test_ext().execute_with(|| {2219		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));22202221		let origin1 = Origin::signed(1);2222		let origin2 = Origin::signed(2);22232224		assert_ok!(TemplateModule::set_public_access_mode(2225			origin1.clone(),2226			collection_id,2227			AccessMode::AllowList2228		));2229		assert_ok!(TemplateModule::set_mint_permission(2230			origin1,2231			collection_id,2232			true2233		));22342235		assert_noop!(2236			TemplateModule::create_item(2237				origin2,2238				collection_id,2239				account(2),2240				default_nft_data().into()2241			)2242			.map_err(|e| e.error),2243			CommonError::<Test>::AddressNotInAllowlist2244		);2245	});2246}22472248// If Public Access mode is set to AllowList, and Mint Permission is set to true, tokens can be created by non-privileged and allow listed address.2249#[test]2250fn allow_list_test_16() {2251	new_test_ext().execute_with(|| {2252		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));22532254		let origin1 = Origin::signed(1);2255		let origin2 = Origin::signed(2);22562257		assert_ok!(TemplateModule::set_public_access_mode(2258			origin1.clone(),2259			collection_id,2260			AccessMode::AllowList2261		));2262		assert_ok!(TemplateModule::set_mint_permission(2263			origin1.clone(),2264			collection_id,2265			true2266		));2267		assert_ok!(TemplateModule::add_to_allow_list(2268			origin1,2269			collection_id,2270			account(2)2271		));22722273		assert_ok!(TemplateModule::create_item(2274			origin2,2275			collection_id,2276			account(2),2277			default_nft_data().into()2278		));2279	});2280}22812282// Total number of collections. Positive test2283#[test]2284fn total_number_collections_bound() {2285	new_test_ext().execute_with(|| {2286		create_test_collection(&CollectionMode::NFT, CollectionId(1));2287	});2288}22892290#[test]2291fn create_max_collections() {2292	new_test_ext().execute_with(|| {2293		for i in 1..COLLECTION_NUMBER_LIMIT {2294			create_test_collection(&CollectionMode::NFT, CollectionId(i));2295		}2296	});2297}22982299// Total number of collections. Negative test2300#[test]2301fn total_number_collections_bound_neg() {2302	new_test_ext().execute_with(|| {2303		let origin1 = Origin::signed(1);23042305		for i in 1..=COLLECTION_NUMBER_LIMIT {2306			create_test_collection(&CollectionMode::NFT, CollectionId(i));2307		}23082309		let col_name1: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();2310		let col_desc1: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();2311		let token_prefix1: Vec<u8> = b"token_prefix1\0".to_vec();23122313		// 11-th collection in chain. Expects error2314		assert_noop!(2315			TemplateModule::create_collection(2316				origin1,2317				col_name1.try_into().unwrap(),2318				col_desc1.try_into().unwrap(),2319				token_prefix1.try_into().unwrap(),2320				CollectionMode::NFT2321			),2322			CommonError::<Test>::TotalCollectionsLimitExceeded2323		);2324	});2325}23262327// Owned tokens by a single address. Positive test2328#[test]2329fn owned_tokens_bound() {2330	new_test_ext().execute_with(|| {2331		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));23322333		let data = default_nft_data();2334		create_test_item(collection_id, &data.clone().into());2335		create_test_item(collection_id, &data.into());2336	});2337}23382339// Owned tokens by a single address. Negotive test2340#[test]2341fn owned_tokens_bound_neg() {2342	new_test_ext().execute_with(|| {2343		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));23442345		let origin1 = Origin::signed(1);23462347		for _ in 1..=MAX_TOKEN_OWNERSHIP {2348			let data = default_nft_data();2349			create_test_item(collection_id, &data.clone().into());2350		}23512352		let data = default_nft_data();2353		assert_noop!(2354			TemplateModule::create_item(origin1, CollectionId(1), account(1), data.into())2355				.map_err(|e| e.error),2356			CommonError::<Test>::AccountTokenLimitExceeded2357		);2358	});2359}23602361// Number of collection admins. Positive test2362#[test]2363fn collection_admins_bound() {2364	new_test_ext().execute_with(|| {2365		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));23662367		let origin1 = Origin::signed(1);23682369		assert_ok!(TemplateModule::add_collection_admin(2370			origin1.clone(),2371			collection_id,2372			account(2)2373		));2374		assert_ok!(TemplateModule::add_collection_admin(2375			origin1,2376			collection_id,2377			account(3)2378		));2379	});2380}23812382// Number of collection admins. Negotive test2383#[test]2384fn collection_admins_bound_neg() {2385	new_test_ext().execute_with(|| {2386		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));23872388		let origin1 = Origin::signed(1);23892390		for i in 0..COLLECTION_ADMINS_LIMIT {2391			assert_ok!(TemplateModule::add_collection_admin(2392				origin1.clone(),2393				collection_id,2394				account((2 + i).into())2395			));2396		}2397		assert_noop!(2398			TemplateModule::add_collection_admin(2399				origin1,2400				collection_id,2401				account((3 + COLLECTION_ADMINS_LIMIT).into())2402			),2403			CommonError::<Test>::CollectionAdminCountExceeded2404		);2405	});2406}2407// #endregion24082409#[test]2410fn set_const_on_chain_schema() {2411	new_test_ext().execute_with(|| {2412		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));24132414		let origin1 = Origin::signed(1);2415		assert_ok!(TemplateModule::set_const_on_chain_schema(2416			origin1,2417			collection_id,2418			b"test const on chain schema".to_vec().try_into().unwrap()2419		));24202421		assert_eq!(2422			<pallet_common::CollectionById<Test>>::get(collection_id)2423				.unwrap()2424				.const_on_chain_schema,2425			b"test const on chain schema".to_vec()2426		);2427		assert_eq!(2428			<pallet_common::CollectionById<Test>>::get(collection_id)2429				.unwrap()2430				.variable_on_chain_schema,2431			b"".to_vec()2432		);2433	});2434}24352436#[test]2437fn set_variable_on_chain_schema() {2438	new_test_ext().execute_with(|| {2439		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));24402441		let origin1 = Origin::signed(1);2442		assert_ok!(TemplateModule::set_variable_on_chain_schema(2443			origin1,2444			collection_id,2445			b"test variable on chain schema"2446				.to_vec()2447				.try_into()2448				.unwrap()2449		));24502451		assert_eq!(2452			<pallet_common::CollectionById<Test>>::get(collection_id)2453				.unwrap()2454				.const_on_chain_schema,2455			b"".to_vec()2456		);2457		assert_eq!(2458			<pallet_common::CollectionById<Test>>::get(collection_id)2459				.unwrap()2460				.variable_on_chain_schema,2461			b"test variable on chain schema".to_vec()2462		);2463	});2464}24652466#[test]2467fn set_variable_meta_data_on_nft_token_stores_variable_meta_data() {2468	new_test_ext().execute_with(|| {2469		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));24702471		let origin1 = Origin::signed(1);24722473		let data = default_nft_data();2474		create_test_item(CollectionId(1), &data.into());24752476		let variable_data = b"test data".to_vec();2477		assert_ok!(TemplateModule::set_variable_meta_data(2478			origin1,2479			collection_id,2480			TokenId(1),2481			variable_data.clone().try_into().unwrap()2482		));24832484		assert_eq!(2485			<pallet_nonfungible::TokenData<Test>>::get((collection_id, 1))2486				.unwrap()2487				.variable_data,2488			variable_data2489		);2490	});2491}24922493#[test]2494fn set_variable_meta_data_on_re_fungible_token_stores_variable_meta_data() {2495	new_test_ext().execute_with(|| {2496		let collection_id = create_test_collection(&CollectionMode::ReFungible, CollectionId(1));24972498		let origin1 = Origin::signed(1);24992500		let data = default_re_fungible_data();2501		create_test_item(collection_id, &data.into());25022503		let variable_data = b"test data".to_vec();2504		assert_ok!(TemplateModule::set_variable_meta_data(2505			origin1,2506			collection_id,2507			TokenId(1),2508			variable_data.clone().try_into().unwrap()2509		));25102511		assert_eq!(2512			<pallet_refungible::TokenData<Test>>::get((collection_id, TokenId(1))).variable_data,2513			variable_data2514		);2515	});2516}25172518#[test]2519fn set_variable_meta_data_on_fungible_token_fails() {2520	new_test_ext().execute_with(|| {2521		let collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));25222523		let origin1 = Origin::signed(1);25242525		let data = default_fungible_data();2526		create_test_item(collection_id, &data.into());25272528		let variable_data = b"test data".to_vec();2529		assert_noop!(2530			TemplateModule::set_variable_meta_data(2531				origin1,2532				collection_id,2533				TokenId(0),2534				variable_data.try_into().unwrap()2535			)2536			.map_err(|e| e.error),2537			<pallet_fungible::Error<Test>>::FungibleItemsDontHaveData2538		);2539	});2540}25412542#[test]2543fn set_variable_meta_data_on_nft_with_item_owner_permission_flag() {2544	new_test_ext().execute_with(|| {2545		//default_limits();25462547		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));25482549		let origin1 = Origin::signed(1);25502551		let data = default_nft_data();2552		create_test_item(collection_id, &data.into());25532554		assert_ok!(TemplateModule::set_meta_update_permission_flag(2555			origin1.clone(),2556			collection_id,2557			MetaUpdatePermission::ItemOwner,2558		));25592560		let variable_data = b"ten chars.".to_vec();2561		assert_ok!(TemplateModule::set_variable_meta_data(2562			origin1,2563			collection_id,2564			TokenId(1),2565			variable_data.clone().try_into().unwrap()2566		));25672568		assert_eq!(2569			<pallet_nonfungible::TokenData<Test>>::get((collection_id, TokenId(1)))2570				.unwrap()2571				.variable_data,2572			variable_data2573		);2574	});2575}25762577#[test]2578fn collection_transfer_flag_works() {2579	new_test_ext().execute_with(|| {2580		let origin1 = Origin::signed(1);25812582		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));2583		assert_ok!(TemplateModule::set_transfers_enabled_flag(2584			origin1,2585			collection_id,2586			true2587		));25882589		let data = default_nft_data();2590		create_test_item(collection_id, &data.into());2591		assert_eq!(2592			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),2593			12594		);2595		assert_eq!(2596			<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),2597			true2598		);25992600		let origin1 = Origin::signed(1);26012602		// default scenario2603		assert_ok!(TemplateModule::transfer(2604			origin1,2605			account(2),2606			collection_id,2607			TokenId(1),2608			12609		));2610		assert_eq!(2611			<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),2612			false2613		);2614		assert_eq!(2615			<pallet_nonfungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))),2616			true2617		);2618		assert_eq!(2619			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),2620			02621		);2622		assert_eq!(2623			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(2))),2624			12625		);2626	});2627}26282629#[test]2630fn set_variable_meta_data_on_nft_with_admin_flag() {2631	new_test_ext().execute_with(|| {2632		// default_limits();26332634		let collection_id =2635			create_test_collection_for_owner(&CollectionMode::NFT, 2, CollectionId(1));26362637		let origin1 = Origin::signed(1);2638		let origin2 = Origin::signed(2);26392640		assert_ok!(TemplateModule::set_mint_permission(2641			origin2.clone(),2642			collection_id,2643			true2644		));2645		assert_ok!(TemplateModule::add_to_allow_list(2646			origin2.clone(),2647			collection_id,2648			account(1)2649		));26502651		assert_ok!(TemplateModule::add_collection_admin(2652			origin2.clone(),2653			collection_id,2654			account(1)2655		));26562657		let data = default_nft_data();2658		create_test_item(collection_id, &data.into());26592660		assert_ok!(TemplateModule::set_meta_update_permission_flag(2661			origin2.clone(),2662			collection_id,2663			MetaUpdatePermission::Admin,2664		));26652666		let variable_data = b"test.".to_vec();2667		assert_ok!(TemplateModule::set_variable_meta_data(2668			origin1,2669			collection_id,2670			TokenId(1),2671			variable_data.clone().try_into().unwrap()2672		));26732674		assert_eq!(2675			<pallet_nonfungible::TokenData<Test>>::get((collection_id, 1))2676				.unwrap()2677				.variable_data,2678			variable_data2679		);2680	});2681}26822683#[test]2684fn set_variable_meta_data_on_nft_with_admin_flag_neg() {2685	new_test_ext().execute_with(|| {2686		// default_limits();26872688		let collection_id =2689			create_test_collection_for_owner(&CollectionMode::NFT, 2, CollectionId(1));26902691		let origin1 = Origin::signed(1);2692		let origin2 = Origin::signed(2);26932694		assert_ok!(TemplateModule::set_mint_permission(2695			origin2.clone(),2696			collection_id,2697			true2698		));2699		assert_ok!(TemplateModule::add_to_allow_list(2700			origin2.clone(),2701			collection_id,2702			account(1)2703		));27042705		let data = default_nft_data();2706		create_test_item(collection_id, &data.into());27072708		assert_ok!(TemplateModule::set_meta_update_permission_flag(2709			origin2.clone(),2710			collection_id,2711			MetaUpdatePermission::Admin,2712		));27132714		let variable_data = b"test.".to_vec();2715		assert_noop!(2716			TemplateModule::set_variable_meta_data(2717				origin1,2718				collection_id,2719				TokenId(1),2720				variable_data.try_into().unwrap()2721			)2722			.map_err(|e| e.error),2723			CommonError::<Test>::NoPermission2724		);2725	});2726}27272728#[test]2729fn set_variable_meta_flag_after_freeze() {2730	new_test_ext().execute_with(|| {2731		// default_limits();27322733		let collection_id =2734			create_test_collection_for_owner(&CollectionMode::NFT, 2, CollectionId(1));27352736		let origin2 = Origin::signed(2);27372738		assert_ok!(TemplateModule::set_meta_update_permission_flag(2739			origin2.clone(),2740			collection_id,2741			MetaUpdatePermission::None,2742		));2743		assert_noop!(2744			TemplateModule::set_meta_update_permission_flag(2745				origin2.clone(),2746				collection_id,2747				MetaUpdatePermission::Admin2748			),2749			CommonError::<Test>::MetadataFlagFrozen2750		);2751	});2752}27532754#[test]2755fn set_variable_meta_data_on_nft_with_none_flag_neg() {2756	new_test_ext().execute_with(|| {2757		// default_limits();27582759		let collection_id =2760			create_test_collection_for_owner(&CollectionMode::NFT, 1, CollectionId(1));2761		let origin1 = Origin::signed(1);27622763		let data = default_nft_data();2764		create_test_item(collection_id, &data.into());27652766		assert_ok!(TemplateModule::set_meta_update_permission_flag(2767			origin1.clone(),2768			collection_id,2769			MetaUpdatePermission::None,2770		));27712772		let variable_data = b"test.".to_vec();2773		assert_noop!(2774			TemplateModule::set_variable_meta_data(2775				origin1.clone(),2776				collection_id,2777				TokenId(1),2778				variable_data.try_into().unwrap()2779			)2780			.map_err(|e| e.error),2781			CommonError::<Test>::NoPermission2782		);2783	});2784}27852786#[test]2787fn collection_transfer_flag_works_neg() {2788	new_test_ext().execute_with(|| {2789		let origin1 = Origin::signed(1);27902791		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));2792		assert_ok!(TemplateModule::set_transfers_enabled_flag(2793			origin1,2794			collection_id,2795			false2796		));27972798		let data = default_nft_data();2799		create_test_item(collection_id, &data.into());2800		assert_eq!(2801			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),2802			12803		);2804		assert_eq!(2805			<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),2806			true2807		);28082809		let origin1 = Origin::signed(1);28102811		// default scenario2812		assert_noop!(2813			TemplateModule::transfer(origin1, account(2), CollectionId(1), TokenId(1), 1)2814				.map_err(|e| e.error),2815			CommonError::<Test>::TransferNotAllowed2816		);2817		assert_eq!(2818			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),2819			12820		);2821		assert_eq!(2822			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(2))),2823			02824		);2825		assert_eq!(2826			<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),2827			true2828		);2829		assert_eq!(2830			<pallet_nonfungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))),2831			false2832		);2833	});2834}