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

difftreelog

Merge pull request #135 from usetech-llc/feature/NFTPAR-299_storage_option_refactor

Greg Zaitsev2021-03-22parents: #c09c218 #39dc916.patch.diff
in: master
Optional collections related review

11 files changed

modifiedpallets/nft/src/lib.rsdiffbeforeafterboth
199 }199 }
200}200}
201201
202#[derive(Encode, Decode, Default, Debug, Clone, PartialEq)]202#[derive(Encode, Decode, Debug, Clone, PartialEq)]
203#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]203#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
204pub struct NftItemType<AccountId> {204pub struct NftItemType<AccountId> {
205 pub owner: AccountId,205 pub owner: AccountId,
213 pub value: u128,213 pub value: u128,
214}214}
215215
216#[derive(Encode, Decode, Default, Debug, Clone, PartialEq)]216#[derive(Encode, Decode, Debug, Clone, PartialEq)]
217#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]217#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
218pub struct ReFungibleItemType<AccountId> {218pub struct ReFungibleItemType<AccountId> {
219 pub owner: Vec<Ownership<AccountId>>,219 pub owner: Vec<Ownership<AccountId>>,
537537
538 /// Amount of items which spender can transfer out of owners account (via transferFrom)538 /// Amount of items which spender can transfer out of owners account (via transferFrom)
539 /// Collection id (controlled?2), (token id (controlled ?2) + owner account id (real) + spender account id (controlled?3))539 /// Collection id (controlled?2), (token id (controlled ?2) + owner account id (real) + spender account id (controlled?3))
540 /// TODO: Off chain worker should remove from this map when token gets removed
540 pub Allowances get(fn approved): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) (TokenId, T::AccountId, T::AccountId) => u128;541 pub Allowances get(fn approved): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) (TokenId, T::AccountId, T::AccountId) => u128;
541542
542 //#region Item collections543 //#region Item collections
543 /// Collection id (controlled?2), token id (controlled?1)544 /// Collection id (controlled?2), token id (controlled?1)
544 pub NftItemList get(fn nft_item_id) config(): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId => NftItemType<T::AccountId>;545 pub NftItemList get(fn nft_item_id) config(): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId => Option<NftItemType<T::AccountId>>;
545 /// Collection id (controlled?2), owner (controlled?2)546 /// Collection id (controlled?2), owner (controlled?2)
546 pub FungibleItemList get(fn fungible_item_id) config(): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) T::AccountId => FungibleItemType;547 pub FungibleItemList get(fn fungible_item_id) config(): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) T::AccountId => FungibleItemType;
547 /// Collection id (controlled?2), token id (controlled?1)548 /// Collection id (controlled?2), token id (controlled?1)
548 pub ReFungibleItemList get(fn refungible_item_id) config(): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId => ReFungibleItemType<T::AccountId>;549 pub ReFungibleItemList get(fn refungible_item_id) config(): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId => Option<ReFungibleItemType<T::AccountId>>;
549 //#endregion550 //#endregion
550551
551 //#region Index list552 //#region Index list
555556
556 //#region Tokens transfer rate limit baskets557 //#region Tokens transfer rate limit baskets
557 /// (Collection id (controlled?2), who created (real))558 /// (Collection id (controlled?2), who created (real))
559 /// TODO: Off chain worker should remove from this map when collection gets removed
558 pub CreateItemBasket get(fn create_item_basket): map hasher(blake2_128_concat) (CollectionId, T::AccountId) => T::BlockNumber;560 pub CreateItemBasket get(fn create_item_basket): map hasher(blake2_128_concat) (CollectionId, T::AccountId) => T::BlockNumber;
559 /// Collection id (controlled?2), token id (controlled?2)561 /// Collection id (controlled?2), token id (controlled?2)
560 pub NftTransferBasket get(fn nft_transfer_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId => T::BlockNumber;562 pub NftTransferBasket get(fn nft_transfer_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId => T::BlockNumber;
570 572
571 //#region Contract Sponsorship and Ownership573 //#region Contract Sponsorship and Ownership
572 /// Contract address (real)574 /// Contract address (real)
573 pub ContractOwner get(fn contract_owner): map hasher(twox_64_concat) T::AccountId => T::AccountId;575 pub ContractOwner get(fn contract_owner): map hasher(twox_64_concat) T::AccountId => Option<T::AccountId>;
574 /// Contract address (real)576 /// Contract address (real)
575 pub ContractSelfSponsoring get(fn contract_self_sponsoring): map hasher(twox_64_concat) T::AccountId => bool;577 pub ContractSelfSponsoring get(fn contract_self_sponsoring): map hasher(twox_64_concat) T::AccountId => bool;
576 /// (Contract address(real), caller (real))578 /// (Contract address(real), caller (real))
968 let sender = ensure_signed(origin)?;970 let sender = ensure_signed(origin)?;
969 let collection = Self::get_collection(collection_id)?;971 let collection = Self::get_collection(collection_id)?;
970 Self::check_owner_or_admin_permissions(&collection, sender)?;972 Self::check_owner_or_admin_permissions(&collection, sender)?;
971 let mut admin_arr: Vec<T::AccountId> = Vec::new();973 let mut admin_arr = <AdminList<T>>::get(collection_id);
972974
973 if <AdminList<T>>::contains_key(collection_id)975 match admin_arr.binary_search(&new_admin_id) {
974 {976 Ok(_) => {},
975 admin_arr = <AdminList<T>>::get(collection_id);977 Err(idx) => {
978 let limits = ChainLimit::get();
976 ensure!(!admin_arr.contains(&new_admin_id), Error::<T>::AlreadyAdmin);979 ensure!(admin_arr.len() < limits.collections_admins_limit as usize, Error::<T>::CollectionAdminsLimitExceeded);
980 admin_arr.insert(idx, new_admin_id);
981 <AdminList<T>>::insert(collection_id, admin_arr);
982 }
977 }983 }
978
979 // Number of collection admins
980 ensure!((admin_arr.len() as u64) < ChainLimit::get().collections_admins_limit, Error::<T>::CollectionAdminsLimitExceeded);
981
982 admin_arr.push(new_admin_id);
983 <AdminList<T>>::insert(collection_id, admin_arr);
984
985 Ok(())984 Ok(())
986 }985 }
987986
1004 let sender = ensure_signed(origin)?;1003 let sender = ensure_signed(origin)?;
1005 let collection = Self::get_collection(collection_id)?;1004 let collection = Self::get_collection(collection_id)?;
1006 Self::check_owner_or_admin_permissions(&collection, sender)?;1005 Self::check_owner_or_admin_permissions(&collection, sender)?;
1007 ensure!(<AdminList<T>>::contains_key(collection_id), Error::<T>::AdminNotFound);
1008
1009 let mut admin_arr = <AdminList<T>>::get(collection_id);1006 let mut admin_arr = <AdminList<T>>::get(collection_id);
1010 admin_arr.retain(|i| *i != account_id);
1011 <AdminList<T>>::insert(collection_id, admin_arr);
10121007
1008 match admin_arr.binary_search(&account_id) {
1009 Ok(idx) => {
1010 admin_arr.remove(idx);
1011 <AdminList<T>>::insert(collection_id, admin_arr);
1012 },
1013 Err(_) => {}
1014 }
1013 Ok(())1015 Ok(())
1014 }1016 }
10151017
1267 let sender = ensure_signed(origin)?;1269 let sender = ensure_signed(origin)?;
1268 let target_collection = Self::get_collection(collection_id)?;1270 let target_collection = Self::get_collection(collection_id)?;
12691271
1270 Self::token_exists(&target_collection, item_id, &sender)?;1272 Self::token_exists(&target_collection, item_id)?;
12711273
1272 // Transfer permissions check1274 // Transfer permissions check
1273 let bypasses_limits = target_collection.limits.owner_can_transfer &&1275 let bypasses_limits = target_collection.limits.owner_can_transfer &&
1419 let sender = ensure_signed(origin)?;1421 let sender = ensure_signed(origin)?;
1420 1422
1421 let target_collection = Self::get_collection(collection_id)?;1423 let target_collection = Self::get_collection(collection_id)?;
1422 Self::token_exists(&target_collection, item_id, &sender)?;1424 Self::token_exists(&target_collection, item_id)?;
14231425
1424 ensure!(ChainLimit::get().custom_data_limit >= data.len() as u32, Error::<T>::TokenVariableDataLimitExceeded);1426 ensure!(ChainLimit::get().custom_data_limit >= data.len() as u32, Error::<T>::TokenVariableDataLimitExceeded);
14251427
1668 <ContractOwner<T>>::insert(contract_address.clone(), sender.clone());1670 <ContractOwner<T>>::insert(contract_address.clone(), sender.clone());
16691671
1670 Self::ensure_contract_owned(sender, &contract_address)?;1672 Self::ensure_contract_owned(sender, &contract_address)?;
1671 <ContractWhiteListEnabled<T>>::insert(contract_address, enable);1673 if enable {
1674 <ContractWhiteListEnabled<T>>::insert(contract_address, true);
1675 } else {
1676 <ContractWhiteListEnabled<T>>::remove(contract_address);
1677 }
1672 Ok(())1678 Ok(())
1673 }1679 }
1674 1680
1901 let collection_id = collection.id;1907 let collection_id = collection.id;
19021908
1903 // Does new owner already have an account?1909 // Does new owner already have an account?
1904 let mut balance: u128 = 0;1910 let balance: u128 = <FungibleItemList<T>>::get(collection_id, owner).value;
1905 if <FungibleItemList<T>>::contains_key(collection_id, owner) {
1906 balance = <FungibleItemList<T>>::get(collection_id, owner).value;
1907 }
19081911
1909 // Mint 1912 // Mint
1910 let item = FungibleItemType {1913 let item = FungibleItemType {
1911 value: balance + value1914 value: balance.checked_add(value).ok_or(Error::<T>::NumOverflow)?,
1912 };1915 };
1913 <FungibleItemList<T>>::insert(collection_id, (*owner).clone(), item);1916 <FungibleItemList<T>>::insert(collection_id, (*owner).clone(), item);
19141917
1984 ) -> DispatchResult {1987 ) -> DispatchResult {
1985 let collection_id = collection.id;1988 let collection_id = collection.id;
19861989
1987 ensure!(1990 let mut token = <ReFungibleItemList<T>>::get(collection_id, item_id)
1988 <ReFungibleItemList<T>>::contains_key(collection_id, item_id),
1989 Error::<T>::TokenNotFound1991 .ok_or(Error::<T>::TokenNotFound)?;
1990 );
1991 let mut token = <ReFungibleItemList<T>>::get(collection_id, item_id);
1992 let rft_balance = token1992 let rft_balance = token
1993 .owner1993 .owner
1994 .iter()1994 .iter()
2026 fn burn_nft_item(collection: &CollectionHandle<T>, item_id: TokenId) -> DispatchResult {2026 fn burn_nft_item(collection: &CollectionHandle<T>, item_id: TokenId) -> DispatchResult {
2027 let collection_id = collection.id;2027 let collection_id = collection.id;
20282028
2029 ensure!(2029 let item = <NftItemList<T>>::get(collection_id, item_id)
2030 <NftItemList<T>>::contains_key(collection_id, item_id),
2031 Error::<T>::TokenNotFound2030 .ok_or(Error::<T>::TokenNotFound)?;
2032 );
2033 let item = <NftItemList<T>>::get(collection_id, item_id);
2034 Self::remove_token_index(collection_id, item_id, &item.owner)?;2031 Self::remove_token_index(collection_id, item_id, &item.owner)?;
20352032
2036 // update balance2033 // update balance
2047 fn burn_fungible_item(owner: &T::AccountId, collection: &CollectionHandle<T>, value: u128) -> DispatchResult {2044 fn burn_fungible_item(owner: &T::AccountId, collection: &CollectionHandle<T>, value: u128) -> DispatchResult {
2048 let collection_id = collection.id;2045 let collection_id = collection.id;
20492046
2050 ensure!(
2051 <FungibleItemList<T>>::contains_key(collection_id, owner),
2052 Error::<T>::TokenNotFound
2053 );
2054 let mut balance = <FungibleItemList<T>>::get(collection_id, owner);2047 let mut balance = <FungibleItemList<T>>::get(collection_id, owner);
2055 ensure!(balance.value >= value, Error::<T>::TokenValueNotEnough);2048 ensure!(balance.value >= value, Error::<T>::TokenValueNotEnough);
20562049
2094 }2087 }
20952088
2096 fn is_owner_or_admin_permissions(collection: &CollectionHandle<T>, subject: T::AccountId) -> bool {2089 fn is_owner_or_admin_permissions(collection: &CollectionHandle<T>, subject: T::AccountId) -> bool {
2097 let mut result: bool = subject == collection.owner;2090 subject == collection.owner || <AdminList<T>>::get(collection.id).contains(&subject)
2098 let exists = <AdminList<T>>::contains_key(collection.id);
2099
2100 if !result & exists {
2101 if <AdminList<T>>::get(collection.id).contains(&subject) {
2102 result = true
2103 }
2104 }
2105
2106 result
2107 }2091 }
21082092
2109 fn check_owner_or_admin_permissions(2093 fn check_owner_or_admin_permissions(
2110 collection: &CollectionHandle<T>,2094 collection: &CollectionHandle<T>,
2111 subject: T::AccountId,2095 subject: T::AccountId,
2112 ) -> DispatchResult {2096 ) -> DispatchResult {
2113 let result = Self::is_owner_or_admin_permissions(collection, subject.clone());2097 ensure!(Self::is_owner_or_admin_permissions(collection, subject), Error::<T>::NoPermission);
21142098
2115 ensure!(
2116 result,
2117 Error::<T>::NoPermission
2118 );
2119 Ok(())2099 Ok(())
2120 }2100 }
21212101
2127 let collection_id = target_collection.id;2107 let collection_id = target_collection.id;
21282108
2129 match target_collection.mode {2109 match target_collection.mode {
2130 CollectionMode::NFT => {2110 CollectionMode::NFT => (<NftItemList<T>>::get(collection_id, item_id)?.owner == subject)
2131 if <NftItemList<T>>::get(collection_id, item_id).owner == subject {
2132 return Some(1)2111 .then(|| 1),
2133 }
2134 None
2135 },
2136 CollectionMode::Fungible(_) => {2112 CollectionMode::Fungible(_) => Some(<FungibleItemList<T>>::get(collection_id, &subject)
2137 if <FungibleItemList<T>>::contains_key(collection_id, &subject) {
2138 return Some(<FungibleItemList<T>>::get(collection_id, &subject)
2139 .value);2113 .value),
2140 }
2141 None
2142 },
2143 CollectionMode::ReFungible => <ReFungibleItemList<T>>::get(collection_id, item_id)2114 CollectionMode::ReFungible => <ReFungibleItemList<T>>::get(collection_id, item_id)?
2144 .owner2115 .owner
2145 .iter()2116 .iter()
2146 .find(|i| i.owner == subject)2117 .find(|i| i.owner == subject)
2150 }2121 }
21512122
2152 fn is_item_owner(subject: T::AccountId, target_collection: &CollectionHandle<T>, item_id: TokenId) -> bool {2123 fn is_item_owner(subject: T::AccountId, target_collection: &CollectionHandle<T>, item_id: TokenId) -> bool {
2153 let collection_id = target_collection.id;
2154
2155 match target_collection.mode {2124 match target_collection.mode {
2156 CollectionMode::NFT => {2125 CollectionMode::Fungible(_) => true,
2157 <NftItemList<T>>::get(collection_id, item_id).owner == subject
2158 }
2159 CollectionMode::Fungible(_) => {
2160 <FungibleItemList<T>>::contains_key(collection_id, &subject)
2161 }2126 _ => Self::owned_amount(subject, target_collection, item_id).is_some(),
2162 CollectionMode::ReFungible => {
2163 <ReFungibleItemList<T>>::get(collection_id, item_id)
2164 .owner
2165 .iter()
2166 .any(|i| i.owner == subject)
2167 }
2168 CollectionMode::Invalid => false,
2169 }2127 }
2170 }2128 }
21712129
2183 fn token_exists(2141 fn token_exists(
2184 target_collection: &CollectionHandle<T>,2142 target_collection: &CollectionHandle<T>,
2185 item_id: TokenId,2143 item_id: TokenId,
2186 owner: &T::AccountId
2187 ) -> DispatchResult {2144 ) -> DispatchResult {
2188 let collection_id = target_collection.id;2145 let collection_id = target_collection.id;
2189 let exists = match target_collection.mode2146 let exists = match target_collection.mode
2190 {2147 {
2191 CollectionMode::NFT => <NftItemList<T>>::contains_key(collection_id, item_id),2148 CollectionMode::NFT => <NftItemList<T>>::contains_key(collection_id, item_id),
2192 CollectionMode::Fungible(_) => <FungibleItemList<T>>::contains_key(collection_id, owner),2149 CollectionMode::Fungible(_) => true,
2193 CollectionMode::ReFungible => <ReFungibleItemList<T>>::contains_key(collection_id, item_id),2150 CollectionMode::ReFungible => <ReFungibleItemList<T>>::contains_key(collection_id, item_id),
2194 _ => false2151 _ => false
2195 };2152 };
2205 recipient: &T::AccountId,2162 recipient: &T::AccountId,
2206 ) -> DispatchResult {2163 ) -> DispatchResult {
2207 let collection_id = collection.id;2164 let collection_id = collection.id;
2208 Self::token_exists(&collection, 0, owner)?;
22092165
2210 let mut balance = <FungibleItemList<T>>::get(collection_id, owner);2166 let mut balance = <FungibleItemList<T>>::get(collection_id, owner);
2211 ensure!(balance.value >= value, Error::<T>::TokenValueTooLow);2167 ensure!(balance.value >= value, Error::<T>::TokenValueTooLow);
2236 new_owner: T::AccountId,2192 new_owner: T::AccountId,
2237 ) -> DispatchResult {2193 ) -> DispatchResult {
2238 let collection_id = collection.id;2194 let collection_id = collection.id;
2239 Self::token_exists(collection, item_id, &owner)?;2195 let full_item = <ReFungibleItemList<T>>::get(collection_id, item_id)
2196 .ok_or(Error::<T>::TokenNotFound)?;
22402197
2241 let full_item = <ReFungibleItemList<T>>::get(collection_id, item_id);
2242 let item = full_item2198 let item = full_item
2243 .owner2199 .owner
2244 .iter()2200 .iter()
2318 new_owner: T::AccountId,2274 new_owner: T::AccountId,
2319 ) -> DispatchResult {2275 ) -> DispatchResult {
2320 let collection_id = collection.id;2276 let collection_id = collection.id;
2321 Self::token_exists(&collection, item_id, &sender)?;2277 let mut item = <NftItemList<T>>::get(collection_id, item_id)
2278 .ok_or(Error::<T>::TokenNotFound)?;
23222279
2323 let mut item = <NftItemList<T>>::get(collection_id, item_id);
2324
2325 ensure!(2280 ensure!(
2326 sender == item.owner,2281 sender == item.owner,
2327 Error::<T>::MustBeTokenOwner2282 Error::<T>::MustBeTokenOwner
2355 data: Vec<u8>2310 data: Vec<u8>
2356 ) -> DispatchResult {2311 ) -> DispatchResult {
2357 let collection_id = collection.id;2312 let collection_id = collection.id;
2358 let mut item = <ReFungibleItemList<T>>::get(collection_id, item_id);2313 let mut item = <ReFungibleItemList<T>>::get(collection_id, item_id)
2314 .ok_or(Error::<T>::TokenNotFound)?;
23592315
2360 item.variable_data = data;2316 item.variable_data = data;
23612317
2370 data: Vec<u8>2326 data: Vec<u8>
2371 ) -> DispatchResult {2327 ) -> DispatchResult {
2372 let collection_id = collection.id;2328 let collection_id = collection.id;
2373 let mut item = <NftItemList<T>>::get(collection_id, item_id);2329 let mut item = <NftItemList<T>>::get(collection_id, item_id)
2330 .ok_or(Error::<T>::TokenNotFound)?;
2374 2331
2375 item.variable_data = data;2332 item.variable_data = data;
23762333
2533 }2490 }
2534 2491
2535 fn ensure_contract_owned(account: T::AccountId, contract: &T::AccountId) -> DispatchResult {2492 fn ensure_contract_owned(account: T::AccountId, contract: &T::AccountId) -> DispatchResult {
2536 if <ContractOwner<T>>::contains_key(contract.clone()) {2493 ensure!(<ContractOwner<T>>::get(contract) == Some(account), Error::<T>::NoPermission);
2537 let owner = <ContractOwner<T>>::get(contract);
2538 ensure!(account == owner, Error::<T>::NoPermission);
2539 } else {
2540 fail!(Error::<T>::NoPermission);
2541 }
25422494
2543 Ok(())2495 Ok(())
2544 }2496 }
27872739
2788 let called_contract: T::AccountId = T::Lookup::lookup((*dest).clone()).unwrap_or(T::AccountId::default());2740 let called_contract: T::AccountId = T::Lookup::lookup((*dest).clone()).unwrap_or(T::AccountId::default());
27892741
2790 let owned_contract = <ContractOwner<T>>::contains_key(called_contract.clone())2742 let owned_contract = <ContractOwner<T>>::get(called_contract.clone()).as_ref() == Some(who);
2791 && <ContractOwner<T>>::get(called_contract.clone()) == *who;
2792 let white_list_enabled = <ContractWhiteListEnabled<T>>::contains_key(called_contract.clone()) && <ContractWhiteListEnabled<T>>::get(called_contract.clone());2743 let white_list_enabled = <ContractWhiteListEnabled<T>>::contains_key(called_contract.clone());
2793 2744
2794 if !owned_contract && white_list_enabled {2745 if !owned_contract && white_list_enabled {
2795 if !<ContractWhiteList<T>>::contains_key(called_contract.clone(), who) {2746 if !<ContractWhiteList<T>>::contains_key(called_contract.clone(), who) {
modifiedtests/package.jsondiffbeforeafterboth
32 "testRemoveFromWhiteList": "mocha --timeout 9999999 -r ts-node/register ./**/removeFromWhiteList.test.ts",32 "testRemoveFromWhiteList": "mocha --timeout 9999999 -r ts-node/register ./**/removeFromWhiteList.test.ts",
33 "testConnection": "mocha --timeout 9999999 -r ts-node/register ./**/connection.test.ts",33 "testConnection": "mocha --timeout 9999999 -r ts-node/register ./**/connection.test.ts",
34 "testCollection": "mocha --timeout 9999999 -r ts-node/register ./**/createCollection.test.ts",34 "testCollection": "mocha --timeout 9999999 -r ts-node/register ./**/createCollection.test.ts",
35 "testContracts": "mocha --timeout 9999999 -r ts-node/register ./**/contracts.test.ts",
35 "testCreateItem": "mocha --timeout 9999999 -r ts-node/register ./**/createItem.test.ts",36 "testCreateItem": "mocha --timeout 9999999 -r ts-node/register ./**/createItem.test.ts",
36 "testCreateMultipleItems": "mocha --timeout 9999999 -r ts-node/register ./**/createMultipleItems.test.ts",37 "testCreateMultipleItems": "mocha --timeout 9999999 -r ts-node/register ./**/createMultipleItems.test.ts",
37 "testApprove": "mocha --timeout 9999999 -r ts-node/register ./**/approve.test.ts",38 "testApprove": "mocha --timeout 9999999 -r ts-node/register ./**/approve.test.ts",
44 "testSetMintPermission": "mocha --timeout 9999999 -r ts-node/register ./**/setMintPermission.test.ts",45 "testSetMintPermission": "mocha --timeout 9999999 -r ts-node/register ./**/setMintPermission.test.ts",
45 "testCreditFeesToTreasury": "mocha --timeout 9999999 -r ts-node/register ./**/creditFeesToTreasury.test.ts",46 "testCreditFeesToTreasury": "mocha --timeout 9999999 -r ts-node/register ./**/creditFeesToTreasury.test.ts",
46 "testEnableContractSponsoring": "mocha --timeout 9999999 -r ts-node/register ./**/enableContractSponsoring.test.ts",47 "testEnableContractSponsoring": "mocha --timeout 9999999 -r ts-node/register ./**/enableContractSponsoring.test.ts",
48 "testRemoveFromContractWhiteList": "mocha --timeout 9999999 -r ts-node/register ./**/removeFromContractWhiteList.test.ts",
47 "testSetContractSponsoringRateLimit": "mocha --timeout 9999999 -r ts-node/register ./**/setContractSponsoringRateLimit.test.ts",49 "testSetContractSponsoringRateLimit": "mocha --timeout 9999999 -r ts-node/register ./**/setContractSponsoringRateLimit.test.ts",
48 "testSetOffchainSchema": "mocha --timeout 9999999 -r ts-node/register ./**/setOffchainSchema.test.ts",50 "testSetOffchainSchema": "mocha --timeout 9999999 -r ts-node/register ./**/setOffchainSchema.test.ts",
49 "testOverflow": "mocha --timeout 9999999 -r ts-node/register ./**/overflow.test.ts",51 "testOverflow": "mocha --timeout 9999999 -r ts-node/register ./**/overflow.test.ts",
modifiedtests/src/approve.test.tsdiffbeforeafterboth
123 // nft123 // nft
124 const nftCollectionId = await createCollectionExpectSuccess();124 const nftCollectionId = await createCollectionExpectSuccess();
125 await approveExpectFail(nftCollectionId, 2, Alice, Bob);125 await approveExpectFail(nftCollectionId, 2, Alice, Bob);
126 // fungible
127 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
128 await approveExpectFail(fungibleCollectionId, 2, Alice, Bob);
129 // reFungible126 // reFungible
130 const reFungibleCollectionId =127 const reFungibleCollectionId =
131 await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});128 await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
modifiedtests/src/burnItem.test.tsdiffbeforeafterboth
46 // tslint:disable-next-line:no-unused-expression46 // tslint:disable-next-line:no-unused-expression
47 expect(result.success).to.be.true;47 expect(result.success).to.be.true;
48 // tslint:disable-next-line:no-unused-expression48 // tslint:disable-next-line:no-unused-expression
49 expect(item).to.be.not.null;49 expect(item).to.be.null;
50 expect(item.Owner).to.be.equal(nullPublicKey);
51 });50 });
5251
53 });52 });
88 87
89 // What to expect88 // What to expect
90 expect(result.success).to.be.true;89 expect(result.success).to.be.true;
91 expect(balance).to.be.not.null;90 expect(balance).to.be.null;
92 expect(balance.Owner.length).to.be.equal(0);
93 });91 });
9492
95 });93 });
modifiedtests/src/contracts.test.tsdiffbeforeafterboth
63 const collectionId = await createCollectionExpectSuccess();63 const collectionId = await createCollectionExpectSuccess();
64 const tokenId = await createItemExpectSuccess(alice, collectionId, 'NFT');64 const tokenId = await createItemExpectSuccess(alice, collectionId, 'NFT');
65 const [contract, deployer] = await deployTransferContract(api);65 const [contract, deployer] = await deployTransferContract(api);
66 const tokenBefore: any = await api.query.nft.nftItemList(collectionId, tokenId);66 const tokenBefore: any = (await api.query.nft.nftItemList(collectionId, tokenId) as any).unwrap();
67 67
68 // Transfer68 // Transfer
69 const transferTx = contract.tx.transfer(value, gasLimit, bob.address, collectionId, tokenId, 1);69 const transferTx = contract.tx.transfer(value, gasLimit, bob.address, collectionId, tokenId, 1);
70 const events = await submitTransactionAsync(alice, transferTx);70 const events = await submitTransactionAsync(alice, transferTx);
71 const result = getGenericResult(events);71 const result = getGenericResult(events);
72 const tokenAfter: any = await api.query.nft.nftItemList(collectionId, tokenId);72 const tokenAfter: any = (await api.query.nft.nftItemList(collectionId, tokenId) as any).unwrap();
7373
74 // tslint:disable-next-line:no-unused-expression74 // tslint:disable-next-line:no-unused-expression
75 expect(result.success).to.be.true;75 expect(result.success).to.be.true;
modifiedtests/src/createMultipleItems.test.tsdiffbeforeafterboth
38 await submitTransactionAsync(Alice, createMultipleItemsTx);38 await submitTransactionAsync(Alice, createMultipleItemsTx);
39 const itemsListIndexAfter = await api.query.nft.itemListIndex(collectionId) as unknown as BN;39 const itemsListIndexAfter = await api.query.nft.itemListIndex(collectionId) as unknown as BN;
40 expect(itemsListIndexAfter.toNumber()).to.be.equal(3);40 expect(itemsListIndexAfter.toNumber()).to.be.equal(3);
41 const token1Data = await api.query.nft.nftItemList(collectionId, 1) as unknown as ITokenDataType;41 const token1Data = (await api.query.nft.nftItemList(collectionId, 1)).toJSON() as unknown as ITokenDataType;
42 const token2Data = await api.query.nft.nftItemList(collectionId, 2) as unknown as ITokenDataType;42 const token2Data = (await api.query.nft.nftItemList(collectionId, 2)).toJSON() as unknown as ITokenDataType;
43 const token3Data = await api.query.nft.nftItemList(collectionId, 3) as unknown as ITokenDataType;43 const token3Data = (await api.query.nft.nftItemList(collectionId, 3)).toJSON() as unknown as ITokenDataType;
4444
45 expect(token1Data.Owner.toString()).to.be.equal(Alice.address);45 expect(token1Data.Owner.toString()).to.be.equal(Alice.address);
46 expect(token2Data.Owner.toString()).to.be.equal(Alice.address);46 expect(token2Data.Owner.toString()).to.be.equal(Alice.address);
72 await submitTransactionAsync(Alice, createMultipleItemsTx);72 await submitTransactionAsync(Alice, createMultipleItemsTx);
73 const itemsListIndexAfter = await api.query.nft.itemListIndex(collectionId) as unknown as BN;73 const itemsListIndexAfter = await api.query.nft.itemListIndex(collectionId) as unknown as BN;
74 expect(itemsListIndexAfter.toNumber()).to.be.equal(3);74 expect(itemsListIndexAfter.toNumber()).to.be.equal(3);
75 const token1Data = await api.query.nft.reFungibleItemList(collectionId, 1) as unknown as IReFungibleTokenDataType;75 const token1Data = (await api.query.nft.reFungibleItemList(collectionId, 1) as any).unwrap() as unknown as IReFungibleTokenDataType;
76 const token2Data = await api.query.nft.reFungibleItemList(collectionId, 2) as unknown as IReFungibleTokenDataType;76 const token2Data = (await api.query.nft.reFungibleItemList(collectionId, 2) as any).unwrap() as unknown as IReFungibleTokenDataType;
77 const token3Data = await api.query.nft.reFungibleItemList(collectionId, 3) as unknown as IReFungibleTokenDataType;77 const token3Data = (await api.query.nft.reFungibleItemList(collectionId, 3) as any).unwrap() as unknown as IReFungibleTokenDataType;
7878
79 expect(token1Data.Owner[0].Owner.toString()).to.be.equal(Alice.address);79 expect(token1Data.Owner[0].Owner.toString()).to.be.equal(Alice.address);
80 expect(token1Data.Owner[0].Fraction.toNumber()).to.be.equal(1);80 expect(token1Data.Owner[0].Fraction.toNumber()).to.be.equal(1);
modifiedtests/src/removeCollectionAdmin.test.tsdiffbeforeafterboth
37 });37 });
38 });38 });
39
40 it('Remove admin from collection that has no admins', async () => {
41 await usingApi(async (api: ApiPromise) => {
42 const Alice = privateKey('//Alice');
43 const collectionId = await createCollectionExpectSuccess();
44
45 const adminListBeforeAddAdmin: any = (await api.query.nft.adminList(collectionId));
46 expect(adminListBeforeAddAdmin).to.have.lengthOf(0);
47
48 const tx = api.tx.nft.removeCollectionAdmin(collectionId, Alice.address);
49 await submitTransactionAsync(Alice, tx);
50 });
51 });
39});52});
4053
41describe('Negative Integration Test removeCollectionAdmin(collection_id, account_id):', () => {54describe('Negative Integration Test removeCollectionAdmin(collection_id, account_id):', () => {
71 });84 });
72 });85 });
73
74 it('Remove admin from collection that has no admins', async () => {
75 await usingApi(async (api: ApiPromise) => {
76 const Alice = privateKey('//Alice');
77 const collectionId = await createCollectionExpectSuccess();
78
79 const adminListBeforeAddAdmin: any = (await api.query.nft.adminList(collectionId));
80 expect(adminListBeforeAddAdmin).to.have.lengthOf(0);
81
82 const tx = api.tx.nft.removeCollectionAdmin(collectionId, Alice.address);
83 await expect(submitTransactionExpectFailAsync(Alice, tx)).to.be.rejected;
84 });
85 });
86});86});
8787
modifiedtests/src/removeFromContractWhiteList.test.tsdiffbeforeafterboth
13describe('Integration Test removeFromContractWhiteList', () => {13describe('Integration Test removeFromContractWhiteList', () => {
14 let bob: IKeyringPair;14 let bob: IKeyringPair;
1515
16 before(() => {16 before(async () => {
17 await usingApi(async () => {
17 bob = privateKey('//Bob');18 bob = privateKey('//Bob');
18 });19 });
20 });
1921
20 it('user is no longer whitelisted after removal', async () => {22 it('user is no longer whitelisted after removal', async () => {
56 let alice: IKeyringPair;58 let alice: IKeyringPair;
57 let bob: IKeyringPair;59 let bob: IKeyringPair;
5860
59 before(() => {61 before(async () => {
62 await usingApi(async () => {
60 alice = privateKey('//Alice');63 alice = privateKey('//Alice');
61 bob = privateKey('//Bob');64 bob = privateKey('//Bob');
62 });65 });
66 });
6367
64 it('fails when called with non-contract address', async () => {68 it('fails when called with non-contract address', async () => {
modifiedtests/src/setVariableMetaData.test.tsdiffbeforeafterboth
4141
42 it('verify data was set', async () => {42 it('verify data was set', async () => {
43 await usingApi(async api => {43 await usingApi(async api => {
44 const item: any = await api.query.nft.nftItemList(collectionId, tokenId);44 const item: any = (await api.query.nft.nftItemList(collectionId, tokenId) as any).unwrap();
4545
46 expect(Array.from(item.VariableData)).to.deep.equal(Array.from(data));46 expect(Array.from(item.VariableData)).to.deep.equal(Array.from(data));
47 });47 });
modifiedtests/src/transferFrom.test.tsdiffbeforeafterboth
237 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});237 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
238 const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');238 const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');
239 await burnItemExpectSuccess(Alice, fungibleCollectionId, 1, 10);239 await burnItemExpectSuccess(Alice, fungibleCollectionId, 1, 10);
240 await approveExpectFail(fungibleCollectionId, newFungibleTokenId, Alice, Bob);240 await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, Alice, Bob);
241 await transferFromExpectFail(fungibleCollectionId, newFungibleTokenId, Bob, Alice, Charlie, 1);241 await transferFromExpectFail(fungibleCollectionId, newFungibleTokenId, Bob, Alice, Charlie, 1);
242 242
243 });243 });
modifiedtests/src/util/helpers.tsdiffbeforeafterboth
599 // tslint:disable-next-line:no-unused-expression599 // tslint:disable-next-line:no-unused-expression
600 expect(result.success).to.be.true;600 expect(result.success).to.be.true;
601 // tslint:disable-next-line:no-unused-expression601 // tslint:disable-next-line:no-unused-expression
602 expect(item).to.be.not.null;602 expect(item).to.be.null;
603 expect(item.Owner).to.be.equal(nullPublicKey);
604 });603 });
605}604}
606605
641 // tslint:disable-next-line:no-unused-expression640 // tslint:disable-next-line:no-unused-expression
642 expect(result.success).to.be.true;641 expect(result.success).to.be.true;
643 if (type === 'NFT') {642 if (type === 'NFT') {
644 const nftItemData = await api.query.nft.nftItemList(collectionId, tokenId) as unknown as ITokenDataType;643 const nftItemData = (await api.query.nft.nftItemList(collectionId, tokenId) as any).unwrap() as ITokenDataType;
645 expect(nftItemData.Owner.toString()).to.be.equal(accountTo.address);644 expect(nftItemData.Owner.toString()).to.be.equal(accountTo.address);
646 }645 }
647 if (type === 'Fungible') {646 if (type === 'Fungible') {
648 const balanceAfter = await api.query.nft.balance(collectionId, accountTo.address) as unknown as BN;647 const balanceAfter = (await api.query.nft.fungibleItemList(collectionId, accountTo.address) as any).Value as unknown as BN;
649 expect(balanceAfter.sub(balanceBefore).toString()).to.be.equal(value.toString());648 expect(balanceAfter.sub(balanceBefore).toString()).to.be.equal(value.toString());
650 }649 }
651 if (type === 'ReFungible') {650 if (type === 'ReFungible') {
652 const nftItemData =651 const nftItemData =
653 await api.query.nft.reFungibleItemList(collectionId, tokenId) as unknown as IReFungibleTokenDataType;652 (await api.query.nft.reFungibleItemList(collectionId, tokenId) as any).unwrap() as IReFungibleTokenDataType;
654 expect(nftItemData.Owner[0].Owner.toString()).to.be.equal(accountTo.address);653 expect(nftItemData.Owner[0].Owner.toString()).to.be.equal(accountTo.address);
655 expect(nftItemData.Owner[0].Fraction.toNumber()).to.be.equal(value);654 expect(nftItemData.Owner[0].Fraction.toNumber()).to.be.equal(value);
656 }655 }
697 expect(result.recipient).to.be.equal(recipient.address);696 expect(result.recipient).to.be.equal(recipient.address);
698 expect(result.value.toString()).to.be.equal(value.toString());697 expect(result.value.toString()).to.be.equal(value.toString());
699 if (type === 'NFT') {698 if (type === 'NFT') {
700 const nftItemData = await api.query.nft.nftItemList(collectionId, tokenId) as unknown as ITokenDataType;699 const nftItemData = (await api.query.nft.nftItemList(collectionId, tokenId)).toJSON() as unknown as ITokenDataType;
701 expect(nftItemData.Owner.toString()).to.be.equal(recipient.address);700 expect(nftItemData.Owner.toString()).to.be.equal(recipient.address);
702 }701 }
703 if (type === 'Fungible') {702 if (type === 'Fungible') {
704 const balanceAfter = await api.query.nft.balance(collectionId, recipient.address) as unknown as BN;703 const balanceAfter = (await api.query.nft.fungibleItemList(collectionId, recipient.address) as any).Value as unknown as BN;
705 expect(balanceAfter.sub(balanceBefore).toString()).to.be.equal(value.toString());704 expect(balanceAfter.sub(balanceBefore).toString()).to.be.equal(value.toString());
706 }705 }
707 if (type === 'ReFungible') {706 if (type === 'ReFungible') {
708 const nftItemData =707 const nftItemData =
709 await api.query.nft.reFungibleItemList(collectionId, tokenId) as unknown as IReFungibleTokenDataType;708 (await api.query.nft.reFungibleItemList(collectionId, tokenId)).toJSON() as unknown as IReFungibleTokenDataType;
710 expect(nftItemData.Owner[0].Owner.toString()).to.be.equal(recipient.address);709 expect(nftItemData.Owner[0].Owner.toString()).to.be.equal(recipient.address);
711 expect(nftItemData.Owner[0].Fraction.toNumber()).to.be.equal(value);710 expect(nftItemData.Owner[0].Fraction.toString()).to.be.equal(value.toString());
712 }711 }
713 });712 });
714}713}