12use 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};11use sp_std::convert::TryInto;1213fn default_nft_data() -> CreateNftData {14 CreateNftData {15 const_data: vec![1, 2, 3].try_into().unwrap(),16 variable_data: vec![3, 2, 1].try_into().unwrap(),17 }18}1920fn default_fungible_data() -> CreateFungibleData {21 CreateFungibleData { value: 5 }22}2324fn default_re_fungible_data() -> CreateReFungibleData {25 CreateReFungibleData {26 const_data: vec![1, 2, 3].try_into().unwrap(),27 variable_data: vec![3, 2, 1].try_into().unwrap(),28 pieces: 1023,29 }30}3132fn create_test_collection_for_owner(33 mode: &CollectionMode,34 owner: u64,35 id: CollectionId,36) -> CollectionId {37 let col_name1: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();38 let col_desc1: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();39 let token_prefix1: Vec<u8> = b"token_prefix1\0".to_vec();4041 let data: CreateCollectionData<u64> = CreateCollectionData {42 name: col_name1.try_into().unwrap(),43 description: col_desc1.try_into().unwrap(),44 token_prefix: token_prefix1.try_into().unwrap(),45 mode: mode.clone(),46 ..Default::default()47 };4849 let origin1 = Origin::signed(owner);50 assert_ok!(TemplateModule::create_collection_ex(origin1, data));5152 let saved_col_name: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();53 let saved_description: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();54 let saved_prefix: Vec<u8> = b"token_prefix1\0".to_vec();55 assert_eq!(56 <pallet_common::CollectionById<Test>>::get(id)57 .unwrap()58 .owner,59 owner60 );61 assert_eq!(62 <pallet_common::CollectionById<Test>>::get(id).unwrap().name,63 saved_col_name64 );65 assert_eq!(66 <pallet_common::CollectionById<Test>>::get(id).unwrap().mode,67 *mode68 );69 assert_eq!(70 <pallet_common::CollectionById<Test>>::get(id)71 .unwrap()72 .description,73 saved_description74 );75 assert_eq!(76 <pallet_common::CollectionById<Test>>::get(id)77 .unwrap()78 .token_prefix,79 saved_prefix80 );81 id82}8384fn create_test_collection(mode: &CollectionMode, id: CollectionId) -> CollectionId {85 create_test_collection_for_owner(&mode, 1, id)86}8788fn create_test_item(collection_id: CollectionId, data: &CreateItemData) {89 let origin1 = Origin::signed(1);90 assert_ok!(TemplateModule::create_item(91 origin1,92 collection_id,93 account(1),94 data.clone()95 ));96}9798fn account(sub: u64) -> TestCrossAccountId {99 TestCrossAccountId::from_sub(sub)100}101102103104105#[test]106fn set_version_schema() {107 new_test_ext().execute_with(|| {108 let origin1 = Origin::signed(1);109 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));110111 assert_ok!(TemplateModule::set_schema_version(112 origin1,113 collection_id,114 SchemaVersion::Unique115 ));116 assert_eq!(117 <pallet_common::CollectionById<Test>>::get(collection_id)118 .unwrap()119 .schema_version,120 SchemaVersion::Unique121 );122 });123}124125#[test]126fn create_fungible_collection_fails_with_large_decimal_numbers() {127 new_test_ext().execute_with(|| {128 let col_name1: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();129 let col_desc1: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();130 let token_prefix1: Vec<u8> = b"token_prefix1\0".to_vec();131132 let data: CreateCollectionData<u64> = CreateCollectionData {133 name: col_name1.try_into().unwrap(),134 description: col_desc1.try_into().unwrap(),135 token_prefix: token_prefix1.try_into().unwrap(),136 mode: CollectionMode::Fungible(MAX_DECIMAL_POINTS + 1),137 ..Default::default()138 };139140 let origin1 = Origin::signed(1);141 assert_noop!(142 TemplateModule::create_collection_ex(origin1, data),143 Error::<Test>::CollectionDecimalPointLimitExceeded144 );145 });146}147148#[test]149fn create_nft_item() {150 new_test_ext().execute_with(|| {151 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));152153 let data = default_nft_data();154 create_test_item(collection_id, &data.clone().into());155156 let item = <pallet_nonfungible::TokenData<Test>>::get((collection_id, 1)).unwrap();157 assert_eq!(item.const_data, data.const_data.into_inner());158 assert_eq!(item.variable_data, data.variable_data.into_inner());159 });160}161162163164#[test]165fn create_nft_multiple_items() {166 new_test_ext().execute_with(|| {167 create_test_collection(&CollectionMode::NFT, CollectionId(1));168169 let origin1 = Origin::signed(1);170171 let items_data = vec![default_nft_data(), default_nft_data(), default_nft_data()];172173 assert_ok!(TemplateModule::create_multiple_items(174 origin1,175 CollectionId(1),176 account(1),177 items_data178 .clone()179 .into_iter()180 .map(|d| { d.into() })181 .collect()182 ));183 for (index, data) in items_data.into_iter().enumerate() {184 let item = <pallet_nonfungible::TokenData<Test>>::get((185 CollectionId(1),186 TokenId((index + 1) as u32),187 ))188 .unwrap();189 assert_eq!(item.const_data.to_vec(), data.const_data.into_inner());190 assert_eq!(item.variable_data.to_vec(), data.variable_data.into_inner());191 }192 });193}194195#[test]196fn create_refungible_item() {197 new_test_ext().execute_with(|| {198 let collection_id = create_test_collection(&CollectionMode::ReFungible, CollectionId(1));199200 let data = default_re_fungible_data();201 create_test_item(collection_id, &data.clone().into());202 let item = <pallet_refungible::TokenData<Test>>::get((collection_id, TokenId(1)));203 let balance =204 <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1)));205 assert_eq!(item.const_data, data.const_data.into_inner());206 assert_eq!(item.variable_data, data.variable_data.into_inner());207 assert_eq!(balance, 1023);208 });209}210211#[test]212fn create_multiple_refungible_items() {213 new_test_ext().execute_with(|| {214 create_test_collection(&CollectionMode::ReFungible, CollectionId(1));215216 let origin1 = Origin::signed(1);217218 let items_data = vec![219 default_re_fungible_data(),220 default_re_fungible_data(),221 default_re_fungible_data(),222 ];223224 assert_ok!(TemplateModule::create_multiple_items(225 origin1,226 CollectionId(1),227 account(1),228 items_data229 .clone()230 .into_iter()231 .map(|d| { d.into() })232 .collect()233 ));234 for (index, data) in items_data.into_iter().enumerate() {235 let item = <pallet_refungible::TokenData<Test>>::get((236 CollectionId(1),237 TokenId((index + 1) as u32),238 ));239 let balance =240 <pallet_refungible::Balance<Test>>::get((CollectionId(1), TokenId(1), account(1)));241 assert_eq!(item.const_data.to_vec(), data.const_data.into_inner());242 assert_eq!(item.variable_data.to_vec(), data.variable_data.into_inner());243 assert_eq!(balance, 1023);244 }245 });246}247248#[test]249fn create_fungible_item() {250 new_test_ext().execute_with(|| {251 let collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));252253 let data = default_fungible_data();254 create_test_item(collection_id, &data.into());255256 assert_eq!(257 <pallet_fungible::Balance<Test>>::get((collection_id, account(1))),258 5259 );260 });261}262263264265266267268269270271272273274275276277278279280281282283284285286287288289#[test]290fn transfer_fungible_item() {291 new_test_ext().execute_with(|| {292 let collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));293294 let origin1 = Origin::signed(1);295 let origin2 = Origin::signed(2);296297 let data = default_fungible_data();298 create_test_item(collection_id, &data.into());299300 assert_eq!(301 <pallet_fungible::Balance<Test>>::get((CollectionId(1), account(1))),302 5303 );304305 306 assert_ok!(TemplateModule::transfer(307 origin1,308 account(2),309 CollectionId(1),310 TokenId(0),311 5312 ));313 assert_eq!(314 <pallet_fungible::Balance<Test>>::get((CollectionId(1), account(1))),315 0316 );317318 319 assert_ok!(TemplateModule::transfer(320 origin2.clone(),321 account(3),322 CollectionId(1),323 TokenId(0),324 3325 ));326327 328 assert_ok!(TemplateModule::transfer(329 origin2,330 account(3),331 CollectionId(1),332 TokenId(0),333 1334 ));335 assert_eq!(336 <pallet_fungible::Balance<Test>>::get((CollectionId(1), account(2))),337 1338 );339 assert_eq!(340 <pallet_fungible::Balance<Test>>::get((CollectionId(1), account(3))),341 4342 );343 });344}345346#[test]347fn transfer_refungible_item() {348 new_test_ext().execute_with(|| {349 let collection_id = create_test_collection(&CollectionMode::ReFungible, CollectionId(1));350351 352 let data = default_re_fungible_data();353 create_test_item(collection_id, &data.clone().into());354 let item = <pallet_refungible::TokenData<Test>>::get((collection_id, TokenId(1)));355 assert_eq!(item.const_data, data.const_data.into_inner());356 assert_eq!(item.variable_data, data.variable_data.into_inner());357 assert_eq!(358 <pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))),359 1360 );361 assert_eq!(362 <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1))),363 1023364 );365 assert_eq!(366 <pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),367 true368 );369370 371 let origin1 = Origin::signed(1);372 let origin2 = Origin::signed(2);373 assert_ok!(TemplateModule::transfer(374 origin1,375 account(2),376 CollectionId(1),377 TokenId(1),378 1023379 ));380 assert_eq!(381 <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(2))),382 1023383 );384 assert_eq!(385 <pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))),386 0387 );388 assert_eq!(389 <pallet_refungible::AccountBalance<Test>>::get((collection_id, account(2))),390 1391 );392 assert_eq!(393 <pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),394 false395 );396 assert_eq!(397 <pallet_refungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))),398 true399 );400401 402 assert_ok!(TemplateModule::transfer(403 origin2.clone(),404 account(3),405 CollectionId(1),406 TokenId(1),407 500408 ));409 assert_eq!(410 <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(2))),411 523412 );413 assert_eq!(414 <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(3))),415 500416 );417 assert_eq!(418 <pallet_refungible::AccountBalance<Test>>::get((collection_id, account(2))),419 1420 );421 assert_eq!(422 <pallet_refungible::AccountBalance<Test>>::get((collection_id, account(3))),423 1424 );425 assert_eq!(426 <pallet_refungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))),427 true428 );429 assert_eq!(430 <pallet_refungible::Owned<Test>>::get((collection_id, account(3), TokenId(1))),431 true432 );433434 435 assert_ok!(TemplateModule::transfer(436 origin2,437 account(3),438 CollectionId(1),439 TokenId(1),440 200441 ));442 assert_eq!(443 <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(2))),444 323445 );446 assert_eq!(447 <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(3))),448 700449 );450 assert_eq!(451 <pallet_refungible::AccountBalance<Test>>::get((collection_id, account(2))),452 1453 );454 assert_eq!(455 <pallet_refungible::AccountBalance<Test>>::get((collection_id, account(3))),456 1457 );458 assert_eq!(459 <pallet_refungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))),460 true461 );462 assert_eq!(463 <pallet_refungible::Owned<Test>>::get((collection_id, account(3), TokenId(1))),464 true465 );466 });467}468469#[test]470fn transfer_nft_item() {471 new_test_ext().execute_with(|| {472 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));473474 let data = default_nft_data();475 create_test_item(collection_id, &data.into());476 assert_eq!(477 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),478 1479 );480 assert_eq!(481 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),482 true483 );484485 let origin1 = Origin::signed(1);486 487 assert_ok!(TemplateModule::transfer(488 origin1,489 account(2),490 CollectionId(1),491 TokenId(1),492 1493 ));494 assert_eq!(495 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),496 0497 );498 assert_eq!(499 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(2))),500 1501 );502 assert_eq!(503 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),504 false505 );506 assert_eq!(507 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))),508 true509 );510 });511}512513#[test]514fn transfer_nft_item_wrong_value() {515 new_test_ext().execute_with(|| {516 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));517518 let data = default_nft_data();519 create_test_item(collection_id, &data.into());520 assert_eq!(521 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),522 1523 );524 assert_eq!(525 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),526 true527 );528529 let origin1 = Origin::signed(1);530531 assert_noop!(532 TemplateModule::transfer(origin1, account(2), CollectionId(1), TokenId(1), 2)533 .map_err(|e| e.error),534 <pallet_nonfungible::Error::<Test>>::NonfungibleItemsHaveNoAmount535 );536 });537}538539#[test]540fn transfer_nft_item_zero_value() {541 new_test_ext().execute_with(|| {542 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));543544 let data = default_nft_data();545 create_test_item(collection_id, &data.into());546 assert_eq!(547 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),548 1549 );550 assert_eq!(551 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),552 true553 );554555 let origin1 = Origin::signed(1);556557 558 assert_ok!(TemplateModule::transfer(559 origin1,560 account(2),561 CollectionId(1),562 TokenId(1),563 0564 ));565 566 assert_eq!(567 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),568 1569 );570 assert_eq!(571 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),572 true573 );574 });575}576577#[test]578fn nft_approve_and_transfer_from() {579 new_test_ext().execute_with(|| {580 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));581582 let data = default_nft_data();583 create_test_item(collection_id, &data.into());584585 let origin1 = Origin::signed(1);586 let origin2 = Origin::signed(2);587588 assert_eq!(589 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),590 1591 );592 assert_eq!(593 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),594 true595 );596597 598 assert_noop!(599 TemplateModule::transfer_from(600 origin2.clone(),601 account(1),602 account(2),603 CollectionId(1),604 TokenId(1),605 1606 )607 .map_err(|e| e.error),608 CommonError::<Test>::ApprovedValueTooLow609 );610611 612 assert_ok!(TemplateModule::approve(613 origin1,614 account(2),615 CollectionId(1),616 TokenId(1),617 1618 ));619 assert_eq!(620 <pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),621 account(2)622 );623624 assert_ok!(TemplateModule::transfer_from(625 origin2,626 account(1),627 account(3),628 CollectionId(1),629 TokenId(1),630 1631 ));632 assert!(633 <pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).is_none()634 );635 });636}637638#[test]639fn nft_approve_and_transfer_from_allow_list() {640 new_test_ext().execute_with(|| {641 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));642643 let origin1 = Origin::signed(1);644 let origin2 = Origin::signed(2);645646 647 let data = default_nft_data();648 create_test_item(collection_id, &data.clone().into());649 assert_eq!(650 &<pallet_nonfungible::TokenData<Test>>::get((collection_id, TokenId(1)))651 .unwrap()652 .const_data,653 &data.const_data.into_inner()654 );655 assert_eq!(656 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),657 1658 );659 assert_eq!(660 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),661 true662 );663664 665 assert_ok!(TemplateModule::set_mint_permission(666 origin1.clone(),667 CollectionId(1),668 true669 ));670 assert_ok!(TemplateModule::set_public_access_mode(671 origin1.clone(),672 CollectionId(1),673 AccessMode::AllowList674 ));675 assert_ok!(TemplateModule::add_to_allow_list(676 origin1.clone(),677 CollectionId(1),678 account(1)679 ));680 assert_ok!(TemplateModule::add_to_allow_list(681 origin1.clone(),682 CollectionId(1),683 account(2)684 ));685 assert_ok!(TemplateModule::add_to_allow_list(686 origin1.clone(),687 CollectionId(1),688 account(3)689 ));690691 692 assert_ok!(TemplateModule::approve(693 origin1.clone(),694 account(2),695 CollectionId(1),696 TokenId(1),697 1698 ));699 assert_eq!(700 <pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),701 account(2)702 );703704 705 assert_ok!(TemplateModule::transfer_from(706 origin2,707 account(1),708 account(3),709 CollectionId(1),710 TokenId(1),711 1712 ));713 assert!(714 <pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).is_none()715 );716 });717}718719#[test]720fn refungible_approve_and_transfer_from() {721 new_test_ext().execute_with(|| {722 let collection_id = create_test_collection(&CollectionMode::ReFungible, CollectionId(1));723724 let origin1 = Origin::signed(1);725 let origin2 = Origin::signed(2);726727 728 let data = default_re_fungible_data();729 create_test_item(collection_id, &data.into());730731 assert_eq!(732 <pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))),733 1734 );735 assert_eq!(736 <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1))),737 1023738 );739 assert_eq!(740 <pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),741 true742 );743744 745 assert_ok!(TemplateModule::set_mint_permission(746 origin1.clone(),747 CollectionId(1),748 true749 ));750 assert_ok!(TemplateModule::set_public_access_mode(751 origin1.clone(),752 CollectionId(1),753 AccessMode::AllowList754 ));755 assert_ok!(TemplateModule::add_to_allow_list(756 origin1.clone(),757 CollectionId(1),758 account(1)759 ));760 assert_ok!(TemplateModule::add_to_allow_list(761 origin1.clone(),762 CollectionId(1),763 account(2)764 ));765 assert_ok!(TemplateModule::add_to_allow_list(766 origin1.clone(),767 CollectionId(1),768 account(3)769 ));770771 772 assert_ok!(TemplateModule::approve(773 origin1,774 account(2),775 CollectionId(1),776 TokenId(1),777 1023778 ));779 assert_eq!(780 <pallet_refungible::Allowance<Test>>::get((781 CollectionId(1),782 TokenId(1),783 account(1),784 account(2)785 )),786 1023787 );788789 790 assert_ok!(TemplateModule::transfer_from(791 origin2,792 account(1),793 account(3),794 CollectionId(1),795 TokenId(1),796 100797 ));798 assert_eq!(799 <pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))),800 1801 );802 assert_eq!(803 <pallet_refungible::AccountBalance<Test>>::get((collection_id, account(3))),804 1805 );806 assert_eq!(807 <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1))),808 923809 );810 assert_eq!(811 <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(3))),812 100813 );814 assert_eq!(815 <pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),816 true817 );818 assert_eq!(819 <pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),820 true821 );822 assert_eq!(823 <pallet_refungible::Allowance<Test>>::get((824 CollectionId(1),825 TokenId(1),826 account(1),827 account(2)828 )),829 923830 );831 });832}833834#[test]835fn fungible_approve_and_transfer_from() {836 new_test_ext().execute_with(|| {837 let collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));838839 let data = default_fungible_data();840 create_test_item(collection_id, &data.into());841842 let origin1 = Origin::signed(1);843 let origin2 = Origin::signed(2);844845 assert_ok!(TemplateModule::set_mint_permission(846 origin1.clone(),847 CollectionId(1),848 true849 ));850 assert_ok!(TemplateModule::set_public_access_mode(851 origin1.clone(),852 CollectionId(1),853 AccessMode::AllowList854 ));855 assert_ok!(TemplateModule::add_to_allow_list(856 origin1.clone(),857 CollectionId(1),858 account(1)859 ));860 assert_ok!(TemplateModule::add_to_allow_list(861 origin1.clone(),862 CollectionId(1),863 account(2)864 ));865 assert_ok!(TemplateModule::add_to_allow_list(866 origin1.clone(),867 CollectionId(1),868 account(3)869 ));870871 872 assert_ok!(TemplateModule::approve(873 origin1.clone(),874 account(2),875 CollectionId(1),876 TokenId(0),877 5878 ));879 assert_eq!(880 <pallet_fungible::Allowance<Test>>::get((CollectionId(1), account(1), account(2))),881 5882 );883 assert_ok!(TemplateModule::approve(884 origin1,885 account(3),886 CollectionId(1),887 TokenId(0),888 5889 ));890 assert_eq!(891 <pallet_fungible::Allowance<Test>>::get((CollectionId(1), account(1), account(2))),892 5893 );894 assert_eq!(895 <pallet_fungible::Allowance<Test>>::get((CollectionId(1), account(1), account(3))),896 5897 );898899 assert_ok!(TemplateModule::transfer_from(900 origin2.clone(),901 account(1),902 account(3),903 CollectionId(1),904 TokenId(0),905 4906 ));907908 assert_eq!(909 <pallet_fungible::Allowance<Test>>::get((CollectionId(1), account(1), account(2))),910 1911 );912913 assert_noop!(914 TemplateModule::transfer_from(915 origin2,916 account(1),917 account(3),918 CollectionId(1),919 TokenId(0),920 4921 )922 .map_err(|e| e.error),923 CommonError::<Test>::ApprovedValueTooLow924 );925 });926}927928#[test]929fn change_collection_owner() {930 new_test_ext().execute_with(|| {931 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));932933 let origin1 = Origin::signed(1);934 assert_ok!(TemplateModule::change_collection_owner(935 origin1,936 collection_id,937 2938 ));939 assert_eq!(940 <pallet_common::CollectionById<Test>>::get(collection_id)941 .unwrap()942 .owner,943 2944 );945 });946}947948#[test]949fn destroy_collection() {950 new_test_ext().execute_with(|| {951 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));952953 let origin1 = Origin::signed(1);954 assert_ok!(TemplateModule::destroy_collection(origin1, collection_id));955 });956}957958#[test]959fn burn_nft_item() {960 new_test_ext().execute_with(|| {961 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));962963 let origin1 = Origin::signed(1);964965 let data = default_nft_data();966 create_test_item(collection_id, &data.into());967968 969 assert_eq!(970 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),971 1972 );973974 975 assert_ok!(TemplateModule::burn_item(976 origin1.clone(),977 collection_id,978 TokenId(1),979 1980 ));981 assert_eq!(982 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),983 0984 );985 });986}987988#[test]989fn burn_same_nft_item_twice() {990 new_test_ext().execute_with(|| {991 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));992993 let origin1 = Origin::signed(1);994995 let data = default_nft_data();996 create_test_item(collection_id, &data.into());997998 999 assert_eq!(1000 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),1001 11002 );10031004 1005 assert_ok!(TemplateModule::burn_item(1006 origin1.clone(),1007 collection_id,1008 TokenId(1),1009 11010 ));10111012 1013 assert_noop!(1014 TemplateModule::burn_item(origin1, collection_id, TokenId(1), 1).map_err(|e| e.error),1015 CommonError::<Test>::TokenNotFound1016 );10171018 assert_eq!(1019 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),1020 01021 );1022 });1023}10241025#[test]1026fn burn_fungible_item() {1027 new_test_ext().execute_with(|| {1028 let collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));10291030 let origin1 = Origin::signed(1);1031 assert_ok!(TemplateModule::add_collection_admin(1032 origin1.clone(),1033 collection_id,1034 account(2)1035 ));10361037 let data = default_fungible_data();1038 create_test_item(collection_id, &data.into());10391040 1041 assert_eq!(1042 <pallet_fungible::Balance<Test>>::get((collection_id, account(1))),1043 51044 );10451046 1047 assert_ok!(TemplateModule::burn_item(1048 origin1.clone(),1049 CollectionId(1),1050 TokenId(0),1051 51052 ));1053 assert_noop!(1054 TemplateModule::burn_item(origin1, CollectionId(1), TokenId(0), 5).map_err(|e| e.error),1055 CommonError::<Test>::TokenValueTooLow1056 );10571058 assert_eq!(1059 <pallet_fungible::Balance<Test>>::get((collection_id, account(1))),1060 01061 );1062 });1063}10641065#[test]1066fn burn_fungible_item_with_token_id() {1067 new_test_ext().execute_with(|| {1068 let collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));10691070 let origin1 = Origin::signed(1);1071 assert_ok!(TemplateModule::add_collection_admin(1072 origin1.clone(),1073 collection_id,1074 account(2)1075 ));10761077 let data = default_fungible_data();1078 create_test_item(collection_id, &data.into());10791080 1081 assert_eq!(1082 <pallet_fungible::Balance<Test>>::get((collection_id, account(1))),1083 51084 );10851086 1087 assert_noop!(1088 TemplateModule::burn_item(origin1, CollectionId(1), TokenId(1), 5).map_err(|e| e.error),1089 <pallet_fungible::Error::<Test>>::FungibleItemsHaveNoId1090 );1091 });1092}1093#[test]1094fn burn_refungible_item() {1095 new_test_ext().execute_with(|| {1096 let collection_id = create_test_collection(&CollectionMode::ReFungible, CollectionId(1));1097 let origin1 = Origin::signed(1);10981099 assert_ok!(TemplateModule::set_mint_permission(1100 origin1.clone(),1101 collection_id,1102 true1103 ));1104 assert_ok!(TemplateModule::set_public_access_mode(1105 origin1.clone(),1106 collection_id,1107 AccessMode::AllowList1108 ));1109 assert_ok!(TemplateModule::add_to_allow_list(1110 origin1.clone(),1111 collection_id,1112 account(1)1113 ));11141115 assert_ok!(TemplateModule::add_collection_admin(1116 origin1.clone(),1117 collection_id,1118 account(2)1119 ));11201121 let data = default_re_fungible_data();1122 create_test_item(collection_id, &data.into());11231124 1125 assert_eq!(1126 <pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))),1127 11128 );1129 assert_eq!(1130 <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1))),1131 10231132 );11331134 1135 assert_ok!(TemplateModule::burn_item(1136 origin1.clone(),1137 collection_id,1138 TokenId(1),1139 10231140 ));1141 assert_noop!(1142 TemplateModule::burn_item(origin1, collection_id, TokenId(1), 1023)1143 .map_err(|e| e.error),1144 CommonError::<Test>::TokenValueTooLow1145 );11461147 assert_eq!(1148 <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1))),1149 01150 );1151 });1152}11531154#[test]1155fn add_collection_admin() {1156 new_test_ext().execute_with(|| {1157 let collection1_id =1158 create_test_collection_for_owner(&CollectionMode::NFT, 1, CollectionId(1));1159 let origin1 = Origin::signed(1);11601161 1162 assert_ok!(TemplateModule::add_collection_admin(1163 origin1.clone(),1164 collection1_id,1165 account(2)1166 ));1167 assert_ok!(TemplateModule::add_collection_admin(1168 origin1,1169 collection1_id,1170 account(3)1171 ));11721173 1174 assert_eq!(1175 <pallet_common::IsAdmin<Test>>::get((CollectionId(1), account(1))),1176 false1177 );1178 assert!(<pallet_common::IsAdmin<Test>>::get((1179 CollectionId(1),1180 account(2)1181 )));1182 assert!(<pallet_common::IsAdmin<Test>>::get((1183 CollectionId(1),1184 account(3)1185 )));1186 });1187}11881189#[test]1190fn remove_collection_admin() {1191 new_test_ext().execute_with(|| {1192 let collection1_id =1193 create_test_collection_for_owner(&CollectionMode::NFT, 1, CollectionId(1));1194 let origin1 = Origin::signed(1);1195 let origin2 = Origin::signed(2);11961197 1198 assert_ok!(TemplateModule::add_collection_admin(1199 origin1.clone(),1200 collection1_id,1201 account(2)1202 ));1203 assert_ok!(TemplateModule::add_collection_admin(1204 origin1,1205 collection1_id,1206 account(3)1207 ));12081209 assert!(<pallet_common::IsAdmin<Test>>::get((1210 CollectionId(1),1211 account(2)1212 )));1213 assert!(<pallet_common::IsAdmin<Test>>::get((1214 CollectionId(1),1215 account(3)1216 )));12171218 1219 assert_ok!(TemplateModule::remove_collection_admin(1220 origin2,1221 CollectionId(1),1222 account(3)1223 ));12241225 1226 assert!(<pallet_common::IsAdmin<Test>>::get((1227 CollectionId(1),1228 account(2)1229 )));1230 assert_eq!(1231 <pallet_common::IsAdmin<Test>>::get((CollectionId(1), account(3))),1232 false1233 );1234 });1235}12361237#[test]1238fn balance_of() {1239 new_test_ext().execute_with(|| {1240 let nft_collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1241 let fungible_collection_id =1242 create_test_collection(&CollectionMode::Fungible(3), CollectionId(2));1243 let re_fungible_collection_id =1244 create_test_collection(&CollectionMode::ReFungible, CollectionId(3));12451246 1247 assert_eq!(1248 <pallet_nonfungible::AccountBalance<Test>>::get((nft_collection_id, account(1))),1249 01250 );1251 assert_eq!(1252 <pallet_fungible::Balance<Test>>::get((fungible_collection_id, account(1))),1253 01254 );1255 assert_eq!(1256 <pallet_refungible::AccountBalance<Test>>::get((re_fungible_collection_id, account(1))),1257 01258 );12591260 let nft_data = default_nft_data();1261 create_test_item(nft_collection_id, &nft_data.into());12621263 let fungible_data = default_fungible_data();1264 create_test_item(fungible_collection_id, &fungible_data.into());12651266 let re_fungible_data = default_re_fungible_data();1267 create_test_item(re_fungible_collection_id, &re_fungible_data.into());12681269 1270 assert_eq!(1271 <pallet_nonfungible::AccountBalance<Test>>::get((nft_collection_id, account(1))),1272 11273 );1274 assert_eq!(1275 <pallet_fungible::Balance<Test>>::get((fungible_collection_id, account(1))),1276 51277 );1278 assert_eq!(1279 <pallet_refungible::AccountBalance<Test>>::get((re_fungible_collection_id, account(1))),1280 11281 );12821283 assert_eq!(1284 <pallet_nonfungible::Owned<Test>>::get((nft_collection_id, account(1), TokenId(1))),1285 true1286 );1287 assert_eq!(1288 <pallet_refungible::Owned<Test>>::get((1289 re_fungible_collection_id,1290 account(1),1291 TokenId(1)1292 )),1293 true1294 );1295 });1296}12971298#[test]1299fn approve() {1300 new_test_ext().execute_with(|| {1301 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));13021303 let data = default_nft_data();1304 create_test_item(collection_id, &data.into());13051306 let origin1 = Origin::signed(1);13071308 1309 assert_ok!(TemplateModule::approve(1310 origin1,1311 account(2),1312 CollectionId(1),1313 TokenId(1),1314 11315 ));1316 assert_eq!(1317 <pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),1318 account(2)1319 );1320 });1321}13221323#[test]1324fn transfer_from() {1325 new_test_ext().execute_with(|| {1326 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1327 let origin1 = Origin::signed(1);1328 let origin2 = Origin::signed(2);13291330 let data = default_nft_data();1331 create_test_item(collection_id, &data.into());13321333 1334 assert_ok!(TemplateModule::approve(1335 origin1.clone(),1336 account(2),1337 CollectionId(1),1338 TokenId(1),1339 11340 ));1341 assert_eq!(1342 <pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),1343 account(2)1344 );13451346 assert_ok!(TemplateModule::set_mint_permission(1347 origin1.clone(),1348 CollectionId(1),1349 true1350 ));1351 assert_ok!(TemplateModule::set_public_access_mode(1352 origin1.clone(),1353 CollectionId(1),1354 AccessMode::AllowList1355 ));1356 assert_ok!(TemplateModule::add_to_allow_list(1357 origin1.clone(),1358 CollectionId(1),1359 account(1)1360 ));1361 assert_ok!(TemplateModule::add_to_allow_list(1362 origin1.clone(),1363 CollectionId(1),1364 account(2)1365 ));1366 assert_ok!(TemplateModule::add_to_allow_list(1367 origin1,1368 CollectionId(1),1369 account(3)1370 ));13711372 assert_ok!(TemplateModule::transfer_from(1373 origin2,1374 account(1),1375 account(2),1376 CollectionId(1),1377 TokenId(1),1378 11379 ));13801381 1382 assert_eq!(1383 <pallet_nonfungible::AccountBalance<Test>>::get((CollectionId(1), account(1))),1384 01385 );1386 assert_eq!(1387 <pallet_nonfungible::AccountBalance<Test>>::get((CollectionId(1), account(2))),1388 11389 );1390 });1391}1392139313941395139613971398#[test]1399fn owner_can_add_address_to_allow_list() {1400 new_test_ext().execute_with(|| {1401 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));14021403 let origin1 = Origin::signed(1);1404 assert_ok!(TemplateModule::add_to_allow_list(1405 origin1,1406 collection_id,1407 account(2)1408 ));1409 assert!(<pallet_common::Allowlist<Test>>::get((1410 collection_id,1411 account(2)1412 )));1413 });1414}14151416#[test]1417fn admin_can_add_address_to_allow_list() {1418 new_test_ext().execute_with(|| {1419 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1420 let origin1 = Origin::signed(1);1421 let origin2 = Origin::signed(2);14221423 assert_ok!(TemplateModule::add_collection_admin(1424 origin1,1425 collection_id,1426 account(2)1427 ));1428 assert_ok!(TemplateModule::add_to_allow_list(1429 origin2,1430 collection_id,1431 account(3)1432 ));1433 assert!(<pallet_common::Allowlist<Test>>::get((1434 collection_id,1435 account(3)1436 )));1437 });1438}14391440#[test]1441fn nonprivileged_user_cannot_add_address_to_allow_list() {1442 new_test_ext().execute_with(|| {1443 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));14441445 let origin2 = Origin::signed(2);1446 assert_noop!(1447 TemplateModule::add_to_allow_list(origin2, collection_id, account(3)),1448 CommonError::<Test>::NoPermission1449 );1450 });1451}14521453#[test]1454fn nobody_can_add_address_to_allow_list_of_nonexisting_collection() {1455 new_test_ext().execute_with(|| {1456 let origin1 = Origin::signed(1);14571458 assert_noop!(1459 TemplateModule::add_to_allow_list(origin1, CollectionId(1), account(2)),1460 CommonError::<Test>::CollectionNotFound1461 );1462 });1463}14641465#[test]1466fn nobody_can_add_address_to_allow_list_of_deleted_collection() {1467 new_test_ext().execute_with(|| {1468 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));14691470 let origin1 = Origin::signed(1);1471 assert_ok!(TemplateModule::destroy_collection(1472 origin1.clone(),1473 collection_id1474 ));1475 assert_noop!(1476 TemplateModule::add_to_allow_list(origin1, collection_id, account(2)),1477 CommonError::<Test>::CollectionNotFound1478 );1479 });1480}148114821483#[test]1484fn address_is_already_added_to_allow_list() {1485 new_test_ext().execute_with(|| {1486 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1487 let origin1 = Origin::signed(1);14881489 assert_ok!(TemplateModule::add_to_allow_list(1490 origin1.clone(),1491 collection_id,1492 account(2)1493 ));1494 assert_ok!(TemplateModule::add_to_allow_list(1495 origin1,1496 collection_id,1497 account(2)1498 ));1499 assert!(<pallet_common::Allowlist<Test>>::get((1500 collection_id,1501 account(2)1502 )));1503 });1504}15051506#[test]1507fn owner_can_remove_address_from_allow_list() {1508 new_test_ext().execute_with(|| {1509 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));15101511 let origin1 = Origin::signed(1);1512 assert_ok!(TemplateModule::add_to_allow_list(1513 origin1.clone(),1514 collection_id,1515 account(2)1516 ));1517 assert_ok!(TemplateModule::remove_from_allow_list(1518 origin1,1519 collection_id,1520 account(2)1521 ));1522 assert_eq!(1523 <pallet_common::Allowlist<Test>>::get((collection_id, account(2))),1524 false1525 );1526 });1527}15281529#[test]1530fn admin_can_remove_address_from_allow_list() {1531 new_test_ext().execute_with(|| {1532 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1533 let origin1 = Origin::signed(1);1534 let origin2 = Origin::signed(2);15351536 1537 assert_ok!(TemplateModule::add_collection_admin(1538 origin1.clone(),1539 collection_id,1540 account(2)1541 ));15421543 1544 assert_ok!(TemplateModule::add_to_allow_list(1545 origin1,1546 collection_id,1547 account(3)1548 ));15491550 1551 assert_ok!(TemplateModule::remove_from_allow_list(1552 origin2,1553 collection_id,1554 account(3)1555 ));1556 assert_eq!(1557 <pallet_common::Allowlist<Test>>::get((collection_id, account(3))),1558 false1559 );1560 });1561}15621563#[test]1564fn nonprivileged_user_cannot_remove_address_from_allow_list() {1565 new_test_ext().execute_with(|| {1566 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1567 let origin1 = Origin::signed(1);1568 let origin2 = Origin::signed(2);15691570 assert_ok!(TemplateModule::add_to_allow_list(1571 origin1,1572 collection_id,1573 account(2)1574 ));1575 assert_noop!(1576 TemplateModule::remove_from_allow_list(origin2, collection_id, account(2)),1577 CommonError::<Test>::NoPermission1578 );1579 assert!(<pallet_common::Allowlist<Test>>::get((1580 collection_id,1581 account(2)1582 )));1583 });1584}15851586#[test]1587fn nobody_can_remove_address_from_allow_list_of_nonexisting_collection() {1588 new_test_ext().execute_with(|| {1589 let origin1 = Origin::signed(1);15901591 assert_noop!(1592 TemplateModule::remove_from_allow_list(origin1, CollectionId(1), account(2)),1593 CommonError::<Test>::CollectionNotFound1594 );1595 });1596}15971598#[test]1599fn nobody_can_remove_address_from_allow_list_of_deleted_collection() {1600 new_test_ext().execute_with(|| {1601 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1602 let origin1 = Origin::signed(1);1603 let origin2 = Origin::signed(2);16041605 1606 assert_ok!(TemplateModule::add_to_allow_list(1607 origin1.clone(),1608 collection_id,1609 account(2)1610 ));16111612 1613 assert!(<pallet_common::Allowlist<Test>>::get((1614 collection_id,1615 account(2)1616 )));16171618 1619 assert_ok!(TemplateModule::destroy_collection(origin1, collection_id));16201621 1622 assert_noop!(1623 TemplateModule::remove_from_allow_list(origin2, collection_id, account(2)),1624 CommonError::<Test>::CollectionNotFound1625 );16261627 1628 assert_eq!(1629 <pallet_common::Allowlist<Test>>::get((collection_id, account(2))),1630 false1631 );1632 });1633}163416351636#[test]1637fn address_is_already_removed_from_allow_list() {1638 new_test_ext().execute_with(|| {1639 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1640 let origin1 = Origin::signed(1);16411642 assert_ok!(TemplateModule::add_to_allow_list(1643 origin1.clone(),1644 collection_id,1645 account(2)1646 ));1647 assert_ok!(TemplateModule::remove_from_allow_list(1648 origin1.clone(),1649 collection_id,1650 account(2)1651 ));1652 assert_eq!(1653 <pallet_common::Allowlist<Test>>::get((collection_id, account(2))),1654 false1655 );1656 assert_ok!(TemplateModule::remove_from_allow_list(1657 origin1,1658 collection_id,1659 account(2)1660 ));1661 assert_eq!(1662 <pallet_common::Allowlist<Test>>::get((collection_id, account(2))),1663 false1664 );1665 });1666}166716681669#[test]1670fn allow_list_test_1() {1671 new_test_ext().execute_with(|| {1672 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));16731674 let origin1 = Origin::signed(1);16751676 let data = default_nft_data();1677 create_test_item(collection_id, &data.into());16781679 assert_ok!(TemplateModule::set_public_access_mode(1680 origin1.clone(),1681 collection_id,1682 AccessMode::AllowList1683 ));1684 assert_ok!(TemplateModule::add_to_allow_list(1685 origin1.clone(),1686 collection_id,1687 account(2)1688 ));16891690 assert_noop!(1691 TemplateModule::transfer(origin1, account(3), CollectionId(1), TokenId(1), 1)1692 .map_err(|e| e.error),1693 CommonError::<Test>::AddressNotInAllowlist1694 );1695 });1696}16971698#[test]1699fn allow_list_test_2() {1700 new_test_ext().execute_with(|| {1701 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1702 let origin1 = Origin::signed(1);17031704 let data = default_nft_data();1705 create_test_item(collection_id, &data.into());17061707 assert_ok!(TemplateModule::set_public_access_mode(1708 origin1.clone(),1709 collection_id,1710 AccessMode::AllowList1711 ));1712 assert_ok!(TemplateModule::add_to_allow_list(1713 origin1.clone(),1714 collection_id,1715 account(1)1716 ));1717 assert_ok!(TemplateModule::add_to_allow_list(1718 origin1.clone(),1719 collection_id,1720 account(2)1721 ));17221723 1724 assert_ok!(TemplateModule::approve(1725 origin1.clone(),1726 account(1),1727 collection_id,1728 TokenId(1),1729 11730 ));1731 assert_eq!(1732 <pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),1733 account(1)1734 );17351736 assert_ok!(TemplateModule::remove_from_allow_list(1737 origin1.clone(),1738 collection_id,1739 account(1)1740 ));17411742 assert_noop!(1743 TemplateModule::transfer_from(1744 origin1,1745 account(1),1746 account(3),1747 CollectionId(1),1748 TokenId(1),1749 11750 )1751 .map_err(|e| e.error),1752 CommonError::<Test>::AddressNotInAllowlist1753 );1754 });1755}175617571758#[test]1759fn allow_list_test_3() {1760 new_test_ext().execute_with(|| {1761 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));17621763 let origin1 = Origin::signed(1);17641765 let data = default_nft_data();1766 create_test_item(collection_id, &data.into());17671768 assert_ok!(TemplateModule::set_public_access_mode(1769 origin1.clone(),1770 collection_id,1771 AccessMode::AllowList1772 ));1773 assert_ok!(TemplateModule::add_to_allow_list(1774 origin1.clone(),1775 collection_id,1776 account(1)1777 ));17781779 assert_noop!(1780 TemplateModule::transfer(origin1, account(3), collection_id, TokenId(1), 1)1781 .map_err(|e| e.error),1782 CommonError::<Test>::AddressNotInAllowlist1783 );1784 });1785}17861787#[test]1788fn allow_list_test_4() {1789 new_test_ext().execute_with(|| {1790 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));17911792 let origin1 = Origin::signed(1);17931794 let data = default_nft_data();1795 create_test_item(collection_id, &data.into());17961797 assert_ok!(TemplateModule::set_public_access_mode(1798 origin1.clone(),1799 collection_id,1800 AccessMode::AllowList1801 ));1802 assert_ok!(TemplateModule::add_to_allow_list(1803 origin1.clone(),1804 collection_id,1805 account(1)1806 ));1807 assert_ok!(TemplateModule::add_to_allow_list(1808 origin1.clone(),1809 collection_id,1810 account(2)1811 ));18121813 1814 assert_ok!(TemplateModule::approve(1815 origin1.clone(),1816 account(1),1817 collection_id,1818 TokenId(1),1819 11820 ));1821 assert_eq!(1822 <pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),1823 account(1)1824 );18251826 assert_ok!(TemplateModule::remove_from_allow_list(1827 origin1.clone(),1828 collection_id,1829 account(2)1830 ));18311832 assert_noop!(1833 TemplateModule::transfer_from(1834 origin1,1835 account(1),1836 account(3),1837 collection_id,1838 TokenId(1),1839 11840 )1841 .map_err(|e| e.error),1842 CommonError::<Test>::AddressNotInAllowlist1843 );1844 });1845}184618471848#[test]1849fn allow_list_test_5() {1850 new_test_ext().execute_with(|| {1851 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));18521853 let origin1 = Origin::signed(1);18541855 let data = default_nft_data();1856 create_test_item(collection_id, &data.into());18571858 assert_ok!(TemplateModule::set_public_access_mode(1859 origin1.clone(),1860 collection_id,1861 AccessMode::AllowList1862 ));1863 assert_noop!(1864 TemplateModule::burn_item(origin1.clone(), CollectionId(1), TokenId(1), 1)1865 .map_err(|e| e.error),1866 CommonError::<Test>::AddressNotInAllowlist1867 );1868 });1869}187018711872#[test]1873fn allow_list_test_6() {1874 new_test_ext().execute_with(|| {1875 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));18761877 let origin1 = Origin::signed(1);18781879 let data = default_nft_data();1880 create_test_item(collection_id, &data.into());18811882 assert_ok!(TemplateModule::set_public_access_mode(1883 origin1.clone(),1884 collection_id,1885 AccessMode::AllowList1886 ));18871888 1889 assert_noop!(1890 TemplateModule::approve(origin1, account(1), CollectionId(1), TokenId(1), 1)1891 .map_err(|e| e.error),1892 CommonError::<Test>::AddressNotInAllowlist1893 );1894 });1895}1896189718981899#[test]1900fn allow_list_test_7() {1901 new_test_ext().execute_with(|| {1902 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));19031904 let data = default_nft_data();1905 create_test_item(collection_id, &data.into());19061907 let origin1 = Origin::signed(1);19081909 assert_ok!(TemplateModule::set_public_access_mode(1910 origin1.clone(),1911 collection_id,1912 AccessMode::AllowList1913 ));1914 assert_ok!(TemplateModule::add_to_allow_list(1915 origin1.clone(),1916 collection_id,1917 account(1)1918 ));1919 assert_ok!(TemplateModule::add_to_allow_list(1920 origin1.clone(),1921 collection_id,1922 account(2)1923 ));19241925 assert_ok!(TemplateModule::transfer(1926 origin1,1927 account(2),1928 CollectionId(1),1929 TokenId(1),1930 11931 ));1932 });1933}19341935#[test]1936fn allow_list_test_8() {1937 new_test_ext().execute_with(|| {1938 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));19391940 1941 let data = default_nft_data();1942 create_test_item(collection_id, &data.into());19431944 let origin1 = Origin::signed(1);19451946 1947 assert_ok!(TemplateModule::set_public_access_mode(1948 origin1.clone(),1949 collection_id,1950 AccessMode::AllowList1951 ));1952 assert_ok!(TemplateModule::add_to_allow_list(1953 origin1.clone(),1954 collection_id,1955 account(1)1956 ));1957 assert_ok!(TemplateModule::add_to_allow_list(1958 origin1.clone(),1959 collection_id,1960 account(2)1961 ));19621963 1964 assert_ok!(TemplateModule::approve(1965 origin1.clone(),1966 account(1),1967 CollectionId(1),1968 TokenId(1),1969 11970 ));1971 assert_eq!(1972 <pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),1973 account(1)1974 );19751976 1977 assert_ok!(TemplateModule::transfer_from(1978 origin1,1979 account(1),1980 account(2),1981 CollectionId(1),1982 TokenId(1),1983 11984 ));1985 });1986}198719881989#[test]1990fn allow_list_test_9() {1991 new_test_ext().execute_with(|| {1992 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1993 let origin1 = Origin::signed(1);19941995 assert_ok!(TemplateModule::set_public_access_mode(1996 origin1.clone(),1997 collection_id,1998 AccessMode::AllowList1999 ));2000 assert_ok!(TemplateModule::set_mint_permission(2001 origin1,2002 collection_id,2003 false2004 ));20052006 let data = default_nft_data();2007 create_test_item(collection_id, &data.into());2008 });2009}201020112012#[test]2013fn allow_list_test_10() {2014 new_test_ext().execute_with(|| {2015 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));20162017 let origin1 = Origin::signed(1);2018 let origin2 = Origin::signed(2);20192020 assert_ok!(TemplateModule::set_public_access_mode(2021 origin1.clone(),2022 collection_id,2023 AccessMode::AllowList2024 ));2025 assert_ok!(TemplateModule::set_mint_permission(2026 origin1.clone(),2027 collection_id,2028 false2029 ));20302031 assert_ok!(TemplateModule::add_collection_admin(2032 origin1,2033 collection_id,2034 account(2)2035 ));20362037 assert_ok!(TemplateModule::create_item(2038 origin2,2039 collection_id,2040 account(2),2041 default_nft_data().into()2042 ));2043 });2044}204520462047#[test]2048fn allow_list_test_11() {2049 new_test_ext().execute_with(|| {2050 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));20512052 let origin1 = Origin::signed(1);2053 let origin2 = Origin::signed(2);20542055 assert_ok!(TemplateModule::set_public_access_mode(2056 origin1.clone(),2057 collection_id,2058 AccessMode::AllowList2059 ));2060 assert_ok!(TemplateModule::set_mint_permission(2061 origin1.clone(),2062 collection_id,2063 false2064 ));2065 assert_ok!(TemplateModule::add_to_allow_list(2066 origin1,2067 collection_id,2068 account(2)2069 ));20702071 assert_noop!(2072 TemplateModule::create_item(2073 origin2,2074 CollectionId(1),2075 account(2),2076 default_nft_data().into()2077 )2078 .map_err(|e| e.error),2079 CommonError::<Test>::PublicMintingNotAllowed2080 );2081 });2082}208320842085#[test]2086fn allow_list_test_12() {2087 new_test_ext().execute_with(|| {2088 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));20892090 let origin1 = Origin::signed(1);2091 let origin2 = Origin::signed(2);20922093 assert_ok!(TemplateModule::set_public_access_mode(2094 origin1.clone(),2095 collection_id,2096 AccessMode::AllowList2097 ));2098 assert_ok!(TemplateModule::set_mint_permission(2099 origin1,2100 collection_id,2101 false2102 ));21032104 assert_noop!(2105 TemplateModule::create_item(2106 origin2,2107 CollectionId(1),2108 account(2),2109 default_nft_data().into()2110 )2111 .map_err(|e| e.error),2112 CommonError::<Test>::PublicMintingNotAllowed2113 );2114 });2115}211621172118#[test]2119fn allow_list_test_13() {2120 new_test_ext().execute_with(|| {2121 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));21222123 let origin1 = Origin::signed(1);21242125 assert_ok!(TemplateModule::set_public_access_mode(2126 origin1.clone(),2127 collection_id,2128 AccessMode::AllowList2129 ));2130 assert_ok!(TemplateModule::set_mint_permission(2131 origin1,2132 collection_id,2133 true2134 ));21352136 let data = default_nft_data();2137 create_test_item(collection_id, &data.into());2138 });2139}214021412142#[test]2143fn allow_list_test_14() {2144 new_test_ext().execute_with(|| {2145 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));21462147 let origin1 = Origin::signed(1);2148 let origin2 = Origin::signed(2);21492150 assert_ok!(TemplateModule::set_public_access_mode(2151 origin1.clone(),2152 collection_id,2153 AccessMode::AllowList2154 ));2155 assert_ok!(TemplateModule::set_mint_permission(2156 origin1.clone(),2157 collection_id,2158 true2159 ));21602161 assert_ok!(TemplateModule::add_collection_admin(2162 origin1,2163 collection_id,2164 account(2)2165 ));21662167 assert_ok!(TemplateModule::create_item(2168 origin2,2169 collection_id,2170 account(2),2171 default_nft_data().into()2172 ));2173 });2174}217521762177#[test]2178fn allow_list_test_15() {2179 new_test_ext().execute_with(|| {2180 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));21812182 let origin1 = Origin::signed(1);2183 let origin2 = Origin::signed(2);21842185 assert_ok!(TemplateModule::set_public_access_mode(2186 origin1.clone(),2187 collection_id,2188 AccessMode::AllowList2189 ));2190 assert_ok!(TemplateModule::set_mint_permission(2191 origin1,2192 collection_id,2193 true2194 ));21952196 assert_noop!(2197 TemplateModule::create_item(2198 origin2,2199 collection_id,2200 account(2),2201 default_nft_data().into()2202 )2203 .map_err(|e| e.error),2204 CommonError::<Test>::AddressNotInAllowlist2205 );2206 });2207}220822092210#[test]2211fn allow_list_test_16() {2212 new_test_ext().execute_with(|| {2213 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));22142215 let origin1 = Origin::signed(1);2216 let origin2 = Origin::signed(2);22172218 assert_ok!(TemplateModule::set_public_access_mode(2219 origin1.clone(),2220 collection_id,2221 AccessMode::AllowList2222 ));2223 assert_ok!(TemplateModule::set_mint_permission(2224 origin1.clone(),2225 collection_id,2226 true2227 ));2228 assert_ok!(TemplateModule::add_to_allow_list(2229 origin1,2230 collection_id,2231 account(2)2232 ));22332234 assert_ok!(TemplateModule::create_item(2235 origin2,2236 collection_id,2237 account(2),2238 default_nft_data().into()2239 ));2240 });2241}224222432244#[test]2245fn total_number_collections_bound() {2246 new_test_ext().execute_with(|| {2247 create_test_collection(&CollectionMode::NFT, CollectionId(1));2248 });2249}22502251#[test]2252fn create_max_collections() {2253 new_test_ext().execute_with(|| {2254 for i in 1..COLLECTION_NUMBER_LIMIT {2255 create_test_collection(&CollectionMode::NFT, CollectionId(i));2256 }2257 });2258}225922602261#[test]2262fn total_number_collections_bound_neg() {2263 new_test_ext().execute_with(|| {2264 let origin1 = Origin::signed(1);22652266 for i in 1..=COLLECTION_NUMBER_LIMIT {2267 create_test_collection(&CollectionMode::NFT, CollectionId(i));2268 }22692270 let col_name1: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();2271 let col_desc1: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();2272 let token_prefix1: Vec<u8> = b"token_prefix1\0".to_vec();22732274 let data: CreateCollectionData<u64> = CreateCollectionData {2275 name: col_name1.try_into().unwrap(),2276 description: col_desc1.try_into().unwrap(),2277 token_prefix: token_prefix1.try_into().unwrap(),2278 mode: CollectionMode::NFT,2279 ..Default::default()2280 };22812282 2283 assert_noop!(2284 TemplateModule::create_collection_ex(origin1, data),2285 CommonError::<Test>::TotalCollectionsLimitExceeded2286 );2287 });2288}228922902291#[test]2292fn owned_tokens_bound() {2293 new_test_ext().execute_with(|| {2294 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));22952296 let data = default_nft_data();2297 create_test_item(collection_id, &data.clone().into());2298 create_test_item(collection_id, &data.into());2299 });2300}230123022303#[test]2304fn owned_tokens_bound_neg() {2305 new_test_ext().execute_with(|| {2306 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));23072308 let origin1 = Origin::signed(1);23092310 for _ in 1..=MAX_TOKEN_OWNERSHIP {2311 let data = default_nft_data();2312 create_test_item(collection_id, &data.clone().into());2313 }23142315 let data = default_nft_data();2316 assert_noop!(2317 TemplateModule::create_item(origin1, CollectionId(1), account(1), data.into())2318 .map_err(|e| e.error),2319 CommonError::<Test>::AccountTokenLimitExceeded2320 );2321 });2322}232323242325#[test]2326fn collection_admins_bound() {2327 new_test_ext().execute_with(|| {2328 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));23292330 let origin1 = Origin::signed(1);23312332 assert_ok!(TemplateModule::add_collection_admin(2333 origin1.clone(),2334 collection_id,2335 account(2)2336 ));2337 assert_ok!(TemplateModule::add_collection_admin(2338 origin1,2339 collection_id,2340 account(3)2341 ));2342 });2343}234423452346#[test]2347fn collection_admins_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 i in 0..COLLECTION_ADMINS_LIMIT {2354 assert_ok!(TemplateModule::add_collection_admin(2355 origin1.clone(),2356 collection_id,2357 account((2 + i).into())2358 ));2359 }2360 assert_noop!(2361 TemplateModule::add_collection_admin(2362 origin1,2363 collection_id,2364 account((3 + COLLECTION_ADMINS_LIMIT).into())2365 ),2366 CommonError::<Test>::CollectionAdminCountExceeded2367 );2368 });2369}237023712372#[test]2373fn set_const_on_chain_schema() {2374 new_test_ext().execute_with(|| {2375 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));23762377 let origin1 = Origin::signed(1);2378 assert_ok!(TemplateModule::set_const_on_chain_schema(2379 origin1,2380 collection_id,2381 b"test const on chain schema".to_vec().try_into().unwrap()2382 ));23832384 assert_eq!(2385 <pallet_common::CollectionById<Test>>::get(collection_id)2386 .unwrap()2387 .const_on_chain_schema,2388 b"test const on chain schema".to_vec()2389 );2390 assert_eq!(2391 <pallet_common::CollectionById<Test>>::get(collection_id)2392 .unwrap()2393 .variable_on_chain_schema,2394 b"".to_vec()2395 );2396 });2397}23982399#[test]2400fn set_variable_on_chain_schema() {2401 new_test_ext().execute_with(|| {2402 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));24032404 let origin1 = Origin::signed(1);2405 assert_ok!(TemplateModule::set_variable_on_chain_schema(2406 origin1,2407 collection_id,2408 b"test variable on chain schema"2409 .to_vec()2410 .try_into()2411 .unwrap()2412 ));24132414 assert_eq!(2415 <pallet_common::CollectionById<Test>>::get(collection_id)2416 .unwrap()2417 .const_on_chain_schema,2418 b"".to_vec()2419 );2420 assert_eq!(2421 <pallet_common::CollectionById<Test>>::get(collection_id)2422 .unwrap()2423 .variable_on_chain_schema,2424 b"test variable on chain schema".to_vec()2425 );2426 });2427}24282429#[test]2430fn set_variable_meta_data_on_nft_token_stores_variable_meta_data() {2431 new_test_ext().execute_with(|| {2432 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));24332434 let origin1 = Origin::signed(1);24352436 let data = default_nft_data();2437 create_test_item(CollectionId(1), &data.into());24382439 let variable_data = b"test data".to_vec();2440 assert_ok!(TemplateModule::set_variable_meta_data(2441 origin1,2442 collection_id,2443 TokenId(1),2444 variable_data.clone().try_into().unwrap()2445 ));24462447 assert_eq!(2448 <pallet_nonfungible::TokenData<Test>>::get((collection_id, 1))2449 .unwrap()2450 .variable_data,2451 variable_data2452 );2453 });2454}24552456#[test]2457fn set_variable_meta_data_on_re_fungible_token_stores_variable_meta_data() {2458 new_test_ext().execute_with(|| {2459 let collection_id = create_test_collection(&CollectionMode::ReFungible, CollectionId(1));24602461 let origin1 = Origin::signed(1);24622463 let data = default_re_fungible_data();2464 create_test_item(collection_id, &data.into());24652466 let variable_data = b"test data".to_vec();2467 assert_ok!(TemplateModule::set_variable_meta_data(2468 origin1,2469 collection_id,2470 TokenId(1),2471 variable_data.clone().try_into().unwrap()2472 ));24732474 assert_eq!(2475 <pallet_refungible::TokenData<Test>>::get((collection_id, TokenId(1))).variable_data,2476 variable_data2477 );2478 });2479}24802481#[test]2482fn set_variable_meta_data_on_fungible_token_fails() {2483 new_test_ext().execute_with(|| {2484 let collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));24852486 let origin1 = Origin::signed(1);24872488 let data = default_fungible_data();2489 create_test_item(collection_id, &data.into());24902491 let variable_data = b"test data".to_vec();2492 assert_noop!(2493 TemplateModule::set_variable_meta_data(2494 origin1,2495 collection_id,2496 TokenId(0),2497 variable_data.try_into().unwrap()2498 )2499 .map_err(|e| e.error),2500 <pallet_fungible::Error<Test>>::FungibleItemsDontHaveData2501 );2502 });2503}25042505#[test]2506fn set_variable_meta_data_on_nft_with_item_owner_permission_flag() {2507 new_test_ext().execute_with(|| {2508 25092510 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));25112512 let origin1 = Origin::signed(1);25132514 let data = default_nft_data();2515 create_test_item(collection_id, &data.into());25162517 assert_ok!(TemplateModule::set_meta_update_permission_flag(2518 origin1.clone(),2519 collection_id,2520 MetaUpdatePermission::ItemOwner,2521 ));25222523 let variable_data = b"ten chars.".to_vec();2524 assert_ok!(TemplateModule::set_variable_meta_data(2525 origin1,2526 collection_id,2527 TokenId(1),2528 variable_data.clone().try_into().unwrap()2529 ));25302531 assert_eq!(2532 <pallet_nonfungible::TokenData<Test>>::get((collection_id, TokenId(1)))2533 .unwrap()2534 .variable_data,2535 variable_data2536 );2537 });2538}25392540#[test]2541fn collection_transfer_flag_works() {2542 new_test_ext().execute_with(|| {2543 let origin1 = Origin::signed(1);25442545 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));2546 assert_ok!(TemplateModule::set_transfers_enabled_flag(2547 origin1,2548 collection_id,2549 true2550 ));25512552 let data = default_nft_data();2553 create_test_item(collection_id, &data.into());2554 assert_eq!(2555 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),2556 12557 );2558 assert_eq!(2559 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),2560 true2561 );25622563 let origin1 = Origin::signed(1);25642565 2566 assert_ok!(TemplateModule::transfer(2567 origin1,2568 account(2),2569 collection_id,2570 TokenId(1),2571 12572 ));2573 assert_eq!(2574 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),2575 false2576 );2577 assert_eq!(2578 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))),2579 true2580 );2581 assert_eq!(2582 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),2583 02584 );2585 assert_eq!(2586 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(2))),2587 12588 );2589 });2590}25912592#[test]2593fn set_variable_meta_data_on_nft_with_admin_flag() {2594 new_test_ext().execute_with(|| {2595 25962597 let collection_id =2598 create_test_collection_for_owner(&CollectionMode::NFT, 2, CollectionId(1));25992600 let origin1 = Origin::signed(1);2601 let origin2 = Origin::signed(2);26022603 assert_ok!(TemplateModule::set_mint_permission(2604 origin2.clone(),2605 collection_id,2606 true2607 ));2608 assert_ok!(TemplateModule::add_to_allow_list(2609 origin2.clone(),2610 collection_id,2611 account(1)2612 ));26132614 assert_ok!(TemplateModule::add_collection_admin(2615 origin2.clone(),2616 collection_id,2617 account(1)2618 ));26192620 let data = default_nft_data();2621 create_test_item(collection_id, &data.into());26222623 assert_ok!(TemplateModule::set_meta_update_permission_flag(2624 origin2.clone(),2625 collection_id,2626 MetaUpdatePermission::Admin,2627 ));26282629 let variable_data = b"test.".to_vec();2630 assert_ok!(TemplateModule::set_variable_meta_data(2631 origin1,2632 collection_id,2633 TokenId(1),2634 variable_data.clone().try_into().unwrap()2635 ));26362637 assert_eq!(2638 <pallet_nonfungible::TokenData<Test>>::get((collection_id, 1))2639 .unwrap()2640 .variable_data,2641 variable_data2642 );2643 });2644}26452646#[test]2647fn set_variable_meta_data_on_nft_with_admin_flag_neg() {2648 new_test_ext().execute_with(|| {2649 26502651 let collection_id =2652 create_test_collection_for_owner(&CollectionMode::NFT, 2, CollectionId(1));26532654 let origin1 = Origin::signed(1);2655 let origin2 = Origin::signed(2);26562657 assert_ok!(TemplateModule::set_mint_permission(2658 origin2.clone(),2659 collection_id,2660 true2661 ));2662 assert_ok!(TemplateModule::add_to_allow_list(2663 origin2.clone(),2664 collection_id,2665 account(1)2666 ));26672668 let data = default_nft_data();2669 create_test_item(collection_id, &data.into());26702671 assert_ok!(TemplateModule::set_meta_update_permission_flag(2672 origin2.clone(),2673 collection_id,2674 MetaUpdatePermission::Admin,2675 ));26762677 let variable_data = b"test.".to_vec();2678 assert_noop!(2679 TemplateModule::set_variable_meta_data(2680 origin1,2681 collection_id,2682 TokenId(1),2683 variable_data.try_into().unwrap()2684 )2685 .map_err(|e| e.error),2686 CommonError::<Test>::NoPermission2687 );2688 });2689}26902691#[test]2692fn set_variable_meta_flag_after_freeze() {2693 new_test_ext().execute_with(|| {2694 26952696 let collection_id =2697 create_test_collection_for_owner(&CollectionMode::NFT, 2, CollectionId(1));26982699 let origin2 = Origin::signed(2);27002701 assert_ok!(TemplateModule::set_meta_update_permission_flag(2702 origin2.clone(),2703 collection_id,2704 MetaUpdatePermission::None,2705 ));2706 assert_noop!(2707 TemplateModule::set_meta_update_permission_flag(2708 origin2.clone(),2709 collection_id,2710 MetaUpdatePermission::Admin2711 ),2712 CommonError::<Test>::MetadataFlagFrozen2713 );2714 });2715}27162717#[test]2718fn set_variable_meta_data_on_nft_with_none_flag_neg() {2719 new_test_ext().execute_with(|| {2720 27212722 let collection_id =2723 create_test_collection_for_owner(&CollectionMode::NFT, 1, CollectionId(1));2724 let origin1 = Origin::signed(1);27252726 let data = default_nft_data();2727 create_test_item(collection_id, &data.into());27282729 assert_ok!(TemplateModule::set_meta_update_permission_flag(2730 origin1.clone(),2731 collection_id,2732 MetaUpdatePermission::None,2733 ));27342735 let variable_data = b"test.".to_vec();2736 assert_noop!(2737 TemplateModule::set_variable_meta_data(2738 origin1.clone(),2739 collection_id,2740 TokenId(1),2741 variable_data.try_into().unwrap()2742 )2743 .map_err(|e| e.error),2744 CommonError::<Test>::NoPermission2745 );2746 });2747}27482749#[test]2750fn collection_transfer_flag_works_neg() {2751 new_test_ext().execute_with(|| {2752 let origin1 = Origin::signed(1);27532754 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));2755 assert_ok!(TemplateModule::set_transfers_enabled_flag(2756 origin1,2757 collection_id,2758 false2759 ));27602761 let data = default_nft_data();2762 create_test_item(collection_id, &data.into());2763 assert_eq!(2764 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),2765 12766 );2767 assert_eq!(2768 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),2769 true2770 );27712772 let origin1 = Origin::signed(1);27732774 2775 assert_noop!(2776 TemplateModule::transfer(origin1, account(2), CollectionId(1), TokenId(1), 1)2777 .map_err(|e| e.error),2778 CommonError::<Test>::TransferNotAllowed2779 );2780 assert_eq!(2781 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),2782 12783 );2784 assert_eq!(2785 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(2))),2786 02787 );2788 assert_eq!(2789 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),2790 true2791 );2792 assert_eq!(2793 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))),2794 false2795 );2796 });2797}