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

difftreelog

fix merge test changes

Yaroslav Bolyukin2021-06-25parent: #928aa03.patch.diff
in: master

7 files changed

modifiedpallets/inflation/src/tests.rsdiffbeforeafterboth
--- a/pallets/inflation/src/tests.rs
+++ b/pallets/inflation/src/tests.rs
@@ -34,9 +34,9 @@
 			NodeBlock = Block,
 			UncheckedExtrinsic = UncheckedExtrinsic,
 		{
-			Balances: pallet_balances::{Module, Call, Storage},
-			System: frame_system::{Module, Call, Config, Storage, Event<T>},
-			Inflation: pallet_inflation::{Module, Call, Storage},
+			Balances: pallet_balances::{Pallet, Call, Storage},
+			System: frame_system::{Pallet, Call, Config, Storage, Event<T>},
+			Inflation: pallet_inflation::{Pallet, Call, Storage},
 		}
 	);
 
@@ -70,6 +70,7 @@
 		type OnKilledAccount = ();
 		type SystemWeightInfo = ();
 		type SS58Prefix = SS58Prefix;
+        type OnSetCode = ();
 	}
 
 	parameter_types! {
modifiedpallets/nft/src/eth/sponsoring.rsdiffbeforeafterboth
--- a/pallets/nft/src/eth/sponsoring.rs
+++ b/pallets/nft/src/eth/sponsoring.rs
@@ -32,7 +32,7 @@
             match call {
                 UniqueNFTCall::ERC721UniqueExtensions(ERC721UniqueExtensionsCall::Transfer {token_id, ..}) | UniqueNFTCall::ERC721(ERC721Call::TransferFrom {token_id, ..})  => {
                     let token_id: u32 = token_id.try_into().map_err(|_| AnyError)?;
-                    let block_number = <frame_system::Module<T>>::block_number() as T::BlockNumber;
+                    let block_number = <frame_system::Pallet<T>>::block_number() as T::BlockNumber;
                     let collection_limits = &collection.limits;
                     let limit: u32 = if collection_limits.sponsor_transfer_timeout > 0 {
                         collection_limits.sponsor_transfer_timeout
@@ -68,7 +68,7 @@
                         ChainLimit::get().fungible_sponsor_transfer_timeout
                     };
 
-                    let block_number = <frame_system::Module<T>>::block_number() as T::BlockNumber;
+                    let block_number = <frame_system::Pallet<T>>::block_number() as T::BlockNumber;
                     let mut sponsored = true;
                     if <FungibleTransferBasket<T>>::contains_key(collection_id, who.as_sub()) {
                         let last_tx_block = <FungibleTransferBasket<T>>::get(collection_id, who.as_sub());
modifiedpallets/nft/src/lib.rsdiffbeforeafterboth
--- a/pallets/nft/src/lib.rs
+++ b/pallets/nft/src/lib.rs
@@ -236,7 +236,6 @@
 
     type EvmAddressMapping: pallet_evm::AddressMapping<Self::AccountId>;
     type EvmBackwardsAddressMapping: EvmBackwardsAddressMapping<Self::AccountId>;
-    type EvmWithdrawOrigin: pallet_evm::EnsureAddressOrigin<Self::Origin, Success = Self::AccountId>;
 
 	type CrossAccountId: CrossAccountId<Self::AccountId>;
     type Currency: Currency<Self::AccountId>;
modifiedpallets/nft/src/mock.rsdiffbeforeafterboth
--- a/pallets/nft/src/mock.rs
+++ b/pallets/nft/src/mock.rs
@@ -11,6 +11,9 @@
 };
 use pallet_transaction_payment::{ CurrencyAdapter};
 use frame_system as system;
+use pallet_evm::AddressMapping;
+use crate::{EvmBackwardsAddressMapping, CrossAccountId};
+use codec::{Encode, Decode};
 
 type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
 type Block = frame_system::mocking::MockBlock<Test>; 
@@ -22,9 +25,9 @@
 		NodeBlock = Block,
 		UncheckedExtrinsic = UncheckedExtrinsic,
 	{
-		System: frame_system::{Module, Call, Config, Storage, Event<T>},
-		TemplateModule: pallet_template::{Module, Call, Storage},
-		Balances: pallet_balances::{Module, Call, Storage},
+		System: frame_system::{Pallet, Call, Config, Storage, Event<T>},
+		TemplateModule: pallet_template::{Pallet, Call, Storage},
+		Balances: pallet_balances::{Pallet, Call, Storage},
 	}
 );
 
@@ -56,6 +59,7 @@
 	type OnKilledAccount = ();
 	type SystemWeightInfo = ();
 	type SS58Prefix = SS58Prefix;
+    type OnSetCode = ();
 }
 
 parameter_types! {
@@ -78,7 +82,7 @@
 }
 
 impl pallet_transaction_payment::Config for Test {
-	type OnChargeTransaction = CurrencyAdapter<pallet_balances::Module<Test>, ()>;
+	type OnChargeTransaction = CurrencyAdapter<pallet_balances::Pallet<Test>, ()>;
 	type TransactionByteFee = TransactionByteFee;
 	type WeightToFee = IdentityFee<u64>;
 	type FeeMultiplierUpdate = ();
@@ -94,27 +98,26 @@
 	type WeightInfo = ();
 }
 
-type Timestamp = pallet_timestamp::Module<Test>;
-type Randomness = pallet_randomness_collective_flip::Module<Test>;
+type Timestamp = pallet_timestamp::Pallet<Test>;
+type Randomness = pallet_randomness_collective_flip::Pallet<Test>;
 
 parameter_types! {
 	pub const TombstoneDeposit: u64 = 1;
 	pub const DepositPerContract: u64 = 1;
 	pub const DepositPerStorageByte: u64 = 1;
 	pub const DepositPerStorageItem: u64 = 1;
-	pub RentFraction: Perbill = Perbill::from_rational_approximation(1u32, 30 * 24 * 60 * 10);
+	pub RentFraction: Perbill = Perbill::from_rational(1u32, 30 * 24 * 60 * 10);
 	pub const SurchargeReward: u64 = 1;
 	pub const SignedClaimHandicap: u32 = 2;
-	pub const MaxDepth: u32 = 32;
-	pub const MaxValueSize: u32 = 16 * 1024;
 	pub DeletionWeightLimit: u64 = u64::MAX;//Perbill::from_percent(10);
 	pub DeletionQueueDepth: u32 = 10;
+	pub Schedule: pallet_contracts::Schedule<Test> = Default::default();
 }
 
 impl pallet_contracts::Config for Test {
 	type Time = Timestamp;
 	type Randomness = Randomness;
-	type Currency = pallet_balances::Module<Test>;
+	type Currency = pallet_balances::Pallet<Test>;
 	type Event = ();
 	type RentPayment = ();
 	type SignedClaimHandicap = SignedClaimHandicap;
@@ -125,26 +128,71 @@
 	type RentFraction = RentFraction;
 	type SurchargeReward = SurchargeReward;
 	type DeletionWeightLimit = DeletionWeightLimit;
-	type MaxDepth = MaxDepth;
 	type DeletionQueueDepth = DeletionQueueDepth;
-	type MaxValueSize = MaxValueSize;
 	type ChainExtension = ();
-	type MaxCodeSize = ();
 	type WeightPrice = ();
 	type WeightInfo = pallet_contracts::weights::SubstrateWeight<Self>;
+    type Schedule = Schedule;
+    type CallStack = [pallet_contracts::Frame<Self>; 31];
 }
 
 parameter_types! {
 	pub const CollectionCreationPrice: u32 = 0;
     pub TreasuryAccountId: u64 = 1234;
+    pub EthereumChainId: u32 = 1111;
+}
+
+pub struct TestEvmAddressMapping;
+impl AddressMapping<u64> for TestEvmAddressMapping {
+    fn into_account_id(addr: sp_core::H160) -> u64 {
+        unimplemented!()
+    }
+}
+
+pub struct TestEvmBackwardsAddressMapping;
+impl EvmBackwardsAddressMapping<u64> for TestEvmBackwardsAddressMapping {
+    fn from_account_id(account_id: u64) -> sp_core::H160 {
+        unimplemented!()
+    }
+}
+
+#[derive(Encode, Decode, Clone, PartialEq, Eq, PartialOrd, Ord, Debug)]
+pub struct TestCrossAccountId(u64, sp_core::H160);
+impl CrossAccountId<u64> for TestCrossAccountId {
+    fn from_sub(sub: u64) -> Self {
+        let mut eth = [0; 20];
+        eth[12..20].copy_from_slice(&sub.to_be_bytes());
+        Self(sub, sp_core::H160(eth))
+    }
+    fn as_sub(&self) -> &u64 {
+        &self.0
+    }
+    fn from_eth(eth: sp_core::H160) -> Self {
+        unimplemented!()
+    }
+    fn as_eth(&self) -> &sp_core::H160 {
+        &self.1
+    }
 }
 
+pub struct TestEtheremTransactionSender;
+impl pallet_ethereum::EthereumTransactionSender for TestEtheremTransactionSender {
+    fn submit_logs_transaction(tx: pallet_ethereum::Transaction, logs: Vec<pallet_ethereum::Log>) -> Result<(), sp_runtime::DispatchError> {
+        Ok(())
+    }
+}
+
 impl pallet_template::Config for Test {
 	type Event = ();
 	type WeightInfo = ();
 	type CollectionCreationPrice = CollectionCreationPrice;
-    type Currency = pallet_balances::Module<Test>;
+    type Currency = pallet_balances::Pallet<Test>;
     type TreasuryAccountId = TreasuryAccountId;
+    type EvmAddressMapping = TestEvmAddressMapping;
+    type EvmBackwardsAddressMapping = TestEvmBackwardsAddressMapping;
+    type CrossAccountId = TestCrossAccountId;
+    type EthereumChainId = EthereumChainId;
+    type EthereumTransactionSender = TestEtheremTransactionSender;
 }
 
 // Build genesis storage according to the mock runtime.
modifiedpallets/nft/src/tests.rsdiffbeforeafterboth
before · pallets/nft/src/tests.rs
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}
after · pallets/nft/src/tests.rs
1// Tests to be written here2use super::*;3use crate::mock::*;4use crate::{5    AccessMode, CollectionMode,6    Ownership, ChainLimits, CreateItemData,7};8use nft_data_structs::{9    CreateNftData, CreateFungibleData, CreateReFungibleData,10    CollectionId, TokenId, MAX_DECIMAL_POINTS,11};12use frame_support::{assert_noop, assert_ok};13use frame_system::{ RawOrigin };1415fn default_collection_numbers_limit() -> u32 {16    1017}1819fn default_limits() {20    assert_ok!(TemplateModule::set_chain_limits(RawOrigin::Root.into(), ChainLimits {21            collection_numbers_limit: default_collection_numbers_limit(),22            account_token_ownership_limit: 10,23            collections_admins_limit: 5,24            custom_data_limit: 2048,25            nft_sponsor_transfer_timeout: 15,26            fungible_sponsor_transfer_timeout: 15,27            refungible_sponsor_transfer_timeout: 15,28            const_on_chain_schema_limit: 1024,29            offchain_schema_limit: 1024,30            variable_on_chain_schema_limit: 1024,31        }));32}3334fn default_nft_data() -> CreateNftData {35    CreateNftData { const_data: vec![1, 2, 3], variable_data: vec![3, 2, 1] }36}3738fn default_fungible_data () -> CreateFungibleData {39    CreateFungibleData { value: 5 }40}4142fn default_re_fungible_data () -> CreateReFungibleData {43    CreateReFungibleData { const_data: vec![1, 2, 3], variable_data: vec![3, 2, 1], pieces: 1023 }44}4546fn create_test_collection_for_owner(mode: &CollectionMode, owner: u64, id: CollectionId) -> CollectionId {47    let col_name1: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();48    let col_desc1: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();49    let token_prefix1: Vec<u8> = b"token_prefix1\0".to_vec();5051    let origin1 = Origin::signed(owner);52    assert_ok!(TemplateModule::create_collection(53            origin1.clone(),54            col_name1.clone(),55            col_desc1.clone(),56            token_prefix1.clone(),57            mode.clone()58        ));5960    let saved_col_name: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();61    let saved_description: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();62    let saved_prefix: Vec<u8> = b"token_prefix1\0".to_vec();63    assert_eq!(TemplateModule::collection_id(id).unwrap().owner, owner);64    assert_eq!(TemplateModule::collection_id(id).unwrap().name, saved_col_name);65    assert_eq!(TemplateModule::collection_id(id).unwrap().mode, *mode);66    assert_eq!(TemplateModule::collection_id(id).unwrap().description, saved_description);67    assert_eq!(TemplateModule::collection_id(id).unwrap().token_prefix, saved_prefix);68    id69}7071fn create_test_collection(mode: &CollectionMode, id: CollectionId) -> CollectionId {72    create_test_collection_for_owner(&mode, 1, id)73}7475fn create_test_item(collection_id: CollectionId, data: &CreateItemData) {76    let origin1 = Origin::signed(1);77    assert_ok!(TemplateModule::create_item(78            origin1.clone(),79            collection_id,80            account(1),81            data.clone()82        ));8384}8586fn account(sub: u64) -> TestCrossAccountId {87    TestCrossAccountId::from_sub(sub)88}8990// Use cases tests region91// #region9293#[test]94fn set_version_schema() {95    new_test_ext().execute_with(|| {96        default_limits();97        let origin1 = Origin::signed(1);98        let collection_id = create_test_collection(&CollectionMode::NFT, 1);99        100        assert_ok!(TemplateModule::set_schema_version(origin1, collection_id, SchemaVersion::Unique));101        assert_eq!(TemplateModule::collection_id(collection_id).unwrap().schema_version, SchemaVersion::Unique);102    });103}104105#[test]106fn create_fungible_collection_fails_with_large_decimal_numbers() {107    new_test_ext().execute_with(|| {108        default_limits();109110        let col_name1: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();111        let col_desc1: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();112        let token_prefix1: Vec<u8> = b"token_prefix1\0".to_vec();113114        let origin1 = Origin::signed(1);115        assert_noop!(TemplateModule::create_collection(116            origin1,117            col_name1,118            col_desc1,119            token_prefix1,120            CollectionMode::Fungible(MAX_DECIMAL_POINTS + 1)121        ), Error::<Test>::CollectionDecimalPointLimitExceeded);122    });    123}124125#[test]126fn create_nft_item() {127    new_test_ext().execute_with(|| {128        default_limits();129        let collection_id = create_test_collection(&CollectionMode::NFT, 1);130        131        let data = default_nft_data();132        create_test_item(collection_id, &data.clone().into());133        let item = TemplateModule::nft_item_id(collection_id, 1).unwrap();134        assert_eq!(item.const_data, data.const_data);135        assert_eq!(item.variable_data, data.variable_data);136    });137}138139// Use cases tests region140// #region141#[test]142fn create_nft_multiple_items() {143    new_test_ext().execute_with(|| {144        default_limits();145        146        create_test_collection(&CollectionMode::NFT, 1);147148        let origin1 = Origin::signed(1);149150        let items_data = vec![default_nft_data(), default_nft_data(), default_nft_data()];151152        assert_ok!(TemplateModule::create_multiple_items(153            origin1.clone(),154            1,155            account(1),156            items_data.clone().into_iter().map(|d| { d.into() }).collect()157        ));158        for (index, data) in items_data.iter().enumerate() {159            let item = TemplateModule::nft_item_id(1, (index + 1) as TokenId).unwrap(); 160            assert_eq!(item.const_data.to_vec(), data.const_data);161            assert_eq!(item.variable_data.to_vec(), data.variable_data);162        }163    });164}165166#[test]167fn create_refungible_item() {168    new_test_ext().execute_with(|| {169        default_limits();170        let collection_id = create_test_collection(&CollectionMode::ReFungible, 1);171172        let data = default_re_fungible_data();173        create_test_item(collection_id, &data.clone().into());174        let item = TemplateModule::refungible_item_id(collection_id, 1).unwrap();175        assert_eq!(176            item.const_data,177            data.const_data178        );179        assert_eq!(180            item.variable_data,181            data.variable_data182        );183        assert_eq!(184            item.owner[0],185            Ownership {186                owner: account(1),187                fraction: 1023188            }189        );190    });191}192193#[test]194fn create_multiple_refungible_items() {195    new_test_ext().execute_with(|| {196        default_limits();197        198        create_test_collection(&CollectionMode::ReFungible, 1);199200        let origin1 = Origin::signed(1);201202        let items_data = vec![default_re_fungible_data(), default_re_fungible_data(), default_re_fungible_data()];203204        assert_ok!(TemplateModule::create_multiple_items(205            origin1.clone(),206            1,207            account(1),208            items_data.clone().into_iter().map(|d| { d.into() }).collect()209        ));210        for (index, data) in items_data.iter().enumerate() {211212            let item = TemplateModule::refungible_item_id(1, (index + 1) as TokenId).unwrap();213            assert_eq!(item.const_data.to_vec(), data.const_data);214            assert_eq!(item.variable_data.to_vec(), data.variable_data);215            assert_eq!(216                item.owner[0],217                Ownership {218                    owner: account(1),219                    fraction: 1023220                }221            );222        }223    });224}225226#[test]227fn create_fungible_item() {228    new_test_ext().execute_with(|| {229        default_limits();230        231        let collection_id = create_test_collection(&CollectionMode::Fungible(3), 1);232233        let data = default_fungible_data();234        create_test_item(collection_id, &data.into());235236        assert_eq!(TemplateModule::fungible_item_id(collection_id, 1).value, 5);237    });238}239240//#[test]241// fn create_multiple_fungible_items() {242//     new_test_ext().execute_with(|| {243//         default_limits();244245//         create_test_collection(&CollectionMode::Fungible(3), 1);246247//         let origin1 = Origin::signed(1);248249//         let items_data = vec![default_fungible_data(), default_fungible_data(), default_fungible_data()];250251//         assert_ok!(TemplateModule::create_multiple_items(252//             origin1.clone(),253//             1,254//             1,255//             items_data.clone().into_iter().map(|d| { d.into() }).collect()256//         ));257        258//         for (index, _) in items_data.iter().enumerate() {259//             assert_eq!(TemplateModule::fungible_item_id(1, (index + 1) as TokenId).value, 5);260//         }261//         assert_eq!(TemplateModule::balance_count(1, 1), 3000);262//         assert_eq!(TemplateModule::address_tokens(1, 1), [1, 2, 3]);263//     });264// }265266#[test]267fn transfer_fungible_item() {268    new_test_ext().execute_with(|| {269        default_limits();270        271        let collection_id = create_test_collection(&CollectionMode::Fungible(3), 1);272273        let origin1 = Origin::signed(1);274        let origin2 = Origin::signed(2);275276        let data = default_fungible_data();277        create_test_item(collection_id, &data.into());278279        assert_eq!(TemplateModule::fungible_item_id(1, 1).value, 5);280        assert_eq!(TemplateModule::balance_count(1, 1), 5);281282        // change owner scenario283        assert_ok!(TemplateModule::transfer(origin1.clone(), account(2), 1, 1, 5));284        assert_eq!(TemplateModule::fungible_item_id(1, 1).value, 0);285        assert_eq!(TemplateModule::balance_count(1, 1), 0);286        assert_eq!(TemplateModule::balance_count(1, 2), 5);287288        // split item scenario289        assert_ok!(TemplateModule::transfer(origin2.clone(), account(3), 1, 1, 3));290        assert_eq!(TemplateModule::balance_count(1, 2), 2);291        assert_eq!(TemplateModule::balance_count(1, 3), 3);292293        // split item and new owner has account scenario294        assert_ok!(TemplateModule::transfer(origin2.clone(), account(3), 1, 1, 1));295        assert_eq!(TemplateModule::fungible_item_id(1, 2).value, 1);296        assert_eq!(TemplateModule::fungible_item_id(1, 3).value, 4);297        assert_eq!(TemplateModule::balance_count(1, 2), 1);298        assert_eq!(TemplateModule::balance_count(1, 3), 4);299    });300}301302#[test]303fn transfer_refungible_item() {304    new_test_ext().execute_with(|| {305        default_limits();306        307        let collection_id = create_test_collection(&CollectionMode::ReFungible, 1);308309        let data = default_re_fungible_data();310        create_test_item(collection_id, &data.clone().into());311312        let origin1 = Origin::signed(1);313        let origin2 = Origin::signed(2);314        {315            let item = TemplateModule::refungible_item_id(collection_id, 1).unwrap();316            assert_eq!(317                item.const_data,318                data.const_data319            );320            assert_eq!(321                item.variable_data,322                data.variable_data323            );324            assert_eq!(325                item.owner[0],326                Ownership {327                    owner: account(1),328                    fraction: 1023329                }330            );331        }332        assert_eq!(TemplateModule::balance_count(1, 1), 1023);333        assert_eq!(TemplateModule::address_tokens(1, 1), [1]);334335        // change owner scenario336        assert_ok!(TemplateModule::transfer(origin1.clone(), account(2), 1, 1, 1023));337        assert_eq!(338            TemplateModule::refungible_item_id(1, 1).unwrap().owner[0],339            Ownership {340                owner: account(2),341                fraction: 1023342            }343        );344        assert_eq!(TemplateModule::balance_count(1, 1), 0);345        assert_eq!(TemplateModule::balance_count(1, 2), 1023);346        // assert_eq!(TemplateModule::address_tokens(1, 1), []);347        assert_eq!(TemplateModule::address_tokens(1, 2), [1]);348349        // split item scenario350        assert_ok!(TemplateModule::transfer(origin2.clone(), account(3), 1, 1, 500));351        {352            let item = TemplateModule::refungible_item_id(1, 1).unwrap();353            assert_eq!(354                item.owner[0],355                Ownership {356                    owner: account(2),357                    fraction: 523358                }359            );360            assert_eq!(361                item.owner[1],362                Ownership {363                    owner: account(3),364                    fraction: 500365                }366            );367        }368        assert_eq!(TemplateModule::balance_count(1, 2), 523);369        assert_eq!(TemplateModule::balance_count(1, 3), 500);370        assert_eq!(TemplateModule::address_tokens(1, 2), [1]);371        assert_eq!(TemplateModule::address_tokens(1, 3), [1]);372373        // split item and new owner has account scenario374        assert_ok!(TemplateModule::transfer(origin2.clone(), account(3), 1, 1, 200));375        {376            let item = TemplateModule::refungible_item_id(1, 1).unwrap();377            assert_eq!(378                item.owner[0],379                Ownership {380                    owner: account(2),381                    fraction: 323382                }383            );384            assert_eq!(385                item.owner[1],386                Ownership {387                    owner: account(3),388                    fraction: 700389                }390            );391        }392        assert_eq!(TemplateModule::balance_count(1, 2), 323);393        assert_eq!(TemplateModule::balance_count(1, 3), 700);394        assert_eq!(TemplateModule::address_tokens(1, 2), [1]);395        assert_eq!(TemplateModule::address_tokens(1, 3), [1]);396    });397}398399#[test]400fn transfer_nft_item() {401    new_test_ext().execute_with(|| {402        default_limits();403        404        let collection_id = create_test_collection(&CollectionMode::NFT, 1);405406        let data = default_nft_data();407        create_test_item(collection_id, &data.into());408        assert_eq!(TemplateModule::balance_count(1, 1), 1);409        assert_eq!(TemplateModule::address_tokens(1, 1), [1]);410411        let origin1 = Origin::signed(1);412        // default scenario413        assert_ok!(TemplateModule::transfer(origin1.clone(), account(2), 1, 1, 1000));414        assert_eq!(TemplateModule::nft_item_id(1, 1).unwrap().owner, account(2));415        assert_eq!(TemplateModule::balance_count(1, 1), 0);416        assert_eq!(TemplateModule::balance_count(1, 2), 1);417        // assert_eq!(TemplateModule::address_tokens(1, 1), []);418        assert_eq!(TemplateModule::address_tokens(1, 2), [1]);419    });420}421422#[test]423fn nft_approve_and_transfer_from() {424    new_test_ext().execute_with(|| {425        default_limits();426        427        let collection_id = create_test_collection(&CollectionMode::NFT, 1);428429        let data = default_nft_data();430        create_test_item(collection_id, &data.into());431432        let origin1 = Origin::signed(1);433        let origin2 = Origin::signed(2);434435        assert_eq!(TemplateModule::balance_count(1, 1), 1);436        assert_eq!(TemplateModule::address_tokens(1, 1), [1]);437438        // neg transfer439        assert_noop!(TemplateModule::transfer_from(440            origin2.clone(),441            account(1),442            account(2),443            1,444            1,445            1), Error::<Test>::NoPermission);446447        // do approve448        assert_ok!(TemplateModule::approve(origin1.clone(), account(2), 1, 1, 5));449        assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 5);450        assert_eq!(451            TemplateModule::approved(1, (1, 1, 2)),452            5453        );454455        assert_ok!(TemplateModule::transfer_from(456            origin2.clone(),457            account(1),458            account(3),459            1,460            1,461            1462        ));463        assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 4);464    });465}466467#[test]468fn nft_approve_and_transfer_from_white_list() {469    new_test_ext().execute_with(|| {470        default_limits();471        472        let collection_id = create_test_collection(&CollectionMode::NFT, 1);473474        let origin1 = Origin::signed(1);475        let origin2 = Origin::signed(2);476477        let data = default_nft_data();478        create_test_item(collection_id, &data.clone().into());479480        assert_eq!(TemplateModule::nft_item_id(1, 1).unwrap().const_data, data.const_data);481        assert_eq!(TemplateModule::balance_count(1, 1), 1);482        assert_eq!(TemplateModule::address_tokens(1, 1), [1]);483484        assert_ok!(TemplateModule::set_mint_permission(485            origin1.clone(),486            1,487            true488        ));489        assert_ok!(TemplateModule::set_public_access_mode(490            origin1.clone(),491            1,492            AccessMode::WhiteList493        ));494        assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), 1, account(1)));495        assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), 1, account(2)));496        assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), 1, account(3)));497498        // do approve499        assert_ok!(TemplateModule::approve(origin1.clone(), account(2), 1, 1, 5));500        assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 5);501        assert_ok!(TemplateModule::approve(origin1.clone(), account(3), 1, 1, 5));502        assert_eq!(TemplateModule::approved(1, (1, 1, 3)), 5);503504        assert_ok!(TemplateModule::transfer_from(505            origin2.clone(),506            account(1),507            account(3),508            1,509            1,510            1511        ));512        assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 4);513    });514}515516#[test]517fn refungible_approve_and_transfer_from() {518    new_test_ext().execute_with(|| {519        default_limits();520        521        let collection_id = create_test_collection(&CollectionMode::ReFungible, 1);522        523        let origin1 = Origin::signed(1);524        let origin2 = Origin::signed(2);525526        let data = default_re_fungible_data();527        create_test_item(collection_id, &data.into());528529        assert_eq!(TemplateModule::balance_count(1, 1), 1023);530        assert_eq!(TemplateModule::address_tokens(1, 1), [1]);531532        assert_ok!(TemplateModule::set_mint_permission(533            origin1.clone(),534            1,535            true536        ));537        assert_ok!(TemplateModule::set_public_access_mode(538            origin1.clone(),539            1,540            AccessMode::WhiteList541        ));542        assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), 1, account(1)));543        assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), 1, account(2)));544        assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), 1, account(3)));545546        // do approve547        assert_ok!(TemplateModule::approve(origin1.clone(), account(2), 1, 1, 1023));548        assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 1023);549550        assert_ok!(TemplateModule::transfer_from(551            origin2.clone(),552            account(1),553            account(3),554            1,555            1,556            100557        ));558        assert_eq!(TemplateModule::balance_count(1, 1), 923);559        assert_eq!(TemplateModule::balance_count(1, 3), 100);560        assert_eq!(TemplateModule::address_tokens(1, 1), [1]);561        assert_eq!(TemplateModule::address_tokens(1, 3), [1]);562563        assert_eq!(564            TemplateModule::approved(1, (1, 1, 2)),565            923566        );567    });568}569570#[test]571fn fungible_approve_and_transfer_from() {572    new_test_ext().execute_with(|| {573        default_limits();574        575        let collection_id = create_test_collection(&CollectionMode::Fungible(3), 1);576        577        let data = default_fungible_data();578        create_test_item(collection_id, &data.into());579580        let origin1 = Origin::signed(1);581        let origin2 = Origin::signed(2);582583        assert_eq!(TemplateModule::balance_count(1, 1), 5);584585        assert_ok!(TemplateModule::set_mint_permission(586            origin1.clone(),587            1,588            true589        ));590        assert_ok!(TemplateModule::set_public_access_mode(591            origin1.clone(),592            1,593            AccessMode::WhiteList594        ));595        assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), 1, account(1)));596        assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), 1, account(2)));597        assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), 1, account(3)));598599        // do approve600        assert_ok!(TemplateModule::approve(origin1.clone(), account(2), 1, 1, 5));601        assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 5);602        assert_ok!(TemplateModule::approve(origin1.clone(), account(3), 1, 1, 5));603        assert_eq!(TemplateModule::approved(1, (1, 1, 3)), 5);604        assert_eq!(605            TemplateModule::approved(1, (1, 1, 2)),606            5607        );608609        assert_ok!(TemplateModule::transfer_from(610            origin2.clone(),611            account(1),612            account(3),613            1,614            1,615            4616        ));617        assert_eq!(TemplateModule::balance_count(1, 1), 1);618        assert_eq!(TemplateModule::balance_count(1, 3), 4);619620        assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 1);621622        assert_noop!(TemplateModule::transfer_from(623            origin2.clone(),624            account(1),625            account(3),626            1,627            1,628            4629        ), Error::<Test>::NoPermission);630    });631}632633#[test]634fn change_collection_owner() {635    new_test_ext().execute_with(|| {636        default_limits();637        638        let collection_id = create_test_collection(&CollectionMode::NFT, 1);639        640        let origin1 = Origin::signed(1);641        assert_ok!(TemplateModule::change_collection_owner(642            origin1.clone(),643            collection_id,644            2645        ));646        assert_eq!(TemplateModule::collection_id(collection_id).unwrap().owner, 2);647    });648}649650#[test]651fn destroy_collection() {652    new_test_ext().execute_with(|| {653        default_limits();654        655        let collection_id = create_test_collection(&CollectionMode::NFT, 1);656        657        let origin1 = Origin::signed(1);658        assert_ok!(TemplateModule::destroy_collection(origin1.clone(), collection_id));659    });660}661662#[test]663fn burn_nft_item() {664    new_test_ext().execute_with(|| {665        default_limits();666        667        let collection_id = create_test_collection(&CollectionMode::NFT, 1);668669        let origin1 = Origin::signed(1);670        assert_ok!(TemplateModule::add_collection_admin(origin1.clone(), collection_id, account(2)));671        672        let data = default_nft_data();673        create_test_item(collection_id, &data.into());674675        // check balance (collection with id = 1, user id = 1)676        assert_eq!(TemplateModule::balance_count(1, 1), 1);677678        // burn item679        assert_ok!(TemplateModule::burn_item(origin1.clone(), 1, 1, 5));680        assert_noop!(681            TemplateModule::burn_item(origin1.clone(), 1, 1, 5),682            Error::<Test>::TokenNotFound683        );684685        assert_eq!(TemplateModule::balance_count(1, 1), 0);686    });687}688689#[test]690fn burn_fungible_item() {691    new_test_ext().execute_with(|| {692        default_limits();693        694        let collection_id = create_test_collection(&CollectionMode::Fungible(3), 1);695        696        let origin1 = Origin::signed(1);697        assert_ok!(TemplateModule::add_collection_admin(origin1.clone(), collection_id, account(2)));698        699        let data = default_fungible_data();700        create_test_item(collection_id, &data.into());701702        // check balance (collection with id = 1, user id = 1)703        assert_eq!(TemplateModule::balance_count(1, 1), 5);704705        // burn item706        assert_ok!(TemplateModule::burn_item(origin1.clone(), 1, 1, 5));707        assert_noop!(708            TemplateModule::burn_item(origin1.clone(), 1, 1, 5),709            Error::<Test>::TokenValueNotEnough710        );711712        assert_eq!(TemplateModule::balance_count(1, 1), 0);713    });714}715716#[test]717fn burn_refungible_item() {718    new_test_ext().execute_with(|| {719        default_limits();720        721        let collection_id = create_test_collection(&CollectionMode::ReFungible, 1);722        let origin1 = Origin::signed(1);723724        assert_ok!(TemplateModule::set_mint_permission(725            origin1.clone(),726            collection_id,727            true728        ));729        assert_ok!(TemplateModule::set_public_access_mode(730            origin1.clone(),731            collection_id,732            AccessMode::WhiteList733        ));734        assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), 1, account(1)));735736        assert_ok!(TemplateModule::add_collection_admin(origin1.clone(), 1, account(2)));737        738        let data = default_re_fungible_data();739        create_test_item(collection_id, &data.into());740741        // check balance (collection with id = 1, user id = 2)742        assert_eq!(TemplateModule::balance_count(1, 1), 1023);743744        // burn item745        assert_ok!(TemplateModule::burn_item(origin1.clone(), 1, 1, 1023));746        assert_noop!(747            TemplateModule::burn_item(origin1.clone(), 1, 1, 1023),748            Error::<Test>::TokenNotFound749        );750751        assert_eq!(TemplateModule::balance_count(1, 1), 0);752    });753}754755#[test]756fn add_collection_admin() {757    new_test_ext().execute_with(|| {758        default_limits();759        760        let collection1_id = create_test_collection_for_owner(&CollectionMode::NFT, 1, 1);761        create_test_collection_for_owner(&CollectionMode::NFT, 2, 2);762        create_test_collection_for_owner(&CollectionMode::NFT, 3, 3);763        764        let origin1 = Origin::signed(1);765766        // collection admin767        assert_ok!(TemplateModule::add_collection_admin(origin1.clone(), collection1_id, account(2)));768        assert_ok!(TemplateModule::add_collection_admin(origin1.clone(), collection1_id, account(3)));769770        assert_eq!(TemplateModule::admin_list_collection(collection1_id).contains(&account(2)), true);771        assert_eq!(TemplateModule::admin_list_collection(collection1_id).contains(&account(3)), true);772    });773}774775#[test]776fn remove_collection_admin() {777    new_test_ext().execute_with(|| {778        default_limits();779        780        let collection1_id = create_test_collection_for_owner(&CollectionMode::NFT, 1, 1);781        create_test_collection_for_owner(&CollectionMode::NFT, 2, 2);782        create_test_collection_for_owner(&CollectionMode::NFT, 3, 3);783784        let origin1 = Origin::signed(1);785        let origin2 = Origin::signed(2);786787        // collection admin788        assert_ok!(TemplateModule::add_collection_admin(origin1.clone(), collection1_id, account(2)));789        assert_ok!(TemplateModule::add_collection_admin(origin1.clone(), collection1_id, account(3)));790791        assert_eq!(TemplateModule::admin_list_collection(1).contains(&account(2)), true);792        assert_eq!(TemplateModule::admin_list_collection(1).contains(&account(3)), true);793794        // remove admin795        assert_ok!(TemplateModule::remove_collection_admin(796            origin2.clone(),797            1,798            account(3)799        ));800        assert_eq!(TemplateModule::admin_list_collection(1).contains(&account(3)), false);801    });802}803804#[test]805fn balance_of() {806    new_test_ext().execute_with(|| {807        default_limits();808        809        let nft_collection_id = create_test_collection(&CollectionMode::NFT, 1);810        let fungible_collection_id = create_test_collection(&CollectionMode::Fungible(3), 2);811        let re_fungible_collection_id = create_test_collection(&CollectionMode::ReFungible, 3);812        813        // check balance before814        assert_eq!(TemplateModule::balance_count(nft_collection_id, 1), 0);815        assert_eq!(TemplateModule::balance_count(fungible_collection_id, 1), 0);816        assert_eq!(TemplateModule::balance_count(re_fungible_collection_id, 1), 0);817818        let nft_data = default_nft_data();819        create_test_item(nft_collection_id, &nft_data.into());820        821        let fungible_data = default_fungible_data();822        create_test_item(fungible_collection_id, &fungible_data.into());823        824        let re_fungible_data = default_re_fungible_data();825        create_test_item(re_fungible_collection_id, &re_fungible_data.into());826827        // check balance (collection with id = 1, user id = 1)828        assert_eq!(TemplateModule::balance_count(nft_collection_id, 1), 1);829        assert_eq!(TemplateModule::balance_count(fungible_collection_id, 1), 5);830        assert_eq!(TemplateModule::balance_count(re_fungible_collection_id, 1), 1023);831        assert_eq!(TemplateModule::nft_item_id(nft_collection_id, 1).unwrap().owner, account(1));832        assert_eq!(TemplateModule::fungible_item_id(fungible_collection_id, 1).value, 5);833        assert_eq!(TemplateModule::refungible_item_id(re_fungible_collection_id, 1).unwrap().owner[0].owner, account(1));834    });835}836837#[test]838fn approve() {839    new_test_ext().execute_with(|| {840        default_limits();841        842        let collection_id = create_test_collection(&CollectionMode::NFT, 1);843        844        let data = default_nft_data();845        create_test_item(collection_id, &data.into());846847        let origin1 = Origin::signed(1);848        849        // approve850        assert_ok!(TemplateModule::approve(origin1.clone(), account(2), 1, 1, 1));851        assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 1);852    });853}854855#[test]856fn transfer_from() {857    new_test_ext().execute_with(|| {858        default_limits();859        860        let collection_id = create_test_collection(&CollectionMode::NFT, 1);861        let origin1 = Origin::signed(1);862        let origin2 = Origin::signed(2);863864        let data = default_nft_data();865        create_test_item(collection_id, &data.into());866867        // approve868        assert_ok!(TemplateModule::approve(origin1.clone(), account(2), 1, 1, 1));869        assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 1);870871        assert_ok!(TemplateModule::set_mint_permission(872            origin1.clone(),873            1,874            true875        ));876        assert_ok!(TemplateModule::set_public_access_mode(877            origin1.clone(),878            1,879            AccessMode::WhiteList880        ));881        assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), 1, account(1)));882        assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), 1, account(2)));883        assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), 1, account(3)));884885        assert_ok!(TemplateModule::transfer_from(886            origin2.clone(),887            account(1),888            account(2),889            1,890            1,891            1892        ));893894        // after transfer895        assert_eq!(TemplateModule::balance_count(1, 1), 0);896        assert_eq!(TemplateModule::balance_count(1, 2), 1);897    });898}899900// #endregion901902// Coverage tests region903// #region904905#[test]906fn owner_can_add_address_to_white_list() {907    new_test_ext().execute_with(|| {908        default_limits();909        910        let collection_id = create_test_collection(&CollectionMode::NFT, 1);911912        let origin1 = Origin::signed(1);913        assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), collection_id, account(2)));914        assert_eq!(TemplateModule::white_list(collection_id, 2), true);915    });916}917918#[test]919fn admin_can_add_address_to_white_list() {920    new_test_ext().execute_with(|| {921        default_limits();922        923        let collection_id = create_test_collection(&CollectionMode::NFT, 1);924        let origin1 = Origin::signed(1);925        let origin2 = Origin::signed(2);926927        assert_ok!(TemplateModule::add_collection_admin(origin1.clone(), collection_id, account(2)));928        assert_ok!(TemplateModule::add_to_white_list(origin2.clone(), collection_id, account(3)));929        assert_eq!(TemplateModule::white_list(collection_id, 3), true);930    });931}932933#[test]934fn nonprivileged_user_cannot_add_address_to_white_list() {935    new_test_ext().execute_with(|| {936        default_limits();937        938        let collection_id = create_test_collection(&CollectionMode::NFT, 1);939940        let origin2 = Origin::signed(2);941        assert_noop!(942            TemplateModule::add_to_white_list(origin2.clone(), collection_id, account(3)),943            Error::<Test>::NoPermission944        );945    });946}947948#[test]949fn nobody_can_add_address_to_white_list_of_nonexisting_collection() {950    new_test_ext().execute_with(|| {951        default_limits();952953        let origin1 = Origin::signed(1);954955        assert_noop!(956            TemplateModule::add_to_white_list(origin1.clone(), 1, account(2)),957            Error::<Test>::CollectionNotFound958        );959    });960}961962#[test]963fn nobody_can_add_address_to_white_list_of_deleted_collection() {964    new_test_ext().execute_with(|| {965        default_limits();966        967        let collection_id = create_test_collection(&CollectionMode::NFT, 1);968969        let origin1 = Origin::signed(1);970        assert_ok!(TemplateModule::destroy_collection(origin1.clone(), collection_id));971        assert_noop!(972            TemplateModule::add_to_white_list(origin1.clone(), collection_id, account(2)),973            Error::<Test>::CollectionNotFound974        );975    });976}977978// If address is already added to white list, nothing happens979#[test]980fn address_is_already_added_to_white_list() {981    new_test_ext().execute_with(|| {982        default_limits();983        984        let collection_id = create_test_collection(&CollectionMode::NFT, 1);985        let origin1 = Origin::signed(1);986        987        assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), collection_id, account(2)));988        assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), collection_id, account(2)));989        assert_eq!(TemplateModule::white_list(collection_id, 2), true);990    });991}992993#[test]994fn owner_can_remove_address_from_white_list() {995    new_test_ext().execute_with(|| {996        default_limits();997        998        let collection_id = create_test_collection(&CollectionMode::NFT, 1);9991000        let origin1 = Origin::signed(1);1001        assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), collection_id, account(2)));1002        assert_ok!(TemplateModule::remove_from_white_list(1003            origin1.clone(),1004            collection_id,1005            account(2)1006        ));1007        assert_eq!(TemplateModule::white_list(collection_id, 2), false);1008    });1009}10101011#[test]1012fn admin_can_remove_address_from_white_list() {1013    new_test_ext().execute_with(|| {1014        default_limits();1015        1016        let collection_id = create_test_collection(&CollectionMode::NFT, 1);1017        let origin1 = Origin::signed(1);1018        let origin2 = Origin::signed(2);10191020        assert_ok!(TemplateModule::add_collection_admin(origin1.clone(), collection_id, account(2)));10211022        assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), collection_id, account(3)));1023        assert_ok!(TemplateModule::remove_from_white_list(1024            origin2.clone(),1025            collection_id,1026            account(3)1027        ));1028        assert_eq!(TemplateModule::white_list(collection_id, 3), false);1029    });1030}10311032#[test]1033fn nonprivileged_user_cannot_remove_address_from_white_list() {1034    new_test_ext().execute_with(|| {1035        default_limits();1036        1037        let collection_id = create_test_collection(&CollectionMode::NFT, 1);1038        let origin1 = Origin::signed(1);1039        let origin2 = Origin::signed(2);10401041        assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), collection_id, account(2)));1042        assert_noop!(1043            TemplateModule::remove_from_white_list(origin2.clone(), collection_id, account(2)),1044            Error::<Test>::NoPermission1045        );1046        assert_eq!(TemplateModule::white_list(collection_id, 2), true);1047    });1048}10491050#[test]1051fn nobody_can_remove_address_from_white_list_of_nonexisting_collection() {1052    new_test_ext().execute_with(|| {1053        default_limits();1054        let origin1 = Origin::signed(1);10551056        assert_noop!(1057            TemplateModule::remove_from_white_list(origin1.clone(), 1, account(2)),1058            Error::<Test>::CollectionNotFound1059        );1060    });1061}10621063#[test]1064fn nobody_can_remove_address_from_white_list_of_deleted_collection() {1065    new_test_ext().execute_with(|| {1066        default_limits();1067        1068        let collection_id = create_test_collection(&CollectionMode::NFT, 1);1069        let origin1 = Origin::signed(1);1070        let origin2 = Origin::signed(2);10711072        assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), collection_id, account(2)));1073        assert_ok!(TemplateModule::destroy_collection(origin1.clone(), collection_id));1074        assert_noop!(1075            TemplateModule::remove_from_white_list(origin2.clone(), collection_id, account(2)),1076            Error::<Test>::CollectionNotFound1077        );1078        assert_eq!(TemplateModule::white_list(collection_id, 2), false);1079    });1080}10811082// If address is already removed from white list, nothing happens1083#[test]1084fn address_is_already_removed_from_white_list() {1085    new_test_ext().execute_with(|| {1086        default_limits();1087        1088        let collection_id = create_test_collection(&CollectionMode::NFT, 1);1089        let origin1 = Origin::signed(1);10901091        assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), collection_id, account(2)));1092        assert_ok!(TemplateModule::remove_from_white_list(1093            origin1.clone(),1094            collection_id,1095            account(2)1096        ));1097        assert_ok!(TemplateModule::remove_from_white_list(1098            origin1.clone(),1099            collection_id,1100            account(2)1101        ));1102        assert_eq!(TemplateModule::white_list(collection_id, 2), false);1103    });1104}11051106// If Public Access mode is set to WhiteList, tokens can’t be transferred from a non-whitelisted address with transfer or transferFrom (2 tests)1107#[test]1108fn white_list_test_1() {1109    new_test_ext().execute_with(|| {1110        default_limits();1111        1112        let collection_id = create_test_collection(&CollectionMode::NFT, 1);11131114        let origin1 = Origin::signed(1);1115        1116        let data = default_nft_data();1117        create_test_item(collection_id, &data.into());11181119        assert_ok!(TemplateModule::set_public_access_mode(1120            origin1.clone(),1121            collection_id,1122            AccessMode::WhiteList1123        ));1124        assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), collection_id, account(2)));11251126        assert_noop!(1127            TemplateModule::transfer(origin1.clone(), account(3), 1, 1, 1),1128            Error::<Test>::AddresNotInWhiteList1129        );1130    });1131}11321133#[test]1134fn white_list_test_2() {1135    new_test_ext().execute_with(|| {1136        default_limits();1137        1138        let collection_id = create_test_collection(&CollectionMode::NFT, 1);1139        let origin1 = Origin::signed(1);1140        1141        let data = default_nft_data();1142        create_test_item(collection_id, &data.into());11431144        assert_ok!(TemplateModule::set_public_access_mode(1145            origin1.clone(),1146            collection_id,1147            AccessMode::WhiteList1148        ));1149        assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), 1, account(1)));1150        assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), 1, account(2)));11511152        // do approve1153        assert_ok!(TemplateModule::approve(origin1.clone(), account(1), 1, 1, 1));1154        assert_eq!(TemplateModule::approved(1, (1, 1, 1)), 1);11551156        assert_ok!(TemplateModule::remove_from_white_list(1157            origin1.clone(),1158            1,1159            account(1)1160        ));11611162        assert_noop!(1163            TemplateModule::transfer_from(origin1.clone(), account(1), account(3), 1, 1, 1),1164            Error::<Test>::AddresNotInWhiteList1165        );1166    });1167}11681169// If Public Access mode is set to WhiteList, tokens can’t be transferred to a non-whitelisted address with transfer or transferFrom (2 tests)1170#[test]1171fn white_list_test_3() {1172    new_test_ext().execute_with(|| {1173        default_limits();1174        1175        let collection_id = create_test_collection(&CollectionMode::NFT, 1);11761177        let origin1 = Origin::signed(1);1178        1179        let data = default_nft_data();1180        create_test_item(collection_id, &data.into());11811182        assert_ok!(TemplateModule::set_public_access_mode(1183            origin1.clone(),1184            collection_id,1185            AccessMode::WhiteList1186        ));1187        assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), 1, account(1)));11881189        assert_noop!(1190            TemplateModule::transfer(origin1.clone(), account(3), 1, 1, 1),1191            Error::<Test>::AddresNotInWhiteList1192        );1193    });1194}11951196#[test]1197fn white_list_test_4() {1198    new_test_ext().execute_with(|| {1199        default_limits();1200        1201        let collection_id = create_test_collection(&CollectionMode::NFT, 1);12021203        let origin1 = Origin::signed(1);12041205        let data = default_nft_data();1206        create_test_item(collection_id, &data.into());12071208        assert_ok!(TemplateModule::set_public_access_mode(1209            origin1.clone(),1210            collection_id,1211            AccessMode::WhiteList1212        ));1213        assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), collection_id, account(1)));1214        assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), collection_id, account(2)));12151216        // do approve1217        assert_ok!(TemplateModule::approve(origin1.clone(), account(1), 1, 1, 1));1218        assert_eq!(TemplateModule::approved(1, (1, 1, 1)), 1);12191220        assert_ok!(TemplateModule::remove_from_white_list(1221            origin1.clone(),1222            collection_id,1223            account(2)1224        ));12251226        assert_noop!(1227            TemplateModule::transfer_from(origin1.clone(), account(1), account(3), 1, 1, 1),1228            Error::<Test>::AddresNotInWhiteList1229        );1230    });1231}12321233// 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)1234#[test]1235fn white_list_test_5() {1236    new_test_ext().execute_with(|| {1237        default_limits();1238        1239        let collection_id = create_test_collection(&CollectionMode::NFT, 1);12401241        let origin1 = Origin::signed(1);12421243        let data = default_nft_data();1244        create_test_item(collection_id, &data.into());12451246        assert_ok!(TemplateModule::set_public_access_mode(1247            origin1.clone(),1248            collection_id,1249            AccessMode::WhiteList1250        ));1251        assert_noop!(1252            TemplateModule::burn_item(origin1.clone(), 1, 1, 5),1253            Error::<Test>::AddresNotInWhiteList1254        );1255    });1256}12571258// If Public Access mode is set to WhiteList, token transfers can’t be Approved by a non-whitelisted address (see Approve method).1259#[test]1260fn white_list_test_6() {1261    new_test_ext().execute_with(|| {1262        default_limits();1263        1264        let collection_id = create_test_collection(&CollectionMode::NFT, 1);12651266        let origin1 = Origin::signed(1);12671268        let data = default_nft_data();1269        create_test_item(collection_id, &data.into());12701271        assert_ok!(TemplateModule::set_public_access_mode(1272            origin1.clone(),1273            collection_id,1274            AccessMode::WhiteList1275        ));12761277        // do approve1278        assert_noop!(1279            TemplateModule::approve(origin1.clone(), account(1), 1, 1, 5),1280            Error::<Test>::AddresNotInWhiteList1281        );1282    });1283}12841285// If Public Access mode is set to WhiteList, tokens can be transferred from a whitelisted address with transfer or transferFrom (2 tests) and1286//          tokens can be transferred from a whitelisted address with transfer or transferFrom (2 tests)1287#[test]1288fn white_list_test_7() {1289    new_test_ext().execute_with(|| {1290        default_limits();1291        1292        let collection_id = create_test_collection(&CollectionMode::NFT, 1);12931294        let data = default_nft_data();1295        create_test_item(collection_id, &data.into());1296        1297        let origin1 = Origin::signed(1);12981299        assert_ok!(TemplateModule::set_public_access_mode(1300            origin1.clone(),1301            collection_id,1302            AccessMode::WhiteList1303        ));1304        assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), collection_id, account(1)));1305        assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), collection_id, account(2)));13061307        assert_ok!(TemplateModule::transfer(origin1.clone(), account(2), 1, 1, 1));1308    });1309}13101311#[test]1312fn white_list_test_8() {1313    new_test_ext().execute_with(|| {1314        default_limits();1315        1316        let collection_id = create_test_collection(&CollectionMode::NFT, 1);13171318        let data = default_nft_data();1319        create_test_item(collection_id, &data.into());1320        1321        let origin1 = Origin::signed(1);13221323        assert_ok!(TemplateModule::set_public_access_mode(1324            origin1.clone(),1325            collection_id,1326            AccessMode::WhiteList1327        ));1328        assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), collection_id, account(1)));1329        assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), collection_id, account(2)));13301331        // do approve1332        assert_ok!(TemplateModule::approve(origin1.clone(), account(1), 1, 1, 5));1333        assert_eq!(TemplateModule::approved(1, (1, 1, 1)), 5);13341335        assert_ok!(TemplateModule::transfer_from(1336            origin1.clone(),1337            account(1),1338            account(2),1339            1,1340            1,1341            11342        ));1343    });1344}13451346// If Public Access mode is set to WhiteList, and Mint Permission is set to false, tokens can be created by owner.1347#[test]1348fn white_list_test_9() {1349    new_test_ext().execute_with(|| {1350        default_limits();1351        1352        let collection_id = create_test_collection(&CollectionMode::NFT, 1);1353        let origin1 = Origin::signed(1);13541355        assert_ok!(TemplateModule::set_public_access_mode(1356            origin1.clone(),1357            collection_id,1358            AccessMode::WhiteList1359        ));1360        assert_ok!(TemplateModule::set_mint_permission(1361            origin1.clone(),1362            collection_id,1363            false1364        ));13651366        let data = default_nft_data();1367        create_test_item(collection_id, &data.into());1368    });1369}13701371// If Public Access mode is set to WhiteList, and Mint Permission is set to false, tokens can be created by admin.1372#[test]1373fn white_list_test_10() {1374    new_test_ext().execute_with(|| {1375        default_limits();1376        1377        let collection_id = create_test_collection(&CollectionMode::NFT, 1);13781379        let origin1 = Origin::signed(1);1380        let origin2 = Origin::signed(2);13811382        assert_ok!(TemplateModule::set_public_access_mode(1383            origin1.clone(),1384            collection_id,1385            AccessMode::WhiteList1386        ));1387        assert_ok!(TemplateModule::set_mint_permission(1388            origin1.clone(),1389            collection_id,1390            false1391        ));13921393        assert_ok!(TemplateModule::add_collection_admin(origin1.clone(), collection_id, account(2)));13941395        assert_ok!(TemplateModule::create_item(1396            origin2.clone(),1397            collection_id,1398            account(2),1399            default_nft_data().into()1400        ));1401    });1402}14031404// 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.1405#[test]1406fn white_list_test_11() {1407    new_test_ext().execute_with(|| {1408        default_limits();1409        1410        let collection_id = create_test_collection(&CollectionMode::NFT, 1);14111412        let origin1 = Origin::signed(1);1413        let origin2 = Origin::signed(2);14141415        assert_ok!(TemplateModule::set_public_access_mode(1416            origin1.clone(),1417            collection_id,1418            AccessMode::WhiteList1419        ));1420        assert_ok!(TemplateModule::set_mint_permission(1421            origin1.clone(),1422            collection_id,1423            false1424        ));1425        assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), collection_id, account(2)));14261427        assert_noop!(1428            TemplateModule::create_item(origin2.clone(), 1, account(2), default_nft_data().into()),1429            Error::<Test>::PublicMintingNotAllowed1430        );1431    });1432}14331434// 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.1435#[test]1436fn white_list_test_12() {1437    new_test_ext().execute_with(|| {1438        default_limits();1439        1440        let collection_id = create_test_collection(&CollectionMode::NFT, 1);14411442        let origin1 = Origin::signed(1);1443        let origin2 = Origin::signed(2);14441445        assert_ok!(TemplateModule::set_public_access_mode(1446            origin1.clone(),1447            collection_id,1448            AccessMode::WhiteList1449        ));1450        assert_ok!(TemplateModule::set_mint_permission(1451            origin1.clone(),1452            collection_id,1453            false1454        ));14551456        assert_noop!(1457            TemplateModule::create_item(origin2.clone(), 1, account(2), default_nft_data().into()),1458            Error::<Test>::PublicMintingNotAllowed1459        );1460    });1461}14621463// If Public Access mode is set to WhiteList, and Mint Permission is set to true, tokens can be created by owner.1464#[test]1465fn white_list_test_13() {1466    new_test_ext().execute_with(|| {1467        default_limits();1468        1469        let collection_id = create_test_collection(&CollectionMode::NFT, 1);14701471        let origin1 = Origin::signed(1);14721473        assert_ok!(TemplateModule::set_public_access_mode(1474            origin1.clone(),1475            collection_id,1476            AccessMode::WhiteList1477        ));1478        assert_ok!(TemplateModule::set_mint_permission(1479            origin1.clone(),1480            collection_id,1481            true1482        ));14831484        let data = default_nft_data();1485        create_test_item(collection_id, &data.into());1486    });1487}14881489// If Public Access mode is set to WhiteList, and Mint Permission is set to true, tokens can be created by admin.1490#[test]1491fn white_list_test_14() {1492    new_test_ext().execute_with(|| {1493        default_limits();1494        1495        let collection_id = create_test_collection(&CollectionMode::NFT, 1);14961497        let origin1 = Origin::signed(1);1498        let origin2 = Origin::signed(2);14991500        assert_ok!(TemplateModule::set_public_access_mode(1501            origin1.clone(),1502            collection_id,1503            AccessMode::WhiteList1504        ));1505        assert_ok!(TemplateModule::set_mint_permission(1506            origin1.clone(),1507            collection_id,1508            true1509        ));15101511        assert_ok!(TemplateModule::add_collection_admin(origin1.clone(), collection_id, account(2)));15121513        assert_ok!(TemplateModule::create_item(1514            origin2.clone(),1515            1,1516            account(2),1517            default_nft_data().into()1518        ));1519    });1520}15211522// 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.1523#[test]1524fn white_list_test_15() {1525    new_test_ext().execute_with(|| {1526        default_limits();1527        1528        let collection_id = create_test_collection(&CollectionMode::NFT, 1);15291530        let origin1 = Origin::signed(1);1531        let origin2 = Origin::signed(2);15321533        assert_ok!(TemplateModule::set_public_access_mode(1534            origin1.clone(),1535            collection_id,1536            AccessMode::WhiteList1537        ));1538        assert_ok!(TemplateModule::set_mint_permission(1539            origin1.clone(),1540            collection_id,1541            true1542        ));15431544        assert_noop!(1545            TemplateModule::create_item(origin2.clone(), 1, account(2), default_nft_data().into()),1546            Error::<Test>::AddresNotInWhiteList1547        );1548    });1549}15501551// 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.1552#[test]1553fn white_list_test_16() {1554    new_test_ext().execute_with(|| {1555        default_limits();1556        1557        let collection_id = create_test_collection(&CollectionMode::NFT, 1);15581559        let origin1 = Origin::signed(1);1560        let origin2 = Origin::signed(2);15611562        assert_ok!(TemplateModule::set_public_access_mode(1563            origin1.clone(),1564            collection_id,1565            AccessMode::WhiteList1566        ));1567        assert_ok!(TemplateModule::set_mint_permission(1568            origin1.clone(),1569            collection_id,1570            true1571        ));1572        assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), collection_id, account(2)));15731574        assert_ok!(TemplateModule::create_item(1575            origin2.clone(),1576            1,1577            account(2),1578            default_nft_data().into()1579        ));1580    });1581}15821583// Total number of collections. Positive test1584#[test]1585fn total_number_collections_bound() {1586    new_test_ext().execute_with(|| {1587        default_limits();1588        1589        create_test_collection(&CollectionMode::NFT, 1);1590    });1591}15921593// Total number of collections. Negotive test1594#[test]1595fn total_number_collections_bound_neg() {1596    new_test_ext().execute_with(|| {1597        default_limits();15981599        let origin1 = Origin::signed(1);16001601        for i in 0..default_collection_numbers_limit() {1602            create_test_collection(&CollectionMode::NFT, i + 1);1603        }16041605        let col_name1: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();1606        let col_desc1: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();1607        let token_prefix1: Vec<u8> = b"token_prefix1\0".to_vec();16081609        // 11-th collection in chain. Expects error1610        assert_noop!(TemplateModule::create_collection(1611            origin1.clone(),1612            col_name1.clone(),1613            col_desc1.clone(),1614            token_prefix1.clone(),1615            CollectionMode::NFT1616        ), Error::<Test>::TotalCollectionsLimitExceeded);1617    });1618}16191620// Owned tokens by a single address. Positive test1621#[test]1622fn owned_tokens_bound() {1623    new_test_ext().execute_with(|| {1624        default_limits();1625        1626        let collection_id = create_test_collection(&CollectionMode::NFT, 1);16271628        let data = default_nft_data();1629        create_test_item(collection_id, &data.clone().into());1630        create_test_item(collection_id, &data.into());1631    });1632}16331634// Owned tokens by a single address. Negotive test1635#[test]1636fn owned_tokens_bound_neg() {1637    new_test_ext().execute_with(|| {1638        assert_ok!(TemplateModule::set_chain_limits(RawOrigin::Root.into(), ChainLimits { 1639            collection_numbers_limit: 10,1640            account_token_ownership_limit: 1,1641            collections_admins_limit: 5,1642            custom_data_limit: 2048,1643            nft_sponsor_transfer_timeout: 15,1644            fungible_sponsor_transfer_timeout: 15,1645            refungible_sponsor_transfer_timeout: 15,1646            const_on_chain_schema_limit: 1024,1647            offchain_schema_limit: 1024,1648            variable_on_chain_schema_limit: 1024,1649        }));1650        1651        let collection_id = create_test_collection(&CollectionMode::NFT, 1);16521653        let origin1 = Origin::signed(1);1654        let data = default_nft_data();1655        create_test_item(collection_id, &data.clone().into());16561657        assert_noop!(TemplateModule::create_item(1658            origin1.clone(),1659            1,1660            account(1),1661            data.into()1662        ),  Error::<Test>::AddressOwnershipLimitExceeded);1663    });1664}16651666// Number of collection admins. Positive test1667#[test]1668fn collection_admins_bound() {1669    new_test_ext().execute_with(|| {1670        assert_ok!(TemplateModule::set_chain_limits(RawOrigin::Root.into(), ChainLimits { 1671            collection_numbers_limit: 10,1672            account_token_ownership_limit: 10,1673            collections_admins_limit: 2,1674            custom_data_limit: 2048,1675            nft_sponsor_transfer_timeout: 15,1676            fungible_sponsor_transfer_timeout: 15,1677            refungible_sponsor_transfer_timeout: 15,1678            const_on_chain_schema_limit: 1024,1679            offchain_schema_limit: 1024,1680            variable_on_chain_schema_limit: 1024,1681        }));1682        1683        let collection_id = create_test_collection(&CollectionMode::NFT, 1);16841685        let origin1 = Origin::signed(1);1686        1687        assert_ok!(TemplateModule::add_collection_admin(origin1.clone(), collection_id, account(2)));1688        assert_ok!(TemplateModule::add_collection_admin(origin1.clone(), collection_id, account(3)));1689    });1690}16911692// Number of collection admins. Negotive test1693#[test]1694fn collection_admins_bound_neg() {1695    new_test_ext().execute_with(|| {1696        assert_ok!(TemplateModule::set_chain_limits(RawOrigin::Root.into(), ChainLimits { 1697            collection_numbers_limit: 10,1698            account_token_ownership_limit: 1,1699            collections_admins_limit: 1,1700            custom_data_limit: 2048,1701            nft_sponsor_transfer_timeout: 15,1702            fungible_sponsor_transfer_timeout: 15,1703            refungible_sponsor_transfer_timeout: 15,1704            const_on_chain_schema_limit: 1024,1705            offchain_schema_limit: 1024,1706            variable_on_chain_schema_limit: 1024,1707        }));1708        1709        let collection_id = create_test_collection(&CollectionMode::NFT, 1);17101711        let origin1 = Origin::signed(1);17121713        assert_ok!(TemplateModule::add_collection_admin(origin1.clone(), collection_id, account(2)));1714        assert_noop!(TemplateModule::add_collection_admin(origin1.clone(), collection_id, account(3)), Error::<Test>::CollectionAdminsLimitExceeded);1715    });1716}17171718// NFT custom data size. Negative test const_data.1719#[test]1720fn custom_data_size_nft_const_data_bound_neg() {1721    new_test_ext().execute_with(|| {1722        assert_ok!(TemplateModule::set_chain_limits(RawOrigin::Root.into(), ChainLimits { 1723            collection_numbers_limit: 10,1724            account_token_ownership_limit: 10,1725            collections_admins_limit: 5,1726            custom_data_limit: 2,1727            nft_sponsor_transfer_timeout: 15,1728            fungible_sponsor_transfer_timeout: 15,1729            refungible_sponsor_transfer_timeout: 15,1730            const_on_chain_schema_limit: 1024,1731            offchain_schema_limit: 1024,1732            variable_on_chain_schema_limit: 1024,1733        }));1734        1735        let collection_id = create_test_collection(&CollectionMode::NFT, 1);17361737        let origin1 = Origin::signed(1);1738        let too_big_const_data = CreateItemData::NFT(CreateNftData{1739            const_data: vec![1, 2, 3, 4],1740            variable_data: vec![]1741        });17421743        assert_noop!(TemplateModule::create_item(1744            origin1.clone(),1745            collection_id,1746            account(1),1747            too_big_const_data1748        ), Error::<Test>::TokenConstDataLimitExceeded);1749    });1750}17511752// NFT custom data size. Negative test variable_data.1753#[test]1754fn custom_data_size_nft_variable_data_bound_neg() {1755    new_test_ext().execute_with(|| {1756        assert_ok!(TemplateModule::set_chain_limits(RawOrigin::Root.into(), ChainLimits { 1757            collection_numbers_limit: 10,1758            account_token_ownership_limit: 10,1759            collections_admins_limit: 5,1760            custom_data_limit: 2,1761            nft_sponsor_transfer_timeout: 15,1762            fungible_sponsor_transfer_timeout: 15,1763            refungible_sponsor_transfer_timeout: 15,1764            const_on_chain_schema_limit: 1024,1765            offchain_schema_limit: 1024,1766            variable_on_chain_schema_limit: 1024,1767        }));17681769        let collection_id = create_test_collection(&CollectionMode::NFT, 1);17701771        let origin1 = Origin::signed(1);1772        let too_big_const_data = CreateItemData::NFT(CreateNftData{1773            const_data: vec![],1774            variable_data: vec![1, 2, 3, 4]1775        });17761777        assert_noop!(TemplateModule::create_item(1778            origin1.clone(),1779            collection_id,1780            account(1),1781            too_big_const_data1782        ), Error::<Test>::TokenVariableDataLimitExceeded);1783    });1784}17851786// Re fungible custom data size. Negative test const_data.1787#[test]1788fn custom_data_size_re_fungible_const_data_bound_neg() {1789    new_test_ext().execute_with(|| {1790        assert_ok!(TemplateModule::set_chain_limits(RawOrigin::Root.into(), ChainLimits { 1791            collection_numbers_limit: 10,1792            account_token_ownership_limit: 10,1793            collections_admins_limit: 5,1794            custom_data_limit: 2,1795            nft_sponsor_transfer_timeout: 15,1796            fungible_sponsor_transfer_timeout: 15,1797            refungible_sponsor_transfer_timeout: 15,1798            const_on_chain_schema_limit: 1024,1799            offchain_schema_limit: 1024,1800            variable_on_chain_schema_limit: 1024,1801        }));18021803        let collection_id = create_test_collection(&CollectionMode::NFT, 1);18041805        let origin1 = Origin::signed(1);1806        let too_big_const_data = CreateItemData::NFT(CreateNftData{1807            const_data: vec![1, 2, 3, 4],1808            variable_data: vec![]1809        });18101811        assert_noop!(TemplateModule::create_item(1812            origin1.clone(),1813            collection_id,1814            account(1),1815            too_big_const_data1816        ), Error::<Test>::TokenConstDataLimitExceeded);1817    });1818}18191820// Re fungible custom data size. Negative test variable_data.1821#[test]1822fn custom_data_size_re_fungible_variable_data_bound_neg() {1823    new_test_ext().execute_with(|| {1824        assert_ok!(TemplateModule::set_chain_limits(RawOrigin::Root.into(), ChainLimits { 1825            collection_numbers_limit: 10,1826            account_token_ownership_limit: 10,1827            collections_admins_limit: 5,1828            custom_data_limit: 2,1829            nft_sponsor_transfer_timeout: 15,1830            fungible_sponsor_transfer_timeout: 15,1831            refungible_sponsor_transfer_timeout: 15,1832            const_on_chain_schema_limit: 1024,1833            offchain_schema_limit: 1024,1834            variable_on_chain_schema_limit: 1024,1835        }));18361837        let collection_id = create_test_collection(&CollectionMode::NFT, 1);18381839        let origin1 = Origin::signed(1);1840        let too_big_const_data = CreateItemData::NFT(CreateNftData{1841            const_data: vec![],1842            variable_data: vec![1, 2, 3, 4]1843        });18441845        assert_noop!(TemplateModule::create_item(1846            origin1.clone(),1847            collection_id,1848            account(1),1849            too_big_const_data1850        ), Error::<Test>::TokenVariableDataLimitExceeded);1851    });1852}1853// #endregion18541855#[test]1856fn set_const_on_chain_schema() {1857    new_test_ext().execute_with(|| {1858        default_limits();18591860        let collection_id = create_test_collection(&CollectionMode::NFT, 1);18611862        let origin1 = Origin::signed(1);1863        assert_ok!(TemplateModule::set_const_on_chain_schema(origin1, collection_id, b"test const on chain schema".to_vec()));18641865        assert_eq!(TemplateModule::collection_id(collection_id).unwrap().const_on_chain_schema, b"test const on chain schema".to_vec());1866        assert_eq!(TemplateModule::collection_id(collection_id).unwrap().variable_on_chain_schema, b"".to_vec());1867    });1868}18691870#[test]1871fn set_variable_on_chain_schema() {1872    new_test_ext().execute_with(|| {1873        default_limits();1874        1875        let collection_id = create_test_collection(&CollectionMode::NFT, 1);18761877        let origin1 = Origin::signed(1);1878        assert_ok!(TemplateModule::set_variable_on_chain_schema(origin1, collection_id, b"test variable on chain schema".to_vec()));18791880        assert_eq!(TemplateModule::collection_id(collection_id).unwrap().const_on_chain_schema, b"".to_vec());1881        assert_eq!(TemplateModule::collection_id(collection_id).unwrap().variable_on_chain_schema, b"test variable on chain schema".to_vec());1882    });1883}18841885#[test]1886fn set_variable_meta_data_on_nft_token_stores_variable_meta_data() {1887    new_test_ext().execute_with(|| {1888        default_limits();18891890        let collection_id = create_test_collection(&CollectionMode::NFT, 1);18911892        let origin1 = Origin::signed(1);1893        1894        let data = default_nft_data();1895        create_test_item(1, &data.into());1896        1897        let variable_data = b"test set_variable_meta_data method.".to_vec();1898        assert_ok!(TemplateModule::set_variable_meta_data(origin1, collection_id, 1, variable_data.clone()));18991900        assert_eq!(TemplateModule::nft_item_id(collection_id, 1).unwrap().variable_data, variable_data);1901    });1902}19031904#[test]1905fn set_variable_meta_data_on_re_fungible_token_stores_variable_meta_data() {1906    new_test_ext().execute_with(|| {1907        default_limits();19081909        let collection_id = create_test_collection(&CollectionMode::ReFungible, 1);19101911        let origin1 = Origin::signed(1);19121913        let data = default_re_fungible_data();1914        create_test_item(1, &data.into());19151916        let variable_data = b"test set_variable_meta_data method.".to_vec();1917        assert_ok!(TemplateModule::set_variable_meta_data(origin1, collection_id, 1, variable_data.clone()));19181919        assert_eq!(TemplateModule::refungible_item_id(collection_id, 1).unwrap().variable_data, variable_data);1920    });1921}192219231924#[test]1925fn set_variable_meta_data_on_fungible_token_fails() {1926    new_test_ext().execute_with(|| {1927        default_limits();19281929        let collection_id = create_test_collection(&CollectionMode::Fungible(3), 1);19301931        let origin1 = Origin::signed(1);19321933        let data = default_fungible_data();1934        create_test_item(1, &data.into());19351936        let variable_data = b"test set_variable_meta_data method.".to_vec();1937        assert_noop!(TemplateModule::set_variable_meta_data(origin1, collection_id, 1, variable_data.clone()), Error::<Test>::CantStoreMetadataInFungibleTokens);1938    });1939}19401941#[test]1942fn set_variable_meta_data_on_nft_token_fails_for_big_data() {1943    new_test_ext().execute_with(|| {1944        assert_ok!(TemplateModule::set_chain_limits(RawOrigin::Root.into(), ChainLimits { 1945            collection_numbers_limit: default_collection_numbers_limit(),1946            account_token_ownership_limit: 10,1947            collections_admins_limit: 5,1948            custom_data_limit: 10,1949            nft_sponsor_transfer_timeout: 15,1950            fungible_sponsor_transfer_timeout: 15,1951            refungible_sponsor_transfer_timeout: 15,1952            const_on_chain_schema_limit: 1024,1953            offchain_schema_limit: 1024,1954            variable_on_chain_schema_limit: 1024,1955        }));19561957        let collection_id = create_test_collection(&CollectionMode::NFT, 1);19581959        let origin1 = Origin::signed(1);19601961        let data = default_nft_data();1962        create_test_item(1, &data.into());19631964        let variable_data = b"test set_variable_meta_data method, bigger than limits.".to_vec();1965        assert_noop!(TemplateModule::set_variable_meta_data(origin1, collection_id, 1, variable_data), Error::<Test>::TokenVariableDataLimitExceeded);1966    });1967}19681969#[test]1970fn set_variable_meta_data_on_re_fungible_token_fails_for_big_data() {1971    new_test_ext().execute_with(|| {1972        assert_ok!(TemplateModule::set_chain_limits(RawOrigin::Root.into(), ChainLimits { 1973            collection_numbers_limit: default_collection_numbers_limit(),1974            account_token_ownership_limit: 10,1975            collections_admins_limit: 5,1976            custom_data_limit: 10,1977            nft_sponsor_transfer_timeout: 15,1978            fungible_sponsor_transfer_timeout: 15,1979            refungible_sponsor_transfer_timeout: 15,1980            const_on_chain_schema_limit: 1024,1981            offchain_schema_limit: 1024,1982            variable_on_chain_schema_limit: 1024,1983        }));198419851986        let collection_id = create_test_collection(&CollectionMode::ReFungible, 1);19871988        let origin1 = Origin::signed(1);19891990        let data = default_re_fungible_data();1991        create_test_item(1, &data.into());19921993        let variable_data = b"test set_variable_meta_data method, bigger than limits.".to_vec();1994        assert_noop!(TemplateModule::set_variable_meta_data(origin1, collection_id, 1, variable_data), Error::<Test>::TokenVariableDataLimitExceeded);1995    });1996}
modifiedpallets/scheduler/src/lib.rsdiffbeforeafterboth
--- a/pallets/scheduler/src/lib.rs
+++ b/pallets/scheduler/src/lib.rs
@@ -887,6 +887,7 @@
 		type ScheduleOrigin = EnsureOneOf<u64, EnsureRoot<u64>, EnsureSignedBy<One, u64>>;
 		type MaxScheduledPerBlock = MaxScheduledPerBlock;
 		type WeightInfo = ();
+        type SponsorshipHandler = ();
 	}
 
 	pub fn new_test_ext() -> sp_io::TestExternalities {
modifiedruntime/src/lib.rsdiffbeforeafterboth
--- a/runtime/src/lib.rs
+++ b/runtime/src/lib.rs
@@ -689,7 +689,6 @@
 	type Event = Event;
 	type WeightInfo = nft_weights::WeightInfo;
 
-	type EvmWithdrawOrigin = EnsureAddressTruncated;
 	type EvmBackwardsAddressMapping = pallet_nft::MapBackwardsAddressTruncated;
 	type EvmAddressMapping = HashedAddressMapping<Self::Hashing>;
 	type CrossAccountId = pallet_nft::BasicCrossAccountId<Self>;