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

difftreelog

Merge pull request #295 from UniqueNetwork/feature/CORE-301

kozyrevdev2022-03-01parents: #cbc95b8 #ad669e8.patch.diff
in: master
change use of function 'create_collection' => 'create_collection_ex'

1 file changed

modifiedpallets/unique/src/tests.rsdiffbeforeafterboth
before · pallets/unique/src/tests.rs
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}
after · pallets/unique/src/tests.rs
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 data: CreateCollectionData<u64> = CreateCollectionData {61		name: col_name1.try_into().unwrap(),62		description: col_desc1.try_into().unwrap(),63		token_prefix: token_prefix1.try_into().unwrap(),64		mode: mode.clone(),65		..Default::default()66	};6768	let origin1 = Origin::signed(owner);69	assert_ok!(TemplateModule::create_collection_ex(origin1, data));7071	let saved_col_name: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();72	let saved_description: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();73	let saved_prefix: Vec<u8> = b"token_prefix1\0".to_vec();74	assert_eq!(75		<pallet_common::CollectionById<Test>>::get(id)76			.unwrap()77			.owner,78		owner79	);80	assert_eq!(81		<pallet_common::CollectionById<Test>>::get(id).unwrap().name,82		saved_col_name83	);84	assert_eq!(85		<pallet_common::CollectionById<Test>>::get(id).unwrap().mode,86		*mode87	);88	assert_eq!(89		<pallet_common::CollectionById<Test>>::get(id)90			.unwrap()91			.description,92		saved_description93	);94	assert_eq!(95		<pallet_common::CollectionById<Test>>::get(id)96			.unwrap()97			.token_prefix,98		saved_prefix99	);100	id101}102103fn create_test_collection(mode: &CollectionMode, id: CollectionId) -> CollectionId {104	create_test_collection_for_owner(&mode, 1, id)105}106107fn create_test_item(collection_id: CollectionId, data: &CreateItemData) {108	let origin1 = Origin::signed(1);109	assert_ok!(TemplateModule::create_item(110		origin1,111		collection_id,112		account(1),113		data.clone()114	));115}116117fn account(sub: u64) -> TestCrossAccountId {118	TestCrossAccountId::from_sub(sub)119}120121// Use cases tests region122// #region123124#[test]125fn set_version_schema() {126	new_test_ext().execute_with(|| {127		let origin1 = Origin::signed(1);128		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));129130		assert_ok!(TemplateModule::set_schema_version(131			origin1,132			collection_id,133			SchemaVersion::Unique134		));135		assert_eq!(136			<pallet_common::CollectionById<Test>>::get(collection_id)137				.unwrap()138				.schema_version,139			SchemaVersion::Unique140		);141	});142}143144#[test]145fn check_not_sufficient_founds() {146	new_test_ext().execute_with(|| {147		let acc: u64 = 1;148		<pallet_balances::Pallet<Test>>::set_balance(Origin::root(), acc, 0, 0).unwrap();149150		let name: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();151		let description: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();152		let token_prefix: Vec<u8> = b"token_prefix1\0".to_vec();153154		let data: CreateCollectionData<<Test as system::Config>::AccountId> =155			CreateCollectionData {156				name: name.try_into().unwrap(),157				description: description.try_into().unwrap(),158				token_prefix: token_prefix.try_into().unwrap(),159				mode: CollectionMode::NFT,160				..Default::default()161			};162163		let result = TemplateModule::create_collection_ex(Origin::signed(acc), data);164		assert_err!(result, <CommonError<Test>>::NotSufficientFounds);165	});166}167168#[test]169fn create_fungible_collection_fails_with_large_decimal_numbers() {170	new_test_ext().execute_with(|| {171		let col_name1: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();172		let col_desc1: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();173		let token_prefix1: Vec<u8> = b"token_prefix1\0".to_vec();174175		let data: CreateCollectionData<u64> = CreateCollectionData {176			name: col_name1.try_into().unwrap(),177			description: col_desc1.try_into().unwrap(),178			token_prefix: token_prefix1.try_into().unwrap(),179			mode: CollectionMode::Fungible(MAX_DECIMAL_POINTS + 1),180			..Default::default()181		};182183		let origin1 = Origin::signed(1);184		assert_noop!(185			TemplateModule::create_collection_ex(origin1, data),186			Error::<Test>::CollectionDecimalPointLimitExceeded187		);188	});189}190191#[test]192fn create_nft_item() {193	new_test_ext().execute_with(|| {194		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));195196		let data = default_nft_data();197		create_test_item(collection_id, &data.clone().into());198199		let item = <pallet_nonfungible::TokenData<Test>>::get((collection_id, 1)).unwrap();200		assert_eq!(item.const_data, data.const_data.into_inner());201		assert_eq!(item.variable_data, data.variable_data.into_inner());202	});203}204205// Use cases tests region206// #region207#[test]208fn create_nft_multiple_items() {209	new_test_ext().execute_with(|| {210		create_test_collection(&CollectionMode::NFT, CollectionId(1));211212		let origin1 = Origin::signed(1);213214		let items_data = vec![default_nft_data(), default_nft_data(), default_nft_data()];215216		assert_ok!(TemplateModule::create_multiple_items(217			origin1,218			CollectionId(1),219			account(1),220			items_data221				.clone()222				.into_iter()223				.map(|d| { d.into() })224				.collect()225		));226		for (index, data) in items_data.into_iter().enumerate() {227			let item = <pallet_nonfungible::TokenData<Test>>::get((228				CollectionId(1),229				TokenId((index + 1) as u32),230			))231			.unwrap();232			assert_eq!(item.const_data.to_vec(), data.const_data.into_inner());233			assert_eq!(item.variable_data.to_vec(), data.variable_data.into_inner());234		}235	});236}237238#[test]239fn create_refungible_item() {240	new_test_ext().execute_with(|| {241		let collection_id = create_test_collection(&CollectionMode::ReFungible, CollectionId(1));242243		let data = default_re_fungible_data();244		create_test_item(collection_id, &data.clone().into());245		let item = <pallet_refungible::TokenData<Test>>::get((collection_id, TokenId(1)));246		let balance =247			<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1)));248		assert_eq!(item.const_data, data.const_data.into_inner());249		assert_eq!(item.variable_data, data.variable_data.into_inner());250		assert_eq!(balance, 1023);251	});252}253254#[test]255fn create_multiple_refungible_items() {256	new_test_ext().execute_with(|| {257		create_test_collection(&CollectionMode::ReFungible, CollectionId(1));258259		let origin1 = Origin::signed(1);260261		let items_data = vec![262			default_re_fungible_data(),263			default_re_fungible_data(),264			default_re_fungible_data(),265		];266267		assert_ok!(TemplateModule::create_multiple_items(268			origin1,269			CollectionId(1),270			account(1),271			items_data272				.clone()273				.into_iter()274				.map(|d| { d.into() })275				.collect()276		));277		for (index, data) in items_data.into_iter().enumerate() {278			let item = <pallet_refungible::TokenData<Test>>::get((279				CollectionId(1),280				TokenId((index + 1) as u32),281			));282			let balance =283				<pallet_refungible::Balance<Test>>::get((CollectionId(1), TokenId(1), account(1)));284			assert_eq!(item.const_data.to_vec(), data.const_data.into_inner());285			assert_eq!(item.variable_data.to_vec(), data.variable_data.into_inner());286			assert_eq!(balance, 1023);287		}288	});289}290291#[test]292fn create_fungible_item() {293	new_test_ext().execute_with(|| {294		let collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));295296		let data = default_fungible_data();297		create_test_item(collection_id, &data.into());298299		assert_eq!(300			<pallet_fungible::Balance<Test>>::get((collection_id, account(1))),301			5302		);303	});304}305306//#[test]307// fn create_multiple_fungible_items() {308//     new_test_ext().execute_with(|| {309//         default_limits();310311//         create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));312313//         let origin1 = Origin::signed(1);314315//         let items_data = vec![default_fungible_data(), default_fungible_data(), default_fungible_data()];316317//         assert_ok!(TemplateModule::create_multiple_items(318//             origin1.clone(),319//             1,320//             1,321//             items_data.clone().into_iter().map(|d| { d.into() }).collect()322//         ));323324//         for (index, _) in items_data.iter().enumerate() {325//             assert_eq!(TemplateModule::fungible_item_id(1, (index + 1) as TokenId).value, 5);326//         }327//         assert_eq!(TemplateModule::balance_count(1, 1), 3000);328//         assert_eq!(TemplateModule::address_tokens(1, 1), [1, 2, 3]);329//     });330// }331332#[test]333fn transfer_fungible_item() {334	new_test_ext().execute_with(|| {335		let collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));336337		let origin1 = Origin::signed(1);338		let origin2 = Origin::signed(2);339340		let data = default_fungible_data();341		create_test_item(collection_id, &data.into());342343		assert_eq!(344			<pallet_fungible::Balance<Test>>::get((CollectionId(1), account(1))),345			5346		);347348		// change owner scenario349		assert_ok!(TemplateModule::transfer(350			origin1,351			account(2),352			CollectionId(1),353			TokenId(0),354			5355		));356		assert_eq!(357			<pallet_fungible::Balance<Test>>::get((CollectionId(1), account(1))),358			0359		);360361		// split item scenario362		assert_ok!(TemplateModule::transfer(363			origin2.clone(),364			account(3),365			CollectionId(1),366			TokenId(0),367			3368		));369370		// split item and new owner has account scenario371		assert_ok!(TemplateModule::transfer(372			origin2,373			account(3),374			CollectionId(1),375			TokenId(0),376			1377		));378		assert_eq!(379			<pallet_fungible::Balance<Test>>::get((CollectionId(1), account(2))),380			1381		);382		assert_eq!(383			<pallet_fungible::Balance<Test>>::get((CollectionId(1), account(3))),384			4385		);386	});387}388389#[test]390fn transfer_refungible_item() {391	new_test_ext().execute_with(|| {392		let collection_id = create_test_collection(&CollectionMode::ReFungible, CollectionId(1));393394		// Create RFT 1 in 1023 pieces for account 1395		let data = default_re_fungible_data();396		create_test_item(collection_id, &data.clone().into());397		let item = <pallet_refungible::TokenData<Test>>::get((collection_id, TokenId(1)));398		assert_eq!(item.const_data, data.const_data.into_inner());399		assert_eq!(item.variable_data, data.variable_data.into_inner());400		assert_eq!(401			<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))),402			1403		);404		assert_eq!(405			<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1))),406			1023407		);408		assert_eq!(409			<pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),410			true411		);412413		// Account 1 transfers all 1023 pieces of RFT 1 to account 2414		let origin1 = Origin::signed(1);415		let origin2 = Origin::signed(2);416		assert_ok!(TemplateModule::transfer(417			origin1,418			account(2),419			CollectionId(1),420			TokenId(1),421			1023422		));423		assert_eq!(424			<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(2))),425			1023426		);427		assert_eq!(428			<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))),429			0430		);431		assert_eq!(432			<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(2))),433			1434		);435		assert_eq!(436			<pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),437			false438		);439		assert_eq!(440			<pallet_refungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))),441			true442		);443444		// Account 2 transfers 500 pieces of RFT 1 to account 3445		assert_ok!(TemplateModule::transfer(446			origin2.clone(),447			account(3),448			CollectionId(1),449			TokenId(1),450			500451		));452		assert_eq!(453			<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(2))),454			523455		);456		assert_eq!(457			<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(3))),458			500459		);460		assert_eq!(461			<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(2))),462			1463		);464		assert_eq!(465			<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(3))),466			1467		);468		assert_eq!(469			<pallet_refungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))),470			true471		);472		assert_eq!(473			<pallet_refungible::Owned<Test>>::get((collection_id, account(3), TokenId(1))),474			true475		);476477		// Account 2 transfers 200 more pieces of RFT 1 to account 3 with pre-existing balance478		assert_ok!(TemplateModule::transfer(479			origin2,480			account(3),481			CollectionId(1),482			TokenId(1),483			200484		));485		assert_eq!(486			<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(2))),487			323488		);489		assert_eq!(490			<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(3))),491			700492		);493		assert_eq!(494			<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(2))),495			1496		);497		assert_eq!(498			<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(3))),499			1500		);501		assert_eq!(502			<pallet_refungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))),503			true504		);505		assert_eq!(506			<pallet_refungible::Owned<Test>>::get((collection_id, account(3), TokenId(1))),507			true508		);509	});510}511512#[test]513fn transfer_nft_item() {514	new_test_ext().execute_with(|| {515		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));516517		let data = default_nft_data();518		create_test_item(collection_id, &data.into());519		assert_eq!(520			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),521			1522		);523		assert_eq!(524			<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),525			true526		);527528		let origin1 = Origin::signed(1);529		// default scenario530		assert_ok!(TemplateModule::transfer(531			origin1,532			account(2),533			CollectionId(1),534			TokenId(1),535			1536		));537		assert_eq!(538			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),539			0540		);541		assert_eq!(542			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(2))),543			1544		);545		assert_eq!(546			<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),547			false548		);549		assert_eq!(550			<pallet_nonfungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))),551			true552		);553	});554}555556#[test]557fn transfer_nft_item_wrong_value() {558	new_test_ext().execute_with(|| {559		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));560561		let data = default_nft_data();562		create_test_item(collection_id, &data.into());563		assert_eq!(564			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),565			1566		);567		assert_eq!(568			<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),569			true570		);571572		let origin1 = Origin::signed(1);573574		assert_noop!(575			TemplateModule::transfer(origin1, account(2), CollectionId(1), TokenId(1), 2)576				.map_err(|e| e.error),577			<pallet_nonfungible::Error::<Test>>::NonfungibleItemsHaveNoAmount578		);579	});580}581582#[test]583fn transfer_nft_item_zero_value() {584	new_test_ext().execute_with(|| {585		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));586587		let data = default_nft_data();588		create_test_item(collection_id, &data.into());589		assert_eq!(590			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),591			1592		);593		assert_eq!(594			<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),595			true596		);597598		let origin1 = Origin::signed(1);599600		// Transferring 0 amount works on NFT...601		assert_ok!(TemplateModule::transfer(602			origin1,603			account(2),604			CollectionId(1),605			TokenId(1),606			0607		));608		// ... and results in no transfer609		assert_eq!(610			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),611			1612		);613		assert_eq!(614			<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),615			true616		);617	});618}619620#[test]621fn nft_approve_and_transfer_from() {622	new_test_ext().execute_with(|| {623		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));624625		let data = default_nft_data();626		create_test_item(collection_id, &data.into());627628		let origin1 = Origin::signed(1);629		let origin2 = Origin::signed(2);630631		assert_eq!(632			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),633			1634		);635		assert_eq!(636			<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),637			true638		);639640		// neg transfer_from641		assert_noop!(642			TemplateModule::transfer_from(643				origin2.clone(),644				account(1),645				account(2),646				CollectionId(1),647				TokenId(1),648				1649			)650			.map_err(|e| e.error),651			CommonError::<Test>::ApprovedValueTooLow652		);653654		// do approve655		assert_ok!(TemplateModule::approve(656			origin1,657			account(2),658			CollectionId(1),659			TokenId(1),660			1661		));662		assert_eq!(663			<pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),664			account(2)665		);666667		assert_ok!(TemplateModule::transfer_from(668			origin2,669			account(1),670			account(3),671			CollectionId(1),672			TokenId(1),673			1674		));675		assert!(676			<pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).is_none()677		);678	});679}680681#[test]682fn nft_approve_and_transfer_from_allow_list() {683	new_test_ext().execute_with(|| {684		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));685686		let origin1 = Origin::signed(1);687		let origin2 = Origin::signed(2);688689		// Create NFT 1 for account 1690		let data = default_nft_data();691		create_test_item(collection_id, &data.clone().into());692		assert_eq!(693			&<pallet_nonfungible::TokenData<Test>>::get((collection_id, TokenId(1)))694				.unwrap()695				.const_data,696			&data.const_data.into_inner()697		);698		assert_eq!(699			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),700			1701		);702		assert_eq!(703			<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),704			true705		);706707		// Allow allow-list users to mint and add accounts 1, 2, and 3 to allow-list708		assert_ok!(TemplateModule::set_mint_permission(709			origin1.clone(),710			CollectionId(1),711			true712		));713		assert_ok!(TemplateModule::set_public_access_mode(714			origin1.clone(),715			CollectionId(1),716			AccessMode::AllowList717		));718		assert_ok!(TemplateModule::add_to_allow_list(719			origin1.clone(),720			CollectionId(1),721			account(1)722		));723		assert_ok!(TemplateModule::add_to_allow_list(724			origin1.clone(),725			CollectionId(1),726			account(2)727		));728		assert_ok!(TemplateModule::add_to_allow_list(729			origin1.clone(),730			CollectionId(1),731			account(3)732		));733734		// Account 1 approves account 2 for NFT 1735		assert_ok!(TemplateModule::approve(736			origin1.clone(),737			account(2),738			CollectionId(1),739			TokenId(1),740			1741		));742		assert_eq!(743			<pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),744			account(2)745		);746747		// Account 2 transfers NFT 1 from account 1 to account 3748		assert_ok!(TemplateModule::transfer_from(749			origin2,750			account(1),751			account(3),752			CollectionId(1),753			TokenId(1),754			1755		));756		assert!(757			<pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).is_none()758		);759	});760}761762#[test]763fn refungible_approve_and_transfer_from() {764	new_test_ext().execute_with(|| {765		let collection_id = create_test_collection(&CollectionMode::ReFungible, CollectionId(1));766767		let origin1 = Origin::signed(1);768		let origin2 = Origin::signed(2);769770		// Create RFT 1 in 1023 pieces for account 1771		let data = default_re_fungible_data();772		create_test_item(collection_id, &data.into());773774		assert_eq!(775			<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))),776			1777		);778		assert_eq!(779			<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1))),780			1023781		);782		assert_eq!(783			<pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),784			true785		);786787		// Allow public minting, enable allow-list and add accounts 1, 2, 3 to allow-list788		assert_ok!(TemplateModule::set_mint_permission(789			origin1.clone(),790			CollectionId(1),791			true792		));793		assert_ok!(TemplateModule::set_public_access_mode(794			origin1.clone(),795			CollectionId(1),796			AccessMode::AllowList797		));798		assert_ok!(TemplateModule::add_to_allow_list(799			origin1.clone(),800			CollectionId(1),801			account(1)802		));803		assert_ok!(TemplateModule::add_to_allow_list(804			origin1.clone(),805			CollectionId(1),806			account(2)807		));808		assert_ok!(TemplateModule::add_to_allow_list(809			origin1.clone(),810			CollectionId(1),811			account(3)812		));813814		// Account 1 approves account 2 for 1023 pieces of RFT 1815		assert_ok!(TemplateModule::approve(816			origin1,817			account(2),818			CollectionId(1),819			TokenId(1),820			1023821		));822		assert_eq!(823			<pallet_refungible::Allowance<Test>>::get((824				CollectionId(1),825				TokenId(1),826				account(1),827				account(2)828			)),829			1023830		);831832		// Account 2 transfers 100 pieces of RFT 1 from account 1 to account 3833		assert_ok!(TemplateModule::transfer_from(834			origin2,835			account(1),836			account(3),837			CollectionId(1),838			TokenId(1),839			100840		));841		assert_eq!(842			<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))),843			1844		);845		assert_eq!(846			<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(3))),847			1848		);849		assert_eq!(850			<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1))),851			923852		);853		assert_eq!(854			<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(3))),855			100856		);857		assert_eq!(858			<pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),859			true860		);861		assert_eq!(862			<pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),863			true864		);865		assert_eq!(866			<pallet_refungible::Allowance<Test>>::get((867				CollectionId(1),868				TokenId(1),869				account(1),870				account(2)871			)),872			923873		);874	});875}876877#[test]878fn fungible_approve_and_transfer_from() {879	new_test_ext().execute_with(|| {880		let collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));881882		let data = default_fungible_data();883		create_test_item(collection_id, &data.into());884885		let origin1 = Origin::signed(1);886		let origin2 = Origin::signed(2);887888		assert_ok!(TemplateModule::set_mint_permission(889			origin1.clone(),890			CollectionId(1),891			true892		));893		assert_ok!(TemplateModule::set_public_access_mode(894			origin1.clone(),895			CollectionId(1),896			AccessMode::AllowList897		));898		assert_ok!(TemplateModule::add_to_allow_list(899			origin1.clone(),900			CollectionId(1),901			account(1)902		));903		assert_ok!(TemplateModule::add_to_allow_list(904			origin1.clone(),905			CollectionId(1),906			account(2)907		));908		assert_ok!(TemplateModule::add_to_allow_list(909			origin1.clone(),910			CollectionId(1),911			account(3)912		));913914		// do approve915		assert_ok!(TemplateModule::approve(916			origin1.clone(),917			account(2),918			CollectionId(1),919			TokenId(0),920			5921		));922		assert_eq!(923			<pallet_fungible::Allowance<Test>>::get((CollectionId(1), account(1), account(2))),924			5925		);926		assert_ok!(TemplateModule::approve(927			origin1,928			account(3),929			CollectionId(1),930			TokenId(0),931			5932		));933		assert_eq!(934			<pallet_fungible::Allowance<Test>>::get((CollectionId(1), account(1), account(2))),935			5936		);937		assert_eq!(938			<pallet_fungible::Allowance<Test>>::get((CollectionId(1), account(1), account(3))),939			5940		);941942		assert_ok!(TemplateModule::transfer_from(943			origin2.clone(),944			account(1),945			account(3),946			CollectionId(1),947			TokenId(0),948			4949		));950951		assert_eq!(952			<pallet_fungible::Allowance<Test>>::get((CollectionId(1), account(1), account(2))),953			1954		);955956		assert_noop!(957			TemplateModule::transfer_from(958				origin2,959				account(1),960				account(3),961				CollectionId(1),962				TokenId(0),963				4964			)965			.map_err(|e| e.error),966			CommonError::<Test>::ApprovedValueTooLow967		);968	});969}970971#[test]972fn change_collection_owner() {973	new_test_ext().execute_with(|| {974		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));975976		let origin1 = Origin::signed(1);977		assert_ok!(TemplateModule::change_collection_owner(978			origin1,979			collection_id,980			2981		));982		assert_eq!(983			<pallet_common::CollectionById<Test>>::get(collection_id)984				.unwrap()985				.owner,986			2987		);988	});989}990991#[test]992fn destroy_collection() {993	new_test_ext().execute_with(|| {994		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));995996		let origin1 = Origin::signed(1);997		assert_ok!(TemplateModule::destroy_collection(origin1, collection_id));998	});999}10001001#[test]1002fn burn_nft_item() {1003	new_test_ext().execute_with(|| {1004		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));10051006		let origin1 = Origin::signed(1);10071008		let data = default_nft_data();1009		create_test_item(collection_id, &data.into());10101011		// check balance (collection with id = 1, user id = 1)1012		assert_eq!(1013			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),1014			11015		);10161017		// burn item1018		assert_ok!(TemplateModule::burn_item(1019			origin1.clone(),1020			collection_id,1021			TokenId(1),1022			11023		));1024		assert_eq!(1025			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),1026			01027		);1028	});1029}10301031#[test]1032fn burn_same_nft_item_twice() {1033	new_test_ext().execute_with(|| {1034		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));10351036		let origin1 = Origin::signed(1);10371038		let data = default_nft_data();1039		create_test_item(collection_id, &data.into());10401041		// check balance (collection with id = 1, user id = 1)1042		assert_eq!(1043			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),1044			11045		);10461047		// burn item1048		assert_ok!(TemplateModule::burn_item(1049			origin1.clone(),1050			collection_id,1051			TokenId(1),1052			11053		));10541055		// burn item again1056		assert_noop!(1057			TemplateModule::burn_item(origin1, collection_id, TokenId(1), 1).map_err(|e| e.error),1058			CommonError::<Test>::TokenNotFound1059		);10601061		assert_eq!(1062			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),1063			01064		);1065	});1066}10671068#[test]1069fn burn_fungible_item() {1070	new_test_ext().execute_with(|| {1071		let collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));10721073		let origin1 = Origin::signed(1);1074		assert_ok!(TemplateModule::add_collection_admin(1075			origin1.clone(),1076			collection_id,1077			account(2)1078		));10791080		let data = default_fungible_data();1081		create_test_item(collection_id, &data.into());10821083		// check balance (collection with id = 1, user id = 1)1084		assert_eq!(1085			<pallet_fungible::Balance<Test>>::get((collection_id, account(1))),1086			51087		);10881089		// burn item1090		assert_ok!(TemplateModule::burn_item(1091			origin1.clone(),1092			CollectionId(1),1093			TokenId(0),1094			51095		));1096		assert_noop!(1097			TemplateModule::burn_item(origin1, CollectionId(1), TokenId(0), 5).map_err(|e| e.error),1098			CommonError::<Test>::TokenValueTooLow1099		);11001101		assert_eq!(1102			<pallet_fungible::Balance<Test>>::get((collection_id, account(1))),1103			01104		);1105	});1106}11071108#[test]1109fn burn_fungible_item_with_token_id() {1110	new_test_ext().execute_with(|| {1111		let collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));11121113		let origin1 = Origin::signed(1);1114		assert_ok!(TemplateModule::add_collection_admin(1115			origin1.clone(),1116			collection_id,1117			account(2)1118		));11191120		let data = default_fungible_data();1121		create_test_item(collection_id, &data.into());11221123		// check balance (collection with id = 1, user id = 1)1124		assert_eq!(1125			<pallet_fungible::Balance<Test>>::get((collection_id, account(1))),1126			51127		);11281129		// Try to burn item using Token ID1130		assert_noop!(1131			TemplateModule::burn_item(origin1, CollectionId(1), TokenId(1), 5).map_err(|e| e.error),1132			<pallet_fungible::Error::<Test>>::FungibleItemsHaveNoId1133		);1134	});1135}1136#[test]1137fn burn_refungible_item() {1138	new_test_ext().execute_with(|| {1139		let collection_id = create_test_collection(&CollectionMode::ReFungible, CollectionId(1));1140		let origin1 = Origin::signed(1);11411142		assert_ok!(TemplateModule::set_mint_permission(1143			origin1.clone(),1144			collection_id,1145			true1146		));1147		assert_ok!(TemplateModule::set_public_access_mode(1148			origin1.clone(),1149			collection_id,1150			AccessMode::AllowList1151		));1152		assert_ok!(TemplateModule::add_to_allow_list(1153			origin1.clone(),1154			collection_id,1155			account(1)1156		));11571158		assert_ok!(TemplateModule::add_collection_admin(1159			origin1.clone(),1160			collection_id,1161			account(2)1162		));11631164		let data = default_re_fungible_data();1165		create_test_item(collection_id, &data.into());11661167		// check balance (collection with id = 1, user id = 2)1168		assert_eq!(1169			<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))),1170			11171		);1172		assert_eq!(1173			<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1))),1174			10231175		);11761177		// burn item1178		assert_ok!(TemplateModule::burn_item(1179			origin1.clone(),1180			collection_id,1181			TokenId(1),1182			10231183		));1184		assert_noop!(1185			TemplateModule::burn_item(origin1, collection_id, TokenId(1), 1023)1186				.map_err(|e| e.error),1187			CommonError::<Test>::TokenValueTooLow1188		);11891190		assert_eq!(1191			<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1))),1192			01193		);1194	});1195}11961197#[test]1198fn add_collection_admin() {1199	new_test_ext().execute_with(|| {1200		let collection1_id =1201			create_test_collection_for_owner(&CollectionMode::NFT, 1, CollectionId(1));1202		let origin1 = Origin::signed(1);12031204		// Add collection admins1205		assert_ok!(TemplateModule::add_collection_admin(1206			origin1.clone(),1207			collection1_id,1208			account(2)1209		));1210		assert_ok!(TemplateModule::add_collection_admin(1211			origin1,1212			collection1_id,1213			account(3)1214		));12151216		// Owner is not an admin by default1217		assert_eq!(1218			<pallet_common::IsAdmin<Test>>::get((CollectionId(1), account(1))),1219			false1220		);1221		assert!(<pallet_common::IsAdmin<Test>>::get((1222			CollectionId(1),1223			account(2)1224		)));1225		assert!(<pallet_common::IsAdmin<Test>>::get((1226			CollectionId(1),1227			account(3)1228		)));1229	});1230}12311232#[test]1233fn remove_collection_admin() {1234	new_test_ext().execute_with(|| {1235		let collection1_id =1236			create_test_collection_for_owner(&CollectionMode::NFT, 1, CollectionId(1));1237		let origin1 = Origin::signed(1);1238		let origin2 = Origin::signed(2);12391240		// Add collection admins 2 and 31241		assert_ok!(TemplateModule::add_collection_admin(1242			origin1.clone(),1243			collection1_id,1244			account(2)1245		));1246		assert_ok!(TemplateModule::add_collection_admin(1247			origin1,1248			collection1_id,1249			account(3)1250		));12511252		assert!(<pallet_common::IsAdmin<Test>>::get((1253			CollectionId(1),1254			account(2)1255		)));1256		assert!(<pallet_common::IsAdmin<Test>>::get((1257			CollectionId(1),1258			account(3)1259		)));12601261		// remove admin 31262		assert_ok!(TemplateModule::remove_collection_admin(1263			origin2,1264			CollectionId(1),1265			account(3)1266		));12671268		// 2 is still admin, 3 is not an admin anymore1269		assert!(<pallet_common::IsAdmin<Test>>::get((1270			CollectionId(1),1271			account(2)1272		)));1273		assert_eq!(1274			<pallet_common::IsAdmin<Test>>::get((CollectionId(1), account(3))),1275			false1276		);1277	});1278}12791280#[test]1281fn balance_of() {1282	new_test_ext().execute_with(|| {1283		let nft_collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1284		let fungible_collection_id =1285			create_test_collection(&CollectionMode::Fungible(3), CollectionId(2));1286		let re_fungible_collection_id =1287			create_test_collection(&CollectionMode::ReFungible, CollectionId(3));12881289		// check balance before1290		assert_eq!(1291			<pallet_nonfungible::AccountBalance<Test>>::get((nft_collection_id, account(1))),1292			01293		);1294		assert_eq!(1295			<pallet_fungible::Balance<Test>>::get((fungible_collection_id, account(1))),1296			01297		);1298		assert_eq!(1299			<pallet_refungible::AccountBalance<Test>>::get((re_fungible_collection_id, account(1))),1300			01301		);13021303		let nft_data = default_nft_data();1304		create_test_item(nft_collection_id, &nft_data.into());13051306		let fungible_data = default_fungible_data();1307		create_test_item(fungible_collection_id, &fungible_data.into());13081309		let re_fungible_data = default_re_fungible_data();1310		create_test_item(re_fungible_collection_id, &re_fungible_data.into());13111312		// check balance (collection with id = 1, user id = 1)1313		assert_eq!(1314			<pallet_nonfungible::AccountBalance<Test>>::get((nft_collection_id, account(1))),1315			11316		);1317		assert_eq!(1318			<pallet_fungible::Balance<Test>>::get((fungible_collection_id, account(1))),1319			51320		);1321		assert_eq!(1322			<pallet_refungible::AccountBalance<Test>>::get((re_fungible_collection_id, account(1))),1323			11324		);13251326		assert_eq!(1327			<pallet_nonfungible::Owned<Test>>::get((nft_collection_id, account(1), TokenId(1))),1328			true1329		);1330		assert_eq!(1331			<pallet_refungible::Owned<Test>>::get((1332				re_fungible_collection_id,1333				account(1),1334				TokenId(1)1335			)),1336			true1337		);1338	});1339}13401341#[test]1342fn approve() {1343	new_test_ext().execute_with(|| {1344		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));13451346		let data = default_nft_data();1347		create_test_item(collection_id, &data.into());13481349		let origin1 = Origin::signed(1);13501351		// approve1352		assert_ok!(TemplateModule::approve(1353			origin1,1354			account(2),1355			CollectionId(1),1356			TokenId(1),1357			11358		));1359		assert_eq!(1360			<pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),1361			account(2)1362		);1363	});1364}13651366#[test]1367fn transfer_from() {1368	new_test_ext().execute_with(|| {1369		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1370		let origin1 = Origin::signed(1);1371		let origin2 = Origin::signed(2);13721373		let data = default_nft_data();1374		create_test_item(collection_id, &data.into());13751376		// approve1377		assert_ok!(TemplateModule::approve(1378			origin1.clone(),1379			account(2),1380			CollectionId(1),1381			TokenId(1),1382			11383		));1384		assert_eq!(1385			<pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),1386			account(2)1387		);13881389		assert_ok!(TemplateModule::set_mint_permission(1390			origin1.clone(),1391			CollectionId(1),1392			true1393		));1394		assert_ok!(TemplateModule::set_public_access_mode(1395			origin1.clone(),1396			CollectionId(1),1397			AccessMode::AllowList1398		));1399		assert_ok!(TemplateModule::add_to_allow_list(1400			origin1.clone(),1401			CollectionId(1),1402			account(1)1403		));1404		assert_ok!(TemplateModule::add_to_allow_list(1405			origin1.clone(),1406			CollectionId(1),1407			account(2)1408		));1409		assert_ok!(TemplateModule::add_to_allow_list(1410			origin1,1411			CollectionId(1),1412			account(3)1413		));14141415		assert_ok!(TemplateModule::transfer_from(1416			origin2,1417			account(1),1418			account(2),1419			CollectionId(1),1420			TokenId(1),1421			11422		));14231424		// after transfer1425		assert_eq!(1426			<pallet_nonfungible::AccountBalance<Test>>::get((CollectionId(1), account(1))),1427			01428		);1429		assert_eq!(1430			<pallet_nonfungible::AccountBalance<Test>>::get((CollectionId(1), account(2))),1431			11432		);1433	});1434}14351436// #endregion14371438// Coverage tests region1439// #region14401441#[test]1442fn owner_can_add_address_to_allow_list() {1443	new_test_ext().execute_with(|| {1444		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));14451446		let origin1 = Origin::signed(1);1447		assert_ok!(TemplateModule::add_to_allow_list(1448			origin1,1449			collection_id,1450			account(2)1451		));1452		assert!(<pallet_common::Allowlist<Test>>::get((1453			collection_id,1454			account(2)1455		)));1456	});1457}14581459#[test]1460fn admin_can_add_address_to_allow_list() {1461	new_test_ext().execute_with(|| {1462		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1463		let origin1 = Origin::signed(1);1464		let origin2 = Origin::signed(2);14651466		assert_ok!(TemplateModule::add_collection_admin(1467			origin1,1468			collection_id,1469			account(2)1470		));1471		assert_ok!(TemplateModule::add_to_allow_list(1472			origin2,1473			collection_id,1474			account(3)1475		));1476		assert!(<pallet_common::Allowlist<Test>>::get((1477			collection_id,1478			account(3)1479		)));1480	});1481}14821483#[test]1484fn nonprivileged_user_cannot_add_address_to_allow_list() {1485	new_test_ext().execute_with(|| {1486		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));14871488		let origin2 = Origin::signed(2);1489		assert_noop!(1490			TemplateModule::add_to_allow_list(origin2, collection_id, account(3)),1491			CommonError::<Test>::NoPermission1492		);1493	});1494}14951496#[test]1497fn nobody_can_add_address_to_allow_list_of_nonexisting_collection() {1498	new_test_ext().execute_with(|| {1499		let origin1 = Origin::signed(1);15001501		assert_noop!(1502			TemplateModule::add_to_allow_list(origin1, CollectionId(1), account(2)),1503			CommonError::<Test>::CollectionNotFound1504		);1505	});1506}15071508#[test]1509fn nobody_can_add_address_to_allow_list_of_deleted_collection() {1510	new_test_ext().execute_with(|| {1511		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));15121513		let origin1 = Origin::signed(1);1514		assert_ok!(TemplateModule::destroy_collection(1515			origin1.clone(),1516			collection_id1517		));1518		assert_noop!(1519			TemplateModule::add_to_allow_list(origin1, collection_id, account(2)),1520			CommonError::<Test>::CollectionNotFound1521		);1522	});1523}15241525// If address is already added to allow list, nothing happens1526#[test]1527fn address_is_already_added_to_allow_list() {1528	new_test_ext().execute_with(|| {1529		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1530		let origin1 = Origin::signed(1);15311532		assert_ok!(TemplateModule::add_to_allow_list(1533			origin1.clone(),1534			collection_id,1535			account(2)1536		));1537		assert_ok!(TemplateModule::add_to_allow_list(1538			origin1,1539			collection_id,1540			account(2)1541		));1542		assert!(<pallet_common::Allowlist<Test>>::get((1543			collection_id,1544			account(2)1545		)));1546	});1547}15481549#[test]1550fn owner_can_remove_address_from_allow_list() {1551	new_test_ext().execute_with(|| {1552		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));15531554		let origin1 = Origin::signed(1);1555		assert_ok!(TemplateModule::add_to_allow_list(1556			origin1.clone(),1557			collection_id,1558			account(2)1559		));1560		assert_ok!(TemplateModule::remove_from_allow_list(1561			origin1,1562			collection_id,1563			account(2)1564		));1565		assert_eq!(1566			<pallet_common::Allowlist<Test>>::get((collection_id, account(2))),1567			false1568		);1569	});1570}15711572#[test]1573fn admin_can_remove_address_from_allow_list() {1574	new_test_ext().execute_with(|| {1575		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1576		let origin1 = Origin::signed(1);1577		let origin2 = Origin::signed(2);15781579		// Owner adds admin1580		assert_ok!(TemplateModule::add_collection_admin(1581			origin1.clone(),1582			collection_id,1583			account(2)1584		));15851586		// Owner adds address 3 to allow list1587		assert_ok!(TemplateModule::add_to_allow_list(1588			origin1,1589			collection_id,1590			account(3)1591		));15921593		// Admin removes address 3 from allow list1594		assert_ok!(TemplateModule::remove_from_allow_list(1595			origin2,1596			collection_id,1597			account(3)1598		));1599		assert_eq!(1600			<pallet_common::Allowlist<Test>>::get((collection_id, account(3))),1601			false1602		);1603	});1604}16051606#[test]1607fn nonprivileged_user_cannot_remove_address_from_allow_list() {1608	new_test_ext().execute_with(|| {1609		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1610		let origin1 = Origin::signed(1);1611		let origin2 = Origin::signed(2);16121613		assert_ok!(TemplateModule::add_to_allow_list(1614			origin1,1615			collection_id,1616			account(2)1617		));1618		assert_noop!(1619			TemplateModule::remove_from_allow_list(origin2, collection_id, account(2)),1620			CommonError::<Test>::NoPermission1621		);1622		assert!(<pallet_common::Allowlist<Test>>::get((1623			collection_id,1624			account(2)1625		)));1626	});1627}16281629#[test]1630fn nobody_can_remove_address_from_allow_list_of_nonexisting_collection() {1631	new_test_ext().execute_with(|| {1632		let origin1 = Origin::signed(1);16331634		assert_noop!(1635			TemplateModule::remove_from_allow_list(origin1, CollectionId(1), account(2)),1636			CommonError::<Test>::CollectionNotFound1637		);1638	});1639}16401641#[test]1642fn nobody_can_remove_address_from_allow_list_of_deleted_collection() {1643	new_test_ext().execute_with(|| {1644		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1645		let origin1 = Origin::signed(1);1646		let origin2 = Origin::signed(2);16471648		// Add account 2 to allow list1649		assert_ok!(TemplateModule::add_to_allow_list(1650			origin1.clone(),1651			collection_id,1652			account(2)1653		));16541655		// Account 2 is in collection allow-list1656		assert!(<pallet_common::Allowlist<Test>>::get((1657			collection_id,1658			account(2)1659		)));16601661		// Destroy collection1662		assert_ok!(TemplateModule::destroy_collection(origin1, collection_id));16631664		// Attempt to remove account 2 from collection allow-list => error1665		assert_noop!(1666			TemplateModule::remove_from_allow_list(origin2, collection_id, account(2)),1667			CommonError::<Test>::CollectionNotFound1668		);16691670		// Account 2 is not found in collection allow-list anyway1671		assert_eq!(1672			<pallet_common::Allowlist<Test>>::get((collection_id, account(2))),1673			false1674		);1675	});1676}16771678// If address is already removed from allow list, nothing happens1679#[test]1680fn address_is_already_removed_from_allow_list() {1681	new_test_ext().execute_with(|| {1682		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1683		let origin1 = Origin::signed(1);16841685		assert_ok!(TemplateModule::add_to_allow_list(1686			origin1.clone(),1687			collection_id,1688			account(2)1689		));1690		assert_ok!(TemplateModule::remove_from_allow_list(1691			origin1.clone(),1692			collection_id,1693			account(2)1694		));1695		assert_eq!(1696			<pallet_common::Allowlist<Test>>::get((collection_id, account(2))),1697			false1698		);1699		assert_ok!(TemplateModule::remove_from_allow_list(1700			origin1,1701			collection_id,1702			account(2)1703		));1704		assert_eq!(1705			<pallet_common::Allowlist<Test>>::get((collection_id, account(2))),1706			false1707		);1708	});1709}17101711// If Public Access mode is set to AllowList, tokens can’t be transferred from a non-allowlisted address with transfer or transferFrom (2 tests)1712#[test]1713fn allow_list_test_1() {1714	new_test_ext().execute_with(|| {1715		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));17161717		let origin1 = Origin::signed(1);17181719		let data = default_nft_data();1720		create_test_item(collection_id, &data.into());17211722		assert_ok!(TemplateModule::set_public_access_mode(1723			origin1.clone(),1724			collection_id,1725			AccessMode::AllowList1726		));1727		assert_ok!(TemplateModule::add_to_allow_list(1728			origin1.clone(),1729			collection_id,1730			account(2)1731		));17321733		assert_noop!(1734			TemplateModule::transfer(origin1, account(3), CollectionId(1), TokenId(1), 1)1735				.map_err(|e| e.error),1736			CommonError::<Test>::AddressNotInAllowlist1737		);1738	});1739}17401741#[test]1742fn allow_list_test_2() {1743	new_test_ext().execute_with(|| {1744		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1745		let origin1 = Origin::signed(1);17461747		let data = default_nft_data();1748		create_test_item(collection_id, &data.into());17491750		assert_ok!(TemplateModule::set_public_access_mode(1751			origin1.clone(),1752			collection_id,1753			AccessMode::AllowList1754		));1755		assert_ok!(TemplateModule::add_to_allow_list(1756			origin1.clone(),1757			collection_id,1758			account(1)1759		));1760		assert_ok!(TemplateModule::add_to_allow_list(1761			origin1.clone(),1762			collection_id,1763			account(2)1764		));17651766		// do approve1767		assert_ok!(TemplateModule::approve(1768			origin1.clone(),1769			account(1),1770			collection_id,1771			TokenId(1),1772			11773		));1774		assert_eq!(1775			<pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),1776			account(1)1777		);17781779		assert_ok!(TemplateModule::remove_from_allow_list(1780			origin1.clone(),1781			collection_id,1782			account(1)1783		));17841785		assert_noop!(1786			TemplateModule::transfer_from(1787				origin1,1788				account(1),1789				account(3),1790				CollectionId(1),1791				TokenId(1),1792				11793			)1794			.map_err(|e| e.error),1795			CommonError::<Test>::AddressNotInAllowlist1796		);1797	});1798}17991800// If Public Access mode is set to AllowList, tokens can’t be transferred to a non-allowlisted address with transfer or transferFrom (2 tests)1801#[test]1802fn allow_list_test_3() {1803	new_test_ext().execute_with(|| {1804		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));18051806		let origin1 = Origin::signed(1);18071808		let data = default_nft_data();1809		create_test_item(collection_id, &data.into());18101811		assert_ok!(TemplateModule::set_public_access_mode(1812			origin1.clone(),1813			collection_id,1814			AccessMode::AllowList1815		));1816		assert_ok!(TemplateModule::add_to_allow_list(1817			origin1.clone(),1818			collection_id,1819			account(1)1820		));18211822		assert_noop!(1823			TemplateModule::transfer(origin1, account(3), collection_id, TokenId(1), 1)1824				.map_err(|e| e.error),1825			CommonError::<Test>::AddressNotInAllowlist1826		);1827	});1828}18291830#[test]1831fn allow_list_test_4() {1832	new_test_ext().execute_with(|| {1833		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));18341835		let origin1 = Origin::signed(1);18361837		let data = default_nft_data();1838		create_test_item(collection_id, &data.into());18391840		assert_ok!(TemplateModule::set_public_access_mode(1841			origin1.clone(),1842			collection_id,1843			AccessMode::AllowList1844		));1845		assert_ok!(TemplateModule::add_to_allow_list(1846			origin1.clone(),1847			collection_id,1848			account(1)1849		));1850		assert_ok!(TemplateModule::add_to_allow_list(1851			origin1.clone(),1852			collection_id,1853			account(2)1854		));18551856		// do approve1857		assert_ok!(TemplateModule::approve(1858			origin1.clone(),1859			account(1),1860			collection_id,1861			TokenId(1),1862			11863		));1864		assert_eq!(1865			<pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),1866			account(1)1867		);18681869		assert_ok!(TemplateModule::remove_from_allow_list(1870			origin1.clone(),1871			collection_id,1872			account(2)1873		));18741875		assert_noop!(1876			TemplateModule::transfer_from(1877				origin1,1878				account(1),1879				account(3),1880				collection_id,1881				TokenId(1),1882				11883			)1884			.map_err(|e| e.error),1885			CommonError::<Test>::AddressNotInAllowlist1886		);1887	});1888}18891890// 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)1891#[test]1892fn allow_list_test_5() {1893	new_test_ext().execute_with(|| {1894		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));18951896		let origin1 = Origin::signed(1);18971898		let data = default_nft_data();1899		create_test_item(collection_id, &data.into());19001901		assert_ok!(TemplateModule::set_public_access_mode(1902			origin1.clone(),1903			collection_id,1904			AccessMode::AllowList1905		));1906		assert_noop!(1907			TemplateModule::burn_item(origin1.clone(), CollectionId(1), TokenId(1), 1)1908				.map_err(|e| e.error),1909			CommonError::<Test>::AddressNotInAllowlist1910		);1911	});1912}19131914// If Public Access mode is set to AllowList, token transfers can’t be Approved by a non-allowlisted address (see Approve method).1915#[test]1916fn allow_list_test_6() {1917	new_test_ext().execute_with(|| {1918		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));19191920		let origin1 = Origin::signed(1);19211922		let data = default_nft_data();1923		create_test_item(collection_id, &data.into());19241925		assert_ok!(TemplateModule::set_public_access_mode(1926			origin1.clone(),1927			collection_id,1928			AccessMode::AllowList1929		));19301931		// do approve1932		assert_noop!(1933			TemplateModule::approve(origin1, account(1), CollectionId(1), TokenId(1), 1)1934				.map_err(|e| e.error),1935			CommonError::<Test>::AddressNotInAllowlist1936		);1937	});1938}19391940// If Public Access mode is set to AllowList, tokens can be transferred from a allowlisted address with transfer or transferFrom (2 tests) and1941//          tokens can be transferred from a allowlisted address with transfer or transferFrom (2 tests)1942#[test]1943fn allow_list_test_7() {1944	new_test_ext().execute_with(|| {1945		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));19461947		let data = default_nft_data();1948		create_test_item(collection_id, &data.into());19491950		let origin1 = Origin::signed(1);19511952		assert_ok!(TemplateModule::set_public_access_mode(1953			origin1.clone(),1954			collection_id,1955			AccessMode::AllowList1956		));1957		assert_ok!(TemplateModule::add_to_allow_list(1958			origin1.clone(),1959			collection_id,1960			account(1)1961		));1962		assert_ok!(TemplateModule::add_to_allow_list(1963			origin1.clone(),1964			collection_id,1965			account(2)1966		));19671968		assert_ok!(TemplateModule::transfer(1969			origin1,1970			account(2),1971			CollectionId(1),1972			TokenId(1),1973			11974		));1975	});1976}19771978#[test]1979fn allow_list_test_8() {1980	new_test_ext().execute_with(|| {1981		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));19821983		// Create NFT for account 11984		let data = default_nft_data();1985		create_test_item(collection_id, &data.into());19861987		let origin1 = Origin::signed(1);19881989		// Toggle Allow List mode and add accounts 1 and 21990		assert_ok!(TemplateModule::set_public_access_mode(1991			origin1.clone(),1992			collection_id,1993			AccessMode::AllowList1994		));1995		assert_ok!(TemplateModule::add_to_allow_list(1996			origin1.clone(),1997			collection_id,1998			account(1)1999		));2000		assert_ok!(TemplateModule::add_to_allow_list(2001			origin1.clone(),2002			collection_id,2003			account(2)2004		));20052006		// Sself-approve account 1 for NFT 12007		assert_ok!(TemplateModule::approve(2008			origin1.clone(),2009			account(1),2010			CollectionId(1),2011			TokenId(1),2012			12013		));2014		assert_eq!(2015			<pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),2016			account(1)2017		);20182019		// Transfer from 1 to 22020		assert_ok!(TemplateModule::transfer_from(2021			origin1,2022			account(1),2023			account(2),2024			CollectionId(1),2025			TokenId(1),2026			12027		));2028	});2029}20302031// If Public Access mode is set to AllowList, and Mint Permission is set to false, tokens can be created by owner.2032#[test]2033fn allow_list_test_9() {2034	new_test_ext().execute_with(|| {2035		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));2036		let origin1 = Origin::signed(1);20372038		assert_ok!(TemplateModule::set_public_access_mode(2039			origin1.clone(),2040			collection_id,2041			AccessMode::AllowList2042		));2043		assert_ok!(TemplateModule::set_mint_permission(2044			origin1,2045			collection_id,2046			false2047		));20482049		let data = default_nft_data();2050		create_test_item(collection_id, &data.into());2051	});2052}20532054// If Public Access mode is set to AllowList, and Mint Permission is set to false, tokens can be created by admin.2055#[test]2056fn allow_list_test_10() {2057	new_test_ext().execute_with(|| {2058		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));20592060		let origin1 = Origin::signed(1);2061		let origin2 = Origin::signed(2);20622063		assert_ok!(TemplateModule::set_public_access_mode(2064			origin1.clone(),2065			collection_id,2066			AccessMode::AllowList2067		));2068		assert_ok!(TemplateModule::set_mint_permission(2069			origin1.clone(),2070			collection_id,2071			false2072		));20732074		assert_ok!(TemplateModule::add_collection_admin(2075			origin1,2076			collection_id,2077			account(2)2078		));20792080		assert_ok!(TemplateModule::create_item(2081			origin2,2082			collection_id,2083			account(2),2084			default_nft_data().into()2085		));2086	});2087}20882089// 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.2090#[test]2091fn allow_list_test_11() {2092	new_test_ext().execute_with(|| {2093		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));20942095		let origin1 = Origin::signed(1);2096		let origin2 = Origin::signed(2);20972098		assert_ok!(TemplateModule::set_public_access_mode(2099			origin1.clone(),2100			collection_id,2101			AccessMode::AllowList2102		));2103		assert_ok!(TemplateModule::set_mint_permission(2104			origin1.clone(),2105			collection_id,2106			false2107		));2108		assert_ok!(TemplateModule::add_to_allow_list(2109			origin1,2110			collection_id,2111			account(2)2112		));21132114		assert_noop!(2115			TemplateModule::create_item(2116				origin2,2117				CollectionId(1),2118				account(2),2119				default_nft_data().into()2120			)2121			.map_err(|e| e.error),2122			CommonError::<Test>::PublicMintingNotAllowed2123		);2124	});2125}21262127// 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.2128#[test]2129fn allow_list_test_12() {2130	new_test_ext().execute_with(|| {2131		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));21322133		let origin1 = Origin::signed(1);2134		let origin2 = Origin::signed(2);21352136		assert_ok!(TemplateModule::set_public_access_mode(2137			origin1.clone(),2138			collection_id,2139			AccessMode::AllowList2140		));2141		assert_ok!(TemplateModule::set_mint_permission(2142			origin1,2143			collection_id,2144			false2145		));21462147		assert_noop!(2148			TemplateModule::create_item(2149				origin2,2150				CollectionId(1),2151				account(2),2152				default_nft_data().into()2153			)2154			.map_err(|e| e.error),2155			CommonError::<Test>::PublicMintingNotAllowed2156		);2157	});2158}21592160// If Public Access mode is set to AllowList, and Mint Permission is set to true, tokens can be created by owner.2161#[test]2162fn allow_list_test_13() {2163	new_test_ext().execute_with(|| {2164		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));21652166		let origin1 = Origin::signed(1);21672168		assert_ok!(TemplateModule::set_public_access_mode(2169			origin1.clone(),2170			collection_id,2171			AccessMode::AllowList2172		));2173		assert_ok!(TemplateModule::set_mint_permission(2174			origin1,2175			collection_id,2176			true2177		));21782179		let data = default_nft_data();2180		create_test_item(collection_id, &data.into());2181	});2182}21832184// If Public Access mode is set to AllowList, and Mint Permission is set to true, tokens can be created by admin.2185#[test]2186fn allow_list_test_14() {2187	new_test_ext().execute_with(|| {2188		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));21892190		let origin1 = Origin::signed(1);2191		let origin2 = Origin::signed(2);21922193		assert_ok!(TemplateModule::set_public_access_mode(2194			origin1.clone(),2195			collection_id,2196			AccessMode::AllowList2197		));2198		assert_ok!(TemplateModule::set_mint_permission(2199			origin1.clone(),2200			collection_id,2201			true2202		));22032204		assert_ok!(TemplateModule::add_collection_admin(2205			origin1,2206			collection_id,2207			account(2)2208		));22092210		assert_ok!(TemplateModule::create_item(2211			origin2,2212			collection_id,2213			account(2),2214			default_nft_data().into()2215		));2216	});2217}22182219// 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.2220#[test]2221fn allow_list_test_15() {2222	new_test_ext().execute_with(|| {2223		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));22242225		let origin1 = Origin::signed(1);2226		let origin2 = Origin::signed(2);22272228		assert_ok!(TemplateModule::set_public_access_mode(2229			origin1.clone(),2230			collection_id,2231			AccessMode::AllowList2232		));2233		assert_ok!(TemplateModule::set_mint_permission(2234			origin1,2235			collection_id,2236			true2237		));22382239		assert_noop!(2240			TemplateModule::create_item(2241				origin2,2242				collection_id,2243				account(2),2244				default_nft_data().into()2245			)2246			.map_err(|e| e.error),2247			CommonError::<Test>::AddressNotInAllowlist2248		);2249	});2250}22512252// 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.2253#[test]2254fn allow_list_test_16() {2255	new_test_ext().execute_with(|| {2256		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));22572258		let origin1 = Origin::signed(1);2259		let origin2 = Origin::signed(2);22602261		assert_ok!(TemplateModule::set_public_access_mode(2262			origin1.clone(),2263			collection_id,2264			AccessMode::AllowList2265		));2266		assert_ok!(TemplateModule::set_mint_permission(2267			origin1.clone(),2268			collection_id,2269			true2270		));2271		assert_ok!(TemplateModule::add_to_allow_list(2272			origin1,2273			collection_id,2274			account(2)2275		));22762277		assert_ok!(TemplateModule::create_item(2278			origin2,2279			collection_id,2280			account(2),2281			default_nft_data().into()2282		));2283	});2284}22852286// Total number of collections. Positive test2287#[test]2288fn total_number_collections_bound() {2289	new_test_ext().execute_with(|| {2290		create_test_collection(&CollectionMode::NFT, CollectionId(1));2291	});2292}22932294#[test]2295fn create_max_collections() {2296	new_test_ext().execute_with(|| {2297		for i in 1..COLLECTION_NUMBER_LIMIT {2298			create_test_collection(&CollectionMode::NFT, CollectionId(i));2299		}2300	});2301}23022303// Total number of collections. Negative test2304#[test]2305fn total_number_collections_bound_neg() {2306	new_test_ext().execute_with(|| {2307		let origin1 = Origin::signed(1);23082309		for i in 1..=COLLECTION_NUMBER_LIMIT {2310			create_test_collection(&CollectionMode::NFT, CollectionId(i));2311		}23122313		let col_name1: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();2314		let col_desc1: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();2315		let token_prefix1: Vec<u8> = b"token_prefix1\0".to_vec();23162317		let data: CreateCollectionData<u64> = CreateCollectionData {2318			name: col_name1.try_into().unwrap(),2319			description: col_desc1.try_into().unwrap(),2320			token_prefix: token_prefix1.try_into().unwrap(),2321			mode: CollectionMode::NFT,2322			..Default::default()2323		};23242325		// 11-th collection in chain. Expects error2326		assert_noop!(2327			TemplateModule::create_collection_ex(origin1, data),2328			CommonError::<Test>::TotalCollectionsLimitExceeded2329		);2330	});2331}23322333// Owned tokens by a single address. Positive test2334#[test]2335fn owned_tokens_bound() {2336	new_test_ext().execute_with(|| {2337		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));23382339		let data = default_nft_data();2340		create_test_item(collection_id, &data.clone().into());2341		create_test_item(collection_id, &data.into());2342	});2343}23442345// Owned tokens by a single address. Negotive test2346#[test]2347fn owned_tokens_bound_neg() {2348	new_test_ext().execute_with(|| {2349		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));23502351		let origin1 = Origin::signed(1);23522353		for _ in 1..=MAX_TOKEN_OWNERSHIP {2354			let data = default_nft_data();2355			create_test_item(collection_id, &data.clone().into());2356		}23572358		let data = default_nft_data();2359		assert_noop!(2360			TemplateModule::create_item(origin1, CollectionId(1), account(1), data.into())2361				.map_err(|e| e.error),2362			CommonError::<Test>::AccountTokenLimitExceeded2363		);2364	});2365}23662367// Number of collection admins. Positive test2368#[test]2369fn collection_admins_bound() {2370	new_test_ext().execute_with(|| {2371		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));23722373		let origin1 = Origin::signed(1);23742375		assert_ok!(TemplateModule::add_collection_admin(2376			origin1.clone(),2377			collection_id,2378			account(2)2379		));2380		assert_ok!(TemplateModule::add_collection_admin(2381			origin1,2382			collection_id,2383			account(3)2384		));2385	});2386}23872388// Number of collection admins. Negotive test2389#[test]2390fn collection_admins_bound_neg() {2391	new_test_ext().execute_with(|| {2392		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));23932394		let origin1 = Origin::signed(1);23952396		for i in 0..COLLECTION_ADMINS_LIMIT {2397			assert_ok!(TemplateModule::add_collection_admin(2398				origin1.clone(),2399				collection_id,2400				account((2 + i).into())2401			));2402		}2403		assert_noop!(2404			TemplateModule::add_collection_admin(2405				origin1,2406				collection_id,2407				account((3 + COLLECTION_ADMINS_LIMIT).into())2408			),2409			CommonError::<Test>::CollectionAdminCountExceeded2410		);2411	});2412}2413// #endregion24142415#[test]2416fn set_const_on_chain_schema() {2417	new_test_ext().execute_with(|| {2418		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));24192420		let origin1 = Origin::signed(1);2421		assert_ok!(TemplateModule::set_const_on_chain_schema(2422			origin1,2423			collection_id,2424			b"test const on chain schema".to_vec().try_into().unwrap()2425		));24262427		assert_eq!(2428			<pallet_common::CollectionById<Test>>::get(collection_id)2429				.unwrap()2430				.const_on_chain_schema,2431			b"test const on chain schema".to_vec()2432		);2433		assert_eq!(2434			<pallet_common::CollectionById<Test>>::get(collection_id)2435				.unwrap()2436				.variable_on_chain_schema,2437			b"".to_vec()2438		);2439	});2440}24412442#[test]2443fn set_variable_on_chain_schema() {2444	new_test_ext().execute_with(|| {2445		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));24462447		let origin1 = Origin::signed(1);2448		assert_ok!(TemplateModule::set_variable_on_chain_schema(2449			origin1,2450			collection_id,2451			b"test variable on chain schema"2452				.to_vec()2453				.try_into()2454				.unwrap()2455		));24562457		assert_eq!(2458			<pallet_common::CollectionById<Test>>::get(collection_id)2459				.unwrap()2460				.const_on_chain_schema,2461			b"".to_vec()2462		);2463		assert_eq!(2464			<pallet_common::CollectionById<Test>>::get(collection_id)2465				.unwrap()2466				.variable_on_chain_schema,2467			b"test variable on chain schema".to_vec()2468		);2469	});2470}24712472#[test]2473fn set_variable_meta_data_on_nft_token_stores_variable_meta_data() {2474	new_test_ext().execute_with(|| {2475		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));24762477		let origin1 = Origin::signed(1);24782479		let data = default_nft_data();2480		create_test_item(CollectionId(1), &data.into());24812482		let variable_data = b"test data".to_vec();2483		assert_ok!(TemplateModule::set_variable_meta_data(2484			origin1,2485			collection_id,2486			TokenId(1),2487			variable_data.clone().try_into().unwrap()2488		));24892490		assert_eq!(2491			<pallet_nonfungible::TokenData<Test>>::get((collection_id, 1))2492				.unwrap()2493				.variable_data,2494			variable_data2495		);2496	});2497}24982499#[test]2500fn set_variable_meta_data_on_re_fungible_token_stores_variable_meta_data() {2501	new_test_ext().execute_with(|| {2502		let collection_id = create_test_collection(&CollectionMode::ReFungible, CollectionId(1));25032504		let origin1 = Origin::signed(1);25052506		let data = default_re_fungible_data();2507		create_test_item(collection_id, &data.into());25082509		let variable_data = b"test data".to_vec();2510		assert_ok!(TemplateModule::set_variable_meta_data(2511			origin1,2512			collection_id,2513			TokenId(1),2514			variable_data.clone().try_into().unwrap()2515		));25162517		assert_eq!(2518			<pallet_refungible::TokenData<Test>>::get((collection_id, TokenId(1))).variable_data,2519			variable_data2520		);2521	});2522}25232524#[test]2525fn set_variable_meta_data_on_fungible_token_fails() {2526	new_test_ext().execute_with(|| {2527		let collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));25282529		let origin1 = Origin::signed(1);25302531		let data = default_fungible_data();2532		create_test_item(collection_id, &data.into());25332534		let variable_data = b"test data".to_vec();2535		assert_noop!(2536			TemplateModule::set_variable_meta_data(2537				origin1,2538				collection_id,2539				TokenId(0),2540				variable_data.try_into().unwrap()2541			)2542			.map_err(|e| e.error),2543			<pallet_fungible::Error<Test>>::FungibleItemsDontHaveData2544		);2545	});2546}25472548#[test]2549fn set_variable_meta_data_on_nft_with_item_owner_permission_flag() {2550	new_test_ext().execute_with(|| {2551		//default_limits();25522553		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));25542555		let origin1 = Origin::signed(1);25562557		let data = default_nft_data();2558		create_test_item(collection_id, &data.into());25592560		assert_ok!(TemplateModule::set_meta_update_permission_flag(2561			origin1.clone(),2562			collection_id,2563			MetaUpdatePermission::ItemOwner,2564		));25652566		let variable_data = b"ten chars.".to_vec();2567		assert_ok!(TemplateModule::set_variable_meta_data(2568			origin1,2569			collection_id,2570			TokenId(1),2571			variable_data.clone().try_into().unwrap()2572		));25732574		assert_eq!(2575			<pallet_nonfungible::TokenData<Test>>::get((collection_id, TokenId(1)))2576				.unwrap()2577				.variable_data,2578			variable_data2579		);2580	});2581}25822583#[test]2584fn collection_transfer_flag_works() {2585	new_test_ext().execute_with(|| {2586		let origin1 = Origin::signed(1);25872588		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));2589		assert_ok!(TemplateModule::set_transfers_enabled_flag(2590			origin1,2591			collection_id,2592			true2593		));25942595		let data = default_nft_data();2596		create_test_item(collection_id, &data.into());2597		assert_eq!(2598			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),2599			12600		);2601		assert_eq!(2602			<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),2603			true2604		);26052606		let origin1 = Origin::signed(1);26072608		// default scenario2609		assert_ok!(TemplateModule::transfer(2610			origin1,2611			account(2),2612			collection_id,2613			TokenId(1),2614			12615		));2616		assert_eq!(2617			<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),2618			false2619		);2620		assert_eq!(2621			<pallet_nonfungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))),2622			true2623		);2624		assert_eq!(2625			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),2626			02627		);2628		assert_eq!(2629			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(2))),2630			12631		);2632	});2633}26342635#[test]2636fn set_variable_meta_data_on_nft_with_admin_flag() {2637	new_test_ext().execute_with(|| {2638		// default_limits();26392640		let collection_id =2641			create_test_collection_for_owner(&CollectionMode::NFT, 2, CollectionId(1));26422643		let origin1 = Origin::signed(1);2644		let origin2 = Origin::signed(2);26452646		assert_ok!(TemplateModule::set_mint_permission(2647			origin2.clone(),2648			collection_id,2649			true2650		));2651		assert_ok!(TemplateModule::add_to_allow_list(2652			origin2.clone(),2653			collection_id,2654			account(1)2655		));26562657		assert_ok!(TemplateModule::add_collection_admin(2658			origin2.clone(),2659			collection_id,2660			account(1)2661		));26622663		let data = default_nft_data();2664		create_test_item(collection_id, &data.into());26652666		assert_ok!(TemplateModule::set_meta_update_permission_flag(2667			origin2.clone(),2668			collection_id,2669			MetaUpdatePermission::Admin,2670		));26712672		let variable_data = b"test.".to_vec();2673		assert_ok!(TemplateModule::set_variable_meta_data(2674			origin1,2675			collection_id,2676			TokenId(1),2677			variable_data.clone().try_into().unwrap()2678		));26792680		assert_eq!(2681			<pallet_nonfungible::TokenData<Test>>::get((collection_id, 1))2682				.unwrap()2683				.variable_data,2684			variable_data2685		);2686	});2687}26882689#[test]2690fn set_variable_meta_data_on_nft_with_admin_flag_neg() {2691	new_test_ext().execute_with(|| {2692		// default_limits();26932694		let collection_id =2695			create_test_collection_for_owner(&CollectionMode::NFT, 2, CollectionId(1));26962697		let origin1 = Origin::signed(1);2698		let origin2 = Origin::signed(2);26992700		assert_ok!(TemplateModule::set_mint_permission(2701			origin2.clone(),2702			collection_id,2703			true2704		));2705		assert_ok!(TemplateModule::add_to_allow_list(2706			origin2.clone(),2707			collection_id,2708			account(1)2709		));27102711		let data = default_nft_data();2712		create_test_item(collection_id, &data.into());27132714		assert_ok!(TemplateModule::set_meta_update_permission_flag(2715			origin2.clone(),2716			collection_id,2717			MetaUpdatePermission::Admin,2718		));27192720		let variable_data = b"test.".to_vec();2721		assert_noop!(2722			TemplateModule::set_variable_meta_data(2723				origin1,2724				collection_id,2725				TokenId(1),2726				variable_data.try_into().unwrap()2727			)2728			.map_err(|e| e.error),2729			CommonError::<Test>::NoPermission2730		);2731	});2732}27332734#[test]2735fn set_variable_meta_flag_after_freeze() {2736	new_test_ext().execute_with(|| {2737		// default_limits();27382739		let collection_id =2740			create_test_collection_for_owner(&CollectionMode::NFT, 2, CollectionId(1));27412742		let origin2 = Origin::signed(2);27432744		assert_ok!(TemplateModule::set_meta_update_permission_flag(2745			origin2.clone(),2746			collection_id,2747			MetaUpdatePermission::None,2748		));2749		assert_noop!(2750			TemplateModule::set_meta_update_permission_flag(2751				origin2.clone(),2752				collection_id,2753				MetaUpdatePermission::Admin2754			),2755			CommonError::<Test>::MetadataFlagFrozen2756		);2757	});2758}27592760#[test]2761fn set_variable_meta_data_on_nft_with_none_flag_neg() {2762	new_test_ext().execute_with(|| {2763		// default_limits();27642765		let collection_id =2766			create_test_collection_for_owner(&CollectionMode::NFT, 1, CollectionId(1));2767		let origin1 = Origin::signed(1);27682769		let data = default_nft_data();2770		create_test_item(collection_id, &data.into());27712772		assert_ok!(TemplateModule::set_meta_update_permission_flag(2773			origin1.clone(),2774			collection_id,2775			MetaUpdatePermission::None,2776		));27772778		let variable_data = b"test.".to_vec();2779		assert_noop!(2780			TemplateModule::set_variable_meta_data(2781				origin1.clone(),2782				collection_id,2783				TokenId(1),2784				variable_data.try_into().unwrap()2785			)2786			.map_err(|e| e.error),2787			CommonError::<Test>::NoPermission2788		);2789	});2790}27912792#[test]2793fn collection_transfer_flag_works_neg() {2794	new_test_ext().execute_with(|| {2795		let origin1 = Origin::signed(1);27962797		let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));2798		assert_ok!(TemplateModule::set_transfers_enabled_flag(2799			origin1,2800			collection_id,2801			false2802		));28032804		let data = default_nft_data();2805		create_test_item(collection_id, &data.into());2806		assert_eq!(2807			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),2808			12809		);2810		assert_eq!(2811			<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),2812			true2813		);28142815		let origin1 = Origin::signed(1);28162817		// default scenario2818		assert_noop!(2819			TemplateModule::transfer(origin1, account(2), CollectionId(1), TokenId(1), 1)2820				.map_err(|e| e.error),2821			CommonError::<Test>::TransferNotAllowed2822		);2823		assert_eq!(2824			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),2825			12826		);2827		assert_eq!(2828			<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(2))),2829			02830		);2831		assert_eq!(2832			<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),2833			true2834		);2835		assert_eq!(2836			<pallet_nonfungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))),2837			false2838		);2839	});2840}