git.delta.rocks / unique-network / refs/commits / 9d35eaceaefb

difftreelog

source

pallets/nft/src/tests.rs64.8 KiBsourcehistory
1// Tests to be written here2use super::*;3use crate::mock::*;4use crate::{AccessMode, CollectionMode,5    Ownership, ChainLimits, CreateItemData, CreateNftData, CreateFungibleData, CreateReFungibleData,6    CollectionId, TokenId, MAX_DECIMAL_POINTS};7use frame_support::{assert_noop, assert_ok};8use frame_system::{ RawOrigin };910fn default_collection_numbers_limit() -> u32 {11    1012}1314fn default_limits() {15    assert_ok!(TemplateModule::set_chain_limits(RawOrigin::Root.into(), ChainLimits {16            collection_numbers_limit: default_collection_numbers_limit(),17            account_token_ownership_limit: 10,18            collections_admins_limit: 5,19            custom_data_limit: 2048,20            nft_sponsor_transfer_timeout: 15,21            fungible_sponsor_transfer_timeout: 15,22            refungible_sponsor_transfer_timeout: 15,23            const_on_chain_schema_limit: 1024,24            offchain_schema_limit: 1024,25            variable_on_chain_schema_limit: 1024,26        }));27}2829fn default_nft_data() -> CreateNftData {30    CreateNftData { const_data: vec![1, 2, 3], variable_data: vec![3, 2, 1] }31}3233fn default_fungible_data () -> CreateFungibleData {34    CreateFungibleData { value: 5 }35}3637fn default_re_fungible_data () -> CreateReFungibleData {38    CreateReFungibleData { const_data: vec![1, 2, 3], variable_data: vec![3, 2, 1], pieces: 1023 }39}4041fn create_test_collection_for_owner(mode: &CollectionMode, owner: u64, id: CollectionId) -> CollectionId {42    let col_name1: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();43    let col_desc1: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();44    let token_prefix1: Vec<u8> = b"token_prefix1\0".to_vec();4546    let origin1 = Origin::signed(owner);47    assert_ok!(TemplateModule::create_collection(48            origin1.clone(),49            col_name1.clone(),50            col_desc1.clone(),51            token_prefix1.clone(),52            mode.clone()53        ));5455    let saved_col_name: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();56    let saved_description: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();57    let saved_prefix: Vec<u8> = b"token_prefix1\0".to_vec();58    assert_eq!(TemplateModule::collection_id(id).unwrap().owner, owner);59    assert_eq!(TemplateModule::collection_id(id).unwrap().name, saved_col_name);60    assert_eq!(TemplateModule::collection_id(id).unwrap().mode, *mode);61    assert_eq!(TemplateModule::collection_id(id).unwrap().description, saved_description);62    assert_eq!(TemplateModule::collection_id(id).unwrap().token_prefix, saved_prefix);63    id64}6566fn create_test_collection(mode: &CollectionMode, id: CollectionId) -> CollectionId {67    create_test_collection_for_owner(&mode, 1, id)68}6970fn create_test_item(collection_id: CollectionId, data: &CreateItemData) {71    let origin1 = Origin::signed(1);72    assert_ok!(TemplateModule::create_item(73            origin1.clone(),74            collection_id,75            1,76            data.clone()77        ));7879}8081// Use cases tests region82// #region8384#[test]85fn set_version_schema() {86    new_test_ext().execute_with(|| {87        default_limits();88        let origin1 = Origin::signed(1);89        let collection_id = create_test_collection(&CollectionMode::NFT, 1);90        91        assert_ok!(TemplateModule::set_schema_version(origin1, collection_id, SchemaVersion::Unique));92        assert_eq!(TemplateModule::collection_id(collection_id).unwrap().schema_version, SchemaVersion::Unique);93    });94}9596#[test]97fn create_fungible_collection_fails_with_large_decimal_numbers() {98    new_test_ext().execute_with(|| {99        default_limits();100101        let col_name1: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();102        let col_desc1: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();103        let token_prefix1: Vec<u8> = b"token_prefix1\0".to_vec();104105        let origin1 = Origin::signed(1);106        assert_noop!(TemplateModule::create_collection(107            origin1,108            col_name1,109            col_desc1,110            token_prefix1,111            CollectionMode::Fungible(MAX_DECIMAL_POINTS + 1)112        ), Error::<Test>::CollectionDecimalPointLimitExceeded);113    });    114}115116#[test]117fn create_nft_item() {118    new_test_ext().execute_with(|| {119        default_limits();120        let collection_id = create_test_collection(&CollectionMode::NFT, 1);121        122        let data = default_nft_data();123        create_test_item(collection_id, &data.clone().into());124        let item = TemplateModule::nft_item_id(collection_id, 1).unwrap();125        assert_eq!(item.const_data, data.const_data);126        assert_eq!(item.variable_data, data.variable_data);127    });128}129130// Use cases tests region131// #region132#[test]133fn create_nft_multiple_items() {134    new_test_ext().execute_with(|| {135        default_limits();136        137        create_test_collection(&CollectionMode::NFT, 1);138139        let origin1 = Origin::signed(1);140141        let items_data = vec![default_nft_data(), default_nft_data(), default_nft_data()];142143        assert_ok!(TemplateModule::create_multiple_items(144            origin1.clone(),145            1,146            1,147            items_data.clone().into_iter().map(|d| { d.into() }).collect()148        ));149        for (index, data) in items_data.iter().enumerate() {150            let item = TemplateModule::nft_item_id(1, (index + 1) as TokenId).unwrap(); 151            assert_eq!(item.const_data.to_vec(), data.const_data);152            assert_eq!(item.variable_data.to_vec(), data.variable_data);153        }154    });155}156157#[test]158fn create_refungible_item() {159    new_test_ext().execute_with(|| {160        default_limits();161        let collection_id = create_test_collection(&CollectionMode::ReFungible, 1);162163        let data = default_re_fungible_data();164        create_test_item(collection_id, &data.clone().into());165        let item = TemplateModule::refungible_item_id(collection_id, 1).unwrap();166        assert_eq!(167            item.const_data,168            data.const_data169        );170        assert_eq!(171            item.variable_data,172            data.variable_data173        );174        assert_eq!(175            item.owner[0],176            Ownership {177                owner: 1,178                fraction: 1023179            }180        );181    });182}183184#[test]185fn create_multiple_refungible_items() {186    new_test_ext().execute_with(|| {187        default_limits();188        189        create_test_collection(&CollectionMode::ReFungible, 1);190191        let origin1 = Origin::signed(1);192193        let items_data = vec![default_re_fungible_data(), default_re_fungible_data(), default_re_fungible_data()];194195        assert_ok!(TemplateModule::create_multiple_items(196            origin1.clone(),197            1,198            1,199            items_data.clone().into_iter().map(|d| { d.into() }).collect()200        ));201        for (index, data) in items_data.iter().enumerate() {202203            let item = TemplateModule::refungible_item_id(1, (index + 1) as TokenId).unwrap();204            assert_eq!(item.const_data.to_vec(), data.const_data);205            assert_eq!(item.variable_data.to_vec(), data.variable_data);206            assert_eq!(207                item.owner[0],208                Ownership {209                    owner: 1,210                    fraction: 1023211                }212            );213        }214    });215}216217#[test]218fn create_fungible_item() {219    new_test_ext().execute_with(|| {220        default_limits();221        222        let collection_id = create_test_collection(&CollectionMode::Fungible(3), 1);223224        let data = default_fungible_data();225        create_test_item(collection_id, &data.into());226227        assert_eq!(TemplateModule::fungible_item_id(collection_id, 1).value, 5);228    });229}230231//#[test]232// fn create_multiple_fungible_items() {233//     new_test_ext().execute_with(|| {234//         default_limits();235236//         create_test_collection(&CollectionMode::Fungible(3), 1);237238//         let origin1 = Origin::signed(1);239240//         let items_data = vec![default_fungible_data(), default_fungible_data(), default_fungible_data()];241242//         assert_ok!(TemplateModule::create_multiple_items(243//             origin1.clone(),244//             1,245//             1,246//             items_data.clone().into_iter().map(|d| { d.into() }).collect()247//         ));248        249//         for (index, _) in items_data.iter().enumerate() {250//             assert_eq!(TemplateModule::fungible_item_id(1, (index + 1) as TokenId).value, 5);251//         }252//         assert_eq!(TemplateModule::balance_count(1, 1), 3000);253//         assert_eq!(TemplateModule::address_tokens(1, 1), [1, 2, 3]);254//     });255// }256257#[test]258fn transfer_fungible_item() {259    new_test_ext().execute_with(|| {260        default_limits();261        262        let collection_id = create_test_collection(&CollectionMode::Fungible(3), 1);263264        let origin1 = Origin::signed(1);265        let origin2 = Origin::signed(2);266267        let data = default_fungible_data();268        create_test_item(collection_id, &data.into());269270        assert_eq!(TemplateModule::fungible_item_id(1, 1).value, 5);271        assert_eq!(TemplateModule::balance_count(1, 1), 5);272273        // change owner scenario274        assert_ok!(TemplateModule::transfer(origin1.clone(), 2, 1, 1, 5));275        assert_eq!(TemplateModule::fungible_item_id(1, 1).value, 0);276        assert_eq!(TemplateModule::balance_count(1, 1), 0);277        assert_eq!(TemplateModule::balance_count(1, 2), 5);278279        // split item scenario280        assert_ok!(TemplateModule::transfer(origin2.clone(), 3, 1, 1, 3));281        assert_eq!(TemplateModule::balance_count(1, 2), 2);282        assert_eq!(TemplateModule::balance_count(1, 3), 3);283284        // split item and new owner has account scenario285        assert_ok!(TemplateModule::transfer(origin2.clone(), 3, 1, 1, 1));286        assert_eq!(TemplateModule::fungible_item_id(1, 2).value, 1);287        assert_eq!(TemplateModule::fungible_item_id(1, 3).value, 4);288        assert_eq!(TemplateModule::balance_count(1, 2), 1);289        assert_eq!(TemplateModule::balance_count(1, 3), 4);290    });291}292293#[test]294fn transfer_refungible_item() {295    new_test_ext().execute_with(|| {296        default_limits();297        298        let collection_id = create_test_collection(&CollectionMode::ReFungible, 1);299300        let data = default_re_fungible_data();301        create_test_item(collection_id, &data.clone().into());302303        let origin1 = Origin::signed(1);304        let origin2 = Origin::signed(2);305        {306            let item = TemplateModule::refungible_item_id(collection_id, 1).unwrap();307            assert_eq!(308                item.const_data,309                data.const_data310            );311            assert_eq!(312                item.variable_data,313                data.variable_data314            );315            assert_eq!(316                item.owner[0],317                Ownership {318                    owner: 1,319                    fraction: 1023320                }321            );322        }323        assert_eq!(TemplateModule::balance_count(1, 1), 1023);324        assert_eq!(TemplateModule::address_tokens(1, 1), [1]);325326        // change owner scenario327        assert_ok!(TemplateModule::transfer(origin1.clone(), 2, 1, 1, 1023));328        assert_eq!(329            TemplateModule::refungible_item_id(1, 1).unwrap().owner[0],330            Ownership {331                owner: 2,332                fraction: 1023333            }334        );335        assert_eq!(TemplateModule::balance_count(1, 1), 0);336        assert_eq!(TemplateModule::balance_count(1, 2), 1023);337        // assert_eq!(TemplateModule::address_tokens(1, 1), []);338        assert_eq!(TemplateModule::address_tokens(1, 2), [1]);339340        // split item scenario341        assert_ok!(TemplateModule::transfer(origin2.clone(), 3, 1, 1, 500));342        {343            let item = TemplateModule::refungible_item_id(1, 1).unwrap();344            assert_eq!(345                item.owner[0],346                Ownership {347                    owner: 2,348                    fraction: 523349                }350            );351            assert_eq!(352                item.owner[1],353                Ownership {354                    owner: 3,355                    fraction: 500356                }357            );358        }359        assert_eq!(TemplateModule::balance_count(1, 2), 523);360        assert_eq!(TemplateModule::balance_count(1, 3), 500);361        assert_eq!(TemplateModule::address_tokens(1, 2), [1]);362        assert_eq!(TemplateModule::address_tokens(1, 3), [1]);363364        // split item and new owner has account scenario365        assert_ok!(TemplateModule::transfer(origin2.clone(), 3, 1, 1, 200));366        {367            let item = TemplateModule::refungible_item_id(1, 1).unwrap();368            assert_eq!(369                item.owner[0],370                Ownership {371                    owner: 2,372                    fraction: 323373                }374            );375            assert_eq!(376                item.owner[1],377                Ownership {378                    owner: 3,379                    fraction: 700380                }381            );382        }383        assert_eq!(TemplateModule::balance_count(1, 2), 323);384        assert_eq!(TemplateModule::balance_count(1, 3), 700);385        assert_eq!(TemplateModule::address_tokens(1, 2), [1]);386        assert_eq!(TemplateModule::address_tokens(1, 3), [1]);387    });388}389390#[test]391fn transfer_nft_item() {392    new_test_ext().execute_with(|| {393        default_limits();394        395        let collection_id = create_test_collection(&CollectionMode::NFT, 1);396397        let data = default_nft_data();398        create_test_item(collection_id, &data.into());399        assert_eq!(TemplateModule::balance_count(1, 1), 1);400        assert_eq!(TemplateModule::address_tokens(1, 1), [1]);401402        let origin1 = Origin::signed(1);403        // default scenario404        assert_ok!(TemplateModule::transfer(origin1.clone(), 2, 1, 1, 1000));405        assert_eq!(TemplateModule::nft_item_id(1, 1).unwrap().owner, 2);406        assert_eq!(TemplateModule::balance_count(1, 1), 0);407        assert_eq!(TemplateModule::balance_count(1, 2), 1);408        // assert_eq!(TemplateModule::address_tokens(1, 1), []);409        assert_eq!(TemplateModule::address_tokens(1, 2), [1]);410    });411}412413#[test]414fn nft_approve_and_transfer_from() {415    new_test_ext().execute_with(|| {416        default_limits();417        418        let collection_id = create_test_collection(&CollectionMode::NFT, 1);419420        let data = default_nft_data();421        create_test_item(collection_id, &data.into());422423        let origin1 = Origin::signed(1);424        let origin2 = Origin::signed(2);425426        assert_eq!(TemplateModule::balance_count(1, 1), 1);427        assert_eq!(TemplateModule::address_tokens(1, 1), [1]);428429        // neg transfer430        assert_noop!(TemplateModule::transfer_from(431            origin2.clone(),432            1,433            2,434            1,435            1,436            1), Error::<Test>::NoPermission);437438        // do approve439        assert_ok!(TemplateModule::approve(origin1.clone(), 2, 1, 1, 5));440        assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 5);441        assert_eq!(442            TemplateModule::approved(1, (1, 1, 2)),443            5444        );445446        assert_ok!(TemplateModule::transfer_from(447            origin2.clone(),448            1,449            3,450            1,451            1,452            1453        ));454        assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 4);455    });456}457458#[test]459fn nft_approve_and_transfer_from_white_list() {460    new_test_ext().execute_with(|| {461        default_limits();462        463        let collection_id = create_test_collection(&CollectionMode::NFT, 1);464465        let origin1 = Origin::signed(1);466        let origin2 = Origin::signed(2);467468        let data = default_nft_data();469        create_test_item(collection_id, &data.clone().into());470471        assert_eq!(TemplateModule::nft_item_id(1, 1).unwrap().const_data, data.const_data);472        assert_eq!(TemplateModule::balance_count(1, 1), 1);473        assert_eq!(TemplateModule::address_tokens(1, 1), [1]);474475        assert_ok!(TemplateModule::set_mint_permission(476            origin1.clone(),477            1,478            true479        ));480        assert_ok!(TemplateModule::set_public_access_mode(481            origin1.clone(),482            1,483            AccessMode::WhiteList484        ));485        assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), 1, 1));486        assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), 1, 2));487        assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), 1, 3));488489        // do approve490        assert_ok!(TemplateModule::approve(origin1.clone(), 2, 1, 1, 5));491        assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 5);492        assert_ok!(TemplateModule::approve(origin1.clone(), 3, 1, 1, 5));493        assert_eq!(TemplateModule::approved(1, (1, 1, 3)), 5);494495        assert_ok!(TemplateModule::transfer_from(496            origin2.clone(),497            1,498            3,499            1,500            1,501            1502        ));503        assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 4);504    });505}506507#[test]508fn refungible_approve_and_transfer_from() {509    new_test_ext().execute_with(|| {510        default_limits();511        512        let collection_id = create_test_collection(&CollectionMode::ReFungible, 1);513        514        let origin1 = Origin::signed(1);515        let origin2 = Origin::signed(2);516517        let data = default_re_fungible_data();518        create_test_item(collection_id, &data.into());519520        assert_eq!(TemplateModule::balance_count(1, 1), 1023);521        assert_eq!(TemplateModule::address_tokens(1, 1), [1]);522523        assert_ok!(TemplateModule::set_mint_permission(524            origin1.clone(),525            1,526            true527        ));528        assert_ok!(TemplateModule::set_public_access_mode(529            origin1.clone(),530            1,531            AccessMode::WhiteList532        ));533        assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), 1, 1));534        assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), 1, 2));535        assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), 1, 3));536537        // do approve538        assert_ok!(TemplateModule::approve(origin1.clone(), 2, 1, 1, 1023));539        assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 1023);540541        assert_ok!(TemplateModule::transfer_from(542            origin2.clone(),543            1,544            3,545            1,546            1,547            100548        ));549        assert_eq!(TemplateModule::balance_count(1, 1), 923);550        assert_eq!(TemplateModule::balance_count(1, 3), 100);551        assert_eq!(TemplateModule::address_tokens(1, 1), [1]);552        assert_eq!(TemplateModule::address_tokens(1, 3), [1]);553554        assert_eq!(555            TemplateModule::approved(1, (1, 1, 2)),556            923557        );558    });559}560561#[test]562fn fungible_approve_and_transfer_from() {563    new_test_ext().execute_with(|| {564        default_limits();565        566        let collection_id = create_test_collection(&CollectionMode::Fungible(3), 1);567        568        let data = default_fungible_data();569        create_test_item(collection_id, &data.into());570571        let origin1 = Origin::signed(1);572        let origin2 = Origin::signed(2);573574        assert_eq!(TemplateModule::balance_count(1, 1), 5);575576        assert_ok!(TemplateModule::set_mint_permission(577            origin1.clone(),578            1,579            true580        ));581        assert_ok!(TemplateModule::set_public_access_mode(582            origin1.clone(),583            1,584            AccessMode::WhiteList585        ));586        assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), 1, 1));587        assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), 1, 2));588        assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), 1, 3));589590        // do approve591        assert_ok!(TemplateModule::approve(origin1.clone(), 2, 1, 1, 5));592        assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 5);593        assert_ok!(TemplateModule::approve(origin1.clone(), 3, 1, 1, 5));594        assert_eq!(TemplateModule::approved(1, (1, 1, 3)), 5);595        assert_eq!(596            TemplateModule::approved(1, (1, 1, 2)),597            5598        );599600        assert_ok!(TemplateModule::transfer_from(601            origin2.clone(),602            1,603            3,604            1,605            1,606            4607        ));608        assert_eq!(TemplateModule::balance_count(1, 1), 1);609        assert_eq!(TemplateModule::balance_count(1, 3), 4);610611        assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 1);612613        assert_noop!(TemplateModule::transfer_from(614            origin2.clone(),615            1,616            3,617            1,618            1,619            4620        ), Error::<Test>::NoPermission);621    });622}623624#[test]625fn change_collection_owner() {626    new_test_ext().execute_with(|| {627        default_limits();628        629        let collection_id = create_test_collection(&CollectionMode::NFT, 1);630        631        let origin1 = Origin::signed(1);632        assert_ok!(TemplateModule::change_collection_owner(633            origin1.clone(),634            collection_id,635            2636        ));637        assert_eq!(TemplateModule::collection_id(collection_id).unwrap().owner, 2);638    });639}640641#[test]642fn destroy_collection() {643    new_test_ext().execute_with(|| {644        default_limits();645        646        let collection_id = create_test_collection(&CollectionMode::NFT, 1);647        648        let origin1 = Origin::signed(1);649        assert_ok!(TemplateModule::destroy_collection(origin1.clone(), collection_id));650    });651}652653#[test]654fn burn_nft_item() {655    new_test_ext().execute_with(|| {656        default_limits();657        658        let collection_id = create_test_collection(&CollectionMode::NFT, 1);659660        let origin1 = Origin::signed(1);661        assert_ok!(TemplateModule::add_collection_admin(origin1.clone(), collection_id, 2));662        663        let data = default_nft_data();664        create_test_item(collection_id, &data.into());665666        // check balance (collection with id = 1, user id = 1)667        assert_eq!(TemplateModule::balance_count(1, 1), 1);668669        // burn item670        assert_ok!(TemplateModule::burn_item(origin1.clone(), 1, 1, 5));671        assert_noop!(672            TemplateModule::burn_item(origin1.clone(), 1, 1, 5),673            Error::<Test>::TokenNotFound674        );675676        assert_eq!(TemplateModule::balance_count(1, 1), 0);677    });678}679680#[test]681fn burn_fungible_item() {682    new_test_ext().execute_with(|| {683        default_limits();684        685        let collection_id = create_test_collection(&CollectionMode::Fungible(3), 1);686        687        let origin1 = Origin::signed(1);688        assert_ok!(TemplateModule::add_collection_admin(origin1.clone(), collection_id, 2));689        690        let data = default_fungible_data();691        create_test_item(collection_id, &data.into());692693        // check balance (collection with id = 1, user id = 1)694        assert_eq!(TemplateModule::balance_count(1, 1), 5);695696        // burn item697        assert_ok!(TemplateModule::burn_item(origin1.clone(), 1, 1, 5));698        assert_noop!(699            TemplateModule::burn_item(origin1.clone(), 1, 1, 5),700            Error::<Test>::TokenValueNotEnough701        );702703        assert_eq!(TemplateModule::balance_count(1, 1), 0);704    });705}706707#[test]708fn burn_refungible_item() {709    new_test_ext().execute_with(|| {710        default_limits();711        712        let collection_id = create_test_collection(&CollectionMode::ReFungible, 1);713        let origin1 = Origin::signed(1);714715        assert_ok!(TemplateModule::set_mint_permission(716            origin1.clone(),717            collection_id,718            true719        ));720        assert_ok!(TemplateModule::set_public_access_mode(721            origin1.clone(),722            collection_id,723            AccessMode::WhiteList724        ));725        assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), 1, 1));726727        assert_ok!(TemplateModule::add_collection_admin(origin1.clone(), 1, 2));728        729        let data = default_re_fungible_data();730        create_test_item(collection_id, &data.into());731732        // check balance (collection with id = 1, user id = 2)733        assert_eq!(TemplateModule::balance_count(1, 1), 1023);734735        // burn item736        assert_ok!(TemplateModule::burn_item(origin1.clone(), 1, 1, 1023));737        assert_noop!(738            TemplateModule::burn_item(origin1.clone(), 1, 1, 1023),739            Error::<Test>::TokenNotFound740        );741742        assert_eq!(TemplateModule::balance_count(1, 1), 0);743    });744}745746#[test]747fn add_collection_admin() {748    new_test_ext().execute_with(|| {749        default_limits();750        751        let collection1_id = create_test_collection_for_owner(&CollectionMode::NFT, 1, 1);752        create_test_collection_for_owner(&CollectionMode::NFT, 2, 2);753        create_test_collection_for_owner(&CollectionMode::NFT, 3, 3);754        755        let origin1 = Origin::signed(1);756757        // collection admin758        assert_ok!(TemplateModule::add_collection_admin(origin1.clone(), collection1_id, 2));759        assert_ok!(TemplateModule::add_collection_admin(origin1.clone(), collection1_id, 3));760761        assert_eq!(TemplateModule::admin_list_collection(collection1_id).contains(&2), true);762        assert_eq!(TemplateModule::admin_list_collection(collection1_id).contains(&3), true);763    });764}765766#[test]767fn remove_collection_admin() {768    new_test_ext().execute_with(|| {769        default_limits();770        771        let collection1_id = create_test_collection_for_owner(&CollectionMode::NFT, 1, 1);772        create_test_collection_for_owner(&CollectionMode::NFT, 2, 2);773        create_test_collection_for_owner(&CollectionMode::NFT, 3, 3);774775        let origin1 = Origin::signed(1);776        let origin2 = Origin::signed(2);777778        // collection admin779        assert_ok!(TemplateModule::add_collection_admin(origin1.clone(), collection1_id, 2));780        assert_ok!(TemplateModule::add_collection_admin(origin1.clone(), collection1_id, 3));781782        assert_eq!(TemplateModule::admin_list_collection(1).contains(&2), true);783        assert_eq!(TemplateModule::admin_list_collection(1).contains(&3), true);784785        // remove admin786        assert_ok!(TemplateModule::remove_collection_admin(787            origin2.clone(),788            1,789            3790        ));791        assert_eq!(TemplateModule::admin_list_collection(1).contains(&3), false);792    });793}794795#[test]796fn balance_of() {797    new_test_ext().execute_with(|| {798        default_limits();799        800        let nft_collection_id = create_test_collection(&CollectionMode::NFT, 1);801        let fungible_collection_id = create_test_collection(&CollectionMode::Fungible(3), 2);802        let re_fungible_collection_id = create_test_collection(&CollectionMode::ReFungible, 3);803        804        // check balance before805        assert_eq!(TemplateModule::balance_count(nft_collection_id, 1), 0);806        assert_eq!(TemplateModule::balance_count(fungible_collection_id, 1), 0);807        assert_eq!(TemplateModule::balance_count(re_fungible_collection_id, 1), 0);808809        let nft_data = default_nft_data();810        create_test_item(nft_collection_id, &nft_data.into());811        812        let fungible_data = default_fungible_data();813        create_test_item(fungible_collection_id, &fungible_data.into());814        815        let re_fungible_data = default_re_fungible_data();816        create_test_item(re_fungible_collection_id, &re_fungible_data.into());817818        // check balance (collection with id = 1, user id = 1)819        assert_eq!(TemplateModule::balance_count(nft_collection_id, 1), 1);820        assert_eq!(TemplateModule::balance_count(fungible_collection_id, 1), 5);821        assert_eq!(TemplateModule::balance_count(re_fungible_collection_id, 1), 1023);822        assert_eq!(TemplateModule::nft_item_id(nft_collection_id, 1).unwrap().owner, 1);823        assert_eq!(TemplateModule::fungible_item_id(fungible_collection_id, 1).value, 5);824        assert_eq!(TemplateModule::refungible_item_id(re_fungible_collection_id, 1).unwrap().owner[0].owner, 1);825    });826}827828#[test]829fn approve() {830    new_test_ext().execute_with(|| {831        default_limits();832        833        let collection_id = create_test_collection(&CollectionMode::NFT, 1);834        835        let data = default_nft_data();836        create_test_item(collection_id, &data.into());837838        let origin1 = Origin::signed(1);839        840        // approve841        assert_ok!(TemplateModule::approve(origin1.clone(), 2, 1, 1, 1));842        assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 1);843    });844}845846#[test]847fn transfer_from() {848    new_test_ext().execute_with(|| {849        default_limits();850        851        let collection_id = create_test_collection(&CollectionMode::NFT, 1);852        let origin1 = Origin::signed(1);853        let origin2 = Origin::signed(2);854855        let data = default_nft_data();856        create_test_item(collection_id, &data.into());857858        // approve859        assert_ok!(TemplateModule::approve(origin1.clone(), 2, 1, 1, 1));860        assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 1);861862        assert_ok!(TemplateModule::set_mint_permission(863            origin1.clone(),864            1,865            true866        ));867        assert_ok!(TemplateModule::set_public_access_mode(868            origin1.clone(),869            1,870            AccessMode::WhiteList871        ));872        assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), 1, 1));873        assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), 1, 2));874        assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), 1, 3));875876        assert_ok!(TemplateModule::transfer_from(877            origin2.clone(),878            1,879            2,880            1,881            1,882            1883        ));884885        // after transfer886        assert_eq!(TemplateModule::balance_count(1, 1), 0);887        assert_eq!(TemplateModule::balance_count(1, 2), 1);888    });889}890891// #endregion892893// Coverage tests region894// #region895896#[test]897fn owner_can_add_address_to_white_list() {898    new_test_ext().execute_with(|| {899        default_limits();900        901        let collection_id = create_test_collection(&CollectionMode::NFT, 1);902903        let origin1 = Origin::signed(1);904        assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), collection_id, 2));905        assert_eq!(TemplateModule::white_list(collection_id, 2), true);906    });907}908909#[test]910fn admin_can_add_address_to_white_list() {911    new_test_ext().execute_with(|| {912        default_limits();913        914        let collection_id = create_test_collection(&CollectionMode::NFT, 1);915        let origin1 = Origin::signed(1);916        let origin2 = Origin::signed(2);917918        assert_ok!(TemplateModule::add_collection_admin(origin1.clone(), collection_id, 2));919        assert_ok!(TemplateModule::add_to_white_list(origin2.clone(), collection_id, 3));920        assert_eq!(TemplateModule::white_list(collection_id, 3), true);921    });922}923924#[test]925fn nonprivileged_user_cannot_add_address_to_white_list() {926    new_test_ext().execute_with(|| {927        default_limits();928        929        let collection_id = create_test_collection(&CollectionMode::NFT, 1);930931        let origin2 = Origin::signed(2);932        assert_noop!(933            TemplateModule::add_to_white_list(origin2.clone(), collection_id, 3),934            Error::<Test>::NoPermission935        );936    });937}938939#[test]940fn nobody_can_add_address_to_white_list_of_nonexisting_collection() {941    new_test_ext().execute_with(|| {942        default_limits();943944        let origin1 = Origin::signed(1);945946        assert_noop!(947            TemplateModule::add_to_white_list(origin1.clone(), 1, 2),948            Error::<Test>::CollectionNotFound949        );950    });951}952953#[test]954fn nobody_can_add_address_to_white_list_of_deleted_collection() {955    new_test_ext().execute_with(|| {956        default_limits();957        958        let collection_id = create_test_collection(&CollectionMode::NFT, 1);959960        let origin1 = Origin::signed(1);961        assert_ok!(TemplateModule::destroy_collection(origin1.clone(), collection_id));962        assert_noop!(963            TemplateModule::add_to_white_list(origin1.clone(), collection_id, 2),964            Error::<Test>::CollectionNotFound965        );966    });967}968969// If address is already added to white list, nothing happens970#[test]971fn address_is_already_added_to_white_list() {972    new_test_ext().execute_with(|| {973        default_limits();974        975        let collection_id = create_test_collection(&CollectionMode::NFT, 1);976        let origin1 = Origin::signed(1);977        978        assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), collection_id, 2));979        assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), collection_id, 2));980        assert_eq!(TemplateModule::white_list(collection_id, 2), true);981    });982}983984#[test]985fn owner_can_remove_address_from_white_list() {986    new_test_ext().execute_with(|| {987        default_limits();988        989        let collection_id = create_test_collection(&CollectionMode::NFT, 1);990991        let origin1 = Origin::signed(1);992        assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), collection_id, 2));993        assert_ok!(TemplateModule::remove_from_white_list(994            origin1.clone(),995            collection_id,996            2997        ));998        assert_eq!(TemplateModule::white_list(collection_id, 2), false);999    });1000}10011002#[test]1003fn admin_can_remove_address_from_white_list() {1004    new_test_ext().execute_with(|| {1005        default_limits();1006        1007        let collection_id = create_test_collection(&CollectionMode::NFT, 1);1008        let origin1 = Origin::signed(1);1009        let origin2 = Origin::signed(2);10101011        assert_ok!(TemplateModule::add_collection_admin(origin1.clone(), collection_id, 2));10121013        assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), collection_id, 3));1014        assert_ok!(TemplateModule::remove_from_white_list(1015            origin2.clone(),1016            collection_id,1017            31018        ));1019        assert_eq!(TemplateModule::white_list(collection_id, 3), false);1020    });1021}10221023#[test]1024fn nonprivileged_user_cannot_remove_address_from_white_list() {1025    new_test_ext().execute_with(|| {1026        default_limits();1027        1028        let collection_id = create_test_collection(&CollectionMode::NFT, 1);1029        let origin1 = Origin::signed(1);1030        let origin2 = Origin::signed(2);10311032        assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), collection_id, 2));1033        assert_noop!(1034            TemplateModule::remove_from_white_list(origin2.clone(), collection_id, 2),1035            Error::<Test>::NoPermission1036        );1037        assert_eq!(TemplateModule::white_list(collection_id, 2), true);1038    });1039}10401041#[test]1042fn nobody_can_remove_address_from_white_list_of_nonexisting_collection() {1043    new_test_ext().execute_with(|| {1044        default_limits();1045        let origin1 = Origin::signed(1);10461047        assert_noop!(1048            TemplateModule::remove_from_white_list(origin1.clone(), 1, 2),1049            Error::<Test>::CollectionNotFound1050        );1051    });1052}10531054#[test]1055fn nobody_can_remove_address_from_white_list_of_deleted_collection() {1056    new_test_ext().execute_with(|| {1057        default_limits();1058        1059        let collection_id = create_test_collection(&CollectionMode::NFT, 1);1060        let origin1 = Origin::signed(1);1061        let origin2 = Origin::signed(2);10621063        assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), collection_id, 2));1064        assert_ok!(TemplateModule::destroy_collection(origin1.clone(), collection_id));1065        assert_noop!(1066            TemplateModule::remove_from_white_list(origin2.clone(), collection_id, 2),1067            Error::<Test>::CollectionNotFound1068        );1069        assert_eq!(TemplateModule::white_list(collection_id, 2), false);1070    });1071}10721073// If address is already removed from white list, nothing happens1074#[test]1075fn address_is_already_removed_from_white_list() {1076    new_test_ext().execute_with(|| {1077        default_limits();1078        1079        let collection_id = create_test_collection(&CollectionMode::NFT, 1);1080        let origin1 = Origin::signed(1);10811082        assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), collection_id, 2));1083        assert_ok!(TemplateModule::remove_from_white_list(1084            origin1.clone(),1085            collection_id,1086            21087        ));1088        assert_ok!(TemplateModule::remove_from_white_list(1089            origin1.clone(),1090            collection_id,1091            21092        ));1093        assert_eq!(TemplateModule::white_list(collection_id, 2), false);1094    });1095}10961097// If Public Access mode is set to WhiteList, tokens can’t be transferred from a non-whitelisted address with transfer or transferFrom (2 tests)1098#[test]1099fn white_list_test_1() {1100    new_test_ext().execute_with(|| {1101        default_limits();1102        1103        let collection_id = create_test_collection(&CollectionMode::NFT, 1);11041105        let origin1 = Origin::signed(1);1106        1107        let data = default_nft_data();1108        create_test_item(collection_id, &data.into());11091110        assert_ok!(TemplateModule::set_public_access_mode(1111            origin1.clone(),1112            collection_id,1113            AccessMode::WhiteList1114        ));1115        assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), collection_id, 2));11161117        assert_noop!(1118            TemplateModule::transfer(origin1.clone(), 3, 1, 1, 1),1119            Error::<Test>::AddresNotInWhiteList1120        );1121    });1122}11231124#[test]1125fn white_list_test_2() {1126    new_test_ext().execute_with(|| {1127        default_limits();1128        1129        let collection_id = create_test_collection(&CollectionMode::NFT, 1);1130        let origin1 = Origin::signed(1);1131        1132        let data = default_nft_data();1133        create_test_item(collection_id, &data.into());11341135        assert_ok!(TemplateModule::set_public_access_mode(1136            origin1.clone(),1137            collection_id,1138            AccessMode::WhiteList1139        ));1140        assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), 1, 1));1141        assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), 1, 2));11421143        // do approve1144        assert_ok!(TemplateModule::approve(origin1.clone(), 1, 1, 1, 1));1145        assert_eq!(TemplateModule::approved(1, (1, 1, 1)), 1);11461147        assert_ok!(TemplateModule::remove_from_white_list(1148            origin1.clone(),1149            1,1150            11151        ));11521153        assert_noop!(1154            TemplateModule::transfer_from(origin1.clone(), 1, 3, 1, 1, 1),1155            Error::<Test>::AddresNotInWhiteList1156        );1157    });1158}11591160// If Public Access mode is set to WhiteList, tokens can’t be transferred to a non-whitelisted address with transfer or transferFrom (2 tests)1161#[test]1162fn white_list_test_3() {1163    new_test_ext().execute_with(|| {1164        default_limits();1165        1166        let collection_id = create_test_collection(&CollectionMode::NFT, 1);11671168        let origin1 = Origin::signed(1);1169        1170        let data = default_nft_data();1171        create_test_item(collection_id, &data.into());11721173        assert_ok!(TemplateModule::set_public_access_mode(1174            origin1.clone(),1175            collection_id,1176            AccessMode::WhiteList1177        ));1178        assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), 1, 1));11791180        assert_noop!(1181            TemplateModule::transfer(origin1.clone(), 3, 1, 1, 1),1182            Error::<Test>::AddresNotInWhiteList1183        );1184    });1185}11861187#[test]1188fn white_list_test_4() {1189    new_test_ext().execute_with(|| {1190        default_limits();1191        1192        let collection_id = create_test_collection(&CollectionMode::NFT, 1);11931194        let origin1 = Origin::signed(1);11951196        let data = default_nft_data();1197        create_test_item(collection_id, &data.into());11981199        assert_ok!(TemplateModule::set_public_access_mode(1200            origin1.clone(),1201            collection_id,1202            AccessMode::WhiteList1203        ));1204        assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), collection_id, 1));1205        assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), collection_id, 2));12061207        // do approve1208        assert_ok!(TemplateModule::approve(origin1.clone(), 1, 1, 1, 1));1209        assert_eq!(TemplateModule::approved(1, (1, 1, 1)), 1);12101211        assert_ok!(TemplateModule::remove_from_white_list(1212            origin1.clone(),1213            collection_id,1214            21215        ));12161217        assert_noop!(1218            TemplateModule::transfer_from(origin1.clone(), 1, 3, 1, 1, 1),1219            Error::<Test>::AddresNotInWhiteList1220        );1221    });1222}12231224// If Public Access mode is set to WhiteList, tokens can’t be destroyed by a non-whitelisted address (even if it owned them before enabling WhiteList mode)1225#[test]1226fn white_list_test_5() {1227    new_test_ext().execute_with(|| {1228        default_limits();1229        1230        let collection_id = create_test_collection(&CollectionMode::NFT, 1);12311232        let origin1 = Origin::signed(1);12331234        let data = default_nft_data();1235        create_test_item(collection_id, &data.into());12361237        assert_ok!(TemplateModule::set_public_access_mode(1238            origin1.clone(),1239            collection_id,1240            AccessMode::WhiteList1241        ));1242        assert_noop!(1243            TemplateModule::burn_item(origin1.clone(), 1, 1, 5),1244            Error::<Test>::AddresNotInWhiteList1245        );1246    });1247}12481249// If Public Access mode is set to WhiteList, token transfers can’t be Approved by a non-whitelisted address (see Approve method).1250#[test]1251fn white_list_test_6() {1252    new_test_ext().execute_with(|| {1253        default_limits();1254        1255        let collection_id = create_test_collection(&CollectionMode::NFT, 1);12561257        let origin1 = Origin::signed(1);12581259        let data = default_nft_data();1260        create_test_item(collection_id, &data.into());12611262        assert_ok!(TemplateModule::set_public_access_mode(1263            origin1.clone(),1264            collection_id,1265            AccessMode::WhiteList1266        ));12671268        // do approve1269        assert_noop!(1270            TemplateModule::approve(origin1.clone(), 1, 1, 1, 5),1271            Error::<Test>::AddresNotInWhiteList1272        );1273    });1274}12751276// If Public Access mode is set to WhiteList, tokens can be transferred from a whitelisted address with transfer or transferFrom (2 tests) and1277//          tokens can be transferred from a whitelisted address with transfer or transferFrom (2 tests)1278#[test]1279fn white_list_test_7() {1280    new_test_ext().execute_with(|| {1281        default_limits();1282        1283        let collection_id = create_test_collection(&CollectionMode::NFT, 1);12841285        let data = default_nft_data();1286        create_test_item(collection_id, &data.into());1287        1288        let origin1 = Origin::signed(1);12891290        assert_ok!(TemplateModule::set_public_access_mode(1291            origin1.clone(),1292            collection_id,1293            AccessMode::WhiteList1294        ));1295        assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), collection_id, 1));1296        assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), collection_id, 2));12971298        assert_ok!(TemplateModule::transfer(origin1.clone(), 2, 1, 1, 1));1299    });1300}13011302#[test]1303fn white_list_test_8() {1304    new_test_ext().execute_with(|| {1305        default_limits();1306        1307        let collection_id = create_test_collection(&CollectionMode::NFT, 1);13081309        let data = default_nft_data();1310        create_test_item(collection_id, &data.into());1311        1312        let origin1 = Origin::signed(1);13131314        assert_ok!(TemplateModule::set_public_access_mode(1315            origin1.clone(),1316            collection_id,1317            AccessMode::WhiteList1318        ));1319        assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), collection_id, 1));1320        assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), collection_id, 2));13211322        // do approve1323        assert_ok!(TemplateModule::approve(origin1.clone(), 1, 1, 1, 5));1324        assert_eq!(TemplateModule::approved(1, (1, 1, 1)), 5);13251326        assert_ok!(TemplateModule::transfer_from(1327            origin1.clone(),1328            1,1329            2,1330            1,1331            1,1332            11333        ));1334    });1335}13361337// If Public Access mode is set to WhiteList, and Mint Permission is set to false, tokens can be created by owner.1338#[test]1339fn white_list_test_9() {1340    new_test_ext().execute_with(|| {1341        default_limits();1342        1343        let collection_id = create_test_collection(&CollectionMode::NFT, 1);1344        let origin1 = Origin::signed(1);13451346        assert_ok!(TemplateModule::set_public_access_mode(1347            origin1.clone(),1348            collection_id,1349            AccessMode::WhiteList1350        ));1351        assert_ok!(TemplateModule::set_mint_permission(1352            origin1.clone(),1353            collection_id,1354            false1355        ));13561357        let data = default_nft_data();1358        create_test_item(collection_id, &data.into());1359    });1360}13611362// If Public Access mode is set to WhiteList, and Mint Permission is set to false, tokens can be created by admin.1363#[test]1364fn white_list_test_10() {1365    new_test_ext().execute_with(|| {1366        default_limits();1367        1368        let collection_id = create_test_collection(&CollectionMode::NFT, 1);13691370        let origin1 = Origin::signed(1);1371        let origin2 = Origin::signed(2);13721373        assert_ok!(TemplateModule::set_public_access_mode(1374            origin1.clone(),1375            collection_id,1376            AccessMode::WhiteList1377        ));1378        assert_ok!(TemplateModule::set_mint_permission(1379            origin1.clone(),1380            collection_id,1381            false1382        ));13831384        assert_ok!(TemplateModule::add_collection_admin(origin1.clone(), collection_id, 2));13851386        assert_ok!(TemplateModule::create_item(1387            origin2.clone(),1388            collection_id,1389            2,1390            default_nft_data().into()1391        ));1392    });1393}13941395// If Public Access mode is set to WhiteList, and Mint Permission is set to false, tokens cannot be created by non-privileged and white listed address.1396#[test]1397fn white_list_test_11() {1398    new_test_ext().execute_with(|| {1399        default_limits();1400        1401        let collection_id = create_test_collection(&CollectionMode::NFT, 1);14021403        let origin1 = Origin::signed(1);1404        let origin2 = Origin::signed(2);14051406        assert_ok!(TemplateModule::set_public_access_mode(1407            origin1.clone(),1408            collection_id,1409            AccessMode::WhiteList1410        ));1411        assert_ok!(TemplateModule::set_mint_permission(1412            origin1.clone(),1413            collection_id,1414            false1415        ));1416        assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), collection_id, 2));14171418        assert_noop!(1419            TemplateModule::create_item(origin2.clone(), 1, 2, default_nft_data().into()),1420            Error::<Test>::PublicMintingNotAllowed1421        );1422    });1423}14241425// If Public Access mode is set to WhiteList, and Mint Permission is set to false, tokens cannot be created by non-privileged and non-white listed address.1426#[test]1427fn white_list_test_12() {1428    new_test_ext().execute_with(|| {1429        default_limits();1430        1431        let collection_id = create_test_collection(&CollectionMode::NFT, 1);14321433        let origin1 = Origin::signed(1);1434        let origin2 = Origin::signed(2);14351436        assert_ok!(TemplateModule::set_public_access_mode(1437            origin1.clone(),1438            collection_id,1439            AccessMode::WhiteList1440        ));1441        assert_ok!(TemplateModule::set_mint_permission(1442            origin1.clone(),1443            collection_id,1444            false1445        ));14461447        assert_noop!(1448            TemplateModule::create_item(origin2.clone(), 1, 2, default_nft_data().into()),1449            Error::<Test>::PublicMintingNotAllowed1450        );1451    });1452}14531454// If Public Access mode is set to WhiteList, and Mint Permission is set to true, tokens can be created by owner.1455#[test]1456fn white_list_test_13() {1457    new_test_ext().execute_with(|| {1458        default_limits();1459        1460        let collection_id = create_test_collection(&CollectionMode::NFT, 1);14611462        let origin1 = Origin::signed(1);14631464        assert_ok!(TemplateModule::set_public_access_mode(1465            origin1.clone(),1466            collection_id,1467            AccessMode::WhiteList1468        ));1469        assert_ok!(TemplateModule::set_mint_permission(1470            origin1.clone(),1471            collection_id,1472            true1473        ));14741475        let data = default_nft_data();1476        create_test_item(collection_id, &data.into());1477    });1478}14791480// If Public Access mode is set to WhiteList, and Mint Permission is set to true, tokens can be created by admin.1481#[test]1482fn white_list_test_14() {1483    new_test_ext().execute_with(|| {1484        default_limits();1485        1486        let collection_id = create_test_collection(&CollectionMode::NFT, 1);14871488        let origin1 = Origin::signed(1);1489        let origin2 = Origin::signed(2);14901491        assert_ok!(TemplateModule::set_public_access_mode(1492            origin1.clone(),1493            collection_id,1494            AccessMode::WhiteList1495        ));1496        assert_ok!(TemplateModule::set_mint_permission(1497            origin1.clone(),1498            collection_id,1499            true1500        ));15011502        assert_ok!(TemplateModule::add_collection_admin(origin1.clone(), collection_id, 2));15031504        assert_ok!(TemplateModule::create_item(1505            origin2.clone(),1506            1,1507            2,1508            default_nft_data().into()1509        ));1510    });1511}15121513// If Public Access mode is set to WhiteList, and Mint Permission is set to true, tokens cannot be created by non-privileged and non-white listed address.1514#[test]1515fn white_list_test_15() {1516    new_test_ext().execute_with(|| {1517        default_limits();1518        1519        let collection_id = create_test_collection(&CollectionMode::NFT, 1);15201521        let origin1 = Origin::signed(1);1522        let origin2 = Origin::signed(2);15231524        assert_ok!(TemplateModule::set_public_access_mode(1525            origin1.clone(),1526            collection_id,1527            AccessMode::WhiteList1528        ));1529        assert_ok!(TemplateModule::set_mint_permission(1530            origin1.clone(),1531            collection_id,1532            true1533        ));15341535        assert_noop!(1536            TemplateModule::create_item(origin2.clone(), 1, 2, default_nft_data().into()),1537            Error::<Test>::AddresNotInWhiteList1538        );1539    });1540}15411542// If Public Access mode is set to WhiteList, and Mint Permission is set to true, tokens can be created by non-privileged and white listed address.1543#[test]1544fn white_list_test_16() {1545    new_test_ext().execute_with(|| {1546        default_limits();1547        1548        let collection_id = create_test_collection(&CollectionMode::NFT, 1);15491550        let origin1 = Origin::signed(1);1551        let origin2 = Origin::signed(2);15521553        assert_ok!(TemplateModule::set_public_access_mode(1554            origin1.clone(),1555            collection_id,1556            AccessMode::WhiteList1557        ));1558        assert_ok!(TemplateModule::set_mint_permission(1559            origin1.clone(),1560            collection_id,1561            true1562        ));1563        assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), collection_id, 2));15641565        assert_ok!(TemplateModule::create_item(1566            origin2.clone(),1567            1,1568            2,1569            default_nft_data().into()1570        ));1571    });1572}15731574// Total number of collections. Positive test1575#[test]1576fn total_number_collections_bound() {1577    new_test_ext().execute_with(|| {1578        default_limits();1579        1580        create_test_collection(&CollectionMode::NFT, 1);1581    });1582}15831584// Total number of collections. Negotive test1585#[test]1586fn total_number_collections_bound_neg() {1587    new_test_ext().execute_with(|| {1588        default_limits();15891590        let origin1 = Origin::signed(1);15911592        for i in 0..default_collection_numbers_limit() {1593            create_test_collection(&CollectionMode::NFT, i + 1);1594        }15951596        let col_name1: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();1597        let col_desc1: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();1598        let token_prefix1: Vec<u8> = b"token_prefix1\0".to_vec();15991600        // 11-th collection in chain. Expects error1601        assert_noop!(TemplateModule::create_collection(1602            origin1.clone(),1603            col_name1.clone(),1604            col_desc1.clone(),1605            token_prefix1.clone(),1606            CollectionMode::NFT1607        ), Error::<Test>::TotalCollectionsLimitExceeded);1608    });1609}16101611// Owned tokens by a single address. Positive test1612#[test]1613fn owned_tokens_bound() {1614    new_test_ext().execute_with(|| {1615        default_limits();1616        1617        let collection_id = create_test_collection(&CollectionMode::NFT, 1);16181619        let data = default_nft_data();1620        create_test_item(collection_id, &data.clone().into());1621        create_test_item(collection_id, &data.into());1622    });1623}16241625// Owned tokens by a single address. Negotive test1626#[test]1627fn owned_tokens_bound_neg() {1628    new_test_ext().execute_with(|| {1629        assert_ok!(TemplateModule::set_chain_limits(RawOrigin::Root.into(), ChainLimits { 1630            collection_numbers_limit: 10,1631            account_token_ownership_limit: 1,1632            collections_admins_limit: 5,1633            custom_data_limit: 2048,1634            nft_sponsor_transfer_timeout: 15,1635            fungible_sponsor_transfer_timeout: 15,1636            refungible_sponsor_transfer_timeout: 15,1637            const_on_chain_schema_limit: 1024,1638            offchain_schema_limit: 1024,1639            variable_on_chain_schema_limit: 1024,1640        }));1641        1642        let collection_id = create_test_collection(&CollectionMode::NFT, 1);16431644        let origin1 = Origin::signed(1);1645        let data = default_nft_data();1646        create_test_item(collection_id, &data.clone().into());16471648        assert_noop!(TemplateModule::create_item(1649            origin1.clone(),1650            1,1651            1,1652            data.into()1653        ),  Error::<Test>::AddressOwnershipLimitExceeded);1654    });1655}16561657// Number of collection admins. Positive test1658#[test]1659fn collection_admins_bound() {1660    new_test_ext().execute_with(|| {1661        assert_ok!(TemplateModule::set_chain_limits(RawOrigin::Root.into(), ChainLimits { 1662            collection_numbers_limit: 10,1663            account_token_ownership_limit: 10,1664            collections_admins_limit: 2,1665            custom_data_limit: 2048,1666            nft_sponsor_transfer_timeout: 15,1667            fungible_sponsor_transfer_timeout: 15,1668            refungible_sponsor_transfer_timeout: 15,1669            const_on_chain_schema_limit: 1024,1670            offchain_schema_limit: 1024,1671            variable_on_chain_schema_limit: 1024,1672        }));1673        1674        let collection_id = create_test_collection(&CollectionMode::NFT, 1);16751676        let origin1 = Origin::signed(1);1677        1678        assert_ok!(TemplateModule::add_collection_admin(origin1.clone(), collection_id, 2));1679        assert_ok!(TemplateModule::add_collection_admin(origin1.clone(), collection_id, 3));1680    });1681}16821683// Number of collection admins. Negotive test1684#[test]1685fn collection_admins_bound_neg() {1686    new_test_ext().execute_with(|| {1687        assert_ok!(TemplateModule::set_chain_limits(RawOrigin::Root.into(), ChainLimits { 1688            collection_numbers_limit: 10,1689            account_token_ownership_limit: 1,1690            collections_admins_limit: 1,1691            custom_data_limit: 2048,1692            nft_sponsor_transfer_timeout: 15,1693            fungible_sponsor_transfer_timeout: 15,1694            refungible_sponsor_transfer_timeout: 15,1695            const_on_chain_schema_limit: 1024,1696            offchain_schema_limit: 1024,1697            variable_on_chain_schema_limit: 1024,1698        }));1699        1700        let collection_id = create_test_collection(&CollectionMode::NFT, 1);17011702        let origin1 = Origin::signed(1);17031704        assert_ok!(TemplateModule::add_collection_admin(origin1.clone(), collection_id, 2));1705        assert_noop!(TemplateModule::add_collection_admin(origin1.clone(), collection_id, 3), Error::<Test>::CollectionAdminsLimitExceeded);1706    });1707}17081709// NFT custom data size. Negative test const_data.1710#[test]1711fn custom_data_size_nft_const_data_bound_neg() {1712    new_test_ext().execute_with(|| {1713        assert_ok!(TemplateModule::set_chain_limits(RawOrigin::Root.into(), ChainLimits { 1714            collection_numbers_limit: 10,1715            account_token_ownership_limit: 10,1716            collections_admins_limit: 5,1717            custom_data_limit: 2,1718            nft_sponsor_transfer_timeout: 15,1719            fungible_sponsor_transfer_timeout: 15,1720            refungible_sponsor_transfer_timeout: 15,1721            const_on_chain_schema_limit: 1024,1722            offchain_schema_limit: 1024,1723            variable_on_chain_schema_limit: 1024,1724        }));1725        1726        let collection_id = create_test_collection(&CollectionMode::NFT, 1);17271728        let origin1 = Origin::signed(1);1729        let too_big_const_data = CreateItemData::NFT(CreateNftData{1730            const_data: vec![1, 2, 3, 4],1731            variable_data: vec![]1732        });17331734        assert_noop!(TemplateModule::create_item(1735            origin1.clone(),1736            collection_id,1737            1,1738            too_big_const_data1739        ), Error::<Test>::TokenConstDataLimitExceeded);1740    });1741}17421743// NFT custom data size. Negative test variable_data.1744#[test]1745fn custom_data_size_nft_variable_data_bound_neg() {1746    new_test_ext().execute_with(|| {1747        assert_ok!(TemplateModule::set_chain_limits(RawOrigin::Root.into(), ChainLimits { 1748            collection_numbers_limit: 10,1749            account_token_ownership_limit: 10,1750            collections_admins_limit: 5,1751            custom_data_limit: 2,1752            nft_sponsor_transfer_timeout: 15,1753            fungible_sponsor_transfer_timeout: 15,1754            refungible_sponsor_transfer_timeout: 15,1755            const_on_chain_schema_limit: 1024,1756            offchain_schema_limit: 1024,1757            variable_on_chain_schema_limit: 1024,1758        }));17591760        let collection_id = create_test_collection(&CollectionMode::NFT, 1);17611762        let origin1 = Origin::signed(1);1763        let too_big_const_data = CreateItemData::NFT(CreateNftData{1764            const_data: vec![],1765            variable_data: vec![1, 2, 3, 4]1766        });17671768        assert_noop!(TemplateModule::create_item(1769            origin1.clone(),1770            collection_id,1771            1,1772            too_big_const_data1773        ), Error::<Test>::TokenVariableDataLimitExceeded);1774    });1775}17761777// Re fungible custom data size. Negative test const_data.1778#[test]1779fn custom_data_size_re_fungible_const_data_bound_neg() {1780    new_test_ext().execute_with(|| {1781        assert_ok!(TemplateModule::set_chain_limits(RawOrigin::Root.into(), ChainLimits { 1782            collection_numbers_limit: 10,1783            account_token_ownership_limit: 10,1784            collections_admins_limit: 5,1785            custom_data_limit: 2,1786            nft_sponsor_transfer_timeout: 15,1787            fungible_sponsor_transfer_timeout: 15,1788            refungible_sponsor_transfer_timeout: 15,1789            const_on_chain_schema_limit: 1024,1790            offchain_schema_limit: 1024,1791            variable_on_chain_schema_limit: 1024,1792        }));17931794        let collection_id = create_test_collection(&CollectionMode::NFT, 1);17951796        let origin1 = Origin::signed(1);1797        let too_big_const_data = CreateItemData::NFT(CreateNftData{1798            const_data: vec![1, 2, 3, 4],1799            variable_data: vec![]1800        });18011802        assert_noop!(TemplateModule::create_item(1803            origin1.clone(),1804            collection_id,1805            1,1806            too_big_const_data1807        ), Error::<Test>::TokenConstDataLimitExceeded);1808    });1809}18101811// Re fungible custom data size. Negative test variable_data.1812#[test]1813fn custom_data_size_re_fungible_variable_data_bound_neg() {1814    new_test_ext().execute_with(|| {1815        assert_ok!(TemplateModule::set_chain_limits(RawOrigin::Root.into(), ChainLimits { 1816            collection_numbers_limit: 10,1817            account_token_ownership_limit: 10,1818            collections_admins_limit: 5,1819            custom_data_limit: 2,1820            nft_sponsor_transfer_timeout: 15,1821            fungible_sponsor_transfer_timeout: 15,1822            refungible_sponsor_transfer_timeout: 15,1823            const_on_chain_schema_limit: 1024,1824            offchain_schema_limit: 1024,1825            variable_on_chain_schema_limit: 1024,1826        }));18271828        let collection_id = create_test_collection(&CollectionMode::NFT, 1);18291830        let origin1 = Origin::signed(1);1831        let too_big_const_data = CreateItemData::NFT(CreateNftData{1832            const_data: vec![],1833            variable_data: vec![1, 2, 3, 4]1834        });18351836        assert_noop!(TemplateModule::create_item(1837            origin1.clone(),1838            collection_id,1839            1,1840            too_big_const_data1841        ), Error::<Test>::TokenVariableDataLimitExceeded);1842    });1843}1844// #endregion18451846#[test]1847fn set_const_on_chain_schema() {1848    new_test_ext().execute_with(|| {1849        default_limits();18501851        let collection_id = create_test_collection(&CollectionMode::NFT, 1);18521853        let origin1 = Origin::signed(1);1854        assert_ok!(TemplateModule::set_const_on_chain_schema(origin1, collection_id, b"test const on chain schema".to_vec()));18551856        assert_eq!(TemplateModule::collection_id(collection_id).unwrap().const_on_chain_schema, b"test const on chain schema".to_vec());1857        assert_eq!(TemplateModule::collection_id(collection_id).unwrap().variable_on_chain_schema, b"".to_vec());1858    });1859}18601861#[test]1862fn set_variable_on_chain_schema() {1863    new_test_ext().execute_with(|| {1864        default_limits();1865        1866        let collection_id = create_test_collection(&CollectionMode::NFT, 1);18671868        let origin1 = Origin::signed(1);1869        assert_ok!(TemplateModule::set_variable_on_chain_schema(origin1, collection_id, b"test variable on chain schema".to_vec()));18701871        assert_eq!(TemplateModule::collection_id(collection_id).unwrap().const_on_chain_schema, b"".to_vec());1872        assert_eq!(TemplateModule::collection_id(collection_id).unwrap().variable_on_chain_schema, b"test variable on chain schema".to_vec());1873    });1874}18751876#[test]1877fn set_variable_meta_data_on_nft_token_stores_variable_meta_data() {1878    new_test_ext().execute_with(|| {1879        default_limits();18801881        let collection_id = create_test_collection(&CollectionMode::NFT, 1);18821883        let origin1 = Origin::signed(1);1884        1885        let data = default_nft_data();1886        create_test_item(1, &data.into());1887        1888        let variable_data = b"test set_variable_meta_data method.".to_vec();1889        assert_ok!(TemplateModule::set_variable_meta_data(origin1, collection_id, 1, variable_data.clone()));18901891        assert_eq!(TemplateModule::nft_item_id(collection_id, 1).unwrap().variable_data, variable_data);1892    });1893}18941895#[test]1896fn set_variable_meta_data_on_re_fungible_token_stores_variable_meta_data() {1897    new_test_ext().execute_with(|| {1898        default_limits();18991900        let collection_id = create_test_collection(&CollectionMode::ReFungible, 1);19011902        let origin1 = Origin::signed(1);19031904        let data = default_re_fungible_data();1905        create_test_item(1, &data.into());19061907        let variable_data = b"test set_variable_meta_data method.".to_vec();1908        assert_ok!(TemplateModule::set_variable_meta_data(origin1, collection_id, 1, variable_data.clone()));19091910        assert_eq!(TemplateModule::refungible_item_id(collection_id, 1).unwrap().variable_data, variable_data);1911    });1912}191319141915#[test]1916fn set_variable_meta_data_on_fungible_token_fails() {1917    new_test_ext().execute_with(|| {1918        default_limits();19191920        let collection_id = create_test_collection(&CollectionMode::Fungible(3), 1);19211922        let origin1 = Origin::signed(1);19231924        let data = default_fungible_data();1925        create_test_item(1, &data.into());19261927        let variable_data = b"test set_variable_meta_data method.".to_vec();1928        assert_noop!(TemplateModule::set_variable_meta_data(origin1, collection_id, 1, variable_data.clone()), Error::<Test>::CantStoreMetadataInFungibleTokens);1929    });1930}19311932#[test]1933fn set_variable_meta_data_on_nft_token_fails_for_big_data() {1934    new_test_ext().execute_with(|| {1935        assert_ok!(TemplateModule::set_chain_limits(RawOrigin::Root.into(), ChainLimits { 1936            collection_numbers_limit: default_collection_numbers_limit(),1937            account_token_ownership_limit: 10,1938            collections_admins_limit: 5,1939            custom_data_limit: 10,1940            nft_sponsor_transfer_timeout: 15,1941            fungible_sponsor_transfer_timeout: 15,1942            refungible_sponsor_transfer_timeout: 15,1943            const_on_chain_schema_limit: 1024,1944            offchain_schema_limit: 1024,1945            variable_on_chain_schema_limit: 1024,1946        }));19471948        let collection_id = create_test_collection(&CollectionMode::NFT, 1);19491950        let origin1 = Origin::signed(1);19511952        let data = default_nft_data();1953        create_test_item(1, &data.into());19541955        let variable_data = b"test set_variable_meta_data method, bigger than limits.".to_vec();1956        assert_noop!(TemplateModule::set_variable_meta_data(origin1, collection_id, 1, variable_data), Error::<Test>::TokenVariableDataLimitExceeded);1957    });1958}19591960#[test]1961fn set_variable_meta_data_on_re_fungible_token_fails_for_big_data() {1962    new_test_ext().execute_with(|| {1963        assert_ok!(TemplateModule::set_chain_limits(RawOrigin::Root.into(), ChainLimits { 1964            collection_numbers_limit: default_collection_numbers_limit(),1965            account_token_ownership_limit: 10,1966            collections_admins_limit: 5,1967            custom_data_limit: 10,1968            nft_sponsor_transfer_timeout: 15,1969            fungible_sponsor_transfer_timeout: 15,1970            refungible_sponsor_transfer_timeout: 15,1971            const_on_chain_schema_limit: 1024,1972            offchain_schema_limit: 1024,1973            variable_on_chain_schema_limit: 1024,1974        }));197519761977        let collection_id = create_test_collection(&CollectionMode::ReFungible, 1);19781979        let origin1 = Origin::signed(1);19801981        let data = default_re_fungible_data();1982        create_test_item(1, &data.into());19831984        let variable_data = b"test set_variable_meta_data method, bigger than limits.".to_vec();1985        assert_noop!(TemplateModule::set_variable_meta_data(origin1, collection_id, 1, variable_data), Error::<Test>::TokenVariableDataLimitExceeded);1986    });1987}