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

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 RICH_USER: u64 = 999;16	assert_ok!(<pallet_balances::Pallet<Test>>::set_balance(Origin::root(), RICH_USER, value, 0));17	assert_ok!(<pallet_balances::Pallet<Test>>::force_transfer(Origin::root(), RICH_USER, user, value));18}1920fn default_nft_data() -> CreateNftData {21	CreateNftData {22		const_data: vec![1, 2, 3].try_into().unwrap(),23		variable_data: vec![3, 2, 1].try_into().unwrap(),24	}25}2627fn default_fungible_data() -> CreateFungibleData {28	CreateFungibleData { value: 5 }29}3031fn default_re_fungible_data() -> CreateReFungibleData {32	CreateReFungibleData {33		const_data: vec![1, 2, 3].try_into().unwrap(),34		variable_data: vec![3, 2, 1].try_into().unwrap(),35		pieces: 1023,36	}37}3839fn create_test_collection_for_owner(40	mode: &CollectionMode,41	owner: u64,42	id: CollectionId,43) -> CollectionId {44	add_balance(owner, CollectionCreationPrice::get() as u64 + 1);4546	let col_name1: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();47	let col_desc1: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();48	let token_prefix1: Vec<u8> = b"token_prefix1\0".to_vec();4950	let origin1 = Origin::signed(owner);51	assert_ok!(TemplateModule::create_collection(52		origin1,53		col_name1.try_into().unwrap(),54		col_desc1.try_into().unwrap(),55		token_prefix1.try_into().unwrap(),56		mode.clone()57	));5859	let saved_col_name: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();60	let saved_description: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();61	let saved_prefix: Vec<u8> = b"token_prefix1\0".to_vec();62	assert_eq!(63		<pallet_common::CollectionById<Test>>::get(id)64			.unwrap()65			.owner,66		owner67	);68	assert_eq!(69		<pallet_common::CollectionById<Test>>::get(id).unwrap().name,70		saved_col_name71	);72	assert_eq!(73		<pallet_common::CollectionById<Test>>::get(id).unwrap().mode,74		*mode75	);76	assert_eq!(77		<pallet_common::CollectionById<Test>>::get(id)78			.unwrap()79			.description,80		saved_description81	);82	assert_eq!(83		<pallet_common::CollectionById<Test>>::get(id)84			.unwrap()85			.token_prefix,86		saved_prefix87	);88	id89}9091fn create_test_collection(mode: &CollectionMode, id: CollectionId) -> CollectionId {92	create_test_collection_for_owner(&mode, 1, id)93}9495fn create_test_item(collection_id: CollectionId, data: &CreateItemData) {96	let origin1 = Origin::signed(1);97	assert_ok!(TemplateModule::create_item(98		origin1,99		collection_id,100		account(1),101		data.clone()102	));103}104105fn account(sub: u64) -> TestCrossAccountId {106	TestCrossAccountId::from_sub(sub)107}108109// Use cases tests region110// #region111112#[test]113fn set_version_schema() {114	new_test_ext().execute_with(|| {115		let origin1 = Origin::signed(1);116		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));117118		assert_ok!(TemplateModule::set_schema_version(119			origin1,120			collection_id,121			SchemaVersion::Unique122		));123		assert_eq!(124			<pallet_common::CollectionById<Test>>::get(collection_id)125				.unwrap()126				.schema_version,127			SchemaVersion::Unique128		);129	});130}131132#[test]133fn check_not_sufficient_founds() {134	new_test_ext().execute_with(|| {135		let acc: u64 = 1;136		<pallet_balances::Pallet<Test>>::set_balance(Origin::root(), acc, 0, 0).unwrap();137138		let name: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();139		let description: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();140		let token_prefix: Vec<u8> = b"token_prefix1\0".to_vec();141142		let data: CreateCollectionData<<Test as system::Config>::AccountId> = CreateCollectionData {143			name: name.try_into().unwrap(),144			description: description.try_into().unwrap(),145			token_prefix: token_prefix.try_into().unwrap(),146			mode: CollectionMode::NFT,147			..Default::default()148		};149	150		let result = TemplateModule::create_collection_ex(Origin::signed(acc), data);151		assert_err!(result, <CommonError<Test>>::NotSufficientFounds);152	});153}154155#[test]156fn create_fungible_collection_fails_with_large_decimal_numbers() {157	new_test_ext().execute_with(|| {158		let col_name1: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();159		let col_desc1: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();160		let token_prefix1: Vec<u8> = b"token_prefix1\0".to_vec();161162		let origin1 = Origin::signed(1);163		assert_noop!(164			TemplateModule::create_collection(165				origin1,166				col_name1.try_into().unwrap(),167				col_desc1.try_into().unwrap(),168				token_prefix1.try_into().unwrap(),169				CollectionMode::Fungible(MAX_DECIMAL_POINTS + 1)170			),171			Error::<Test>::CollectionDecimalPointLimitExceeded172		);173	});174}175176#[test]177fn create_nft_item() {178	new_test_ext().execute_with(|| {179		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));180181		let data = default_nft_data();182		create_test_item(collection_id, &data.clone().into());183184		let item = <pallet_nonfungible::TokenData<Test>>::get((collection_id, 1)).unwrap();185		assert_eq!(item.const_data, data.const_data.into_inner());186		assert_eq!(item.variable_data, data.variable_data.into_inner());187	});188}189190// Use cases tests region191// #region192#[test]193fn create_nft_multiple_items() {194	new_test_ext().execute_with(|| {195		create_test_collection(&CollectionMode::NFT, CollectionId(1));196197		let origin1 = Origin::signed(1);198199		let items_data = vec![default_nft_data(), default_nft_data(), default_nft_data()];200201		assert_ok!(TemplateModule::create_multiple_items(202			origin1,203			CollectionId(1),204			account(1),205			items_data206				.clone()207				.into_iter()208				.map(|d| { d.into() })209				.collect()210		));211		for (index, data) in items_data.into_iter().enumerate() {212			let item = <pallet_nonfungible::TokenData<Test>>::get((213				CollectionId(1),214				TokenId((index + 1) as u32),215			))216			.unwrap();217			assert_eq!(item.const_data.to_vec(), data.const_data.into_inner());218			assert_eq!(item.variable_data.to_vec(), data.variable_data.into_inner());219		}220	});221}222223#[test]224fn create_refungible_item() {225	new_test_ext().execute_with(|| {226		let collection_id = create_test_collection(&CollectionMode::ReFungible, CollectionId(1));227228		let data = default_re_fungible_data();229		create_test_item(collection_id, &data.clone().into());230		let item = <pallet_refungible::TokenData<Test>>::get((collection_id, TokenId(1)));231		let balance =232			<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1)));233		assert_eq!(item.const_data, data.const_data.into_inner());234		assert_eq!(item.variable_data, data.variable_data.into_inner());235		assert_eq!(balance, 1023);236	});237}238239#[test]240fn create_multiple_refungible_items() {241	new_test_ext().execute_with(|| {242		create_test_collection(&CollectionMode::ReFungible, CollectionId(1));243244		let origin1 = Origin::signed(1);245246		let items_data = vec![247			default_re_fungible_data(),248			default_re_fungible_data(),249			default_re_fungible_data(),250		];251252		assert_ok!(TemplateModule::create_multiple_items(253			origin1,254			CollectionId(1),255			account(1),256			items_data257				.clone()258				.into_iter()259				.map(|d| { d.into() })260				.collect()261		));262		for (index, data) in items_data.into_iter().enumerate() {263			let item = <pallet_refungible::TokenData<Test>>::get((264				CollectionId(1),265				TokenId((index + 1) as u32),266			));267			let balance =268				<pallet_refungible::Balance<Test>>::get((CollectionId(1), TokenId(1), account(1)));269			assert_eq!(item.const_data.to_vec(), data.const_data.into_inner());270			assert_eq!(item.variable_data.to_vec(), data.variable_data.into_inner());271			assert_eq!(balance, 1023);272		}273	});274}275276#[test]277fn create_fungible_item() {278	new_test_ext().execute_with(|| {279		let collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));280281		let data = default_fungible_data();282		create_test_item(collection_id, &data.into());283284		assert_eq!(285			<pallet_fungible::Balance<Test>>::get((collection_id, account(1))),286			5287		);288	});289}290291//#[test]292// fn create_multiple_fungible_items() {293//     new_test_ext().execute_with(|| {294//         default_limits();295296//         create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));297298//         let origin1 = Origin::signed(1);299300//         let items_data = vec![default_fungible_data(), default_fungible_data(), default_fungible_data()];301302//         assert_ok!(TemplateModule::create_multiple_items(303//             origin1.clone(),304//             1,305//             1,306//             items_data.clone().into_iter().map(|d| { d.into() }).collect()307//         ));308309//         for (index, _) in items_data.iter().enumerate() {310//             assert_eq!(TemplateModule::fungible_item_id(1, (index + 1) as TokenId).value, 5);311//         }312//         assert_eq!(TemplateModule::balance_count(1, 1), 3000);313//         assert_eq!(TemplateModule::address_tokens(1, 1), [1, 2, 3]);314//     });315// }316317#[test]318fn transfer_fungible_item() {319	new_test_ext().execute_with(|| {320		let collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));321322		let origin1 = Origin::signed(1);323		let origin2 = Origin::signed(2);324325		let data = default_fungible_data();326		create_test_item(collection_id, &data.into());327328		assert_eq!(329			<pallet_fungible::Balance<Test>>::get((CollectionId(1), account(1))),330			5331		);332333		// change owner scenario334		assert_ok!(TemplateModule::transfer(335			origin1,336			account(2),337			CollectionId(1),338			TokenId(0),339			5340		));341		assert_eq!(342			<pallet_fungible::Balance<Test>>::get((CollectionId(1), account(1))),343			0344		);345346		// split item scenario347		assert_ok!(TemplateModule::transfer(348			origin2.clone(),349			account(3),350			CollectionId(1),351			TokenId(0),352			3353		));354355		// split item and new owner has account scenario356		assert_ok!(TemplateModule::transfer(357			origin2,358			account(3),359			CollectionId(1),360			TokenId(0),361			1362		));363		assert_eq!(364			<pallet_fungible::Balance<Test>>::get((CollectionId(1), account(2))),365			1366		);367		assert_eq!(368			<pallet_fungible::Balance<Test>>::get((CollectionId(1), account(3))),369			4370		);371	});372}373374#[test]375fn transfer_refungible_item() {376	new_test_ext().execute_with(|| {377		let collection_id = create_test_collection(&CollectionMode::ReFungible, CollectionId(1));378379		// Create RFT 1 in 1023 pieces for account 1380		let data = default_re_fungible_data();381		create_test_item(collection_id, &data.clone().into());382		let item = <pallet_refungible::TokenData<Test>>::get((collection_id, TokenId(1)));383		assert_eq!(item.const_data, data.const_data.into_inner());384		assert_eq!(item.variable_data, data.variable_data.into_inner());385		assert_eq!(386			<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))),387			1388		);389		assert_eq!(390			<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1))),391			1023392		);393		assert_eq!(394			<pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),395			true396		);397398		// Account 1 transfers all 1023 pieces of RFT 1 to account 2399		let origin1 = Origin::signed(1);400		let origin2 = Origin::signed(2);401		assert_ok!(TemplateModule::transfer(402			origin1,403			account(2),404			CollectionId(1),405			TokenId(1),406			1023407		));408		assert_eq!(409			<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(2))),410			1023411		);412		assert_eq!(413			<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))),414			0415		);416		assert_eq!(417			<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(2))),418			1419		);420		assert_eq!(421			<pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),422			false423		);424		assert_eq!(425			<pallet_refungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))),426			true427		);428429		// Account 2 transfers 500 pieces of RFT 1 to account 3430		assert_ok!(TemplateModule::transfer(431			origin2.clone(),432			account(3),433			CollectionId(1),434			TokenId(1),435			500436		));437		assert_eq!(438			<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(2))),439			523440		);441		assert_eq!(442			<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(3))),443			500444		);445		assert_eq!(446			<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(2))),447			1448		);449		assert_eq!(450			<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(3))),451			1452		);453		assert_eq!(454			<pallet_refungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))),455			true456		);457		assert_eq!(458			<pallet_refungible::Owned<Test>>::get((collection_id, account(3), TokenId(1))),459			true460		);461462		// Account 2 transfers 200 more pieces of RFT 1 to account 3 with pre-existing balance463		assert_ok!(TemplateModule::transfer(464			origin2,465			account(3),466			CollectionId(1),467			TokenId(1),468			200469		));470		assert_eq!(471			<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(2))),472			323473		);474		assert_eq!(475			<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(3))),476			700477		);478		assert_eq!(479			<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(2))),480			1481		);482		assert_eq!(483			<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(3))),484			1485		);486		assert_eq!(487			<pallet_refungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))),488			true489		);490		assert_eq!(491			<pallet_refungible::Owned<Test>>::get((collection_id, account(3), TokenId(1))),492			true493		);494	});495}496497#[test]498fn transfer_nft_item() {499	new_test_ext().execute_with(|| {500		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));501502		let data = default_nft_data();503		create_test_item(collection_id, &data.into());504		assert_eq!(505			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),506			1507		);508		assert_eq!(509			<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),510			true511		);512513		let origin1 = Origin::signed(1);514		// default scenario515		assert_ok!(TemplateModule::transfer(516			origin1,517			account(2),518			CollectionId(1),519			TokenId(1),520			1521		));522		assert_eq!(523			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),524			0525		);526		assert_eq!(527			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(2))),528			1529		);530		assert_eq!(531			<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),532			false533		);534		assert_eq!(535			<pallet_nonfungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))),536			true537		);538	});539}540541#[test]542fn transfer_nft_item_wrong_value() {543	new_test_ext().execute_with(|| {544		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));545546		let data = default_nft_data();547		create_test_item(collection_id, &data.into());548		assert_eq!(549			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),550			1551		);552		assert_eq!(553			<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),554			true555		);556557		let origin1 = Origin::signed(1);558559		assert_noop!(560			TemplateModule::transfer(origin1, account(2), CollectionId(1), TokenId(1), 2)561				.map_err(|e| e.error),562			<pallet_nonfungible::Error::<Test>>::NonfungibleItemsHaveNoAmount563		);564	});565}566567#[test]568fn transfer_nft_item_zero_value() {569	new_test_ext().execute_with(|| {570		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));571572		let data = default_nft_data();573		create_test_item(collection_id, &data.into());574		assert_eq!(575			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),576			1577		);578		assert_eq!(579			<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),580			true581		);582583		let origin1 = Origin::signed(1);584585		// Transferring 0 amount works on NFT...586		assert_ok!(TemplateModule::transfer(587			origin1,588			account(2),589			CollectionId(1),590			TokenId(1),591			0592		));593		// ... and results in no transfer594		assert_eq!(595			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),596			1597		);598		assert_eq!(599			<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),600			true601		);602	});603}604605#[test]606fn nft_approve_and_transfer_from() {607	new_test_ext().execute_with(|| {608		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));609610		let data = default_nft_data();611		create_test_item(collection_id, &data.into());612613		let origin1 = Origin::signed(1);614		let origin2 = Origin::signed(2);615616		assert_eq!(617			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),618			1619		);620		assert_eq!(621			<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),622			true623		);624625		// neg transfer_from626		assert_noop!(627			TemplateModule::transfer_from(628				origin2.clone(),629				account(1),630				account(2),631				CollectionId(1),632				TokenId(1),633				1634			)635			.map_err(|e| e.error),636			CommonError::<Test>::ApprovedValueTooLow637		);638639		// do approve640		assert_ok!(TemplateModule::approve(641			origin1,642			account(2),643			CollectionId(1),644			TokenId(1),645			1646		));647		assert_eq!(648			<pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),649			account(2)650		);651652		assert_ok!(TemplateModule::transfer_from(653			origin2,654			account(1),655			account(3),656			CollectionId(1),657			TokenId(1),658			1659		));660		assert!(661			<pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).is_none()662		);663	});664}665666#[test]667fn nft_approve_and_transfer_from_allow_list() {668	new_test_ext().execute_with(|| {669		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));670671		let origin1 = Origin::signed(1);672		let origin2 = Origin::signed(2);673674		// Create NFT 1 for account 1675		let data = default_nft_data();676		create_test_item(collection_id, &data.clone().into());677		assert_eq!(678			&<pallet_nonfungible::TokenData<Test>>::get((collection_id, TokenId(1)))679				.unwrap()680				.const_data,681			&data.const_data.into_inner()682		);683		assert_eq!(684			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),685			1686		);687		assert_eq!(688			<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),689			true690		);691692		// Allow allow-list users to mint and add accounts 1, 2, and 3 to allow-list693		assert_ok!(TemplateModule::set_mint_permission(694			origin1.clone(),695			CollectionId(1),696			true697		));698		assert_ok!(TemplateModule::set_public_access_mode(699			origin1.clone(),700			CollectionId(1),701			AccessMode::AllowList702		));703		assert_ok!(TemplateModule::add_to_allow_list(704			origin1.clone(),705			CollectionId(1),706			account(1)707		));708		assert_ok!(TemplateModule::add_to_allow_list(709			origin1.clone(),710			CollectionId(1),711			account(2)712		));713		assert_ok!(TemplateModule::add_to_allow_list(714			origin1.clone(),715			CollectionId(1),716			account(3)717		));718719		// Account 1 approves account 2 for NFT 1720		assert_ok!(TemplateModule::approve(721			origin1.clone(),722			account(2),723			CollectionId(1),724			TokenId(1),725			1726		));727		assert_eq!(728			<pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),729			account(2)730		);731732		// Account 2 transfers NFT 1 from account 1 to account 3733		assert_ok!(TemplateModule::transfer_from(734			origin2,735			account(1),736			account(3),737			CollectionId(1),738			TokenId(1),739			1740		));741		assert!(742			<pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).is_none()743		);744	});745}746747#[test]748fn refungible_approve_and_transfer_from() {749	new_test_ext().execute_with(|| {750		let collection_id = create_test_collection(&CollectionMode::ReFungible, CollectionId(1));751752		let origin1 = Origin::signed(1);753		let origin2 = Origin::signed(2);754755		// Create RFT 1 in 1023 pieces for account 1756		let data = default_re_fungible_data();757		create_test_item(collection_id, &data.into());758759		assert_eq!(760			<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))),761			1762		);763		assert_eq!(764			<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1))),765			1023766		);767		assert_eq!(768			<pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),769			true770		);771772		// Allow public minting, enable allow-list and add accounts 1, 2, 3 to allow-list773		assert_ok!(TemplateModule::set_mint_permission(774			origin1.clone(),775			CollectionId(1),776			true777		));778		assert_ok!(TemplateModule::set_public_access_mode(779			origin1.clone(),780			CollectionId(1),781			AccessMode::AllowList782		));783		assert_ok!(TemplateModule::add_to_allow_list(784			origin1.clone(),785			CollectionId(1),786			account(1)787		));788		assert_ok!(TemplateModule::add_to_allow_list(789			origin1.clone(),790			CollectionId(1),791			account(2)792		));793		assert_ok!(TemplateModule::add_to_allow_list(794			origin1.clone(),795			CollectionId(1),796			account(3)797		));798799		// Account 1 approves account 2 for 1023 pieces of RFT 1800		assert_ok!(TemplateModule::approve(801			origin1,802			account(2),803			CollectionId(1),804			TokenId(1),805			1023806		));807		assert_eq!(808			<pallet_refungible::Allowance<Test>>::get((809				CollectionId(1),810				TokenId(1),811				account(1),812				account(2)813			)),814			1023815		);816817		// Account 2 transfers 100 pieces of RFT 1 from account 1 to account 3818		assert_ok!(TemplateModule::transfer_from(819			origin2,820			account(1),821			account(3),822			CollectionId(1),823			TokenId(1),824			100825		));826		assert_eq!(827			<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))),828			1829		);830		assert_eq!(831			<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(3))),832			1833		);834		assert_eq!(835			<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1))),836			923837		);838		assert_eq!(839			<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(3))),840			100841		);842		assert_eq!(843			<pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),844			true845		);846		assert_eq!(847			<pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),848			true849		);850		assert_eq!(851			<pallet_refungible::Allowance<Test>>::get((852				CollectionId(1),853				TokenId(1),854				account(1),855				account(2)856			)),857			923858		);859	});860}861862#[test]863fn fungible_approve_and_transfer_from() {864	new_test_ext().execute_with(|| {865		let collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));866867		let data = default_fungible_data();868		create_test_item(collection_id, &data.into());869870		let origin1 = Origin::signed(1);871		let origin2 = Origin::signed(2);872873		assert_ok!(TemplateModule::set_mint_permission(874			origin1.clone(),875			CollectionId(1),876			true877		));878		assert_ok!(TemplateModule::set_public_access_mode(879			origin1.clone(),880			CollectionId(1),881			AccessMode::AllowList882		));883		assert_ok!(TemplateModule::add_to_allow_list(884			origin1.clone(),885			CollectionId(1),886			account(1)887		));888		assert_ok!(TemplateModule::add_to_allow_list(889			origin1.clone(),890			CollectionId(1),891			account(2)892		));893		assert_ok!(TemplateModule::add_to_allow_list(894			origin1.clone(),895			CollectionId(1),896			account(3)897		));898899		// do approve900		assert_ok!(TemplateModule::approve(901			origin1.clone(),902			account(2),903			CollectionId(1),904			TokenId(0),905			5906		));907		assert_eq!(908			<pallet_fungible::Allowance<Test>>::get((CollectionId(1), account(1), account(2))),909			5910		);911		assert_ok!(TemplateModule::approve(912			origin1,913			account(3),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_eq!(923			<pallet_fungible::Allowance<Test>>::get((CollectionId(1), account(1), account(3))),924			5925		);926927		assert_ok!(TemplateModule::transfer_from(928			origin2.clone(),929			account(1),930			account(3),931			CollectionId(1),932			TokenId(0),933			4934		));935936		assert_eq!(937			<pallet_fungible::Allowance<Test>>::get((CollectionId(1), account(1), account(2))),938			1939		);940941		assert_noop!(942			TemplateModule::transfer_from(943				origin2,944				account(1),945				account(3),946				CollectionId(1),947				TokenId(0),948				4949			)950			.map_err(|e| e.error),951			CommonError::<Test>::ApprovedValueTooLow952		);953	});954}955956#[test]957fn change_collection_owner() {958	new_test_ext().execute_with(|| {959		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));960961		let origin1 = Origin::signed(1);962		assert_ok!(TemplateModule::change_collection_owner(963			origin1,964			collection_id,965			2966		));967		assert_eq!(968			<pallet_common::CollectionById<Test>>::get(collection_id)969				.unwrap()970				.owner,971			2972		);973	});974}975976#[test]977fn destroy_collection() {978	new_test_ext().execute_with(|| {979		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));980981		let origin1 = Origin::signed(1);982		assert_ok!(TemplateModule::destroy_collection(origin1, collection_id));983	});984}985986#[test]987fn burn_nft_item() {988	new_test_ext().execute_with(|| {989		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));990991		let origin1 = Origin::signed(1);992993		let data = default_nft_data();994		create_test_item(collection_id, &data.into());995996		// check balance (collection with id = 1, user id = 1)997		assert_eq!(998			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),999			11000		);10011002		// burn item1003		assert_ok!(TemplateModule::burn_item(1004			origin1.clone(),1005			collection_id,1006			TokenId(1),1007			11008		));1009		assert_eq!(1010			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),1011			01012		);1013	});1014}10151016#[test]1017fn burn_same_nft_item_twice() {1018	new_test_ext().execute_with(|| {1019		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));10201021		let origin1 = Origin::signed(1);10221023		let data = default_nft_data();1024		create_test_item(collection_id, &data.into());10251026		// check balance (collection with id = 1, user id = 1)1027		assert_eq!(1028			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),1029			11030		);10311032		// burn item1033		assert_ok!(TemplateModule::burn_item(1034			origin1.clone(),1035			collection_id,1036			TokenId(1),1037			11038		));10391040		// burn item again1041		assert_noop!(1042			TemplateModule::burn_item(origin1, collection_id, TokenId(1), 1).map_err(|e| e.error),1043			CommonError::<Test>::TokenNotFound1044		);10451046		assert_eq!(1047			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),1048			01049		);1050	});1051}10521053#[test]1054fn burn_fungible_item() {1055	new_test_ext().execute_with(|| {1056		let collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));10571058		let origin1 = Origin::signed(1);1059		assert_ok!(TemplateModule::add_collection_admin(1060			origin1.clone(),1061			collection_id,1062			account(2)1063		));10641065		let data = default_fungible_data();1066		create_test_item(collection_id, &data.into());10671068		// check balance (collection with id = 1, user id = 1)1069		assert_eq!(1070			<pallet_fungible::Balance<Test>>::get((collection_id, account(1))),1071			51072		);10731074		// burn item1075		assert_ok!(TemplateModule::burn_item(1076			origin1.clone(),1077			CollectionId(1),1078			TokenId(0),1079			51080		));1081		assert_noop!(1082			TemplateModule::burn_item(origin1, CollectionId(1), TokenId(0), 5).map_err(|e| e.error),1083			CommonError::<Test>::TokenValueTooLow1084		);10851086		assert_eq!(1087			<pallet_fungible::Balance<Test>>::get((collection_id, account(1))),1088			01089		);1090	});1091}10921093#[test]1094fn burn_fungible_item_with_token_id() {1095	new_test_ext().execute_with(|| {1096		let collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));10971098		let origin1 = Origin::signed(1);1099		assert_ok!(TemplateModule::add_collection_admin(1100			origin1.clone(),1101			collection_id,1102			account(2)1103		));11041105		let data = default_fungible_data();1106		create_test_item(collection_id, &data.into());11071108		// check balance (collection with id = 1, user id = 1)1109		assert_eq!(1110			<pallet_fungible::Balance<Test>>::get((collection_id, account(1))),1111			51112		);11131114		// Try to burn item using Token ID1115		assert_noop!(1116			TemplateModule::burn_item(origin1, CollectionId(1), TokenId(1), 5).map_err(|e| e.error),1117			<pallet_fungible::Error::<Test>>::FungibleItemsHaveNoId1118		);1119	});1120}1121#[test]1122fn burn_refungible_item() {1123	new_test_ext().execute_with(|| {1124		let collection_id = create_test_collection(&CollectionMode::ReFungible, CollectionId(1));1125		let origin1 = Origin::signed(1);11261127		assert_ok!(TemplateModule::set_mint_permission(1128			origin1.clone(),1129			collection_id,1130			true1131		));1132		assert_ok!(TemplateModule::set_public_access_mode(1133			origin1.clone(),1134			collection_id,1135			AccessMode::AllowList1136		));1137		assert_ok!(TemplateModule::add_to_allow_list(1138			origin1.clone(),1139			collection_id,1140			account(1)1141		));11421143		assert_ok!(TemplateModule::add_collection_admin(1144			origin1.clone(),1145			collection_id,1146			account(2)1147		));11481149		let data = default_re_fungible_data();1150		create_test_item(collection_id, &data.into());11511152		// check balance (collection with id = 1, user id = 2)1153		assert_eq!(1154			<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))),1155			11156		);1157		assert_eq!(1158			<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1))),1159			10231160		);11611162		// burn item1163		assert_ok!(TemplateModule::burn_item(1164			origin1.clone(),1165			collection_id,1166			TokenId(1),1167			10231168		));1169		assert_noop!(1170			TemplateModule::burn_item(origin1, collection_id, TokenId(1), 1023)1171				.map_err(|e| e.error),1172			CommonError::<Test>::TokenValueTooLow1173		);11741175		assert_eq!(1176			<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1))),1177			01178		);1179	});1180}11811182#[test]1183fn add_collection_admin() {1184	new_test_ext().execute_with(|| {1185		let collection1_id =1186			create_test_collection_for_owner(&CollectionMode::NFT, 1, CollectionId(1));1187		let origin1 = Origin::signed(1);11881189		// Add collection admins1190		assert_ok!(TemplateModule::add_collection_admin(1191			origin1.clone(),1192			collection1_id,1193			account(2)1194		));1195		assert_ok!(TemplateModule::add_collection_admin(1196			origin1,1197			collection1_id,1198			account(3)1199		));12001201		// Owner is not an admin by default1202		assert_eq!(1203			<pallet_common::IsAdmin<Test>>::get((CollectionId(1), account(1))),1204			false1205		);1206		assert!(<pallet_common::IsAdmin<Test>>::get((1207			CollectionId(1),1208			account(2)1209		)));1210		assert!(<pallet_common::IsAdmin<Test>>::get((1211			CollectionId(1),1212			account(3)1213		)));1214	});1215}12161217#[test]1218fn remove_collection_admin() {1219	new_test_ext().execute_with(|| {1220		let collection1_id =1221			create_test_collection_for_owner(&CollectionMode::NFT, 1, CollectionId(1));1222		let origin1 = Origin::signed(1);1223		let origin2 = Origin::signed(2);12241225		// Add collection admins 2 and 31226		assert_ok!(TemplateModule::add_collection_admin(1227			origin1.clone(),1228			collection1_id,1229			account(2)1230		));1231		assert_ok!(TemplateModule::add_collection_admin(1232			origin1,1233			collection1_id,1234			account(3)1235		));12361237		assert!(<pallet_common::IsAdmin<Test>>::get((1238			CollectionId(1),1239			account(2)1240		)));1241		assert!(<pallet_common::IsAdmin<Test>>::get((1242			CollectionId(1),1243			account(3)1244		)));12451246		// remove admin 31247		assert_ok!(TemplateModule::remove_collection_admin(1248			origin2,1249			CollectionId(1),1250			account(3)1251		));12521253		// 2 is still admin, 3 is not an admin anymore1254		assert!(<pallet_common::IsAdmin<Test>>::get((1255			CollectionId(1),1256			account(2)1257		)));1258		assert_eq!(1259			<pallet_common::IsAdmin<Test>>::get((CollectionId(1), account(3))),1260			false1261		);1262	});1263}12641265#[test]1266fn balance_of() {1267	new_test_ext().execute_with(|| {1268		let nft_collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1269		let fungible_collection_id =1270			create_test_collection(&CollectionMode::Fungible(3), CollectionId(2));1271		let re_fungible_collection_id =1272			create_test_collection(&CollectionMode::ReFungible, CollectionId(3));12731274		// check balance before1275		assert_eq!(1276			<pallet_nonfungible::AccountBalance<Test>>::get((nft_collection_id, account(1))),1277			01278		);1279		assert_eq!(1280			<pallet_fungible::Balance<Test>>::get((fungible_collection_id, account(1))),1281			01282		);1283		assert_eq!(1284			<pallet_refungible::AccountBalance<Test>>::get((re_fungible_collection_id, account(1))),1285			01286		);12871288		let nft_data = default_nft_data();1289		create_test_item(nft_collection_id, &nft_data.into());12901291		let fungible_data = default_fungible_data();1292		create_test_item(fungible_collection_id, &fungible_data.into());12931294		let re_fungible_data = default_re_fungible_data();1295		create_test_item(re_fungible_collection_id, &re_fungible_data.into());12961297		// check balance (collection with id = 1, user id = 1)1298		assert_eq!(1299			<pallet_nonfungible::AccountBalance<Test>>::get((nft_collection_id, account(1))),1300			11301		);1302		assert_eq!(1303			<pallet_fungible::Balance<Test>>::get((fungible_collection_id, account(1))),1304			51305		);1306		assert_eq!(1307			<pallet_refungible::AccountBalance<Test>>::get((re_fungible_collection_id, account(1))),1308			11309		);13101311		assert_eq!(1312			<pallet_nonfungible::Owned<Test>>::get((nft_collection_id, account(1), TokenId(1))),1313			true1314		);1315		assert_eq!(1316			<pallet_refungible::Owned<Test>>::get((1317				re_fungible_collection_id,1318				account(1),1319				TokenId(1)1320			)),1321			true1322		);1323	});1324}13251326#[test]1327fn approve() {1328	new_test_ext().execute_with(|| {1329		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));13301331		let data = default_nft_data();1332		create_test_item(collection_id, &data.into());13331334		let origin1 = Origin::signed(1);13351336		// approve1337		assert_ok!(TemplateModule::approve(1338			origin1,1339			account(2),1340			CollectionId(1),1341			TokenId(1),1342			11343		));1344		assert_eq!(1345			<pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),1346			account(2)1347		);1348	});1349}13501351#[test]1352fn transfer_from() {1353	new_test_ext().execute_with(|| {1354		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1355		let origin1 = Origin::signed(1);1356		let origin2 = Origin::signed(2);13571358		let data = default_nft_data();1359		create_test_item(collection_id, &data.into());13601361		// approve1362		assert_ok!(TemplateModule::approve(1363			origin1.clone(),1364			account(2),1365			CollectionId(1),1366			TokenId(1),1367			11368		));1369		assert_eq!(1370			<pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),1371			account(2)1372		);13731374		assert_ok!(TemplateModule::set_mint_permission(1375			origin1.clone(),1376			CollectionId(1),1377			true1378		));1379		assert_ok!(TemplateModule::set_public_access_mode(1380			origin1.clone(),1381			CollectionId(1),1382			AccessMode::AllowList1383		));1384		assert_ok!(TemplateModule::add_to_allow_list(1385			origin1.clone(),1386			CollectionId(1),1387			account(1)1388		));1389		assert_ok!(TemplateModule::add_to_allow_list(1390			origin1.clone(),1391			CollectionId(1),1392			account(2)1393		));1394		assert_ok!(TemplateModule::add_to_allow_list(1395			origin1,1396			CollectionId(1),1397			account(3)1398		));13991400		assert_ok!(TemplateModule::transfer_from(1401			origin2,1402			account(1),1403			account(2),1404			CollectionId(1),1405			TokenId(1),1406			11407		));14081409		// after transfer1410		assert_eq!(1411			<pallet_nonfungible::AccountBalance<Test>>::get((CollectionId(1), account(1))),1412			01413		);1414		assert_eq!(1415			<pallet_nonfungible::AccountBalance<Test>>::get((CollectionId(1), account(2))),1416			11417		);1418	});1419}14201421// #endregion14221423// Coverage tests region1424// #region14251426#[test]1427fn owner_can_add_address_to_allow_list() {1428	new_test_ext().execute_with(|| {1429		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));14301431		let origin1 = Origin::signed(1);1432		assert_ok!(TemplateModule::add_to_allow_list(1433			origin1,1434			collection_id,1435			account(2)1436		));1437		assert!(<pallet_common::Allowlist<Test>>::get((1438			collection_id,1439			account(2)1440		)));1441	});1442}14431444#[test]1445fn admin_can_add_address_to_allow_list() {1446	new_test_ext().execute_with(|| {1447		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1448		let origin1 = Origin::signed(1);1449		let origin2 = Origin::signed(2);14501451		assert_ok!(TemplateModule::add_collection_admin(1452			origin1,1453			collection_id,1454			account(2)1455		));1456		assert_ok!(TemplateModule::add_to_allow_list(1457			origin2,1458			collection_id,1459			account(3)1460		));1461		assert!(<pallet_common::Allowlist<Test>>::get((1462			collection_id,1463			account(3)1464		)));1465	});1466}14671468#[test]1469fn nonprivileged_user_cannot_add_address_to_allow_list() {1470	new_test_ext().execute_with(|| {1471		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));14721473		let origin2 = Origin::signed(2);1474		assert_noop!(1475			TemplateModule::add_to_allow_list(origin2, collection_id, account(3)),1476			CommonError::<Test>::NoPermission1477		);1478	});1479}14801481#[test]1482fn nobody_can_add_address_to_allow_list_of_nonexisting_collection() {1483	new_test_ext().execute_with(|| {1484		let origin1 = Origin::signed(1);14851486		assert_noop!(1487			TemplateModule::add_to_allow_list(origin1, CollectionId(1), account(2)),1488			CommonError::<Test>::CollectionNotFound1489		);1490	});1491}14921493#[test]1494fn nobody_can_add_address_to_allow_list_of_deleted_collection() {1495	new_test_ext().execute_with(|| {1496		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));14971498		let origin1 = Origin::signed(1);1499		assert_ok!(TemplateModule::destroy_collection(1500			origin1.clone(),1501			collection_id1502		));1503		assert_noop!(1504			TemplateModule::add_to_allow_list(origin1, collection_id, account(2)),1505			CommonError::<Test>::CollectionNotFound1506		);1507	});1508}15091510// If address is already added to allow list, nothing happens1511#[test]1512fn address_is_already_added_to_allow_list() {1513	new_test_ext().execute_with(|| {1514		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1515		let origin1 = Origin::signed(1);15161517		assert_ok!(TemplateModule::add_to_allow_list(1518			origin1.clone(),1519			collection_id,1520			account(2)1521		));1522		assert_ok!(TemplateModule::add_to_allow_list(1523			origin1,1524			collection_id,1525			account(2)1526		));1527		assert!(<pallet_common::Allowlist<Test>>::get((1528			collection_id,1529			account(2)1530		)));1531	});1532}15331534#[test]1535fn owner_can_remove_address_from_allow_list() {1536	new_test_ext().execute_with(|| {1537		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));15381539		let origin1 = Origin::signed(1);1540		assert_ok!(TemplateModule::add_to_allow_list(1541			origin1.clone(),1542			collection_id,1543			account(2)1544		));1545		assert_ok!(TemplateModule::remove_from_allow_list(1546			origin1,1547			collection_id,1548			account(2)1549		));1550		assert_eq!(1551			<pallet_common::Allowlist<Test>>::get((collection_id, account(2))),1552			false1553		);1554	});1555}15561557#[test]1558fn admin_can_remove_address_from_allow_list() {1559	new_test_ext().execute_with(|| {1560		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1561		let origin1 = Origin::signed(1);1562		let origin2 = Origin::signed(2);15631564		// Owner adds admin1565		assert_ok!(TemplateModule::add_collection_admin(1566			origin1.clone(),1567			collection_id,1568			account(2)1569		));15701571		// Owner adds address 3 to allow list1572		assert_ok!(TemplateModule::add_to_allow_list(1573			origin1,1574			collection_id,1575			account(3)1576		));15771578		// Admin removes address 3 from allow list1579		assert_ok!(TemplateModule::remove_from_allow_list(1580			origin2,1581			collection_id,1582			account(3)1583		));1584		assert_eq!(1585			<pallet_common::Allowlist<Test>>::get((collection_id, account(3))),1586			false1587		);1588	});1589}15901591#[test]1592fn nonprivileged_user_cannot_remove_address_from_allow_list() {1593	new_test_ext().execute_with(|| {1594		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1595		let origin1 = Origin::signed(1);1596		let origin2 = Origin::signed(2);15971598		assert_ok!(TemplateModule::add_to_allow_list(1599			origin1,1600			collection_id,1601			account(2)1602		));1603		assert_noop!(1604			TemplateModule::remove_from_allow_list(origin2, collection_id, account(2)),1605			CommonError::<Test>::NoPermission1606		);1607		assert!(<pallet_common::Allowlist<Test>>::get((1608			collection_id,1609			account(2)1610		)));1611	});1612}16131614#[test]1615fn nobody_can_remove_address_from_allow_list_of_nonexisting_collection() {1616	new_test_ext().execute_with(|| {1617		let origin1 = Origin::signed(1);16181619		assert_noop!(1620			TemplateModule::remove_from_allow_list(origin1, CollectionId(1), account(2)),1621			CommonError::<Test>::CollectionNotFound1622		);1623	});1624}16251626#[test]1627fn nobody_can_remove_address_from_allow_list_of_deleted_collection() {1628	new_test_ext().execute_with(|| {1629		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1630		let origin1 = Origin::signed(1);1631		let origin2 = Origin::signed(2);16321633		// Add account 2 to allow list1634		assert_ok!(TemplateModule::add_to_allow_list(1635			origin1.clone(),1636			collection_id,1637			account(2)1638		));16391640		// Account 2 is in collection allow-list1641		assert!(<pallet_common::Allowlist<Test>>::get((1642			collection_id,1643			account(2)1644		)));16451646		// Destroy collection1647		assert_ok!(TemplateModule::destroy_collection(origin1, collection_id));16481649		// Attempt to remove account 2 from collection allow-list => error1650		assert_noop!(1651			TemplateModule::remove_from_allow_list(origin2, collection_id, account(2)),1652			CommonError::<Test>::CollectionNotFound1653		);16541655		// Account 2 is not found in collection allow-list anyway1656		assert_eq!(1657			<pallet_common::Allowlist<Test>>::get((collection_id, account(2))),1658			false1659		);1660	});1661}16621663// If address is already removed from allow list, nothing happens1664#[test]1665fn address_is_already_removed_from_allow_list() {1666	new_test_ext().execute_with(|| {1667		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1668		let origin1 = Origin::signed(1);16691670		assert_ok!(TemplateModule::add_to_allow_list(1671			origin1.clone(),1672			collection_id,1673			account(2)1674		));1675		assert_ok!(TemplateModule::remove_from_allow_list(1676			origin1.clone(),1677			collection_id,1678			account(2)1679		));1680		assert_eq!(1681			<pallet_common::Allowlist<Test>>::get((collection_id, account(2))),1682			false1683		);1684		assert_ok!(TemplateModule::remove_from_allow_list(1685			origin1,1686			collection_id,1687			account(2)1688		));1689		assert_eq!(1690			<pallet_common::Allowlist<Test>>::get((collection_id, account(2))),1691			false1692		);1693	});1694}16951696// If Public Access mode is set to AllowList, tokens can’t be transferred from a non-allowlisted address with transfer or transferFrom (2 tests)1697#[test]1698fn allow_list_test_1() {1699	new_test_ext().execute_with(|| {1700		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));17011702		let origin1 = Origin::signed(1);17031704		let data = default_nft_data();1705		create_test_item(collection_id, &data.into());17061707		assert_ok!(TemplateModule::set_public_access_mode(1708			origin1.clone(),1709			collection_id,1710			AccessMode::AllowList1711		));1712		assert_ok!(TemplateModule::add_to_allow_list(1713			origin1.clone(),1714			collection_id,1715			account(2)1716		));17171718		assert_noop!(1719			TemplateModule::transfer(origin1, account(3), CollectionId(1), TokenId(1), 1)1720				.map_err(|e| e.error),1721			CommonError::<Test>::AddressNotInAllowlist1722		);1723	});1724}17251726#[test]1727fn allow_list_test_2() {1728	new_test_ext().execute_with(|| {1729		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1730		let origin1 = Origin::signed(1);17311732		let data = default_nft_data();1733		create_test_item(collection_id, &data.into());17341735		assert_ok!(TemplateModule::set_public_access_mode(1736			origin1.clone(),1737			collection_id,1738			AccessMode::AllowList1739		));1740		assert_ok!(TemplateModule::add_to_allow_list(1741			origin1.clone(),1742			collection_id,1743			account(1)1744		));1745		assert_ok!(TemplateModule::add_to_allow_list(1746			origin1.clone(),1747			collection_id,1748			account(2)1749		));17501751		// do approve1752		assert_ok!(TemplateModule::approve(1753			origin1.clone(),1754			account(1),1755			collection_id,1756			TokenId(1),1757			11758		));1759		assert_eq!(1760			<pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),1761			account(1)1762		);17631764		assert_ok!(TemplateModule::remove_from_allow_list(1765			origin1.clone(),1766			collection_id,1767			account(1)1768		));17691770		assert_noop!(1771			TemplateModule::transfer_from(1772				origin1,1773				account(1),1774				account(3),1775				CollectionId(1),1776				TokenId(1),1777				11778			)1779			.map_err(|e| e.error),1780			CommonError::<Test>::AddressNotInAllowlist1781		);1782	});1783}17841785// If Public Access mode is set to AllowList, tokens can’t be transferred to a non-allowlisted address with transfer or transferFrom (2 tests)1786#[test]1787fn allow_list_test_3() {1788	new_test_ext().execute_with(|| {1789		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));17901791		let origin1 = Origin::signed(1);17921793		let data = default_nft_data();1794		create_test_item(collection_id, &data.into());17951796		assert_ok!(TemplateModule::set_public_access_mode(1797			origin1.clone(),1798			collection_id,1799			AccessMode::AllowList1800		));1801		assert_ok!(TemplateModule::add_to_allow_list(1802			origin1.clone(),1803			collection_id,1804			account(1)1805		));18061807		assert_noop!(1808			TemplateModule::transfer(origin1, account(3), collection_id, TokenId(1), 1)1809				.map_err(|e| e.error),1810			CommonError::<Test>::AddressNotInAllowlist1811		);1812	});1813}18141815#[test]1816fn allow_list_test_4() {1817	new_test_ext().execute_with(|| {1818		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));18191820		let origin1 = Origin::signed(1);18211822		let data = default_nft_data();1823		create_test_item(collection_id, &data.into());18241825		assert_ok!(TemplateModule::set_public_access_mode(1826			origin1.clone(),1827			collection_id,1828			AccessMode::AllowList1829		));1830		assert_ok!(TemplateModule::add_to_allow_list(1831			origin1.clone(),1832			collection_id,1833			account(1)1834		));1835		assert_ok!(TemplateModule::add_to_allow_list(1836			origin1.clone(),1837			collection_id,1838			account(2)1839		));18401841		// do approve1842		assert_ok!(TemplateModule::approve(1843			origin1.clone(),1844			account(1),1845			collection_id,1846			TokenId(1),1847			11848		));1849		assert_eq!(1850			<pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),1851			account(1)1852		);18531854		assert_ok!(TemplateModule::remove_from_allow_list(1855			origin1.clone(),1856			collection_id,1857			account(2)1858		));18591860		assert_noop!(1861			TemplateModule::transfer_from(1862				origin1,1863				account(1),1864				account(3),1865				collection_id,1866				TokenId(1),1867				11868			)1869			.map_err(|e| e.error),1870			CommonError::<Test>::AddressNotInAllowlist1871		);1872	});1873}18741875// 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)1876#[test]1877fn allow_list_test_5() {1878	new_test_ext().execute_with(|| {1879		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));18801881		let origin1 = Origin::signed(1);18821883		let data = default_nft_data();1884		create_test_item(collection_id, &data.into());18851886		assert_ok!(TemplateModule::set_public_access_mode(1887			origin1.clone(),1888			collection_id,1889			AccessMode::AllowList1890		));1891		assert_noop!(1892			TemplateModule::burn_item(origin1.clone(), CollectionId(1), TokenId(1), 1)1893				.map_err(|e| e.error),1894			CommonError::<Test>::AddressNotInAllowlist1895		);1896	});1897}18981899// If Public Access mode is set to AllowList, token transfers can’t be Approved by a non-allowlisted address (see Approve method).1900#[test]1901fn allow_list_test_6() {1902	new_test_ext().execute_with(|| {1903		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));19041905		let origin1 = Origin::signed(1);19061907		let data = default_nft_data();1908		create_test_item(collection_id, &data.into());19091910		assert_ok!(TemplateModule::set_public_access_mode(1911			origin1.clone(),1912			collection_id,1913			AccessMode::AllowList1914		));19151916		// do approve1917		assert_noop!(1918			TemplateModule::approve(origin1, account(1), CollectionId(1), TokenId(1), 1)1919				.map_err(|e| e.error),1920			CommonError::<Test>::AddressNotInAllowlist1921		);1922	});1923}19241925// If Public Access mode is set to AllowList, tokens can be transferred from a allowlisted address with transfer or transferFrom (2 tests) and1926//          tokens can be transferred from a allowlisted address with transfer or transferFrom (2 tests)1927#[test]1928fn allow_list_test_7() {1929	new_test_ext().execute_with(|| {1930		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));19311932		let data = default_nft_data();1933		create_test_item(collection_id, &data.into());19341935		let origin1 = Origin::signed(1);19361937		assert_ok!(TemplateModule::set_public_access_mode(1938			origin1.clone(),1939			collection_id,1940			AccessMode::AllowList1941		));1942		assert_ok!(TemplateModule::add_to_allow_list(1943			origin1.clone(),1944			collection_id,1945			account(1)1946		));1947		assert_ok!(TemplateModule::add_to_allow_list(1948			origin1.clone(),1949			collection_id,1950			account(2)1951		));19521953		assert_ok!(TemplateModule::transfer(1954			origin1,1955			account(2),1956			CollectionId(1),1957			TokenId(1),1958			11959		));1960	});1961}19621963#[test]1964fn allow_list_test_8() {1965	new_test_ext().execute_with(|| {1966		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));19671968		// Create NFT for account 11969		let data = default_nft_data();1970		create_test_item(collection_id, &data.into());19711972		let origin1 = Origin::signed(1);19731974		// Toggle Allow List mode and add accounts 1 and 21975		assert_ok!(TemplateModule::set_public_access_mode(1976			origin1.clone(),1977			collection_id,1978			AccessMode::AllowList1979		));1980		assert_ok!(TemplateModule::add_to_allow_list(1981			origin1.clone(),1982			collection_id,1983			account(1)1984		));1985		assert_ok!(TemplateModule::add_to_allow_list(1986			origin1.clone(),1987			collection_id,1988			account(2)1989		));19901991		// Sself-approve account 1 for NFT 11992		assert_ok!(TemplateModule::approve(1993			origin1.clone(),1994			account(1),1995			CollectionId(1),1996			TokenId(1),1997			11998		));1999		assert_eq!(2000			<pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),2001			account(1)2002		);20032004		// Transfer from 1 to 22005		assert_ok!(TemplateModule::transfer_from(2006			origin1,2007			account(1),2008			account(2),2009			CollectionId(1),2010			TokenId(1),2011			12012		));2013	});2014}20152016// If Public Access mode is set to AllowList, and Mint Permission is set to false, tokens can be created by owner.2017#[test]2018fn allow_list_test_9() {2019	new_test_ext().execute_with(|| {2020		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));2021		let origin1 = Origin::signed(1);20222023		assert_ok!(TemplateModule::set_public_access_mode(2024			origin1.clone(),2025			collection_id,2026			AccessMode::AllowList2027		));2028		assert_ok!(TemplateModule::set_mint_permission(2029			origin1,2030			collection_id,2031			false2032		));20332034		let data = default_nft_data();2035		create_test_item(collection_id, &data.into());2036	});2037}20382039// If Public Access mode is set to AllowList, and Mint Permission is set to false, tokens can be created by admin.2040#[test]2041fn allow_list_test_10() {2042	new_test_ext().execute_with(|| {2043		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));20442045		let origin1 = Origin::signed(1);2046		let origin2 = Origin::signed(2);20472048		assert_ok!(TemplateModule::set_public_access_mode(2049			origin1.clone(),2050			collection_id,2051			AccessMode::AllowList2052		));2053		assert_ok!(TemplateModule::set_mint_permission(2054			origin1.clone(),2055			collection_id,2056			false2057		));20582059		assert_ok!(TemplateModule::add_collection_admin(2060			origin1,2061			collection_id,2062			account(2)2063		));20642065		assert_ok!(TemplateModule::create_item(2066			origin2,2067			collection_id,2068			account(2),2069			default_nft_data().into()2070		));2071	});2072}20732074// 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.2075#[test]2076fn allow_list_test_11() {2077	new_test_ext().execute_with(|| {2078		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));20792080		let origin1 = Origin::signed(1);2081		let origin2 = Origin::signed(2);20822083		assert_ok!(TemplateModule::set_public_access_mode(2084			origin1.clone(),2085			collection_id,2086			AccessMode::AllowList2087		));2088		assert_ok!(TemplateModule::set_mint_permission(2089			origin1.clone(),2090			collection_id,2091			false2092		));2093		assert_ok!(TemplateModule::add_to_allow_list(2094			origin1,2095			collection_id,2096			account(2)2097		));20982099		assert_noop!(2100			TemplateModule::create_item(2101				origin2,2102				CollectionId(1),2103				account(2),2104				default_nft_data().into()2105			)2106			.map_err(|e| e.error),2107			CommonError::<Test>::PublicMintingNotAllowed2108		);2109	});2110}21112112// 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.2113#[test]2114fn allow_list_test_12() {2115	new_test_ext().execute_with(|| {2116		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));21172118		let origin1 = Origin::signed(1);2119		let origin2 = Origin::signed(2);21202121		assert_ok!(TemplateModule::set_public_access_mode(2122			origin1.clone(),2123			collection_id,2124			AccessMode::AllowList2125		));2126		assert_ok!(TemplateModule::set_mint_permission(2127			origin1,2128			collection_id,2129			false2130		));21312132		assert_noop!(2133			TemplateModule::create_item(2134				origin2,2135				CollectionId(1),2136				account(2),2137				default_nft_data().into()2138			)2139			.map_err(|e| e.error),2140			CommonError::<Test>::PublicMintingNotAllowed2141		);2142	});2143}21442145// If Public Access mode is set to AllowList, and Mint Permission is set to true, tokens can be created by owner.2146#[test]2147fn allow_list_test_13() {2148	new_test_ext().execute_with(|| {2149		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));21502151		let origin1 = Origin::signed(1);21522153		assert_ok!(TemplateModule::set_public_access_mode(2154			origin1.clone(),2155			collection_id,2156			AccessMode::AllowList2157		));2158		assert_ok!(TemplateModule::set_mint_permission(2159			origin1,2160			collection_id,2161			true2162		));21632164		let data = default_nft_data();2165		create_test_item(collection_id, &data.into());2166	});2167}21682169// If Public Access mode is set to AllowList, and Mint Permission is set to true, tokens can be created by admin.2170#[test]2171fn allow_list_test_14() {2172	new_test_ext().execute_with(|| {2173		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));21742175		let origin1 = Origin::signed(1);2176		let origin2 = Origin::signed(2);21772178		assert_ok!(TemplateModule::set_public_access_mode(2179			origin1.clone(),2180			collection_id,2181			AccessMode::AllowList2182		));2183		assert_ok!(TemplateModule::set_mint_permission(2184			origin1.clone(),2185			collection_id,2186			true2187		));21882189		assert_ok!(TemplateModule::add_collection_admin(2190			origin1,2191			collection_id,2192			account(2)2193		));21942195		assert_ok!(TemplateModule::create_item(2196			origin2,2197			collection_id,2198			account(2),2199			default_nft_data().into()2200		));2201	});2202}22032204// 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.2205#[test]2206fn allow_list_test_15() {2207	new_test_ext().execute_with(|| {2208		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));22092210		let origin1 = Origin::signed(1);2211		let origin2 = Origin::signed(2);22122213		assert_ok!(TemplateModule::set_public_access_mode(2214			origin1.clone(),2215			collection_id,2216			AccessMode::AllowList2217		));2218		assert_ok!(TemplateModule::set_mint_permission(2219			origin1,2220			collection_id,2221			true2222		));22232224		assert_noop!(2225			TemplateModule::create_item(2226				origin2,2227				collection_id,2228				account(2),2229				default_nft_data().into()2230			)2231			.map_err(|e| e.error),2232			CommonError::<Test>::AddressNotInAllowlist2233		);2234	});2235}22362237// 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.2238#[test]2239fn allow_list_test_16() {2240	new_test_ext().execute_with(|| {2241		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));22422243		let origin1 = Origin::signed(1);2244		let origin2 = Origin::signed(2);22452246		assert_ok!(TemplateModule::set_public_access_mode(2247			origin1.clone(),2248			collection_id,2249			AccessMode::AllowList2250		));2251		assert_ok!(TemplateModule::set_mint_permission(2252			origin1.clone(),2253			collection_id,2254			true2255		));2256		assert_ok!(TemplateModule::add_to_allow_list(2257			origin1,2258			collection_id,2259			account(2)2260		));22612262		assert_ok!(TemplateModule::create_item(2263			origin2,2264			collection_id,2265			account(2),2266			default_nft_data().into()2267		));2268	});2269}22702271// Total number of collections. Positive test2272#[test]2273fn total_number_collections_bound() {2274	new_test_ext().execute_with(|| {2275		create_test_collection(&CollectionMode::NFT, CollectionId(1));2276	});2277}22782279#[test]2280fn create_max_collections() {2281	new_test_ext().execute_with(|| {2282		for i in 1..COLLECTION_NUMBER_LIMIT {2283			create_test_collection(&CollectionMode::NFT, CollectionId(i));2284		}2285	});2286}22872288// Total number of collections. Negative test2289#[test]2290fn total_number_collections_bound_neg() {2291	new_test_ext().execute_with(|| {2292		let origin1 = Origin::signed(1);22932294		for i in 1..=COLLECTION_NUMBER_LIMIT {2295			create_test_collection(&CollectionMode::NFT, CollectionId(i));2296		}22972298		let col_name1: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();2299		let col_desc1: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();2300		let token_prefix1: Vec<u8> = b"token_prefix1\0".to_vec();23012302		// 11-th collection in chain. Expects error2303		assert_noop!(2304			TemplateModule::create_collection(2305				origin1,2306				col_name1.try_into().unwrap(),2307				col_desc1.try_into().unwrap(),2308				token_prefix1.try_into().unwrap(),2309				CollectionMode::NFT2310			),2311			CommonError::<Test>::TotalCollectionsLimitExceeded2312		);2313	});2314}23152316// Owned tokens by a single address. Positive test2317#[test]2318fn owned_tokens_bound() {2319	new_test_ext().execute_with(|| {2320		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));23212322		let data = default_nft_data();2323		create_test_item(collection_id, &data.clone().into());2324		create_test_item(collection_id, &data.into());2325	});2326}23272328// Owned tokens by a single address. Negotive test2329#[test]2330fn owned_tokens_bound_neg() {2331	new_test_ext().execute_with(|| {2332		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));23332334		let origin1 = Origin::signed(1);23352336		for _ in 1..=MAX_TOKEN_OWNERSHIP {2337			let data = default_nft_data();2338			create_test_item(collection_id, &data.clone().into());2339		}23402341		let data = default_nft_data();2342		assert_noop!(2343			TemplateModule::create_item(origin1, CollectionId(1), account(1), data.into())2344				.map_err(|e| e.error),2345			CommonError::<Test>::AccountTokenLimitExceeded2346		);2347	});2348}23492350// Number of collection admins. Positive test2351#[test]2352fn collection_admins_bound() {2353	new_test_ext().execute_with(|| {2354		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));23552356		let origin1 = Origin::signed(1);23572358		assert_ok!(TemplateModule::add_collection_admin(2359			origin1.clone(),2360			collection_id,2361			account(2)2362		));2363		assert_ok!(TemplateModule::add_collection_admin(2364			origin1,2365			collection_id,2366			account(3)2367		));2368	});2369}23702371// Number of collection admins. Negotive test2372#[test]2373fn collection_admins_bound_neg() {2374	new_test_ext().execute_with(|| {2375		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));23762377		let origin1 = Origin::signed(1);23782379		for i in 0..COLLECTION_ADMINS_LIMIT {2380			assert_ok!(TemplateModule::add_collection_admin(2381				origin1.clone(),2382				collection_id,2383				account((2 + i).into())2384			));2385		}2386		assert_noop!(2387			TemplateModule::add_collection_admin(2388				origin1,2389				collection_id,2390				account((3 + COLLECTION_ADMINS_LIMIT).into())2391			),2392			CommonError::<Test>::CollectionAdminCountExceeded2393		);2394	});2395}2396// #endregion23972398#[test]2399fn set_const_on_chain_schema() {2400	new_test_ext().execute_with(|| {2401		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));24022403		let origin1 = Origin::signed(1);2404		assert_ok!(TemplateModule::set_const_on_chain_schema(2405			origin1,2406			collection_id,2407			b"test const on chain schema".to_vec().try_into().unwrap()2408		));24092410		assert_eq!(2411			<pallet_common::CollectionById<Test>>::get(collection_id)2412				.unwrap()2413				.const_on_chain_schema,2414			b"test const on chain schema".to_vec()2415		);2416		assert_eq!(2417			<pallet_common::CollectionById<Test>>::get(collection_id)2418				.unwrap()2419				.variable_on_chain_schema,2420			b"".to_vec()2421		);2422	});2423}24242425#[test]2426fn set_variable_on_chain_schema() {2427	new_test_ext().execute_with(|| {2428		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));24292430		let origin1 = Origin::signed(1);2431		assert_ok!(TemplateModule::set_variable_on_chain_schema(2432			origin1,2433			collection_id,2434			b"test variable on chain schema"2435				.to_vec()2436				.try_into()2437				.unwrap()2438		));24392440		assert_eq!(2441			<pallet_common::CollectionById<Test>>::get(collection_id)2442				.unwrap()2443				.const_on_chain_schema,2444			b"".to_vec()2445		);2446		assert_eq!(2447			<pallet_common::CollectionById<Test>>::get(collection_id)2448				.unwrap()2449				.variable_on_chain_schema,2450			b"test variable on chain schema".to_vec()2451		);2452	});2453}24542455#[test]2456fn set_variable_meta_data_on_nft_token_stores_variable_meta_data() {2457	new_test_ext().execute_with(|| {2458		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));24592460		let origin1 = Origin::signed(1);24612462		let data = default_nft_data();2463		create_test_item(CollectionId(1), &data.into());24642465		let variable_data = b"test data".to_vec();2466		assert_ok!(TemplateModule::set_variable_meta_data(2467			origin1,2468			collection_id,2469			TokenId(1),2470			variable_data.clone().try_into().unwrap()2471		));24722473		assert_eq!(2474			<pallet_nonfungible::TokenData<Test>>::get((collection_id, 1))2475				.unwrap()2476				.variable_data,2477			variable_data2478		);2479	});2480}24812482#[test]2483fn set_variable_meta_data_on_re_fungible_token_stores_variable_meta_data() {2484	new_test_ext().execute_with(|| {2485		let collection_id = create_test_collection(&CollectionMode::ReFungible, CollectionId(1));24862487		let origin1 = Origin::signed(1);24882489		let data = default_re_fungible_data();2490		create_test_item(collection_id, &data.into());24912492		let variable_data = b"test data".to_vec();2493		assert_ok!(TemplateModule::set_variable_meta_data(2494			origin1,2495			collection_id,2496			TokenId(1),2497			variable_data.clone().try_into().unwrap()2498		));24992500		assert_eq!(2501			<pallet_refungible::TokenData<Test>>::get((collection_id, TokenId(1))).variable_data,2502			variable_data2503		);2504	});2505}25062507#[test]2508fn set_variable_meta_data_on_fungible_token_fails() {2509	new_test_ext().execute_with(|| {2510		let collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));25112512		let origin1 = Origin::signed(1);25132514		let data = default_fungible_data();2515		create_test_item(collection_id, &data.into());25162517		let variable_data = b"test data".to_vec();2518		assert_noop!(2519			TemplateModule::set_variable_meta_data(2520				origin1,2521				collection_id,2522				TokenId(0),2523				variable_data.try_into().unwrap()2524			)2525			.map_err(|e| e.error),2526			<pallet_fungible::Error<Test>>::FungibleItemsDontHaveData2527		);2528	});2529}25302531#[test]2532fn set_variable_meta_data_on_nft_with_item_owner_permission_flag() {2533	new_test_ext().execute_with(|| {2534		//default_limits();25352536		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));25372538		let origin1 = Origin::signed(1);25392540		let data = default_nft_data();2541		create_test_item(collection_id, &data.into());25422543		assert_ok!(TemplateModule::set_meta_update_permission_flag(2544			origin1.clone(),2545			collection_id,2546			MetaUpdatePermission::ItemOwner,2547		));25482549		let variable_data = b"ten chars.".to_vec();2550		assert_ok!(TemplateModule::set_variable_meta_data(2551			origin1,2552			collection_id,2553			TokenId(1),2554			variable_data.clone().try_into().unwrap()2555		));25562557		assert_eq!(2558			<pallet_nonfungible::TokenData<Test>>::get((collection_id, TokenId(1)))2559				.unwrap()2560				.variable_data,2561			variable_data2562		);2563	});2564}25652566#[test]2567fn collection_transfer_flag_works() {2568	new_test_ext().execute_with(|| {2569		let origin1 = Origin::signed(1);25702571		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));2572		assert_ok!(TemplateModule::set_transfers_enabled_flag(2573			origin1,2574			collection_id,2575			true2576		));25772578		let data = default_nft_data();2579		create_test_item(collection_id, &data.into());2580		assert_eq!(2581			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),2582			12583		);2584		assert_eq!(2585			<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),2586			true2587		);25882589		let origin1 = Origin::signed(1);25902591		// default scenario2592		assert_ok!(TemplateModule::transfer(2593			origin1,2594			account(2),2595			collection_id,2596			TokenId(1),2597			12598		));2599		assert_eq!(2600			<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),2601			false2602		);2603		assert_eq!(2604			<pallet_nonfungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))),2605			true2606		);2607		assert_eq!(2608			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),2609			02610		);2611		assert_eq!(2612			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(2))),2613			12614		);2615	});2616}26172618#[test]2619fn set_variable_meta_data_on_nft_with_admin_flag() {2620	new_test_ext().execute_with(|| {2621		// default_limits();26222623		let collection_id =2624			create_test_collection_for_owner(&CollectionMode::NFT, 2, CollectionId(1));26252626		let origin1 = Origin::signed(1);2627		let origin2 = Origin::signed(2);26282629		assert_ok!(TemplateModule::set_mint_permission(2630			origin2.clone(),2631			collection_id,2632			true2633		));2634		assert_ok!(TemplateModule::add_to_allow_list(2635			origin2.clone(),2636			collection_id,2637			account(1)2638		));26392640		assert_ok!(TemplateModule::add_collection_admin(2641			origin2.clone(),2642			collection_id,2643			account(1)2644		));26452646		let data = default_nft_data();2647		create_test_item(collection_id, &data.into());26482649		assert_ok!(TemplateModule::set_meta_update_permission_flag(2650			origin2.clone(),2651			collection_id,2652			MetaUpdatePermission::Admin,2653		));26542655		let variable_data = b"test.".to_vec();2656		assert_ok!(TemplateModule::set_variable_meta_data(2657			origin1,2658			collection_id,2659			TokenId(1),2660			variable_data.clone().try_into().unwrap()2661		));26622663		assert_eq!(2664			<pallet_nonfungible::TokenData<Test>>::get((collection_id, 1))2665				.unwrap()2666				.variable_data,2667			variable_data2668		);2669	});2670}26712672#[test]2673fn set_variable_meta_data_on_nft_with_admin_flag_neg() {2674	new_test_ext().execute_with(|| {2675		// default_limits();26762677		let collection_id =2678			create_test_collection_for_owner(&CollectionMode::NFT, 2, CollectionId(1));26792680		let origin1 = Origin::signed(1);2681		let origin2 = Origin::signed(2);26822683		assert_ok!(TemplateModule::set_mint_permission(2684			origin2.clone(),2685			collection_id,2686			true2687		));2688		assert_ok!(TemplateModule::add_to_allow_list(2689			origin2.clone(),2690			collection_id,2691			account(1)2692		));26932694		let data = default_nft_data();2695		create_test_item(collection_id, &data.into());26962697		assert_ok!(TemplateModule::set_meta_update_permission_flag(2698			origin2.clone(),2699			collection_id,2700			MetaUpdatePermission::Admin,2701		));27022703		let variable_data = b"test.".to_vec();2704		assert_noop!(2705			TemplateModule::set_variable_meta_data(2706				origin1,2707				collection_id,2708				TokenId(1),2709				variable_data.try_into().unwrap()2710			)2711			.map_err(|e| e.error),2712			CommonError::<Test>::NoPermission2713		);2714	});2715}27162717#[test]2718fn set_variable_meta_flag_after_freeze() {2719	new_test_ext().execute_with(|| {2720		// default_limits();27212722		let collection_id =2723			create_test_collection_for_owner(&CollectionMode::NFT, 2, CollectionId(1));27242725		let origin2 = Origin::signed(2);27262727		assert_ok!(TemplateModule::set_meta_update_permission_flag(2728			origin2.clone(),2729			collection_id,2730			MetaUpdatePermission::None,2731		));2732		assert_noop!(2733			TemplateModule::set_meta_update_permission_flag(2734				origin2.clone(),2735				collection_id,2736				MetaUpdatePermission::Admin2737			),2738			CommonError::<Test>::MetadataFlagFrozen2739		);2740	});2741}27422743#[test]2744fn set_variable_meta_data_on_nft_with_none_flag_neg() {2745	new_test_ext().execute_with(|| {2746		// default_limits();27472748		let collection_id =2749			create_test_collection_for_owner(&CollectionMode::NFT, 1, CollectionId(1));2750		let origin1 = Origin::signed(1);27512752		let data = default_nft_data();2753		create_test_item(collection_id, &data.into());27542755		assert_ok!(TemplateModule::set_meta_update_permission_flag(2756			origin1.clone(),2757			collection_id,2758			MetaUpdatePermission::None,2759		));27602761		let variable_data = b"test.".to_vec();2762		assert_noop!(2763			TemplateModule::set_variable_meta_data(2764				origin1.clone(),2765				collection_id,2766				TokenId(1),2767				variable_data.try_into().unwrap()2768			)2769			.map_err(|e| e.error),2770			CommonError::<Test>::NoPermission2771		);2772	});2773}27742775#[test]2776fn collection_transfer_flag_works_neg() {2777	new_test_ext().execute_with(|| {2778		let origin1 = Origin::signed(1);27792780		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));2781		assert_ok!(TemplateModule::set_transfers_enabled_flag(2782			origin1,2783			collection_id,2784			false2785		));27862787		let data = default_nft_data();2788		create_test_item(collection_id, &data.into());2789		assert_eq!(2790			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),2791			12792		);2793		assert_eq!(2794			<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),2795			true2796		);27972798		let origin1 = Origin::signed(1);27992800		// default scenario2801		assert_noop!(2802			TemplateModule::transfer(origin1, account(2), CollectionId(1), TokenId(1), 1)2803				.map_err(|e| e.error),2804			CommonError::<Test>::TransferNotAllowed2805		);2806		assert_eq!(2807			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),2808			12809		);2810		assert_eq!(2811			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(2))),2812			02813		);2814		assert_eq!(2815			<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),2816			true2817		);2818		assert_eq!(2819			<pallet_nonfungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))),2820			false2821		);2822	});2823}