difftreelog
fix(tests) fix default_nft_data
in: master
1 file changed
runtime/tests/src/tests.rsdiffbeforeafterboth1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617// Tests to be written here18use crate::{Test, TestCrossAccountId, CollectionCreationPrice, Origin, Unique, new_test_ext};19use up_data_structs::{20 COLLECTION_NUMBER_LIMIT, CollectionId, CreateItemData, CreateFungibleData, CreateNftData,21 CreateReFungibleData, MAX_DECIMAL_POINTS, COLLECTION_ADMINS_LIMIT,22 TokenId, MAX_TOKEN_OWNERSHIP, CreateCollectionData, CollectionField, SchemaVersion,23 CollectionMode, AccessMode,24};25use frame_support::{assert_noop, assert_ok, assert_err};26use sp_std::convert::TryInto;27use pallet_evm::account::CrossAccountId;28use pallet_common::Error as CommonError;29use pallet_unique::Error as UniqueError;3031fn add_balance(user: u64, value: u64) {32 const DONOR_USER: u64 = 999;33 assert_ok!(<pallet_balances::Pallet<Test>>::set_balance(34 Origin::root(),35 DONOR_USER,36 value,37 038 ));39 assert_ok!(<pallet_balances::Pallet<Test>>::force_transfer(40 Origin::root(),41 DONOR_USER,42 user,43 value44 ));45}4647fn default_nft_data() -> CreateNftData {48 CreateNftData {49 const_data: vec![1, 2, 3].try_into().unwrap(),50 }51}5253fn default_fungible_data() -> CreateFungibleData {54 CreateFungibleData { value: 5 }55}5657fn default_re_fungible_data() -> CreateReFungibleData {58 CreateReFungibleData {59 const_data: vec![1, 2, 3].try_into().unwrap(),60 pieces: 1023,61 }62}6364fn create_test_collection_for_owner(65 mode: &CollectionMode,66 owner: u64,67 id: CollectionId,68) -> CollectionId {69 add_balance(owner, CollectionCreationPrice::get() as u64 + 1);7071 let col_name1: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();72 let col_desc1: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();73 let token_prefix1: Vec<u8> = b"token_prefix1\0".to_vec();7475 let data: CreateCollectionData<u64> = CreateCollectionData {76 name: col_name1.try_into().unwrap(),77 description: col_desc1.try_into().unwrap(),78 token_prefix: token_prefix1.try_into().unwrap(),79 mode: mode.clone(),80 ..Default::default()81 };8283 let origin1 = Origin::signed(owner);84 assert_ok!(Unique::create_collection_ex(origin1, data));8586 let saved_col_name: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();87 let saved_description: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();88 let saved_prefix: Vec<u8> = b"token_prefix1\0".to_vec();89 assert_eq!(90 <pallet_common::CollectionById<Test>>::get(id)91 .unwrap()92 .owner,93 owner94 );95 assert_eq!(96 <pallet_common::CollectionById<Test>>::get(id).unwrap().name,97 saved_col_name98 );99 assert_eq!(100 <pallet_common::CollectionById<Test>>::get(id).unwrap().mode,101 *mode102 );103 assert_eq!(104 <pallet_common::CollectionById<Test>>::get(id)105 .unwrap()106 .description,107 saved_description108 );109 assert_eq!(110 <pallet_common::CollectionById<Test>>::get(id)111 .unwrap()112 .token_prefix,113 saved_prefix114 );115 id116}117118fn create_test_collection(mode: &CollectionMode, id: CollectionId) -> CollectionId {119 create_test_collection_for_owner(&mode, 1, id)120}121122fn create_test_item(collection_id: CollectionId, data: &CreateItemData) {123 let origin1 = Origin::signed(1);124 assert_ok!(Unique::create_item(125 origin1,126 collection_id,127 account(1),128 data.clone()129 ));130}131132fn account(sub: u64) -> TestCrossAccountId {133 TestCrossAccountId::from_sub(sub)134}135136// Use cases tests region137// #region138139#[test]140fn set_version_schema() {141 new_test_ext().execute_with(|| {142 let origin1 = Origin::signed(1);143 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));144145 assert_ok!(Unique::set_schema_version(146 origin1,147 collection_id,148 SchemaVersion::Unique149 ));150 assert_eq!(151 <pallet_common::CollectionById<Test>>::get(collection_id)152 .unwrap()153 .schema_version,154 SchemaVersion::Unique155 );156 });157}158159#[test]160fn check_not_sufficient_founds() {161 new_test_ext().execute_with(|| {162 let acc: u64 = 1;163 <pallet_balances::Pallet<Test>>::set_balance(Origin::root(), acc, 0, 0).unwrap();164165 let name: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();166 let description: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();167 let token_prefix: Vec<u8> = b"token_prefix1\0".to_vec();168169 let data: CreateCollectionData<<Test as frame_system::Config>::AccountId> =170 CreateCollectionData {171 name: name.try_into().unwrap(),172 description: description.try_into().unwrap(),173 token_prefix: token_prefix.try_into().unwrap(),174 mode: CollectionMode::NFT,175 ..Default::default()176 };177178 let result = Unique::create_collection_ex(Origin::signed(acc), data);179 assert_err!(result, <CommonError<Test>>::NotSufficientFounds);180 });181}182183#[test]184fn create_fungible_collection_fails_with_large_decimal_numbers() {185 new_test_ext().execute_with(|| {186 let col_name1: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();187 let col_desc1: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();188 let token_prefix1: Vec<u8> = b"token_prefix1\0".to_vec();189190 let data: CreateCollectionData<u64> = CreateCollectionData {191 name: col_name1.try_into().unwrap(),192 description: col_desc1.try_into().unwrap(),193 token_prefix: token_prefix1.try_into().unwrap(),194 mode: CollectionMode::Fungible(MAX_DECIMAL_POINTS + 1),195 ..Default::default()196 };197198 let origin1 = Origin::signed(1);199 assert_noop!(200 Unique::create_collection_ex(origin1, data),201 UniqueError::<Test>::CollectionDecimalPointLimitExceeded202 );203 });204}205206#[test]207fn create_nft_item() {208 new_test_ext().execute_with(|| {209 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));210211 let data = default_nft_data();212 create_test_item(collection_id, &data.clone().into());213214 let item = <pallet_nonfungible::TokenData<Test>>::get((collection_id, 1)).unwrap();215 assert_eq!(item.const_data, data.const_data.into_inner());216 });217}218219// Use cases tests region220// #region221#[test]222fn create_nft_multiple_items() {223 new_test_ext().execute_with(|| {224 create_test_collection(&CollectionMode::NFT, CollectionId(1));225226 let origin1 = Origin::signed(1);227228 let items_data = vec![default_nft_data(), default_nft_data(), default_nft_data()];229230 assert_ok!(Unique::create_multiple_items(231 origin1,232 CollectionId(1),233 account(1),234 items_data235 .clone()236 .into_iter()237 .map(|d| { d.into() })238 .collect()239 ));240 for (index, data) in items_data.into_iter().enumerate() {241 let item = <pallet_nonfungible::TokenData<Test>>::get((242 CollectionId(1),243 TokenId((index + 1) as u32),244 ))245 .unwrap();246 assert_eq!(item.const_data.to_vec(), data.const_data.into_inner());247 }248 });249}250251#[test]252fn create_refungible_item() {253 new_test_ext().execute_with(|| {254 let collection_id = create_test_collection(&CollectionMode::ReFungible, CollectionId(1));255256 let data = default_re_fungible_data();257 create_test_item(collection_id, &data.clone().into());258 let item = <pallet_refungible::TokenData<Test>>::get((collection_id, TokenId(1)));259 let balance =260 <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1)));261 assert_eq!(item.const_data, data.const_data.into_inner());262 assert_eq!(balance, 1023);263 });264}265266#[test]267fn create_multiple_refungible_items() {268 new_test_ext().execute_with(|| {269 create_test_collection(&CollectionMode::ReFungible, CollectionId(1));270271 let origin1 = Origin::signed(1);272273 let items_data = vec![274 default_re_fungible_data(),275 default_re_fungible_data(),276 default_re_fungible_data(),277 ];278279 assert_ok!(Unique::create_multiple_items(280 origin1,281 CollectionId(1),282 account(1),283 items_data284 .clone()285 .into_iter()286 .map(|d| { d.into() })287 .collect()288 ));289 for (index, data) in items_data.into_iter().enumerate() {290 let item = <pallet_refungible::TokenData<Test>>::get((291 CollectionId(1),292 TokenId((index + 1) as u32),293 ));294 let balance =295 <pallet_refungible::Balance<Test>>::get((CollectionId(1), TokenId(1), account(1)));296 assert_eq!(item.const_data.to_vec(), data.const_data.into_inner());297 assert_eq!(balance, 1023);298 }299 });300}301302#[test]303fn create_fungible_item() {304 new_test_ext().execute_with(|| {305 let collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));306307 let data = default_fungible_data();308 create_test_item(collection_id, &data.into());309310 assert_eq!(311 <pallet_fungible::Balance<Test>>::get((collection_id, account(1))),312 5313 );314 });315}316317//#[test]318// fn create_multiple_fungible_items() {319// new_test_ext().execute_with(|| {320// default_limits();321322// create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));323324// let origin1 = Origin::signed(1);325326// let items_data = vec![default_fungible_data(), default_fungible_data(), default_fungible_data()];327328// assert_ok!(Unique::create_multiple_items(329// origin1.clone(),330// 1,331// 1,332// items_data.clone().into_iter().map(|d| { d.into() }).collect()333// ));334335// for (index, _) in items_data.iter().enumerate() {336// assert_eq!(Unique::fungible_item_id(1, (index + 1) as TokenId).value, 5);337// }338// assert_eq!(Unique::balance_count(1, 1), 3000);339// assert_eq!(Unique::address_tokens(1, 1), [1, 2, 3]);340// });341// }342343#[test]344fn transfer_fungible_item() {345 new_test_ext().execute_with(|| {346 let collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));347348 let origin1 = Origin::signed(1);349 let origin2 = Origin::signed(2);350351 let data = default_fungible_data();352 create_test_item(collection_id, &data.into());353354 assert_eq!(355 <pallet_fungible::Balance<Test>>::get((CollectionId(1), account(1))),356 5357 );358359 // change owner scenario360 assert_ok!(Unique::transfer(361 origin1,362 account(2),363 CollectionId(1),364 TokenId(0),365 5366 ));367 assert_eq!(368 <pallet_fungible::Balance<Test>>::get((CollectionId(1), account(1))),369 0370 );371372 // split item scenario373 assert_ok!(Unique::transfer(374 origin2.clone(),375 account(3),376 CollectionId(1),377 TokenId(0),378 3379 ));380381 // split item and new owner has account scenario382 assert_ok!(Unique::transfer(383 origin2,384 account(3),385 CollectionId(1),386 TokenId(0),387 1388 ));389 assert_eq!(390 <pallet_fungible::Balance<Test>>::get((CollectionId(1), account(2))),391 1392 );393 assert_eq!(394 <pallet_fungible::Balance<Test>>::get((CollectionId(1), account(3))),395 4396 );397 });398}399400#[test]401fn transfer_refungible_item() {402 new_test_ext().execute_with(|| {403 let collection_id = create_test_collection(&CollectionMode::ReFungible, CollectionId(1));404405 // Create RFT 1 in 1023 pieces for account 1406 let data = default_re_fungible_data();407 create_test_item(collection_id, &data.clone().into());408 let item = <pallet_refungible::TokenData<Test>>::get((collection_id, TokenId(1)));409 assert_eq!(item.const_data, data.const_data.into_inner());410 assert_eq!(411 <pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))),412 1413 );414 assert_eq!(415 <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1))),416 1023417 );418 assert_eq!(419 <pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),420 true421 );422423 // Account 1 transfers all 1023 pieces of RFT 1 to account 2424 let origin1 = Origin::signed(1);425 let origin2 = Origin::signed(2);426 assert_ok!(Unique::transfer(427 origin1,428 account(2),429 CollectionId(1),430 TokenId(1),431 1023432 ));433 assert_eq!(434 <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(2))),435 1023436 );437 assert_eq!(438 <pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))),439 0440 );441 assert_eq!(442 <pallet_refungible::AccountBalance<Test>>::get((collection_id, account(2))),443 1444 );445 assert_eq!(446 <pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),447 false448 );449 assert_eq!(450 <pallet_refungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))),451 true452 );453454 // Account 2 transfers 500 pieces of RFT 1 to account 3455 assert_ok!(Unique::transfer(456 origin2.clone(),457 account(3),458 CollectionId(1),459 TokenId(1),460 500461 ));462 assert_eq!(463 <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(2))),464 523465 );466 assert_eq!(467 <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(3))),468 500469 );470 assert_eq!(471 <pallet_refungible::AccountBalance<Test>>::get((collection_id, account(2))),472 1473 );474 assert_eq!(475 <pallet_refungible::AccountBalance<Test>>::get((collection_id, account(3))),476 1477 );478 assert_eq!(479 <pallet_refungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))),480 true481 );482 assert_eq!(483 <pallet_refungible::Owned<Test>>::get((collection_id, account(3), TokenId(1))),484 true485 );486487 // Account 2 transfers 200 more pieces of RFT 1 to account 3 with pre-existing balance488 assert_ok!(Unique::transfer(489 origin2,490 account(3),491 CollectionId(1),492 TokenId(1),493 200494 ));495 assert_eq!(496 <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(2))),497 323498 );499 assert_eq!(500 <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(3))),501 700502 );503 assert_eq!(504 <pallet_refungible::AccountBalance<Test>>::get((collection_id, account(2))),505 1506 );507 assert_eq!(508 <pallet_refungible::AccountBalance<Test>>::get((collection_id, account(3))),509 1510 );511 assert_eq!(512 <pallet_refungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))),513 true514 );515 assert_eq!(516 <pallet_refungible::Owned<Test>>::get((collection_id, account(3), TokenId(1))),517 true518 );519 });520}521522#[test]523fn transfer_nft_item() {524 new_test_ext().execute_with(|| {525 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));526527 let data = default_nft_data();528 create_test_item(collection_id, &data.into());529 assert_eq!(530 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),531 1532 );533 assert_eq!(534 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),535 true536 );537538 let origin1 = Origin::signed(1);539 // default scenario540 assert_ok!(Unique::transfer(541 origin1,542 account(2),543 CollectionId(1),544 TokenId(1),545 1546 ));547 assert_eq!(548 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),549 0550 );551 assert_eq!(552 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(2))),553 1554 );555 assert_eq!(556 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),557 false558 );559 assert_eq!(560 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))),561 true562 );563 });564}565566#[test]567fn transfer_nft_item_wrong_value() {568 new_test_ext().execute_with(|| {569 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));570571 let data = default_nft_data();572 create_test_item(collection_id, &data.into());573 assert_eq!(574 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),575 1576 );577 assert_eq!(578 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),579 true580 );581582 let origin1 = Origin::signed(1);583584 assert_noop!(585 Unique::transfer(origin1, account(2), CollectionId(1), TokenId(1), 2)586 .map_err(|e| e.error),587 <pallet_nonfungible::Error::<Test>>::NonfungibleItemsHaveNoAmount588 );589 });590}591592#[test]593fn transfer_nft_item_zero_value() {594 new_test_ext().execute_with(|| {595 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));596597 let data = default_nft_data();598 create_test_item(collection_id, &data.into());599 assert_eq!(600 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),601 1602 );603 assert_eq!(604 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),605 true606 );607608 let origin1 = Origin::signed(1);609610 // Transferring 0 amount works on NFT...611 assert_ok!(Unique::transfer(612 origin1,613 account(2),614 CollectionId(1),615 TokenId(1),616 0617 ));618 // ... and results in no transfer619 assert_eq!(620 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),621 1622 );623 assert_eq!(624 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),625 true626 );627 });628}629630#[test]631fn nft_approve_and_transfer_from() {632 new_test_ext().execute_with(|| {633 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));634635 let data = default_nft_data();636 create_test_item(collection_id, &data.into());637638 let origin1 = Origin::signed(1);639 let origin2 = Origin::signed(2);640641 assert_eq!(642 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),643 1644 );645 assert_eq!(646 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),647 true648 );649650 // neg transfer_from651 assert_noop!(652 Unique::transfer_from(653 origin2.clone(),654 account(1),655 account(2),656 CollectionId(1),657 TokenId(1),658 1659 )660 .map_err(|e| e.error),661 CommonError::<Test>::ApprovedValueTooLow662 );663664 // do approve665 assert_ok!(Unique::approve(666 origin1,667 account(2),668 CollectionId(1),669 TokenId(1),670 1671 ));672 assert_eq!(673 <pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),674 account(2)675 );676677 assert_ok!(Unique::transfer_from(678 origin2,679 account(1),680 account(3),681 CollectionId(1),682 TokenId(1),683 1684 ));685 assert!(686 <pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).is_none()687 );688 });689}690691#[test]692fn nft_approve_and_transfer_from_allow_list() {693 new_test_ext().execute_with(|| {694 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));695696 let origin1 = Origin::signed(1);697 let origin2 = Origin::signed(2);698699 // Create NFT 1 for account 1700 let data = default_nft_data();701 create_test_item(collection_id, &data.clone().into());702 assert_eq!(703 &<pallet_nonfungible::TokenData<Test>>::get((collection_id, TokenId(1)))704 .unwrap()705 .const_data,706 &data.const_data.into_inner()707 );708 assert_eq!(709 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),710 1711 );712 assert_eq!(713 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),714 true715 );716717 // Allow allow-list users to mint and add accounts 1, 2, and 3 to allow-list718 assert_ok!(Unique::set_mint_permission(719 origin1.clone(),720 CollectionId(1),721 true722 ));723 assert_ok!(Unique::set_public_access_mode(724 origin1.clone(),725 CollectionId(1),726 AccessMode::AllowList727 ));728 assert_ok!(Unique::add_to_allow_list(729 origin1.clone(),730 CollectionId(1),731 account(1)732 ));733 assert_ok!(Unique::add_to_allow_list(734 origin1.clone(),735 CollectionId(1),736 account(2)737 ));738 assert_ok!(Unique::add_to_allow_list(739 origin1.clone(),740 CollectionId(1),741 account(3)742 ));743744 // Account 1 approves account 2 for NFT 1745 assert_ok!(Unique::approve(746 origin1.clone(),747 account(2),748 CollectionId(1),749 TokenId(1),750 1751 ));752 assert_eq!(753 <pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),754 account(2)755 );756757 // Account 2 transfers NFT 1 from account 1 to account 3758 assert_ok!(Unique::transfer_from(759 origin2,760 account(1),761 account(3),762 CollectionId(1),763 TokenId(1),764 1765 ));766 assert!(767 <pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).is_none()768 );769 });770}771772#[test]773fn refungible_approve_and_transfer_from() {774 new_test_ext().execute_with(|| {775 let collection_id = create_test_collection(&CollectionMode::ReFungible, CollectionId(1));776777 let origin1 = Origin::signed(1);778 let origin2 = Origin::signed(2);779780 // Create RFT 1 in 1023 pieces for account 1781 let data = default_re_fungible_data();782 create_test_item(collection_id, &data.into());783784 assert_eq!(785 <pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))),786 1787 );788 assert_eq!(789 <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1))),790 1023791 );792 assert_eq!(793 <pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),794 true795 );796797 // Allow public minting, enable allow-list and add accounts 1, 2, 3 to allow-list798 assert_ok!(Unique::set_mint_permission(799 origin1.clone(),800 CollectionId(1),801 true802 ));803 assert_ok!(Unique::set_public_access_mode(804 origin1.clone(),805 CollectionId(1),806 AccessMode::AllowList807 ));808 assert_ok!(Unique::add_to_allow_list(809 origin1.clone(),810 CollectionId(1),811 account(1)812 ));813 assert_ok!(Unique::add_to_allow_list(814 origin1.clone(),815 CollectionId(1),816 account(2)817 ));818 assert_ok!(Unique::add_to_allow_list(819 origin1.clone(),820 CollectionId(1),821 account(3)822 ));823824 // Account 1 approves account 2 for 1023 pieces of RFT 1825 assert_ok!(Unique::approve(826 origin1,827 account(2),828 CollectionId(1),829 TokenId(1),830 1023831 ));832 assert_eq!(833 <pallet_refungible::Allowance<Test>>::get((834 CollectionId(1),835 TokenId(1),836 account(1),837 account(2)838 )),839 1023840 );841842 // Account 2 transfers 100 pieces of RFT 1 from account 1 to account 3843 assert_ok!(Unique::transfer_from(844 origin2,845 account(1),846 account(3),847 CollectionId(1),848 TokenId(1),849 100850 ));851 assert_eq!(852 <pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))),853 1854 );855 assert_eq!(856 <pallet_refungible::AccountBalance<Test>>::get((collection_id, account(3))),857 1858 );859 assert_eq!(860 <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1))),861 923862 );863 assert_eq!(864 <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(3))),865 100866 );867 assert_eq!(868 <pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),869 true870 );871 assert_eq!(872 <pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),873 true874 );875 assert_eq!(876 <pallet_refungible::Allowance<Test>>::get((877 CollectionId(1),878 TokenId(1),879 account(1),880 account(2)881 )),882 923883 );884 });885}886887#[test]888fn fungible_approve_and_transfer_from() {889 new_test_ext().execute_with(|| {890 let collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));891892 let data = default_fungible_data();893 create_test_item(collection_id, &data.into());894895 let origin1 = Origin::signed(1);896 let origin2 = Origin::signed(2);897898 assert_ok!(Unique::set_mint_permission(899 origin1.clone(),900 CollectionId(1),901 true902 ));903 assert_ok!(Unique::set_public_access_mode(904 origin1.clone(),905 CollectionId(1),906 AccessMode::AllowList907 ));908 assert_ok!(Unique::add_to_allow_list(909 origin1.clone(),910 CollectionId(1),911 account(1)912 ));913 assert_ok!(Unique::add_to_allow_list(914 origin1.clone(),915 CollectionId(1),916 account(2)917 ));918 assert_ok!(Unique::add_to_allow_list(919 origin1.clone(),920 CollectionId(1),921 account(3)922 ));923924 // do approve925 assert_ok!(Unique::approve(926 origin1.clone(),927 account(2),928 CollectionId(1),929 TokenId(0),930 5931 ));932 assert_eq!(933 <pallet_fungible::Allowance<Test>>::get((CollectionId(1), account(1), account(2))),934 5935 );936 assert_ok!(Unique::approve(937 origin1,938 account(3),939 CollectionId(1),940 TokenId(0),941 5942 ));943 assert_eq!(944 <pallet_fungible::Allowance<Test>>::get((CollectionId(1), account(1), account(2))),945 5946 );947 assert_eq!(948 <pallet_fungible::Allowance<Test>>::get((CollectionId(1), account(1), account(3))),949 5950 );951952 assert_ok!(Unique::transfer_from(953 origin2.clone(),954 account(1),955 account(3),956 CollectionId(1),957 TokenId(0),958 4959 ));960961 assert_eq!(962 <pallet_fungible::Allowance<Test>>::get((CollectionId(1), account(1), account(2))),963 1964 );965966 assert_noop!(967 Unique::transfer_from(968 origin2,969 account(1),970 account(3),971 CollectionId(1),972 TokenId(0),973 4974 )975 .map_err(|e| e.error),976 CommonError::<Test>::ApprovedValueTooLow977 );978 });979}980981#[test]982fn change_collection_owner() {983 new_test_ext().execute_with(|| {984 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));985986 let origin1 = Origin::signed(1);987 assert_ok!(Unique::change_collection_owner(origin1, collection_id, 2));988 assert_eq!(989 <pallet_common::CollectionById<Test>>::get(collection_id)990 .unwrap()991 .owner,992 2993 );994 });995}996997#[test]998fn destroy_collection() {999 new_test_ext().execute_with(|| {1000 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));10011002 let origin1 = Origin::signed(1);1003 assert_ok!(Unique::destroy_collection(origin1, collection_id));1004 });1005}10061007#[test]1008fn burn_nft_item() {1009 new_test_ext().execute_with(|| {1010 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));10111012 let origin1 = Origin::signed(1);10131014 let data = default_nft_data();1015 create_test_item(collection_id, &data.into());10161017 // check balance (collection with id = 1, user id = 1)1018 assert_eq!(1019 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),1020 11021 );10221023 // burn item1024 assert_ok!(Unique::burn_item(1025 origin1.clone(),1026 collection_id,1027 TokenId(1),1028 11029 ));1030 assert_eq!(1031 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),1032 01033 );1034 });1035}10361037#[test]1038fn burn_same_nft_item_twice() {1039 new_test_ext().execute_with(|| {1040 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));10411042 let origin1 = Origin::signed(1);10431044 let data = default_nft_data();1045 create_test_item(collection_id, &data.into());10461047 // check balance (collection with id = 1, user id = 1)1048 assert_eq!(1049 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),1050 11051 );10521053 // burn item1054 assert_ok!(Unique::burn_item(1055 origin1.clone(),1056 collection_id,1057 TokenId(1),1058 11059 ));10601061 // burn item again1062 assert_noop!(1063 Unique::burn_item(origin1, collection_id, TokenId(1), 1).map_err(|e| e.error),1064 CommonError::<Test>::TokenNotFound1065 );10661067 assert_eq!(1068 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),1069 01070 );1071 });1072}10731074#[test]1075fn burn_fungible_item() {1076 new_test_ext().execute_with(|| {1077 let collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));10781079 let origin1 = Origin::signed(1);1080 assert_ok!(Unique::add_collection_admin(1081 origin1.clone(),1082 collection_id,1083 account(2)1084 ));10851086 let data = default_fungible_data();1087 create_test_item(collection_id, &data.into());10881089 // check balance (collection with id = 1, user id = 1)1090 assert_eq!(1091 <pallet_fungible::Balance<Test>>::get((collection_id, account(1))),1092 51093 );10941095 // burn item1096 assert_ok!(Unique::burn_item(1097 origin1.clone(),1098 CollectionId(1),1099 TokenId(0),1100 51101 ));1102 assert_noop!(1103 Unique::burn_item(origin1, CollectionId(1), TokenId(0), 5).map_err(|e| e.error),1104 CommonError::<Test>::TokenValueTooLow1105 );11061107 assert_eq!(1108 <pallet_fungible::Balance<Test>>::get((collection_id, account(1))),1109 01110 );1111 });1112}11131114#[test]1115fn burn_fungible_item_with_token_id() {1116 new_test_ext().execute_with(|| {1117 let collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));11181119 let origin1 = Origin::signed(1);1120 assert_ok!(Unique::add_collection_admin(1121 origin1.clone(),1122 collection_id,1123 account(2)1124 ));11251126 let data = default_fungible_data();1127 create_test_item(collection_id, &data.into());11281129 // check balance (collection with id = 1, user id = 1)1130 assert_eq!(1131 <pallet_fungible::Balance<Test>>::get((collection_id, account(1))),1132 51133 );11341135 // Try to burn item using Token ID1136 assert_noop!(1137 Unique::burn_item(origin1, CollectionId(1), TokenId(1), 5).map_err(|e| e.error),1138 <pallet_fungible::Error::<Test>>::FungibleItemsHaveNoId1139 );1140 });1141}1142#[test]1143fn burn_refungible_item() {1144 new_test_ext().execute_with(|| {1145 let collection_id = create_test_collection(&CollectionMode::ReFungible, CollectionId(1));1146 let origin1 = Origin::signed(1);11471148 assert_ok!(Unique::set_mint_permission(1149 origin1.clone(),1150 collection_id,1151 true1152 ));1153 assert_ok!(Unique::set_public_access_mode(1154 origin1.clone(),1155 collection_id,1156 AccessMode::AllowList1157 ));1158 assert_ok!(Unique::add_to_allow_list(1159 origin1.clone(),1160 collection_id,1161 account(1)1162 ));11631164 assert_ok!(Unique::add_collection_admin(1165 origin1.clone(),1166 collection_id,1167 account(2)1168 ));11691170 let data = default_re_fungible_data();1171 create_test_item(collection_id, &data.into());11721173 // check balance (collection with id = 1, user id = 2)1174 assert_eq!(1175 <pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))),1176 11177 );1178 assert_eq!(1179 <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1))),1180 10231181 );11821183 // burn item1184 assert_ok!(Unique::burn_item(1185 origin1.clone(),1186 collection_id,1187 TokenId(1),1188 10231189 ));1190 assert_noop!(1191 Unique::burn_item(origin1, collection_id, TokenId(1), 1023).map_err(|e| e.error),1192 CommonError::<Test>::TokenValueTooLow1193 );11941195 assert_eq!(1196 <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1))),1197 01198 );1199 });1200}12011202#[test]1203fn add_collection_admin() {1204 new_test_ext().execute_with(|| {1205 let collection1_id =1206 create_test_collection_for_owner(&CollectionMode::NFT, 1, CollectionId(1));1207 let origin1 = Origin::signed(1);12081209 // Add collection admins1210 assert_ok!(Unique::add_collection_admin(1211 origin1.clone(),1212 collection1_id,1213 account(2)1214 ));1215 assert_ok!(Unique::add_collection_admin(1216 origin1,1217 collection1_id,1218 account(3)1219 ));12201221 // Owner is not an admin by default1222 assert_eq!(1223 <pallet_common::IsAdmin<Test>>::get((CollectionId(1), account(1))),1224 false1225 );1226 assert!(<pallet_common::IsAdmin<Test>>::get((1227 CollectionId(1),1228 account(2)1229 )));1230 assert!(<pallet_common::IsAdmin<Test>>::get((1231 CollectionId(1),1232 account(3)1233 )));1234 });1235}12361237#[test]1238fn remove_collection_admin() {1239 new_test_ext().execute_with(|| {1240 let collection1_id =1241 create_test_collection_for_owner(&CollectionMode::NFT, 1, CollectionId(1));1242 let origin1 = Origin::signed(1);1243 let origin2 = Origin::signed(2);12441245 // Add collection admins 2 and 31246 assert_ok!(Unique::add_collection_admin(1247 origin1.clone(),1248 collection1_id,1249 account(2)1250 ));1251 assert_ok!(Unique::add_collection_admin(1252 origin1,1253 collection1_id,1254 account(3)1255 ));12561257 assert!(<pallet_common::IsAdmin<Test>>::get((1258 CollectionId(1),1259 account(2)1260 )));1261 assert!(<pallet_common::IsAdmin<Test>>::get((1262 CollectionId(1),1263 account(3)1264 )));12651266 // remove admin 31267 assert_ok!(Unique::remove_collection_admin(1268 origin2,1269 CollectionId(1),1270 account(3)1271 ));12721273 // 2 is still admin, 3 is not an admin anymore1274 assert!(<pallet_common::IsAdmin<Test>>::get((1275 CollectionId(1),1276 account(2)1277 )));1278 assert_eq!(1279 <pallet_common::IsAdmin<Test>>::get((CollectionId(1), account(3))),1280 false1281 );1282 });1283}12841285#[test]1286fn balance_of() {1287 new_test_ext().execute_with(|| {1288 let nft_collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1289 let fungible_collection_id =1290 create_test_collection(&CollectionMode::Fungible(3), CollectionId(2));1291 let re_fungible_collection_id =1292 create_test_collection(&CollectionMode::ReFungible, CollectionId(3));12931294 // check balance before1295 assert_eq!(1296 <pallet_nonfungible::AccountBalance<Test>>::get((nft_collection_id, account(1))),1297 01298 );1299 assert_eq!(1300 <pallet_fungible::Balance<Test>>::get((fungible_collection_id, account(1))),1301 01302 );1303 assert_eq!(1304 <pallet_refungible::AccountBalance<Test>>::get((re_fungible_collection_id, account(1))),1305 01306 );13071308 let nft_data = default_nft_data();1309 create_test_item(nft_collection_id, &nft_data.into());13101311 let fungible_data = default_fungible_data();1312 create_test_item(fungible_collection_id, &fungible_data.into());13131314 let re_fungible_data = default_re_fungible_data();1315 create_test_item(re_fungible_collection_id, &re_fungible_data.into());13161317 // check balance (collection with id = 1, user id = 1)1318 assert_eq!(1319 <pallet_nonfungible::AccountBalance<Test>>::get((nft_collection_id, account(1))),1320 11321 );1322 assert_eq!(1323 <pallet_fungible::Balance<Test>>::get((fungible_collection_id, account(1))),1324 51325 );1326 assert_eq!(1327 <pallet_refungible::AccountBalance<Test>>::get((re_fungible_collection_id, account(1))),1328 11329 );13301331 assert_eq!(1332 <pallet_nonfungible::Owned<Test>>::get((nft_collection_id, account(1), TokenId(1))),1333 true1334 );1335 assert_eq!(1336 <pallet_refungible::Owned<Test>>::get((1337 re_fungible_collection_id,1338 account(1),1339 TokenId(1)1340 )),1341 true1342 );1343 });1344}13451346#[test]1347fn approve() {1348 new_test_ext().execute_with(|| {1349 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));13501351 let data = default_nft_data();1352 create_test_item(collection_id, &data.into());13531354 let origin1 = Origin::signed(1);13551356 // approve1357 assert_ok!(Unique::approve(1358 origin1,1359 account(2),1360 CollectionId(1),1361 TokenId(1),1362 11363 ));1364 assert_eq!(1365 <pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),1366 account(2)1367 );1368 });1369}13701371#[test]1372fn transfer_from() {1373 new_test_ext().execute_with(|| {1374 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1375 let origin1 = Origin::signed(1);1376 let origin2 = Origin::signed(2);13771378 let data = default_nft_data();1379 create_test_item(collection_id, &data.into());13801381 // approve1382 assert_ok!(Unique::approve(1383 origin1.clone(),1384 account(2),1385 CollectionId(1),1386 TokenId(1),1387 11388 ));1389 assert_eq!(1390 <pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),1391 account(2)1392 );13931394 assert_ok!(Unique::set_mint_permission(1395 origin1.clone(),1396 CollectionId(1),1397 true1398 ));1399 assert_ok!(Unique::set_public_access_mode(1400 origin1.clone(),1401 CollectionId(1),1402 AccessMode::AllowList1403 ));1404 assert_ok!(Unique::add_to_allow_list(1405 origin1.clone(),1406 CollectionId(1),1407 account(1)1408 ));1409 assert_ok!(Unique::add_to_allow_list(1410 origin1.clone(),1411 CollectionId(1),1412 account(2)1413 ));1414 assert_ok!(Unique::add_to_allow_list(1415 origin1,1416 CollectionId(1),1417 account(3)1418 ));14191420 assert_ok!(Unique::transfer_from(1421 origin2,1422 account(1),1423 account(2),1424 CollectionId(1),1425 TokenId(1),1426 11427 ));14281429 // after transfer1430 assert_eq!(1431 <pallet_nonfungible::AccountBalance<Test>>::get((CollectionId(1), account(1))),1432 01433 );1434 assert_eq!(1435 <pallet_nonfungible::AccountBalance<Test>>::get((CollectionId(1), account(2))),1436 11437 );1438 });1439}14401441// #endregion14421443// Coverage tests region1444// #region14451446#[test]1447fn owner_can_add_address_to_allow_list() {1448 new_test_ext().execute_with(|| {1449 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));14501451 let origin1 = Origin::signed(1);1452 assert_ok!(Unique::add_to_allow_list(1453 origin1,1454 collection_id,1455 account(2)1456 ));1457 assert!(<pallet_common::Allowlist<Test>>::get((1458 collection_id,1459 account(2)1460 )));1461 });1462}14631464#[test]1465fn admin_can_add_address_to_allow_list() {1466 new_test_ext().execute_with(|| {1467 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1468 let origin1 = Origin::signed(1);1469 let origin2 = Origin::signed(2);14701471 assert_ok!(Unique::add_collection_admin(1472 origin1,1473 collection_id,1474 account(2)1475 ));1476 assert_ok!(Unique::add_to_allow_list(1477 origin2,1478 collection_id,1479 account(3)1480 ));1481 assert!(<pallet_common::Allowlist<Test>>::get((1482 collection_id,1483 account(3)1484 )));1485 });1486}14871488#[test]1489fn nonprivileged_user_cannot_add_address_to_allow_list() {1490 new_test_ext().execute_with(|| {1491 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));14921493 let origin2 = Origin::signed(2);1494 assert_noop!(1495 Unique::add_to_allow_list(origin2, collection_id, account(3)),1496 CommonError::<Test>::NoPermission1497 );1498 });1499}15001501#[test]1502fn nobody_can_add_address_to_allow_list_of_nonexisting_collection() {1503 new_test_ext().execute_with(|| {1504 let origin1 = Origin::signed(1);15051506 assert_noop!(1507 Unique::add_to_allow_list(origin1, CollectionId(1), account(2)),1508 CommonError::<Test>::CollectionNotFound1509 );1510 });1511}15121513#[test]1514fn nobody_can_add_address_to_allow_list_of_deleted_collection() {1515 new_test_ext().execute_with(|| {1516 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));15171518 let origin1 = Origin::signed(1);1519 assert_ok!(Unique::destroy_collection(origin1.clone(), collection_id));1520 assert_noop!(1521 Unique::add_to_allow_list(origin1, collection_id, account(2)),1522 CommonError::<Test>::CollectionNotFound1523 );1524 });1525}15261527// If address is already added to allow list, nothing happens1528#[test]1529fn address_is_already_added_to_allow_list() {1530 new_test_ext().execute_with(|| {1531 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1532 let origin1 = Origin::signed(1);15331534 assert_ok!(Unique::add_to_allow_list(1535 origin1.clone(),1536 collection_id,1537 account(2)1538 ));1539 assert_ok!(Unique::add_to_allow_list(1540 origin1,1541 collection_id,1542 account(2)1543 ));1544 assert!(<pallet_common::Allowlist<Test>>::get((1545 collection_id,1546 account(2)1547 )));1548 });1549}15501551#[test]1552fn owner_can_remove_address_from_allow_list() {1553 new_test_ext().execute_with(|| {1554 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));15551556 let origin1 = Origin::signed(1);1557 assert_ok!(Unique::add_to_allow_list(1558 origin1.clone(),1559 collection_id,1560 account(2)1561 ));1562 assert_ok!(Unique::remove_from_allow_list(1563 origin1,1564 collection_id,1565 account(2)1566 ));1567 assert_eq!(1568 <pallet_common::Allowlist<Test>>::get((collection_id, account(2))),1569 false1570 );1571 });1572}15731574#[test]1575fn admin_can_remove_address_from_allow_list() {1576 new_test_ext().execute_with(|| {1577 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1578 let origin1 = Origin::signed(1);1579 let origin2 = Origin::signed(2);15801581 // Owner adds admin1582 assert_ok!(Unique::add_collection_admin(1583 origin1.clone(),1584 collection_id,1585 account(2)1586 ));15871588 // Owner adds address 3 to allow list1589 assert_ok!(Unique::add_to_allow_list(1590 origin1,1591 collection_id,1592 account(3)1593 ));15941595 // Admin removes address 3 from allow list1596 assert_ok!(Unique::remove_from_allow_list(1597 origin2,1598 collection_id,1599 account(3)1600 ));1601 assert_eq!(1602 <pallet_common::Allowlist<Test>>::get((collection_id, account(3))),1603 false1604 );1605 });1606}16071608#[test]1609fn nonprivileged_user_cannot_remove_address_from_allow_list() {1610 new_test_ext().execute_with(|| {1611 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1612 let origin1 = Origin::signed(1);1613 let origin2 = Origin::signed(2);16141615 assert_ok!(Unique::add_to_allow_list(1616 origin1,1617 collection_id,1618 account(2)1619 ));1620 assert_noop!(1621 Unique::remove_from_allow_list(origin2, collection_id, account(2)),1622 CommonError::<Test>::NoPermission1623 );1624 assert!(<pallet_common::Allowlist<Test>>::get((1625 collection_id,1626 account(2)1627 )));1628 });1629}16301631#[test]1632fn nobody_can_remove_address_from_allow_list_of_nonexisting_collection() {1633 new_test_ext().execute_with(|| {1634 let origin1 = Origin::signed(1);16351636 assert_noop!(1637 Unique::remove_from_allow_list(origin1, CollectionId(1), account(2)),1638 CommonError::<Test>::CollectionNotFound1639 );1640 });1641}16421643#[test]1644fn nobody_can_remove_address_from_allow_list_of_deleted_collection() {1645 new_test_ext().execute_with(|| {1646 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1647 let origin1 = Origin::signed(1);1648 let origin2 = Origin::signed(2);16491650 // Add account 2 to allow list1651 assert_ok!(Unique::add_to_allow_list(1652 origin1.clone(),1653 collection_id,1654 account(2)1655 ));16561657 // Account 2 is in collection allow-list1658 assert!(<pallet_common::Allowlist<Test>>::get((1659 collection_id,1660 account(2)1661 )));16621663 // Destroy collection1664 assert_ok!(Unique::destroy_collection(origin1, collection_id));16651666 // Attempt to remove account 2 from collection allow-list => error1667 assert_noop!(1668 Unique::remove_from_allow_list(origin2, collection_id, account(2)),1669 CommonError::<Test>::CollectionNotFound1670 );16711672 // Account 2 is not found in collection allow-list anyway1673 assert_eq!(1674 <pallet_common::Allowlist<Test>>::get((collection_id, account(2))),1675 false1676 );1677 });1678}16791680// If address is already removed from allow list, nothing happens1681#[test]1682fn address_is_already_removed_from_allow_list() {1683 new_test_ext().execute_with(|| {1684 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1685 let origin1 = Origin::signed(1);16861687 assert_ok!(Unique::add_to_allow_list(1688 origin1.clone(),1689 collection_id,1690 account(2)1691 ));1692 assert_ok!(Unique::remove_from_allow_list(1693 origin1.clone(),1694 collection_id,1695 account(2)1696 ));1697 assert_eq!(1698 <pallet_common::Allowlist<Test>>::get((collection_id, account(2))),1699 false1700 );1701 assert_ok!(Unique::remove_from_allow_list(1702 origin1,1703 collection_id,1704 account(2)1705 ));1706 assert_eq!(1707 <pallet_common::Allowlist<Test>>::get((collection_id, account(2))),1708 false1709 );1710 });1711}17121713// If Public Access mode is set to AllowList, tokens can’t be transferred from a non-allowlisted address with transfer or transferFrom (2 tests)1714#[test]1715fn allow_list_test_1() {1716 new_test_ext().execute_with(|| {1717 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));17181719 let origin1 = Origin::signed(1);17201721 let data = default_nft_data();1722 create_test_item(collection_id, &data.into());17231724 assert_ok!(Unique::set_public_access_mode(1725 origin1.clone(),1726 collection_id,1727 AccessMode::AllowList1728 ));1729 assert_ok!(Unique::add_to_allow_list(1730 origin1.clone(),1731 collection_id,1732 account(2)1733 ));17341735 assert_noop!(1736 Unique::transfer(origin1, account(3), CollectionId(1), TokenId(1), 1)1737 .map_err(|e| e.error),1738 CommonError::<Test>::AddressNotInAllowlist1739 );1740 });1741}17421743#[test]1744fn allow_list_test_2() {1745 new_test_ext().execute_with(|| {1746 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1747 let origin1 = Origin::signed(1);17481749 let data = default_nft_data();1750 create_test_item(collection_id, &data.into());17511752 assert_ok!(Unique::set_public_access_mode(1753 origin1.clone(),1754 collection_id,1755 AccessMode::AllowList1756 ));1757 assert_ok!(Unique::add_to_allow_list(1758 origin1.clone(),1759 collection_id,1760 account(1)1761 ));1762 assert_ok!(Unique::add_to_allow_list(1763 origin1.clone(),1764 collection_id,1765 account(2)1766 ));17671768 // do approve1769 assert_ok!(Unique::approve(1770 origin1.clone(),1771 account(1),1772 collection_id,1773 TokenId(1),1774 11775 ));1776 assert_eq!(1777 <pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),1778 account(1)1779 );17801781 assert_ok!(Unique::remove_from_allow_list(1782 origin1.clone(),1783 collection_id,1784 account(1)1785 ));17861787 assert_noop!(1788 Unique::transfer_from(1789 origin1,1790 account(1),1791 account(3),1792 CollectionId(1),1793 TokenId(1),1794 11795 )1796 .map_err(|e| e.error),1797 CommonError::<Test>::AddressNotInAllowlist1798 );1799 });1800}18011802// If Public Access mode is set to AllowList, tokens can’t be transferred to a non-allowlisted address with transfer or transferFrom (2 tests)1803#[test]1804fn allow_list_test_3() {1805 new_test_ext().execute_with(|| {1806 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));18071808 let origin1 = Origin::signed(1);18091810 let data = default_nft_data();1811 create_test_item(collection_id, &data.into());18121813 assert_ok!(Unique::set_public_access_mode(1814 origin1.clone(),1815 collection_id,1816 AccessMode::AllowList1817 ));1818 assert_ok!(Unique::add_to_allow_list(1819 origin1.clone(),1820 collection_id,1821 account(1)1822 ));18231824 assert_noop!(1825 Unique::transfer(origin1, account(3), collection_id, TokenId(1), 1)1826 .map_err(|e| e.error),1827 CommonError::<Test>::AddressNotInAllowlist1828 );1829 });1830}18311832#[test]1833fn allow_list_test_4() {1834 new_test_ext().execute_with(|| {1835 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));18361837 let origin1 = Origin::signed(1);18381839 let data = default_nft_data();1840 create_test_item(collection_id, &data.into());18411842 assert_ok!(Unique::set_public_access_mode(1843 origin1.clone(),1844 collection_id,1845 AccessMode::AllowList1846 ));1847 assert_ok!(Unique::add_to_allow_list(1848 origin1.clone(),1849 collection_id,1850 account(1)1851 ));1852 assert_ok!(Unique::add_to_allow_list(1853 origin1.clone(),1854 collection_id,1855 account(2)1856 ));18571858 // do approve1859 assert_ok!(Unique::approve(1860 origin1.clone(),1861 account(1),1862 collection_id,1863 TokenId(1),1864 11865 ));1866 assert_eq!(1867 <pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),1868 account(1)1869 );18701871 assert_ok!(Unique::remove_from_allow_list(1872 origin1.clone(),1873 collection_id,1874 account(2)1875 ));18761877 assert_noop!(1878 Unique::transfer_from(1879 origin1,1880 account(1),1881 account(3),1882 collection_id,1883 TokenId(1),1884 11885 )1886 .map_err(|e| e.error),1887 CommonError::<Test>::AddressNotInAllowlist1888 );1889 });1890}18911892// 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)1893#[test]1894fn allow_list_test_5() {1895 new_test_ext().execute_with(|| {1896 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));18971898 let origin1 = Origin::signed(1);18991900 let data = default_nft_data();1901 create_test_item(collection_id, &data.into());19021903 assert_ok!(Unique::set_public_access_mode(1904 origin1.clone(),1905 collection_id,1906 AccessMode::AllowList1907 ));1908 assert_noop!(1909 Unique::burn_item(origin1.clone(), CollectionId(1), TokenId(1), 1).map_err(|e| e.error),1910 CommonError::<Test>::AddressNotInAllowlist1911 );1912 });1913}19141915// If Public Access mode is set to AllowList, token transfers can’t be Approved by a non-allowlisted address (see Approve method).1916#[test]1917fn allow_list_test_6() {1918 new_test_ext().execute_with(|| {1919 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));19201921 let origin1 = Origin::signed(1);19221923 let data = default_nft_data();1924 create_test_item(collection_id, &data.into());19251926 assert_ok!(Unique::set_public_access_mode(1927 origin1.clone(),1928 collection_id,1929 AccessMode::AllowList1930 ));19311932 // do approve1933 assert_noop!(1934 Unique::approve(origin1, account(1), CollectionId(1), TokenId(1), 1)1935 .map_err(|e| e.error),1936 CommonError::<Test>::AddressNotInAllowlist1937 );1938 });1939}19401941// If Public Access mode is set to AllowList, tokens can be transferred from a allowlisted address with transfer or transferFrom (2 tests) and1942// tokens can be transferred from a allowlisted address with transfer or transferFrom (2 tests)1943#[test]1944fn allow_list_test_7() {1945 new_test_ext().execute_with(|| {1946 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));19471948 let data = default_nft_data();1949 create_test_item(collection_id, &data.into());19501951 let origin1 = Origin::signed(1);19521953 assert_ok!(Unique::set_public_access_mode(1954 origin1.clone(),1955 collection_id,1956 AccessMode::AllowList1957 ));1958 assert_ok!(Unique::add_to_allow_list(1959 origin1.clone(),1960 collection_id,1961 account(1)1962 ));1963 assert_ok!(Unique::add_to_allow_list(1964 origin1.clone(),1965 collection_id,1966 account(2)1967 ));19681969 assert_ok!(Unique::transfer(1970 origin1,1971 account(2),1972 CollectionId(1),1973 TokenId(1),1974 11975 ));1976 });1977}19781979#[test]1980fn allow_list_test_8() {1981 new_test_ext().execute_with(|| {1982 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));19831984 // Create NFT for account 11985 let data = default_nft_data();1986 create_test_item(collection_id, &data.into());19871988 let origin1 = Origin::signed(1);19891990 // Toggle Allow List mode and add accounts 1 and 21991 assert_ok!(Unique::set_public_access_mode(1992 origin1.clone(),1993 collection_id,1994 AccessMode::AllowList1995 ));1996 assert_ok!(Unique::add_to_allow_list(1997 origin1.clone(),1998 collection_id,1999 account(1)2000 ));2001 assert_ok!(Unique::add_to_allow_list(2002 origin1.clone(),2003 collection_id,2004 account(2)2005 ));20062007 // Sself-approve account 1 for NFT 12008 assert_ok!(Unique::approve(2009 origin1.clone(),2010 account(1),2011 CollectionId(1),2012 TokenId(1),2013 12014 ));2015 assert_eq!(2016 <pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),2017 account(1)2018 );20192020 // Transfer from 1 to 22021 assert_ok!(Unique::transfer_from(2022 origin1,2023 account(1),2024 account(2),2025 CollectionId(1),2026 TokenId(1),2027 12028 ));2029 });2030}20312032// If Public Access mode is set to AllowList, and Mint Permission is set to false, tokens can be created by owner.2033#[test]2034fn allow_list_test_9() {2035 new_test_ext().execute_with(|| {2036 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));2037 let origin1 = Origin::signed(1);20382039 assert_ok!(Unique::set_public_access_mode(2040 origin1.clone(),2041 collection_id,2042 AccessMode::AllowList2043 ));2044 assert_ok!(Unique::set_mint_permission(origin1, collection_id, false));20452046 let data = default_nft_data();2047 create_test_item(collection_id, &data.into());2048 });2049}20502051// If Public Access mode is set to AllowList, and Mint Permission is set to false, tokens can be created by admin.2052#[test]2053fn allow_list_test_10() {2054 new_test_ext().execute_with(|| {2055 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));20562057 let origin1 = Origin::signed(1);2058 let origin2 = Origin::signed(2);20592060 assert_ok!(Unique::set_public_access_mode(2061 origin1.clone(),2062 collection_id,2063 AccessMode::AllowList2064 ));2065 assert_ok!(Unique::set_mint_permission(2066 origin1.clone(),2067 collection_id,2068 false2069 ));20702071 assert_ok!(Unique::add_collection_admin(2072 origin1,2073 collection_id,2074 account(2)2075 ));20762077 assert_ok!(Unique::create_item(2078 origin2,2079 collection_id,2080 account(2),2081 default_nft_data().into()2082 ));2083 });2084}20852086// 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.2087#[test]2088fn allow_list_test_11() {2089 new_test_ext().execute_with(|| {2090 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));20912092 let origin1 = Origin::signed(1);2093 let origin2 = Origin::signed(2);20942095 assert_ok!(Unique::set_public_access_mode(2096 origin1.clone(),2097 collection_id,2098 AccessMode::AllowList2099 ));2100 assert_ok!(Unique::set_mint_permission(2101 origin1.clone(),2102 collection_id,2103 false2104 ));2105 assert_ok!(Unique::add_to_allow_list(2106 origin1,2107 collection_id,2108 account(2)2109 ));21102111 assert_noop!(2112 Unique::create_item(2113 origin2,2114 CollectionId(1),2115 account(2),2116 default_nft_data().into()2117 )2118 .map_err(|e| e.error),2119 CommonError::<Test>::PublicMintingNotAllowed2120 );2121 });2122}21232124// 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.2125#[test]2126fn allow_list_test_12() {2127 new_test_ext().execute_with(|| {2128 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));21292130 let origin1 = Origin::signed(1);2131 let origin2 = Origin::signed(2);21322133 assert_ok!(Unique::set_public_access_mode(2134 origin1.clone(),2135 collection_id,2136 AccessMode::AllowList2137 ));2138 assert_ok!(Unique::set_mint_permission(origin1, collection_id, false));21392140 assert_noop!(2141 Unique::create_item(2142 origin2,2143 CollectionId(1),2144 account(2),2145 default_nft_data().into()2146 )2147 .map_err(|e| e.error),2148 CommonError::<Test>::PublicMintingNotAllowed2149 );2150 });2151}21522153// If Public Access mode is set to AllowList, and Mint Permission is set to true, tokens can be created by owner.2154#[test]2155fn allow_list_test_13() {2156 new_test_ext().execute_with(|| {2157 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));21582159 let origin1 = Origin::signed(1);21602161 assert_ok!(Unique::set_public_access_mode(2162 origin1.clone(),2163 collection_id,2164 AccessMode::AllowList2165 ));2166 assert_ok!(Unique::set_mint_permission(origin1, collection_id, true));21672168 let data = default_nft_data();2169 create_test_item(collection_id, &data.into());2170 });2171}21722173// If Public Access mode is set to AllowList, and Mint Permission is set to true, tokens can be created by admin.2174#[test]2175fn allow_list_test_14() {2176 new_test_ext().execute_with(|| {2177 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));21782179 let origin1 = Origin::signed(1);2180 let origin2 = Origin::signed(2);21812182 assert_ok!(Unique::set_public_access_mode(2183 origin1.clone(),2184 collection_id,2185 AccessMode::AllowList2186 ));2187 assert_ok!(Unique::set_mint_permission(2188 origin1.clone(),2189 collection_id,2190 true2191 ));21922193 assert_ok!(Unique::add_collection_admin(2194 origin1,2195 collection_id,2196 account(2)2197 ));21982199 assert_ok!(Unique::create_item(2200 origin2,2201 collection_id,2202 account(2),2203 default_nft_data().into()2204 ));2205 });2206}22072208// 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.2209#[test]2210fn allow_list_test_15() {2211 new_test_ext().execute_with(|| {2212 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));22132214 let origin1 = Origin::signed(1);2215 let origin2 = Origin::signed(2);22162217 assert_ok!(Unique::set_public_access_mode(2218 origin1.clone(),2219 collection_id,2220 AccessMode::AllowList2221 ));2222 assert_ok!(Unique::set_mint_permission(origin1, collection_id, true));22232224 assert_noop!(2225 Unique::create_item(2226 origin2,2227 collection_id,2228 account(2),2229 default_nft_data().into()2230 )2231 .map_err(|e| e.error),2232 CommonError::<Test>::AddressNotInAllowlist2233 );2234 });2235}22362237// If Public Access mode is set to AllowList, and Mint Permission is set to true, tokens can be created by non-privileged and allow listed address.2238#[test]2239fn allow_list_test_16() {2240 new_test_ext().execute_with(|| {2241 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));22422243 let origin1 = Origin::signed(1);2244 let origin2 = Origin::signed(2);22452246 assert_ok!(Unique::set_public_access_mode(2247 origin1.clone(),2248 collection_id,2249 AccessMode::AllowList2250 ));2251 assert_ok!(Unique::set_mint_permission(2252 origin1.clone(),2253 collection_id,2254 true2255 ));2256 assert_ok!(Unique::add_to_allow_list(2257 origin1,2258 collection_id,2259 account(2)2260 ));22612262 assert_ok!(Unique::create_item(2263 origin2,2264 collection_id,2265 account(2),2266 default_nft_data().into()2267 ));2268 });2269}22702271// Total number of collections. Positive test2272#[test]2273fn total_number_collections_bound() {2274 new_test_ext().execute_with(|| {2275 create_test_collection(&CollectionMode::NFT, CollectionId(1));2276 });2277}22782279#[test]2280fn create_max_collections() {2281 new_test_ext().execute_with(|| {2282 for i in 1..COLLECTION_NUMBER_LIMIT {2283 create_test_collection(&CollectionMode::NFT, CollectionId(i));2284 }2285 });2286}22872288// Total number of collections. Negative test2289#[test]2290fn total_number_collections_bound_neg() {2291 new_test_ext().execute_with(|| {2292 let origin1 = Origin::signed(1);22932294 for i in 1..=COLLECTION_NUMBER_LIMIT {2295 create_test_collection(&CollectionMode::NFT, CollectionId(i));2296 }22972298 let col_name1: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();2299 let col_desc1: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();2300 let token_prefix1: Vec<u8> = b"token_prefix1\0".to_vec();23012302 let data: CreateCollectionData<u64> = CreateCollectionData {2303 name: col_name1.try_into().unwrap(),2304 description: col_desc1.try_into().unwrap(),2305 token_prefix: token_prefix1.try_into().unwrap(),2306 mode: CollectionMode::NFT,2307 ..Default::default()2308 };23092310 // 11-th collection in chain. Expects error2311 assert_noop!(2312 Unique::create_collection_ex(origin1, data),2313 CommonError::<Test>::TotalCollectionsLimitExceeded2314 );2315 });2316}23172318// Owned tokens by a single address. Positive test2319#[test]2320fn owned_tokens_bound() {2321 new_test_ext().execute_with(|| {2322 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));23232324 let data = default_nft_data();2325 create_test_item(collection_id, &data.clone().into());2326 create_test_item(collection_id, &data.into());2327 });2328}23292330// Owned tokens by a single address. Negotive test2331#[test]2332fn owned_tokens_bound_neg() {2333 new_test_ext().execute_with(|| {2334 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));23352336 let origin1 = Origin::signed(1);23372338 for _ in 1..=MAX_TOKEN_OWNERSHIP {2339 let data = default_nft_data();2340 create_test_item(collection_id, &data.clone().into());2341 }23422343 let data = default_nft_data();2344 assert_noop!(2345 Unique::create_item(origin1, CollectionId(1), account(1), data.into())2346 .map_err(|e| e.error),2347 CommonError::<Test>::AccountTokenLimitExceeded2348 );2349 });2350}23512352// Number of collection admins. Positive test2353#[test]2354fn collection_admins_bound() {2355 new_test_ext().execute_with(|| {2356 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));23572358 let origin1 = Origin::signed(1);23592360 assert_ok!(Unique::add_collection_admin(2361 origin1.clone(),2362 collection_id,2363 account(2)2364 ));2365 assert_ok!(Unique::add_collection_admin(2366 origin1,2367 collection_id,2368 account(3)2369 ));2370 });2371}23722373// Number of collection admins. Negotive test2374#[test]2375fn collection_admins_bound_neg() {2376 new_test_ext().execute_with(|| {2377 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));23782379 let origin1 = Origin::signed(1);23802381 for i in 0..COLLECTION_ADMINS_LIMIT {2382 assert_ok!(Unique::add_collection_admin(2383 origin1.clone(),2384 collection_id,2385 account((2 + i).into())2386 ));2387 }2388 assert_noop!(2389 Unique::add_collection_admin(2390 origin1,2391 collection_id,2392 account((3 + COLLECTION_ADMINS_LIMIT).into())2393 ),2394 CommonError::<Test>::CollectionAdminCountExceeded2395 );2396 });2397}2398// #endregion23992400#[test]2401fn set_const_on_chain_schema() {2402 new_test_ext().execute_with(|| {2403 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));24042405 let origin1 = Origin::signed(1);2406 assert_ok!(Unique::set_const_on_chain_schema(2407 origin1,2408 collection_id,2409 b"test const on chain schema".to_vec().try_into().unwrap()2410 ));24112412 assert_eq!(2413 <pallet_common::CollectionData<Test>>::get((2414 collection_id,2415 CollectionField::ConstOnChainSchema2416 )),2417 b"test const on chain schema".to_vec()2418 );2419 });2420}24212422#[test]2423fn collection_transfer_flag_works() {2424 new_test_ext().execute_with(|| {2425 let origin1 = Origin::signed(1);24262427 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));2428 assert_ok!(Unique::set_transfers_enabled_flag(2429 origin1,2430 collection_id,2431 true2432 ));24332434 let data = default_nft_data();2435 create_test_item(collection_id, &data.into());2436 assert_eq!(2437 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),2438 12439 );2440 assert_eq!(2441 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),2442 true2443 );24442445 let origin1 = Origin::signed(1);24462447 // default scenario2448 assert_ok!(Unique::transfer(2449 origin1,2450 account(2),2451 collection_id,2452 TokenId(1),2453 12454 ));2455 assert_eq!(2456 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),2457 false2458 );2459 assert_eq!(2460 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))),2461 true2462 );2463 assert_eq!(2464 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),2465 02466 );2467 assert_eq!(2468 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(2))),2469 12470 );2471 });2472}24732474#[test]2475fn collection_transfer_flag_works_neg() {2476 new_test_ext().execute_with(|| {2477 let origin1 = Origin::signed(1);24782479 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));2480 assert_ok!(Unique::set_transfers_enabled_flag(2481 origin1,2482 collection_id,2483 false2484 ));24852486 let data = default_nft_data();2487 create_test_item(collection_id, &data.into());2488 assert_eq!(2489 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),2490 12491 );2492 assert_eq!(2493 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),2494 true2495 );24962497 let origin1 = Origin::signed(1);24982499 // default scenario2500 assert_noop!(2501 Unique::transfer(origin1, account(2), CollectionId(1), TokenId(1), 1)2502 .map_err(|e| e.error),2503 CommonError::<Test>::TransferNotAllowed2504 );2505 assert_eq!(2506 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),2507 12508 );2509 assert_eq!(2510 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(2))),2511 02512 );2513 assert_eq!(2514 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),2515 true2516 );2517 assert_eq!(2518 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))),2519 false2520 );2521 });2522}25232524#[test]2525fn collection_sponsoring() {2526 new_test_ext().execute_with(|| {2527 // default_limits();2528 let user1 = 1_u64;2529 let user2 = 777_u64;2530 let origin1 = Origin::signed(user1);2531 let origin2 = Origin::signed(user2);2532 let account2 = account(user2);25332534 let collection_id =2535 create_test_collection_for_owner(&CollectionMode::NFT, user1, CollectionId(1));2536 assert_ok!(Unique::set_collection_sponsor(2537 origin1.clone(),2538 collection_id,2539 user12540 ));2541 assert_ok!(Unique::confirm_sponsorship(origin1.clone(), collection_id));25422543 // Expect error while have no permissions2544 assert!(Unique::create_item(2545 origin2.clone(),2546 collection_id,2547 account2.clone(),2548 default_nft_data().into()2549 )2550 .is_err());25512552 assert_ok!(Unique::set_public_access_mode(2553 origin1.clone(),2554 collection_id,2555 AccessMode::AllowList2556 ));2557 assert_ok!(Unique::add_to_allow_list(2558 origin1.clone(),2559 collection_id,2560 account2.clone()2561 ));2562 assert_ok!(Unique::set_mint_permission(2563 origin1.clone(),2564 collection_id,2565 true2566 ));25672568 assert_ok!(Unique::create_item(2569 origin2,2570 collection_id,2571 account2,2572 default_nft_data().into()2573 ));2574 });2575}1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617// Tests to be written here18use crate::{Test, TestCrossAccountId, CollectionCreationPrice, Origin, Unique, new_test_ext};19use up_data_structs::{20 COLLECTION_NUMBER_LIMIT, CollectionId, CreateItemData, CreateFungibleData, CreateNftData,21 CreateReFungibleData, MAX_DECIMAL_POINTS, COLLECTION_ADMINS_LIMIT,22 TokenId, MAX_TOKEN_OWNERSHIP, CreateCollectionData, CollectionField, SchemaVersion,23 CollectionMode, AccessMode,24};25use frame_support::{assert_noop, assert_ok, assert_err};26use sp_std::convert::TryInto;27use pallet_evm::account::CrossAccountId;28use pallet_common::Error as CommonError;29use pallet_unique::Error as UniqueError;3031fn add_balance(user: u64, value: u64) {32 const DONOR_USER: u64 = 999;33 assert_ok!(<pallet_balances::Pallet<Test>>::set_balance(34 Origin::root(),35 DONOR_USER,36 value,37 038 ));39 assert_ok!(<pallet_balances::Pallet<Test>>::force_transfer(40 Origin::root(),41 DONOR_USER,42 user,43 value44 ));45}4647fn default_nft_data() -> CreateNftData {48 CreateNftData {49 const_data: vec![1, 2, 3].try_into().unwrap(),50 properties: vec![].try_into().unwrap(),51 }52}5354fn default_fungible_data() -> CreateFungibleData {55 CreateFungibleData { value: 5 }56}5758fn default_re_fungible_data() -> CreateReFungibleData {59 CreateReFungibleData {60 const_data: vec![1, 2, 3].try_into().unwrap(),61 pieces: 1023,62 }63}6465fn create_test_collection_for_owner(66 mode: &CollectionMode,67 owner: u64,68 id: CollectionId,69) -> CollectionId {70 add_balance(owner, CollectionCreationPrice::get() as u64 + 1);7172 let col_name1: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();73 let col_desc1: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();74 let token_prefix1: Vec<u8> = b"token_prefix1\0".to_vec();7576 let data: CreateCollectionData<u64> = CreateCollectionData {77 name: col_name1.try_into().unwrap(),78 description: col_desc1.try_into().unwrap(),79 token_prefix: token_prefix1.try_into().unwrap(),80 mode: mode.clone(),81 ..Default::default()82 };8384 let origin1 = Origin::signed(owner);85 assert_ok!(Unique::create_collection_ex(origin1, data));8687 let saved_col_name: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();88 let saved_description: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();89 let saved_prefix: Vec<u8> = b"token_prefix1\0".to_vec();90 assert_eq!(91 <pallet_common::CollectionById<Test>>::get(id)92 .unwrap()93 .owner,94 owner95 );96 assert_eq!(97 <pallet_common::CollectionById<Test>>::get(id).unwrap().name,98 saved_col_name99 );100 assert_eq!(101 <pallet_common::CollectionById<Test>>::get(id).unwrap().mode,102 *mode103 );104 assert_eq!(105 <pallet_common::CollectionById<Test>>::get(id)106 .unwrap()107 .description,108 saved_description109 );110 assert_eq!(111 <pallet_common::CollectionById<Test>>::get(id)112 .unwrap()113 .token_prefix,114 saved_prefix115 );116 id117}118119fn create_test_collection(mode: &CollectionMode, id: CollectionId) -> CollectionId {120 create_test_collection_for_owner(&mode, 1, id)121}122123fn create_test_item(collection_id: CollectionId, data: &CreateItemData) {124 let origin1 = Origin::signed(1);125 assert_ok!(Unique::create_item(126 origin1,127 collection_id,128 account(1),129 data.clone()130 ));131}132133fn account(sub: u64) -> TestCrossAccountId {134 TestCrossAccountId::from_sub(sub)135}136137// Use cases tests region138// #region139140#[test]141fn set_version_schema() {142 new_test_ext().execute_with(|| {143 let origin1 = Origin::signed(1);144 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));145146 assert_ok!(Unique::set_schema_version(147 origin1,148 collection_id,149 SchemaVersion::Unique150 ));151 assert_eq!(152 <pallet_common::CollectionById<Test>>::get(collection_id)153 .unwrap()154 .schema_version,155 SchemaVersion::Unique156 );157 });158}159160#[test]161fn check_not_sufficient_founds() {162 new_test_ext().execute_with(|| {163 let acc: u64 = 1;164 <pallet_balances::Pallet<Test>>::set_balance(Origin::root(), acc, 0, 0).unwrap();165166 let name: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();167 let description: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();168 let token_prefix: Vec<u8> = b"token_prefix1\0".to_vec();169170 let data: CreateCollectionData<<Test as frame_system::Config>::AccountId> =171 CreateCollectionData {172 name: name.try_into().unwrap(),173 description: description.try_into().unwrap(),174 token_prefix: token_prefix.try_into().unwrap(),175 mode: CollectionMode::NFT,176 ..Default::default()177 };178179 let result = Unique::create_collection_ex(Origin::signed(acc), data);180 assert_err!(result, <CommonError<Test>>::NotSufficientFounds);181 });182}183184#[test]185fn create_fungible_collection_fails_with_large_decimal_numbers() {186 new_test_ext().execute_with(|| {187 let col_name1: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();188 let col_desc1: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();189 let token_prefix1: Vec<u8> = b"token_prefix1\0".to_vec();190191 let data: CreateCollectionData<u64> = CreateCollectionData {192 name: col_name1.try_into().unwrap(),193 description: col_desc1.try_into().unwrap(),194 token_prefix: token_prefix1.try_into().unwrap(),195 mode: CollectionMode::Fungible(MAX_DECIMAL_POINTS + 1),196 ..Default::default()197 };198199 let origin1 = Origin::signed(1);200 assert_noop!(201 Unique::create_collection_ex(origin1, data),202 UniqueError::<Test>::CollectionDecimalPointLimitExceeded203 );204 });205}206207#[test]208fn create_nft_item() {209 new_test_ext().execute_with(|| {210 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));211212 let data = default_nft_data();213 create_test_item(collection_id, &data.clone().into());214215 let item = <pallet_nonfungible::TokenData<Test>>::get((collection_id, 1)).unwrap();216 assert_eq!(item.const_data, data.const_data.into_inner());217 });218}219220// Use cases tests region221// #region222#[test]223fn create_nft_multiple_items() {224 new_test_ext().execute_with(|| {225 create_test_collection(&CollectionMode::NFT, CollectionId(1));226227 let origin1 = Origin::signed(1);228229 let items_data = vec![default_nft_data(), default_nft_data(), default_nft_data()];230231 assert_ok!(Unique::create_multiple_items(232 origin1,233 CollectionId(1),234 account(1),235 items_data236 .clone()237 .into_iter()238 .map(|d| { d.into() })239 .collect()240 ));241 for (index, data) in items_data.into_iter().enumerate() {242 let item = <pallet_nonfungible::TokenData<Test>>::get((243 CollectionId(1),244 TokenId((index + 1) as u32),245 ))246 .unwrap();247 assert_eq!(item.const_data.to_vec(), data.const_data.into_inner());248 }249 });250}251252#[test]253fn create_refungible_item() {254 new_test_ext().execute_with(|| {255 let collection_id = create_test_collection(&CollectionMode::ReFungible, CollectionId(1));256257 let data = default_re_fungible_data();258 create_test_item(collection_id, &data.clone().into());259 let item = <pallet_refungible::TokenData<Test>>::get((collection_id, TokenId(1)));260 let balance =261 <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1)));262 assert_eq!(item.const_data, data.const_data.into_inner());263 assert_eq!(balance, 1023);264 });265}266267#[test]268fn create_multiple_refungible_items() {269 new_test_ext().execute_with(|| {270 create_test_collection(&CollectionMode::ReFungible, CollectionId(1));271272 let origin1 = Origin::signed(1);273274 let items_data = vec![275 default_re_fungible_data(),276 default_re_fungible_data(),277 default_re_fungible_data(),278 ];279280 assert_ok!(Unique::create_multiple_items(281 origin1,282 CollectionId(1),283 account(1),284 items_data285 .clone()286 .into_iter()287 .map(|d| { d.into() })288 .collect()289 ));290 for (index, data) in items_data.into_iter().enumerate() {291 let item = <pallet_refungible::TokenData<Test>>::get((292 CollectionId(1),293 TokenId((index + 1) as u32),294 ));295 let balance =296 <pallet_refungible::Balance<Test>>::get((CollectionId(1), TokenId(1), account(1)));297 assert_eq!(item.const_data.to_vec(), data.const_data.into_inner());298 assert_eq!(balance, 1023);299 }300 });301}302303#[test]304fn create_fungible_item() {305 new_test_ext().execute_with(|| {306 let collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));307308 let data = default_fungible_data();309 create_test_item(collection_id, &data.into());310311 assert_eq!(312 <pallet_fungible::Balance<Test>>::get((collection_id, account(1))),313 5314 );315 });316}317318//#[test]319// fn create_multiple_fungible_items() {320// new_test_ext().execute_with(|| {321// default_limits();322323// create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));324325// let origin1 = Origin::signed(1);326327// let items_data = vec![default_fungible_data(), default_fungible_data(), default_fungible_data()];328329// assert_ok!(Unique::create_multiple_items(330// origin1.clone(),331// 1,332// 1,333// items_data.clone().into_iter().map(|d| { d.into() }).collect()334// ));335336// for (index, _) in items_data.iter().enumerate() {337// assert_eq!(Unique::fungible_item_id(1, (index + 1) as TokenId).value, 5);338// }339// assert_eq!(Unique::balance_count(1, 1), 3000);340// assert_eq!(Unique::address_tokens(1, 1), [1, 2, 3]);341// });342// }343344#[test]345fn transfer_fungible_item() {346 new_test_ext().execute_with(|| {347 let collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));348349 let origin1 = Origin::signed(1);350 let origin2 = Origin::signed(2);351352 let data = default_fungible_data();353 create_test_item(collection_id, &data.into());354355 assert_eq!(356 <pallet_fungible::Balance<Test>>::get((CollectionId(1), account(1))),357 5358 );359360 // change owner scenario361 assert_ok!(Unique::transfer(362 origin1,363 account(2),364 CollectionId(1),365 TokenId(0),366 5367 ));368 assert_eq!(369 <pallet_fungible::Balance<Test>>::get((CollectionId(1), account(1))),370 0371 );372373 // split item scenario374 assert_ok!(Unique::transfer(375 origin2.clone(),376 account(3),377 CollectionId(1),378 TokenId(0),379 3380 ));381382 // split item and new owner has account scenario383 assert_ok!(Unique::transfer(384 origin2,385 account(3),386 CollectionId(1),387 TokenId(0),388 1389 ));390 assert_eq!(391 <pallet_fungible::Balance<Test>>::get((CollectionId(1), account(2))),392 1393 );394 assert_eq!(395 <pallet_fungible::Balance<Test>>::get((CollectionId(1), account(3))),396 4397 );398 });399}400401#[test]402fn transfer_refungible_item() {403 new_test_ext().execute_with(|| {404 let collection_id = create_test_collection(&CollectionMode::ReFungible, CollectionId(1));405406 // Create RFT 1 in 1023 pieces for account 1407 let data = default_re_fungible_data();408 create_test_item(collection_id, &data.clone().into());409 let item = <pallet_refungible::TokenData<Test>>::get((collection_id, TokenId(1)));410 assert_eq!(item.const_data, data.const_data.into_inner());411 assert_eq!(412 <pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))),413 1414 );415 assert_eq!(416 <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1))),417 1023418 );419 assert_eq!(420 <pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),421 true422 );423424 // Account 1 transfers all 1023 pieces of RFT 1 to account 2425 let origin1 = Origin::signed(1);426 let origin2 = Origin::signed(2);427 assert_ok!(Unique::transfer(428 origin1,429 account(2),430 CollectionId(1),431 TokenId(1),432 1023433 ));434 assert_eq!(435 <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(2))),436 1023437 );438 assert_eq!(439 <pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))),440 0441 );442 assert_eq!(443 <pallet_refungible::AccountBalance<Test>>::get((collection_id, account(2))),444 1445 );446 assert_eq!(447 <pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),448 false449 );450 assert_eq!(451 <pallet_refungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))),452 true453 );454455 // Account 2 transfers 500 pieces of RFT 1 to account 3456 assert_ok!(Unique::transfer(457 origin2.clone(),458 account(3),459 CollectionId(1),460 TokenId(1),461 500462 ));463 assert_eq!(464 <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(2))),465 523466 );467 assert_eq!(468 <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(3))),469 500470 );471 assert_eq!(472 <pallet_refungible::AccountBalance<Test>>::get((collection_id, account(2))),473 1474 );475 assert_eq!(476 <pallet_refungible::AccountBalance<Test>>::get((collection_id, account(3))),477 1478 );479 assert_eq!(480 <pallet_refungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))),481 true482 );483 assert_eq!(484 <pallet_refungible::Owned<Test>>::get((collection_id, account(3), TokenId(1))),485 true486 );487488 // Account 2 transfers 200 more pieces of RFT 1 to account 3 with pre-existing balance489 assert_ok!(Unique::transfer(490 origin2,491 account(3),492 CollectionId(1),493 TokenId(1),494 200495 ));496 assert_eq!(497 <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(2))),498 323499 );500 assert_eq!(501 <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(3))),502 700503 );504 assert_eq!(505 <pallet_refungible::AccountBalance<Test>>::get((collection_id, account(2))),506 1507 );508 assert_eq!(509 <pallet_refungible::AccountBalance<Test>>::get((collection_id, account(3))),510 1511 );512 assert_eq!(513 <pallet_refungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))),514 true515 );516 assert_eq!(517 <pallet_refungible::Owned<Test>>::get((collection_id, account(3), TokenId(1))),518 true519 );520 });521}522523#[test]524fn transfer_nft_item() {525 new_test_ext().execute_with(|| {526 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));527528 let data = default_nft_data();529 create_test_item(collection_id, &data.into());530 assert_eq!(531 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),532 1533 );534 assert_eq!(535 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),536 true537 );538539 let origin1 = Origin::signed(1);540 // default scenario541 assert_ok!(Unique::transfer(542 origin1,543 account(2),544 CollectionId(1),545 TokenId(1),546 1547 ));548 assert_eq!(549 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),550 0551 );552 assert_eq!(553 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(2))),554 1555 );556 assert_eq!(557 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),558 false559 );560 assert_eq!(561 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))),562 true563 );564 });565}566567#[test]568fn transfer_nft_item_wrong_value() {569 new_test_ext().execute_with(|| {570 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));571572 let data = default_nft_data();573 create_test_item(collection_id, &data.into());574 assert_eq!(575 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),576 1577 );578 assert_eq!(579 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),580 true581 );582583 let origin1 = Origin::signed(1);584585 assert_noop!(586 Unique::transfer(origin1, account(2), CollectionId(1), TokenId(1), 2)587 .map_err(|e| e.error),588 <pallet_nonfungible::Error::<Test>>::NonfungibleItemsHaveNoAmount589 );590 });591}592593#[test]594fn transfer_nft_item_zero_value() {595 new_test_ext().execute_with(|| {596 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));597598 let data = default_nft_data();599 create_test_item(collection_id, &data.into());600 assert_eq!(601 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),602 1603 );604 assert_eq!(605 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),606 true607 );608609 let origin1 = Origin::signed(1);610611 // Transferring 0 amount works on NFT...612 assert_ok!(Unique::transfer(613 origin1,614 account(2),615 CollectionId(1),616 TokenId(1),617 0618 ));619 // ... and results in no transfer620 assert_eq!(621 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),622 1623 );624 assert_eq!(625 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),626 true627 );628 });629}630631#[test]632fn nft_approve_and_transfer_from() {633 new_test_ext().execute_with(|| {634 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));635636 let data = default_nft_data();637 create_test_item(collection_id, &data.into());638639 let origin1 = Origin::signed(1);640 let origin2 = Origin::signed(2);641642 assert_eq!(643 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),644 1645 );646 assert_eq!(647 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),648 true649 );650651 // neg transfer_from652 assert_noop!(653 Unique::transfer_from(654 origin2.clone(),655 account(1),656 account(2),657 CollectionId(1),658 TokenId(1),659 1660 )661 .map_err(|e| e.error),662 CommonError::<Test>::ApprovedValueTooLow663 );664665 // do approve666 assert_ok!(Unique::approve(667 origin1,668 account(2),669 CollectionId(1),670 TokenId(1),671 1672 ));673 assert_eq!(674 <pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),675 account(2)676 );677678 assert_ok!(Unique::transfer_from(679 origin2,680 account(1),681 account(3),682 CollectionId(1),683 TokenId(1),684 1685 ));686 assert!(687 <pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).is_none()688 );689 });690}691692#[test]693fn nft_approve_and_transfer_from_allow_list() {694 new_test_ext().execute_with(|| {695 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));696697 let origin1 = Origin::signed(1);698 let origin2 = Origin::signed(2);699700 // Create NFT 1 for account 1701 let data = default_nft_data();702 create_test_item(collection_id, &data.clone().into());703 assert_eq!(704 &<pallet_nonfungible::TokenData<Test>>::get((collection_id, TokenId(1)))705 .unwrap()706 .const_data,707 &data.const_data.into_inner()708 );709 assert_eq!(710 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),711 1712 );713 assert_eq!(714 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),715 true716 );717718 // Allow allow-list users to mint and add accounts 1, 2, and 3 to allow-list719 assert_ok!(Unique::set_mint_permission(720 origin1.clone(),721 CollectionId(1),722 true723 ));724 assert_ok!(Unique::set_public_access_mode(725 origin1.clone(),726 CollectionId(1),727 AccessMode::AllowList728 ));729 assert_ok!(Unique::add_to_allow_list(730 origin1.clone(),731 CollectionId(1),732 account(1)733 ));734 assert_ok!(Unique::add_to_allow_list(735 origin1.clone(),736 CollectionId(1),737 account(2)738 ));739 assert_ok!(Unique::add_to_allow_list(740 origin1.clone(),741 CollectionId(1),742 account(3)743 ));744745 // Account 1 approves account 2 for NFT 1746 assert_ok!(Unique::approve(747 origin1.clone(),748 account(2),749 CollectionId(1),750 TokenId(1),751 1752 ));753 assert_eq!(754 <pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),755 account(2)756 );757758 // Account 2 transfers NFT 1 from account 1 to account 3759 assert_ok!(Unique::transfer_from(760 origin2,761 account(1),762 account(3),763 CollectionId(1),764 TokenId(1),765 1766 ));767 assert!(768 <pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).is_none()769 );770 });771}772773#[test]774fn refungible_approve_and_transfer_from() {775 new_test_ext().execute_with(|| {776 let collection_id = create_test_collection(&CollectionMode::ReFungible, CollectionId(1));777778 let origin1 = Origin::signed(1);779 let origin2 = Origin::signed(2);780781 // Create RFT 1 in 1023 pieces for account 1782 let data = default_re_fungible_data();783 create_test_item(collection_id, &data.into());784785 assert_eq!(786 <pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))),787 1788 );789 assert_eq!(790 <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1))),791 1023792 );793 assert_eq!(794 <pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),795 true796 );797798 // Allow public minting, enable allow-list and add accounts 1, 2, 3 to allow-list799 assert_ok!(Unique::set_mint_permission(800 origin1.clone(),801 CollectionId(1),802 true803 ));804 assert_ok!(Unique::set_public_access_mode(805 origin1.clone(),806 CollectionId(1),807 AccessMode::AllowList808 ));809 assert_ok!(Unique::add_to_allow_list(810 origin1.clone(),811 CollectionId(1),812 account(1)813 ));814 assert_ok!(Unique::add_to_allow_list(815 origin1.clone(),816 CollectionId(1),817 account(2)818 ));819 assert_ok!(Unique::add_to_allow_list(820 origin1.clone(),821 CollectionId(1),822 account(3)823 ));824825 // Account 1 approves account 2 for 1023 pieces of RFT 1826 assert_ok!(Unique::approve(827 origin1,828 account(2),829 CollectionId(1),830 TokenId(1),831 1023832 ));833 assert_eq!(834 <pallet_refungible::Allowance<Test>>::get((835 CollectionId(1),836 TokenId(1),837 account(1),838 account(2)839 )),840 1023841 );842843 // Account 2 transfers 100 pieces of RFT 1 from account 1 to account 3844 assert_ok!(Unique::transfer_from(845 origin2,846 account(1),847 account(3),848 CollectionId(1),849 TokenId(1),850 100851 ));852 assert_eq!(853 <pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))),854 1855 );856 assert_eq!(857 <pallet_refungible::AccountBalance<Test>>::get((collection_id, account(3))),858 1859 );860 assert_eq!(861 <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1))),862 923863 );864 assert_eq!(865 <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(3))),866 100867 );868 assert_eq!(869 <pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),870 true871 );872 assert_eq!(873 <pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),874 true875 );876 assert_eq!(877 <pallet_refungible::Allowance<Test>>::get((878 CollectionId(1),879 TokenId(1),880 account(1),881 account(2)882 )),883 923884 );885 });886}887888#[test]889fn fungible_approve_and_transfer_from() {890 new_test_ext().execute_with(|| {891 let collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));892893 let data = default_fungible_data();894 create_test_item(collection_id, &data.into());895896 let origin1 = Origin::signed(1);897 let origin2 = Origin::signed(2);898899 assert_ok!(Unique::set_mint_permission(900 origin1.clone(),901 CollectionId(1),902 true903 ));904 assert_ok!(Unique::set_public_access_mode(905 origin1.clone(),906 CollectionId(1),907 AccessMode::AllowList908 ));909 assert_ok!(Unique::add_to_allow_list(910 origin1.clone(),911 CollectionId(1),912 account(1)913 ));914 assert_ok!(Unique::add_to_allow_list(915 origin1.clone(),916 CollectionId(1),917 account(2)918 ));919 assert_ok!(Unique::add_to_allow_list(920 origin1.clone(),921 CollectionId(1),922 account(3)923 ));924925 // do approve926 assert_ok!(Unique::approve(927 origin1.clone(),928 account(2),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_ok!(Unique::approve(938 origin1,939 account(3),940 CollectionId(1),941 TokenId(0),942 5943 ));944 assert_eq!(945 <pallet_fungible::Allowance<Test>>::get((CollectionId(1), account(1), account(2))),946 5947 );948 assert_eq!(949 <pallet_fungible::Allowance<Test>>::get((CollectionId(1), account(1), account(3))),950 5951 );952953 assert_ok!(Unique::transfer_from(954 origin2.clone(),955 account(1),956 account(3),957 CollectionId(1),958 TokenId(0),959 4960 ));961962 assert_eq!(963 <pallet_fungible::Allowance<Test>>::get((CollectionId(1), account(1), account(2))),964 1965 );966967 assert_noop!(968 Unique::transfer_from(969 origin2,970 account(1),971 account(3),972 CollectionId(1),973 TokenId(0),974 4975 )976 .map_err(|e| e.error),977 CommonError::<Test>::ApprovedValueTooLow978 );979 });980}981982#[test]983fn change_collection_owner() {984 new_test_ext().execute_with(|| {985 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));986987 let origin1 = Origin::signed(1);988 assert_ok!(Unique::change_collection_owner(origin1, collection_id, 2));989 assert_eq!(990 <pallet_common::CollectionById<Test>>::get(collection_id)991 .unwrap()992 .owner,993 2994 );995 });996}997998#[test]999fn destroy_collection() {1000 new_test_ext().execute_with(|| {1001 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));10021003 let origin1 = Origin::signed(1);1004 assert_ok!(Unique::destroy_collection(origin1, collection_id));1005 });1006}10071008#[test]1009fn burn_nft_item() {1010 new_test_ext().execute_with(|| {1011 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));10121013 let origin1 = Origin::signed(1);10141015 let data = default_nft_data();1016 create_test_item(collection_id, &data.into());10171018 // check balance (collection with id = 1, user id = 1)1019 assert_eq!(1020 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),1021 11022 );10231024 // burn item1025 assert_ok!(Unique::burn_item(1026 origin1.clone(),1027 collection_id,1028 TokenId(1),1029 11030 ));1031 assert_eq!(1032 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),1033 01034 );1035 });1036}10371038#[test]1039fn burn_same_nft_item_twice() {1040 new_test_ext().execute_with(|| {1041 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));10421043 let origin1 = Origin::signed(1);10441045 let data = default_nft_data();1046 create_test_item(collection_id, &data.into());10471048 // check balance (collection with id = 1, user id = 1)1049 assert_eq!(1050 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),1051 11052 );10531054 // burn item1055 assert_ok!(Unique::burn_item(1056 origin1.clone(),1057 collection_id,1058 TokenId(1),1059 11060 ));10611062 // burn item again1063 assert_noop!(1064 Unique::burn_item(origin1, collection_id, TokenId(1), 1).map_err(|e| e.error),1065 CommonError::<Test>::TokenNotFound1066 );10671068 assert_eq!(1069 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),1070 01071 );1072 });1073}10741075#[test]1076fn burn_fungible_item() {1077 new_test_ext().execute_with(|| {1078 let collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));10791080 let origin1 = Origin::signed(1);1081 assert_ok!(Unique::add_collection_admin(1082 origin1.clone(),1083 collection_id,1084 account(2)1085 ));10861087 let data = default_fungible_data();1088 create_test_item(collection_id, &data.into());10891090 // check balance (collection with id = 1, user id = 1)1091 assert_eq!(1092 <pallet_fungible::Balance<Test>>::get((collection_id, account(1))),1093 51094 );10951096 // burn item1097 assert_ok!(Unique::burn_item(1098 origin1.clone(),1099 CollectionId(1),1100 TokenId(0),1101 51102 ));1103 assert_noop!(1104 Unique::burn_item(origin1, CollectionId(1), TokenId(0), 5).map_err(|e| e.error),1105 CommonError::<Test>::TokenValueTooLow1106 );11071108 assert_eq!(1109 <pallet_fungible::Balance<Test>>::get((collection_id, account(1))),1110 01111 );1112 });1113}11141115#[test]1116fn burn_fungible_item_with_token_id() {1117 new_test_ext().execute_with(|| {1118 let collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));11191120 let origin1 = Origin::signed(1);1121 assert_ok!(Unique::add_collection_admin(1122 origin1.clone(),1123 collection_id,1124 account(2)1125 ));11261127 let data = default_fungible_data();1128 create_test_item(collection_id, &data.into());11291130 // check balance (collection with id = 1, user id = 1)1131 assert_eq!(1132 <pallet_fungible::Balance<Test>>::get((collection_id, account(1))),1133 51134 );11351136 // Try to burn item using Token ID1137 assert_noop!(1138 Unique::burn_item(origin1, CollectionId(1), TokenId(1), 5).map_err(|e| e.error),1139 <pallet_fungible::Error::<Test>>::FungibleItemsHaveNoId1140 );1141 });1142}1143#[test]1144fn burn_refungible_item() {1145 new_test_ext().execute_with(|| {1146 let collection_id = create_test_collection(&CollectionMode::ReFungible, CollectionId(1));1147 let origin1 = Origin::signed(1);11481149 assert_ok!(Unique::set_mint_permission(1150 origin1.clone(),1151 collection_id,1152 true1153 ));1154 assert_ok!(Unique::set_public_access_mode(1155 origin1.clone(),1156 collection_id,1157 AccessMode::AllowList1158 ));1159 assert_ok!(Unique::add_to_allow_list(1160 origin1.clone(),1161 collection_id,1162 account(1)1163 ));11641165 assert_ok!(Unique::add_collection_admin(1166 origin1.clone(),1167 collection_id,1168 account(2)1169 ));11701171 let data = default_re_fungible_data();1172 create_test_item(collection_id, &data.into());11731174 // check balance (collection with id = 1, user id = 2)1175 assert_eq!(1176 <pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))),1177 11178 );1179 assert_eq!(1180 <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1))),1181 10231182 );11831184 // burn item1185 assert_ok!(Unique::burn_item(1186 origin1.clone(),1187 collection_id,1188 TokenId(1),1189 10231190 ));1191 assert_noop!(1192 Unique::burn_item(origin1, collection_id, TokenId(1), 1023).map_err(|e| e.error),1193 CommonError::<Test>::TokenValueTooLow1194 );11951196 assert_eq!(1197 <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1))),1198 01199 );1200 });1201}12021203#[test]1204fn add_collection_admin() {1205 new_test_ext().execute_with(|| {1206 let collection1_id =1207 create_test_collection_for_owner(&CollectionMode::NFT, 1, CollectionId(1));1208 let origin1 = Origin::signed(1);12091210 // Add collection admins1211 assert_ok!(Unique::add_collection_admin(1212 origin1.clone(),1213 collection1_id,1214 account(2)1215 ));1216 assert_ok!(Unique::add_collection_admin(1217 origin1,1218 collection1_id,1219 account(3)1220 ));12211222 // Owner is not an admin by default1223 assert_eq!(1224 <pallet_common::IsAdmin<Test>>::get((CollectionId(1), account(1))),1225 false1226 );1227 assert!(<pallet_common::IsAdmin<Test>>::get((1228 CollectionId(1),1229 account(2)1230 )));1231 assert!(<pallet_common::IsAdmin<Test>>::get((1232 CollectionId(1),1233 account(3)1234 )));1235 });1236}12371238#[test]1239fn remove_collection_admin() {1240 new_test_ext().execute_with(|| {1241 let collection1_id =1242 create_test_collection_for_owner(&CollectionMode::NFT, 1, CollectionId(1));1243 let origin1 = Origin::signed(1);1244 let origin2 = Origin::signed(2);12451246 // Add collection admins 2 and 31247 assert_ok!(Unique::add_collection_admin(1248 origin1.clone(),1249 collection1_id,1250 account(2)1251 ));1252 assert_ok!(Unique::add_collection_admin(1253 origin1,1254 collection1_id,1255 account(3)1256 ));12571258 assert!(<pallet_common::IsAdmin<Test>>::get((1259 CollectionId(1),1260 account(2)1261 )));1262 assert!(<pallet_common::IsAdmin<Test>>::get((1263 CollectionId(1),1264 account(3)1265 )));12661267 // remove admin 31268 assert_ok!(Unique::remove_collection_admin(1269 origin2,1270 CollectionId(1),1271 account(3)1272 ));12731274 // 2 is still admin, 3 is not an admin anymore1275 assert!(<pallet_common::IsAdmin<Test>>::get((1276 CollectionId(1),1277 account(2)1278 )));1279 assert_eq!(1280 <pallet_common::IsAdmin<Test>>::get((CollectionId(1), account(3))),1281 false1282 );1283 });1284}12851286#[test]1287fn balance_of() {1288 new_test_ext().execute_with(|| {1289 let nft_collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1290 let fungible_collection_id =1291 create_test_collection(&CollectionMode::Fungible(3), CollectionId(2));1292 let re_fungible_collection_id =1293 create_test_collection(&CollectionMode::ReFungible, CollectionId(3));12941295 // check balance before1296 assert_eq!(1297 <pallet_nonfungible::AccountBalance<Test>>::get((nft_collection_id, account(1))),1298 01299 );1300 assert_eq!(1301 <pallet_fungible::Balance<Test>>::get((fungible_collection_id, account(1))),1302 01303 );1304 assert_eq!(1305 <pallet_refungible::AccountBalance<Test>>::get((re_fungible_collection_id, account(1))),1306 01307 );13081309 let nft_data = default_nft_data();1310 create_test_item(nft_collection_id, &nft_data.into());13111312 let fungible_data = default_fungible_data();1313 create_test_item(fungible_collection_id, &fungible_data.into());13141315 let re_fungible_data = default_re_fungible_data();1316 create_test_item(re_fungible_collection_id, &re_fungible_data.into());13171318 // check balance (collection with id = 1, user id = 1)1319 assert_eq!(1320 <pallet_nonfungible::AccountBalance<Test>>::get((nft_collection_id, account(1))),1321 11322 );1323 assert_eq!(1324 <pallet_fungible::Balance<Test>>::get((fungible_collection_id, account(1))),1325 51326 );1327 assert_eq!(1328 <pallet_refungible::AccountBalance<Test>>::get((re_fungible_collection_id, account(1))),1329 11330 );13311332 assert_eq!(1333 <pallet_nonfungible::Owned<Test>>::get((nft_collection_id, account(1), TokenId(1))),1334 true1335 );1336 assert_eq!(1337 <pallet_refungible::Owned<Test>>::get((1338 re_fungible_collection_id,1339 account(1),1340 TokenId(1)1341 )),1342 true1343 );1344 });1345}13461347#[test]1348fn approve() {1349 new_test_ext().execute_with(|| {1350 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));13511352 let data = default_nft_data();1353 create_test_item(collection_id, &data.into());13541355 let origin1 = Origin::signed(1);13561357 // approve1358 assert_ok!(Unique::approve(1359 origin1,1360 account(2),1361 CollectionId(1),1362 TokenId(1),1363 11364 ));1365 assert_eq!(1366 <pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),1367 account(2)1368 );1369 });1370}13711372#[test]1373fn transfer_from() {1374 new_test_ext().execute_with(|| {1375 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1376 let origin1 = Origin::signed(1);1377 let origin2 = Origin::signed(2);13781379 let data = default_nft_data();1380 create_test_item(collection_id, &data.into());13811382 // approve1383 assert_ok!(Unique::approve(1384 origin1.clone(),1385 account(2),1386 CollectionId(1),1387 TokenId(1),1388 11389 ));1390 assert_eq!(1391 <pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),1392 account(2)1393 );13941395 assert_ok!(Unique::set_mint_permission(1396 origin1.clone(),1397 CollectionId(1),1398 true1399 ));1400 assert_ok!(Unique::set_public_access_mode(1401 origin1.clone(),1402 CollectionId(1),1403 AccessMode::AllowList1404 ));1405 assert_ok!(Unique::add_to_allow_list(1406 origin1.clone(),1407 CollectionId(1),1408 account(1)1409 ));1410 assert_ok!(Unique::add_to_allow_list(1411 origin1.clone(),1412 CollectionId(1),1413 account(2)1414 ));1415 assert_ok!(Unique::add_to_allow_list(1416 origin1,1417 CollectionId(1),1418 account(3)1419 ));14201421 assert_ok!(Unique::transfer_from(1422 origin2,1423 account(1),1424 account(2),1425 CollectionId(1),1426 TokenId(1),1427 11428 ));14291430 // after transfer1431 assert_eq!(1432 <pallet_nonfungible::AccountBalance<Test>>::get((CollectionId(1), account(1))),1433 01434 );1435 assert_eq!(1436 <pallet_nonfungible::AccountBalance<Test>>::get((CollectionId(1), account(2))),1437 11438 );1439 });1440}14411442// #endregion14431444// Coverage tests region1445// #region14461447#[test]1448fn owner_can_add_address_to_allow_list() {1449 new_test_ext().execute_with(|| {1450 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));14511452 let origin1 = Origin::signed(1);1453 assert_ok!(Unique::add_to_allow_list(1454 origin1,1455 collection_id,1456 account(2)1457 ));1458 assert!(<pallet_common::Allowlist<Test>>::get((1459 collection_id,1460 account(2)1461 )));1462 });1463}14641465#[test]1466fn admin_can_add_address_to_allow_list() {1467 new_test_ext().execute_with(|| {1468 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1469 let origin1 = Origin::signed(1);1470 let origin2 = Origin::signed(2);14711472 assert_ok!(Unique::add_collection_admin(1473 origin1,1474 collection_id,1475 account(2)1476 ));1477 assert_ok!(Unique::add_to_allow_list(1478 origin2,1479 collection_id,1480 account(3)1481 ));1482 assert!(<pallet_common::Allowlist<Test>>::get((1483 collection_id,1484 account(3)1485 )));1486 });1487}14881489#[test]1490fn nonprivileged_user_cannot_add_address_to_allow_list() {1491 new_test_ext().execute_with(|| {1492 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));14931494 let origin2 = Origin::signed(2);1495 assert_noop!(1496 Unique::add_to_allow_list(origin2, collection_id, account(3)),1497 CommonError::<Test>::NoPermission1498 );1499 });1500}15011502#[test]1503fn nobody_can_add_address_to_allow_list_of_nonexisting_collection() {1504 new_test_ext().execute_with(|| {1505 let origin1 = Origin::signed(1);15061507 assert_noop!(1508 Unique::add_to_allow_list(origin1, CollectionId(1), account(2)),1509 CommonError::<Test>::CollectionNotFound1510 );1511 });1512}15131514#[test]1515fn nobody_can_add_address_to_allow_list_of_deleted_collection() {1516 new_test_ext().execute_with(|| {1517 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));15181519 let origin1 = Origin::signed(1);1520 assert_ok!(Unique::destroy_collection(origin1.clone(), collection_id));1521 assert_noop!(1522 Unique::add_to_allow_list(origin1, collection_id, account(2)),1523 CommonError::<Test>::CollectionNotFound1524 );1525 });1526}15271528// If address is already added to allow list, nothing happens1529#[test]1530fn address_is_already_added_to_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);15341535 assert_ok!(Unique::add_to_allow_list(1536 origin1.clone(),1537 collection_id,1538 account(2)1539 ));1540 assert_ok!(Unique::add_to_allow_list(1541 origin1,1542 collection_id,1543 account(2)1544 ));1545 assert!(<pallet_common::Allowlist<Test>>::get((1546 collection_id,1547 account(2)1548 )));1549 });1550}15511552#[test]1553fn owner_can_remove_address_from_allow_list() {1554 new_test_ext().execute_with(|| {1555 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));15561557 let origin1 = Origin::signed(1);1558 assert_ok!(Unique::add_to_allow_list(1559 origin1.clone(),1560 collection_id,1561 account(2)1562 ));1563 assert_ok!(Unique::remove_from_allow_list(1564 origin1,1565 collection_id,1566 account(2)1567 ));1568 assert_eq!(1569 <pallet_common::Allowlist<Test>>::get((collection_id, account(2))),1570 false1571 );1572 });1573}15741575#[test]1576fn admin_can_remove_address_from_allow_list() {1577 new_test_ext().execute_with(|| {1578 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1579 let origin1 = Origin::signed(1);1580 let origin2 = Origin::signed(2);15811582 // Owner adds admin1583 assert_ok!(Unique::add_collection_admin(1584 origin1.clone(),1585 collection_id,1586 account(2)1587 ));15881589 // Owner adds address 3 to allow list1590 assert_ok!(Unique::add_to_allow_list(1591 origin1,1592 collection_id,1593 account(3)1594 ));15951596 // Admin removes address 3 from allow list1597 assert_ok!(Unique::remove_from_allow_list(1598 origin2,1599 collection_id,1600 account(3)1601 ));1602 assert_eq!(1603 <pallet_common::Allowlist<Test>>::get((collection_id, account(3))),1604 false1605 );1606 });1607}16081609#[test]1610fn nonprivileged_user_cannot_remove_address_from_allow_list() {1611 new_test_ext().execute_with(|| {1612 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1613 let origin1 = Origin::signed(1);1614 let origin2 = Origin::signed(2);16151616 assert_ok!(Unique::add_to_allow_list(1617 origin1,1618 collection_id,1619 account(2)1620 ));1621 assert_noop!(1622 Unique::remove_from_allow_list(origin2, collection_id, account(2)),1623 CommonError::<Test>::NoPermission1624 );1625 assert!(<pallet_common::Allowlist<Test>>::get((1626 collection_id,1627 account(2)1628 )));1629 });1630}16311632#[test]1633fn nobody_can_remove_address_from_allow_list_of_nonexisting_collection() {1634 new_test_ext().execute_with(|| {1635 let origin1 = Origin::signed(1);16361637 assert_noop!(1638 Unique::remove_from_allow_list(origin1, CollectionId(1), account(2)),1639 CommonError::<Test>::CollectionNotFound1640 );1641 });1642}16431644#[test]1645fn nobody_can_remove_address_from_allow_list_of_deleted_collection() {1646 new_test_ext().execute_with(|| {1647 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1648 let origin1 = Origin::signed(1);1649 let origin2 = Origin::signed(2);16501651 // Add account 2 to allow list1652 assert_ok!(Unique::add_to_allow_list(1653 origin1.clone(),1654 collection_id,1655 account(2)1656 ));16571658 // Account 2 is in collection allow-list1659 assert!(<pallet_common::Allowlist<Test>>::get((1660 collection_id,1661 account(2)1662 )));16631664 // Destroy collection1665 assert_ok!(Unique::destroy_collection(origin1, collection_id));16661667 // Attempt to remove account 2 from collection allow-list => error1668 assert_noop!(1669 Unique::remove_from_allow_list(origin2, collection_id, account(2)),1670 CommonError::<Test>::CollectionNotFound1671 );16721673 // Account 2 is not found in collection allow-list anyway1674 assert_eq!(1675 <pallet_common::Allowlist<Test>>::get((collection_id, account(2))),1676 false1677 );1678 });1679}16801681// If address is already removed from allow list, nothing happens1682#[test]1683fn address_is_already_removed_from_allow_list() {1684 new_test_ext().execute_with(|| {1685 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1686 let origin1 = Origin::signed(1);16871688 assert_ok!(Unique::add_to_allow_list(1689 origin1.clone(),1690 collection_id,1691 account(2)1692 ));1693 assert_ok!(Unique::remove_from_allow_list(1694 origin1.clone(),1695 collection_id,1696 account(2)1697 ));1698 assert_eq!(1699 <pallet_common::Allowlist<Test>>::get((collection_id, account(2))),1700 false1701 );1702 assert_ok!(Unique::remove_from_allow_list(1703 origin1,1704 collection_id,1705 account(2)1706 ));1707 assert_eq!(1708 <pallet_common::Allowlist<Test>>::get((collection_id, account(2))),1709 false1710 );1711 });1712}17131714// If Public Access mode is set to AllowList, tokens can’t be transferred from a non-allowlisted address with transfer or transferFrom (2 tests)1715#[test]1716fn allow_list_test_1() {1717 new_test_ext().execute_with(|| {1718 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));17191720 let origin1 = Origin::signed(1);17211722 let data = default_nft_data();1723 create_test_item(collection_id, &data.into());17241725 assert_ok!(Unique::set_public_access_mode(1726 origin1.clone(),1727 collection_id,1728 AccessMode::AllowList1729 ));1730 assert_ok!(Unique::add_to_allow_list(1731 origin1.clone(),1732 collection_id,1733 account(2)1734 ));17351736 assert_noop!(1737 Unique::transfer(origin1, account(3), CollectionId(1), TokenId(1), 1)1738 .map_err(|e| e.error),1739 CommonError::<Test>::AddressNotInAllowlist1740 );1741 });1742}17431744#[test]1745fn allow_list_test_2() {1746 new_test_ext().execute_with(|| {1747 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));1748 let origin1 = Origin::signed(1);17491750 let data = default_nft_data();1751 create_test_item(collection_id, &data.into());17521753 assert_ok!(Unique::set_public_access_mode(1754 origin1.clone(),1755 collection_id,1756 AccessMode::AllowList1757 ));1758 assert_ok!(Unique::add_to_allow_list(1759 origin1.clone(),1760 collection_id,1761 account(1)1762 ));1763 assert_ok!(Unique::add_to_allow_list(1764 origin1.clone(),1765 collection_id,1766 account(2)1767 ));17681769 // do approve1770 assert_ok!(Unique::approve(1771 origin1.clone(),1772 account(1),1773 collection_id,1774 TokenId(1),1775 11776 ));1777 assert_eq!(1778 <pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),1779 account(1)1780 );17811782 assert_ok!(Unique::remove_from_allow_list(1783 origin1.clone(),1784 collection_id,1785 account(1)1786 ));17871788 assert_noop!(1789 Unique::transfer_from(1790 origin1,1791 account(1),1792 account(3),1793 CollectionId(1),1794 TokenId(1),1795 11796 )1797 .map_err(|e| e.error),1798 CommonError::<Test>::AddressNotInAllowlist1799 );1800 });1801}18021803// If Public Access mode is set to AllowList, tokens can’t be transferred to a non-allowlisted address with transfer or transferFrom (2 tests)1804#[test]1805fn allow_list_test_3() {1806 new_test_ext().execute_with(|| {1807 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));18081809 let origin1 = Origin::signed(1);18101811 let data = default_nft_data();1812 create_test_item(collection_id, &data.into());18131814 assert_ok!(Unique::set_public_access_mode(1815 origin1.clone(),1816 collection_id,1817 AccessMode::AllowList1818 ));1819 assert_ok!(Unique::add_to_allow_list(1820 origin1.clone(),1821 collection_id,1822 account(1)1823 ));18241825 assert_noop!(1826 Unique::transfer(origin1, account(3), collection_id, TokenId(1), 1)1827 .map_err(|e| e.error),1828 CommonError::<Test>::AddressNotInAllowlist1829 );1830 });1831}18321833#[test]1834fn allow_list_test_4() {1835 new_test_ext().execute_with(|| {1836 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));18371838 let origin1 = Origin::signed(1);18391840 let data = default_nft_data();1841 create_test_item(collection_id, &data.into());18421843 assert_ok!(Unique::set_public_access_mode(1844 origin1.clone(),1845 collection_id,1846 AccessMode::AllowList1847 ));1848 assert_ok!(Unique::add_to_allow_list(1849 origin1.clone(),1850 collection_id,1851 account(1)1852 ));1853 assert_ok!(Unique::add_to_allow_list(1854 origin1.clone(),1855 collection_id,1856 account(2)1857 ));18581859 // do approve1860 assert_ok!(Unique::approve(1861 origin1.clone(),1862 account(1),1863 collection_id,1864 TokenId(1),1865 11866 ));1867 assert_eq!(1868 <pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),1869 account(1)1870 );18711872 assert_ok!(Unique::remove_from_allow_list(1873 origin1.clone(),1874 collection_id,1875 account(2)1876 ));18771878 assert_noop!(1879 Unique::transfer_from(1880 origin1,1881 account(1),1882 account(3),1883 collection_id,1884 TokenId(1),1885 11886 )1887 .map_err(|e| e.error),1888 CommonError::<Test>::AddressNotInAllowlist1889 );1890 });1891}18921893// 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)1894#[test]1895fn allow_list_test_5() {1896 new_test_ext().execute_with(|| {1897 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));18981899 let origin1 = Origin::signed(1);19001901 let data = default_nft_data();1902 create_test_item(collection_id, &data.into());19031904 assert_ok!(Unique::set_public_access_mode(1905 origin1.clone(),1906 collection_id,1907 AccessMode::AllowList1908 ));1909 assert_noop!(1910 Unique::burn_item(origin1.clone(), CollectionId(1), TokenId(1), 1).map_err(|e| e.error),1911 CommonError::<Test>::AddressNotInAllowlist1912 );1913 });1914}19151916// If Public Access mode is set to AllowList, token transfers can’t be Approved by a non-allowlisted address (see Approve method).1917#[test]1918fn allow_list_test_6() {1919 new_test_ext().execute_with(|| {1920 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));19211922 let origin1 = Origin::signed(1);19231924 let data = default_nft_data();1925 create_test_item(collection_id, &data.into());19261927 assert_ok!(Unique::set_public_access_mode(1928 origin1.clone(),1929 collection_id,1930 AccessMode::AllowList1931 ));19321933 // do approve1934 assert_noop!(1935 Unique::approve(origin1, account(1), CollectionId(1), TokenId(1), 1)1936 .map_err(|e| e.error),1937 CommonError::<Test>::AddressNotInAllowlist1938 );1939 });1940}19411942// If Public Access mode is set to AllowList, tokens can be transferred from a allowlisted address with transfer or transferFrom (2 tests) and1943// tokens can be transferred from a allowlisted address with transfer or transferFrom (2 tests)1944#[test]1945fn allow_list_test_7() {1946 new_test_ext().execute_with(|| {1947 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));19481949 let data = default_nft_data();1950 create_test_item(collection_id, &data.into());19511952 let origin1 = Origin::signed(1);19531954 assert_ok!(Unique::set_public_access_mode(1955 origin1.clone(),1956 collection_id,1957 AccessMode::AllowList1958 ));1959 assert_ok!(Unique::add_to_allow_list(1960 origin1.clone(),1961 collection_id,1962 account(1)1963 ));1964 assert_ok!(Unique::add_to_allow_list(1965 origin1.clone(),1966 collection_id,1967 account(2)1968 ));19691970 assert_ok!(Unique::transfer(1971 origin1,1972 account(2),1973 CollectionId(1),1974 TokenId(1),1975 11976 ));1977 });1978}19791980#[test]1981fn allow_list_test_8() {1982 new_test_ext().execute_with(|| {1983 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));19841985 // Create NFT for account 11986 let data = default_nft_data();1987 create_test_item(collection_id, &data.into());19881989 let origin1 = Origin::signed(1);19901991 // Toggle Allow List mode and add accounts 1 and 21992 assert_ok!(Unique::set_public_access_mode(1993 origin1.clone(),1994 collection_id,1995 AccessMode::AllowList1996 ));1997 assert_ok!(Unique::add_to_allow_list(1998 origin1.clone(),1999 collection_id,2000 account(1)2001 ));2002 assert_ok!(Unique::add_to_allow_list(2003 origin1.clone(),2004 collection_id,2005 account(2)2006 ));20072008 // Sself-approve account 1 for NFT 12009 assert_ok!(Unique::approve(2010 origin1.clone(),2011 account(1),2012 CollectionId(1),2013 TokenId(1),2014 12015 ));2016 assert_eq!(2017 <pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(),2018 account(1)2019 );20202021 // Transfer from 1 to 22022 assert_ok!(Unique::transfer_from(2023 origin1,2024 account(1),2025 account(2),2026 CollectionId(1),2027 TokenId(1),2028 12029 ));2030 });2031}20322033// If Public Access mode is set to AllowList, and Mint Permission is set to false, tokens can be created by owner.2034#[test]2035fn allow_list_test_9() {2036 new_test_ext().execute_with(|| {2037 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));2038 let origin1 = Origin::signed(1);20392040 assert_ok!(Unique::set_public_access_mode(2041 origin1.clone(),2042 collection_id,2043 AccessMode::AllowList2044 ));2045 assert_ok!(Unique::set_mint_permission(origin1, collection_id, false));20462047 let data = default_nft_data();2048 create_test_item(collection_id, &data.into());2049 });2050}20512052// If Public Access mode is set to AllowList, and Mint Permission is set to false, tokens can be created by admin.2053#[test]2054fn allow_list_test_10() {2055 new_test_ext().execute_with(|| {2056 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));20572058 let origin1 = Origin::signed(1);2059 let origin2 = Origin::signed(2);20602061 assert_ok!(Unique::set_public_access_mode(2062 origin1.clone(),2063 collection_id,2064 AccessMode::AllowList2065 ));2066 assert_ok!(Unique::set_mint_permission(2067 origin1.clone(),2068 collection_id,2069 false2070 ));20712072 assert_ok!(Unique::add_collection_admin(2073 origin1,2074 collection_id,2075 account(2)2076 ));20772078 assert_ok!(Unique::create_item(2079 origin2,2080 collection_id,2081 account(2),2082 default_nft_data().into()2083 ));2084 });2085}20862087// 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.2088#[test]2089fn allow_list_test_11() {2090 new_test_ext().execute_with(|| {2091 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));20922093 let origin1 = Origin::signed(1);2094 let origin2 = Origin::signed(2);20952096 assert_ok!(Unique::set_public_access_mode(2097 origin1.clone(),2098 collection_id,2099 AccessMode::AllowList2100 ));2101 assert_ok!(Unique::set_mint_permission(2102 origin1.clone(),2103 collection_id,2104 false2105 ));2106 assert_ok!(Unique::add_to_allow_list(2107 origin1,2108 collection_id,2109 account(2)2110 ));21112112 assert_noop!(2113 Unique::create_item(2114 origin2,2115 CollectionId(1),2116 account(2),2117 default_nft_data().into()2118 )2119 .map_err(|e| e.error),2120 CommonError::<Test>::PublicMintingNotAllowed2121 );2122 });2123}21242125// 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.2126#[test]2127fn allow_list_test_12() {2128 new_test_ext().execute_with(|| {2129 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));21302131 let origin1 = Origin::signed(1);2132 let origin2 = Origin::signed(2);21332134 assert_ok!(Unique::set_public_access_mode(2135 origin1.clone(),2136 collection_id,2137 AccessMode::AllowList2138 ));2139 assert_ok!(Unique::set_mint_permission(origin1, collection_id, false));21402141 assert_noop!(2142 Unique::create_item(2143 origin2,2144 CollectionId(1),2145 account(2),2146 default_nft_data().into()2147 )2148 .map_err(|e| e.error),2149 CommonError::<Test>::PublicMintingNotAllowed2150 );2151 });2152}21532154// If Public Access mode is set to AllowList, and Mint Permission is set to true, tokens can be created by owner.2155#[test]2156fn allow_list_test_13() {2157 new_test_ext().execute_with(|| {2158 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));21592160 let origin1 = Origin::signed(1);21612162 assert_ok!(Unique::set_public_access_mode(2163 origin1.clone(),2164 collection_id,2165 AccessMode::AllowList2166 ));2167 assert_ok!(Unique::set_mint_permission(origin1, collection_id, true));21682169 let data = default_nft_data();2170 create_test_item(collection_id, &data.into());2171 });2172}21732174// If Public Access mode is set to AllowList, and Mint Permission is set to true, tokens can be created by admin.2175#[test]2176fn allow_list_test_14() {2177 new_test_ext().execute_with(|| {2178 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));21792180 let origin1 = Origin::signed(1);2181 let origin2 = Origin::signed(2);21822183 assert_ok!(Unique::set_public_access_mode(2184 origin1.clone(),2185 collection_id,2186 AccessMode::AllowList2187 ));2188 assert_ok!(Unique::set_mint_permission(2189 origin1.clone(),2190 collection_id,2191 true2192 ));21932194 assert_ok!(Unique::add_collection_admin(2195 origin1,2196 collection_id,2197 account(2)2198 ));21992200 assert_ok!(Unique::create_item(2201 origin2,2202 collection_id,2203 account(2),2204 default_nft_data().into()2205 ));2206 });2207}22082209// 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.2210#[test]2211fn allow_list_test_15() {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!(Unique::set_public_access_mode(2219 origin1.clone(),2220 collection_id,2221 AccessMode::AllowList2222 ));2223 assert_ok!(Unique::set_mint_permission(origin1, collection_id, true));22242225 assert_noop!(2226 Unique::create_item(2227 origin2,2228 collection_id,2229 account(2),2230 default_nft_data().into()2231 )2232 .map_err(|e| e.error),2233 CommonError::<Test>::AddressNotInAllowlist2234 );2235 });2236}22372238// 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.2239#[test]2240fn allow_list_test_16() {2241 new_test_ext().execute_with(|| {2242 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));22432244 let origin1 = Origin::signed(1);2245 let origin2 = Origin::signed(2);22462247 assert_ok!(Unique::set_public_access_mode(2248 origin1.clone(),2249 collection_id,2250 AccessMode::AllowList2251 ));2252 assert_ok!(Unique::set_mint_permission(2253 origin1.clone(),2254 collection_id,2255 true2256 ));2257 assert_ok!(Unique::add_to_allow_list(2258 origin1,2259 collection_id,2260 account(2)2261 ));22622263 assert_ok!(Unique::create_item(2264 origin2,2265 collection_id,2266 account(2),2267 default_nft_data().into()2268 ));2269 });2270}22712272// Total number of collections. Positive test2273#[test]2274fn total_number_collections_bound() {2275 new_test_ext().execute_with(|| {2276 create_test_collection(&CollectionMode::NFT, CollectionId(1));2277 });2278}22792280#[test]2281fn create_max_collections() {2282 new_test_ext().execute_with(|| {2283 for i in 1..COLLECTION_NUMBER_LIMIT {2284 create_test_collection(&CollectionMode::NFT, CollectionId(i));2285 }2286 });2287}22882289// Total number of collections. Negative test2290#[test]2291fn total_number_collections_bound_neg() {2292 new_test_ext().execute_with(|| {2293 let origin1 = Origin::signed(1);22942295 for i in 1..=COLLECTION_NUMBER_LIMIT {2296 create_test_collection(&CollectionMode::NFT, CollectionId(i));2297 }22982299 let col_name1: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();2300 let col_desc1: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();2301 let token_prefix1: Vec<u8> = b"token_prefix1\0".to_vec();23022303 let data: CreateCollectionData<u64> = CreateCollectionData {2304 name: col_name1.try_into().unwrap(),2305 description: col_desc1.try_into().unwrap(),2306 token_prefix: token_prefix1.try_into().unwrap(),2307 mode: CollectionMode::NFT,2308 ..Default::default()2309 };23102311 // 11-th collection in chain. Expects error2312 assert_noop!(2313 Unique::create_collection_ex(origin1, data),2314 CommonError::<Test>::TotalCollectionsLimitExceeded2315 );2316 });2317}23182319// Owned tokens by a single address. Positive test2320#[test]2321fn owned_tokens_bound() {2322 new_test_ext().execute_with(|| {2323 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));23242325 let data = default_nft_data();2326 create_test_item(collection_id, &data.clone().into());2327 create_test_item(collection_id, &data.into());2328 });2329}23302331// Owned tokens by a single address. Negotive test2332#[test]2333fn owned_tokens_bound_neg() {2334 new_test_ext().execute_with(|| {2335 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));23362337 let origin1 = Origin::signed(1);23382339 for _ in 1..=MAX_TOKEN_OWNERSHIP {2340 let data = default_nft_data();2341 create_test_item(collection_id, &data.clone().into());2342 }23432344 let data = default_nft_data();2345 assert_noop!(2346 Unique::create_item(origin1, CollectionId(1), account(1), data.into())2347 .map_err(|e| e.error),2348 CommonError::<Test>::AccountTokenLimitExceeded2349 );2350 });2351}23522353// Number of collection admins. Positive test2354#[test]2355fn collection_admins_bound() {2356 new_test_ext().execute_with(|| {2357 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));23582359 let origin1 = Origin::signed(1);23602361 assert_ok!(Unique::add_collection_admin(2362 origin1.clone(),2363 collection_id,2364 account(2)2365 ));2366 assert_ok!(Unique::add_collection_admin(2367 origin1,2368 collection_id,2369 account(3)2370 ));2371 });2372}23732374// Number of collection admins. Negotive test2375#[test]2376fn collection_admins_bound_neg() {2377 new_test_ext().execute_with(|| {2378 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));23792380 let origin1 = Origin::signed(1);23812382 for i in 0..COLLECTION_ADMINS_LIMIT {2383 assert_ok!(Unique::add_collection_admin(2384 origin1.clone(),2385 collection_id,2386 account((2 + i).into())2387 ));2388 }2389 assert_noop!(2390 Unique::add_collection_admin(2391 origin1,2392 collection_id,2393 account((3 + COLLECTION_ADMINS_LIMIT).into())2394 ),2395 CommonError::<Test>::CollectionAdminCountExceeded2396 );2397 });2398}2399// #endregion24002401#[test]2402fn set_const_on_chain_schema() {2403 new_test_ext().execute_with(|| {2404 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));24052406 let origin1 = Origin::signed(1);2407 assert_ok!(Unique::set_const_on_chain_schema(2408 origin1,2409 collection_id,2410 b"test const on chain schema".to_vec().try_into().unwrap()2411 ));24122413 assert_eq!(2414 <pallet_common::CollectionData<Test>>::get((2415 collection_id,2416 CollectionField::ConstOnChainSchema2417 )),2418 b"test const on chain schema".to_vec()2419 );2420 });2421}24222423#[test]2424fn collection_transfer_flag_works() {2425 new_test_ext().execute_with(|| {2426 let origin1 = Origin::signed(1);24272428 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));2429 assert_ok!(Unique::set_transfers_enabled_flag(2430 origin1,2431 collection_id,2432 true2433 ));24342435 let data = default_nft_data();2436 create_test_item(collection_id, &data.into());2437 assert_eq!(2438 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),2439 12440 );2441 assert_eq!(2442 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),2443 true2444 );24452446 let origin1 = Origin::signed(1);24472448 // default scenario2449 assert_ok!(Unique::transfer(2450 origin1,2451 account(2),2452 collection_id,2453 TokenId(1),2454 12455 ));2456 assert_eq!(2457 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),2458 false2459 );2460 assert_eq!(2461 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))),2462 true2463 );2464 assert_eq!(2465 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),2466 02467 );2468 assert_eq!(2469 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(2))),2470 12471 );2472 });2473}24742475#[test]2476fn collection_transfer_flag_works_neg() {2477 new_test_ext().execute_with(|| {2478 let origin1 = Origin::signed(1);24792480 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));2481 assert_ok!(Unique::set_transfers_enabled_flag(2482 origin1,2483 collection_id,2484 false2485 ));24862487 let data = default_nft_data();2488 create_test_item(collection_id, &data.into());2489 assert_eq!(2490 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),2491 12492 );2493 assert_eq!(2494 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),2495 true2496 );24972498 let origin1 = Origin::signed(1);24992500 // default scenario2501 assert_noop!(2502 Unique::transfer(origin1, account(2), CollectionId(1), TokenId(1), 1)2503 .map_err(|e| e.error),2504 CommonError::<Test>::TransferNotAllowed2505 );2506 assert_eq!(2507 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))),2508 12509 );2510 assert_eq!(2511 <pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(2))),2512 02513 );2514 assert_eq!(2515 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))),2516 true2517 );2518 assert_eq!(2519 <pallet_nonfungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))),2520 false2521 );2522 });2523}25242525#[test]2526fn collection_sponsoring() {2527 new_test_ext().execute_with(|| {2528 // default_limits();2529 let user1 = 1_u64;2530 let user2 = 777_u64;2531 let origin1 = Origin::signed(user1);2532 let origin2 = Origin::signed(user2);2533 let account2 = account(user2);25342535 let collection_id =2536 create_test_collection_for_owner(&CollectionMode::NFT, user1, CollectionId(1));2537 assert_ok!(Unique::set_collection_sponsor(2538 origin1.clone(),2539 collection_id,2540 user12541 ));2542 assert_ok!(Unique::confirm_sponsorship(origin1.clone(), collection_id));25432544 // Expect error while have no permissions2545 assert!(Unique::create_item(2546 origin2.clone(),2547 collection_id,2548 account2.clone(),2549 default_nft_data().into()2550 )2551 .is_err());25522553 assert_ok!(Unique::set_public_access_mode(2554 origin1.clone(),2555 collection_id,2556 AccessMode::AllowList2557 ));2558 assert_ok!(Unique::add_to_allow_list(2559 origin1.clone(),2560 collection_id,2561 account2.clone()2562 ));2563 assert_ok!(Unique::set_mint_permission(2564 origin1.clone(),2565 collection_id,2566 true2567 ));25682569 assert_ok!(Unique::create_item(2570 origin2,2571 collection_id,2572 account2,2573 default_nft_data().into()2574 ));2575 });2576}