difftreelog
Merge pull request #70 from usetech-llc/fix/NFTPAR-290_291
in: master
Fix/nftpar 290 291
4 files changed
pallets/nft/src/lib.rsdiffbeforeafterboth--- a/pallets/nft/src/lib.rs
+++ b/pallets/nft/src/lib.rs
@@ -1009,7 +1009,7 @@
{
CollectionMode::NFT => Self::burn_nft_item(collection_id, item_id)?,
CollectionMode::Fungible(_) => Self::burn_fungible_item(&sender, collection_id, value)?,
- CollectionMode::ReFungible(_) => Self::burn_refungible_item(collection_id, item_id, sender.clone())?,
+ CollectionMode::ReFungible(_) => Self::burn_refungible_item(collection_id, item_id, &sender)?,
_ => ()
};
@@ -1092,6 +1092,9 @@
let sender = ensure_signed(origin)?;
+ Self::collection_exists(collection_id)?;
+ Self::token_exists(collection_id, item_id, &sender)?;
+
// Transfer permissions check
let target_collection = <Collection<T>>::get(collection_id);
ensure!(Self::is_item_owner(sender.clone(), collection_id, item_id) ||
@@ -1216,7 +1219,8 @@
let sender = ensure_signed(origin)?;
Self::collection_exists(collection_id)?;
-
+ Self::token_exists(collection_id, item_id, &sender)?;
+
ensure!(ChainLimit::get().custom_data_limit >= data.len() as u32, Error::<T>::TokenVariableDataLimitExceeded);
// Modify permissions check
@@ -1224,8 +1228,6 @@
ensure!(Self::is_item_owner(sender.clone(), collection_id, item_id) ||
Self::is_owner_or_admin_permissions(collection_id, sender.clone()),
Error::<T>::NoPermission);
-
- Self::item_exists(collection_id, item_id, &target_collection.mode)?;
match target_collection.mode
{
@@ -1320,7 +1322,7 @@
Self::check_owner_or_admin_permissions(collection_id, sender.clone())?;
// check schema limit
- ensure!(schema.len() as u32 > ChainLimit::get().const_on_chain_schema_limit, "");
+ ensure!(schema.len() as u32 <= ChainLimit::get().const_on_chain_schema_limit, "");
let mut target_collection = <Collection<T>>::get(collection_id);
target_collection.const_on_chain_schema = schema;
@@ -1351,7 +1353,7 @@
Self::check_owner_or_admin_permissions(collection_id, sender.clone())?;
// check schema limit
- ensure!(schema.len() as u32 > ChainLimit::get().variable_on_chain_schema_limit, "");
+ ensure!(schema.len() as u32 <= ChainLimit::get().variable_on_chain_schema_limit, "");
let mut target_collection = <Collection<T>>::get(collection_id);
target_collection.variable_on_chain_schema = schema;
@@ -1677,13 +1679,13 @@
let value = item.owner.first().unwrap().fraction;
let owner = item.owner.first().unwrap().owner.clone();
- Self::add_token_index(collection_id, current_index, owner.clone())?;
+ Self::add_token_index(collection_id, current_index, &owner)?;
<ItemListIndex>::insert(collection_id, current_index);
<ReFungibleItemList<T>>::insert(collection_id, current_index, itemcopy);
// Update balance
- let new_balance = <Balance<T>>::get(collection_id, owner.clone())
+ let new_balance = <Balance<T>>::get(collection_id, &owner)
.checked_add(value)
.ok_or(Error::<T>::NumOverflow)?;
<Balance<T>>::insert(collection_id, owner.clone(), new_balance);
@@ -1697,7 +1699,7 @@
.ok_or(Error::<T>::NumOverflow)?;
let item_owner = item.owner.clone();
- Self::add_token_index(collection_id, current_index, item.owner.clone())?;
+ Self::add_token_index(collection_id, current_index, &item.owner)?;
<ItemListIndex>::insert(collection_id, current_index);
<NftItemList<T>>::insert(collection_id, current_index, item);
@@ -1714,29 +1716,44 @@
fn burn_refungible_item(
collection_id: CollectionId,
item_id: TokenId,
- owner: T::AccountId,
+ owner: &T::AccountId,
) -> DispatchResult {
ensure!(
<ReFungibleItemList<T>>::contains_key(collection_id, item_id),
Error::<T>::TokenNotFound
);
- let collection = <ReFungibleItemList<T>>::get(collection_id, item_id);
- let item = collection
+ let mut token = <ReFungibleItemList<T>>::get(collection_id, item_id);
+ let rft_balance = token
.owner
.iter()
- .filter(|&i| i.owner == owner)
+ .filter(|&i| i.owner == *owner)
.next()
.unwrap();
- Self::remove_token_index(collection_id, item_id, owner.clone())?;
+ Self::remove_token_index(collection_id, item_id, owner)?;
// update balance
- let new_balance = <Balance<T>>::get(collection_id, item.owner.clone())
- .checked_sub(item.fraction)
+ let new_balance = <Balance<T>>::get(collection_id, rft_balance.owner.clone())
+ .checked_sub(rft_balance.fraction)
.ok_or(Error::<T>::NumOverflow)?;
- <Balance<T>>::insert(collection_id, item.owner.clone(), new_balance);
+ <Balance<T>>::insert(collection_id, rft_balance.owner.clone(), new_balance);
- <ReFungibleItemList<T>>::remove(collection_id, item_id);
+ // Re-create owners list with sender removed
+ let index = token
+ .owner
+ .iter()
+ .position(|i| i.owner == *owner)
+ .unwrap();
+ token.owner.remove(index);
+ let owner_count = token.owner.len();
+ // Burn the token completely if this was the last (only) owner
+ if owner_count == 0 {
+ <ReFungibleItemList<T>>::remove(collection_id, item_id);
+ }
+ else {
+ <ReFungibleItemList<T>>::insert(collection_id, item_id, token);
+ }
+
Ok(())
}
@@ -1746,10 +1763,10 @@
Error::<T>::TokenNotFound
);
let item = <NftItemList<T>>::get(collection_id, item_id);
- Self::remove_token_index(collection_id, item_id, item.owner.clone())?;
+ Self::remove_token_index(collection_id, item_id, &item.owner)?;
// update balance
- let new_balance = <Balance<T>>::get(collection_id, item.owner.clone())
+ let new_balance = <Balance<T>>::get(collection_id, &item.owner)
.checked_sub(1)
.ok_or(Error::<T>::NumOverflow)?;
<Balance<T>>::insert(collection_id, item.owner.clone(), new_balance);
@@ -1858,16 +1875,33 @@
Ok(())
}
+ /// Check if token exists. In case of Fungible, check if there is an entry for
+ /// the owner in fungible balances double map
+ fn token_exists(
+ collection_id: CollectionId,
+ item_id: TokenId,
+ owner: &T::AccountId
+ ) -> DispatchResult {
+ let target_collection = <Collection<T>>::get(collection_id);
+ let exists = match target_collection.mode
+ {
+ CollectionMode::NFT => <NftItemList<T>>::contains_key(collection_id, item_id),
+ CollectionMode::Fungible(_) => <FungibleItemList<T>>::contains_key(collection_id, owner),
+ CollectionMode::ReFungible(_) => <ReFungibleItemList<T>>::contains_key(collection_id, item_id),
+ _ => false
+ };
+
+ ensure!(exists == true, Error::<T>::TokenNotFound);
+ Ok(())
+ }
+
fn transfer_fungible(
collection_id: CollectionId,
value: u128,
owner: &T::AccountId,
recipient: &T::AccountId,
) -> DispatchResult {
- ensure!(
- <FungibleItemList<T>>::contains_key(collection_id, owner),
- Error::<T>::TokenNotFound
- );
+ Self::token_exists(collection_id, 0, owner)?;
let mut balance = <FungibleItemList<T>>::get(collection_id, owner);
ensure!(balance.value >= value, Error::<T>::TokenValueTooLow);
@@ -1897,10 +1931,7 @@
owner: T::AccountId,
new_owner: T::AccountId,
) -> DispatchResult {
- ensure!(
- <ReFungibleItemList<T>>::contains_key(collection_id, item_id),
- Error::<T>::TokenNotFound
- );
+ Self::token_exists(collection_id, item_id, &owner)?;
let full_item = <ReFungibleItemList<T>>::get(collection_id, item_id);
let item = full_item
@@ -1941,7 +1972,7 @@
<ReFungibleItemList<T>>::insert(collection_id, item_id, new_full_item);
// update index collection
- Self::move_token_index(collection_id, item_id, old_owner.clone(), new_owner.clone())?;
+ Self::move_token_index(collection_id, item_id, &old_owner, &new_owner)?;
} else {
let mut new_full_item = full_item.clone();
new_full_item
@@ -1966,7 +1997,7 @@
owner: new_owner.clone(),
fraction: value,
});
- Self::add_token_index(collection_id, item_id, new_owner.clone())?;
+ Self::add_token_index(collection_id, item_id, &new_owner)?;
}
<ReFungibleItemList<T>>::insert(collection_id, item_id, new_full_item);
@@ -1981,10 +2012,7 @@
sender: T::AccountId,
new_owner: T::AccountId,
) -> DispatchResult {
- ensure!(
- <NftItemList<T>>::contains_key(collection_id, item_id),
- Error::<T>::TokenNotFound
- );
+ Self::token_exists(collection_id, item_id, &sender)?;
let mut item = <NftItemList<T>>::get(collection_id, item_id);
@@ -2010,25 +2038,11 @@
<NftItemList<T>>::insert(collection_id, item_id, item);
// update index collection
- Self::move_token_index(collection_id, item_id, old_owner.clone(), new_owner.clone())?;
+ Self::move_token_index(collection_id, item_id, &old_owner, &new_owner)?;
Ok(())
}
- fn item_exists(
- collection_id: CollectionId,
- item_id: TokenId,
- mode: &CollectionMode
- ) -> DispatchResult {
- match mode {
- CollectionMode::NFT => ensure!(<NftItemList<T>>::contains_key(collection_id, item_id), Error::<T>::TokenNotFound),
- CollectionMode::ReFungible(_) => ensure!(<ReFungibleItemList<T>>::contains_key(collection_id, item_id), Error::<T>::TokenNotFound),
- _ => ()
- };
-
- Ok(())
- }
-
fn set_re_fungible_variable_data(
collection_id: CollectionId,
item_id: TokenId,
@@ -2090,12 +2104,12 @@
.unwrap();
let item_owner = item.owner.clone();
- Self::add_token_index(collection_id, current_index, item.owner.clone()).unwrap();
+ Self::add_token_index(collection_id, current_index, &item.owner).unwrap();
<ItemListIndex>::insert(collection_id, current_index);
// Update balance
- let new_balance = <Balance<T>>::get(collection_id, item_owner.clone())
+ let new_balance = <Balance<T>>::get(collection_id, &item_owner)
.checked_add(1)
.unwrap();
<Balance<T>>::insert(collection_id, item_owner.clone(), new_balance);
@@ -2106,7 +2120,7 @@
.checked_add(1)
.unwrap();
- Self::add_token_index(collection_id, current_index, (*owner).clone()).unwrap();
+ Self::add_token_index(collection_id, current_index, owner).unwrap();
<ItemListIndex>::insert(collection_id, current_index);
@@ -2125,24 +2139,24 @@
let value = item.owner.first().unwrap().fraction;
let owner = item.owner.first().unwrap().owner.clone();
- Self::add_token_index(collection_id, current_index, owner.clone()).unwrap();
+ Self::add_token_index(collection_id, current_index, &owner).unwrap();
<ItemListIndex>::insert(collection_id, current_index);
// Update balance
- let new_balance = <Balance<T>>::get(collection_id, owner.clone())
+ let new_balance = <Balance<T>>::get(collection_id, &owner)
.checked_add(value)
.unwrap();
<Balance<T>>::insert(collection_id, owner.clone(), new_balance);
}
- fn add_token_index(collection_id: CollectionId, item_index: TokenId, owner: T::AccountId) -> DispatchResult {
+ fn add_token_index(collection_id: CollectionId, item_index: TokenId, owner: &T::AccountId) -> DispatchResult {
// add to account limit
- if <AccountItemCount<T>>::contains_key(owner.clone()) {
+ if <AccountItemCount<T>>::contains_key(owner) {
// bound Owned tokens by a single address
- let count = <AccountItemCount<T>>::get(owner.clone());
+ let count = <AccountItemCount<T>>::get(owner);
ensure!(count < ChainLimit::get().account_token_ownership_limit, Error::<T>::AddressOwnershipLimitExceeded);
<AccountItemCount<T>>::insert(owner.clone(), count
@@ -2153,9 +2167,9 @@
<AccountItemCount<T>>::insert(owner.clone(), 1);
}
- let list_exists = <AddressTokens<T>>::contains_key(collection_id, owner.clone());
+ let list_exists = <AddressTokens<T>>::contains_key(collection_id, owner);
if list_exists {
- let mut list = <AddressTokens<T>>::get(collection_id, owner.clone());
+ let mut list = <AddressTokens<T>>::get(collection_id, owner);
let item_contains = list.contains(&item_index.clone());
if !item_contains {
@@ -2166,8 +2180,7 @@
} else {
let mut itm = Vec::new();
itm.push(item_index.clone());
- <AddressTokens<T>>::insert(collection_id, owner, itm);
-
+ <AddressTokens<T>>::insert(collection_id, owner.clone(), itm);
}
Ok(())
@@ -2176,24 +2189,24 @@
fn remove_token_index(
collection_id: CollectionId,
item_index: TokenId,
- owner: T::AccountId,
+ owner: &T::AccountId,
) -> DispatchResult {
// update counter
<AccountItemCount<T>>::insert(owner.clone(),
- <AccountItemCount<T>>::get(owner.clone())
+ <AccountItemCount<T>>::get(owner)
.checked_sub(1)
.ok_or(Error::<T>::NumOverflow)?);
- let list_exists = <AddressTokens<T>>::contains_key(collection_id, owner.clone());
+ let list_exists = <AddressTokens<T>>::contains_key(collection_id, owner);
if list_exists {
- let mut list = <AddressTokens<T>>::get(collection_id, owner.clone());
+ let mut list = <AddressTokens<T>>::get(collection_id, owner);
let item_contains = list.contains(&item_index.clone());
if item_contains {
list.retain(|&item| item != item_index);
- <AddressTokens<T>>::insert(collection_id, owner, list);
+ <AddressTokens<T>>::insert(collection_id, owner.clone(), list);
}
}
@@ -2203,8 +2216,8 @@
fn move_token_index(
collection_id: CollectionId,
item_index: TokenId,
- old_owner: T::AccountId,
- new_owner: T::AccountId,
+ old_owner: &T::AccountId,
+ new_owner: &T::AccountId,
) -> DispatchResult {
Self::remove_token_index(collection_id, item_index, old_owner)?;
Self::add_token_index(collection_id, item_index, new_owner)?;
pallets/nft/src/tests.rsdiffbeforeafterboth1// 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 }));24}2526fn default_nft_data() -> CreateNftData {27 CreateNftData { const_data: vec![1, 2, 3], variable_data: vec![3, 2, 1] }28}2930fn default_fungible_data () -> CreateFungibleData {31 CreateFungibleData { value: 5 }32}3334fn default_re_fungible_data () -> CreateReFungibleData {35 CreateReFungibleData { const_data: vec![1, 2, 3], variable_data: vec![3, 2, 1] }36}3738fn create_test_collection_for_owner(mode: &CollectionMode, owner: u64, id: CollectionId) -> CollectionId {39 let col_name1: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();40 let col_desc1: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();41 let token_prefix1: Vec<u8> = b"token_prefix1\0".to_vec();4243 let origin1 = Origin::signed(owner);44 assert_ok!(TemplateModule::create_collection(45 origin1.clone(),46 col_name1.clone(),47 col_desc1.clone(),48 token_prefix1.clone(),49 mode.clone()50 ));5152 let saved_col_name: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();53 let saved_description: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();54 let saved_prefix: Vec<u8> = b"token_prefix1\0".to_vec();55 assert_eq!(TemplateModule::collection(id).owner, owner);56 assert_eq!(TemplateModule::collection(id).name, saved_col_name);57 assert_eq!(TemplateModule::collection(id).mode, *mode);58 assert_eq!(TemplateModule::collection(id).description, saved_description);59 assert_eq!(TemplateModule::collection(id).token_prefix, saved_prefix);60 id61}6263fn create_test_collection(mode: &CollectionMode, id: CollectionId) -> CollectionId {64 create_test_collection_for_owner(&mode, 1, id)65}6667fn create_test_item(collection_id: CollectionId, data: &CreateItemData) {68 let origin1 = Origin::signed(1);69 assert_ok!(TemplateModule::create_item(70 origin1.clone(),71 collection_id,72 1,73 data.clone()74 ));7576}7778// Use cases tests region79// #region8081#[test]82fn set_version_schema() {83 new_test_ext().execute_with(|| {84 default_limits();85 let origin1 = Origin::signed(1);86 let collection_id = create_test_collection(&CollectionMode::NFT, 1);87 88 assert_ok!(TemplateModule::set_schema_version(origin1, collection_id, SchemaVersion::Unique));89 assert_eq!(TemplateModule::collection(collection_id).schema_version, SchemaVersion::Unique);90 });91}9293#[test]94fn create_fungible_collection_fails_with_large_decimal_numbers() {95 new_test_ext().execute_with(|| {96 default_limits();9798 let col_name1: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();99 let col_desc1: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();100 let token_prefix1: Vec<u8> = b"token_prefix1\0".to_vec();101102 let origin1 = Origin::signed(1);103 assert_noop!(TemplateModule::create_collection(104 origin1,105 col_name1,106 col_desc1,107 token_prefix1,108 CollectionMode::Fungible(MAX_DECIMAL_POINTS + 1)109 ), Error::<Test>::CollectionDecimalPointLimitExceeded);110 }); 111}112113#[test]114fn create_re_fungible_collection_fails_with_large_decimal_numbers() {115 new_test_ext().execute_with(|| {116 default_limits();117118 let col_name1: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();119 let col_desc1: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();120 let token_prefix1: Vec<u8> = b"token_prefix1\0".to_vec();121122 let origin1 = Origin::signed(1);123 assert_noop!(TemplateModule::create_collection(124 origin1,125 col_name1,126 col_desc1,127 token_prefix1,128 CollectionMode::ReFungible(MAX_DECIMAL_POINTS + 1)129 ), Error::<Test>::CollectionDecimalPointLimitExceeded);130 });131}132133#[test]134fn create_nft_item() {135 new_test_ext().execute_with(|| {136 default_limits();137 let collection_id = create_test_collection(&CollectionMode::NFT, 1);138 139 let data = default_nft_data();140 create_test_item(collection_id, &data.clone().into());141 assert_eq!(TemplateModule::nft_item_id(collection_id, 1).const_data, data.const_data);142 assert_eq!(TemplateModule::nft_item_id(collection_id, 1).variable_data, data.variable_data);143 });144}145146// Use cases tests region147// #region148#[test]149fn create_nft_multiple_items() {150 new_test_ext().execute_with(|| {151 default_limits();152 153 create_test_collection(&CollectionMode::NFT, 1);154155 let origin1 = Origin::signed(1);156157 let items_data = vec![default_nft_data(), default_nft_data(), default_nft_data()];158159 assert_ok!(TemplateModule::create_multiple_items(160 origin1.clone(),161 1,162 1,163 items_data.clone().into_iter().map(|d| { d.into() }).collect()164 ));165 for (index, data) in items_data.iter().enumerate() {166 assert_eq!(TemplateModule::nft_item_id(1, (index + 1) as TokenId).const_data.to_vec(), data.const_data);167 assert_eq!(TemplateModule::nft_item_id(1, (index + 1) as TokenId).variable_data.to_vec(), data.variable_data);168 }169 });170}171172#[test]173fn create_refungible_item() {174 new_test_ext().execute_with(|| {175 default_limits();176 let collection_id = create_test_collection(&CollectionMode::ReFungible(3), 1);177178 let data = default_re_fungible_data();179 create_test_item(collection_id, &data.clone().into());180 assert_eq!(181 TemplateModule::refungible_item_id(collection_id, 1).const_data,182 data.const_data183 );184 assert_eq!(185 TemplateModule::refungible_item_id(collection_id, 1).variable_data,186 data.variable_data187 );188 assert_eq!(189 TemplateModule::refungible_item_id(collection_id, 1).owner[0],190 Ownership {191 owner: 1,192 fraction: 1000193 }194 );195 });196}197198#[test]199fn create_multiple_refungible_items() {200 new_test_ext().execute_with(|| {201 default_limits();202 203 create_test_collection(&CollectionMode::ReFungible(3), 1);204205 let origin1 = Origin::signed(1);206207 let items_data = vec![default_re_fungible_data(), default_re_fungible_data(), default_re_fungible_data()];208209 assert_ok!(TemplateModule::create_multiple_items(210 origin1.clone(),211 1,212 1,213 items_data.clone().into_iter().map(|d| { d.into() }).collect()214 ));215 for (index, data) in items_data.iter().enumerate() {216217 let item = TemplateModule::refungible_item_id(1, (index + 1) as TokenId);218 assert_eq!(item.const_data.to_vec(), data.const_data);219 assert_eq!(item.variable_data.to_vec(), data.variable_data);220 assert_eq!(221 item.owner[0],222 Ownership {223 owner: 1,224 fraction: 1000225 }226 );227 }228 });229}230231#[test]232fn create_fungible_item() {233 new_test_ext().execute_with(|| {234 default_limits();235 236 let collection_id = create_test_collection(&CollectionMode::Fungible(3), 1);237238 let data = default_fungible_data();239 create_test_item(collection_id, &data.into());240241 assert_eq!(TemplateModule::fungible_item_id(collection_id, 1).value, 5);242 });243}244245//#[test]246// fn create_multiple_fungible_items() {247// new_test_ext().execute_with(|| {248// default_limits();249250// create_test_collection(&CollectionMode::Fungible(3), 1);251252// let origin1 = Origin::signed(1);253254// let items_data = vec![default_fungible_data(), default_fungible_data(), default_fungible_data()];255256// assert_ok!(TemplateModule::create_multiple_items(257// origin1.clone(),258// 1,259// 1,260// items_data.clone().into_iter().map(|d| { d.into() }).collect()261// ));262 263// for (index, _) in items_data.iter().enumerate() {264// assert_eq!(TemplateModule::fungible_item_id(1, (index + 1) as TokenId).value, 5);265// }266// assert_eq!(TemplateModule::balance_count(1, 1), 3000);267// assert_eq!(TemplateModule::address_tokens(1, 1), [1, 2, 3]);268// });269// }270271#[test]272fn transfer_fungible_item() {273 new_test_ext().execute_with(|| {274 default_limits();275 276 let collection_id = create_test_collection(&CollectionMode::Fungible(3), 1);277278 let origin1 = Origin::signed(1);279 let origin2 = Origin::signed(2);280281 let data = default_fungible_data();282 create_test_item(collection_id, &data.into());283284 assert_eq!(TemplateModule::fungible_item_id(1, 1).value, 5);285 assert_eq!(TemplateModule::balance_count(1, 1), 5);286287 // change owner scenario288 assert_ok!(TemplateModule::transfer(origin1.clone(), 2, 1, 1, 5));289 assert_eq!(TemplateModule::fungible_item_id(1, 1).value, 0);290 assert_eq!(TemplateModule::balance_count(1, 1), 0);291 assert_eq!(TemplateModule::balance_count(1, 2), 5);292293 // split item scenario294 assert_ok!(TemplateModule::transfer(origin2.clone(), 3, 1, 1, 3));295 assert_eq!(TemplateModule::balance_count(1, 2), 2);296 assert_eq!(TemplateModule::balance_count(1, 3), 3);297298 // split item and new owner has account scenario299 assert_ok!(TemplateModule::transfer(origin2.clone(), 3, 1, 1, 1));300 assert_eq!(TemplateModule::fungible_item_id(1, 2).value, 1);301 assert_eq!(TemplateModule::fungible_item_id(1, 3).value, 4);302 assert_eq!(TemplateModule::balance_count(1, 2), 1);303 assert_eq!(TemplateModule::balance_count(1, 3), 4);304 });305}306307#[test]308fn transfer_refungible_item() {309 new_test_ext().execute_with(|| {310 default_limits();311 312 let collection_id = create_test_collection(&CollectionMode::ReFungible(3), 1);313314 let data = default_re_fungible_data();315 create_test_item(collection_id, &data.clone().into());316317 let origin1 = Origin::signed(1);318 let origin2 = Origin::signed(2);319 assert_eq!(320 TemplateModule::refungible_item_id(collection_id, 1).const_data,321 data.const_data322 );323 assert_eq!(324 TemplateModule::refungible_item_id(collection_id, 1).variable_data,325 data.variable_data326 );327 assert_eq!(328 TemplateModule::refungible_item_id(collection_id, 1).owner[0],329 Ownership {330 owner: 1,331 fraction: 1000332 }333 );334 assert_eq!(TemplateModule::balance_count(1, 1), 1000);335 assert_eq!(TemplateModule::address_tokens(1, 1), [1]);336337 // change owner scenario338 assert_ok!(TemplateModule::transfer(origin1.clone(), 2, 1, 1, 1000));339 assert_eq!(340 TemplateModule::refungible_item_id(1, 1).owner[0],341 Ownership {342 owner: 2,343 fraction: 1000344 }345 );346 assert_eq!(TemplateModule::balance_count(1, 1), 0);347 assert_eq!(TemplateModule::balance_count(1, 2), 1000);348 // assert_eq!(TemplateModule::address_tokens(1, 1), []);349 assert_eq!(TemplateModule::address_tokens(1, 2), [1]);350351 // split item scenario352 assert_ok!(TemplateModule::transfer(origin2.clone(), 3, 1, 1, 500));353 assert_eq!(354 TemplateModule::refungible_item_id(1, 1).owner[0],355 Ownership {356 owner: 2,357 fraction: 500358 }359 );360 assert_eq!(361 TemplateModule::refungible_item_id(1, 1).owner[1],362 Ownership {363 owner: 3,364 fraction: 500365 }366 );367 assert_eq!(TemplateModule::balance_count(1, 2), 500);368 assert_eq!(TemplateModule::balance_count(1, 3), 500);369 assert_eq!(TemplateModule::address_tokens(1, 2), [1]);370 assert_eq!(TemplateModule::address_tokens(1, 3), [1]);371372 // split item and new owner has account scenario373 assert_ok!(TemplateModule::transfer(origin2.clone(), 3, 1, 1, 200));374 assert_eq!(375 TemplateModule::refungible_item_id(1, 1).owner[0],376 Ownership {377 owner: 2,378 fraction: 300379 }380 );381 assert_eq!(382 TemplateModule::refungible_item_id(1, 1).owner[1],383 Ownership {384 owner: 3,385 fraction: 700386 }387 );388 assert_eq!(TemplateModule::balance_count(1, 2), 300);389 assert_eq!(TemplateModule::balance_count(1, 3), 700);390 assert_eq!(TemplateModule::address_tokens(1, 2), [1]);391 assert_eq!(TemplateModule::address_tokens(1, 3), [1]);392 });393}394395#[test]396fn transfer_nft_item() {397 new_test_ext().execute_with(|| {398 default_limits();399 400 let collection_id = create_test_collection(&CollectionMode::NFT, 1);401402 let data = default_nft_data();403 create_test_item(collection_id, &data.into());404 assert_eq!(TemplateModule::balance_count(1, 1), 1);405 assert_eq!(TemplateModule::address_tokens(1, 1), [1]);406407 let origin1 = Origin::signed(1);408 // default scenario409 assert_ok!(TemplateModule::transfer(origin1.clone(), 2, 1, 1, 1000));410 assert_eq!(TemplateModule::nft_item_id(1, 1).owner, 2);411 assert_eq!(TemplateModule::balance_count(1, 1), 0);412 assert_eq!(TemplateModule::balance_count(1, 2), 1);413 // assert_eq!(TemplateModule::address_tokens(1, 1), []);414 assert_eq!(TemplateModule::address_tokens(1, 2), [1]);415 });416}417418#[test]419fn nft_approve_and_transfer_from() {420 new_test_ext().execute_with(|| {421 default_limits();422 423 let collection_id = create_test_collection(&CollectionMode::NFT, 1);424425 let data = default_nft_data();426 create_test_item(collection_id, &data.into());427428 let origin1 = Origin::signed(1);429 let origin2 = Origin::signed(2);430431 assert_eq!(TemplateModule::balance_count(1, 1), 1);432 assert_eq!(TemplateModule::address_tokens(1, 1), [1]);433434 // neg transfer435 assert_noop!(TemplateModule::transfer_from(436 origin2.clone(),437 1,438 2,439 1,440 1,441 1), Error::<Test>::NoPermission);442443 // do approve444 assert_ok!(TemplateModule::approve(origin1.clone(), 2, 1, 1, 5));445 assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 5);446 assert_eq!(447 TemplateModule::approved(1, (1, 1, 2)),448 5449 );450451 assert_ok!(TemplateModule::transfer_from(452 origin2.clone(),453 1,454 2,455 1,456 1,457 1458 ));459 assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 4);460 });461}462463#[test]464fn nft_approve_and_transfer_from_white_list() {465 new_test_ext().execute_with(|| {466 default_limits();467 468 let collection_id = create_test_collection(&CollectionMode::NFT, 1);469470 let origin1 = Origin::signed(1);471 let origin2 = Origin::signed(2);472473 let data = default_nft_data();474 create_test_item(collection_id, &data.clone().into());475476 assert_eq!(TemplateModule::nft_item_id(1, 1).const_data, data.const_data);477 assert_eq!(TemplateModule::balance_count(1, 1), 1);478 assert_eq!(TemplateModule::address_tokens(1, 1), [1]);479480 assert_ok!(TemplateModule::set_mint_permission(481 origin1.clone(),482 1,483 true484 ));485 assert_ok!(TemplateModule::set_public_access_mode(486 origin1.clone(),487 1,488 AccessMode::WhiteList489 ));490 assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), 1, 1));491 assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), 1, 2));492 assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), 1, 3));493494 // do approve495 assert_ok!(TemplateModule::approve(origin1.clone(), 2, 1, 1, 5));496 assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 5);497 assert_ok!(TemplateModule::approve(origin1.clone(), 3, 1, 1, 5));498 assert_eq!(TemplateModule::approved(1, (1, 1, 3)), 5);499500 assert_ok!(TemplateModule::transfer_from(501 origin2.clone(),502 1,503 3,504 1,505 1,506 1507 ));508 assert_eq!(TemplateModule::approved(1, (1, 1, 3)), 4);509 });510}511512#[test]513fn refungible_approve_and_transfer_from() {514 new_test_ext().execute_with(|| {515 default_limits();516 517 let collection_id = create_test_collection(&CollectionMode::ReFungible(3), 1);518 519 let origin1 = Origin::signed(1);520 let origin2 = Origin::signed(2);521522 let data = default_re_fungible_data();523 create_test_item(collection_id, &data.into());524525 assert_eq!(TemplateModule::balance_count(1, 1), 1000);526 assert_eq!(TemplateModule::address_tokens(1, 1), [1]);527528 assert_ok!(TemplateModule::set_mint_permission(529 origin1.clone(),530 1,531 true532 ));533 assert_ok!(TemplateModule::set_public_access_mode(534 origin1.clone(),535 1,536 AccessMode::WhiteList537 ));538 assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), 1, 1));539 assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), 1, 2));540 assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), 1, 3));541542 // do approve543 assert_ok!(TemplateModule::approve(origin1.clone(), 2, 1, 1, 5));544 assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 5);545 assert_ok!(TemplateModule::approve(origin1.clone(), 3, 1, 1, 1000));546 assert_eq!(TemplateModule::approved(1, (1, 1, 3)), 1000);547548 assert_ok!(TemplateModule::transfer_from(549 origin2.clone(),550 1,551 3,552 1,553 1,554 100555 ));556 assert_eq!(TemplateModule::balance_count(1, 1), 900);557 assert_eq!(TemplateModule::balance_count(1, 3), 100);558 assert_eq!(TemplateModule::address_tokens(1, 1), [1]);559 assert_eq!(TemplateModule::address_tokens(1, 3), [1]);560561 assert_eq!(562 TemplateModule::approved(1, (1, 1, 3)),563 900564 );565 });566}567568#[test]569fn fungible_approve_and_transfer_from() {570 new_test_ext().execute_with(|| {571 default_limits();572 573 let collection_id = create_test_collection(&CollectionMode::Fungible(3), 1);574 575 let data = default_fungible_data();576 create_test_item(collection_id, &data.into());577578 let origin1 = Origin::signed(1);579 let origin2 = Origin::signed(2);580581 assert_eq!(TemplateModule::balance_count(1, 1), 5);582583 assert_ok!(TemplateModule::set_mint_permission(584 origin1.clone(),585 1,586 true587 ));588 assert_ok!(TemplateModule::set_public_access_mode(589 origin1.clone(),590 1,591 AccessMode::WhiteList592 ));593 assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), 1, 1));594 assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), 1, 2));595 assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), 1, 3));596597 // do approve598 assert_ok!(TemplateModule::approve(origin1.clone(), 2, 1, 1, 5));599 assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 5);600 assert_ok!(TemplateModule::approve(origin1.clone(), 3, 1, 1, 5));601 assert_eq!(TemplateModule::approved(1, (1, 1, 3)), 5);602 assert_eq!(603 TemplateModule::approved(1, (1, 1, 2)),604 5605 );606607 assert_ok!(TemplateModule::transfer_from(608 origin2.clone(),609 1,610 3,611 1,612 1,613 4614 ));615 assert_eq!(TemplateModule::balance_count(1, 1), 1);616 assert_eq!(TemplateModule::balance_count(1, 3), 4);617618 assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 5);619 assert_eq!(TemplateModule::approved(1, (1, 1, 3)), 1);620621 assert_ok!(TemplateModule::approve(origin1.clone(), 2, 1, 1, 5));622 assert_noop!(TemplateModule::transfer_from(623 origin2.clone(),624 1,625 3,626 1,627 1,628 4629 ), Error::<Test>::TokenValueNotEnough);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(collection_id).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, 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, 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>::TokenNotFound710 );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(3), 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, 1));735736 assert_ok!(TemplateModule::add_collection_admin(origin1.clone(), 1, 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), 1000);743744 // burn item745 assert_ok!(TemplateModule::burn_item(origin1.clone(), 1, 1, 1000));746 assert_noop!(747 TemplateModule::burn_item(origin1.clone(), 1, 1, 1000),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, 2));768 assert_ok!(TemplateModule::add_collection_admin(origin1.clone(), collection1_id, 3));769770 assert_eq!(TemplateModule::admin_list_collection(collection1_id).contains(&2), true);771 assert_eq!(TemplateModule::admin_list_collection(collection1_id).contains(&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, 2));789 assert_ok!(TemplateModule::add_collection_admin(origin1.clone(), collection1_id, 3));790791 assert_eq!(TemplateModule::admin_list_collection(1).contains(&2), true);792 assert_eq!(TemplateModule::admin_list_collection(1).contains(&3), true);793794 // remove admin795 assert_ok!(TemplateModule::remove_collection_admin(796 origin2.clone(),797 1,798 3799 ));800 assert_eq!(TemplateModule::admin_list_collection(1).contains(&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), 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), 1000);831 assert_eq!(TemplateModule::nft_item_id(nft_collection_id, 1).owner, 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).owner[0].owner, 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(), 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(), 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, 1));882 assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), 1, 2));883 assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), 1, 3));884885 assert_ok!(TemplateModule::transfer_from(886 origin2.clone(),887 1,888 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, 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, 2));928 assert_ok!(TemplateModule::add_to_white_list(origin2.clone(), collection_id, 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, 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, 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, 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, 2));988 assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), collection_id, 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, 2));1002 assert_ok!(TemplateModule::remove_from_white_list(1003 origin1.clone(),1004 collection_id,1005 21006 ));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, 2));10211022 assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), collection_id, 3));1023 assert_ok!(TemplateModule::remove_from_white_list(1024 origin2.clone(),1025 collection_id,1026 31027 ));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, 2));1042 assert_noop!(1043 TemplateModule::remove_from_white_list(origin2.clone(), collection_id, 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, 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, 2));1073 assert_ok!(TemplateModule::destroy_collection(origin1.clone(), collection_id));1074 assert_noop!(1075 TemplateModule::remove_from_white_list(origin2.clone(), collection_id, 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, 2));1092 assert_ok!(TemplateModule::remove_from_white_list(1093 origin1.clone(),1094 collection_id,1095 21096 ));1097 assert_ok!(TemplateModule::remove_from_white_list(1098 origin1.clone(),1099 collection_id,1100 21101 ));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, 2));11251126 assert_noop!(1127 TemplateModule::transfer(origin1.clone(), 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, 1));1150 assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), 1, 2));11511152 // do approve1153 assert_ok!(TemplateModule::approve(origin1.clone(), 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 11160 ));11611162 assert_noop!(1163 TemplateModule::transfer_from(origin1.clone(), 1, 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, 1));11881189 assert_noop!(1190 TemplateModule::transfer(origin1.clone(), 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, 1));1214 assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), collection_id, 2));12151216 // do approve1217 assert_ok!(TemplateModule::approve(origin1.clone(), 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 21224 ));12251226 assert_noop!(1227 TemplateModule::transfer_from(origin1.clone(), 1, 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, oken 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);1267 assert_ok!(TemplateModule::set_public_access_mode(1268 origin1.clone(),1269 collection_id,1270 AccessMode::WhiteList1271 ));12721273 // do approve1274 assert_noop!(1275 TemplateModule::approve(origin1.clone(), 1, 1, 1, 5),1276 Error::<Test>::AddresNotInWhiteList1277 );1278 });1279}12801281// If Public Access mode is set to WhiteList, tokens can be transferred from a whitelisted address with transfer or transferFrom (2 tests) and1282// tokens can be transferred from a whitelisted address with transfer or transferFrom (2 tests)1283#[test]1284fn white_list_test_7() {1285 new_test_ext().execute_with(|| {1286 default_limits();1287 1288 let collection_id = create_test_collection(&CollectionMode::NFT, 1);12891290 let data = default_nft_data();1291 create_test_item(collection_id, &data.into());1292 1293 let origin1 = Origin::signed(1);12941295 assert_ok!(TemplateModule::set_public_access_mode(1296 origin1.clone(),1297 collection_id,1298 AccessMode::WhiteList1299 ));1300 assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), collection_id, 1));1301 assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), collection_id, 2));13021303 assert_ok!(TemplateModule::transfer(origin1.clone(), 2, 1, 1, 1));1304 });1305}13061307#[test]1308fn white_list_test_8() {1309 new_test_ext().execute_with(|| {1310 default_limits();1311 1312 let collection_id = create_test_collection(&CollectionMode::NFT, 1);13131314 let data = default_nft_data();1315 create_test_item(collection_id, &data.into());1316 1317 let origin1 = Origin::signed(1);13181319 assert_ok!(TemplateModule::set_public_access_mode(1320 origin1.clone(),1321 collection_id,1322 AccessMode::WhiteList1323 ));1324 assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), collection_id, 1));1325 assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), collection_id, 2));13261327 // do approve1328 assert_ok!(TemplateModule::approve(origin1.clone(), 1, 1, 1, 5));1329 assert_eq!(TemplateModule::approved(1, (1, 1, 1)), 5);13301331 assert_ok!(TemplateModule::transfer_from(1332 origin1.clone(),1333 1,1334 2,1335 1,1336 1,1337 11338 ));1339 });1340}13411342// If Public Access mode is set to WhiteList, and Mint Permission is set to false, tokens can be created by owner.1343#[test]1344fn white_list_test_9() {1345 new_test_ext().execute_with(|| {1346 default_limits();1347 1348 let collection_id = create_test_collection(&CollectionMode::NFT, 1);1349 let origin1 = Origin::signed(1);13501351 assert_ok!(TemplateModule::set_public_access_mode(1352 origin1.clone(),1353 collection_id,1354 AccessMode::WhiteList1355 ));1356 assert_ok!(TemplateModule::set_mint_permission(1357 origin1.clone(),1358 collection_id,1359 false1360 ));13611362 let data = default_nft_data();1363 create_test_item(collection_id, &data.into());1364 });1365}13661367// If Public Access mode is set to WhiteList, and Mint Permission is set to false, tokens can be created by admin.1368#[test]1369fn white_list_test_10() {1370 new_test_ext().execute_with(|| {1371 default_limits();1372 1373 let collection_id = create_test_collection(&CollectionMode::NFT, 1);13741375 let origin1 = Origin::signed(1);1376 let origin2 = Origin::signed(2);13771378 assert_ok!(TemplateModule::set_public_access_mode(1379 origin1.clone(),1380 collection_id,1381 AccessMode::WhiteList1382 ));1383 assert_ok!(TemplateModule::set_mint_permission(1384 origin1.clone(),1385 collection_id,1386 false1387 ));13881389 assert_ok!(TemplateModule::add_collection_admin(origin1.clone(), collection_id, 2));13901391 assert_ok!(TemplateModule::create_item(1392 origin2.clone(),1393 collection_id,1394 2,1395 default_nft_data().into()1396 ));1397 });1398}13991400// 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.1401#[test]1402fn white_list_test_11() {1403 new_test_ext().execute_with(|| {1404 default_limits();1405 1406 let collection_id = create_test_collection(&CollectionMode::NFT, 1);14071408 let origin1 = Origin::signed(1);1409 let origin2 = Origin::signed(2);14101411 assert_ok!(TemplateModule::set_public_access_mode(1412 origin1.clone(),1413 collection_id,1414 AccessMode::WhiteList1415 ));1416 assert_ok!(TemplateModule::set_mint_permission(1417 origin1.clone(),1418 collection_id,1419 false1420 ));1421 assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), collection_id, 2));14221423 assert_noop!(1424 TemplateModule::create_item(origin2.clone(), 1, 2, default_nft_data().into()),1425 Error::<Test>::PublicMintingNotAllowed1426 );1427 });1428}14291430// 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.1431#[test]1432fn white_list_test_12() {1433 new_test_ext().execute_with(|| {1434 default_limits();1435 1436 let collection_id = create_test_collection(&CollectionMode::NFT, 1);14371438 let origin1 = Origin::signed(1);1439 let origin2 = Origin::signed(2);14401441 assert_ok!(TemplateModule::set_public_access_mode(1442 origin1.clone(),1443 collection_id,1444 AccessMode::WhiteList1445 ));1446 assert_ok!(TemplateModule::set_mint_permission(1447 origin1.clone(),1448 collection_id,1449 false1450 ));14511452 assert_noop!(1453 TemplateModule::create_item(origin2.clone(), 1, 2, default_nft_data().into()),1454 Error::<Test>::PublicMintingNotAllowed1455 );1456 });1457}14581459// If Public Access mode is set to WhiteList, and Mint Permission is set to true, tokens can be created by owner.1460#[test]1461fn white_list_test_13() {1462 new_test_ext().execute_with(|| {1463 default_limits();1464 1465 let collection_id = create_test_collection(&CollectionMode::NFT, 1);14661467 let origin1 = Origin::signed(1);14681469 assert_ok!(TemplateModule::set_public_access_mode(1470 origin1.clone(),1471 collection_id,1472 AccessMode::WhiteList1473 ));1474 assert_ok!(TemplateModule::set_mint_permission(1475 origin1.clone(),1476 collection_id,1477 true1478 ));14791480 let data = default_nft_data();1481 create_test_item(collection_id, &data.into());1482 });1483}14841485// If Public Access mode is set to WhiteList, and Mint Permission is set to true, tokens can be created by admin.1486#[test]1487fn white_list_test_14() {1488 new_test_ext().execute_with(|| {1489 default_limits();1490 1491 let collection_id = create_test_collection(&CollectionMode::NFT, 1);14921493 let origin1 = Origin::signed(1);1494 let origin2 = Origin::signed(2);14951496 assert_ok!(TemplateModule::set_public_access_mode(1497 origin1.clone(),1498 collection_id,1499 AccessMode::WhiteList1500 ));1501 assert_ok!(TemplateModule::set_mint_permission(1502 origin1.clone(),1503 collection_id,1504 true1505 ));15061507 assert_ok!(TemplateModule::add_collection_admin(origin1.clone(), collection_id, 2));15081509 assert_ok!(TemplateModule::create_item(1510 origin2.clone(),1511 1,1512 2,1513 default_nft_data().into()1514 ));1515 });1516}15171518// 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.1519#[test]1520fn white_list_test_15() {1521 new_test_ext().execute_with(|| {1522 default_limits();1523 1524 let collection_id = create_test_collection(&CollectionMode::NFT, 1);15251526 let origin1 = Origin::signed(1);1527 let origin2 = Origin::signed(2);15281529 assert_ok!(TemplateModule::set_public_access_mode(1530 origin1.clone(),1531 collection_id,1532 AccessMode::WhiteList1533 ));1534 assert_ok!(TemplateModule::set_mint_permission(1535 origin1.clone(),1536 collection_id,1537 true1538 ));15391540 assert_noop!(1541 TemplateModule::create_item(origin2.clone(), 1, 2, default_nft_data().into()),1542 Error::<Test>::AddresNotInWhiteList1543 );1544 });1545}15461547// 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.1548#[test]1549fn white_list_test_16() {1550 new_test_ext().execute_with(|| {1551 default_limits();1552 1553 let collection_id = create_test_collection(&CollectionMode::NFT, 1);15541555 let origin1 = Origin::signed(1);1556 let origin2 = Origin::signed(2);15571558 assert_ok!(TemplateModule::set_public_access_mode(1559 origin1.clone(),1560 collection_id,1561 AccessMode::WhiteList1562 ));1563 assert_ok!(TemplateModule::set_mint_permission(1564 origin1.clone(),1565 collection_id,1566 true1567 ));1568 assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), collection_id, 2));15691570 assert_ok!(TemplateModule::create_item(1571 origin2.clone(),1572 1,1573 2,1574 default_nft_data().into()1575 ));1576 });1577}15781579// Total number of collections. Positive test1580#[test]1581fn total_number_collections_bound() {1582 new_test_ext().execute_with(|| {1583 default_limits();1584 1585 create_test_collection(&CollectionMode::NFT, 1);1586 });1587}15881589// Total number of collections. Negotive test1590#[test]1591fn total_number_collections_bound_neg() {1592 new_test_ext().execute_with(|| {1593 default_limits();15941595 let origin1 = Origin::signed(1);15961597 for i in 0..default_collection_numbers_limit() {1598 create_test_collection(&CollectionMode::NFT, i + 1);1599 }16001601 let col_name1: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();1602 let col_desc1: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();1603 let token_prefix1: Vec<u8> = b"token_prefix1\0".to_vec();16041605 // 11-th collection in chain. Expects error1606 assert_noop!(TemplateModule::create_collection(1607 origin1.clone(),1608 col_name1.clone(),1609 col_desc1.clone(),1610 token_prefix1.clone(),1611 CollectionMode::NFT1612 ), Error::<Test>::TotalCollectionsLimitExceeded);1613 });1614}16151616// Owned tokens by a single address. Positive test1617#[test]1618fn owned_tokens_bound() {1619 new_test_ext().execute_with(|| {1620 default_limits();1621 1622 let collection_id = create_test_collection(&CollectionMode::NFT, 1);16231624 let data = default_nft_data();1625 create_test_item(collection_id, &data.clone().into());1626 create_test_item(collection_id, &data.into());1627 });1628}16291630// Owned tokens by a single address. Negotive test1631#[test]1632fn owned_tokens_bound_neg() {1633 new_test_ext().execute_with(|| {1634 assert_ok!(TemplateModule::set_chain_limits(RawOrigin::Root.into(), ChainLimits { 1635 collection_numbers_limit: 10,1636 account_token_ownership_limit: 1,1637 collections_admins_limit: 5,1638 custom_data_limit: 2048,1639 nft_sponsor_transfer_timeout: 15,1640 fungible_sponsor_transfer_timeout: 15,1641 refungible_sponsor_transfer_timeout: 15, 1642 }));1643 1644 let collection_id = create_test_collection(&CollectionMode::NFT, 1);16451646 let origin1 = Origin::signed(1);1647 let data = default_nft_data();1648 create_test_item(collection_id, &data.clone().into());16491650 assert_noop!(TemplateModule::create_item(1651 origin1.clone(),1652 1,1653 1,1654 data.into()1655 ), Error::<Test>::AddressOwnershipLimitExceeded);1656 });1657}16581659// Number of collection admins. Positive test1660#[test]1661fn collection_admins_bound() {1662 new_test_ext().execute_with(|| {1663 assert_ok!(TemplateModule::set_chain_limits(RawOrigin::Root.into(), ChainLimits { 1664 collection_numbers_limit: 10,1665 account_token_ownership_limit: 10,1666 collections_admins_limit: 2,1667 custom_data_limit: 2048,1668 nft_sponsor_transfer_timeout: 15,1669 fungible_sponsor_transfer_timeout: 15,1670 refungible_sponsor_transfer_timeout: 15, 1671 }));1672 1673 let collection_id = create_test_collection(&CollectionMode::NFT, 1);16741675 let origin1 = Origin::signed(1);1676 1677 assert_ok!(TemplateModule::add_collection_admin(origin1.clone(), collection_id, 2));1678 assert_ok!(TemplateModule::add_collection_admin(origin1.clone(), collection_id, 3));1679 });1680}16811682// Number of collection admins. Negotive test1683#[test]1684fn collection_admins_bound_neg() {1685 new_test_ext().execute_with(|| {1686 assert_ok!(TemplateModule::set_chain_limits(RawOrigin::Root.into(), ChainLimits { 1687 collection_numbers_limit: 10,1688 account_token_ownership_limit: 1,1689 collections_admins_limit: 1,1690 custom_data_limit: 2048,1691 nft_sponsor_transfer_timeout: 15,1692 fungible_sponsor_transfer_timeout: 15,1693 refungible_sponsor_transfer_timeout: 15, 1694 }));1695 1696 let collection_id = create_test_collection(&CollectionMode::NFT, 1);16971698 let origin1 = Origin::signed(1);16991700 assert_ok!(TemplateModule::add_collection_admin(origin1.clone(), collection_id, 2));1701 assert_noop!(TemplateModule::add_collection_admin(origin1.clone(), collection_id, 3), Error::<Test>::CollectionAdminsLimitExceeded);1702 });1703}17041705// NFT custom data size. Negative test const_data.1706#[test]1707fn custom_data_size_nft_const_data_bound_neg() {1708 new_test_ext().execute_with(|| {1709 assert_ok!(TemplateModule::set_chain_limits(RawOrigin::Root.into(), ChainLimits { 1710 collection_numbers_limit: 10,1711 account_token_ownership_limit: 10,1712 collections_admins_limit: 5,1713 custom_data_limit: 2,1714 nft_sponsor_transfer_timeout: 15,1715 fungible_sponsor_transfer_timeout: 15,1716 refungible_sponsor_transfer_timeout: 15, 1717 }));1718 1719 let collection_id = create_test_collection(&CollectionMode::NFT, 1);17201721 let origin1 = Origin::signed(1);1722 let too_big_const_data = CreateItemData::NFT(CreateNftData{1723 const_data: vec![1, 2, 3, 4],1724 variable_data: vec![]1725 });17261727 assert_noop!(TemplateModule::create_item(1728 origin1.clone(),1729 collection_id,1730 1,1731 too_big_const_data1732 ), Error::<Test>::TokenConstDataLimitExceeded);1733 });1734}17351736// NFT custom data size. Negative test variable_data.1737#[test]1738fn custom_data_size_nft_variable_data_bound_neg() {1739 new_test_ext().execute_with(|| {1740 assert_ok!(TemplateModule::set_chain_limits(RawOrigin::Root.into(), ChainLimits { 1741 collection_numbers_limit: 10,1742 account_token_ownership_limit: 10,1743 collections_admins_limit: 5,1744 custom_data_limit: 2,1745 nft_sponsor_transfer_timeout: 15,1746 fungible_sponsor_transfer_timeout: 15,1747 refungible_sponsor_transfer_timeout: 15, 1748 }));17491750 let collection_id = create_test_collection(&CollectionMode::NFT, 1);17511752 let origin1 = Origin::signed(1);1753 let too_big_const_data = CreateItemData::NFT(CreateNftData{1754 const_data: vec![],1755 variable_data: vec![1, 2, 3, 4]1756 });17571758 assert_noop!(TemplateModule::create_item(1759 origin1.clone(),1760 collection_id,1761 1,1762 too_big_const_data1763 ), Error::<Test>::TokenVariableDataLimitExceeded);1764 });1765}17661767// Re fungible custom data size. Negative test const_data.1768#[test]1769fn custom_data_size_re_fungible_const_data_bound_neg() {1770 new_test_ext().execute_with(|| {1771 assert_ok!(TemplateModule::set_chain_limits(RawOrigin::Root.into(), ChainLimits { 1772 collection_numbers_limit: 10,1773 account_token_ownership_limit: 10,1774 collections_admins_limit: 5,1775 custom_data_limit: 2,1776 nft_sponsor_transfer_timeout: 15,1777 fungible_sponsor_transfer_timeout: 15,1778 refungible_sponsor_transfer_timeout: 15, 1779 }));17801781 let collection_id = create_test_collection(&CollectionMode::NFT, 1);17821783 let origin1 = Origin::signed(1);1784 let too_big_const_data = CreateItemData::NFT(CreateNftData{1785 const_data: vec![1, 2, 3, 4],1786 variable_data: vec![]1787 });17881789 assert_noop!(TemplateModule::create_item(1790 origin1.clone(),1791 collection_id,1792 1,1793 too_big_const_data1794 ), Error::<Test>::TokenConstDataLimitExceeded);1795 });1796}17971798// Re fungible custom data size. Negative test variable_data.1799#[test]1800fn custom_data_size_re_fungible_variable_data_bound_neg() {1801 new_test_ext().execute_with(|| {1802 assert_ok!(TemplateModule::set_chain_limits(RawOrigin::Root.into(), ChainLimits { 1803 collection_numbers_limit: 10,1804 account_token_ownership_limit: 10,1805 collections_admins_limit: 5,1806 custom_data_limit: 2,1807 nft_sponsor_transfer_timeout: 15,1808 fungible_sponsor_transfer_timeout: 15,1809 refungible_sponsor_transfer_timeout: 15, 1810 }));18111812 let collection_id = create_test_collection(&CollectionMode::NFT, 1);18131814 let origin1 = Origin::signed(1);1815 let too_big_const_data = CreateItemData::NFT(CreateNftData{1816 const_data: vec![],1817 variable_data: vec![1, 2, 3, 4]1818 });18191820 assert_noop!(TemplateModule::create_item(1821 origin1.clone(),1822 collection_id,1823 1,1824 too_big_const_data1825 ), Error::<Test>::TokenVariableDataLimitExceeded);1826 });1827}1828// #endregion18291830#[test]1831fn set_const_on_chain_schema() {1832 new_test_ext().execute_with(|| {1833 default_limits();18341835 let collection_id = create_test_collection(&CollectionMode::NFT, 1);18361837 let origin1 = Origin::signed(1);1838 assert_ok!(TemplateModule::set_const_on_chain_schema(origin1, collection_id, b"test const on chain schema".to_vec()));18391840 assert_eq!(TemplateModule::collection(collection_id).const_on_chain_schema, b"test const on chain schema".to_vec());1841 assert_eq!(TemplateModule::collection(collection_id).variable_on_chain_schema, b"".to_vec());1842 });1843}18441845#[test]1846fn set_variable_on_chain_schema() {1847 new_test_ext().execute_with(|| {1848 default_limits();1849 1850 let collection_id = create_test_collection(&CollectionMode::NFT, 1);18511852 let origin1 = Origin::signed(1);1853 assert_ok!(TemplateModule::set_variable_on_chain_schema(origin1, collection_id, b"test variable on chain schema".to_vec()));18541855 assert_eq!(TemplateModule::collection(collection_id).const_on_chain_schema, b"".to_vec());1856 assert_eq!(TemplateModule::collection(collection_id).variable_on_chain_schema, b"test variable on chain schema".to_vec());1857 });1858}18591860#[test]1861fn set_variable_meta_data_on_nft_token_stores_variable_meta_data() {1862 new_test_ext().execute_with(|| {1863 default_limits();18641865 let collection_id = create_test_collection(&CollectionMode::NFT, 1);18661867 let origin1 = Origin::signed(1);1868 1869 let data = default_nft_data();1870 create_test_item(1, &data.into());1871 1872 let variable_data = b"test set_variable_meta_data method.".to_vec();1873 assert_ok!(TemplateModule::set_variable_meta_data(origin1, collection_id, 1, variable_data.clone()));18741875 assert_eq!(TemplateModule::nft_item_id(collection_id, 1).variable_data, variable_data);1876 });1877}18781879#[test]1880fn set_variable_meta_data_on_re_fungible_token_stores_variable_meta_data() {1881 new_test_ext().execute_with(|| {1882 default_limits();18831884 let collection_id = create_test_collection(&CollectionMode::ReFungible(3), 1);18851886 let origin1 = Origin::signed(1);18871888 let data = default_re_fungible_data();1889 create_test_item(1, &data.into());18901891 let variable_data = b"test set_variable_meta_data method.".to_vec();1892 assert_ok!(TemplateModule::set_variable_meta_data(origin1, collection_id, 1, variable_data.clone()));18931894 assert_eq!(TemplateModule::refungible_item_id(collection_id, 1).variable_data, variable_data);1895 });1896}189718981899#[test]1900fn set_variable_meta_data_on_fungible_token_fails() {1901 new_test_ext().execute_with(|| {1902 default_limits();19031904 let collection_id = create_test_collection(&CollectionMode::Fungible(3), 1);19051906 let origin1 = Origin::signed(1);19071908 let data = default_fungible_data();1909 create_test_item(1, &data.into());19101911 let variable_data = b"test set_variable_meta_data method.".to_vec();1912 assert_noop!(TemplateModule::set_variable_meta_data(origin1, collection_id, 1, variable_data.clone()), Error::<Test>::CantStoreMetadataInFungibleTokens);1913 });1914}19151916#[test]1917fn set_variable_meta_data_on_nft_token_fails_for_big_data() {1918 new_test_ext().execute_with(|| {1919 assert_ok!(TemplateModule::set_chain_limits(RawOrigin::Root.into(), ChainLimits { 1920 collection_numbers_limit: default_collection_numbers_limit(),1921 account_token_ownership_limit: 10,1922 collections_admins_limit: 5,1923 custom_data_limit: 10,1924 nft_sponsor_transfer_timeout: 15,1925 fungible_sponsor_transfer_timeout: 15,1926 refungible_sponsor_transfer_timeout: 15, 1927 }));19281929 let collection_id = create_test_collection(&CollectionMode::NFT, 1);19301931 let origin1 = Origin::signed(1);19321933 let data = default_nft_data();1934 create_test_item(1, &data.into());19351936 let variable_data = b"test set_variable_meta_data method, bigger than limits.".to_vec();1937 assert_noop!(TemplateModule::set_variable_meta_data(origin1, collection_id, 1, variable_data), Error::<Test>::TokenVariableDataLimitExceeded);1938 });1939}19401941#[test]1942fn set_variable_meta_data_on_re_fungible_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 }));195319541955 let collection_id = create_test_collection(&CollectionMode::ReFungible(3), 1);19561957 let origin1 = Origin::signed(1);19581959 let data = default_re_fungible_data();1960 create_test_item(1, &data.into());19611962 let variable_data = b"test set_variable_meta_data method, bigger than limits.".to_vec();1963 assert_noop!(TemplateModule::set_variable_meta_data(origin1, collection_id, 1, variable_data), Error::<Test>::TokenVariableDataLimitExceeded);1964 });1965}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] }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).owner, owner);59 assert_eq!(TemplateModule::collection(id).name, saved_col_name);60 assert_eq!(TemplateModule::collection(id).mode, *mode);61 assert_eq!(TemplateModule::collection(id).description, saved_description);62 assert_eq!(TemplateModule::collection(id).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(collection_id).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_re_fungible_collection_fails_with_large_decimal_numbers() {118 new_test_ext().execute_with(|| {119 default_limits();120121 let col_name1: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();122 let col_desc1: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();123 let token_prefix1: Vec<u8> = b"token_prefix1\0".to_vec();124125 let origin1 = Origin::signed(1);126 assert_noop!(TemplateModule::create_collection(127 origin1,128 col_name1,129 col_desc1,130 token_prefix1,131 CollectionMode::ReFungible(MAX_DECIMAL_POINTS + 1)132 ), Error::<Test>::CollectionDecimalPointLimitExceeded);133 });134}135136#[test]137fn create_nft_item() {138 new_test_ext().execute_with(|| {139 default_limits();140 let collection_id = create_test_collection(&CollectionMode::NFT, 1);141 142 let data = default_nft_data();143 create_test_item(collection_id, &data.clone().into());144 assert_eq!(TemplateModule::nft_item_id(collection_id, 1).const_data, data.const_data);145 assert_eq!(TemplateModule::nft_item_id(collection_id, 1).variable_data, data.variable_data);146 });147}148149// Use cases tests region150// #region151#[test]152fn create_nft_multiple_items() {153 new_test_ext().execute_with(|| {154 default_limits();155 156 create_test_collection(&CollectionMode::NFT, 1);157158 let origin1 = Origin::signed(1);159160 let items_data = vec![default_nft_data(), default_nft_data(), default_nft_data()];161162 assert_ok!(TemplateModule::create_multiple_items(163 origin1.clone(),164 1,165 1,166 items_data.clone().into_iter().map(|d| { d.into() }).collect()167 ));168 for (index, data) in items_data.iter().enumerate() {169 assert_eq!(TemplateModule::nft_item_id(1, (index + 1) as TokenId).const_data.to_vec(), data.const_data);170 assert_eq!(TemplateModule::nft_item_id(1, (index + 1) as TokenId).variable_data.to_vec(), data.variable_data);171 }172 });173}174175#[test]176fn create_refungible_item() {177 new_test_ext().execute_with(|| {178 default_limits();179 let collection_id = create_test_collection(&CollectionMode::ReFungible(3), 1);180181 let data = default_re_fungible_data();182 create_test_item(collection_id, &data.clone().into());183 assert_eq!(184 TemplateModule::refungible_item_id(collection_id, 1).const_data,185 data.const_data186 );187 assert_eq!(188 TemplateModule::refungible_item_id(collection_id, 1).variable_data,189 data.variable_data190 );191 assert_eq!(192 TemplateModule::refungible_item_id(collection_id, 1).owner[0],193 Ownership {194 owner: 1,195 fraction: 1000196 }197 );198 });199}200201#[test]202fn create_multiple_refungible_items() {203 new_test_ext().execute_with(|| {204 default_limits();205 206 create_test_collection(&CollectionMode::ReFungible(3), 1);207208 let origin1 = Origin::signed(1);209210 let items_data = vec![default_re_fungible_data(), default_re_fungible_data(), default_re_fungible_data()];211212 assert_ok!(TemplateModule::create_multiple_items(213 origin1.clone(),214 1,215 1,216 items_data.clone().into_iter().map(|d| { d.into() }).collect()217 ));218 for (index, data) in items_data.iter().enumerate() {219220 let item = TemplateModule::refungible_item_id(1, (index + 1) as TokenId);221 assert_eq!(item.const_data.to_vec(), data.const_data);222 assert_eq!(item.variable_data.to_vec(), data.variable_data);223 assert_eq!(224 item.owner[0],225 Ownership {226 owner: 1,227 fraction: 1000228 }229 );230 }231 });232}233234#[test]235fn create_fungible_item() {236 new_test_ext().execute_with(|| {237 default_limits();238 239 let collection_id = create_test_collection(&CollectionMode::Fungible(3), 1);240241 let data = default_fungible_data();242 create_test_item(collection_id, &data.into());243244 assert_eq!(TemplateModule::fungible_item_id(collection_id, 1).value, 5);245 });246}247248//#[test]249// fn create_multiple_fungible_items() {250// new_test_ext().execute_with(|| {251// default_limits();252253// create_test_collection(&CollectionMode::Fungible(3), 1);254255// let origin1 = Origin::signed(1);256257// let items_data = vec![default_fungible_data(), default_fungible_data(), default_fungible_data()];258259// assert_ok!(TemplateModule::create_multiple_items(260// origin1.clone(),261// 1,262// 1,263// items_data.clone().into_iter().map(|d| { d.into() }).collect()264// ));265 266// for (index, _) in items_data.iter().enumerate() {267// assert_eq!(TemplateModule::fungible_item_id(1, (index + 1) as TokenId).value, 5);268// }269// assert_eq!(TemplateModule::balance_count(1, 1), 3000);270// assert_eq!(TemplateModule::address_tokens(1, 1), [1, 2, 3]);271// });272// }273274#[test]275fn transfer_fungible_item() {276 new_test_ext().execute_with(|| {277 default_limits();278 279 let collection_id = create_test_collection(&CollectionMode::Fungible(3), 1);280281 let origin1 = Origin::signed(1);282 let origin2 = Origin::signed(2);283284 let data = default_fungible_data();285 create_test_item(collection_id, &data.into());286287 assert_eq!(TemplateModule::fungible_item_id(1, 1).value, 5);288 assert_eq!(TemplateModule::balance_count(1, 1), 5);289290 // change owner scenario291 assert_ok!(TemplateModule::transfer(origin1.clone(), 2, 1, 1, 5));292 assert_eq!(TemplateModule::fungible_item_id(1, 1).value, 0);293 assert_eq!(TemplateModule::balance_count(1, 1), 0);294 assert_eq!(TemplateModule::balance_count(1, 2), 5);295296 // split item scenario297 assert_ok!(TemplateModule::transfer(origin2.clone(), 3, 1, 1, 3));298 assert_eq!(TemplateModule::balance_count(1, 2), 2);299 assert_eq!(TemplateModule::balance_count(1, 3), 3);300301 // split item and new owner has account scenario302 assert_ok!(TemplateModule::transfer(origin2.clone(), 3, 1, 1, 1));303 assert_eq!(TemplateModule::fungible_item_id(1, 2).value, 1);304 assert_eq!(TemplateModule::fungible_item_id(1, 3).value, 4);305 assert_eq!(TemplateModule::balance_count(1, 2), 1);306 assert_eq!(TemplateModule::balance_count(1, 3), 4);307 });308}309310#[test]311fn transfer_refungible_item() {312 new_test_ext().execute_with(|| {313 default_limits();314 315 let collection_id = create_test_collection(&CollectionMode::ReFungible(3), 1);316317 let data = default_re_fungible_data();318 create_test_item(collection_id, &data.clone().into());319320 let origin1 = Origin::signed(1);321 let origin2 = Origin::signed(2);322 assert_eq!(323 TemplateModule::refungible_item_id(collection_id, 1).const_data,324 data.const_data325 );326 assert_eq!(327 TemplateModule::refungible_item_id(collection_id, 1).variable_data,328 data.variable_data329 );330 assert_eq!(331 TemplateModule::refungible_item_id(collection_id, 1).owner[0],332 Ownership {333 owner: 1,334 fraction: 1000335 }336 );337 assert_eq!(TemplateModule::balance_count(1, 1), 1000);338 assert_eq!(TemplateModule::address_tokens(1, 1), [1]);339340 // change owner scenario341 assert_ok!(TemplateModule::transfer(origin1.clone(), 2, 1, 1, 1000));342 assert_eq!(343 TemplateModule::refungible_item_id(1, 1).owner[0],344 Ownership {345 owner: 2,346 fraction: 1000347 }348 );349 assert_eq!(TemplateModule::balance_count(1, 1), 0);350 assert_eq!(TemplateModule::balance_count(1, 2), 1000);351 // assert_eq!(TemplateModule::address_tokens(1, 1), []);352 assert_eq!(TemplateModule::address_tokens(1, 2), [1]);353354 // split item scenario355 assert_ok!(TemplateModule::transfer(origin2.clone(), 3, 1, 1, 500));356 assert_eq!(357 TemplateModule::refungible_item_id(1, 1).owner[0],358 Ownership {359 owner: 2,360 fraction: 500361 }362 );363 assert_eq!(364 TemplateModule::refungible_item_id(1, 1).owner[1],365 Ownership {366 owner: 3,367 fraction: 500368 }369 );370 assert_eq!(TemplateModule::balance_count(1, 2), 500);371 assert_eq!(TemplateModule::balance_count(1, 3), 500);372 assert_eq!(TemplateModule::address_tokens(1, 2), [1]);373 assert_eq!(TemplateModule::address_tokens(1, 3), [1]);374375 // split item and new owner has account scenario376 assert_ok!(TemplateModule::transfer(origin2.clone(), 3, 1, 1, 200));377 assert_eq!(378 TemplateModule::refungible_item_id(1, 1).owner[0],379 Ownership {380 owner: 2,381 fraction: 300382 }383 );384 assert_eq!(385 TemplateModule::refungible_item_id(1, 1).owner[1],386 Ownership {387 owner: 3,388 fraction: 700389 }390 );391 assert_eq!(TemplateModule::balance_count(1, 2), 300);392 assert_eq!(TemplateModule::balance_count(1, 3), 700);393 assert_eq!(TemplateModule::address_tokens(1, 2), [1]);394 assert_eq!(TemplateModule::address_tokens(1, 3), [1]);395 });396}397398#[test]399fn transfer_nft_item() {400 new_test_ext().execute_with(|| {401 default_limits();402 403 let collection_id = create_test_collection(&CollectionMode::NFT, 1);404405 let data = default_nft_data();406 create_test_item(collection_id, &data.into());407 assert_eq!(TemplateModule::balance_count(1, 1), 1);408 assert_eq!(TemplateModule::address_tokens(1, 1), [1]);409410 let origin1 = Origin::signed(1);411 // default scenario412 assert_ok!(TemplateModule::transfer(origin1.clone(), 2, 1, 1, 1000));413 assert_eq!(TemplateModule::nft_item_id(1, 1).owner, 2);414 assert_eq!(TemplateModule::balance_count(1, 1), 0);415 assert_eq!(TemplateModule::balance_count(1, 2), 1);416 // assert_eq!(TemplateModule::address_tokens(1, 1), []);417 assert_eq!(TemplateModule::address_tokens(1, 2), [1]);418 });419}420421#[test]422fn nft_approve_and_transfer_from() {423 new_test_ext().execute_with(|| {424 default_limits();425 426 let collection_id = create_test_collection(&CollectionMode::NFT, 1);427428 let data = default_nft_data();429 create_test_item(collection_id, &data.into());430431 let origin1 = Origin::signed(1);432 let origin2 = Origin::signed(2);433434 assert_eq!(TemplateModule::balance_count(1, 1), 1);435 assert_eq!(TemplateModule::address_tokens(1, 1), [1]);436437 // neg transfer438 assert_noop!(TemplateModule::transfer_from(439 origin2.clone(),440 1,441 2,442 1,443 1,444 1), Error::<Test>::NoPermission);445446 // do approve447 assert_ok!(TemplateModule::approve(origin1.clone(), 2, 1, 1, 5));448 assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 5);449 assert_eq!(450 TemplateModule::approved(1, (1, 1, 2)),451 5452 );453454 assert_ok!(TemplateModule::transfer_from(455 origin2.clone(),456 1,457 2,458 1,459 1,460 1461 ));462 assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 4);463 });464}465466#[test]467fn nft_approve_and_transfer_from_white_list() {468 new_test_ext().execute_with(|| {469 default_limits();470 471 let collection_id = create_test_collection(&CollectionMode::NFT, 1);472473 let origin1 = Origin::signed(1);474 let origin2 = Origin::signed(2);475476 let data = default_nft_data();477 create_test_item(collection_id, &data.clone().into());478479 assert_eq!(TemplateModule::nft_item_id(1, 1).const_data, data.const_data);480 assert_eq!(TemplateModule::balance_count(1, 1), 1);481 assert_eq!(TemplateModule::address_tokens(1, 1), [1]);482483 assert_ok!(TemplateModule::set_mint_permission(484 origin1.clone(),485 1,486 true487 ));488 assert_ok!(TemplateModule::set_public_access_mode(489 origin1.clone(),490 1,491 AccessMode::WhiteList492 ));493 assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), 1, 1));494 assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), 1, 2));495 assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), 1, 3));496497 // do approve498 assert_ok!(TemplateModule::approve(origin1.clone(), 2, 1, 1, 5));499 assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 5);500 assert_ok!(TemplateModule::approve(origin1.clone(), 3, 1, 1, 5));501 assert_eq!(TemplateModule::approved(1, (1, 1, 3)), 5);502503 assert_ok!(TemplateModule::transfer_from(504 origin2.clone(),505 1,506 3,507 1,508 1,509 1510 ));511 assert_eq!(TemplateModule::approved(1, (1, 1, 3)), 4);512 });513}514515#[test]516fn refungible_approve_and_transfer_from() {517 new_test_ext().execute_with(|| {518 default_limits();519 520 let collection_id = create_test_collection(&CollectionMode::ReFungible(3), 1);521 522 let origin1 = Origin::signed(1);523 let origin2 = Origin::signed(2);524525 let data = default_re_fungible_data();526 create_test_item(collection_id, &data.into());527528 assert_eq!(TemplateModule::balance_count(1, 1), 1000);529 assert_eq!(TemplateModule::address_tokens(1, 1), [1]);530531 assert_ok!(TemplateModule::set_mint_permission(532 origin1.clone(),533 1,534 true535 ));536 assert_ok!(TemplateModule::set_public_access_mode(537 origin1.clone(),538 1,539 AccessMode::WhiteList540 ));541 assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), 1, 1));542 assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), 1, 2));543 assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), 1, 3));544545 // do approve546 assert_ok!(TemplateModule::approve(origin1.clone(), 2, 1, 1, 5));547 assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 5);548 assert_ok!(TemplateModule::approve(origin1.clone(), 3, 1, 1, 1000));549 assert_eq!(TemplateModule::approved(1, (1, 1, 3)), 1000);550551 assert_ok!(TemplateModule::transfer_from(552 origin2.clone(),553 1,554 3,555 1,556 1,557 100558 ));559 assert_eq!(TemplateModule::balance_count(1, 1), 900);560 assert_eq!(TemplateModule::balance_count(1, 3), 100);561 assert_eq!(TemplateModule::address_tokens(1, 1), [1]);562 assert_eq!(TemplateModule::address_tokens(1, 3), [1]);563564 assert_eq!(565 TemplateModule::approved(1, (1, 1, 3)),566 900567 );568 });569}570571#[test]572fn fungible_approve_and_transfer_from() {573 new_test_ext().execute_with(|| {574 default_limits();575 576 let collection_id = create_test_collection(&CollectionMode::Fungible(3), 1);577 578 let data = default_fungible_data();579 create_test_item(collection_id, &data.into());580581 let origin1 = Origin::signed(1);582 let origin2 = Origin::signed(2);583584 assert_eq!(TemplateModule::balance_count(1, 1), 5);585586 assert_ok!(TemplateModule::set_mint_permission(587 origin1.clone(),588 1,589 true590 ));591 assert_ok!(TemplateModule::set_public_access_mode(592 origin1.clone(),593 1,594 AccessMode::WhiteList595 ));596 assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), 1, 1));597 assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), 1, 2));598 assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), 1, 3));599600 // do approve601 assert_ok!(TemplateModule::approve(origin1.clone(), 2, 1, 1, 5));602 assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 5);603 assert_ok!(TemplateModule::approve(origin1.clone(), 3, 1, 1, 5));604 assert_eq!(TemplateModule::approved(1, (1, 1, 3)), 5);605 assert_eq!(606 TemplateModule::approved(1, (1, 1, 2)),607 5608 );609610 assert_ok!(TemplateModule::transfer_from(611 origin2.clone(),612 1,613 3,614 1,615 1,616 4617 ));618 assert_eq!(TemplateModule::balance_count(1, 1), 1);619 assert_eq!(TemplateModule::balance_count(1, 3), 4);620621 assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 5);622 assert_eq!(TemplateModule::approved(1, (1, 1, 3)), 1);623624 assert_ok!(TemplateModule::approve(origin1.clone(), 2, 1, 1, 5));625 assert_noop!(TemplateModule::transfer_from(626 origin2.clone(),627 1,628 3,629 1,630 1,631 4632 ), Error::<Test>::TokenValueNotEnough);633 });634}635636#[test]637fn change_collection_owner() {638 new_test_ext().execute_with(|| {639 default_limits();640 641 let collection_id = create_test_collection(&CollectionMode::NFT, 1);642 643 let origin1 = Origin::signed(1);644 assert_ok!(TemplateModule::change_collection_owner(645 origin1.clone(),646 collection_id,647 2648 ));649 assert_eq!(TemplateModule::collection(collection_id).owner, 2);650 });651}652653#[test]654fn destroy_collection() {655 new_test_ext().execute_with(|| {656 default_limits();657 658 let collection_id = create_test_collection(&CollectionMode::NFT, 1);659 660 let origin1 = Origin::signed(1);661 assert_ok!(TemplateModule::destroy_collection(origin1.clone(), collection_id));662 });663}664665#[test]666fn burn_nft_item() {667 new_test_ext().execute_with(|| {668 default_limits();669 670 let collection_id = create_test_collection(&CollectionMode::NFT, 1);671672 let origin1 = Origin::signed(1);673 assert_ok!(TemplateModule::add_collection_admin(origin1.clone(), collection_id, 2));674 675 let data = default_nft_data();676 create_test_item(collection_id, &data.into());677678 // check balance (collection with id = 1, user id = 1)679 assert_eq!(TemplateModule::balance_count(1, 1), 1);680681 // burn item682 assert_ok!(TemplateModule::burn_item(origin1.clone(), 1, 1, 5));683 assert_noop!(684 TemplateModule::burn_item(origin1.clone(), 1, 1, 5),685 Error::<Test>::TokenNotFound686 );687688 assert_eq!(TemplateModule::balance_count(1, 1), 0);689 });690}691692#[test]693fn burn_fungible_item() {694 new_test_ext().execute_with(|| {695 default_limits();696 697 let collection_id = create_test_collection(&CollectionMode::Fungible(3), 1);698 699 let origin1 = Origin::signed(1);700 assert_ok!(TemplateModule::add_collection_admin(origin1.clone(), collection_id, 2));701 702 let data = default_fungible_data();703 create_test_item(collection_id, &data.into());704705 // check balance (collection with id = 1, user id = 1)706 assert_eq!(TemplateModule::balance_count(1, 1), 5);707708 // burn item709 assert_ok!(TemplateModule::burn_item(origin1.clone(), 1, 1, 5));710 assert_noop!(711 TemplateModule::burn_item(origin1.clone(), 1, 1, 5),712 Error::<Test>::TokenNotFound713 );714715 assert_eq!(TemplateModule::balance_count(1, 1), 0);716 });717}718719#[test]720fn burn_refungible_item() {721 new_test_ext().execute_with(|| {722 default_limits();723 724 let collection_id = create_test_collection(&CollectionMode::ReFungible(3), 1);725 let origin1 = Origin::signed(1);726727 assert_ok!(TemplateModule::set_mint_permission(728 origin1.clone(),729 collection_id,730 true731 ));732 assert_ok!(TemplateModule::set_public_access_mode(733 origin1.clone(),734 collection_id,735 AccessMode::WhiteList736 ));737 assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), 1, 1));738739 assert_ok!(TemplateModule::add_collection_admin(origin1.clone(), 1, 2));740 741 let data = default_re_fungible_data();742 create_test_item(collection_id, &data.into());743744 // check balance (collection with id = 1, user id = 2)745 assert_eq!(TemplateModule::balance_count(1, 1), 1000);746747 // burn item748 assert_ok!(TemplateModule::burn_item(origin1.clone(), 1, 1, 1000));749 assert_noop!(750 TemplateModule::burn_item(origin1.clone(), 1, 1, 1000),751 Error::<Test>::TokenNotFound752 );753754 assert_eq!(TemplateModule::balance_count(1, 1), 0);755 });756}757758#[test]759fn add_collection_admin() {760 new_test_ext().execute_with(|| {761 default_limits();762 763 let collection1_id = create_test_collection_for_owner(&CollectionMode::NFT, 1, 1);764 create_test_collection_for_owner(&CollectionMode::NFT, 2, 2);765 create_test_collection_for_owner(&CollectionMode::NFT, 3, 3);766 767 let origin1 = Origin::signed(1);768769 // collection admin770 assert_ok!(TemplateModule::add_collection_admin(origin1.clone(), collection1_id, 2));771 assert_ok!(TemplateModule::add_collection_admin(origin1.clone(), collection1_id, 3));772773 assert_eq!(TemplateModule::admin_list_collection(collection1_id).contains(&2), true);774 assert_eq!(TemplateModule::admin_list_collection(collection1_id).contains(&3), true);775 });776}777778#[test]779fn remove_collection_admin() {780 new_test_ext().execute_with(|| {781 default_limits();782 783 let collection1_id = create_test_collection_for_owner(&CollectionMode::NFT, 1, 1);784 create_test_collection_for_owner(&CollectionMode::NFT, 2, 2);785 create_test_collection_for_owner(&CollectionMode::NFT, 3, 3);786787 let origin1 = Origin::signed(1);788 let origin2 = Origin::signed(2);789790 // collection admin791 assert_ok!(TemplateModule::add_collection_admin(origin1.clone(), collection1_id, 2));792 assert_ok!(TemplateModule::add_collection_admin(origin1.clone(), collection1_id, 3));793794 assert_eq!(TemplateModule::admin_list_collection(1).contains(&2), true);795 assert_eq!(TemplateModule::admin_list_collection(1).contains(&3), true);796797 // remove admin798 assert_ok!(TemplateModule::remove_collection_admin(799 origin2.clone(),800 1,801 3802 ));803 assert_eq!(TemplateModule::admin_list_collection(1).contains(&3), false);804 });805}806807#[test]808fn balance_of() {809 new_test_ext().execute_with(|| {810 default_limits();811 812 let nft_collection_id = create_test_collection(&CollectionMode::NFT, 1);813 let fungible_collection_id = create_test_collection(&CollectionMode::Fungible(3), 2);814 let re_fungible_collection_id = create_test_collection(&CollectionMode::ReFungible(3), 3);815 816 // check balance before817 assert_eq!(TemplateModule::balance_count(nft_collection_id, 1), 0);818 assert_eq!(TemplateModule::balance_count(fungible_collection_id, 1), 0);819 assert_eq!(TemplateModule::balance_count(re_fungible_collection_id, 1), 0);820821 let nft_data = default_nft_data();822 create_test_item(nft_collection_id, &nft_data.into());823 824 let fungible_data = default_fungible_data();825 create_test_item(fungible_collection_id, &fungible_data.into());826 827 let re_fungible_data = default_re_fungible_data();828 create_test_item(re_fungible_collection_id, &re_fungible_data.into());829830 // check balance (collection with id = 1, user id = 1)831 assert_eq!(TemplateModule::balance_count(nft_collection_id, 1), 1);832 assert_eq!(TemplateModule::balance_count(fungible_collection_id, 1), 5);833 assert_eq!(TemplateModule::balance_count(re_fungible_collection_id, 1), 1000);834 assert_eq!(TemplateModule::nft_item_id(nft_collection_id, 1).owner, 1);835 assert_eq!(TemplateModule::fungible_item_id(fungible_collection_id, 1).value, 5);836 assert_eq!(TemplateModule::refungible_item_id(re_fungible_collection_id, 1).owner[0].owner, 1);837 });838}839840#[test]841fn approve() {842 new_test_ext().execute_with(|| {843 default_limits();844 845 let collection_id = create_test_collection(&CollectionMode::NFT, 1);846 847 let data = default_nft_data();848 create_test_item(collection_id, &data.into());849850 let origin1 = Origin::signed(1);851 852 // approve853 assert_ok!(TemplateModule::approve(origin1.clone(), 2, 1, 1, 1));854 assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 1);855 });856}857858#[test]859fn transfer_from() {860 new_test_ext().execute_with(|| {861 default_limits();862 863 let collection_id = create_test_collection(&CollectionMode::NFT, 1);864 let origin1 = Origin::signed(1);865 let origin2 = Origin::signed(2);866867 let data = default_nft_data();868 create_test_item(collection_id, &data.into());869870 // approve871 assert_ok!(TemplateModule::approve(origin1.clone(), 2, 1, 1, 1));872 assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 1);873874 assert_ok!(TemplateModule::set_mint_permission(875 origin1.clone(),876 1,877 true878 ));879 assert_ok!(TemplateModule::set_public_access_mode(880 origin1.clone(),881 1,882 AccessMode::WhiteList883 ));884 assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), 1, 1));885 assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), 1, 2));886 assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), 1, 3));887888 assert_ok!(TemplateModule::transfer_from(889 origin2.clone(),890 1,891 2,892 1,893 1,894 1895 ));896897 // after transfer898 assert_eq!(TemplateModule::balance_count(1, 1), 0);899 assert_eq!(TemplateModule::balance_count(1, 2), 1);900 });901}902903// #endregion904905// Coverage tests region906// #region907908#[test]909fn owner_can_add_address_to_white_list() {910 new_test_ext().execute_with(|| {911 default_limits();912 913 let collection_id = create_test_collection(&CollectionMode::NFT, 1);914915 let origin1 = Origin::signed(1);916 assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), collection_id, 2));917 assert_eq!(TemplateModule::white_list(collection_id, 2), true);918 });919}920921#[test]922fn admin_can_add_address_to_white_list() {923 new_test_ext().execute_with(|| {924 default_limits();925 926 let collection_id = create_test_collection(&CollectionMode::NFT, 1);927 let origin1 = Origin::signed(1);928 let origin2 = Origin::signed(2);929930 assert_ok!(TemplateModule::add_collection_admin(origin1.clone(), collection_id, 2));931 assert_ok!(TemplateModule::add_to_white_list(origin2.clone(), collection_id, 3));932 assert_eq!(TemplateModule::white_list(collection_id, 3), true);933 });934}935936#[test]937fn nonprivileged_user_cannot_add_address_to_white_list() {938 new_test_ext().execute_with(|| {939 default_limits();940 941 let collection_id = create_test_collection(&CollectionMode::NFT, 1);942943 let origin2 = Origin::signed(2);944 assert_noop!(945 TemplateModule::add_to_white_list(origin2.clone(), collection_id, 3),946 Error::<Test>::NoPermission947 );948 });949}950951#[test]952fn nobody_can_add_address_to_white_list_of_nonexisting_collection() {953 new_test_ext().execute_with(|| {954 default_limits();955956 let origin1 = Origin::signed(1);957958 assert_noop!(959 TemplateModule::add_to_white_list(origin1.clone(), 1, 2),960 Error::<Test>::CollectionNotFound961 );962 });963}964965#[test]966fn nobody_can_add_address_to_white_list_of_deleted_collection() {967 new_test_ext().execute_with(|| {968 default_limits();969 970 let collection_id = create_test_collection(&CollectionMode::NFT, 1);971972 let origin1 = Origin::signed(1);973 assert_ok!(TemplateModule::destroy_collection(origin1.clone(), collection_id));974 assert_noop!(975 TemplateModule::add_to_white_list(origin1.clone(), collection_id, 2),976 Error::<Test>::CollectionNotFound977 );978 });979}980981// If address is already added to white list, nothing happens982#[test]983fn address_is_already_added_to_white_list() {984 new_test_ext().execute_with(|| {985 default_limits();986 987 let collection_id = create_test_collection(&CollectionMode::NFT, 1);988 let origin1 = Origin::signed(1);989 990 assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), collection_id, 2));991 assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), collection_id, 2));992 assert_eq!(TemplateModule::white_list(collection_id, 2), true);993 });994}995996#[test]997fn owner_can_remove_address_from_white_list() {998 new_test_ext().execute_with(|| {999 default_limits();1000 1001 let collection_id = create_test_collection(&CollectionMode::NFT, 1);10021003 let origin1 = Origin::signed(1);1004 assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), collection_id, 2));1005 assert_ok!(TemplateModule::remove_from_white_list(1006 origin1.clone(),1007 collection_id,1008 21009 ));1010 assert_eq!(TemplateModule::white_list(collection_id, 2), false);1011 });1012}10131014#[test]1015fn admin_can_remove_address_from_white_list() {1016 new_test_ext().execute_with(|| {1017 default_limits();1018 1019 let collection_id = create_test_collection(&CollectionMode::NFT, 1);1020 let origin1 = Origin::signed(1);1021 let origin2 = Origin::signed(2);10221023 assert_ok!(TemplateModule::add_collection_admin(origin1.clone(), collection_id, 2));10241025 assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), collection_id, 3));1026 assert_ok!(TemplateModule::remove_from_white_list(1027 origin2.clone(),1028 collection_id,1029 31030 ));1031 assert_eq!(TemplateModule::white_list(collection_id, 3), false);1032 });1033}10341035#[test]1036fn nonprivileged_user_cannot_remove_address_from_white_list() {1037 new_test_ext().execute_with(|| {1038 default_limits();1039 1040 let collection_id = create_test_collection(&CollectionMode::NFT, 1);1041 let origin1 = Origin::signed(1);1042 let origin2 = Origin::signed(2);10431044 assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), collection_id, 2));1045 assert_noop!(1046 TemplateModule::remove_from_white_list(origin2.clone(), collection_id, 2),1047 Error::<Test>::NoPermission1048 );1049 assert_eq!(TemplateModule::white_list(collection_id, 2), true);1050 });1051}10521053#[test]1054fn nobody_can_remove_address_from_white_list_of_nonexisting_collection() {1055 new_test_ext().execute_with(|| {1056 default_limits();1057 let origin1 = Origin::signed(1);10581059 assert_noop!(1060 TemplateModule::remove_from_white_list(origin1.clone(), 1, 2),1061 Error::<Test>::CollectionNotFound1062 );1063 });1064}10651066#[test]1067fn nobody_can_remove_address_from_white_list_of_deleted_collection() {1068 new_test_ext().execute_with(|| {1069 default_limits();1070 1071 let collection_id = create_test_collection(&CollectionMode::NFT, 1);1072 let origin1 = Origin::signed(1);1073 let origin2 = Origin::signed(2);10741075 assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), collection_id, 2));1076 assert_ok!(TemplateModule::destroy_collection(origin1.clone(), collection_id));1077 assert_noop!(1078 TemplateModule::remove_from_white_list(origin2.clone(), collection_id, 2),1079 Error::<Test>::CollectionNotFound1080 );1081 assert_eq!(TemplateModule::white_list(collection_id, 2), false);1082 });1083}10841085// If address is already removed from white list, nothing happens1086#[test]1087fn address_is_already_removed_from_white_list() {1088 new_test_ext().execute_with(|| {1089 default_limits();1090 1091 let collection_id = create_test_collection(&CollectionMode::NFT, 1);1092 let origin1 = Origin::signed(1);10931094 assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), collection_id, 2));1095 assert_ok!(TemplateModule::remove_from_white_list(1096 origin1.clone(),1097 collection_id,1098 21099 ));1100 assert_ok!(TemplateModule::remove_from_white_list(1101 origin1.clone(),1102 collection_id,1103 21104 ));1105 assert_eq!(TemplateModule::white_list(collection_id, 2), false);1106 });1107}11081109// If Public Access mode is set to WhiteList, tokens can’t be transferred from a non-whitelisted address with transfer or transferFrom (2 tests)1110#[test]1111fn white_list_test_1() {1112 new_test_ext().execute_with(|| {1113 default_limits();1114 1115 let collection_id = create_test_collection(&CollectionMode::NFT, 1);11161117 let origin1 = Origin::signed(1);1118 1119 let data = default_nft_data();1120 create_test_item(collection_id, &data.into());11211122 assert_ok!(TemplateModule::set_public_access_mode(1123 origin1.clone(),1124 collection_id,1125 AccessMode::WhiteList1126 ));1127 assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), collection_id, 2));11281129 assert_noop!(1130 TemplateModule::transfer(origin1.clone(), 3, 1, 1, 1),1131 Error::<Test>::AddresNotInWhiteList1132 );1133 });1134}11351136#[test]1137fn white_list_test_2() {1138 new_test_ext().execute_with(|| {1139 default_limits();1140 1141 let collection_id = create_test_collection(&CollectionMode::NFT, 1);1142 let origin1 = Origin::signed(1);1143 1144 let data = default_nft_data();1145 create_test_item(collection_id, &data.into());11461147 assert_ok!(TemplateModule::set_public_access_mode(1148 origin1.clone(),1149 collection_id,1150 AccessMode::WhiteList1151 ));1152 assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), 1, 1));1153 assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), 1, 2));11541155 // do approve1156 assert_ok!(TemplateModule::approve(origin1.clone(), 1, 1, 1, 1));1157 assert_eq!(TemplateModule::approved(1, (1, 1, 1)), 1);11581159 assert_ok!(TemplateModule::remove_from_white_list(1160 origin1.clone(),1161 1,1162 11163 ));11641165 assert_noop!(1166 TemplateModule::transfer_from(origin1.clone(), 1, 3, 1, 1, 1),1167 Error::<Test>::AddresNotInWhiteList1168 );1169 });1170}11711172// If Public Access mode is set to WhiteList, tokens can’t be transferred to a non-whitelisted address with transfer or transferFrom (2 tests)1173#[test]1174fn white_list_test_3() {1175 new_test_ext().execute_with(|| {1176 default_limits();1177 1178 let collection_id = create_test_collection(&CollectionMode::NFT, 1);11791180 let origin1 = Origin::signed(1);1181 1182 let data = default_nft_data();1183 create_test_item(collection_id, &data.into());11841185 assert_ok!(TemplateModule::set_public_access_mode(1186 origin1.clone(),1187 collection_id,1188 AccessMode::WhiteList1189 ));1190 assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), 1, 1));11911192 assert_noop!(1193 TemplateModule::transfer(origin1.clone(), 3, 1, 1, 1),1194 Error::<Test>::AddresNotInWhiteList1195 );1196 });1197}11981199#[test]1200fn white_list_test_4() {1201 new_test_ext().execute_with(|| {1202 default_limits();1203 1204 let collection_id = create_test_collection(&CollectionMode::NFT, 1);12051206 let origin1 = Origin::signed(1);12071208 let data = default_nft_data();1209 create_test_item(collection_id, &data.into());12101211 assert_ok!(TemplateModule::set_public_access_mode(1212 origin1.clone(),1213 collection_id,1214 AccessMode::WhiteList1215 ));1216 assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), collection_id, 1));1217 assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), collection_id, 2));12181219 // do approve1220 assert_ok!(TemplateModule::approve(origin1.clone(), 1, 1, 1, 1));1221 assert_eq!(TemplateModule::approved(1, (1, 1, 1)), 1);12221223 assert_ok!(TemplateModule::remove_from_white_list(1224 origin1.clone(),1225 collection_id,1226 21227 ));12281229 assert_noop!(1230 TemplateModule::transfer_from(origin1.clone(), 1, 3, 1, 1, 1),1231 Error::<Test>::AddresNotInWhiteList1232 );1233 });1234}12351236// 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)1237#[test]1238fn white_list_test_5() {1239 new_test_ext().execute_with(|| {1240 default_limits();1241 1242 let collection_id = create_test_collection(&CollectionMode::NFT, 1);12431244 let origin1 = Origin::signed(1);12451246 let data = default_nft_data();1247 create_test_item(collection_id, &data.into());12481249 assert_ok!(TemplateModule::set_public_access_mode(1250 origin1.clone(),1251 collection_id,1252 AccessMode::WhiteList1253 ));1254 assert_noop!(1255 TemplateModule::burn_item(origin1.clone(), 1, 1, 5),1256 Error::<Test>::AddresNotInWhiteList1257 );1258 });1259}12601261// If Public Access mode is set to WhiteList, token transfers can’t be Approved by a non-whitelisted address (see Approve method).1262#[test]1263fn white_list_test_6() {1264 new_test_ext().execute_with(|| {1265 default_limits();1266 1267 let collection_id = create_test_collection(&CollectionMode::NFT, 1);12681269 let origin1 = Origin::signed(1);12701271 let data = default_nft_data();1272 create_test_item(collection_id, &data.into());12731274 assert_ok!(TemplateModule::set_public_access_mode(1275 origin1.clone(),1276 collection_id,1277 AccessMode::WhiteList1278 ));12791280 // do approve1281 assert_noop!(1282 TemplateModule::approve(origin1.clone(), 1, 1, 1, 5),1283 Error::<Test>::AddresNotInWhiteList1284 );1285 });1286}12871288// If Public Access mode is set to WhiteList, tokens can be transferred from a whitelisted address with transfer or transferFrom (2 tests) and1289// tokens can be transferred from a whitelisted address with transfer or transferFrom (2 tests)1290#[test]1291fn white_list_test_7() {1292 new_test_ext().execute_with(|| {1293 default_limits();1294 1295 let collection_id = create_test_collection(&CollectionMode::NFT, 1);12961297 let data = default_nft_data();1298 create_test_item(collection_id, &data.into());1299 1300 let origin1 = Origin::signed(1);13011302 assert_ok!(TemplateModule::set_public_access_mode(1303 origin1.clone(),1304 collection_id,1305 AccessMode::WhiteList1306 ));1307 assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), collection_id, 1));1308 assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), collection_id, 2));13091310 assert_ok!(TemplateModule::transfer(origin1.clone(), 2, 1, 1, 1));1311 });1312}13131314#[test]1315fn white_list_test_8() {1316 new_test_ext().execute_with(|| {1317 default_limits();1318 1319 let collection_id = create_test_collection(&CollectionMode::NFT, 1);13201321 let data = default_nft_data();1322 create_test_item(collection_id, &data.into());1323 1324 let origin1 = Origin::signed(1);13251326 assert_ok!(TemplateModule::set_public_access_mode(1327 origin1.clone(),1328 collection_id,1329 AccessMode::WhiteList1330 ));1331 assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), collection_id, 1));1332 assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), collection_id, 2));13331334 // do approve1335 assert_ok!(TemplateModule::approve(origin1.clone(), 1, 1, 1, 5));1336 assert_eq!(TemplateModule::approved(1, (1, 1, 1)), 5);13371338 assert_ok!(TemplateModule::transfer_from(1339 origin1.clone(),1340 1,1341 2,1342 1,1343 1,1344 11345 ));1346 });1347}13481349// If Public Access mode is set to WhiteList, and Mint Permission is set to false, tokens can be created by owner.1350#[test]1351fn white_list_test_9() {1352 new_test_ext().execute_with(|| {1353 default_limits();1354 1355 let collection_id = create_test_collection(&CollectionMode::NFT, 1);1356 let origin1 = Origin::signed(1);13571358 assert_ok!(TemplateModule::set_public_access_mode(1359 origin1.clone(),1360 collection_id,1361 AccessMode::WhiteList1362 ));1363 assert_ok!(TemplateModule::set_mint_permission(1364 origin1.clone(),1365 collection_id,1366 false1367 ));13681369 let data = default_nft_data();1370 create_test_item(collection_id, &data.into());1371 });1372}13731374// If Public Access mode is set to WhiteList, and Mint Permission is set to false, tokens can be created by admin.1375#[test]1376fn white_list_test_10() {1377 new_test_ext().execute_with(|| {1378 default_limits();1379 1380 let collection_id = create_test_collection(&CollectionMode::NFT, 1);13811382 let origin1 = Origin::signed(1);1383 let origin2 = Origin::signed(2);13841385 assert_ok!(TemplateModule::set_public_access_mode(1386 origin1.clone(),1387 collection_id,1388 AccessMode::WhiteList1389 ));1390 assert_ok!(TemplateModule::set_mint_permission(1391 origin1.clone(),1392 collection_id,1393 false1394 ));13951396 assert_ok!(TemplateModule::add_collection_admin(origin1.clone(), collection_id, 2));13971398 assert_ok!(TemplateModule::create_item(1399 origin2.clone(),1400 collection_id,1401 2,1402 default_nft_data().into()1403 ));1404 });1405}14061407// 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.1408#[test]1409fn white_list_test_11() {1410 new_test_ext().execute_with(|| {1411 default_limits();1412 1413 let collection_id = create_test_collection(&CollectionMode::NFT, 1);14141415 let origin1 = Origin::signed(1);1416 let origin2 = Origin::signed(2);14171418 assert_ok!(TemplateModule::set_public_access_mode(1419 origin1.clone(),1420 collection_id,1421 AccessMode::WhiteList1422 ));1423 assert_ok!(TemplateModule::set_mint_permission(1424 origin1.clone(),1425 collection_id,1426 false1427 ));1428 assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), collection_id, 2));14291430 assert_noop!(1431 TemplateModule::create_item(origin2.clone(), 1, 2, default_nft_data().into()),1432 Error::<Test>::PublicMintingNotAllowed1433 );1434 });1435}14361437// 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.1438#[test]1439fn white_list_test_12() {1440 new_test_ext().execute_with(|| {1441 default_limits();1442 1443 let collection_id = create_test_collection(&CollectionMode::NFT, 1);14441445 let origin1 = Origin::signed(1);1446 let origin2 = Origin::signed(2);14471448 assert_ok!(TemplateModule::set_public_access_mode(1449 origin1.clone(),1450 collection_id,1451 AccessMode::WhiteList1452 ));1453 assert_ok!(TemplateModule::set_mint_permission(1454 origin1.clone(),1455 collection_id,1456 false1457 ));14581459 assert_noop!(1460 TemplateModule::create_item(origin2.clone(), 1, 2, default_nft_data().into()),1461 Error::<Test>::PublicMintingNotAllowed1462 );1463 });1464}14651466// If Public Access mode is set to WhiteList, and Mint Permission is set to true, tokens can be created by owner.1467#[test]1468fn white_list_test_13() {1469 new_test_ext().execute_with(|| {1470 default_limits();1471 1472 let collection_id = create_test_collection(&CollectionMode::NFT, 1);14731474 let origin1 = Origin::signed(1);14751476 assert_ok!(TemplateModule::set_public_access_mode(1477 origin1.clone(),1478 collection_id,1479 AccessMode::WhiteList1480 ));1481 assert_ok!(TemplateModule::set_mint_permission(1482 origin1.clone(),1483 collection_id,1484 true1485 ));14861487 let data = default_nft_data();1488 create_test_item(collection_id, &data.into());1489 });1490}14911492// If Public Access mode is set to WhiteList, and Mint Permission is set to true, tokens can be created by admin.1493#[test]1494fn white_list_test_14() {1495 new_test_ext().execute_with(|| {1496 default_limits();1497 1498 let collection_id = create_test_collection(&CollectionMode::NFT, 1);14991500 let origin1 = Origin::signed(1);1501 let origin2 = Origin::signed(2);15021503 assert_ok!(TemplateModule::set_public_access_mode(1504 origin1.clone(),1505 collection_id,1506 AccessMode::WhiteList1507 ));1508 assert_ok!(TemplateModule::set_mint_permission(1509 origin1.clone(),1510 collection_id,1511 true1512 ));15131514 assert_ok!(TemplateModule::add_collection_admin(origin1.clone(), collection_id, 2));15151516 assert_ok!(TemplateModule::create_item(1517 origin2.clone(),1518 1,1519 2,1520 default_nft_data().into()1521 ));1522 });1523}15241525// 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.1526#[test]1527fn white_list_test_15() {1528 new_test_ext().execute_with(|| {1529 default_limits();1530 1531 let collection_id = create_test_collection(&CollectionMode::NFT, 1);15321533 let origin1 = Origin::signed(1);1534 let origin2 = Origin::signed(2);15351536 assert_ok!(TemplateModule::set_public_access_mode(1537 origin1.clone(),1538 collection_id,1539 AccessMode::WhiteList1540 ));1541 assert_ok!(TemplateModule::set_mint_permission(1542 origin1.clone(),1543 collection_id,1544 true1545 ));15461547 assert_noop!(1548 TemplateModule::create_item(origin2.clone(), 1, 2, default_nft_data().into()),1549 Error::<Test>::AddresNotInWhiteList1550 );1551 });1552}15531554// 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.1555#[test]1556fn white_list_test_16() {1557 new_test_ext().execute_with(|| {1558 default_limits();1559 1560 let collection_id = create_test_collection(&CollectionMode::NFT, 1);15611562 let origin1 = Origin::signed(1);1563 let origin2 = Origin::signed(2);15641565 assert_ok!(TemplateModule::set_public_access_mode(1566 origin1.clone(),1567 collection_id,1568 AccessMode::WhiteList1569 ));1570 assert_ok!(TemplateModule::set_mint_permission(1571 origin1.clone(),1572 collection_id,1573 true1574 ));1575 assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), collection_id, 2));15761577 assert_ok!(TemplateModule::create_item(1578 origin2.clone(),1579 1,1580 2,1581 default_nft_data().into()1582 ));1583 });1584}15851586// Total number of collections. Positive test1587#[test]1588fn total_number_collections_bound() {1589 new_test_ext().execute_with(|| {1590 default_limits();1591 1592 create_test_collection(&CollectionMode::NFT, 1);1593 });1594}15951596// Total number of collections. Negotive test1597#[test]1598fn total_number_collections_bound_neg() {1599 new_test_ext().execute_with(|| {1600 default_limits();16011602 let origin1 = Origin::signed(1);16031604 for i in 0..default_collection_numbers_limit() {1605 create_test_collection(&CollectionMode::NFT, i + 1);1606 }16071608 let col_name1: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();1609 let col_desc1: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();1610 let token_prefix1: Vec<u8> = b"token_prefix1\0".to_vec();16111612 // 11-th collection in chain. Expects error1613 assert_noop!(TemplateModule::create_collection(1614 origin1.clone(),1615 col_name1.clone(),1616 col_desc1.clone(),1617 token_prefix1.clone(),1618 CollectionMode::NFT1619 ), Error::<Test>::TotalCollectionsLimitExceeded);1620 });1621}16221623// Owned tokens by a single address. Positive test1624#[test]1625fn owned_tokens_bound() {1626 new_test_ext().execute_with(|| {1627 default_limits();1628 1629 let collection_id = create_test_collection(&CollectionMode::NFT, 1);16301631 let data = default_nft_data();1632 create_test_item(collection_id, &data.clone().into());1633 create_test_item(collection_id, &data.into());1634 });1635}16361637// Owned tokens by a single address. Negotive test1638#[test]1639fn owned_tokens_bound_neg() {1640 new_test_ext().execute_with(|| {1641 assert_ok!(TemplateModule::set_chain_limits(RawOrigin::Root.into(), ChainLimits { 1642 collection_numbers_limit: 10,1643 account_token_ownership_limit: 1,1644 collections_admins_limit: 5,1645 custom_data_limit: 2048,1646 nft_sponsor_transfer_timeout: 15,1647 fungible_sponsor_transfer_timeout: 15,1648 refungible_sponsor_transfer_timeout: 15,1649 const_on_chain_schema_limit: 1024,1650 offchain_schema_limit: 1024,1651 variable_on_chain_schema_limit: 1024,1652 }));1653 1654 let collection_id = create_test_collection(&CollectionMode::NFT, 1);16551656 let origin1 = Origin::signed(1);1657 let data = default_nft_data();1658 create_test_item(collection_id, &data.clone().into());16591660 assert_noop!(TemplateModule::create_item(1661 origin1.clone(),1662 1,1663 1,1664 data.into()1665 ), Error::<Test>::AddressOwnershipLimitExceeded);1666 });1667}16681669// Number of collection admins. Positive test1670#[test]1671fn collection_admins_bound() {1672 new_test_ext().execute_with(|| {1673 assert_ok!(TemplateModule::set_chain_limits(RawOrigin::Root.into(), ChainLimits { 1674 collection_numbers_limit: 10,1675 account_token_ownership_limit: 10,1676 collections_admins_limit: 2,1677 custom_data_limit: 2048,1678 nft_sponsor_transfer_timeout: 15,1679 fungible_sponsor_transfer_timeout: 15,1680 refungible_sponsor_transfer_timeout: 15,1681 const_on_chain_schema_limit: 1024,1682 offchain_schema_limit: 1024,1683 variable_on_chain_schema_limit: 1024,1684 }));1685 1686 let collection_id = create_test_collection(&CollectionMode::NFT, 1);16871688 let origin1 = Origin::signed(1);1689 1690 assert_ok!(TemplateModule::add_collection_admin(origin1.clone(), collection_id, 2));1691 assert_ok!(TemplateModule::add_collection_admin(origin1.clone(), collection_id, 3));1692 });1693}16941695// Number of collection admins. Negotive test1696#[test]1697fn collection_admins_bound_neg() {1698 new_test_ext().execute_with(|| {1699 assert_ok!(TemplateModule::set_chain_limits(RawOrigin::Root.into(), ChainLimits { 1700 collection_numbers_limit: 10,1701 account_token_ownership_limit: 1,1702 collections_admins_limit: 1,1703 custom_data_limit: 2048,1704 nft_sponsor_transfer_timeout: 15,1705 fungible_sponsor_transfer_timeout: 15,1706 refungible_sponsor_transfer_timeout: 15,1707 const_on_chain_schema_limit: 1024,1708 offchain_schema_limit: 1024,1709 variable_on_chain_schema_limit: 1024,1710 }));1711 1712 let collection_id = create_test_collection(&CollectionMode::NFT, 1);17131714 let origin1 = Origin::signed(1);17151716 assert_ok!(TemplateModule::add_collection_admin(origin1.clone(), collection_id, 2));1717 assert_noop!(TemplateModule::add_collection_admin(origin1.clone(), collection_id, 3), Error::<Test>::CollectionAdminsLimitExceeded);1718 });1719}17201721// NFT custom data size. Negative test const_data.1722#[test]1723fn custom_data_size_nft_const_data_bound_neg() {1724 new_test_ext().execute_with(|| {1725 assert_ok!(TemplateModule::set_chain_limits(RawOrigin::Root.into(), ChainLimits { 1726 collection_numbers_limit: 10,1727 account_token_ownership_limit: 10,1728 collections_admins_limit: 5,1729 custom_data_limit: 2,1730 nft_sponsor_transfer_timeout: 15,1731 fungible_sponsor_transfer_timeout: 15,1732 refungible_sponsor_transfer_timeout: 15,1733 const_on_chain_schema_limit: 1024,1734 offchain_schema_limit: 1024,1735 variable_on_chain_schema_limit: 1024,1736 }));1737 1738 let collection_id = create_test_collection(&CollectionMode::NFT, 1);17391740 let origin1 = Origin::signed(1);1741 let too_big_const_data = CreateItemData::NFT(CreateNftData{1742 const_data: vec![1, 2, 3, 4],1743 variable_data: vec![]1744 });17451746 assert_noop!(TemplateModule::create_item(1747 origin1.clone(),1748 collection_id,1749 1,1750 too_big_const_data1751 ), Error::<Test>::TokenConstDataLimitExceeded);1752 });1753}17541755// NFT custom data size. Negative test variable_data.1756#[test]1757fn custom_data_size_nft_variable_data_bound_neg() {1758 new_test_ext().execute_with(|| {1759 assert_ok!(TemplateModule::set_chain_limits(RawOrigin::Root.into(), ChainLimits { 1760 collection_numbers_limit: 10,1761 account_token_ownership_limit: 10,1762 collections_admins_limit: 5,1763 custom_data_limit: 2,1764 nft_sponsor_transfer_timeout: 15,1765 fungible_sponsor_transfer_timeout: 15,1766 refungible_sponsor_transfer_timeout: 15,1767 const_on_chain_schema_limit: 1024,1768 offchain_schema_limit: 1024,1769 variable_on_chain_schema_limit: 1024,1770 }));17711772 let collection_id = create_test_collection(&CollectionMode::NFT, 1);17731774 let origin1 = Origin::signed(1);1775 let too_big_const_data = CreateItemData::NFT(CreateNftData{1776 const_data: vec![],1777 variable_data: vec![1, 2, 3, 4]1778 });17791780 assert_noop!(TemplateModule::create_item(1781 origin1.clone(),1782 collection_id,1783 1,1784 too_big_const_data1785 ), Error::<Test>::TokenVariableDataLimitExceeded);1786 });1787}17881789// Re fungible custom data size. Negative test const_data.1790#[test]1791fn custom_data_size_re_fungible_const_data_bound_neg() {1792 new_test_ext().execute_with(|| {1793 assert_ok!(TemplateModule::set_chain_limits(RawOrigin::Root.into(), ChainLimits { 1794 collection_numbers_limit: 10,1795 account_token_ownership_limit: 10,1796 collections_admins_limit: 5,1797 custom_data_limit: 2,1798 nft_sponsor_transfer_timeout: 15,1799 fungible_sponsor_transfer_timeout: 15,1800 refungible_sponsor_transfer_timeout: 15,1801 const_on_chain_schema_limit: 1024,1802 offchain_schema_limit: 1024,1803 variable_on_chain_schema_limit: 1024,1804 }));18051806 let collection_id = create_test_collection(&CollectionMode::NFT, 1);18071808 let origin1 = Origin::signed(1);1809 let too_big_const_data = CreateItemData::NFT(CreateNftData{1810 const_data: vec![1, 2, 3, 4],1811 variable_data: vec![]1812 });18131814 assert_noop!(TemplateModule::create_item(1815 origin1.clone(),1816 collection_id,1817 1,1818 too_big_const_data1819 ), Error::<Test>::TokenConstDataLimitExceeded);1820 });1821}18221823// Re fungible custom data size. Negative test variable_data.1824#[test]1825fn custom_data_size_re_fungible_variable_data_bound_neg() {1826 new_test_ext().execute_with(|| {1827 assert_ok!(TemplateModule::set_chain_limits(RawOrigin::Root.into(), ChainLimits { 1828 collection_numbers_limit: 10,1829 account_token_ownership_limit: 10,1830 collections_admins_limit: 5,1831 custom_data_limit: 2,1832 nft_sponsor_transfer_timeout: 15,1833 fungible_sponsor_transfer_timeout: 15,1834 refungible_sponsor_transfer_timeout: 15,1835 const_on_chain_schema_limit: 1024,1836 offchain_schema_limit: 1024,1837 variable_on_chain_schema_limit: 1024,1838 }));18391840 let collection_id = create_test_collection(&CollectionMode::NFT, 1);18411842 let origin1 = Origin::signed(1);1843 let too_big_const_data = CreateItemData::NFT(CreateNftData{1844 const_data: vec![],1845 variable_data: vec![1, 2, 3, 4]1846 });18471848 assert_noop!(TemplateModule::create_item(1849 origin1.clone(),1850 collection_id,1851 1,1852 too_big_const_data1853 ), Error::<Test>::TokenVariableDataLimitExceeded);1854 });1855}1856// #endregion18571858#[test]1859fn set_const_on_chain_schema() {1860 new_test_ext().execute_with(|| {1861 default_limits();18621863 let collection_id = create_test_collection(&CollectionMode::NFT, 1);18641865 let origin1 = Origin::signed(1);1866 assert_ok!(TemplateModule::set_const_on_chain_schema(origin1, collection_id, b"test const on chain schema".to_vec()));18671868 assert_eq!(TemplateModule::collection(collection_id).const_on_chain_schema, b"test const on chain schema".to_vec());1869 assert_eq!(TemplateModule::collection(collection_id).variable_on_chain_schema, b"".to_vec());1870 });1871}18721873#[test]1874fn set_variable_on_chain_schema() {1875 new_test_ext().execute_with(|| {1876 default_limits();1877 1878 let collection_id = create_test_collection(&CollectionMode::NFT, 1);18791880 let origin1 = Origin::signed(1);1881 assert_ok!(TemplateModule::set_variable_on_chain_schema(origin1, collection_id, b"test variable on chain schema".to_vec()));18821883 assert_eq!(TemplateModule::collection(collection_id).const_on_chain_schema, b"".to_vec());1884 assert_eq!(TemplateModule::collection(collection_id).variable_on_chain_schema, b"test variable on chain schema".to_vec());1885 });1886}18871888#[test]1889fn set_variable_meta_data_on_nft_token_stores_variable_meta_data() {1890 new_test_ext().execute_with(|| {1891 default_limits();18921893 let collection_id = create_test_collection(&CollectionMode::NFT, 1);18941895 let origin1 = Origin::signed(1);1896 1897 let data = default_nft_data();1898 create_test_item(1, &data.into());1899 1900 let variable_data = b"test set_variable_meta_data method.".to_vec();1901 assert_ok!(TemplateModule::set_variable_meta_data(origin1, collection_id, 1, variable_data.clone()));19021903 assert_eq!(TemplateModule::nft_item_id(collection_id, 1).variable_data, variable_data);1904 });1905}19061907#[test]1908fn set_variable_meta_data_on_re_fungible_token_stores_variable_meta_data() {1909 new_test_ext().execute_with(|| {1910 default_limits();19111912 let collection_id = create_test_collection(&CollectionMode::ReFungible(3), 1);19131914 let origin1 = Origin::signed(1);19151916 let data = default_re_fungible_data();1917 create_test_item(1, &data.into());19181919 let variable_data = b"test set_variable_meta_data method.".to_vec();1920 assert_ok!(TemplateModule::set_variable_meta_data(origin1, collection_id, 1, variable_data.clone()));19211922 assert_eq!(TemplateModule::refungible_item_id(collection_id, 1).variable_data, variable_data);1923 });1924}192519261927#[test]1928fn set_variable_meta_data_on_fungible_token_fails() {1929 new_test_ext().execute_with(|| {1930 default_limits();19311932 let collection_id = create_test_collection(&CollectionMode::Fungible(3), 1);19331934 let origin1 = Origin::signed(1);19351936 let data = default_fungible_data();1937 create_test_item(1, &data.into());19381939 let variable_data = b"test set_variable_meta_data method.".to_vec();1940 assert_noop!(TemplateModule::set_variable_meta_data(origin1, collection_id, 1, variable_data.clone()), Error::<Test>::CantStoreMetadataInFungibleTokens);1941 });1942}19431944#[test]1945fn set_variable_meta_data_on_nft_token_fails_for_big_data() {1946 new_test_ext().execute_with(|| {1947 assert_ok!(TemplateModule::set_chain_limits(RawOrigin::Root.into(), ChainLimits { 1948 collection_numbers_limit: default_collection_numbers_limit(),1949 account_token_ownership_limit: 10,1950 collections_admins_limit: 5,1951 custom_data_limit: 10,1952 nft_sponsor_transfer_timeout: 15,1953 fungible_sponsor_transfer_timeout: 15,1954 refungible_sponsor_transfer_timeout: 15,1955 const_on_chain_schema_limit: 1024,1956 offchain_schema_limit: 1024,1957 variable_on_chain_schema_limit: 1024,1958 }));19591960 let collection_id = create_test_collection(&CollectionMode::NFT, 1);19611962 let origin1 = Origin::signed(1);19631964 let data = default_nft_data();1965 create_test_item(1, &data.into());19661967 let variable_data = b"test set_variable_meta_data method, bigger than limits.".to_vec();1968 assert_noop!(TemplateModule::set_variable_meta_data(origin1, collection_id, 1, variable_data), Error::<Test>::TokenVariableDataLimitExceeded);1969 });1970}19711972#[test]1973fn set_variable_meta_data_on_re_fungible_token_fails_for_big_data() {1974 new_test_ext().execute_with(|| {1975 assert_ok!(TemplateModule::set_chain_limits(RawOrigin::Root.into(), ChainLimits { 1976 collection_numbers_limit: default_collection_numbers_limit(),1977 account_token_ownership_limit: 10,1978 collections_admins_limit: 5,1979 custom_data_limit: 10,1980 nft_sponsor_transfer_timeout: 15,1981 fungible_sponsor_transfer_timeout: 15,1982 refungible_sponsor_transfer_timeout: 15,1983 const_on_chain_schema_limit: 1024,1984 offchain_schema_limit: 1024,1985 variable_on_chain_schema_limit: 1024,1986 }));198719881989 let collection_id = create_test_collection(&CollectionMode::ReFungible(3), 1);19901991 let origin1 = Origin::signed(1);19921993 let data = default_re_fungible_data();1994 create_test_item(1, &data.into());19951996 let variable_data = b"test set_variable_meta_data method, bigger than limits.".to_vec();1997 assert_noop!(TemplateModule::set_variable_meta_data(origin1, collection_id, 1, variable_data), Error::<Test>::TokenVariableDataLimitExceeded);1998 });1999}tests/package.jsondiffbeforeafterboth--- a/tests/package.json
+++ b/tests/package.json
@@ -29,7 +29,8 @@
"testCreateCollection": "mocha --timeout 9999999 -r ts-node/register ./**/createCollection.test.ts",
"testToggleContractWhiteList": "mocha --timeout 9999999 -r ts-node/register ./**/toggleContractWhiteList.test.ts",
"testAddToContractWhiteList": "mocha --timeout 9999999 -r ts-node/register ./**/addToContractWhiteList.test.ts",
- "testTransfer": "mocha --timeout 9999999 -r ts-node/register ./**/transfer.test.ts"
+ "testTransfer": "mocha --timeout 9999999 -r ts-node/register ./**/transfer.test.ts",
+ "testBurnItem": "mocha --timeout 9999999 -r ts-node/register ./**/burnItem.test.ts"
},
"author": "",
"license": "Apache 2.0",
tests/src/addToWhiteList.test.tsdiffbeforeafterboth--- a/tests/src/addToWhiteList.test.ts
+++ b/tests/src/addToWhiteList.test.ts
@@ -18,7 +18,7 @@
let Alice: IKeyringPair;
let Bob: IKeyringPair;
-describe.only('Integration Test ext. addToWhiteList()', () => {
+describe('Integration Test ext. addToWhiteList()', () => {
before(async () => {
await usingApi(async (api) => {
@@ -41,7 +41,7 @@
});
});
-describe.only('Negative Integration Test ext. addToWhiteList()', () => {
+describe('Negative Integration Test ext. addToWhiteList()', () => {
it('White list an address in the collection that does not exist', async () => {
await usingApi(async (api) => {